From fdf33f356a769fe1000486331e8ae7bf9d7d2f55 Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Mon, 12 Dec 2011 00:27:32 +0100 Subject: [PATCH] Add a delegate for incoming/outgoing elements. --- src/XMPPConnection.h | 4 ++++ src/XMPPConnection.m | 11 +++++++++-- tests/test.m | 12 ++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/XMPPConnection.h b/src/XMPPConnection.h index a976a7d..00f91e5 100644 --- a/src/XMPPConnection.h +++ b/src/XMPPConnection.h @@ -40,6 +40,10 @@ #ifdef OF_HAVE_OPTIONAL_PROTOCOLS @optional #endif +- (void)connection: (XMPPConnection*)connection + didReceiveElement: (OFXMLElement*)element; +- (void)connection: (XMPPConnection*)connection + didSendElement: (OFXMLElement*)element; - (void)connectionWasAuthenticated: (XMPPConnection*)connection; - (void)connection: (XMPPConnection*)connection wasBoundToJID: (XMPPJID*)JID; diff --git a/src/XMPPConnection.m b/src/XMPPConnection.m index fb83309..3f9bb81 100644 --- a/src/XMPPConnection.m +++ b/src/XMPPConnection.m @@ -344,7 +344,11 @@ - (void)sendStanza: (OFXMLElement*)element { - of_log(@"Out: %@", element); + if ([delegate respondsToSelector: + @selector(connection:didSendElement:)]) + [delegate connection: self + didSendElement: element]; + [sock writeString: [element XMLString]]; } @@ -404,7 +408,10 @@ [element setPrefix: @"stream" forNamespace: XMPP_NS_STREAM]; - of_log(@"In: %@", element); + if ([delegate respondsToSelector: + @selector(connection:didReceiveElement:)]) + [delegate connection: self + didReceiveElement: element]; if ([[element namespace] isEqual: XMPP_NS_CLIENT]) [self XMPP_handleStanza: element]; diff --git a/tests/test.m b/tests/test.m index 74c36e7..0df3f1a 100644 --- a/tests/test.m +++ b/tests/test.m @@ -111,6 +111,18 @@ OF_APPLICATION_DELEGATE(AppDelegate) } } +- (void)connection: (XMPPConnection*)conn + didReceiveElement: (OFXMLElement*)element +{ + of_log(@"In: %@", element); +} + +- (void)connection: (XMPPConnection*)conn + didSendElement: (OFXMLElement*)element +{ + of_log(@"Out: %@", element); +} + - (void)connectionWasAuthenticated: (XMPPConnection*)conn { of_log(@"Auth successful");