Trace socket/connection events.
This commit is contained in:
parent
58ca0d1dd5
commit
bbfdcc36a0
@ -119,6 +119,7 @@ void IMAPConnection::connect()
|
|||||||
|
|
||||||
// Create and connect the socket
|
// Create and connect the socket
|
||||||
m_socket = store->getSocketFactory()->create(m_timeoutHandler);
|
m_socket = store->getSocketFactory()->create(m_timeoutHandler);
|
||||||
|
m_socket->setTracer(m_tracer);
|
||||||
|
|
||||||
#if VMIME_HAVE_TLS_SUPPORT
|
#if VMIME_HAVE_TLS_SUPPORT
|
||||||
if (store->isIMAPS()) // dedicated port/IMAPS
|
if (store->isIMAPS()) // dedicated port/IMAPS
|
||||||
|
@ -106,6 +106,7 @@ void POP3Connection::connect()
|
|||||||
|
|
||||||
// Create and connect the socket
|
// Create and connect the socket
|
||||||
m_socket = store->getSocketFactory()->create(m_timeoutHandler);
|
m_socket = store->getSocketFactory()->create(m_timeoutHandler);
|
||||||
|
m_socket->setTracer(m_tracer);
|
||||||
|
|
||||||
#if VMIME_HAVE_TLS_SUPPORT
|
#if VMIME_HAVE_TLS_SUPPORT
|
||||||
if (store->isPOP3S()) // dedicated port/POP3S
|
if (store->isPOP3S()) // dedicated port/POP3S
|
||||||
|
@ -107,6 +107,7 @@ void SMTPConnection::connect()
|
|||||||
|
|
||||||
// Create and connect the socket
|
// Create and connect the socket
|
||||||
m_socket = transport->getSocketFactory()->create(m_timeoutHandler);
|
m_socket = transport->getSocketFactory()->create(m_timeoutHandler);
|
||||||
|
m_socket->setTracer(m_tracer);
|
||||||
|
|
||||||
#if VMIME_HAVE_TLS_SUPPORT
|
#if VMIME_HAVE_TLS_SUPPORT
|
||||||
if (transport->isSMTPS()) // dedicated port/SMTPS
|
if (transport->isSMTPS()) // dedicated port/SMTPS
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
#include "vmime/base.hpp"
|
#include "vmime/base.hpp"
|
||||||
|
|
||||||
#include "vmime/net/timeoutHandler.hpp"
|
#include "vmime/net/timeoutHandler.hpp"
|
||||||
|
#include "vmime/net/tracer.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace vmime {
|
namespace vmime {
|
||||||
@ -168,6 +169,20 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual shared_ptr <timeoutHandler> getTimeoutHandler() = 0;
|
virtual shared_ptr <timeoutHandler> getTimeoutHandler() = 0;
|
||||||
|
|
||||||
|
/** Set the tracer used by this socket. Tracer will only be used
|
||||||
|
* to report socket-specific events such as connection (not when
|
||||||
|
* sending/receiving data).
|
||||||
|
*
|
||||||
|
* @param tracer tracer to use
|
||||||
|
*/
|
||||||
|
virtual void setTracer(shared_ptr <tracer> tracer) = 0;
|
||||||
|
|
||||||
|
/** Return the tracer used by this socket.
|
||||||
|
*
|
||||||
|
* @return tracer, or NULL if none is set
|
||||||
|
*/
|
||||||
|
virtual shared_ptr <tracer> getTracer() = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
socket() { }
|
socket() { }
|
||||||
|
@ -74,7 +74,7 @@ public:
|
|||||||
* @return server certificate chain, or NULL if the handshake
|
* @return server certificate chain, or NULL if the handshake
|
||||||
* has not been performed yet
|
* has not been performed yet
|
||||||
*/
|
*/
|
||||||
virtual shared_ptr <security::cert::certificateChain> getPeerCertificates() const = 0;
|
virtual shared_ptr <security::cert::certificateChain> getPeerCertificates() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -147,6 +147,18 @@ shared_ptr <timeoutHandler> TLSSocket_GnuTLS::getTimeoutHandler()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TLSSocket_GnuTLS::setTracer(shared_ptr <net::tracer> tracer)
|
||||||
|
{
|
||||||
|
m_wrapped->setTracer(tracer);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
shared_ptr <net::tracer> TLSSocket_GnuTLS::getTracer()
|
||||||
|
{
|
||||||
|
return m_wrapped->getTracer();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool TLSSocket_GnuTLS::waitForRead(const int msecs)
|
bool TLSSocket_GnuTLS::waitForRead(const int msecs)
|
||||||
{
|
{
|
||||||
return m_wrapped->waitForRead(msecs);
|
return m_wrapped->waitForRead(msecs);
|
||||||
@ -287,6 +299,9 @@ void TLSSocket_GnuTLS::handshake()
|
|||||||
if (toHandler)
|
if (toHandler)
|
||||||
toHandler->resetTimeOut();
|
toHandler->resetTimeOut();
|
||||||
|
|
||||||
|
if (getTracer())
|
||||||
|
getTracer()->traceSend("Beginning SSL/TLS handshake");
|
||||||
|
|
||||||
// Start handshaking process
|
// Start handshaking process
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -406,8 +421,11 @@ ssize_t TLSSocket_GnuTLS::gnutlsPullFunc
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
shared_ptr <security::cert::certificateChain> TLSSocket_GnuTLS::getPeerCertificates() const
|
shared_ptr <security::cert::certificateChain> TLSSocket_GnuTLS::getPeerCertificates()
|
||||||
{
|
{
|
||||||
|
if (getTracer())
|
||||||
|
getTracer()->traceSend("Getting peer certificates");
|
||||||
|
|
||||||
unsigned int certCount = 0;
|
unsigned int certCount = 0;
|
||||||
const gnutls_datum* rawData = gnutls_certificate_get_peers
|
const gnutls_datum* rawData = gnutls_certificate_get_peers
|
||||||
(*m_session->m_gnutlsSession, &certCount);
|
(*m_session->m_gnutlsSession, &certCount);
|
||||||
|
@ -56,7 +56,7 @@ public:
|
|||||||
|
|
||||||
void handshake();
|
void handshake();
|
||||||
|
|
||||||
shared_ptr <security::cert::certificateChain> getPeerCertificates() const;
|
shared_ptr <security::cert::certificateChain> getPeerCertificates();
|
||||||
|
|
||||||
// Implementation of 'socket'
|
// Implementation of 'socket'
|
||||||
void connect(const string& address, const port_t port);
|
void connect(const string& address, const port_t port);
|
||||||
@ -83,6 +83,9 @@ public:
|
|||||||
|
|
||||||
shared_ptr <timeoutHandler> getTimeoutHandler();
|
shared_ptr <timeoutHandler> getTimeoutHandler();
|
||||||
|
|
||||||
|
void setTracer(shared_ptr <net::tracer> tracer);
|
||||||
|
shared_ptr <net::tracer> getTracer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void internalThrow();
|
void internalThrow();
|
||||||
|
@ -193,6 +193,18 @@ shared_ptr <timeoutHandler> TLSSocket_OpenSSL::getTimeoutHandler()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TLSSocket_OpenSSL::setTracer(shared_ptr <net::tracer> tracer)
|
||||||
|
{
|
||||||
|
m_wrapped->setTracer(tracer);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
shared_ptr <net::tracer> TLSSocket_OpenSSL::getTracer()
|
||||||
|
{
|
||||||
|
return m_wrapped->getTracer();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool TLSSocket_OpenSSL::waitForRead(const int msecs)
|
bool TLSSocket_OpenSSL::waitForRead(const int msecs)
|
||||||
{
|
{
|
||||||
return m_wrapped->waitForRead(msecs);
|
return m_wrapped->waitForRead(msecs);
|
||||||
@ -343,6 +355,9 @@ void TLSSocket_OpenSSL::handshake()
|
|||||||
if (toHandler)
|
if (toHandler)
|
||||||
toHandler->resetTimeOut();
|
toHandler->resetTimeOut();
|
||||||
|
|
||||||
|
if (getTracer())
|
||||||
|
getTracer()->traceSend("Beginning SSL/TLS handshake");
|
||||||
|
|
||||||
// Start handshaking process
|
// Start handshaking process
|
||||||
if (!m_ssl)
|
if (!m_ssl)
|
||||||
createSSLHandle();
|
createSSLHandle();
|
||||||
@ -389,8 +404,11 @@ void TLSSocket_OpenSSL::handshake()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
shared_ptr <security::cert::certificateChain> TLSSocket_OpenSSL::getPeerCertificates() const
|
shared_ptr <security::cert::certificateChain> TLSSocket_OpenSSL::getPeerCertificates()
|
||||||
{
|
{
|
||||||
|
if (getTracer())
|
||||||
|
getTracer()->traceSend("Getting peer certificates");
|
||||||
|
|
||||||
STACK_OF(X509)* chain = SSL_get_peer_cert_chain(m_ssl);
|
STACK_OF(X509)* chain = SSL_get_peer_cert_chain(m_ssl);
|
||||||
|
|
||||||
if (chain == NULL)
|
if (chain == NULL)
|
||||||
|
@ -60,7 +60,7 @@ public:
|
|||||||
|
|
||||||
void handshake();
|
void handshake();
|
||||||
|
|
||||||
shared_ptr <security::cert::certificateChain> getPeerCertificates() const;
|
shared_ptr <security::cert::certificateChain> getPeerCertificates();
|
||||||
|
|
||||||
// Implementation of 'socket'
|
// Implementation of 'socket'
|
||||||
void connect(const string& address, const port_t port);
|
void connect(const string& address, const port_t port);
|
||||||
@ -87,6 +87,9 @@ public:
|
|||||||
|
|
||||||
shared_ptr <timeoutHandler> getTimeoutHandler();
|
shared_ptr <timeoutHandler> getTimeoutHandler();
|
||||||
|
|
||||||
|
void setTracer(shared_ptr <net::tracer> tracer);
|
||||||
|
shared_ptr <net::tracer> getTracer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
static BIO_METHOD sm_customBIOMethod;
|
static BIO_METHOD sm_customBIOMethod;
|
||||||
|
@ -84,6 +84,14 @@ void posixSocket::connect(const vmime::string& address, const vmime::port_t port
|
|||||||
m_desc = -1;
|
m_desc = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_tracer)
|
||||||
|
{
|
||||||
|
std::ostringstream trace;
|
||||||
|
trace << "Connecting to " << address << ", port " << port;
|
||||||
|
|
||||||
|
m_tracer->traceSend(trace.str());
|
||||||
|
}
|
||||||
|
|
||||||
#if VMIME_HAVE_GETADDRINFO // use thread-safe and IPv6-aware getaddrinfo() if available
|
#if VMIME_HAVE_GETADDRINFO // use thread-safe and IPv6-aware getaddrinfo() if available
|
||||||
|
|
||||||
// Resolve address, if needed
|
// Resolve address, if needed
|
||||||
@ -370,6 +378,9 @@ void posixSocket::disconnect()
|
|||||||
{
|
{
|
||||||
if (m_desc != -1)
|
if (m_desc != -1)
|
||||||
{
|
{
|
||||||
|
if (m_tracer)
|
||||||
|
m_tracer->traceSend("Disconnecting");
|
||||||
|
|
||||||
::shutdown(m_desc, SHUT_RDWR);
|
::shutdown(m_desc, SHUT_RDWR);
|
||||||
::close(m_desc);
|
::close(m_desc);
|
||||||
|
|
||||||
@ -730,6 +741,18 @@ shared_ptr <net::timeoutHandler> posixSocket::getTimeoutHandler()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void posixSocket::setTracer(shared_ptr <net::tracer> tracer)
|
||||||
|
{
|
||||||
|
m_tracer = tracer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
shared_ptr <net::tracer> posixSocket::getTracer()
|
||||||
|
{
|
||||||
|
return m_tracer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// posixSocketFactory
|
// posixSocketFactory
|
||||||
|
@ -70,6 +70,9 @@ public:
|
|||||||
|
|
||||||
shared_ptr <net::timeoutHandler> getTimeoutHandler();
|
shared_ptr <net::timeoutHandler> getTimeoutHandler();
|
||||||
|
|
||||||
|
void setTracer(shared_ptr <net::tracer> tracer);
|
||||||
|
shared_ptr <net::tracer> getTracer();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
bool waitForData(const bool read, const bool write, const int msecs);
|
bool waitForData(const bool read, const bool write, const int msecs);
|
||||||
@ -79,6 +82,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
shared_ptr <vmime::net::timeoutHandler> m_timeoutHandler;
|
shared_ptr <vmime::net::timeoutHandler> m_timeoutHandler;
|
||||||
|
shared_ptr <net::tracer> m_tracer;
|
||||||
|
|
||||||
byte_t m_buffer[65536];
|
byte_t m_buffer[65536];
|
||||||
int m_desc;
|
int m_desc;
|
||||||
|
@ -81,6 +81,14 @@ void windowsSocket::connect(const vmime::string& address, const vmime::port_t po
|
|||||||
addr.sin_port = htons(static_cast <unsigned short>(port));
|
addr.sin_port = htons(static_cast <unsigned short>(port));
|
||||||
addr.sin_addr.s_addr = ::inet_addr(address.c_str());
|
addr.sin_addr.s_addr = ::inet_addr(address.c_str());
|
||||||
|
|
||||||
|
if (m_tracer)
|
||||||
|
{
|
||||||
|
std::ostringstream trace;
|
||||||
|
trace << "Connecting to " << address << ", port " << port;
|
||||||
|
|
||||||
|
m_tracer->traceSend(trace.str());
|
||||||
|
}
|
||||||
|
|
||||||
if (addr.sin_addr.s_addr == static_cast <int>(-1))
|
if (addr.sin_addr.s_addr == static_cast <int>(-1))
|
||||||
{
|
{
|
||||||
::hostent* hostInfo = ::gethostbyname(address.c_str());
|
::hostent* hostInfo = ::gethostbyname(address.c_str());
|
||||||
@ -153,6 +161,9 @@ void windowsSocket::disconnect()
|
|||||||
{
|
{
|
||||||
if (m_desc != INVALID_SOCKET)
|
if (m_desc != INVALID_SOCKET)
|
||||||
{
|
{
|
||||||
|
if (m_tracer)
|
||||||
|
m_tracer->traceSend("Disconnecting");
|
||||||
|
|
||||||
::shutdown(m_desc, SD_BOTH);
|
::shutdown(m_desc, SD_BOTH);
|
||||||
::closesocket(m_desc);
|
::closesocket(m_desc);
|
||||||
|
|
||||||
@ -491,6 +502,18 @@ shared_ptr <net::timeoutHandler> windowsSocket::getTimeoutHandler()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void windowsSocket::setTracer(shared_ptr <net::tracer> tracer)
|
||||||
|
{
|
||||||
|
m_tracer = tracer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
shared_ptr <net::tracer> windowsSocket::getTracer()
|
||||||
|
{
|
||||||
|
return m_tracer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// posixSocketFactory
|
// posixSocketFactory
|
||||||
|
@ -74,6 +74,9 @@ public:
|
|||||||
|
|
||||||
shared_ptr <net::timeoutHandler> getTimeoutHandler();
|
shared_ptr <net::timeoutHandler> getTimeoutHandler();
|
||||||
|
|
||||||
|
void setTracer(shared_ptr <net::tracer> tracer);
|
||||||
|
shared_ptr <net::tracer> getTracer();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void throwSocketError(const int err);
|
void throwSocketError(const int err);
|
||||||
|
@ -102,6 +102,18 @@ shared_ptr <net::timeoutHandler> SASLSocket::getTimeoutHandler()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SASLSocket::setTracer(shared_ptr <net::tracer> tracer)
|
||||||
|
{
|
||||||
|
m_wrapped->setTracer(tracer);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
shared_ptr <net::tracer> SASLSocket::getTracer()
|
||||||
|
{
|
||||||
|
return m_wrapped->getTracer();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool SASLSocket::waitForRead(const int msecs)
|
bool SASLSocket::waitForRead(const int msecs)
|
||||||
{
|
{
|
||||||
return m_wrapped->waitForRead(msecs);
|
return m_wrapped->waitForRead(msecs);
|
||||||
|
@ -78,6 +78,9 @@ public:
|
|||||||
|
|
||||||
shared_ptr <net::timeoutHandler> getTimeoutHandler();
|
shared_ptr <net::timeoutHandler> getTimeoutHandler();
|
||||||
|
|
||||||
|
void setTracer(shared_ptr <net::tracer> tracer);
|
||||||
|
shared_ptr <net::tracer> getTracer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
shared_ptr <SASLSession> m_session;
|
shared_ptr <SASLSession> m_session;
|
||||||
|
@ -85,6 +85,17 @@ vmime::shared_ptr <vmime::net::timeoutHandler> testSocket::getTimeoutHandler()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void testSocket::setTracer(vmime::shared_ptr <vmime::net::tracer> tracer)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
vmime::shared_ptr <vmime::net::tracer> testSocket::getTracer()
|
||||||
|
{
|
||||||
|
return vmime::null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool testSocket::waitForRead(const int msecs)
|
bool testSocket::waitForRead(const int msecs)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
@ -268,6 +268,9 @@ public:
|
|||||||
|
|
||||||
vmime::shared_ptr <vmime::net::timeoutHandler> getTimeoutHandler();
|
vmime::shared_ptr <vmime::net::timeoutHandler> getTimeoutHandler();
|
||||||
|
|
||||||
|
void setTracer(vmime::shared_ptr <vmime::net::tracer> tracer);
|
||||||
|
vmime::shared_ptr <vmime::net::tracer> getTracer();
|
||||||
|
|
||||||
/** Send data to client.
|
/** Send data to client.
|
||||||
*
|
*
|
||||||
* @param buffer data to send
|
* @param buffer data to send
|
||||||
|
Loading…
Reference in New Issue
Block a user