net: Simplify error reporting
This commit is contained in:
parent
bbd1accb93
commit
3d0186695f
|
@ -329,7 +329,7 @@ SecureSocket::initSsl(bool server)
|
||||||
initContext(server);
|
initContext(server);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SecureSocket::loadCertificates(std::string& filename)
|
bool SecureSocket::loadCertificates(const std::string& filename)
|
||||||
{
|
{
|
||||||
if (filename.empty()) {
|
if (filename.empty()) {
|
||||||
showError("ssl certificate is not specified");
|
showError("ssl certificate is not specified");
|
||||||
|
@ -341,9 +341,7 @@ bool SecureSocket::loadCertificates(std::string& filename)
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
if (!exist) {
|
if (!exist) {
|
||||||
std::string errorMsg("ssl certificate doesn't exist: ");
|
showError("ssl certificate doesn't exist: " + filename);
|
||||||
errorMsg.append(filename);
|
|
||||||
showError(errorMsg.c_str());
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -403,7 +401,7 @@ SecureSocket::initContext(bool server)
|
||||||
SSL_CTX_set_options(m_ssl->m_context, SSL_OP_NO_SSLv3);
|
SSL_CTX_set_options(m_ssl->m_context, SSL_OP_NO_SSLv3);
|
||||||
|
|
||||||
if (m_ssl->m_context == NULL) {
|
if (m_ssl->m_context == NULL) {
|
||||||
showError();
|
showError("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -618,16 +616,15 @@ SecureSocket::checkResult(int status, int& retry)
|
||||||
|
|
||||||
if (isFatal()) {
|
if (isFatal()) {
|
||||||
retry = 0;
|
retry = 0;
|
||||||
showError();
|
showError("");
|
||||||
disconnect();
|
disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void SecureSocket::showError(const std::string& reason)
|
||||||
SecureSocket::showError(const char* reason)
|
|
||||||
{
|
{
|
||||||
if (reason != NULL) {
|
if (!reason.empty()) {
|
||||||
LOG((CLOG_ERR "%s", reason));
|
LOG((CLOG_ERR "%s", reason.c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string error = getError();
|
std::string error = getError();
|
||||||
|
|
|
@ -55,7 +55,7 @@ public:
|
||||||
EJobResult doRead() override;
|
EJobResult doRead() override;
|
||||||
EJobResult doWrite() override;
|
EJobResult doWrite() override;
|
||||||
void initSsl(bool server);
|
void initSsl(bool server);
|
||||||
bool loadCertificates(std::string& CertFile);
|
bool loadCertificates(const std::string& filename);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// SSL
|
// SSL
|
||||||
|
@ -65,7 +65,7 @@ private:
|
||||||
int secureConnect(int s);
|
int secureConnect(int s);
|
||||||
bool showCertificate();
|
bool showCertificate();
|
||||||
void checkResult(int n, int& retry);
|
void checkResult(int n, int& retry);
|
||||||
void showError(const char* reason = NULL);
|
void showError(const std::string& reason);
|
||||||
std::string getError();
|
std::string getError();
|
||||||
void disconnect();
|
void disconnect();
|
||||||
void formatFingerprint(std::string& fingerprint, bool hex = true, bool separator = true);
|
void formatFingerprint(std::string& fingerprint, bool hex = true, bool separator = true);
|
||||||
|
|
Loading…
Reference in New Issue