From b2cdde047f8e9c9ce8201d701785fe2d28fa743c Mon Sep 17 00:00:00 2001 From: Paul Young Date: Sun, 30 Jun 2013 19:29:48 -0400 Subject: Renamed mailcore::logEnabled and mailcore::logInternal to MCLogEnabled and MCLogInternal as discussed in MailCore/mailcore2#118. * Followed the diff in MailCore/mailcore2#124. * Renamed the implementation file from .cc to .c * Added `extern "C" {}` around header declaration. --- src/core/basetypes/MCLog.c | 79 +++++++++++++++++++++++++++++++++++++++++++++ src/core/basetypes/MCLog.cc | 79 --------------------------------------------- src/core/basetypes/MCLog.h | 22 ++++++++----- 3 files changed, 93 insertions(+), 87 deletions(-) create mode 100644 src/core/basetypes/MCLog.c delete mode 100644 src/core/basetypes/MCLog.cc (limited to 'src') diff --git a/src/core/basetypes/MCLog.c b/src/core/basetypes/MCLog.c new file mode 100644 index 00000000..f361c258 --- /dev/null +++ b/src/core/basetypes/MCLog.c @@ -0,0 +1,79 @@ +#include "MCLog.h" + +#include +#include +#include +#include +#include +#include +#include + +static pid_t sPid = -1; +bool MCLogEnabled = false; + +__attribute__((constructor)) +static void initialize() { + sPid = getpid(); +} + +static void logInternalv(FILE * file, + const char * user, const char * filename, unsigned int line, + int dumpStack, const char * format, va_list argp); + +void MCLogInternal(const char * user, + const char * filename, + unsigned int line, + int dumpStack, + const char * format, ...) +{ + va_list argp; + + va_start(argp, format); + logInternalv(stderr, user, filename, line, dumpStack, format, argp); + va_end(argp); +} + +static void logInternalv(FILE * file, + const char * user, const char * filename, unsigned int line, + int dumpStack, const char * format, va_list argp) +{ + if (!mailcore::logEnabled) + return; + + while (1) { + const char * p = filename; + + p = strchr(filename, '/'); + if (p == NULL) { + break; + } + filename = p + 1; + } + + struct timeval tv; + struct tm tm_value; + pthread_t thread_id = pthread_self(); + + gettimeofday(&tv, NULL); + localtime_r(&tv.tv_sec, &tm_value); + fprintf(file, "%04u-%02u-%02u %02u:%02u:%02u.%03u ", tm_value.tm_year + 1900, tm_value.tm_mon + 1, tm_value.tm_mday, tm_value.tm_hour, tm_value.tm_min, tm_value.tm_sec, (int) (tv.tv_usec / 1000)); + +#ifdef __MACH__ + if (pthread_main_np()) { +#else + if (0) { +#endif + fprintf(file, "[%i:main] %s:%i: ", sPid, filename, line); + } + else { + unsigned long threadValue; +#ifdef _MACH_PORT_T + threadValue = pthread_mach_thread_np(thread_id); +#else + threadValue = (unsigned long) thread_id; +#endif + fprintf(file, "[%i:%lx] %s:%i: ", sPid, threadValue, filename, line); + } + vfprintf(file, format, argp); + fprintf(file, "\n"); +} diff --git a/src/core/basetypes/MCLog.cc b/src/core/basetypes/MCLog.cc deleted file mode 100644 index 7db01b41..00000000 --- a/src/core/basetypes/MCLog.cc +++ /dev/null @@ -1,79 +0,0 @@ -#include "MCLog.h" - -#include -#include -#include -#include -#include -#include -#include - -static pid_t sPid = -1; -bool mailcore::logEnabled = false; - -__attribute__((constructor)) -static void initialize() { - sPid = getpid(); -} - -static void logInternalv(FILE * file, - const char * user, const char * filename, unsigned int line, - int dumpStack, const char * format, va_list argp); - -void mailcore::logInternal(const char * user, - const char * filename, - unsigned int line, - int dumpStack, - const char * format, ...) -{ - va_list argp; - - va_start(argp, format); - logInternalv(stderr, user, filename, line, dumpStack, format, argp); - va_end(argp); -} - -static void logInternalv(FILE * file, - const char * user, const char * filename, unsigned int line, - int dumpStack, const char * format, va_list argp) -{ - if (!mailcore::logEnabled) - return; - - while (1) { - const char * p = filename; - - p = strchr(filename, '/'); - if (p == NULL) { - break; - } - filename = p + 1; - } - - struct timeval tv; - struct tm tm_value; - pthread_t thread_id = pthread_self(); - - gettimeofday(&tv, NULL); - localtime_r(&tv.tv_sec, &tm_value); - fprintf(file, "%04u-%02u-%02u %02u:%02u:%02u.%03u ", tm_value.tm_year + 1900, tm_value.tm_mon + 1, tm_value.tm_mday, tm_value.tm_hour, tm_value.tm_min, tm_value.tm_sec, (int) (tv.tv_usec / 1000)); - -#ifdef __MACH__ - if (pthread_main_np()) { -#else - if (0) { -#endif - fprintf(file, "[%i:main] %s:%i: ", sPid, filename, line); - } - else { - unsigned long threadValue; -#ifdef _MACH_PORT_T - threadValue = pthread_mach_thread_np(thread_id); -#else - threadValue = (unsigned long) thread_id; -#endif - fprintf(file, "[%i:%lx] %s:%i: ", sPid, threadValue, filename, line); - } - vfprintf(file, format, argp); - fprintf(file, "\n"); -} diff --git a/src/core/basetypes/MCLog.h b/src/core/basetypes/MCLog.h index b84a2182..f4e940e2 100644 --- a/src/core/basetypes/MCLog.h +++ b/src/core/basetypes/MCLog.h @@ -6,22 +6,28 @@ #ifdef __cplusplus -#define MCLog(...) mailcore::logInternal(NULL, __FILE__, __LINE__, 0, __VA_ARGS__) +#define MCLog(...) MCLogInternal(NULL, __FILE__, __LINE__, 0, __VA_ARGS__) namespace mailcore { - extern bool logEnabled; + extern bool MCLogEnabled; #ifndef __printflike #define __printflike(a,b) #endif - void logInternal(const char * user, - const char * filename, - unsigned int line, - int dumpStack, - const char * format, ...) __printflike(5, 6); - +#ifdef __cplusplus +extern "C" { +#endif + void MCLogInternal(const char * user, + const char * filename, + unsigned int line, + int dumpStack, + const char * format, ...) __printflike(5, 6); +#ifdef __cplusplus +} +#endif + } #endif -- cgit v1.2.3 From cd1277b20cc085d9de2c8b0d3588ea37377501ca Mon Sep 17 00:00:00 2001 From: Paul Young Date: Tue, 2 Jul 2013 22:35:17 -0400 Subject: Updated mailcore::logEnabled to MCLogEnabled in logInternalv. --- src/core/basetypes/MCLog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/core/basetypes/MCLog.c b/src/core/basetypes/MCLog.c index f361c258..60278d27 100644 --- a/src/core/basetypes/MCLog.c +++ b/src/core/basetypes/MCLog.c @@ -37,7 +37,7 @@ static void logInternalv(FILE * file, const char * user, const char * filename, unsigned int line, int dumpStack, const char * format, va_list argp) { - if (!mailcore::logEnabled) + if (!MCLogEnabled) return; while (1) { -- cgit v1.2.3 From e50fcbb5dc3603c0138a3844aaf514373bb52938 Mon Sep 17 00:00:00 2001 From: Paul Young Date: Tue, 2 Jul 2013 22:43:37 -0400 Subject: Including the stdbool header. * As per http://stackoverflow.com/a/1921557/339925 --- src/core/basetypes/MCLog.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/core/basetypes/MCLog.c b/src/core/basetypes/MCLog.c index 60278d27..f3ce2318 100644 --- a/src/core/basetypes/MCLog.c +++ b/src/core/basetypes/MCLog.c @@ -7,6 +7,7 @@ #include #include #include +#include static pid_t sPid = -1; bool MCLogEnabled = false; -- cgit v1.2.3 From 7f6923f520745ff9f1dd4df142de96ecbe64e045 Mon Sep 17 00:00:00 2001 From: Paul Young Date: Wed, 3 Jul 2013 00:04:57 -0400 Subject: Updated type of MCLogEnabled to int instead of bool. --- example/ios/iOS UI Test/iOS UI Test/main.mm | 2 +- src/core/basetypes/MCLog.c | 3 +-- src/core/basetypes/MCLog.h | 2 +- tests/test-all.mm | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/example/ios/iOS UI Test/iOS UI Test/main.mm b/example/ios/iOS UI Test/iOS UI Test/main.mm index 0089973b..e6253102 100644 --- a/example/ios/iOS UI Test/iOS UI Test/main.mm +++ b/example/ios/iOS UI Test/iOS UI Test/main.mm @@ -12,6 +12,6 @@ #import int main(int argc, char *argv[]) { - MCLogEnabled = true; + MCLogEnabled = 1; return UIApplicationMain(argc, argv, nil, @"AppDelegate"); } diff --git a/src/core/basetypes/MCLog.c b/src/core/basetypes/MCLog.c index f3ce2318..8744f2dd 100644 --- a/src/core/basetypes/MCLog.c +++ b/src/core/basetypes/MCLog.c @@ -7,10 +7,9 @@ #include #include #include -#include static pid_t sPid = -1; -bool MCLogEnabled = false; +int MCLogEnabled = 0; __attribute__((constructor)) static void initialize() { diff --git a/src/core/basetypes/MCLog.h b/src/core/basetypes/MCLog.h index f4e940e2..de75314f 100644 --- a/src/core/basetypes/MCLog.h +++ b/src/core/basetypes/MCLog.h @@ -10,7 +10,7 @@ namespace mailcore { - extern bool MCLogEnabled; + extern int MCLogEnabled; #ifndef __printflike #define __printflike(a,b) diff --git a/tests/test-all.mm b/tests/test-all.mm index 4155bbb2..fdb0888c 100644 --- a/tests/test-all.mm +++ b/tests/test-all.mm @@ -351,7 +351,7 @@ void testAll() displayName = MCSTR("My Email"); mailcore::AutoreleasePool * pool = new mailcore::AutoreleasePool(); - MCLogEnabled = true; + MCLogEnabled = 1; mailstream_debug = 1; //mailcore::Data * data = testMessageBuilder(); -- cgit v1.2.3 From 6f2d15d22afaf947690d895047a7ea6a9d8bad8c Mon Sep 17 00:00:00 2001 From: "Hoa V. DINH" Date: Wed, 3 Jul 2013 23:14:18 -0400 Subject: Fixed logger --- example/ios/iOS UI Test/iOS UI Test/MasterViewController.m | 11 +++++++++-- scripts/prepare-libetpan-ios.sh | 2 +- scripts/prepare-libetpan-macos.sh | 2 +- src/async/imap/MCIMAPAsyncConnection.cc | 2 +- src/async/pop/MCPOPAsyncSession.cc | 2 +- src/async/smtp/MCSMTPAsyncSession.cc | 2 +- src/core/basetypes/MCConnectionLogger.h | 1 - src/objc/imap/MCOIMAPSession.mm | 2 +- src/objc/pop/MCOPOPSession.mm | 2 +- src/objc/smtp/MCOSMTPSession.mm | 2 +- 10 files changed, 17 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/example/ios/iOS UI Test/iOS UI Test/MasterViewController.m b/example/ios/iOS UI Test/iOS UI Test/MasterViewController.m index c9866ff8..3e5e4422 100644 --- a/example/ios/iOS UI Test/iOS UI Test/MasterViewController.m +++ b/example/ios/iOS UI Test/iOS UI Test/MasterViewController.m @@ -45,9 +45,16 @@ self.imapSession.username = username; self.imapSession.password = password; self.imapSession.connectionType = MCOConnectionTypeTLS; - + MasterViewController * __weak weakSelf = self; + self.imapSession.connectionLogger = ^(void * connectionID, MCOConnectionLogType type, NSData * data) { + @synchronized(weakSelf) { + if (type != MCOConnectionLogTypeSentPrivate) { + NSLog(@"event logged:%p %i withData: %@", connectionID, type, [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]); + } + } + }; + NSLog(@"checking account"); - __weak MasterViewController *weakSelf = self; self.imapCheckOp = [self.imapSession checkAccountOperation]; [self.imapCheckOp start:^(NSError *error) { MasterViewController *strongSelf = weakSelf; diff --git a/scripts/prepare-libetpan-ios.sh b/scripts/prepare-libetpan-ios.sh index 7a5a054b..ea109b5d 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=78427a0506be00e1e72ac8f88aa4b71bebd4137f +rev=517a7fb7c47d925f67cc48ddf9636170c74ecd9e pushd `dirname $0` > /dev/null scriptpath=`pwd` diff --git a/scripts/prepare-libetpan-macos.sh b/scripts/prepare-libetpan-macos.sh index 81013fa6..c8eaf26b 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=78427a0506be00e1e72ac8f88aa4b71bebd4137f +rev=517a7fb7c47d925f67cc48ddf9636170c74ecd9e pushd `dirname $0` > /dev/null scriptpath=`pwd` diff --git a/src/async/imap/MCIMAPAsyncConnection.cc b/src/async/imap/MCIMAPAsyncConnection.cc index fc1935b7..1d07f79a 100644 --- a/src/async/imap/MCIMAPAsyncConnection.cc +++ b/src/async/imap/MCIMAPAsyncConnection.cc @@ -69,7 +69,7 @@ namespace mailcore { virtual ~IMAPConnectionLogger() { } - virtual void log(void * context, void * sender, ConnectionLogType logType, Data * buffer) + virtual void log(void * sender, ConnectionLogType logType, Data * buffer) { mConnection->logConnection(logType, buffer); } diff --git a/src/async/pop/MCPOPAsyncSession.cc b/src/async/pop/MCPOPAsyncSession.cc index 342b0f5e..bfabc847 100644 --- a/src/async/pop/MCPOPAsyncSession.cc +++ b/src/async/pop/MCPOPAsyncSession.cc @@ -50,7 +50,7 @@ namespace mailcore { virtual ~POPConnectionLogger() { } - virtual void log(void * context, void * sender, ConnectionLogType logType, Data * buffer) + virtual void log(void * sender, ConnectionLogType logType, Data * buffer) { mSession->logConnection(logType, buffer); } diff --git a/src/async/smtp/MCSMTPAsyncSession.cc b/src/async/smtp/MCSMTPAsyncSession.cc index fafc2e82..38d57756 100644 --- a/src/async/smtp/MCSMTPAsyncSession.cc +++ b/src/async/smtp/MCSMTPAsyncSession.cc @@ -41,7 +41,7 @@ namespace mailcore { virtual ~SMTPConnectionLogger() { } - virtual void log(void * context, void * sender, ConnectionLogType logType, Data * buffer) + virtual void log(void * sender, ConnectionLogType logType, Data * buffer) { mSession->logConnection(logType, buffer); } diff --git a/src/core/basetypes/MCConnectionLogger.h b/src/core/basetypes/MCConnectionLogger.h index dd596857..bdb588bc 100644 --- a/src/core/basetypes/MCConnectionLogger.h +++ b/src/core/basetypes/MCConnectionLogger.h @@ -16,7 +16,6 @@ namespace mailcore { class Data; - class String; enum ConnectionLogType { // Received data diff --git a/src/objc/imap/MCOIMAPSession.mm b/src/objc/imap/MCOIMAPSession.mm index 43f366e6..0c23f1e2 100644 --- a/src/objc/imap/MCOIMAPSession.mm +++ b/src/objc/imap/MCOIMAPSession.mm @@ -35,7 +35,7 @@ public: mSession = session; } - virtual void log(void * context, void * sender, ConnectionLogType logType, Data * data) + virtual void log(void * sender, ConnectionLogType logType, Data * data) { [mSession _logWithSender:sender connectionType:(MCOConnectionLogType)logType data:MCO_TO_OBJC(data)]; } diff --git a/src/objc/pop/MCOPOPSession.mm b/src/objc/pop/MCOPOPSession.mm index 42c76646..fb48cb1e 100644 --- a/src/objc/pop/MCOPOPSession.mm +++ b/src/objc/pop/MCOPOPSession.mm @@ -31,7 +31,7 @@ public: mSession = session; } - virtual void log(void * context, void * sender, ConnectionLogType logType, Data * data) + virtual void log(void * sender, ConnectionLogType logType, Data * data) { [mSession _logWithSender:sender connectionType:(MCOConnectionLogType)logType data:MCO_TO_OBJC(data)]; } diff --git a/src/objc/smtp/MCOSMTPSession.mm b/src/objc/smtp/MCOSMTPSession.mm index 1538d53a..1cadf4ad 100644 --- a/src/objc/smtp/MCOSMTPSession.mm +++ b/src/objc/smtp/MCOSMTPSession.mm @@ -32,7 +32,7 @@ public: mSession = session; } - virtual void log(void * context, void * sender, ConnectionLogType logType, Data * data) + virtual void log(void * sender, ConnectionLogType logType, Data * data) { [mSession _logWithSender:sender connectionType:(MCOConnectionLogType)logType data:MCO_TO_OBJC(data)]; } -- cgit v1.2.3 From 160f1ab92c8a9a329745034558a009678aa63b4f Mon Sep 17 00:00:00 2001 From: "Hoa V. DINH" Date: Wed, 3 Jul 2013 23:24:43 -0400 Subject: Fixed IDLE behavior --- src/async/imap/MCIMAPIdleOperation.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/async/imap/MCIMAPIdleOperation.cc b/src/async/imap/MCIMAPIdleOperation.cc index 42c58f90..8b48b77c 100644 --- a/src/async/imap/MCIMAPIdleOperation.cc +++ b/src/async/imap/MCIMAPIdleOperation.cc @@ -47,7 +47,7 @@ void IMAPIdleOperation::unprepare() void IMAPIdleOperation::main() { - performMethodOnMainThread((Object::Method) &IMAPIdleOperation::prepare, NULL); + performMethodOnMainThread((Object::Method) &IMAPIdleOperation::prepare, NULL, true); if (!mSetupSuccess) { return; @@ -57,7 +57,7 @@ void IMAPIdleOperation::main() session()->session()->idle(folder(), mLastKnownUid, &error); setError(error); - performMethodOnMainThread((Object::Method) &IMAPIdleOperation::unprepare, NULL); + performMethodOnMainThread((Object::Method) &IMAPIdleOperation::unprepare, NULL, true); } void IMAPIdleOperation::interruptIdle() -- cgit v1.2.3