Add a delegate for incoming/outgoing elements.

This commit is contained in:
Jonathan Schleifer 2011-12-12 00:27:32 +01:00
parent 4aaa754a4d
commit fdf33f356a
3 changed files with 25 additions and 2 deletions

View file

@ -40,6 +40,10 @@
#ifdef OF_HAVE_OPTIONAL_PROTOCOLS #ifdef OF_HAVE_OPTIONAL_PROTOCOLS
@optional @optional
#endif #endif
- (void)connection: (XMPPConnection*)connection
didReceiveElement: (OFXMLElement*)element;
- (void)connection: (XMPPConnection*)connection
didSendElement: (OFXMLElement*)element;
- (void)connectionWasAuthenticated: (XMPPConnection*)connection; - (void)connectionWasAuthenticated: (XMPPConnection*)connection;
- (void)connection: (XMPPConnection*)connection - (void)connection: (XMPPConnection*)connection
wasBoundToJID: (XMPPJID*)JID; wasBoundToJID: (XMPPJID*)JID;

View file

@ -344,7 +344,11 @@
- (void)sendStanza: (OFXMLElement*)element - (void)sendStanza: (OFXMLElement*)element
{ {
of_log(@"Out: %@", element); if ([delegate respondsToSelector:
@selector(connection:didSendElement:)])
[delegate connection: self
didSendElement: element];
[sock writeString: [element XMLString]]; [sock writeString: [element XMLString]];
} }
@ -404,7 +408,10 @@
[element setPrefix: @"stream" [element setPrefix: @"stream"
forNamespace: XMPP_NS_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]) if ([[element namespace] isEqual: XMPP_NS_CLIENT])
[self XMPP_handleStanza: element]; [self XMPP_handleStanza: element];

View file

@ -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 - (void)connectionWasAuthenticated: (XMPPConnection*)conn
{ {
of_log(@"Auth successful"); of_log(@"Auth successful");