- Associated debugging output with log level > 0.
- Fixed bug where TLSClient::_limit was uninitialized.
This commit is contained in:
Paul Beckingham 2013-05-19 20:04:19 -04:00
parent adf374eb06
commit 00f8f56c00

View file

@ -54,6 +54,7 @@ static void gnutls_log_function (int level, const char* message)
TLSClient::TLSClient () TLSClient::TLSClient ()
: _ca ("") : _ca ("")
, _socket (0) , _socket (0)
, _limit (0)
, _debug (false) , _debug (false)
{ {
} }
@ -80,9 +81,10 @@ void TLSClient::limit (int max)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Calling this method results in all subsequent socket traffic being sent to // Calling this method results in all subsequent socket traffic being sent to
// std::cout, labelled with >>> for outgoing, <<< for incoming. // std::cout, labelled with 'c: ...'.
void TLSClient::debug (int level) void TLSClient::debug (int level)
{ {
if (level)
_debug = true; _debug = true;
gnutls_global_set_log_function (gnutls_log_function); gnutls_global_set_log_function (gnutls_log_function);
@ -104,7 +106,7 @@ void TLSClient::init (const std::string& ca)
int ret = gnutls_priority_set_direct (_session, "NORMAL", &err); int ret = gnutls_priority_set_direct (_session, "NORMAL", &err);
if (ret < 0) if (ret < 0)
{ {
if (ret == GNUTLS_E_INVALID_REQUEST) if (_debug && ret == GNUTLS_E_INVALID_REQUEST)
std::cout << "c: ERROR Priority error at: " << err << "\n"; std::cout << "c: ERROR Priority error at: " << err << "\n";
throw std::string (STRING_TLS_INIT_FAIL); throw std::string (STRING_TLS_INIT_FAIL);
@ -160,14 +162,15 @@ void TLSClient::connect (const std::string& host, const std::string& port)
// Perform the TLS handshake // Perform the TLS handshake
int ret = gnutls_handshake (_session); int ret = gnutls_handshake (_session);
if (ret < 0) if (ret < 0)
{ {
if (_debug)
std::cout << "c: ERROR Handshake failed\n"; std::cout << "c: ERROR Handshake failed\n";
gnutls_perror (ret); gnutls_perror (ret);
} }
else else
{ {
if (_debug)
std::cout << "c: INFO Handshake was completed\n"; std::cout << "c: INFO Handshake was completed\n";
} }
} }
@ -240,6 +243,7 @@ void TLSClient::recv (std::string& data)
(header[1]<<16) | (header[1]<<16) |
(header[2]<<8) | (header[2]<<8) |
header[3]; header[3];
if (_debug)
std::cout << "c: INFO expecting " << expected << " bytes.\n"; std::cout << "c: INFO expecting " << expected << " bytes.\n";
// TODO This would be a good place to assert 'expected < _limit'. // TODO This would be a good place to assert 'expected < _limit'.
@ -263,6 +267,7 @@ void TLSClient::recv (std::string& data)
// Other end closed the connection. // Other end closed the connection.
if (received == 0) if (received == 0)
{ {
if (_debug)
std::cout << "c: INFO Peer has closed the TLS connection\n"; std::cout << "c: INFO Peer has closed the TLS connection\n";
break; break;
} }