aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/async/smtp/MCSMTPAsyncSession.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/async/smtp/MCSMTPAsyncSession.cc')
-rw-r--r--src/async/smtp/MCSMTPAsyncSession.cc57
1 files changed, 57 insertions, 0 deletions
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);
+}