diff options
author | Hoa V. DINH <dinh.viet.hoa@gmail.com> | 2013-06-26 01:37:52 -0700 |
---|---|---|
committer | CodaFi <devteam.codafi@gmail.com> | 2013-06-27 22:38:26 -0600 |
commit | 415fee56bc7ff1af0b7e8056e7195fb8172f723b (patch) | |
tree | a7ceb39b05d7538ed85462ce459766cba508bce3 /src/core | |
parent | 148f566d5fede3b4c6f3c060eb070ba5e729b143 (diff) |
Implement IMAP logger. Work in progress on POP and SMTP loggers.
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/basetypes/MCConnectionLogger.h | 16 | ||||
-rw-r--r-- | src/core/basetypes/MCConnectionLoggerUtils.cc | 19 | ||||
-rw-r--r-- | src/core/imap/MCIMAPSession.cc | 8 | ||||
-rw-r--r-- | src/core/pop/MCPOPSession.cc | 5 | ||||
-rw-r--r-- | src/core/smtp/MCSMTPSession.cc | 7 |
5 files changed, 25 insertions, 30 deletions
diff --git a/src/core/basetypes/MCConnectionLogger.h b/src/core/basetypes/MCConnectionLogger.h index 8083d12d..371e6152 100644 --- a/src/core/basetypes/MCConnectionLogger.h +++ b/src/core/basetypes/MCConnectionLogger.h @@ -9,6 +9,8 @@ #ifndef __MAILCORE_CONNECTION_LOGGER_H_ #define __MAILCORE_CONNECTION_LOGGER_H_ +#include <stdlib.h> + #ifdef __cplusplus namespace mailcore { @@ -17,20 +19,24 @@ namespace mailcore { class String; enum ConnectionLogType { - ConnectionLogTypeGeneric, + // Received data ConnectionLogTypeReceived, + // Sent data ConnectionLogTypeSent, + // Sent private data ConnectionLogTypeSentPrivate, - ConnectionLogTypeErrorGeneric, + // Parse error + ConnectionLogTypeErrorParse, + // Error while receiving data - log() is called with a NULL buffer. ConnectionLogTypeErrorReceived, + // Error while sending data - log() is called with a NULL buffer. ConnectionLogTypeErrorSent, - ConnectionLogTypeErrorSentPrivate, }; class ConnectionLogger { public: - virtual void logBuffer(ConnectionLogType logType, Data * buffer) {} - virtual void logString(ConnectionLogType logType, String * log) {} + virtual void log(void * context, void * sender, ConnectionLogType logType, Data * buffer) {} + virtual void * context() { return NULL; } }; } diff --git a/src/core/basetypes/MCConnectionLoggerUtils.cc b/src/core/basetypes/MCConnectionLoggerUtils.cc index 669c8449..234713e7 100644 --- a/src/core/basetypes/MCConnectionLoggerUtils.cc +++ b/src/core/basetypes/MCConnectionLoggerUtils.cc @@ -14,21 +14,12 @@ mailcore::ConnectionLogType mailcore::getConnectionType(int log_type) { - ConnectionLogType type = ConnectionLogTypeGeneric; + ConnectionLogType type = (ConnectionLogType) -1; bool isBuffer = false; switch (log_type) { - case MAILSTREAM_LOG_TYPE_INFO_GENERIC: - type = ConnectionLogTypeGeneric; - break; - case MAILSTREAM_LOG_TYPE_INFO_RECEIVED: - type = ConnectionLogTypeReceived; - break; - case MAILSTREAM_LOG_TYPE_INFO_SENT: - type = ConnectionLogTypeSent; - break; - case MAILSTREAM_LOG_TYPE_ERROR_GENERIC: - type = ConnectionLogTypeErrorGeneric; + case MAILSTREAM_LOG_TYPE_ERROR_PARSE: + type = ConnectionLogTypeErrorParse; isBuffer = true; break; case MAILSTREAM_LOG_TYPE_ERROR_RECEIVED: @@ -60,9 +51,7 @@ bool mailcore::isBufferFromLogType(int log_type) bool isBuffer = false; switch (log_type) { - case MAILSTREAM_LOG_TYPE_ERROR_GENERIC: - case MAILSTREAM_LOG_TYPE_ERROR_RECEIVED: - case MAILSTREAM_LOG_TYPE_ERROR_SENT: + case MAILSTREAM_LOG_TYPE_ERROR_PARSE: case MAILSTREAM_LOG_TYPE_DATA_RECEIVED: case MAILSTREAM_LOG_TYPE_DATA_SENT: case MAILSTREAM_LOG_TYPE_DATA_SENT_PRIVATE: diff --git a/src/core/imap/MCIMAPSession.cc b/src/core/imap/MCIMAPSession.cc index 0b194ff7..9bd89f69 100644 --- a/src/core/imap/MCIMAPSession.cc +++ b/src/core/imap/MCIMAPSession.cc @@ -498,15 +498,17 @@ static void logger(mailimap * imap, int log_type, const char * buffer, size_t si return; ConnectionLogType type = getConnectionType(log_type); + if ((int) type == -1) + return; + bool isBuffer = isBufferFromLogType(log_type); if (isBuffer) { Data * data = Data::dataWithBytes(buffer, (unsigned int) size); - session->connectionLogger()->logBuffer(type, data); + session->connectionLogger()->log(session->connectionLogger()->context(), session, type, data); } else { - Data * data = Data::dataWithBytes(buffer, (unsigned int) size); - session->connectionLogger()->logString(type, String::stringWithData(data)); + session->connectionLogger()->log(session->connectionLogger()->context(), session, type, NULL); } } diff --git a/src/core/pop/MCPOPSession.cc b/src/core/pop/MCPOPSession.cc index fe15c500..9e771027 100644 --- a/src/core/pop/MCPOPSession.cc +++ b/src/core/pop/MCPOPSession.cc @@ -160,11 +160,10 @@ static void logger(mailpop3 * pop3, int log_type, const char * buffer, size_t si if (isBuffer) { Data * data = Data::dataWithBytes(buffer, (unsigned int) size); - session->connectionLogger()->logBuffer(type, data); + session->connectionLogger()->log(session->connectionLogger()->context(), session, type, data); } else { - Data * data = Data::dataWithBytes(buffer, (unsigned int) size); - session->connectionLogger()->logString(type, String::stringWithData(data)); + session->connectionLogger()->log(session->connectionLogger()->context(), session, type, NULL); } } diff --git a/src/core/smtp/MCSMTPSession.cc b/src/core/smtp/MCSMTPSession.cc index e74a540a..da2e19e5 100644 --- a/src/core/smtp/MCSMTPSession.cc +++ b/src/core/smtp/MCSMTPSession.cc @@ -164,7 +164,7 @@ void SMTPSession::bodyProgress(unsigned int current, unsigned int maximum) } -static void logger(mailsmtp * pop3, int log_type, const char * buffer, size_t size, void * context) +static void logger(mailsmtp * smtp, int log_type, const char * buffer, size_t size, void * context) { SMTPSession * session = (SMTPSession *) context; @@ -176,11 +176,10 @@ static void logger(mailsmtp * pop3, int log_type, const char * buffer, size_t si if (isBuffer) { Data * data = Data::dataWithBytes(buffer, (unsigned int) size); - session->connectionLogger()->logBuffer(type, data); + session->connectionLogger()->log(session->connectionLogger()->context(), session, type, data); } else { - Data * data = Data::dataWithBytes(buffer, (unsigned int) size); - session->connectionLogger()->logString(type, String::stringWithData(data)); + session->connectionLogger()->log(session->connectionLogger()->context(), session, type, NULL); } } |