Send an error reply for unhandled IQ stanzas.

This commit is contained in:
Jonathan Schleifer 2011-03-21 21:36:59 +01:00
parent e71c601cbe
commit 08e9104a17
3 changed files with 37 additions and 4 deletions

View file

@ -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;

View file

@ -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

View file

@ -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