diff options
Diffstat (limited to 'src/async/smtp/MCSMTPAsyncSession.cc')
-rw-r--r-- | src/async/smtp/MCSMTPAsyncSession.cc | 61 |
1 files changed, 59 insertions, 2 deletions
diff --git a/src/async/smtp/MCSMTPAsyncSession.cc b/src/async/smtp/MCSMTPAsyncSession.cc index 723c0330..fafc2e82 100644 --- a/src/async/smtp/MCSMTPAsyncSession.cc +++ b/src/async/smtp/MCSMTPAsyncSession.cc @@ -19,11 +19,11 @@ namespace mailcore { virtual ~SMTPOperationQueueCallback() { } - virtual void queueStartRunning() { + virtual void queueStartRunning(OperationQueue * queue) { mSession->retain(); } - virtual void queueStoppedRunning() { + virtual void queueStoppedRunning(OperationQueue * queue) { mSession->tryAutomaticDisconnect(); mSession->release(); } @@ -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(this, logType, buffer); + } + pthread_mutex_unlock(&mConnectionLoggerLock); +} |