net: Simplify error reporting

This commit is contained in:
Povilas Kanapickas 2020-07-19 11:56:13 +03:00
parent bbd1accb93
commit 3d0186695f
2 changed files with 9 additions and 12 deletions

View File

@ -329,7 +329,7 @@ SecureSocket::initSsl(bool server)
initContext(server);
}
bool SecureSocket::loadCertificates(std::string& filename)
bool SecureSocket::loadCertificates(const std::string& filename)
{
if (filename.empty()) {
showError("ssl certificate is not specified");
@ -341,9 +341,7 @@ bool SecureSocket::loadCertificates(std::string& filename)
file.close();
if (!exist) {
std::string errorMsg("ssl certificate doesn't exist: ");
errorMsg.append(filename);
showError(errorMsg.c_str());
showError("ssl certificate doesn't exist: " + filename);
return false;
}
}
@ -403,7 +401,7 @@ SecureSocket::initContext(bool server)
SSL_CTX_set_options(m_ssl->m_context, SSL_OP_NO_SSLv3);
if (m_ssl->m_context == NULL) {
showError();
showError("");
}
}
@ -618,16 +616,15 @@ SecureSocket::checkResult(int status, int& retry)
if (isFatal()) {
retry = 0;
showError();
showError("");
disconnect();
}
}
void
SecureSocket::showError(const char* reason)
void SecureSocket::showError(const std::string& reason)
{
if (reason != NULL) {
LOG((CLOG_ERR "%s", reason));
if (!reason.empty()) {
LOG((CLOG_ERR "%s", reason.c_str()));
}
std::string error = getError();

View File

@ -55,7 +55,7 @@ public:
EJobResult doRead() override;
EJobResult doWrite() override;
void initSsl(bool server);
bool loadCertificates(std::string& CertFile);
bool loadCertificates(const std::string& filename);
private:
// SSL
@ -65,7 +65,7 @@ private:
int secureConnect(int s);
bool showCertificate();
void checkResult(int n, int& retry);
void showError(const char* reason = NULL);
void showError(const std::string& reason);
std::string getError();
void disconnect();
void formatFingerprint(std::string& fingerprint, bool hex = true, bool separator = true);