aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/async/imap/MCIMAPAsyncConnection.cc
diff options
context:
space:
mode:
authorGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2013-06-26 01:37:52 -0700
committerGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2013-06-26 01:38:02 -0700
commit49eaf450344d73d815124bc343e92402dab5b7ab (patch)
treea7ceb39b05d7538ed85462ce459766cba508bce3 /src/async/imap/MCIMAPAsyncConnection.cc
parentfe9037f4248d50c35679cea5534d6ee87e71ede6 (diff)
Implement IMAP logger. Work in progress on POP and SMTP loggers.
Diffstat (limited to 'src/async/imap/MCIMAPAsyncConnection.cc')
-rw-r--r--src/async/imap/MCIMAPAsyncConnection.cc55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/async/imap/MCIMAPAsyncConnection.cc b/src/async/imap/MCIMAPAsyncConnection.cc
index 2891d439..5ea68794 100644
--- a/src/async/imap/MCIMAPAsyncConnection.cc
+++ b/src/async/imap/MCIMAPAsyncConnection.cc
@@ -33,6 +33,7 @@
#include "MCOperationQueueCallback.h"
#include "MCIMAPDisconnectOperation.h"
#include "MCIMAPAsyncSession.h"
+#include "MCConnectionLogger.h"
using namespace mailcore;
@@ -58,6 +59,24 @@ namespace mailcore {
private:
IMAPAsyncConnection * mConnection;
};
+
+ class IMAPConnectionLogger : public Object, public ConnectionLogger {
+ public:
+ IMAPConnectionLogger(IMAPAsyncConnection * connection) {
+ mConnection = connection;
+ }
+
+ virtual ~IMAPConnectionLogger() {
+ }
+
+ virtual void log(ConnectionLogType logType, Data * buffer)
+ {
+ mConnection->logConnection(logType, buffer);
+ }
+
+ private:
+ IMAPAsyncConnection * mConnection;
+ };
}
IMAPAsyncConnection::IMAPAsyncConnection()
@@ -70,11 +89,16 @@ IMAPAsyncConnection::IMAPAsyncConnection()
mQueueCallback = new IMAPOperationQueueCallback(this);
mQueue->setCallback(mQueueCallback);
mOwner = NULL;
+ mConnectionLogger = NULL;
+ pthread_mutex_init(&mConnectionLoggerLock, NULL);
+ mInternalLogger = new IMAPConnectionLogger(this);
}
IMAPAsyncConnection::~IMAPAsyncConnection()
{
cancelDelayedPerformMethod((Object::Method) &IMAPAsyncConnection::tryAutomaticDisconnectAfterDelay, NULL);
+ pthread_mutex_destroy(&mConnectionLoggerLock);
+ MC_SAFE_RELEASE(mInternalLogger);
MC_SAFE_RELEASE(mQueueCallback);
MC_SAFE_RELEASE(mLastFolder);
MC_SAFE_RELEASE(mDefaultNamespace);
@@ -526,4 +550,35 @@ IMAPAsyncSession * IMAPAsyncConnection::owner()
return mOwner;
}
+void IMAPAsyncConnection::setConnectionLogger(ConnectionLogger * logger)
+{
+ pthread_mutex_lock(&mConnectionLoggerLock);
+ mConnectionLogger = logger;
+ if (mConnectionLogger != NULL) {
+ mSession->setConnectionLogger(mInternalLogger);
+ }
+ else {
+ mSession->setConnectionLogger(NULL);
+ }
+ pthread_mutex_unlock(&mConnectionLoggerLock);
+}
+
+ConnectionLogger * IMAPAsyncConnection::connectionLogger()
+{
+ ConnectionLogger * result;
+
+ pthread_mutex_lock(&mConnectionLoggerLock);
+ result = mConnectionLogger;
+ pthread_mutex_unlock(&mConnectionLoggerLock);
+
+ return result;
+}
+void IMAPAsyncConnection::logConnection(ConnectionLogType logType, Data * buffer)
+{
+ pthread_mutex_lock(&mConnectionLoggerLock);
+ if (mConnectionLogger != NULL) {
+ mConnectionLogger->log(mConnectionLogger->context(), this, logType, buffer);
+ }
+ pthread_mutex_unlock(&mConnectionLoggerLock);
+}