aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objc/imap/MCOIMAPSession.mm
diff options
context:
space:
mode:
authorGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2013-06-26 03:19:20 -0700
committerGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2013-06-26 03:19:20 -0700
commitb17b5d9ebf687241f177c562f7db96f7e5e637cb (patch)
tree5647172399f90ab04ef5fb226bf34c5e6cb2d0c6 /src/objc/imap/MCOIMAPSession.mm
parente8649c3ecfc093e379439aa4e88910b3dc27422e (diff)
Implemented logging API for SMTP, POP and IMAP
Diffstat (limited to 'src/objc/imap/MCOIMAPSession.mm')
-rw-r--r--src/objc/imap/MCOIMAPSession.mm56
1 files changed, 53 insertions, 3 deletions
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