From 1e23a36e1da749c21ba7a42cb033fb12dad719a5 Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Sun, 1 Apr 2018 12:06:29 +0100 Subject: [PATCH] More translateable strings (#1354) --- include/znc/Socket.h | 3 ++- src/SSLVerifyHost.cpp | 10 +++++++--- src/Socket.cpp | 16 ++++++++++------ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/include/znc/Socket.h b/include/znc/Socket.h index 3cddc461..a667b643 100644 --- a/include/znc/Socket.h +++ b/include/znc/Socket.h @@ -72,7 +72,8 @@ class CZNCSock : public Csock, public CCoreTranslationMixin { enum EAddrType { ADDR_IPV4ONLY, ADDR_IPV6ONLY, ADDR_ALL }; -class CSockManager : public TSocketManager { +class CSockManager : public TSocketManager, + private CCoreTranslationMixin { public: CSockManager(); virtual ~CSockManager(); diff --git a/src/SSLVerifyHost.cpp b/src/SSLVerifyHost.cpp index 95859e45..30d9487c 100644 --- a/src/SSLVerifyHost.cpp +++ b/src/SSLVerifyHost.cpp @@ -15,6 +15,7 @@ */ #include +#include #ifdef HAVE_LIBSSL #if defined(OPENSSL_VERSION_NUMBER) && !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100007 @@ -432,6 +433,9 @@ static HostnameValidationResult validate_hostname(const char* hostname, bool ZNC_SSLVerifyHost(const CString& sHost, const X509* pCert, CString& sError) { + struct Tr : CCoreTranslationMixin { + using CCoreTranslationMixin::t_s; + }; DEBUG("SSLVerifyHost: checking " << sHost); ZNC_iSECPartners::HostnameValidationResult eResult = ZNC_iSECPartners::validate_hostname(sHost.c_str(), pCert); @@ -441,15 +445,15 @@ bool ZNC_SSLVerifyHost(const CString& sHost, const X509* pCert, return true; case ZNC_iSECPartners::MatchNotFound: DEBUG("SSLVerifyHost: host doesn't match"); - sError = "hostname doesn't match"; + sError = Tr::t_s("hostname doesn't match"); return false; case ZNC_iSECPartners::MalformedCertificate: DEBUG("SSLVerifyHost: malformed cert"); - sError = "malformed hostname in certificate"; + sError = Tr::t_s("malformed hostname in certificate"); return false; default: DEBUG("SSLVerifyHost: error"); - sError = "hostname verification error"; + sError = Tr::t_s("hostname verification error"); return false; } } diff --git a/src/Socket.cpp b/src/Socket.cpp index a15daed4..fa510462 100644 --- a/src/Socket.cpp +++ b/src/Socket.cpp @@ -333,16 +333,19 @@ void CSockManager::SetTDNSThreadFinished(TDNSTask* task, bool bBind, try { if (ssTargets4.empty() && ssTargets6.empty()) { - throw "Can't resolve server hostname"; + throw t_s("Can't resolve server hostname"); } else if (task->sBindhost.empty()) { // Choose random target std::tie(sTargetHost, std::ignore) = RandomFrom2SetsWithBias(ssTargets4, ssTargets6, gen); } else if (ssBinds4.empty() && ssBinds6.empty()) { - throw "Can't resolve bind hostname. Try /znc ClearBindHost and /znc ClearUserBindHost"; + throw t_s( + "Can't resolve bind hostname. Try /znc ClearBindHost and /znc " + "ClearUserBindHost"); } else if (ssBinds4.empty()) { if (ssTargets6.empty()) { - throw "Server address is IPv4-only, but bindhost is IPv6-only"; + throw t_s( + "Server address is IPv4-only, but bindhost is IPv6-only"); } else { // Choose random target and bindhost from IPv6-only sets sTargetHost = RandomFromSet(ssTargets6, gen); @@ -350,7 +353,8 @@ void CSockManager::SetTDNSThreadFinished(TDNSTask* task, bool bBind, } } else if (ssBinds6.empty()) { if (ssTargets4.empty()) { - throw "Server address is IPv6-only, but bindhost is IPv4-only"; + throw t_s( + "Server address is IPv6-only, but bindhost is IPv4-only"); } else { // Choose random target and bindhost from IPv4-only sets sTargetHost = RandomFromSet(ssTargets4, gen); @@ -370,7 +374,7 @@ void CSockManager::SetTDNSThreadFinished(TDNSTask* task, bool bBind, << "] using bindhost [" << sBindhost << "]"); FinishConnect(sTargetHost, task->iPort, task->sSockName, task->iTimeout, task->bSSL, sBindhost, task->pcSock); - } catch (const char* s) { + } catch (const CString& s) { DEBUG(task->sSockName << ", dns resolving error: " << s); task->pcSock->SetSockName(task->sSockName); task->pcSock->SockError(-1, s); @@ -508,7 +512,7 @@ void CSocket::ReachedMaxBuffer() { DEBUG(GetSockName() << " == ReachedMaxBuffer()"); if (m_pModule) m_pModule->PutModule( - "Some socket reached its max buffer limit and was closed!"); + t_s("Some socket reached its max buffer limit and was closed!")); Close(); }