aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/smtp
diff options
context:
space:
mode:
authorGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2013-06-25 01:31:06 -0700
committerGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2013-06-25 01:31:06 -0700
commit3473ed58a90b4b00cd4123722a37c1a87c8f2e55 (patch)
treebbef8676d16c6d62f15f050a9fdf74d5d27f56b4 /src/core/smtp
parent82acf0886ec1ae2a92d2a8f9a5a246e3bdc93f72 (diff)
Implement logging for src/core/
Diffstat (limited to 'src/core/smtp')
-rw-r--r--src/core/smtp/MCSMTPSession.cc39
-rw-r--r--src/core/smtp/MCSMTPSession.h137
2 files changed, 108 insertions, 68 deletions
diff --git a/src/core/smtp/MCSMTPSession.cc b/src/core/smtp/MCSMTPSession.cc
index ee225b16..e74a540a 100644
--- a/src/core/smtp/MCSMTPSession.cc
+++ b/src/core/smtp/MCSMTPSession.cc
@@ -8,6 +8,7 @@
#include "MCMessageParser.h"
#include "MCMessageHeader.h"
#include "MCSMTPProgressCallback.h"
+#include "MCConnectionLoggerUtils.h"
using namespace mailcore;
@@ -35,6 +36,7 @@ void SMTPSession::init()
mLastSMTPResponse = NULL;
mLastLibetpanError = 0;
mLastSMTPResponseCode = 0;
+ mConnectionLogger = NULL;
}
SMTPSession::SMTPSession()
@@ -161,11 +163,34 @@ 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)
+{
+ SMTPSession * session = (SMTPSession *) context;
+
+ if (session->connectionLogger() == NULL)
+ return;
+
+ ConnectionLogType type = getConnectionType(log_type);
+ bool isBuffer = isBufferFromLogType(log_type);
+
+ if (isBuffer) {
+ Data * data = Data::dataWithBytes(buffer, (unsigned int) size);
+ session->connectionLogger()->logBuffer(type, data);
+ }
+ else {
+ Data * data = Data::dataWithBytes(buffer, (unsigned int) size);
+ session->connectionLogger()->logString(type, String::stringWithData(data));
+ }
+}
+
+
void SMTPSession::setup()
{
- mSmtp = mailsmtp_new(0, NULL);
- mailsmtp_set_timeout(mSmtp, timeout());
+ mSmtp = mailsmtp_new(0, NULL);
+ mailsmtp_set_timeout(mSmtp, timeout());
mailsmtp_set_progress_callback(mSmtp, body_progress, this);
+ mailsmtp_set_logger(mSmtp, logger, this);
}
void SMTPSession::unsetup()
@@ -681,3 +706,13 @@ bool SMTPSession::isDisconnected()
{
return mState == STATE_DISCONNECTED;
}
+
+void SMTPSession::setConnectionLogger(ConnectionLogger * logger)
+{
+ mConnectionLogger = logger;
+}
+
+ConnectionLogger * SMTPSession::connectionLogger()
+{
+ return mConnectionLogger;
+}
diff --git a/src/core/smtp/MCSMTPSession.h b/src/core/smtp/MCSMTPSession.h
index 57c6e0ce..491ecb07 100644
--- a/src/core/smtp/MCSMTPSession.h
+++ b/src/core/smtp/MCSMTPSession.h
@@ -8,88 +8,93 @@
#ifdef __cplusplus
namespace mailcore {
-
- class Address;
- class SMTPProgressCallback;
- class MessageBuilder;
+
+ class Address;
+ class SMTPProgressCallback;
+ class MessageBuilder;
- class SMTPSession : public Object {
- public:
- SMTPSession();
- virtual ~SMTPSession();
-
- virtual void setHostname(String * hostname);
- virtual String * hostname();
+ class SMTPSession : public Object {
+ public:
+ SMTPSession();
+ virtual ~SMTPSession();
+
+ virtual void setHostname(String * hostname);
+ virtual String * hostname();
- virtual void setPort(unsigned int port);
- virtual unsigned int port();
+ virtual void setPort(unsigned int port);
+ virtual unsigned int port();
- virtual void setUsername(String * username);
- virtual String * username();
+ virtual void setUsername(String * username);
+ virtual String * username();
- virtual void setPassword(String * password);
- virtual String * password();
+ virtual void setPassword(String * password);
+ virtual String * password();
- virtual void setAuthType(AuthType authType);
- virtual AuthType authType();
+ virtual void setAuthType(AuthType authType);
+ virtual AuthType authType();
- virtual void setConnectionType(ConnectionType connectionType);
- virtual ConnectionType connectionType();
+ virtual void setConnectionType(ConnectionType connectionType);
+ virtual ConnectionType connectionType();
- virtual void setTimeout(time_t timeout);
- virtual time_t timeout();
-
- virtual void setCheckCertificateEnabled(bool enabled);
- virtual bool isCheckCertificateEnabled();
-
- virtual void setUseHeloIPEnabled(bool enabled);
- virtual bool useHeloIPEnabled();
-
- virtual void connect(ErrorCode * pError);
- virtual void disconnect();
-
- virtual void login(ErrorCode * pError);
-
+ virtual void setTimeout(time_t timeout);
+ virtual time_t timeout();
+
+ virtual void setCheckCertificateEnabled(bool enabled);
+ virtual bool isCheckCertificateEnabled();
+
+ virtual void setUseHeloIPEnabled(bool enabled);
+ virtual bool useHeloIPEnabled();
+
+ virtual void connect(ErrorCode * pError);
+ virtual void disconnect();
+
+ virtual void login(ErrorCode * pError);
+
virtual void checkAccount(Address * from, ErrorCode * pError);
- virtual void sendMessage(Data * messageData, SMTPProgressCallback * callback, ErrorCode * pError);
+ virtual void sendMessage(Data * messageData, SMTPProgressCallback * callback, ErrorCode * pError);
- private:
- String * mHostname;
- unsigned int mPort;
- String * mUsername;
- String * mPassword;
- AuthType mAuthType;
- ConnectionType mConnectionType;
- time_t mTimeout;
- bool mCheckCertificateEnabled;
- bool mUseHeloIPEnabled;
-
- mailsmtp * mSmtp;
- SMTPProgressCallback * mProgressCallback;
- int mState;
- String * mLastSMTPResponse;
+ virtual void setConnectionLogger(ConnectionLogger * logger);
+ virtual ConnectionLogger * connectionLogger();
+
+ private:
+ String * mHostname;
+ unsigned int mPort;
+ String * mUsername;
+ String * mPassword;
+ AuthType mAuthType;
+ ConnectionType mConnectionType;
+ time_t mTimeout;
+ bool mCheckCertificateEnabled;
+ bool mUseHeloIPEnabled;
+
+ mailsmtp * mSmtp;
+ SMTPProgressCallback * mProgressCallback;
+ int mState;
+ String * mLastSMTPResponse;
int mLastLibetpanError;
int mLastSMTPResponseCode;
-
- void init();
- Data * dataWithFilteredBcc(Data * data);
- static void body_progress(size_t current, size_t maximum, void * context);
- void bodyProgress(unsigned int current, unsigned int maximum);
- void setup();
- void unsetup();
- void connectIfNeeded(ErrorCode * pError);
- void loginIfNeeded(ErrorCode * pError);
- bool checkCertificate();
-
- void sendMessage(Address * from, Array * /* Address */ recipients, Data * messageData,
+
+ ConnectionLogger * mConnectionLogger;
+
+ void init();
+ Data * dataWithFilteredBcc(Data * data);
+ static void body_progress(size_t current, size_t maximum, void * context);
+ void bodyProgress(unsigned int current, unsigned int maximum);
+ void setup();
+ void unsetup();
+ void connectIfNeeded(ErrorCode * pError);
+ void loginIfNeeded(ErrorCode * pError);
+ bool checkCertificate();
+
+ void sendMessage(Address * from, Array * /* Address */ recipients, Data * messageData,
SMTPProgressCallback * callback, ErrorCode * pError);
- void sendMessage(MessageBuilder * msg, SMTPProgressCallback * callback, ErrorCode * pError);
+ void sendMessage(MessageBuilder * msg, SMTPProgressCallback * callback, ErrorCode * pError);
public: // private
virtual bool isDisconnected();
- };
-
+ };
+
}
#endif