Send an error reply for unhandled IQ stanzas.
This commit is contained in:
parent
e71c601cbe
commit
08e9104a17
3 changed files with 37 additions and 4 deletions
|
@ -36,7 +36,7 @@
|
||||||
- (void)connection: (XMPPConnection*)conn
|
- (void)connection: (XMPPConnection*)conn
|
||||||
wasBoundToJID: (XMPPJID*)jid;
|
wasBoundToJID: (XMPPJID*)jid;
|
||||||
- (void)connectionDidReceiveRoster: (XMPPConnection*)conn;
|
- (void)connectionDidReceiveRoster: (XMPPConnection*)conn;
|
||||||
- (void)connection: (XMPPConnection*)conn
|
- (BOOL)connection: (XMPPConnection*)conn
|
||||||
didReceiveIQ: (XMPPIQ*)iq;
|
didReceiveIQ: (XMPPIQ*)iq;
|
||||||
- (void)connection: (XMPPConnection*)conn
|
- (void)connection: (XMPPConnection*)conn
|
||||||
didReceivePresence: (XMPPPresence*)pres;
|
didReceivePresence: (XMPPPresence*)pres;
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
#define NS_ROSTER @"jabber:iq:roster"
|
#define NS_ROSTER @"jabber:iq:roster"
|
||||||
#define NS_SASL @"urn:ietf:params:xml:ns:xmpp-sasl"
|
#define NS_SASL @"urn:ietf:params:xml:ns:xmpp-sasl"
|
||||||
#define NS_STARTTLS @"urn:ietf:params:xml:ns:xmpp-tls"
|
#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_SESSION @"urn:ietf:params:xml:ns:xmpp-session"
|
||||||
#define NS_STREAM @"http://etherx.jabber.org/streams"
|
#define NS_STREAM @"http://etherx.jabber.org/streams"
|
||||||
|
|
||||||
|
@ -396,6 +397,8 @@
|
||||||
|
|
||||||
- (void)XMPP_handleIQ: (XMPPIQ*)iq
|
- (void)XMPP_handleIQ: (XMPPIQ*)iq
|
||||||
{
|
{
|
||||||
|
BOOL handled = NO;
|
||||||
|
|
||||||
if ([iq.ID isEqual: bindID]) {
|
if ([iq.ID isEqual: bindID]) {
|
||||||
[self XMPP_handleResourceBind: iq];
|
[self XMPP_handleResourceBind: iq];
|
||||||
return;
|
return;
|
||||||
|
@ -412,8 +415,36 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([delegate respondsToSelector: @selector(connection:didReceiveIQ:)])
|
if ([delegate respondsToSelector: @selector(connection:didReceiveIQ:)])
|
||||||
[delegate connection: self
|
handled = [delegate connection: self
|
||||||
didReceiveIQ: iq];
|
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
|
- (void)XMPP_handleMessage: (XMPPMessage*)msg
|
||||||
|
|
|
@ -129,10 +129,12 @@ OF_APPLICATION_DELEGATE(AppDelegate)
|
||||||
[conn sendStanza: pres];
|
[conn sendStanza: pres];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)connection: (XMPPConnection*)conn
|
- (BOOL)connection: (XMPPConnection*)conn
|
||||||
didReceiveIQ: (XMPPIQ*)iq
|
didReceiveIQ: (XMPPIQ*)iq
|
||||||
{
|
{
|
||||||
of_log(@"IQ: %@", iq);
|
of_log(@"IQ: %@", iq);
|
||||||
|
|
||||||
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)connection: (XMPPConnection*)conn
|
- (void)connection: (XMPPConnection*)conn
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue