aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2013-06-26 02:35:34 -0700
committerGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2013-06-26 02:35:34 -0700
commite8649c3ecfc093e379439aa4e88910b3dc27422e (patch)
tree296c456f51d43b8f4fc2184045aea3de16502f0f
parent74558e034a096331841a0327a48fdfc5ab095ec6 (diff)
Logger API for SMTP, POP
-rw-r--r--src/async/imap/MCIMAPAsyncConnection.cc2
-rw-r--r--src/async/imap/MCIMAPAsyncSession.h1
-rw-r--r--src/async/pop/MCPOPAsyncSession.cc58
-rw-r--r--src/async/pop/MCPOPAsyncSession.h9
-rw-r--r--src/async/smtp/MCSMTPAsyncSession.cc57
-rw-r--r--src/async/smtp/MCSMTPAsyncSession.h10
6 files changed, 133 insertions, 4 deletions
diff --git a/src/async/imap/MCIMAPAsyncConnection.cc b/src/async/imap/MCIMAPAsyncConnection.cc
index 5ea68794..5753726a 100644
--- a/src/async/imap/MCIMAPAsyncConnection.cc
+++ b/src/async/imap/MCIMAPAsyncConnection.cc
@@ -69,7 +69,7 @@ namespace mailcore {
virtual ~IMAPConnectionLogger() {
}
- virtual void log(ConnectionLogType logType, Data * buffer)
+ virtual void log(void * context, void * sender, ConnectionLogType logType, Data * buffer)
{
mConnection->logConnection(logType, buffer);
}
diff --git a/src/async/imap/MCIMAPAsyncSession.h b/src/async/imap/MCIMAPAsyncSession.h
index eae6ea15..d7f95407 100644
--- a/src/async/imap/MCIMAPAsyncSession.h
+++ b/src/async/imap/MCIMAPAsyncSession.h
@@ -33,7 +33,6 @@ namespace mailcore {
class IMAPIdentityOperation;
class IMAPAsyncConnection;
class IMAPCapabilityOperation;
- class ConnectionLogger;
class IMAPAsyncSession : public Object {
public:
diff --git a/src/async/pop/MCPOPAsyncSession.cc b/src/async/pop/MCPOPAsyncSession.cc
index 1269a34b..d72da0b3 100644
--- a/src/async/pop/MCPOPAsyncSession.cc
+++ b/src/async/pop/MCPOPAsyncSession.cc
@@ -15,6 +15,7 @@
#include "MCPOPFetchMessagesOperation.h"
#include "MCPOPCheckAccountOperation.h"
#include "MCOperationQueueCallback.h"
+#include "MCConnectionLogger.h"
using namespace mailcore;
@@ -39,6 +40,24 @@ namespace mailcore {
private:
POPAsyncSession * mSession;
};
+
+ class POPConnectionLogger : public Object, public ConnectionLogger {
+ public:
+ POPConnectionLogger(POPAsyncSession * session) {
+ mSession = session;
+ }
+
+ virtual ~POPConnectionLogger() {
+ }
+
+ virtual void log(void * context, void * sender, ConnectionLogType logType, Data * buffer)
+ {
+ mSession->logConnection(logType, buffer);
+ }
+
+ private:
+ POPAsyncSession * mSession;
+ };
}
POPAsyncSession::POPAsyncSession()
@@ -47,10 +66,16 @@ POPAsyncSession::POPAsyncSession()
mQueue = new OperationQueue();
mQueueCallback = new POPOperationQueueCallback(this);
mQueue->setCallback(mQueueCallback);
+ mConnectionLogger = NULL;
+ pthread_mutex_init(&mConnectionLoggerLock, NULL);
+ mInternalLogger = new POPConnectionLogger(this);
+ mSession->setConnectionLogger(mInternalLogger);
}
POPAsyncSession::~POPAsyncSession()
{
+ MC_SAFE_RELEASE(mInternalLogger);
+ pthread_mutex_destroy(&mConnectionLoggerLock);
MC_SAFE_RELEASE(mQueueCallback);
MC_SAFE_RELEASE(mSession);
MC_SAFE_RELEASE(mQueue);
@@ -193,3 +218,36 @@ void POPAsyncSession::runOperation(POPOperation * operation)
{
mQueue->addOperation(operation);
}
+
+void POPAsyncSession::setConnectionLogger(ConnectionLogger * logger)
+{
+ pthread_mutex_lock(&mConnectionLoggerLock);
+ mConnectionLogger = logger;
+ if (mConnectionLogger != NULL) {
+ mSession->setConnectionLogger(mInternalLogger);
+ }
+ else {
+ mSession->setConnectionLogger(NULL);
+ }
+ pthread_mutex_unlock(&mConnectionLoggerLock);
+}
+
+ConnectionLogger * POPAsyncSession::connectionLogger()
+{
+ ConnectionLogger * result;
+
+ pthread_mutex_lock(&mConnectionLoggerLock);
+ result = mConnectionLogger;
+ pthread_mutex_unlock(&mConnectionLoggerLock);
+
+ return result;
+}
+
+void POPAsyncSession::logConnection(ConnectionLogType logType, Data * buffer)
+{
+ pthread_mutex_lock(&mConnectionLoggerLock);
+ if (mConnectionLogger != NULL) {
+ mConnectionLogger->log(mConnectionLogger->context(), this, logType, buffer);
+ }
+ pthread_mutex_unlock(&mConnectionLoggerLock);
+}
diff --git a/src/async/pop/MCPOPAsyncSession.h b/src/async/pop/MCPOPAsyncSession.h
index 452d4d75..0345ecd6 100644
--- a/src/async/pop/MCPOPAsyncSession.h
+++ b/src/async/pop/MCPOPAsyncSession.h
@@ -23,6 +23,7 @@ namespace mailcore {
class POPDeleteMessagesOperation;
class POPFetchMessagesOperation;
class POPOperationQueueCallback;
+ class POPConnectionLogger;
class POPAsyncSession : public Object {
public:
@@ -53,6 +54,9 @@ namespace mailcore {
virtual void setCheckCertificateEnabled(bool enabled);
virtual bool isCheckCertificateEnabled();
+ virtual void setConnectionLogger(ConnectionLogger * logger);
+ virtual ConnectionLogger * connectionLogger();
+
virtual POPFetchMessagesOperation * fetchMessagesOperation();
virtual POPFetchHeaderOperation * fetchHeaderOperation(unsigned int index);
@@ -70,11 +74,14 @@ namespace mailcore {
POPSession * mSession;
OperationQueue * mQueue;
POPOperationQueueCallback * mQueueCallback;
+ ConnectionLogger * mConnectionLogger;
+ pthread_mutex_t mConnectionLoggerLock;
+ POPConnectionLogger * mInternalLogger;
public: // private
virtual void runOperation(POPOperation * operation);
virtual POPSession * session();
-
+ virtual void logConnection(ConnectionLogType logType, Data * buffer);
};
}
diff --git a/src/async/smtp/MCSMTPAsyncSession.cc b/src/async/smtp/MCSMTPAsyncSession.cc
index 723c0330..c1ff90c9 100644
--- a/src/async/smtp/MCSMTPAsyncSession.cc
+++ b/src/async/smtp/MCSMTPAsyncSession.cc
@@ -31,6 +31,24 @@ namespace mailcore {
private:
SMTPAsyncSession * mSession;
};
+
+ class SMTPConnectionLogger : public Object, public ConnectionLogger {
+ public:
+ SMTPConnectionLogger(SMTPAsyncSession * session) {
+ mSession = session;
+ }
+
+ virtual ~SMTPConnectionLogger() {
+ }
+
+ virtual void log(void * context, void * sender, ConnectionLogType logType, Data * buffer)
+ {
+ mSession->logConnection(logType, buffer);
+ }
+
+ private:
+ SMTPAsyncSession * mSession;
+ };
}
SMTPAsyncSession::SMTPAsyncSession()
@@ -39,10 +57,16 @@ SMTPAsyncSession::SMTPAsyncSession()
mQueue = new OperationQueue();
mQueueCallback = new SMTPOperationQueueCallback(this);
mQueue->setCallback(mQueueCallback);
+ mConnectionLogger = NULL;
+ pthread_mutex_init(&mConnectionLoggerLock, NULL);
+ mInternalLogger = new SMTPConnectionLogger(this);
+ mSession->setConnectionLogger(mInternalLogger);
}
SMTPAsyncSession::~SMTPAsyncSession()
{
+ MC_SAFE_RELEASE(mInternalLogger);
+ pthread_mutex_destroy(&mConnectionLoggerLock);
cancelDelayedPerformMethod((Object::Method) &SMTPAsyncSession::tryAutomaticDisconnectAfterDelay, NULL);
MC_SAFE_RELEASE(mQueueCallback);
MC_SAFE_RELEASE(mQueue);
@@ -184,3 +208,36 @@ SMTPOperation * SMTPAsyncSession::checkAccountOperation(Address * from)
op->setSession(this);
return (SMTPOperation *) op->autorelease();
}
+
+void SMTPAsyncSession::setConnectionLogger(ConnectionLogger * logger)
+{
+ pthread_mutex_lock(&mConnectionLoggerLock);
+ mConnectionLogger = logger;
+ if (mConnectionLogger != NULL) {
+ mSession->setConnectionLogger(mInternalLogger);
+ }
+ else {
+ mSession->setConnectionLogger(NULL);
+ }
+ pthread_mutex_unlock(&mConnectionLoggerLock);
+}
+
+ConnectionLogger * SMTPAsyncSession::connectionLogger()
+{
+ ConnectionLogger * result;
+
+ pthread_mutex_lock(&mConnectionLoggerLock);
+ result = mConnectionLogger;
+ pthread_mutex_unlock(&mConnectionLoggerLock);
+
+ return result;
+}
+
+void SMTPAsyncSession::logConnection(ConnectionLogType logType, Data * buffer)
+{
+ pthread_mutex_lock(&mConnectionLoggerLock);
+ if (mConnectionLogger != NULL) {
+ mConnectionLogger->log(mConnectionLogger->context(), this, logType, buffer);
+ }
+ pthread_mutex_unlock(&mConnectionLoggerLock);
+}
diff --git a/src/async/smtp/MCSMTPAsyncSession.h b/src/async/smtp/MCSMTPAsyncSession.h
index 9cd7a8f0..9fa6dbdf 100644
--- a/src/async/smtp/MCSMTPAsyncSession.h
+++ b/src/async/smtp/MCSMTPAsyncSession.h
@@ -14,6 +14,7 @@ namespace mailcore {
class SMTPSession;
class Address;
class SMTPOperationQueueCallback;
+ class SMTPConnectionLogger;
class SMTPAsyncSession : public Object {
public:
@@ -47,6 +48,9 @@ namespace mailcore {
virtual void setUseHeloIPEnabled(bool enabled);
virtual bool useHeloIPEnabled();
+ virtual void setConnectionLogger(ConnectionLogger * logger);
+ virtual ConnectionLogger * connectionLogger();
+
virtual SMTPOperation * sendMessageOperation(Data * messageData);
virtual SMTPOperation * checkAccountOperation(Address * from);
@@ -54,11 +58,15 @@ namespace mailcore {
virtual void runOperation(SMTPOperation * operation);
virtual SMTPSession * session();
virtual void tryAutomaticDisconnect();
-
+ virtual void logConnection(ConnectionLogType logType, Data * buffer);
+
private:
SMTPSession * mSession;
OperationQueue * mQueue;
SMTPOperationQueueCallback * mQueueCallback;
+ ConnectionLogger * mConnectionLogger;
+ pthread_mutex_t mConnectionLoggerLock;
+ SMTPConnectionLogger * mInternalLogger;
virtual void tryAutomaticDisconnectAfterDelay(void * context);
};