diff --git a/src/XMPPConnection.h b/src/XMPPConnection.h index 470cdd6..2494b58 100644 --- a/src/XMPPConnection.h +++ b/src/XMPPConnection.h @@ -36,7 +36,7 @@ - (void)connection: (XMPPConnection*)conn wasBoundToJID: (XMPPJID*)jid; - (void)connectionDidReceiveRoster: (XMPPConnection*)conn; -- (void)connection: (XMPPConnection*)conn +- (BOOL)connection: (XMPPConnection*)conn didReceiveIQ: (XMPPIQ*)iq; - (void)connection: (XMPPConnection*)conn didReceivePresence: (XMPPPresence*)pres; diff --git a/src/XMPPConnection.m b/src/XMPPConnection.m index acd8ec5..971509c 100644 --- a/src/XMPPConnection.m +++ b/src/XMPPConnection.m @@ -43,6 +43,7 @@ #define NS_ROSTER @"jabber:iq:roster" #define NS_SASL @"urn:ietf:params:xml:ns:xmpp-sasl" #define NS_STARTTLS @"urn:ietf:params:xml:ns:xmpp-tls" +#define NS_STANZAS @"urn:ietf:params:xml:ns:xmpp-stanzas" #define NS_SESSION @"urn:ietf:params:xml:ns:xmpp-session" #define NS_STREAM @"http://etherx.jabber.org/streams" @@ -396,6 +397,8 @@ - (void)XMPP_handleIQ: (XMPPIQ*)iq { + BOOL handled = NO; + if ([iq.ID isEqual: bindID]) { [self XMPP_handleResourceBind: iq]; return; @@ -412,8 +415,36 @@ } if ([delegate respondsToSelector: @selector(connection:didReceiveIQ:)]) - [delegate connection: self - didReceiveIQ: iq]; + handled = [delegate connection: self + didReceiveIQ: iq]; + + if (!handled) { + OFString *from = [iq attributeForName: @"from"].stringValue; + OFString *to = [iq attributeForName: @"to"].stringValue; + OFXMLElement *error; + + [iq setType: @"error"]; + + [iq removeAttributeForName: @"from"]; + [iq removeAttributeForName: @"to"]; + + if (from != nil) + [iq addAttributeWithName: @"to" + stringValue: from]; + if (to != nil) + [iq addAttributeWithName: @"from" + stringValue: to]; + + error = [OFXMLElement elementWithName: @"error"]; + [error addAttributeWithName: @"type" + stringValue: @"cancel"]; + [error addChild: + [OFXMLElement elementWithName: @"service-unavailable" + namespace: NS_STANZAS]]; + [iq addChild: error]; + + [self sendStanza: iq]; + } } - (void)XMPP_handleMessage: (XMPPMessage*)msg diff --git a/tests/test.m b/tests/test.m index 089a334..90424e9 100644 --- a/tests/test.m +++ b/tests/test.m @@ -129,10 +129,12 @@ OF_APPLICATION_DELEGATE(AppDelegate) [conn sendStanza: pres]; } -- (void)connection: (XMPPConnection*)conn +- (BOOL)connection: (XMPPConnection*)conn didReceiveIQ: (XMPPIQ*)iq { of_log(@"IQ: %@", iq); + + return NO; } - (void)connection: (XMPPConnection*)conn