Index: src/XMPPConnection.h ================================================================== --- src/XMPPConnection.h +++ src/XMPPConnection.h @@ -34,11 +34,11 @@ @optional - (void)connectionWasAuthenticated: (XMPPConnection*)conn; - (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; - (void)connection: (XMPPConnection*)conn didReceiveMessage: (XMPPMessage*)msg; Index: src/XMPPConnection.m ================================================================== --- src/XMPPConnection.m +++ src/XMPPConnection.m @@ -41,10 +41,11 @@ #define NS_BIND @"urn:ietf:params:xml:ns:xmpp-bind" #define NS_CLIENT @"jabber:client" #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" @interface XMPPConnection () - (void)XMPP_startStream; @@ -394,10 +395,12 @@ @"version='1.0'>", server]; } - (void)XMPP_handleIQ: (XMPPIQ*)iq { + BOOL handled = NO; + if ([iq.ID isEqual: bindID]) { [self XMPP_handleResourceBind: iq]; return; } @@ -410,12 +413,40 @@ [self XMPP_handleRoster: iq]; return; } 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 { if ([delegate respondsToSelector: Index: tests/test.m ================================================================== --- tests/test.m +++ tests/test.m @@ -127,14 +127,16 @@ [pres addStatus: @"ObjXMPP test is working!"]; [conn sendStanza: pres]; } -- (void)connection: (XMPPConnection*)conn +- (BOOL)connection: (XMPPConnection*)conn didReceiveIQ: (XMPPIQ*)iq { of_log(@"IQ: %@", iq); + + return NO; } - (void)connection: (XMPPConnection*)conn didReceiveMessage: (XMPPMessage*)msg {