From 5405330587d30cbd68908c1a5de233653e8e0d69 Mon Sep 17 00:00:00 2001 From: CodaFi Date: Sun, 23 Jun 2013 20:08:26 -0600 Subject: Updated to reflect dylib copy instructions --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 464b1759..324a43fc 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,9 @@ MailCore 2 provides a simple and asynchronous Objective-C API to work with the e - Go to Build Phases from your build target, and under 'Link Binary With Libraries', add `MailCore.framework`. - Make sure to use LLVM C++ standard library. Open Build Settings, scroll down to 'C++ Standard Library', and select `libc++`. - In Build Phases, add a Target Dependency of `mailcore osx` (it's the one with a little toolbox icon). + - Goto `Editor > Add Build Phase > Copy Files`. + - Expand the newly created Build Phase and change it's destination to "Frameworks". + - Click the `+` icon and select `MailCore.framework`. * Mac static library - Go to Build Phases from your build target, and under 'Link Binary With Libraries', add `libMailCore.a`. - Set 'Other Linker Flags' under Build Settings: `-lctemplate -letpan -licudata -licui18n -licuuc -lxml2 -lsasl2 -liconv -ltidy` `-lc++ -stdlib=libc++ -all_load` -- cgit v1.2.3 From 912e158e08cc45a2204977e4f8ebc58f07730c0b Mon Sep 17 00:00:00 2001 From: "Hoa V. DINH" Date: Mon, 24 Jun 2013 08:36:32 -0700 Subject: Fixed crash when a method is scheduled twice to perform after delay. Fixed #149. --- src/async/imap/MCIMAPAsyncConnection.cc | 1 + src/async/smtp/MCSMTPAsyncSession.cc | 1 + src/core/basetypes/MCOperationQueue.cc | 1 + 3 files changed, 3 insertions(+) diff --git a/src/async/imap/MCIMAPAsyncConnection.cc b/src/async/imap/MCIMAPAsyncConnection.cc index ed40932c..2891d439 100644 --- a/src/async/imap/MCIMAPAsyncConnection.cc +++ b/src/async/imap/MCIMAPAsyncConnection.cc @@ -482,6 +482,7 @@ void IMAPAsyncConnection::tryAutomaticDisconnect() return; } + cancelDelayedPerformMethod((Object::Method) &IMAPAsyncConnection::tryAutomaticDisconnectAfterDelay, NULL); performMethodAfterDelay((Object::Method) &IMAPAsyncConnection::tryAutomaticDisconnectAfterDelay, NULL, 30); } diff --git a/src/async/smtp/MCSMTPAsyncSession.cc b/src/async/smtp/MCSMTPAsyncSession.cc index 73bc2a54..723c0330 100644 --- a/src/async/smtp/MCSMTPAsyncSession.cc +++ b/src/async/smtp/MCSMTPAsyncSession.cc @@ -157,6 +157,7 @@ void SMTPAsyncSession::tryAutomaticDisconnect() return; } + cancelDelayedPerformMethod((Object::Method) &SMTPAsyncSession::tryAutomaticDisconnectAfterDelay, NULL); performMethodAfterDelay((Object::Method) &SMTPAsyncSession::tryAutomaticDisconnectAfterDelay, NULL, 30); } diff --git a/src/core/basetypes/MCOperationQueue.cc b/src/core/basetypes/MCOperationQueue.cc index e448c237..666758cc 100644 --- a/src/core/basetypes/MCOperationQueue.cc +++ b/src/core/basetypes/MCOperationQueue.cc @@ -127,6 +127,7 @@ void OperationQueue::callbackOnMainThread(Operation * op) void OperationQueue::checkRunningOnMainThread(void * context) { + cancelDelayedPerformMethod((Object::Method) &OperationQueue::checkRunningAfterDelay, NULL); performMethodAfterDelay((Object::Method) &OperationQueue::checkRunningAfterDelay, NULL, 1); } -- cgit v1.2.3 From 876a84992ad13848a9f77d2f0cd4a8c8d3c0b75a Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Mon, 24 Jun 2013 09:33:18 -0700 Subject: Fix for MCMessageBuilder copy constructor Fix for HTML body being overwritten with text body. --- src/core/rfc822/MCMessageBuilder.cc | 2 +- tests/test-all.mm | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/core/rfc822/MCMessageBuilder.cc b/src/core/rfc822/MCMessageBuilder.cc index 435557db..ea449fd6 100644 --- a/src/core/rfc822/MCMessageBuilder.cc +++ b/src/core/rfc822/MCMessageBuilder.cc @@ -478,7 +478,7 @@ MessageBuilder::MessageBuilder(MessageBuilder * other) { init(); setHTMLBody(other->mHTMLBody); - setHTMLBody(other->mTextBody); + setTextBody(other->mTextBody); setAttachments(other->mAttachments); setRelatedAttachments(other->mRelatedAttachments); MC_SAFE_REPLACE_COPY(String, mBoundaryPrefix, other->mBoundaryPrefix); diff --git a/tests/test-all.mm b/tests/test-all.mm index cfa37b66..2201d6d5 100644 --- a/tests/test-all.mm +++ b/tests/test-all.mm @@ -67,7 +67,13 @@ static mailcore::Data * testMessageBuilder() MCLog("%s", data->bytes()); + mailcore::MessageBuilder * msg2 = new mailcore::MessageBuilder(msg); + mailcore::String *htmlBody = msg->htmlBody(); + mailcore::String *htmlBody2 = msg2->htmlBody(); + MCAssert(htmlBody->isEqual(htmlBody2)); + msg->release(); + msg2->release(); return data; } -- cgit v1.2.3 From 1c901d081ef98777c28241aa6443f95302ee94f1 Mon Sep 17 00:00:00 2001 From: "Hoa V. DINH" Date: Mon, 24 Jun 2013 21:19:38 -0700 Subject: Fixed crash in performMethodAfterDelay. Fixed #149. --- src/core/basetypes/MCMainThread.mm | 87 +++++++++++++++++++++++++--------- src/core/basetypes/MCOperationQueue.cc | 2 +- 2 files changed, 65 insertions(+), 24 deletions(-) diff --git a/src/core/basetypes/MCMainThread.mm b/src/core/basetypes/MCMainThread.mm index 4e9c6fc7..8ecb7cae 100644 --- a/src/core/basetypes/MCMainThread.mm +++ b/src/core/basetypes/MCMainThread.mm @@ -6,15 +6,20 @@ using namespace mailcore; +static void destroyDelayedCall(void * caller); + @interface LEPPPMainThreadCaller : NSObject { - void (* _function)(void *); - void * _context; + void (* _function)(void *); + void * _context; + NSTimer * _timer; } @property (nonatomic, assign) void (* function)(void *); @property (nonatomic, assign) void * context; +@property (nonatomic, retain) NSTimer * timer; - (void) call; +- (void) cancel; @end @@ -22,48 +27,84 @@ using namespace mailcore; @synthesize function = _function; @synthesize context = _context; +@synthesize timer = _timer; + +- (id) init +{ + self = [super init]; + return self; +} + +- (void) dealloc +{ + [_timer release]; + [super dealloc]; +} - (void) call { AutoreleasePool * pool = new AutoreleasePool(); - _function(_context); + _function(_context); pool->release(); + + [self setTimer:nil]; + + destroyDelayedCall((void *) self); +} + +- (void) cancel +{ + [_timer invalidate]; + [self setTimer:nil]; + destroyDelayedCall((void *) self); } @end void mailcore::callOnMainThread(void (* function)(void *), void * context) { - LEPPPMainThreadCaller * caller; - caller = [[LEPPPMainThreadCaller alloc] init]; - [caller setFunction:function]; - [caller setContext:context]; - [caller performSelectorOnMainThread:@selector(call) withObject:nil waitUntilDone:NO]; - [caller release]; + LEPPPMainThreadCaller * caller; + caller = [[LEPPPMainThreadCaller alloc] init]; + [caller setFunction:function]; + [caller setContext:context]; + [caller performSelectorOnMainThread:@selector(call) withObject:nil waitUntilDone:NO]; + //[caller release]; } void mailcore::callOnMainThreadAndWait(void (* function)(void *), void * context) { - LEPPPMainThreadCaller * caller; - caller = [[LEPPPMainThreadCaller alloc] init]; - [caller setFunction:function]; - [caller setContext:context]; - [caller performSelectorOnMainThread:@selector(call) withObject:nil waitUntilDone:YES]; - [caller release]; + LEPPPMainThreadCaller * caller; + caller = [[LEPPPMainThreadCaller alloc] init]; + [caller setFunction:function]; + [caller setContext:context]; + [caller performSelectorOnMainThread:@selector(call) withObject:nil waitUntilDone:YES]; + //[caller release]; } void * mailcore::callAfterDelay(void (* function)(void *), void * context, double time) { - LEPPPMainThreadCaller * caller; - caller = [[LEPPPMainThreadCaller alloc] init]; - [caller setFunction:function]; - [caller setContext:context]; - [caller performSelector:@selector(call) withObject:nil afterDelay:time]; - return [caller autorelease]; + LEPPPMainThreadCaller * caller; + caller = [[LEPPPMainThreadCaller alloc] init]; + [caller setFunction:function]; + [caller setContext:context]; + + NSTimer * timer = [NSTimer scheduledTimerWithTimeInterval:(NSTimeInterval) time + target:caller + selector:@selector(call) + userInfo:nil + repeats:NO]; + [caller setTimer:timer]; + + return caller; +} + +static void destroyDelayedCall(void * caller) +{ + [(LEPPPMainThreadCaller *) caller release]; } void mailcore::cancelDelayedCall(void * delayedCall) { - LEPPPMainThreadCaller * caller = (LEPPPMainThreadCaller *) delayedCall; - [NSObject cancelPreviousPerformRequestsWithTarget:caller selector:@selector(call) object:nil]; + LEPPPMainThreadCaller * caller = (LEPPPMainThreadCaller *) delayedCall; + [caller cancel]; } diff --git a/src/core/basetypes/MCOperationQueue.cc b/src/core/basetypes/MCOperationQueue.cc index 666758cc..d4529fab 100644 --- a/src/core/basetypes/MCOperationQueue.cc +++ b/src/core/basetypes/MCOperationQueue.cc @@ -72,7 +72,7 @@ void OperationQueue::runOperations() quitting = mQuitting; pthread_mutex_unlock(&mLock); - MCLog("quitting %i %p", mQuitting, op); + //MCLog("quitting %i %p", mQuitting, op); if ((op == NULL) && quitting) { MCLog("stopping %p", this); mailsem_up(mStopSem); -- cgit v1.2.3 From 94f9c0b2a7ab86c4d4687b3d132b870b5f9f3bb8 Mon Sep 17 00:00:00 2001 From: "Hoa V. DINH" Date: Tue, 25 Jun 2013 01:02:33 -0700 Subject: Improved dependencies fetching. --- scripts/get-prebuilt.sh | 46 +++++++++++++++++++++++++++++---------- scripts/prepare-libetpan-ios.sh | 2 +- scripts/prepare-libetpan-macos.sh | 2 +- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/scripts/get-prebuilt.sh b/scripts/get-prebuilt.sh index 75eccb45..3bfb244a 100755 --- a/scripts/get-prebuilt.sh +++ b/scripts/get-prebuilt.sh @@ -1,18 +1,42 @@ #!/bin/sh +url_prefix="https://github.com/MailCore/mailcore2-deps/raw/master" + if test x$1 != xskipprebuilt ; then - if test ! -d ../Externals/prebuilt ; then - mkdir -p ../Externals/builds/builds - mkdir -p ../Externals/prebuilt - pushd ../Externals/prebuilt - if test -d mailcore2-deps ; then - cd mailcore2-deps - git pull --rebase - cd .. - else - git clone --depth=1 https://github.com/MailCore/mailcore2-deps.git + file_timestamp=0 + if test -f prebuilt.list ; then + file_timestamp=`stat -f '%m' prebuilt.list` + fi + timestamp=`ruby -e 'puts Time.now.to_i'` + age=$((($timestamp-$file_timestamp)/3600)) # in hours + if test $age -gt 0 ; then + networkerror=no + #echo "$url_prefix/prebuilt.list" + curl -s -L "$url_prefix/prebuilt.list" > prebuilt.list.tmp + if test x$? != x0 ; then + networkerror=yes fi - cp mailcore2-deps/*.zip ../builds/builds + + if test x$networkerror = xyes ; then + echo WARNING: could not get prebuilt.list from repository + fi + + mv prebuilt.list.tmp prebuilt.list + fi + + if test -f prebuilt.list ; then + files=`cat prebuilt.list` + mkdir -p ../Externals/builds/builds + mkdir -p ../Externals/prebuilt/mailcore2-deps + pushd ../Externals/prebuilt/mailcore2-deps + rm -rf .git + for filename in $files ; do + if test ! -f $filename ; then + echo get $filename + curl -O "$url_prefix/$filename" + fi + done + rsync --exclude=.git -av ./ ../../builds/builds/ popd fi fi diff --git a/scripts/prepare-libetpan-ios.sh b/scripts/prepare-libetpan-ios.sh index e7ed4928..5ab8a8a6 100755 --- a/scripts/prepare-libetpan-ios.sh +++ b/scripts/prepare-libetpan-ios.sh @@ -2,7 +2,7 @@ sdkversion=6.1 url="https://github.com/dinhviethoa/libetpan.git" -rev=349d184dcf2008ee7b5396743580e32b3bf65689 +rev=fb889b032d5a5f7e7178a038918bcdcd5d19d6ec pushd `dirname $0` > /dev/null scriptpath=`pwd` diff --git a/scripts/prepare-libetpan-macos.sh b/scripts/prepare-libetpan-macos.sh index 3854ef22..1972bf84 100755 --- a/scripts/prepare-libetpan-macos.sh +++ b/scripts/prepare-libetpan-macos.sh @@ -1,7 +1,7 @@ #!/bin/sh url="https://github.com/dinhviethoa/libetpan.git" -rev=349d184dcf2008ee7b5396743580e32b3bf65689 +rev=fb889b032d5a5f7e7178a038918bcdcd5d19d6ec pushd `dirname $0` > /dev/null scriptpath=`pwd` -- cgit v1.2.3 From 82acf0886ec1ae2a92d2a8f9a5a246e3bdc93f72 Mon Sep 17 00:00:00 2001 From: "Hoa V. DINH" Date: Tue, 25 Jun 2013 01:04:28 -0700 Subject: Fixed fetch of dependencies. --- scripts/get-prebuilt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/get-prebuilt.sh b/scripts/get-prebuilt.sh index 3bfb244a..a059bae3 100755 --- a/scripts/get-prebuilt.sh +++ b/scripts/get-prebuilt.sh @@ -33,7 +33,7 @@ if test x$1 != xskipprebuilt ; then for filename in $files ; do if test ! -f $filename ; then echo get $filename - curl -O "$url_prefix/$filename" + curl -L -O "$url_prefix/$filename" fi done rsync --exclude=.git -av ./ ../../builds/builds/ -- cgit v1.2.3 From 3473ed58a90b4b00cd4123722a37c1a87c8f2e55 Mon Sep 17 00:00:00 2001 From: "Hoa V. DINH" Date: Tue, 25 Jun 2013 01:31:06 -0700 Subject: Implement logging for src/core/ --- build-mac/mailcore2.xcodeproj/project.pbxproj | 14 +++ src/core/basetypes/MCBaseTypes.h | 1 + src/core/basetypes/MCConnectionLogger.h | 40 ++++++++ src/core/basetypes/MCConnectionLoggerUtils.cc | 73 ++++++++++++++ src/core/basetypes/MCConnectionLoggerUtils.h | 21 ++++ src/core/imap/MCIMAPSession.cc | 68 +++++++++---- src/core/imap/MCIMAPSession.h | 4 + src/core/pop/MCPOPSession.cc | 32 ++++++ src/core/pop/MCPOPSession.h | 139 +++++++++++++------------- src/core/smtp/MCSMTPSession.cc | 39 +++++++- src/core/smtp/MCSMTPSession.h | 137 +++++++++++++------------ 11 files changed, 416 insertions(+), 152 deletions(-) create mode 100644 src/core/basetypes/MCConnectionLogger.h create mode 100644 src/core/basetypes/MCConnectionLoggerUtils.cc create mode 100644 src/core/basetypes/MCConnectionLoggerUtils.h diff --git a/build-mac/mailcore2.xcodeproj/project.pbxproj b/build-mac/mailcore2.xcodeproj/project.pbxproj index 0f932f5c..27e70eb4 100644 --- a/build-mac/mailcore2.xcodeproj/project.pbxproj +++ b/build-mac/mailcore2.xcodeproj/project.pbxproj @@ -237,6 +237,10 @@ C668E2CC1735CB8900A2BB47 /* MCAutoreleasePoolMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = C668E2CA1735CB8900A2BB47 /* MCAutoreleasePoolMac.mm */; }; C668E2CD1735CB8900A2BB47 /* MCAutoreleasePoolMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = C668E2CA1735CB8900A2BB47 /* MCAutoreleasePoolMac.mm */; }; C668E2DD1736333900A2BB47 /* providers.json in Resources */ = {isa = PBXBuildFile; fileRef = 84AF9E7D172DBAF600E60AA3 /* providers.json */; }; + C68B2AEE1778A865005E61EF /* MCConnectionLogger.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = C68B2AEB1778A589005E61EF /* MCConnectionLogger.h */; }; + C68B2AEF1778A869005E61EF /* MCConnectionLogger.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = C68B2AEB1778A589005E61EF /* MCConnectionLogger.h */; }; + C68B2AF717797389005E61EF /* MCConnectionLoggerUtils.cc in Sources */ = {isa = PBXBuildFile; fileRef = C68B2AF517797389005E61EF /* MCConnectionLoggerUtils.cc */; }; + C68B2AF817797389005E61EF /* MCConnectionLoggerUtils.cc in Sources */ = {isa = PBXBuildFile; fileRef = C68B2AF517797389005E61EF /* MCConnectionLoggerUtils.cc */; }; C6A81B931706840C00882C15 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C6A81B921706840C00882C15 /* UIKit.framework */; }; C6A81B941706840C00882C15 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C64EA78F169F259200778456 /* Foundation.framework */; }; C6A81B961706840C00882C15 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C6A81B951706840C00882C15 /* CoreGraphics.framework */; }; @@ -709,6 +713,7 @@ C6CF62CD1753250E006398B9 /* MCOMailProvider.h in CopyFiles */, C6CF62CE17532510006398B9 /* MCOMailProvidersManager.h in CopyFiles */, C6CF62D017532521006398B9 /* MCOProvider.h in CopyFiles */, + C68B2AEE1778A865005E61EF /* MCConnectionLogger.h in CopyFiles */, C6CF62D117532527006398B9 /* MCMailProvider.h in CopyFiles */, C6CF62D417532531006398B9 /* MCProvider.h in CopyFiles */, C6CF62D31753252F006398B9 /* MCNetService.h in CopyFiles */, @@ -897,6 +902,7 @@ C6CF62D6175325BD006398B9 /* MCOMailProvidersManager.h in CopyFiles */, C6CF62D7175325BF006398B9 /* MCONetService.h in CopyFiles */, C6CF62D8175325C5006398B9 /* MCOProvider.h in CopyFiles */, + C68B2AEF1778A869005E61EF /* MCConnectionLogger.h in CopyFiles */, C6CF62D9175325CC006398B9 /* MCMailProvider.h in CopyFiles */, C6AC113517124D0A00B715B7 /* MCLibetpanTypes.h in CopyFiles */, C6BA2B0C1705F4E6003F0E9E /* MCHTMLRendererCallback.h in CopyFiles */, @@ -1313,6 +1319,9 @@ C64FF39016B3C13000F8C162 /* MCOObjectWrapper.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MCOObjectWrapper.mm; sourceTree = ""; }; C668E2C51735C8D500A2BB47 /* MCObjectMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MCObjectMac.mm; sourceTree = ""; }; C668E2CA1735CB8900A2BB47 /* MCAutoreleasePoolMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MCAutoreleasePoolMac.mm; sourceTree = ""; }; + C68B2AEB1778A589005E61EF /* MCConnectionLogger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCConnectionLogger.h; sourceTree = ""; }; + C68B2AF517797389005E61EF /* MCConnectionLoggerUtils.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MCConnectionLoggerUtils.cc; sourceTree = ""; }; + C68B2AF617797389005E61EF /* MCConnectionLoggerUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCConnectionLoggerUtils.h; sourceTree = ""; }; C6A81B911706840C00882C15 /* test-ios.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "test-ios.app"; sourceTree = BUILT_PRODUCTS_DIR; }; C6A81B921706840C00882C15 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; }; C6A81B951706840C00882C15 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = Library/Frameworks/CoreGraphics.framework; sourceTree = DEVELOPER_DIR; }; @@ -1821,6 +1830,9 @@ C6AC1131171249DF00B715B7 /* MCLibetpanTypes.h */, C6D6F9691720F8F4006F5B28 /* MCICUTypes.h */, C6D6F96D1721028D006F5B28 /* MCIterator.h */, + C68B2AEB1778A589005E61EF /* MCConnectionLogger.h */, + C68B2AF517797389005E61EF /* MCConnectionLoggerUtils.cc */, + C68B2AF617797389005E61EF /* MCConnectionLoggerUtils.h */, ); path = basetypes; sourceTree = ""; @@ -2345,6 +2357,7 @@ C64EA72F169E847800778456 /* MCIMAPPart.cc in Sources */, C64EA732169E847800778456 /* MCIMAPSearchExpression.cc in Sources */, C64EA734169E847800778456 /* MCIMAPSession.cc in Sources */, + C68B2AF717797389005E61EF /* MCConnectionLoggerUtils.cc in Sources */, C64EA737169E847800778456 /* MCPOPMessageInfo.cc in Sources */, C64EA73A169E847800778456 /* MCPOPSession.cc in Sources */, C64EA73C169E847800778456 /* MCAttachment.cc in Sources */, @@ -2525,6 +2538,7 @@ C6BA2BB41705F4E6003F0E9E /* MCIMAPPart.cc in Sources */, C6BA2BB51705F4E6003F0E9E /* MCIMAPSearchExpression.cc in Sources */, C6BA2BB61705F4E6003F0E9E /* MCIMAPSession.cc in Sources */, + C68B2AF817797389005E61EF /* MCConnectionLoggerUtils.cc in Sources */, C6BA2BB71705F4E6003F0E9E /* MCPOPMessageInfo.cc in Sources */, C6BA2BB81705F4E6003F0E9E /* MCPOPSession.cc in Sources */, C6BA2BB91705F4E6003F0E9E /* MCAttachment.cc in Sources */, diff --git a/src/core/basetypes/MCBaseTypes.h b/src/core/basetypes/MCBaseTypes.h index 4919e1f5..96fa23fd 100644 --- a/src/core/basetypes/MCBaseTypes.h +++ b/src/core/basetypes/MCBaseTypes.h @@ -25,5 +25,6 @@ #include #include #include +#include #endif diff --git a/src/core/basetypes/MCConnectionLogger.h b/src/core/basetypes/MCConnectionLogger.h new file mode 100644 index 00000000..8083d12d --- /dev/null +++ b/src/core/basetypes/MCConnectionLogger.h @@ -0,0 +1,40 @@ +// +// MCConnectionLogger.h +// mailcore2 +// +// Created by DINH Viêt Hoà on 6/24/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#ifndef __MAILCORE_CONNECTION_LOGGER_H_ +#define __MAILCORE_CONNECTION_LOGGER_H_ + +#ifdef __cplusplus + +namespace mailcore { + + class Data; + class String; + + enum ConnectionLogType { + ConnectionLogTypeGeneric, + ConnectionLogTypeReceived, + ConnectionLogTypeSent, + ConnectionLogTypeSentPrivate, + ConnectionLogTypeErrorGeneric, + ConnectionLogTypeErrorReceived, + ConnectionLogTypeErrorSent, + ConnectionLogTypeErrorSentPrivate, + }; + + class ConnectionLogger { + public: + virtual void logBuffer(ConnectionLogType logType, Data * buffer) {} + virtual void logString(ConnectionLogType logType, String * log) {} + }; + +} + +#endif + +#endif diff --git a/src/core/basetypes/MCConnectionLoggerUtils.cc b/src/core/basetypes/MCConnectionLoggerUtils.cc new file mode 100644 index 00000000..669c8449 --- /dev/null +++ b/src/core/basetypes/MCConnectionLoggerUtils.cc @@ -0,0 +1,73 @@ +// +// MCConnectionLoggerUtils.cc +// mailcore2 +// +// Created by DINH Viêt Hoà on 6/24/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#include "MCConnectionLoggerUtils.h" + +#include + +#include "MCConnectionLogger.h" + +mailcore::ConnectionLogType mailcore::getConnectionType(int log_type) +{ + ConnectionLogType type = ConnectionLogTypeGeneric; + bool isBuffer = false; + + switch (log_type) { + case MAILSTREAM_LOG_TYPE_INFO_GENERIC: + type = ConnectionLogTypeGeneric; + break; + case MAILSTREAM_LOG_TYPE_INFO_RECEIVED: + type = ConnectionLogTypeReceived; + break; + case MAILSTREAM_LOG_TYPE_INFO_SENT: + type = ConnectionLogTypeSent; + break; + case MAILSTREAM_LOG_TYPE_ERROR_GENERIC: + type = ConnectionLogTypeErrorGeneric; + isBuffer = true; + break; + case MAILSTREAM_LOG_TYPE_ERROR_RECEIVED: + type = ConnectionLogTypeErrorReceived; + isBuffer = true; + break; + case MAILSTREAM_LOG_TYPE_ERROR_SENT: + type = ConnectionLogTypeErrorSent; + isBuffer = true; + break; + case MAILSTREAM_LOG_TYPE_DATA_RECEIVED: + type = ConnectionLogTypeReceived; + isBuffer = true; + break; + case MAILSTREAM_LOG_TYPE_DATA_SENT: + type = ConnectionLogTypeSent; + isBuffer = true; + break; + case MAILSTREAM_LOG_TYPE_DATA_SENT_PRIVATE: + type = ConnectionLogTypeSentPrivate; + isBuffer = true; + break; + } + return type; +} + +bool mailcore::isBufferFromLogType(int log_type) +{ + bool isBuffer = false; + + switch (log_type) { + case MAILSTREAM_LOG_TYPE_ERROR_GENERIC: + case MAILSTREAM_LOG_TYPE_ERROR_RECEIVED: + case MAILSTREAM_LOG_TYPE_ERROR_SENT: + case MAILSTREAM_LOG_TYPE_DATA_RECEIVED: + case MAILSTREAM_LOG_TYPE_DATA_SENT: + case MAILSTREAM_LOG_TYPE_DATA_SENT_PRIVATE: + isBuffer = true; + break; + } + return isBuffer; +} diff --git a/src/core/basetypes/MCConnectionLoggerUtils.h b/src/core/basetypes/MCConnectionLoggerUtils.h new file mode 100644 index 00000000..86f3c591 --- /dev/null +++ b/src/core/basetypes/MCConnectionLoggerUtils.h @@ -0,0 +1,21 @@ +// +// MCConnectionLoggerUtils.h +// mailcore2 +// +// Created by DINH Viêt Hoà on 6/24/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#ifndef __MAILCORE_MCCONNECTIONLOGGERUTILS_H_ +#define __MAILCORE_MCCONNECTIONLOGGERUTILS_H_ + +#include + +namespace mailcore { + + ConnectionLogType getConnectionType(int log_type); + bool isBufferFromLogType(int log_type); + +} + +#endif diff --git a/src/core/imap/MCIMAPSession.cc b/src/core/imap/MCIMAPSession.cc index a03c3edb..0b194ff7 100644 --- a/src/core/imap/MCIMAPSession.cc +++ b/src/core/imap/MCIMAPSession.cc @@ -14,6 +14,8 @@ #include "MCIMAPNamespace.h" #include "MCIMAPSyncResult.h" #include "MCIMAPFolderStatus.h" +#include "MCConnectionLogger.h" +#include "MCConnectionLoggerUtils.h" using namespace mailcore; @@ -308,38 +310,39 @@ static IndexSet * indexSetFromSet(struct mailimap_set * imap_set) void IMAPSession::init() { mHostname = NULL; - mPort = 0; + mPort = 0; mUsername = NULL; mPassword = NULL; mAuthType = AuthTypeSASLNone; mConnectionType = ConnectionTypeClear; - mCheckCertificateEnabled = true; + mCheckCertificateEnabled = true; mVoIPEnabled = true; - mDelimiter = 0; - + mDelimiter = 0; + mBodyProgressEnabled = true; mIdleEnabled = false; - mXListEnabled = false; + mXListEnabled = false; mQResyncEnabled = false; mCondstoreEnabled = false; mIdentityEnabled = false; mWelcomeString = NULL; - mNeedsMboxMailWorkaround = false; - mDefaultNamespace = NULL; - mTimeout = 30; - mUIDValidity = 0; - mUIDNext = 0; + mNeedsMboxMailWorkaround = false; + mDefaultNamespace = NULL; + mTimeout = 30; + mUIDValidity = 0; + mUIDNext = 0; mModSequenceValue = 0; - mFolderMsgCount = 0; + mFolderMsgCount = 0; mFirstUnseenUid = 0; - mLastFetchedSequenceNumber = 0; - mCurrentFolder = NULL; + mLastFetchedSequenceNumber = 0; + mCurrentFolder = NULL; pthread_mutex_init(&mIdleLock, NULL); mCanIdle = false; - mState = STATE_DISCONNECTED; - mImap = NULL; - mProgressCallback = NULL; - mProgressItemsCount = 0; + mState = STATE_DISCONNECTED; + mImap = NULL; + mProgressCallback = NULL; + mProgressItemsCount = 0; + mConnectionLogger = NULL; } IMAPSession::IMAPSession() @@ -487,6 +490,26 @@ void IMAPSession::items_progress(size_t current, size_t maximum, void * context) session->itemsProgress((unsigned int) current, (unsigned int) maximum); } +static void logger(mailimap * imap, int log_type, const char * buffer, size_t size, void * context) +{ + IMAPSession * session = (IMAPSession *) context; + + if (session->connectionLogger() == NULL) + return; + + ConnectionLogType type = getConnectionType(log_type); + bool isBuffer = isBufferFromLogType(log_type); + + if (isBuffer) { + Data * data = Data::dataWithBytes(buffer, (unsigned int) size); + session->connectionLogger()->logBuffer(type, data); + } + else { + Data * data = Data::dataWithBytes(buffer, (unsigned int) size); + session->connectionLogger()->logString(type, String::stringWithData(data)); + } +} + void IMAPSession::setup() { MCAssert(mImap == NULL); @@ -494,6 +517,7 @@ void IMAPSession::setup() mImap = mailimap_new(0, NULL); mailimap_set_timeout(mImap, timeout()); mailimap_set_progress_callback(mImap, body_progress, IMAPSession::items_progress, this); + mailimap_set_logger(mImap, logger, this); } void IMAPSession::unsetup() @@ -2964,3 +2988,13 @@ bool IMAPSession::isDisconnected() { return mState == STATE_DISCONNECTED; } + +void IMAPSession::setConnectionLogger(ConnectionLogger * logger) +{ + mConnectionLogger = logger; +} + +ConnectionLogger * IMAPSession::connectionLogger() +{ + return mConnectionLogger; +} diff --git a/src/core/imap/MCIMAPSession.h b/src/core/imap/MCIMAPSession.h index c21c36cd..ac282072 100644 --- a/src/core/imap/MCIMAPSession.h +++ b/src/core/imap/MCIMAPSession.h @@ -132,6 +132,9 @@ namespace mailcore { virtual bool isQResyncEnabled(); virtual bool isIdentityEnabled(); + virtual void setConnectionLogger(ConnectionLogger * logger); + virtual ConnectionLogger * connectionLogger(); + public: // private virtual void loginIfNeeded(ErrorCode * pError); virtual void connectIfNeeded(ErrorCode * pError); @@ -172,6 +175,7 @@ namespace mailcore { mailimap * mImap; IMAPProgressCallback * mProgressCallback; unsigned int mProgressItemsCount; + ConnectionLogger * mConnectionLogger; void init(); void bodyProgress(unsigned int current, unsigned int maximum); diff --git a/src/core/pop/MCPOPSession.cc b/src/core/pop/MCPOPSession.cc index 9cfe9157..fe15c500 100644 --- a/src/core/pop/MCPOPSession.cc +++ b/src/core/pop/MCPOPSession.cc @@ -6,6 +6,7 @@ #include "MCPOPMessageInfo.h" #include "MCPOPProgressCallback.h" #include "MCMessageHeader.h" +#include "MCConnectionLoggerUtils.h" using namespace mailcore; @@ -31,6 +32,7 @@ void POPSession::init() mCapabilities = POPCapabilityNone; mProgressCallback = NULL; mState = STATE_DISCONNECTED; + mConnectionLogger = NULL; } POPSession::POPSession() @@ -146,10 +148,31 @@ void POPSession::body_progress(size_t current, size_t maximum, void * context) session->bodyProgress((unsigned int) current, (unsigned int) maximum); } +static void logger(mailpop3 * pop3, int log_type, const char * buffer, size_t size, void * context) +{ + POPSession * session = (POPSession *) context; + + if (session->connectionLogger() == NULL) + return; + + ConnectionLogType type = getConnectionType(log_type); + bool isBuffer = isBufferFromLogType(log_type); + + if (isBuffer) { + Data * data = Data::dataWithBytes(buffer, (unsigned int) size); + session->connectionLogger()->logBuffer(type, data); + } + else { + Data * data = Data::dataWithBytes(buffer, (unsigned int) size); + session->connectionLogger()->logString(type, String::stringWithData(data)); + } +} + void POPSession::setup() { mPop = mailpop3_new(0, NULL); mailpop3_set_progress_callback(mPop, POPSession::body_progress, this); + mailpop3_set_logger(mPop, logger, this); } void POPSession::unsetup() @@ -544,3 +567,12 @@ void POPSession::checkAccount(ErrorCode * pError) loginIfNeeded(pError); } +void POPSession::setConnectionLogger(ConnectionLogger * logger) +{ + mConnectionLogger = logger; +} + +ConnectionLogger * POPSession::connectionLogger() +{ + return mConnectionLogger; +} diff --git a/src/core/pop/MCPOPSession.h b/src/core/pop/MCPOPSession.h index 3bbccf61..5de96b60 100644 --- a/src/core/pop/MCPOPSession.h +++ b/src/core/pop/MCPOPSession.h @@ -8,84 +8,89 @@ #ifdef __cplusplus namespace mailcore { - - class POPMessageInfo; - class POPProgressCallback; - class MessageHeader; + + class POPMessageInfo; + class POPProgressCallback; + class MessageHeader; - class POPSession : public Object { - - public: - POPSession(); - virtual ~POPSession(); - - virtual void setHostname(String * hostname); - virtual String * hostname(); + class POPSession : public Object { + + public: + POPSession(); + virtual ~POPSession(); + + virtual void setHostname(String * hostname); + virtual String * hostname(); - virtual void setPort(unsigned int port); - virtual unsigned int port(); + virtual void setPort(unsigned int port); + virtual unsigned int port(); - virtual void setUsername(String * username); - virtual String * username(); + virtual void setUsername(String * username); + virtual String * username(); - virtual void setPassword(String * password); - virtual String * password(); + virtual void setPassword(String * password); + virtual String * password(); - virtual void setAuthType(AuthType authType); - virtual AuthType authType(); + virtual void setAuthType(AuthType authType); + virtual AuthType authType(); - virtual void setConnectionType(ConnectionType connectionType); - virtual ConnectionType connectionType(); + virtual void setConnectionType(ConnectionType connectionType); + virtual ConnectionType connectionType(); - virtual void setTimeout(time_t timeout); - virtual time_t timeout(); - - virtual void setCheckCertificateEnabled(bool enabled); - virtual bool isCheckCertificateEnabled(); + virtual void setTimeout(time_t timeout); + virtual time_t timeout(); + + virtual void setCheckCertificateEnabled(bool enabled); + virtual bool isCheckCertificateEnabled(); - virtual void connect(ErrorCode * pError); - virtual void disconnect(); - - virtual void login(ErrorCode * pError); - + virtual void connect(ErrorCode * pError); + virtual void disconnect(); + + virtual void login(ErrorCode * pError); + virtual void checkAccount(ErrorCode * pError); - Array * /* POPMessageInfo */ fetchMessages(ErrorCode * pError); - - MessageHeader * fetchHeader(unsigned int index, ErrorCode * pError); - MessageHeader * fetchHeader(POPMessageInfo * msg, ErrorCode * pError); - - Data * fetchMessage(unsigned int index, POPProgressCallback * callback, ErrorCode * pError); - Data * fetchMessage(POPMessageInfo * msg, POPProgressCallback * callback, ErrorCode * pError); - - void deleteMessage(unsigned int index, ErrorCode * pError); - void deleteMessage(POPMessageInfo * msg, ErrorCode * pError); + Array * /* POPMessageInfo */ fetchMessages(ErrorCode * pError); + + MessageHeader * fetchHeader(unsigned int index, ErrorCode * pError); + MessageHeader * fetchHeader(POPMessageInfo * msg, ErrorCode * pError); + + Data * fetchMessage(unsigned int index, POPProgressCallback * callback, ErrorCode * pError); + Data * fetchMessage(POPMessageInfo * msg, POPProgressCallback * callback, ErrorCode * pError); + + void deleteMessage(unsigned int index, ErrorCode * pError); + void deleteMessage(POPMessageInfo * msg, ErrorCode * pError); + + virtual void setConnectionLogger(ConnectionLogger * logger); + virtual ConnectionLogger * connectionLogger(); + + private: + String * mHostname; + unsigned int mPort; + String * mUsername; + String * mPassword; + AuthType mAuthType; + ConnectionType mConnectionType; + bool mCheckCertificateEnabled; + time_t mTimeout; + + mailpop3 * mPop; + POPCapability mCapabilities; + POPProgressCallback * mProgressCallback; + int mState; + + ConnectionLogger * mConnectionLogger; - private: - String * mHostname; - unsigned int mPort; - String * mUsername; - String * mPassword; - AuthType mAuthType; - ConnectionType mConnectionType; - bool mCheckCertificateEnabled; - time_t mTimeout; - - mailpop3 * mPop; - POPCapability mCapabilities; - POPProgressCallback * mProgressCallback; - int mState; - - void init(); - void bodyProgress(unsigned int current, unsigned int maximum); - bool checkCertificate(); - static void body_progress(size_t current, size_t maximum, void * context); - void setup(); - void unsetup(); - void connectIfNeeded(ErrorCode * pError); - void loginIfNeeded(ErrorCode * pError); - void listIfNeeded(ErrorCode * pError); - }; + void init(); + void bodyProgress(unsigned int current, unsigned int maximum); + bool checkCertificate(); + static void body_progress(size_t current, size_t maximum, void * context); + void setup(); + void unsetup(); + void connectIfNeeded(ErrorCode * pError); + void loginIfNeeded(ErrorCode * pError); + void listIfNeeded(ErrorCode * pError); + }; } diff --git a/src/core/smtp/MCSMTPSession.cc b/src/core/smtp/MCSMTPSession.cc index ee225b16..e74a540a 100644 --- a/src/core/smtp/MCSMTPSession.cc +++ b/src/core/smtp/MCSMTPSession.cc @@ -8,6 +8,7 @@ #include "MCMessageParser.h" #include "MCMessageHeader.h" #include "MCSMTPProgressCallback.h" +#include "MCConnectionLoggerUtils.h" using namespace mailcore; @@ -35,6 +36,7 @@ void SMTPSession::init() mLastSMTPResponse = NULL; mLastLibetpanError = 0; mLastSMTPResponseCode = 0; + mConnectionLogger = NULL; } SMTPSession::SMTPSession() @@ -161,11 +163,34 @@ void SMTPSession::bodyProgress(unsigned int current, unsigned int maximum) } } + +static void logger(mailsmtp * pop3, int log_type, const char * buffer, size_t size, void * context) +{ + SMTPSession * session = (SMTPSession *) context; + + if (session->connectionLogger() == NULL) + return; + + ConnectionLogType type = getConnectionType(log_type); + bool isBuffer = isBufferFromLogType(log_type); + + if (isBuffer) { + Data * data = Data::dataWithBytes(buffer, (unsigned int) size); + session->connectionLogger()->logBuffer(type, data); + } + else { + Data * data = Data::dataWithBytes(buffer, (unsigned int) size); + session->connectionLogger()->logString(type, String::stringWithData(data)); + } +} + + void SMTPSession::setup() { - mSmtp = mailsmtp_new(0, NULL); - mailsmtp_set_timeout(mSmtp, timeout()); + mSmtp = mailsmtp_new(0, NULL); + mailsmtp_set_timeout(mSmtp, timeout()); mailsmtp_set_progress_callback(mSmtp, body_progress, this); + mailsmtp_set_logger(mSmtp, logger, this); } void SMTPSession::unsetup() @@ -681,3 +706,13 @@ bool SMTPSession::isDisconnected() { return mState == STATE_DISCONNECTED; } + +void SMTPSession::setConnectionLogger(ConnectionLogger * logger) +{ + mConnectionLogger = logger; +} + +ConnectionLogger * SMTPSession::connectionLogger() +{ + return mConnectionLogger; +} diff --git a/src/core/smtp/MCSMTPSession.h b/src/core/smtp/MCSMTPSession.h index 57c6e0ce..491ecb07 100644 --- a/src/core/smtp/MCSMTPSession.h +++ b/src/core/smtp/MCSMTPSession.h @@ -8,88 +8,93 @@ #ifdef __cplusplus namespace mailcore { - - class Address; - class SMTPProgressCallback; - class MessageBuilder; + + class Address; + class SMTPProgressCallback; + class MessageBuilder; - class SMTPSession : public Object { - public: - SMTPSession(); - virtual ~SMTPSession(); - - virtual void setHostname(String * hostname); - virtual String * hostname(); + class SMTPSession : public Object { + public: + SMTPSession(); + virtual ~SMTPSession(); + + virtual void setHostname(String * hostname); + virtual String * hostname(); - virtual void setPort(unsigned int port); - virtual unsigned int port(); + virtual void setPort(unsigned int port); + virtual unsigned int port(); - virtual void setUsername(String * username); - virtual String * username(); + virtual void setUsername(String * username); + virtual String * username(); - virtual void setPassword(String * password); - virtual String * password(); + virtual void setPassword(String * password); + virtual String * password(); - virtual void setAuthType(AuthType authType); - virtual AuthType authType(); + virtual void setAuthType(AuthType authType); + virtual AuthType authType(); - virtual void setConnectionType(ConnectionType connectionType); - virtual ConnectionType connectionType(); + virtual void setConnectionType(ConnectionType connectionType); + virtual ConnectionType connectionType(); - virtual void setTimeout(time_t timeout); - virtual time_t timeout(); - - virtual void setCheckCertificateEnabled(bool enabled); - virtual bool isCheckCertificateEnabled(); - - virtual void setUseHeloIPEnabled(bool enabled); - virtual bool useHeloIPEnabled(); - - virtual void connect(ErrorCode * pError); - virtual void disconnect(); - - virtual void login(ErrorCode * pError); - + virtual void setTimeout(time_t timeout); + virtual time_t timeout(); + + virtual void setCheckCertificateEnabled(bool enabled); + virtual bool isCheckCertificateEnabled(); + + virtual void setUseHeloIPEnabled(bool enabled); + virtual bool useHeloIPEnabled(); + + virtual void connect(ErrorCode * pError); + virtual void disconnect(); + + virtual void login(ErrorCode * pError); + virtual void checkAccount(Address * from, ErrorCode * pError); - virtual void sendMessage(Data * messageData, SMTPProgressCallback * callback, ErrorCode * pError); + virtual void sendMessage(Data * messageData, SMTPProgressCallback * callback, ErrorCode * pError); - private: - String * mHostname; - unsigned int mPort; - String * mUsername; - String * mPassword; - AuthType mAuthType; - ConnectionType mConnectionType; - time_t mTimeout; - bool mCheckCertificateEnabled; - bool mUseHeloIPEnabled; - - mailsmtp * mSmtp; - SMTPProgressCallback * mProgressCallback; - int mState; - String * mLastSMTPResponse; + virtual void setConnectionLogger(ConnectionLogger * logger); + virtual ConnectionLogger * connectionLogger(); + + private: + String * mHostname; + unsigned int mPort; + String * mUsername; + String * mPassword; + AuthType mAuthType; + ConnectionType mConnectionType; + time_t mTimeout; + bool mCheckCertificateEnabled; + bool mUseHeloIPEnabled; + + mailsmtp * mSmtp; + SMTPProgressCallback * mProgressCallback; + int mState; + String * mLastSMTPResponse; int mLastLibetpanError; int mLastSMTPResponseCode; - - void init(); - Data * dataWithFilteredBcc(Data * data); - static void body_progress(size_t current, size_t maximum, void * context); - void bodyProgress(unsigned int current, unsigned int maximum); - void setup(); - void unsetup(); - void connectIfNeeded(ErrorCode * pError); - void loginIfNeeded(ErrorCode * pError); - bool checkCertificate(); - - void sendMessage(Address * from, Array * /* Address */ recipients, Data * messageData, + + ConnectionLogger * mConnectionLogger; + + void init(); + Data * dataWithFilteredBcc(Data * data); + static void body_progress(size_t current, size_t maximum, void * context); + void bodyProgress(unsigned int current, unsigned int maximum); + void setup(); + void unsetup(); + void connectIfNeeded(ErrorCode * pError); + void loginIfNeeded(ErrorCode * pError); + bool checkCertificate(); + + void sendMessage(Address * from, Array * /* Address */ recipients, Data * messageData, SMTPProgressCallback * callback, ErrorCode * pError); - void sendMessage(MessageBuilder * msg, SMTPProgressCallback * callback, ErrorCode * pError); + void sendMessage(MessageBuilder * msg, SMTPProgressCallback * callback, ErrorCode * pError); public: // private virtual bool isDisconnected(); - }; - + }; + } #endif -- cgit v1.2.3 From 4a0cdf4f9a079ef1b45f56818f6e82c533956281 Mon Sep 17 00:00:00 2001 From: "Hoa V. DINH" Date: Tue, 25 Jun 2013 01:43:15 -0700 Subject: Improved build scripts --- scripts/get-prebuilt.sh | 40 +++++++++++++++++++++++--------------- scripts/prepare-ctemplate-ios.sh | 2 ++ scripts/prepare-ctemplate-macos.sh | 2 ++ scripts/prepare-icu4c-ios.sh | 2 ++ scripts/prepare-icu4c-macos.sh | 2 ++ scripts/prepare-ios.sh | 14 ++++++------- scripts/prepare-libetpan-ios.sh | 3 +++ scripts/prepare-libetpan-macos.sh | 2 ++ scripts/prepare-mac.sh | 12 +++++++----- scripts/prepare-tidy-ios.sh | 2 ++ 10 files changed, 53 insertions(+), 28 deletions(-) diff --git a/scripts/get-prebuilt.sh b/scripts/get-prebuilt.sh index a059bae3..7d02e3ff 100755 --- a/scripts/get-prebuilt.sh +++ b/scripts/get-prebuilt.sh @@ -1,6 +1,7 @@ #!/bin/sh -url_prefix="https://github.com/MailCore/mailcore2-deps/raw/master" +url="https://github.com/MailCore/mailcore2-deps" +url_prefix="$url/raw/master" if test x$1 != xskipprebuilt ; then file_timestamp=0 @@ -22,21 +23,28 @@ if test x$1 != xskipprebuilt ; then fi mv prebuilt.list.tmp prebuilt.list - fi - if test -f prebuilt.list ; then - files=`cat prebuilt.list` - mkdir -p ../Externals/builds/builds - mkdir -p ../Externals/prebuilt/mailcore2-deps - pushd ../Externals/prebuilt/mailcore2-deps - rm -rf .git - for filename in $files ; do - if test ! -f $filename ; then - echo get $filename - curl -L -O "$url_prefix/$filename" + if test -f prebuilt.list ; then + files=`cat prebuilt.list` + mkdir -p ../Externals/builds/builds + mkdir -p ../Externals/prebuilt/mailcore2-deps + pushd ../Externals/prebuilt + rm -rf .git + if test -d mailcore2-deps ; then + cd mailcore2-deps + git pull --rebase + cd .. + else + git clone --depth 1 "$url" fi - done - rsync --exclude=.git -av ./ ../../builds/builds/ - popd - fi + # for filename in $files ; do + # if test ! -f $filename ; then + # echo get $filename + # curl -L -O "$url_prefix/$filename" + # fi + # done + rsync --exclude=.git -av mailcore2-deps/ ../builds/builds/ + popd + fi + fi fi diff --git a/scripts/prepare-ctemplate-ios.sh b/scripts/prepare-ctemplate-ios.sh index 240dc5d9..512bdc9e 100755 --- a/scripts/prepare-ctemplate-ios.sh +++ b/scripts/prepare-ctemplate-ios.sh @@ -42,6 +42,8 @@ if test -f "$resultdir/ctemplate-ios-$version.zip" ; then mkdir -p ../Externals/tmp unzip -q "$resultdir/ctemplate-ios-$version.zip" -d ../Externals/tmp mv "../Externals/tmp/ctemplate-ios-$version/ctemplate-ios" ../Externals + mkdir -p ../Externals/installed + ln -s "$resultdir/ctemplate-ios-$version.zip" ../Externals/installed rm -rf ../Externals/tmp exit 0 fi diff --git a/scripts/prepare-ctemplate-macos.sh b/scripts/prepare-ctemplate-macos.sh index bea782f9..43b0e8fa 100755 --- a/scripts/prepare-ctemplate-macos.sh +++ b/scripts/prepare-ctemplate-macos.sh @@ -48,6 +48,8 @@ if test -f "$resultdir/ctemplate-$version.zip" ; then mkdir -p ../Externals/tmp unzip -q "$resultdir/ctemplate-$version.zip" -d ../Externals/tmp mv "../Externals/tmp/ctemplate-$version/ctemplate" ../Externals + mkdir -p ../Externals/installed + ln -s "$resultdir/ctemplate-$version.zip" ../Externals/installed rm -rf ../Externals/tmp exit 0 fi diff --git a/scripts/prepare-icu4c-ios.sh b/scripts/prepare-icu4c-ios.sh index 9d50d985..a915df76 100755 --- a/scripts/prepare-icu4c-ios.sh +++ b/scripts/prepare-icu4c-ios.sh @@ -27,6 +27,8 @@ if test -f "$resultdir/icu4c-ios-$version.zip" ; then mkdir -p ../Externals/tmp unzip -q "$resultdir/icu4c-ios-$version.zip" -d ../Externals/tmp mv "../Externals/tmp/icu4c-ios-$version/icu4c-ios" ../Externals + mkdir -p ../Externals/installed + ln -s "$resultdir/icu4c-ios-$version.zip" ../Externals/installed rm -rf ../Externals/tmp exit 0 fi diff --git a/scripts/prepare-icu4c-macos.sh b/scripts/prepare-icu4c-macos.sh index 903d2fa8..dcc6421a 100755 --- a/scripts/prepare-icu4c-macos.sh +++ b/scripts/prepare-icu4c-macos.sh @@ -32,6 +32,8 @@ if test -f "$resultdir/icu4c-$version.zip" ; then mkdir -p ../Externals/tmp unzip -q "$resultdir/icu4c-$version.zip" -d ../Externals/tmp mv "../Externals/tmp/icu4c-$version/icu4c" ../Externals + mkdir -p ../Externals/installed + ln -s "$resultdir/icu4c-$version.zip" ../Externals/installed rm -rf ../Externals/tmp exit 0 fi diff --git a/scripts/prepare-ios.sh b/scripts/prepare-ios.sh index 44ccb2e0..49bac30e 100755 --- a/scripts/prepare-ios.sh +++ b/scripts/prepare-ios.sh @@ -1,15 +1,15 @@ #!/bin/sh ./get-prebuilt.sh -if test ! -d ../Externals/tidy-html5-ios ; then +missing=no +for filename in `cat prebuilt.list|grep -- -ios` ; do + if test ! -f "../Externals/installed/$filename" ; then + missing=yes + fi +done +if test $missing = yes ; then ./prepare-tidy-ios.sh -fi -if test ! -d ../Externals/icu4c-ios ; then ./prepare-icu4c-ios.sh -fi -if test ! -d ../Externals/libetpan-ios ; then ./prepare-libetpan-ios.sh -fi -if test ! -d ../Externals/ctemplate-ios ; then ./prepare-ctemplate-ios.sh fi diff --git a/scripts/prepare-libetpan-ios.sh b/scripts/prepare-libetpan-ios.sh index 5ab8a8a6..d416df67 100755 --- a/scripts/prepare-libetpan-ios.sh +++ b/scripts/prepare-libetpan-ios.sh @@ -46,6 +46,9 @@ if test -f "$resultdir/libetpan-ios-$version.zip" ; then unzip -q "$resultdir/libsasl-ios-$version.zip" -d ../Externals/tmp mv "../Externals/tmp/libetpan-ios-$version/libetpan-ios" ../Externals mv "../Externals/tmp/libsasl-ios-$version/libsasl-ios" ../Externals + mkdir -p ../Externals/installed + ln -s "$resultdir/libetpan-ios-$version.zip" ../Externals/installed + ln -s "$resultdir/libsasl-ios-$version.zip" ../Externals/installed rm -rf ../Externals/tmp exit 0 fi diff --git a/scripts/prepare-libetpan-macos.sh b/scripts/prepare-libetpan-macos.sh index 1972bf84..555d47e5 100755 --- a/scripts/prepare-libetpan-macos.sh +++ b/scripts/prepare-libetpan-macos.sh @@ -42,6 +42,8 @@ if test -f "$resultdir/libetpan-$version.zip" ; then mkdir -p ../Externals/tmp unzip -q "$resultdir/libetpan-$version.zip" -d ../Externals/tmp mv "../Externals/tmp/libetpan-$version/libetpan" ../Externals + mkdir -p ../Externals/installed + ln -s "$resultdir/libetpan-$version.zip" ../Externals/installed rm -rf ../Externals/tmp exit 0 fi diff --git a/scripts/prepare-mac.sh b/scripts/prepare-mac.sh index f29dfa04..2b9fdca8 100755 --- a/scripts/prepare-mac.sh +++ b/scripts/prepare-mac.sh @@ -1,13 +1,15 @@ #!/bin/sh ./get-prebuilt.sh -if test ! -d ../Externals/icu4c ; then +missing=no +for filename in `cat prebuilt.list|grep -v -- -ios` ; do + if test ! -f "../Externals/installed/$filename" ; then + missing=yes + fi +done +if test $missing = yes ; then ./prepare-icu4c-macos.sh -fi -if test ! -d ../Externals/libetpan ; then ./prepare-libetpan-macos.sh -fi -if test ! -d ../Externals/ctemplate ; then ./prepare-ctemplate-macos.sh fi diff --git a/scripts/prepare-tidy-ios.sh b/scripts/prepare-tidy-ios.sh index 55435e2b..e24bb678 100755 --- a/scripts/prepare-tidy-ios.sh +++ b/scripts/prepare-tidy-ios.sh @@ -41,6 +41,8 @@ if test -f "$resultdir/tidy-html5-ios-$version.zip" ; then mkdir -p ../Externals/tmp unzip -q "$resultdir/tidy-html5-ios-$version.zip" -d ../Externals/tmp mv "../Externals/tmp/tidy-html5-ios-$version/tidy-html5-ios" ../Externals + mkdir -p ../Externals/installed + ln -s "$resultdir/tidy-html5-ios-$version.zip" ../Externals/installed rm -rf ../Externals/tmp exit 0 fi -- cgit v1.2.3 From db2597c4bc86bf221c4bc52dc6f2efedcfbdfde4 Mon Sep 17 00:00:00 2001 From: "Hoa V. DINH" Date: Tue, 25 Jun 2013 01:46:48 -0700 Subject: Fixed issue when creating symbolic links while links already exist. --- scripts/prepare-ctemplate-ios.sh | 2 +- scripts/prepare-ctemplate-macos.sh | 2 +- scripts/prepare-icu4c-ios.sh | 2 +- scripts/prepare-icu4c-macos.sh | 2 +- scripts/prepare-libetpan-ios.sh | 4 ++-- scripts/prepare-libetpan-macos.sh | 2 +- scripts/prepare-tidy-ios.sh | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/prepare-ctemplate-ios.sh b/scripts/prepare-ctemplate-ios.sh index 512bdc9e..caeb430c 100755 --- a/scripts/prepare-ctemplate-ios.sh +++ b/scripts/prepare-ctemplate-ios.sh @@ -43,7 +43,7 @@ if test -f "$resultdir/ctemplate-ios-$version.zip" ; then unzip -q "$resultdir/ctemplate-ios-$version.zip" -d ../Externals/tmp mv "../Externals/tmp/ctemplate-ios-$version/ctemplate-ios" ../Externals mkdir -p ../Externals/installed - ln -s "$resultdir/ctemplate-ios-$version.zip" ../Externals/installed + ln -sf "$resultdir/ctemplate-ios-$version.zip" ../Externals/installed rm -rf ../Externals/tmp exit 0 fi diff --git a/scripts/prepare-ctemplate-macos.sh b/scripts/prepare-ctemplate-macos.sh index 43b0e8fa..2e0fdd60 100755 --- a/scripts/prepare-ctemplate-macos.sh +++ b/scripts/prepare-ctemplate-macos.sh @@ -49,7 +49,7 @@ if test -f "$resultdir/ctemplate-$version.zip" ; then unzip -q "$resultdir/ctemplate-$version.zip" -d ../Externals/tmp mv "../Externals/tmp/ctemplate-$version/ctemplate" ../Externals mkdir -p ../Externals/installed - ln -s "$resultdir/ctemplate-$version.zip" ../Externals/installed + ln -sf "$resultdir/ctemplate-$version.zip" ../Externals/installed rm -rf ../Externals/tmp exit 0 fi diff --git a/scripts/prepare-icu4c-ios.sh b/scripts/prepare-icu4c-ios.sh index a915df76..eee89069 100755 --- a/scripts/prepare-icu4c-ios.sh +++ b/scripts/prepare-icu4c-ios.sh @@ -28,7 +28,7 @@ if test -f "$resultdir/icu4c-ios-$version.zip" ; then unzip -q "$resultdir/icu4c-ios-$version.zip" -d ../Externals/tmp mv "../Externals/tmp/icu4c-ios-$version/icu4c-ios" ../Externals mkdir -p ../Externals/installed - ln -s "$resultdir/icu4c-ios-$version.zip" ../Externals/installed + ln -sf "$resultdir/icu4c-ios-$version.zip" ../Externals/installed rm -rf ../Externals/tmp exit 0 fi diff --git a/scripts/prepare-icu4c-macos.sh b/scripts/prepare-icu4c-macos.sh index dcc6421a..9ae0cf7d 100755 --- a/scripts/prepare-icu4c-macos.sh +++ b/scripts/prepare-icu4c-macos.sh @@ -33,7 +33,7 @@ if test -f "$resultdir/icu4c-$version.zip" ; then unzip -q "$resultdir/icu4c-$version.zip" -d ../Externals/tmp mv "../Externals/tmp/icu4c-$version/icu4c" ../Externals mkdir -p ../Externals/installed - ln -s "$resultdir/icu4c-$version.zip" ../Externals/installed + ln -sf "$resultdir/icu4c-$version.zip" ../Externals/installed rm -rf ../Externals/tmp exit 0 fi diff --git a/scripts/prepare-libetpan-ios.sh b/scripts/prepare-libetpan-ios.sh index d416df67..395b51a7 100755 --- a/scripts/prepare-libetpan-ios.sh +++ b/scripts/prepare-libetpan-ios.sh @@ -47,8 +47,8 @@ if test -f "$resultdir/libetpan-ios-$version.zip" ; then mv "../Externals/tmp/libetpan-ios-$version/libetpan-ios" ../Externals mv "../Externals/tmp/libsasl-ios-$version/libsasl-ios" ../Externals mkdir -p ../Externals/installed - ln -s "$resultdir/libetpan-ios-$version.zip" ../Externals/installed - ln -s "$resultdir/libsasl-ios-$version.zip" ../Externals/installed + ln -sf "$resultdir/libetpan-ios-$version.zip" ../Externals/installed + ln -sf "$resultdir/libsasl-ios-$version.zip" ../Externals/installed rm -rf ../Externals/tmp exit 0 fi diff --git a/scripts/prepare-libetpan-macos.sh b/scripts/prepare-libetpan-macos.sh index 555d47e5..cd1fa8e3 100755 --- a/scripts/prepare-libetpan-macos.sh +++ b/scripts/prepare-libetpan-macos.sh @@ -43,7 +43,7 @@ if test -f "$resultdir/libetpan-$version.zip" ; then unzip -q "$resultdir/libetpan-$version.zip" -d ../Externals/tmp mv "../Externals/tmp/libetpan-$version/libetpan" ../Externals mkdir -p ../Externals/installed - ln -s "$resultdir/libetpan-$version.zip" ../Externals/installed + ln -sf "$resultdir/libetpan-$version.zip" ../Externals/installed rm -rf ../Externals/tmp exit 0 fi diff --git a/scripts/prepare-tidy-ios.sh b/scripts/prepare-tidy-ios.sh index e24bb678..53989950 100755 --- a/scripts/prepare-tidy-ios.sh +++ b/scripts/prepare-tidy-ios.sh @@ -42,7 +42,7 @@ if test -f "$resultdir/tidy-html5-ios-$version.zip" ; then unzip -q "$resultdir/tidy-html5-ios-$version.zip" -d ../Externals/tmp mv "../Externals/tmp/tidy-html5-ios-$version/tidy-html5-ios" ../Externals mkdir -p ../Externals/installed - ln -s "$resultdir/tidy-html5-ios-$version.zip" ../Externals/installed + ln -sf "$resultdir/tidy-html5-ios-$version.zip" ../Externals/installed rm -rf ../Externals/tmp exit 0 fi -- cgit v1.2.3 From fe9037f4248d50c35679cea5534d6ee87e71ede6 Mon Sep 17 00:00:00 2001 From: "Hoa V. Dinh" Date: Tue, 25 Jun 2013 16:50:59 -0700 Subject: Fixed fetch of prebuilt dependencies --- scripts/get-prebuilt.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/get-prebuilt.sh b/scripts/get-prebuilt.sh index 7d02e3ff..35b2980f 100755 --- a/scripts/get-prebuilt.sh +++ b/scripts/get-prebuilt.sh @@ -10,6 +10,9 @@ if test x$1 != xskipprebuilt ; then fi timestamp=`ruby -e 'puts Time.now.to_i'` age=$((($timestamp-$file_timestamp)/3600)) # in hours + if test ! -d ../Externals/prebuilt ; then + age=1 + fi if test $age -gt 0 ; then networkerror=no #echo "$url_prefix/prebuilt.list" @@ -20,6 +23,7 @@ if test x$1 != xskipprebuilt ; then if test x$networkerror = xyes ; then echo WARNING: could not get prebuilt.list from repository + exit 1 fi mv prebuilt.list.tmp prebuilt.list @@ -27,7 +31,7 @@ if test x$1 != xskipprebuilt ; then if test -f prebuilt.list ; then files=`cat prebuilt.list` mkdir -p ../Externals/builds/builds - mkdir -p ../Externals/prebuilt/mailcore2-deps + mkdir -p ../Externals/prebuilt pushd ../Externals/prebuilt rm -rf .git if test -d mailcore2-deps ; then -- cgit v1.2.3 From 49eaf450344d73d815124bc343e92402dab5b7ab Mon Sep 17 00:00:00 2001 From: "Hoa V. DINH" Date: Wed, 26 Jun 2013 01:37:52 -0700 Subject: Implement IMAP logger. Work in progress on POP and SMTP loggers. --- scripts/prepare-libetpan-ios.sh | 2 +- scripts/prepare-libetpan-macos.sh | 2 +- src/async/imap/MCIMAPAsyncConnection.cc | 55 +++++++++++++++++++++++++++ src/async/imap/MCIMAPAsyncConnection.h | 9 +++++ src/async/imap/MCIMAPAsyncSession.cc | 16 ++++++++ src/async/imap/MCIMAPAsyncSession.h | 5 +++ src/core/basetypes/MCConnectionLogger.h | 16 +++++--- src/core/basetypes/MCConnectionLoggerUtils.cc | 19 ++------- src/core/imap/MCIMAPSession.cc | 8 ++-- src/core/pop/MCPOPSession.cc | 5 +-- src/core/smtp/MCSMTPSession.cc | 7 ++-- 11 files changed, 112 insertions(+), 32 deletions(-) diff --git a/scripts/prepare-libetpan-ios.sh b/scripts/prepare-libetpan-ios.sh index 395b51a7..7a5a054b 100755 --- a/scripts/prepare-libetpan-ios.sh +++ b/scripts/prepare-libetpan-ios.sh @@ -2,7 +2,7 @@ sdkversion=6.1 url="https://github.com/dinhviethoa/libetpan.git" -rev=fb889b032d5a5f7e7178a038918bcdcd5d19d6ec +rev=78427a0506be00e1e72ac8f88aa4b71bebd4137f pushd `dirname $0` > /dev/null scriptpath=`pwd` diff --git a/scripts/prepare-libetpan-macos.sh b/scripts/prepare-libetpan-macos.sh index cd1fa8e3..81013fa6 100755 --- a/scripts/prepare-libetpan-macos.sh +++ b/scripts/prepare-libetpan-macos.sh @@ -1,7 +1,7 @@ #!/bin/sh url="https://github.com/dinhviethoa/libetpan.git" -rev=fb889b032d5a5f7e7178a038918bcdcd5d19d6ec +rev=78427a0506be00e1e72ac8f88aa4b71bebd4137f pushd `dirname $0` > /dev/null scriptpath=`pwd` 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); +} diff --git a/src/async/imap/MCIMAPAsyncConnection.h b/src/async/imap/MCIMAPAsyncConnection.h index d6ef6a91..48d47ad9 100644 --- a/src/async/imap/MCIMAPAsyncConnection.h +++ b/src/async/imap/MCIMAPAsyncConnection.h @@ -27,6 +27,7 @@ namespace mailcore { class IMAPCapabilityOperation; class IMAPOperationQueueCallback; class IMAPAsyncSession; + class IMAPConnectionLogger; class IMAPAsyncConnection : public Object { public: @@ -66,6 +67,9 @@ namespace mailcore { virtual void setDefaultNamespace(IMAPNamespace * ns); virtual IMAPNamespace * defaultNamespace(); + virtual void setConnectionLogger(ConnectionLogger * logger); + virtual ConnectionLogger * connectionLogger(); + virtual IMAPFolderInfoOperation * folderInfoOperation(String * folder); virtual IMAPFolderStatusOperation * folderStatusOperation(String * folder); @@ -120,6 +124,9 @@ namespace mailcore { String * mLastFolder; IMAPOperationQueueCallback * mQueueCallback; IMAPAsyncSession * mOwner; + ConnectionLogger * mConnectionLogger; + IMAPConnectionLogger * mInternalLogger; + pthread_mutex_t mConnectionLoggerLock; virtual void tryAutomaticDisconnectAfterDelay(void * context); @@ -138,6 +145,8 @@ namespace mailcore { virtual void setOwner(IMAPAsyncSession * owner); virtual IMAPAsyncSession * owner(); + + virtual void logConnection(ConnectionLogType logType, Data * buffer); }; } diff --git a/src/async/imap/MCIMAPAsyncSession.cc b/src/async/imap/MCIMAPAsyncSession.cc index 7c085e4a..9272a034 100644 --- a/src/async/imap/MCIMAPAsyncSession.cc +++ b/src/async/imap/MCIMAPAsyncSession.cc @@ -11,6 +11,7 @@ #include "MCIMAPAsyncConnection.h" #include "MCIMAPNamespace.h" #include "MCOperationQueueCallback.h" +#include "MCConnectionLogger.h" #define DEFAULT_MAX_CONNECTIONS 3 @@ -33,6 +34,7 @@ IMAPAsyncSession::IMAPAsyncSession() mDelimiter = 0; mDefaultNamespace = NULL; mTimeout = 30.; + mConnectionLogger = NULL; } IMAPAsyncSession::~IMAPAsyncSession() @@ -174,6 +176,7 @@ unsigned int IMAPAsyncSession::maximumConnections() IMAPAsyncConnection * IMAPAsyncSession::session() { IMAPAsyncConnection * session = new IMAPAsyncConnection(); + session->setConnectionLogger(mConnectionLogger); session->setOwner(this); session->autorelease(); @@ -429,3 +432,16 @@ IMAPCapabilityOperation * IMAPAsyncSession::capabilityOperation() return session->capabilityOperation(); } +void IMAPAsyncSession::setConnectionLogger(ConnectionLogger * logger) +{ + mConnectionLogger = logger; + for(unsigned int i = 0 ; i < mSessions->count() ; i ++) { + IMAPAsyncConnection * currentSession = (IMAPAsyncConnection *) mSessions->objectAtIndex(i); + currentSession->setConnectionLogger(logger); + } +} + +ConnectionLogger * IMAPAsyncSession::connectionLogger() +{ + return mConnectionLogger; +} diff --git a/src/async/imap/MCIMAPAsyncSession.h b/src/async/imap/MCIMAPAsyncSession.h index 390fdab8..eae6ea15 100644 --- a/src/async/imap/MCIMAPAsyncSession.h +++ b/src/async/imap/MCIMAPAsyncSession.h @@ -33,6 +33,7 @@ namespace mailcore { class IMAPIdentityOperation; class IMAPAsyncConnection; class IMAPCapabilityOperation; + class ConnectionLogger; class IMAPAsyncSession : public Object { public: @@ -78,6 +79,9 @@ namespace mailcore { virtual void setMaximumConnections(unsigned int maxConnections); virtual unsigned int maximumConnections(); + virtual void setConnectionLogger(ConnectionLogger * logger); + virtual ConnectionLogger * connectionLogger(); + virtual IMAPFolderInfoOperation * folderInfoOperation(String * folder); virtual IMAPFolderStatusOperation * folderStatusOperation(String * folder); @@ -141,6 +145,7 @@ namespace mailcore { time_t mTimeout; bool mAllowsFolderConcurrentAccessEnabled; unsigned int mMaximumConnections; + ConnectionLogger * mConnectionLogger; virtual IMAPAsyncConnection * sessionForFolder(String * folder, bool urgent = false); virtual IMAPAsyncConnection * session(); diff --git a/src/core/basetypes/MCConnectionLogger.h b/src/core/basetypes/MCConnectionLogger.h index 8083d12d..371e6152 100644 --- a/src/core/basetypes/MCConnectionLogger.h +++ b/src/core/basetypes/MCConnectionLogger.h @@ -9,6 +9,8 @@ #ifndef __MAILCORE_CONNECTION_LOGGER_H_ #define __MAILCORE_CONNECTION_LOGGER_H_ +#include + #ifdef __cplusplus namespace mailcore { @@ -17,20 +19,24 @@ namespace mailcore { class String; enum ConnectionLogType { - ConnectionLogTypeGeneric, + // Received data ConnectionLogTypeReceived, + // Sent data ConnectionLogTypeSent, + // Sent private data ConnectionLogTypeSentPrivate, - ConnectionLogTypeErrorGeneric, + // Parse error + ConnectionLogTypeErrorParse, + // Error while receiving data - log() is called with a NULL buffer. ConnectionLogTypeErrorReceived, + // Error while sending data - log() is called with a NULL buffer. ConnectionLogTypeErrorSent, - ConnectionLogTypeErrorSentPrivate, }; class ConnectionLogger { public: - virtual void logBuffer(ConnectionLogType logType, Data * buffer) {} - virtual void logString(ConnectionLogType logType, String * log) {} + virtual void log(void * context, void * sender, ConnectionLogType logType, Data * buffer) {} + virtual void * context() { return NULL; } }; } diff --git a/src/core/basetypes/MCConnectionLoggerUtils.cc b/src/core/basetypes/MCConnectionLoggerUtils.cc index 669c8449..234713e7 100644 --- a/src/core/basetypes/MCConnectionLoggerUtils.cc +++ b/src/core/basetypes/MCConnectionLoggerUtils.cc @@ -14,21 +14,12 @@ mailcore::ConnectionLogType mailcore::getConnectionType(int log_type) { - ConnectionLogType type = ConnectionLogTypeGeneric; + ConnectionLogType type = (ConnectionLogType) -1; bool isBuffer = false; switch (log_type) { - case MAILSTREAM_LOG_TYPE_INFO_GENERIC: - type = ConnectionLogTypeGeneric; - break; - case MAILSTREAM_LOG_TYPE_INFO_RECEIVED: - type = ConnectionLogTypeReceived; - break; - case MAILSTREAM_LOG_TYPE_INFO_SENT: - type = ConnectionLogTypeSent; - break; - case MAILSTREAM_LOG_TYPE_ERROR_GENERIC: - type = ConnectionLogTypeErrorGeneric; + case MAILSTREAM_LOG_TYPE_ERROR_PARSE: + type = ConnectionLogTypeErrorParse; isBuffer = true; break; case MAILSTREAM_LOG_TYPE_ERROR_RECEIVED: @@ -60,9 +51,7 @@ bool mailcore::isBufferFromLogType(int log_type) bool isBuffer = false; switch (log_type) { - case MAILSTREAM_LOG_TYPE_ERROR_GENERIC: - case MAILSTREAM_LOG_TYPE_ERROR_RECEIVED: - case MAILSTREAM_LOG_TYPE_ERROR_SENT: + case MAILSTREAM_LOG_TYPE_ERROR_PARSE: case MAILSTREAM_LOG_TYPE_DATA_RECEIVED: case MAILSTREAM_LOG_TYPE_DATA_SENT: case MAILSTREAM_LOG_TYPE_DATA_SENT_PRIVATE: diff --git a/src/core/imap/MCIMAPSession.cc b/src/core/imap/MCIMAPSession.cc index 0b194ff7..9bd89f69 100644 --- a/src/core/imap/MCIMAPSession.cc +++ b/src/core/imap/MCIMAPSession.cc @@ -498,15 +498,17 @@ static void logger(mailimap * imap, int log_type, const char * buffer, size_t si return; ConnectionLogType type = getConnectionType(log_type); + if ((int) type == -1) + return; + bool isBuffer = isBufferFromLogType(log_type); if (isBuffer) { Data * data = Data::dataWithBytes(buffer, (unsigned int) size); - session->connectionLogger()->logBuffer(type, data); + session->connectionLogger()->log(session->connectionLogger()->context(), session, type, data); } else { - Data * data = Data::dataWithBytes(buffer, (unsigned int) size); - session->connectionLogger()->logString(type, String::stringWithData(data)); + session->connectionLogger()->log(session->connectionLogger()->context(), session, type, NULL); } } diff --git a/src/core/pop/MCPOPSession.cc b/src/core/pop/MCPOPSession.cc index fe15c500..9e771027 100644 --- a/src/core/pop/MCPOPSession.cc +++ b/src/core/pop/MCPOPSession.cc @@ -160,11 +160,10 @@ static void logger(mailpop3 * pop3, int log_type, const char * buffer, size_t si if (isBuffer) { Data * data = Data::dataWithBytes(buffer, (unsigned int) size); - session->connectionLogger()->logBuffer(type, data); + session->connectionLogger()->log(session->connectionLogger()->context(), session, type, data); } else { - Data * data = Data::dataWithBytes(buffer, (unsigned int) size); - session->connectionLogger()->logString(type, String::stringWithData(data)); + session->connectionLogger()->log(session->connectionLogger()->context(), session, type, NULL); } } diff --git a/src/core/smtp/MCSMTPSession.cc b/src/core/smtp/MCSMTPSession.cc index e74a540a..da2e19e5 100644 --- a/src/core/smtp/MCSMTPSession.cc +++ b/src/core/smtp/MCSMTPSession.cc @@ -164,7 +164,7 @@ void SMTPSession::bodyProgress(unsigned int current, unsigned int maximum) } -static void logger(mailsmtp * pop3, int log_type, const char * buffer, size_t size, void * context) +static void logger(mailsmtp * smtp, int log_type, const char * buffer, size_t size, void * context) { SMTPSession * session = (SMTPSession *) context; @@ -176,11 +176,10 @@ static void logger(mailsmtp * pop3, int log_type, const char * buffer, size_t si if (isBuffer) { Data * data = Data::dataWithBytes(buffer, (unsigned int) size); - session->connectionLogger()->logBuffer(type, data); + session->connectionLogger()->log(session->connectionLogger()->context(), session, type, data); } else { - Data * data = Data::dataWithBytes(buffer, (unsigned int) size); - session->connectionLogger()->logString(type, String::stringWithData(data)); + session->connectionLogger()->log(session->connectionLogger()->context(), session, type, NULL); } } -- cgit v1.2.3 From 74558e034a096331841a0327a48fdfc5ab095ec6 Mon Sep 17 00:00:00 2001 From: "Hoa V. DINH" Date: Wed, 26 Jun 2013 01:39:25 -0700 Subject: Added prebuilt.list to .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ef1ed6b8..73cdfa35 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,5 @@ xcuserdata project.xcworkspace example/ios/iOS UI Test/DerivedData - +scripts/prebuilt.list -- cgit v1.2.3 From e8649c3ecfc093e379439aa4e88910b3dc27422e Mon Sep 17 00:00:00 2001 From: "Hoa V. DINH" Date: Wed, 26 Jun 2013 02:35:34 -0700 Subject: Logger API for SMTP, POP --- src/async/imap/MCIMAPAsyncConnection.cc | 2 +- src/async/imap/MCIMAPAsyncSession.h | 1 - src/async/pop/MCPOPAsyncSession.cc | 58 +++++++++++++++++++++++++++++++++ src/async/pop/MCPOPAsyncSession.h | 9 ++++- src/async/smtp/MCSMTPAsyncSession.cc | 57 ++++++++++++++++++++++++++++++++ src/async/smtp/MCSMTPAsyncSession.h | 10 +++++- 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); }; -- cgit v1.2.3 From b17b5d9ebf687241f177c562f7db96f7e5e637cb Mon Sep 17 00:00:00 2001 From: "Hoa V. DINH" Date: Wed, 26 Jun 2013 03:19:20 -0700 Subject: Implemented logging API for SMTP, POP and IMAP --- src/async/imap/MCIMAPAsyncSession.h | 2 +- src/objc/abstract/MCOConstants.h | 24 +++++++++++++++ src/objc/imap/MCOIMAPSession.h | 9 ++++++ src/objc/imap/MCOIMAPSession.mm | 56 +++++++++++++++++++++++++++++++++-- src/objc/pop/MCOPOPSession.h | 9 ++++++ src/objc/pop/MCOPOPSession.mm | 58 +++++++++++++++++++++++++++++++++++-- src/objc/smtp/MCOSMTPSession.h | 9 ++++++ src/objc/smtp/MCOSMTPSession.mm | 58 +++++++++++++++++++++++++++++++++++-- 8 files changed, 215 insertions(+), 10 deletions(-) diff --git a/src/async/imap/MCIMAPAsyncSession.h b/src/async/imap/MCIMAPAsyncSession.h index d7f95407..ded3ffae 100644 --- a/src/async/imap/MCIMAPAsyncSession.h +++ b/src/async/imap/MCIMAPAsyncSession.h @@ -127,7 +127,7 @@ namespace mailcore { virtual IMAPOperation * checkAccountOperation(); virtual IMAPCapabilityOperation * capabilityOperation(); - + private: Array * mSessions; diff --git a/src/objc/abstract/MCOConstants.h b/src/objc/abstract/MCOConstants.h index 8fafabf3..a1916ef1 100644 --- a/src/objc/abstract/MCOConstants.h +++ b/src/objc/abstract/MCOConstants.h @@ -324,4 +324,28 @@ typedef enum { MCOErrorInvalidAccount, } MCOErrorCode; +/** Here's the list of connection log types.*/ +typedef enum { + /** Received data.*/ + MCOConnectionLogTypeReceived, + /** Sent data.*/ + MCOConnectionLogTypeSent, + /** Sent private data. It can be a password.*/ + MCOConnectionLogTypeSentPrivate, + /** Parse error.*/ + MCOConnectionLogTypeErrorParse, + /** Error while receiving data. The data passed to the log will be nil.*/ + MCOConnectionLogTypeErrorReceived, + /** Error while sending dataThe data passed to the log will be nil.*/ + MCOConnectionLogTypeErrorSent, +} MCOConnectionLogType; + +/** + It's a network traffic logger. + @param connectionID is the identifier of the underlaying network socket. + @param type is the type of the log. + @param data is the data related to the log. + */ +typedef void (^MCOConnectionLogger)(void * connectionID, MCOConnectionLogType type, NSData * data); + #endif diff --git a/src/objc/imap/MCOIMAPSession.h b/src/objc/imap/MCOIMAPSession.h index 1b394eff..0358f7ad 100644 --- a/src/objc/imap/MCOIMAPSession.h +++ b/src/objc/imap/MCOIMAPSession.h @@ -90,6 +90,15 @@ */ @property (nonatomic, assign) unsigned int maximumConnections; +/** + Sets logger callback. The network traffic will be sent to this block. + + [session setConnectionLogger:^(void * connectionID, MCOConnectionLogType type, NSData * data) { + ... + }]; +*/ +@property (nonatomic, copy) MCOConnectionLogger connectionLogger; + /** @name Folder Operations */ /** diff --git a/src/objc/imap/MCOIMAPSession.mm b/src/objc/imap/MCOIMAPSession.mm index a8df8aed..43f366e6 100644 --- a/src/objc/imap/MCOIMAPSession.mm +++ b/src/objc/imap/MCOIMAPSession.mm @@ -22,8 +22,32 @@ using namespace mailcore; +@interface MCOIMAPSession () + +- (void) _logWithSender:(void *)sender connectionType:(MCOConnectionLogType)logType data:(NSData *)data; + +@end + +class MCOIMAPConnectionLoggerBridge : public Object, public ConnectionLogger { +public: + MCOIMAPConnectionLoggerBridge(MCOIMAPSession * session) + { + mSession = session; + } + + virtual void log(void * context, void * sender, ConnectionLogType logType, Data * data) + { + [mSession _logWithSender:sender connectionType:(MCOConnectionLogType)logType data:MCO_TO_OBJC(data)]; + } + +private: + MCOIMAPSession * mSession; +}; + @implementation MCOIMAPSession { IMAPAsyncSession * _session; + MCOConnectionLogger _connectionLogger; + MCOIMAPConnectionLoggerBridge * _loggerBridge; } #define nativeType mailcore::IMAPAsyncSession @@ -35,13 +59,16 @@ using namespace mailcore; - (id)init { self = [super init]; - if (self) { - _session = new IMAPAsyncSession(); - } + + _session = new IMAPAsyncSession(); + _loggerBridge = new MCOIMAPConnectionLoggerBridge(self); + return self; } - (void)dealloc { + MC_SAFE_RELEASE(_loggerBridge); + [_connectionLogger release]; _session->release(); [super dealloc]; } @@ -59,6 +86,24 @@ MCO_OBJC_SYNTHESIZE_SCALAR(char, char, setDelimiter, delimiter) MCO_OBJC_SYNTHESIZE_SCALAR(BOOL, BOOL, setAllowsFolderConcurrentAccessEnabled, allowsFolderConcurrentAccessEnabled) MCO_OBJC_SYNTHESIZE_SCALAR(unsigned int, unsigned int, setMaximumConnections, maximumConnections) +- (void) setConnectionLogger:(MCOConnectionLogger)connectionLogger +{ + [_connectionLogger release]; + _connectionLogger = [connectionLogger copy]; + + if (_connectionLogger != nil) { + _session->setConnectionLogger(_loggerBridge); + } + else { + _session->setConnectionLogger(NULL); + } +} + +- (MCOConnectionLogger) connectionLogger +{ + return _connectionLogger; +} + #pragma mark - Operations #define MCO_TO_OBJC_OP(op) [self _objcOperationFromNativeOp:op]; @@ -303,4 +348,9 @@ MCO_OBJC_SYNTHESIZE_SCALAR(unsigned int, unsigned int, setMaximumConnections, ma return MCO_TO_OBJC_OP(coreOp); } +- (void) _logWithSender:(void *)sender connectionType:(MCOConnectionLogType)logType data:(NSData *)data +{ + _connectionLogger(sender, logType, data); +} + @end diff --git a/src/objc/pop/MCOPOPSession.h b/src/objc/pop/MCOPOPSession.h index 6ecca042..4f98421c 100644 --- a/src/objc/pop/MCOPOPSession.h +++ b/src/objc/pop/MCOPOPSession.h @@ -53,6 +53,15 @@ See MCOConnectionType for more information.*/ /** When set to YES, the connection will fail if the certificate is incorrect.*/ @property (nonatomic, assign, getter=isCheckCertificateEnabled) BOOL checkCertificateEnabled; +/** + Sets logger callback. The network traffic will be sent to this block. + + [session setConnectionLogger:^(void * connectionID, MCOConnectionLogType type, NSData * data) { + ... + }]; + */ +@property (nonatomic, copy) MCOConnectionLogger connectionLogger; + /** @name Operations */ /** diff --git a/src/objc/pop/MCOPOPSession.mm b/src/objc/pop/MCOPOPSession.mm index 11f7cad6..42c76646 100644 --- a/src/objc/pop/MCOPOPSession.mm +++ b/src/objc/pop/MCOPOPSession.mm @@ -16,8 +16,34 @@ #import "MCOPOPFetchMessagesOperation.h" #import "MCOPOPOperation+Private.h" +using namespace mailcore; + +@interface MCOPOPSession () + +- (void) _logWithSender:(void *)sender connectionType:(MCOConnectionLogType)logType data:(NSData *)data; + +@end + +class MCOPOPConnectionLoggerBridge : public Object, public ConnectionLogger { +public: + MCOPOPConnectionLoggerBridge(MCOPOPSession * session) + { + mSession = session; + } + + virtual void log(void * context, void * sender, ConnectionLogType logType, Data * data) + { + [mSession _logWithSender:sender connectionType:(MCOConnectionLogType)logType data:MCO_TO_OBJC(data)]; + } + +private: + MCOPOPSession * mSession; +}; + @implementation MCOPOPSession { mailcore::POPAsyncSession * _session; + MCOConnectionLogger _connectionLogger; + MCOPOPConnectionLoggerBridge * _loggerBridge; } #define nativeType mailcore::POPAsyncSession @@ -34,13 +60,16 @@ - (id)init { self = [super init]; - if (self) { - _session = new mailcore::POPAsyncSession(); - } + + _session = new mailcore::POPAsyncSession(); + _loggerBridge = new MCOPOPConnectionLoggerBridge(self); + return self; } - (void)dealloc { + MC_SAFE_RELEASE(_loggerBridge); + [_connectionLogger release]; _session->release(); [super dealloc]; } @@ -54,6 +83,24 @@ MCO_OBJC_SYNTHESIZE_SCALAR(MCOConnectionType, mailcore::ConnectionType, setConne MCO_OBJC_SYNTHESIZE_SCALAR(NSTimeInterval, time_t, setTimeout, timeout) MCO_OBJC_SYNTHESIZE_BOOL(setCheckCertificateEnabled, isCheckCertificateEnabled) +- (void) setConnectionLogger:(MCOConnectionLogger)connectionLogger +{ + [_connectionLogger release]; + _connectionLogger = [connectionLogger copy]; + + if (_connectionLogger != nil) { + _session->setConnectionLogger(_loggerBridge); + } + else { + _session->setConnectionLogger(NULL); + } +} + +- (MCOConnectionLogger) connectionLogger +{ + return _connectionLogger; +} + #pragma mark - Operations @@ -111,4 +158,9 @@ MCO_OBJC_SYNTHESIZE_BOOL(setCheckCertificateEnabled, isCheckCertificateEnabled) return OPAQUE_OPERATION(coreOp); } +- (void) _logWithSender:(void *)sender connectionType:(MCOConnectionLogType)logType data:(NSData *)data +{ + _connectionLogger(sender, logType, data); +} + @end diff --git a/src/objc/smtp/MCOSMTPSession.h b/src/objc/smtp/MCOSMTPSession.h index 08189bed..44d37942 100644 --- a/src/objc/smtp/MCOSMTPSession.h +++ b/src/objc/smtp/MCOSMTPSession.h @@ -64,6 +64,15 @@ */ @property (nonatomic, assign, getter=isUseHeloIPEnabled) BOOL useHeloIPEnabled; +/** + Sets logger callback. The network traffic will be sent to this block. + + [session setConnectionLogger:^(void * connectionID, MCOConnectionLogType type, NSData * data) { + ... + }]; + */ +@property (nonatomic, copy) MCOConnectionLogger connectionLogger; + /** @name Operations */ /** diff --git a/src/objc/smtp/MCOSMTPSession.mm b/src/objc/smtp/MCOSMTPSession.mm index de6b54cd..1538d53a 100644 --- a/src/objc/smtp/MCOSMTPSession.mm +++ b/src/objc/smtp/MCOSMTPSession.mm @@ -17,8 +17,34 @@ #import "MCOAddress.h" #import "MCOSMTPOperation+Private.h" +using namespace mailcore; + +@interface MCOSMTPSession () + +- (void) _logWithSender:(void *)sender connectionType:(MCOConnectionLogType)logType data:(NSData *)data; + +@end + +class MCOSMTPConnectionLoggerBridge : public Object, public ConnectionLogger { +public: + MCOSMTPConnectionLoggerBridge(MCOSMTPSession * session) + { + mSession = session; + } + + virtual void log(void * context, void * sender, ConnectionLogType logType, Data * data) + { + [mSession _logWithSender:sender connectionType:(MCOConnectionLogType)logType data:MCO_TO_OBJC(data)]; + } + +private: + MCOSMTPSession * mSession; +}; + @implementation MCOSMTPSession { mailcore::SMTPAsyncSession * _session; + MCOConnectionLogger _connectionLogger; + MCOSMTPConnectionLoggerBridge * _loggerBridge; } #define nativeType mailcore::SMTPAsyncSession @@ -30,13 +56,16 @@ - (id)init { self = [super init]; - if (self) { - _session = new mailcore::SMTPAsyncSession(); - } + + _session = new mailcore::SMTPAsyncSession(); + _loggerBridge = new MCOSMTPConnectionLoggerBridge(self); + return self; } - (void)dealloc { + MC_SAFE_RELEASE(_loggerBridge); + [_connectionLogger release]; _session->release(); [super dealloc]; } @@ -51,6 +80,24 @@ MCO_OBJC_SYNTHESIZE_SCALAR(NSTimeInterval, time_t, setTimeout, timeout) MCO_OBJC_SYNTHESIZE_BOOL(setCheckCertificateEnabled, isCheckCertificateEnabled) MCO_OBJC_SYNTHESIZE_BOOL(setUseHeloIPEnabled, useHeloIPEnabled) +- (void) setConnectionLogger:(MCOConnectionLogger)connectionLogger +{ + [_connectionLogger release]; + _connectionLogger = [connectionLogger copy]; + + if (_connectionLogger != nil) { + _session->setConnectionLogger(_loggerBridge); + } + else { + _session->setConnectionLogger(NULL); + } +} + +- (MCOConnectionLogger) connectionLogger +{ + return _connectionLogger; +} + #pragma mark - Operations - (MCOSMTPSendOperation *) sendOperationWithData:(NSData *)messageData @@ -69,4 +116,9 @@ MCO_OBJC_SYNTHESIZE_BOOL(setUseHeloIPEnabled, useHeloIPEnabled) return result; } +- (void) _logWithSender:(void *)sender connectionType:(MCOConnectionLogType)logType data:(NSData *)data +{ + _connectionLogger(sender, logType, data); +} + @end -- cgit v1.2.3 From 1b7e875e49b5dbac686587bde3158eec56600f91 Mon Sep 17 00:00:00 2001 From: "Hoa V. DINH" Date: Wed, 26 Jun 2013 03:31:08 -0700 Subject: Simplified logger C++ API --- src/async/imap/MCIMAPAsyncConnection.cc | 2 +- src/async/pop/MCPOPAsyncSession.cc | 2 +- src/async/smtp/MCSMTPAsyncSession.cc | 2 +- src/core/basetypes/MCConnectionLogger.h | 3 +-- src/core/imap/MCIMAPSession.cc | 4 ++-- src/core/pop/MCPOPSession.cc | 4 ++-- src/core/smtp/MCSMTPSession.cc | 4 ++-- 7 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/async/imap/MCIMAPAsyncConnection.cc b/src/async/imap/MCIMAPAsyncConnection.cc index 5753726a..232b343a 100644 --- a/src/async/imap/MCIMAPAsyncConnection.cc +++ b/src/async/imap/MCIMAPAsyncConnection.cc @@ -578,7 +578,7 @@ void IMAPAsyncConnection::logConnection(ConnectionLogType logType, Data * buffer { pthread_mutex_lock(&mConnectionLoggerLock); if (mConnectionLogger != NULL) { - mConnectionLogger->log(mConnectionLogger->context(), this, logType, buffer); + mConnectionLogger->log(this, logType, buffer); } pthread_mutex_unlock(&mConnectionLoggerLock); } diff --git a/src/async/pop/MCPOPAsyncSession.cc b/src/async/pop/MCPOPAsyncSession.cc index d72da0b3..5a49e022 100644 --- a/src/async/pop/MCPOPAsyncSession.cc +++ b/src/async/pop/MCPOPAsyncSession.cc @@ -247,7 +247,7 @@ void POPAsyncSession::logConnection(ConnectionLogType logType, Data * buffer) { pthread_mutex_lock(&mConnectionLoggerLock); if (mConnectionLogger != NULL) { - mConnectionLogger->log(mConnectionLogger->context(), this, logType, buffer); + mConnectionLogger->log(this, logType, buffer); } pthread_mutex_unlock(&mConnectionLoggerLock); } diff --git a/src/async/smtp/MCSMTPAsyncSession.cc b/src/async/smtp/MCSMTPAsyncSession.cc index c1ff90c9..d680abee 100644 --- a/src/async/smtp/MCSMTPAsyncSession.cc +++ b/src/async/smtp/MCSMTPAsyncSession.cc @@ -237,7 +237,7 @@ void SMTPAsyncSession::logConnection(ConnectionLogType logType, Data * buffer) { pthread_mutex_lock(&mConnectionLoggerLock); if (mConnectionLogger != NULL) { - mConnectionLogger->log(mConnectionLogger->context(), this, logType, buffer); + mConnectionLogger->log(this, logType, buffer); } pthread_mutex_unlock(&mConnectionLoggerLock); } diff --git a/src/core/basetypes/MCConnectionLogger.h b/src/core/basetypes/MCConnectionLogger.h index 371e6152..dd596857 100644 --- a/src/core/basetypes/MCConnectionLogger.h +++ b/src/core/basetypes/MCConnectionLogger.h @@ -35,8 +35,7 @@ namespace mailcore { class ConnectionLogger { public: - virtual void log(void * context, void * sender, ConnectionLogType logType, Data * buffer) {} - virtual void * context() { return NULL; } + virtual void log(void * sender, ConnectionLogType logType, Data * buffer) {} }; } diff --git a/src/core/imap/MCIMAPSession.cc b/src/core/imap/MCIMAPSession.cc index 9bd89f69..2dc970c5 100644 --- a/src/core/imap/MCIMAPSession.cc +++ b/src/core/imap/MCIMAPSession.cc @@ -505,10 +505,10 @@ static void logger(mailimap * imap, int log_type, const char * buffer, size_t si if (isBuffer) { Data * data = Data::dataWithBytes(buffer, (unsigned int) size); - session->connectionLogger()->log(session->connectionLogger()->context(), session, type, data); + session->connectionLogger()->log(session, type, data); } else { - session->connectionLogger()->log(session->connectionLogger()->context(), session, type, NULL); + session->connectionLogger()->log(session, type, NULL); } } diff --git a/src/core/pop/MCPOPSession.cc b/src/core/pop/MCPOPSession.cc index 9e771027..fea4e5e0 100644 --- a/src/core/pop/MCPOPSession.cc +++ b/src/core/pop/MCPOPSession.cc @@ -160,10 +160,10 @@ static void logger(mailpop3 * pop3, int log_type, const char * buffer, size_t si if (isBuffer) { Data * data = Data::dataWithBytes(buffer, (unsigned int) size); - session->connectionLogger()->log(session->connectionLogger()->context(), session, type, data); + session->connectionLogger()->log(session, type, data); } else { - session->connectionLogger()->log(session->connectionLogger()->context(), session, type, NULL); + session->connectionLogger()->log(session, type, NULL); } } diff --git a/src/core/smtp/MCSMTPSession.cc b/src/core/smtp/MCSMTPSession.cc index da2e19e5..dcbad71e 100644 --- a/src/core/smtp/MCSMTPSession.cc +++ b/src/core/smtp/MCSMTPSession.cc @@ -176,10 +176,10 @@ static void logger(mailsmtp * smtp, int log_type, const char * buffer, size_t si if (isBuffer) { Data * data = Data::dataWithBytes(buffer, (unsigned int) size); - session->connectionLogger()->log(session->connectionLogger()->context(), session, type, data); + session->connectionLogger()->log(session, type, data); } else { - session->connectionLogger()->log(session->connectionLogger()->context(), session, type, NULL); + session->connectionLogger()->log(session, type, NULL); } } -- cgit v1.2.3 From 70a503cd49da7b222edb0ed1238fb597de581c1c Mon Sep 17 00:00:00 2001 From: "Hoa V. DINH" Date: Wed, 26 Jun 2013 03:34:50 -0700 Subject: Added one argument to the operation queue callback. It might be useful when an object owns several queues. --- src/core/basetypes/MCOperationQueue.cc | 4 ++-- src/core/basetypes/MCOperationQueueCallback.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/basetypes/MCOperationQueue.cc b/src/core/basetypes/MCOperationQueue.cc index d4529fab..9c30ad22 100644 --- a/src/core/basetypes/MCOperationQueue.cc +++ b/src/core/basetypes/MCOperationQueue.cc @@ -159,7 +159,7 @@ void OperationQueue::stoppedOnMainThread(void * context) mStarted = false; if (mCallback) { - mCallback->queueStoppedRunning(); + mCallback->queueStoppedRunning(this); } release(); // (2) @@ -173,7 +173,7 @@ void OperationQueue::startThread() return; if (mCallback) { - mCallback->queueStartRunning(); + mCallback->queueStartRunning(this); } retain(); // (3) diff --git a/src/core/basetypes/MCOperationQueueCallback.h b/src/core/basetypes/MCOperationQueueCallback.h index 367888bb..605de030 100644 --- a/src/core/basetypes/MCOperationQueueCallback.h +++ b/src/core/basetypes/MCOperationQueueCallback.h @@ -15,8 +15,8 @@ namespace mailcore { class OperationQueueCallback { public: - virtual void queueStartRunning() {} - virtual void queueStoppedRunning() {} + virtual void queueStartRunning(OperationQueue * queue) {} + virtual void queueStoppedRunning(OperationQueue * queue) {} }; } -- cgit v1.2.3 From 56fa4fe95e3c387ee9b2907454d5ad12ebae799e Mon Sep 17 00:00:00 2001 From: "Hoa V. DINH" Date: Thu, 27 Jun 2013 01:40:39 -0700 Subject: Fixed some memory leaks --- src/core/basetypes/MCHTMLCleaner.cc | 1 + src/core/basetypes/MCString.cc | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/core/basetypes/MCHTMLCleaner.cc b/src/core/basetypes/MCHTMLCleaner.cc index 12f1371e..7d45d3f2 100644 --- a/src/core/basetypes/MCHTMLCleaner.cc +++ b/src/core/basetypes/MCHTMLCleaner.cc @@ -68,6 +68,7 @@ String * HTMLCleaner::cleanHTML(String * input) String * result = String::stringWithUTF8Characters((const char *) output.bp); + tidyBufFree(&docbuf); tidyBufFree(&output); tidyBufFree(&errbuf); tidyRelease(tdoc); diff --git a/src/core/basetypes/MCString.cc b/src/core/basetypes/MCString.cc index 832ffac2..2c0311dd 100644 --- a/src/core/basetypes/MCString.cc +++ b/src/core/basetypes/MCString.cc @@ -781,7 +781,9 @@ String * String::stringWithVUTF8Format(const char * format, va_list ap) { char * result; vasprintf(&result, format, ap); - return stringWithUTF8Characters(result); + String * str = stringWithUTF8Characters(result); + free(result); + return str; } String * String::stringWithUTF8Characters(const char * UTF8Characters) -- cgit v1.2.3 From 29bc4a2eac587c83f1de1ecf5ee5dc2299452966 Mon Sep 17 00:00:00 2001 From: "Hoa V. Dinh" Date: Thu, 27 Jun 2013 10:50:35 -0700 Subject: Fixed callback usage --- src/async/imap/MCIMAPAsyncConnection.cc | 4 ++-- src/async/pop/MCPOPAsyncSession.cc | 4 ++-- src/async/smtp/MCSMTPAsyncSession.cc | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/async/imap/MCIMAPAsyncConnection.cc b/src/async/imap/MCIMAPAsyncConnection.cc index 232b343a..a4244ed3 100644 --- a/src/async/imap/MCIMAPAsyncConnection.cc +++ b/src/async/imap/MCIMAPAsyncConnection.cc @@ -47,11 +47,11 @@ namespace mailcore { virtual ~IMAPOperationQueueCallback() { } - virtual void queueStartRunning() { + virtual void queueStartRunning(OperationQueue * queue) { mConnection->queueStartRunning(); } - virtual void queueStoppedRunning() { + virtual void queueStoppedRunning(OperationQueue * queue) { mConnection->tryAutomaticDisconnect(); mConnection->queueStoppedRunning(); } diff --git a/src/async/pop/MCPOPAsyncSession.cc b/src/async/pop/MCPOPAsyncSession.cc index 5a49e022..342b0f5e 100644 --- a/src/async/pop/MCPOPAsyncSession.cc +++ b/src/async/pop/MCPOPAsyncSession.cc @@ -29,11 +29,11 @@ namespace mailcore { virtual ~POPOperationQueueCallback() { } - virtual void queueStartRunning() { + virtual void queueStartRunning(OperationQueue * queue) { mSession->retain(); } - virtual void queueStoppedRunning() { + virtual void queueStoppedRunning(OperationQueue * queue) { mSession->release(); } diff --git a/src/async/smtp/MCSMTPAsyncSession.cc b/src/async/smtp/MCSMTPAsyncSession.cc index d680abee..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(); } -- cgit v1.2.3