aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objc/smtp
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/smtp
parente8649c3ecfc093e379439aa4e88910b3dc27422e (diff)
Implemented logging API for SMTP, POP and IMAP
Diffstat (limited to 'src/objc/smtp')
-rw-r--r--src/objc/smtp/MCOSMTPSession.h9
-rw-r--r--src/objc/smtp/MCOSMTPSession.mm58
2 files changed, 64 insertions, 3 deletions
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