diff options
author | Hoa V. DINH <dinh.viet.hoa@gmail.com> | 2016-03-03 22:45:19 -0800 |
---|---|---|
committer | Hoa V. DINH <dinh.viet.hoa@gmail.com> | 2016-03-03 22:45:19 -0800 |
commit | a55c8f370bd663ea1d31fed230987711aa1cf176 (patch) | |
tree | 567a995e2f0565d24aebff0fab959d3c95045670 /src/core/provider | |
parent | 886aae2ab94c74a4d4c644c446f67d37a333c1f9 (diff) |
Thread safety on logger
Diffstat (limited to 'src/core/provider')
-rw-r--r-- | src/core/provider/MCAccountValidator.cpp | 43 | ||||
-rw-r--r-- | src/core/provider/MCAccountValidator.h | 13 |
2 files changed, 51 insertions, 5 deletions
diff --git a/src/core/provider/MCAccountValidator.cpp b/src/core/provider/MCAccountValidator.cpp index 59538c72..1e6ebdd9 100644 --- a/src/core/provider/MCAccountValidator.cpp +++ b/src/core/provider/MCAccountValidator.cpp @@ -64,6 +64,9 @@ void AccountValidator::init() mImapEnabled = false; mPopEnabled = false; mSmtpEnabled = false; + + mConnectionLogger = NULL; + pthread_mutex_init(&mConnectionLoggerLock, NULL); } AccountValidator::AccountValidator() @@ -73,6 +76,7 @@ AccountValidator::AccountValidator() AccountValidator::~AccountValidator() { + pthread_mutex_destroy(&mConnectionLoggerLock); MC_SAFE_RELEASE(mEmail); MC_SAFE_RELEASE(mUsername); MC_SAFE_RELEASE(mPassword); @@ -250,6 +254,7 @@ void AccountValidator::checkNextHost() mImapSession->setHostname(mImapServer->hostname()); mImapSession->setPort(mImapServer->port()); mImapSession->setConnectionType(mImapServer->connectionType()); + mImapSession->setConnectionLogger(this); mOperation = (IMAPOperation *)mImapSession->checkAccountOperation(); mOperation->retain(); @@ -271,12 +276,13 @@ void AccountValidator::checkNextHost() mPopSession = new POPAsyncSession(); mPopSession->setUsername(mUsername); mPopSession->setPassword(mPassword); - + mPopServer = (NetService *) mPopServices->objectAtIndex(mCurrentServiceIndex); mPopSession->setHostname(mPopServer->hostname()); mPopSession->setPort(mPopServer->port()); mPopSession->setConnectionType(mPopServer->connectionType()); - + mPopSession->setConnectionLogger(this); + mOperation = mPopSession->checkAccountOperation(); mOperation->retain(); mOperation->setCallback(this); @@ -306,7 +312,8 @@ void AccountValidator::checkNextHost() mSmtpSession->setHostname(mSmtpServer->hostname()); mSmtpSession->setPort(mSmtpServer->port()); mSmtpSession->setConnectionType(mSmtpServer->connectionType()); - + mSmtpSession->setConnectionLogger(this); + mOperation = mSmtpSession->checkAccountOperation(Address::addressWithMailbox(mEmail)); mOperation->retain(); mOperation->setCallback(this); @@ -334,16 +341,19 @@ void AccountValidator::checkNextHostDone() if (mCurrentServiceTested == SERVICE_IMAP) { mImapError = ((IMAPOperation *)mOperation)->error(); error = mImapError; + mImapSession->setConnectionLogger(NULL); MC_SAFE_RELEASE(mImapSession); } else if (mCurrentServiceTested == SERVICE_POP) { mPopError = ((POPOperation *)mOperation)->error(); error = mPopError; + mPopSession->setConnectionLogger(NULL); MC_SAFE_RELEASE(mPopSession); } else if (mCurrentServiceTested == SERVICE_SMTP) { mSmtpError = ((SMTPOperation *)mOperation)->error(); error = mSmtpError; + mSmtpSession->setConnectionLogger(NULL); MC_SAFE_RELEASE(mSmtpSession); } @@ -495,3 +505,30 @@ ErrorCode AccountValidator::smtpError() { return mSmtpError; } + +void AccountValidator::setConnectionLogger(ConnectionLogger * logger) +{ + pthread_mutex_lock(&mConnectionLoggerLock); + mConnectionLogger = logger; + pthread_mutex_unlock(&mConnectionLoggerLock); +} + +ConnectionLogger * AccountValidator::connectionLogger() +{ + ConnectionLogger * result; + + pthread_mutex_lock(&mConnectionLoggerLock); + result = mConnectionLogger; + pthread_mutex_unlock(&mConnectionLoggerLock); + + return result; +} + +void AccountValidator::log(void * sender, ConnectionLogType logType, Data * buffer) +{ + pthread_mutex_lock(&mConnectionLoggerLock); + if (mConnectionLogger != NULL) { + mConnectionLogger->log(this, logType, buffer); + } + pthread_mutex_unlock(&mConnectionLoggerLock); +} diff --git a/src/core/provider/MCAccountValidator.h b/src/core/provider/MCAccountValidator.h index 436317cf..788458b6 100644 --- a/src/core/provider/MCAccountValidator.h +++ b/src/core/provider/MCAccountValidator.h @@ -23,7 +23,7 @@ namespace mailcore { class POPAsyncSession; class SMTPAsyncSession; - class MAILCORE_EXPORT AccountValidator : public Operation, public OperationCallback { + class MAILCORE_EXPORT AccountValidator : public Operation, public OperationCallback, public ConnectionLogger { public: AccountValidator(); virtual ~AccountValidator(); @@ -53,6 +53,9 @@ namespace mailcore { virtual void setPopServices(Array * popServices); virtual Array * /* NetService */ popServices(); + virtual void setConnectionLogger(ConnectionLogger * logger); + virtual ConnectionLogger * connectionLogger(); + // result virtual String * identifier(); virtual NetService * imapServer(); @@ -64,7 +67,10 @@ namespace mailcore { virtual void start(); virtual void cancel(); - + + public: // ConnectionLogger + virtual void log(void * sender, ConnectionLogType logType, Data * buffer); + private: String * mEmail; /* for SMTP */ String * mUsername; @@ -104,6 +110,9 @@ namespace mailcore { bool mPopEnabled; bool mSmtpEnabled; + pthread_mutex_t mConnectionLoggerLock; + ConnectionLogger * mConnectionLogger; + void init(); void setupServices(); void resolveMX(); |