Generate stanza errors

This commit is contained in:
Florian Zeitz 2012-01-25 15:05:09 +01:00
parent 446490ebc5
commit 71b02af421
2 changed files with 51 additions and 8 deletions

View file

@ -216,11 +216,13 @@ withCallbackBlock: (void(^)(XMPPIQ*))callback;
- (void)XMPP_handleSASL: (OFXMLElement*)element; - (void)XMPP_handleSASL: (OFXMLElement*)element;
- (void)XMPP_handleStanza: (OFXMLElement*)element; - (void)XMPP_handleStanza: (OFXMLElement*)element;
- (void)XMPP_sendAuth: (OFString*)authName; - (void)XMPP_sendAuth: (OFString*)authName;
- (void)XMPP_sendResourceBind;
- (void)XMPP_sendStreamError: (OFString*)condition
text: (OFString*)text;
- (void)XMPP_handleIQ: (XMPPIQ*)iq; - (void)XMPP_handleIQ: (XMPPIQ*)iq;
- (void)XMPP_handleMessage: (XMPPMessage*)message; - (void)XMPP_handleMessage: (XMPPMessage*)message;
- (void)XMPP_handlePresence: (XMPPPresence*)presence; - (void)XMPP_handlePresence: (XMPPPresence*)presence;
- (void)XMPP_handleFeatures: (OFXMLElement*)element; - (void)XMPP_handleFeatures: (OFXMLElement*)element;
- (void)XMPP_sendResourceBind;
- (void)XMPP_handleResourceBind: (XMPPIQ*)iq; - (void)XMPP_handleResourceBind: (XMPPIQ*)iq;
- (void)XMPP_sendSession; - (void)XMPP_sendSession;
- (void)XMPP_handleSession: (XMPPIQ*)iq; - (void)XMPP_handleSession: (XMPPIQ*)iq;

View file

@ -414,18 +414,38 @@ withCallbackBlock: (xmpp_callback_block)callback;
OFEnumerator *enumerator; OFEnumerator *enumerator;
OFXMLAttribute *attribute; OFXMLAttribute *attribute;
if (![name isEqual: @"stream"] || ![prefix isEqual: @"stream"] || if (![name isEqual: @"stream"]) {
![ns isEqual: XMPP_NS_STREAM]) { // No dedicated stream error for this, may not even be XMPP
of_log(@"Did not get expected stream start!"); [self close];
assert(0); [sock close];
return;
}
if (![prefix isEqual: @"stream"]) {
[self XMPP_sendStreamError: @"bad-namespace-prefix"
text: nil];
return;
}
if (![ns isEqual: XMPP_NS_STREAM]) {
[self XMPP_sendStreamError: @"invalid-namespace"
text: nil];
return;
} }
enumerator = [attributes objectEnumerator]; enumerator = [attributes objectEnumerator];
while ((attribute = [enumerator nextObject]) != nil) { while ((attribute = [enumerator nextObject]) != nil) {
if ([[attribute name] isEqual: @"from"] && if ([[attribute name] isEqual: @"from"] &&
![[attribute stringValue] isEqual: domain]) { ![[attribute stringValue] isEqual: domain]) {
of_log(@"Got invalid from in stream start!"); [self XMPP_sendStreamError: @"invalid-from"
assert(0); text: nil];
return;
}
if ([[attribute name] isEqual: @"version"] &&
![[attribute stringValue] isEqual: @"1.0"]) {
[self XMPP_sendStreamError: @"unsupported-version"
text: nil];
return;
} }
} }
@ -534,7 +554,8 @@ withCallbackBlock: (xmpp_callback_block)callback;
return; return;
} }
assert(0); [self XMPP_sendStreamError: @"unsupported-stanza-type"
text: nil];
} }
@ -885,6 +906,26 @@ withCallbackBlock: (xmpp_callback_block)callback;
selector: @selector(XMPP_handleResourceBind:)]; selector: @selector(XMPP_handleResourceBind:)];
} }
- (void)XMPP_sendStreamError: (OFString*)condition
text: (OFString*)text
{
OFXMLElement *error = [OFXMLElement
elementWithName: @"error"
namespace: XMPP_NS_STREAM];
[error setPrefix: @"stream"
forNamespace: XMPP_NS_STREAM];
[error addChild: [OFXMLElement elementWithName: condition
namespace: XMPP_NS_XMPP_STREAM]];
if (text)
[error addChild: [OFXMLElement
elementWithName: @"text"
namespace: XMPP_NS_XMPP_STREAM
stringValue: text]];
[parser setDelegate: nil];
[self sendStanza: error];
[self close];
}
- (void)XMPP_handleResourceBind: (XMPPIQ*)iq - (void)XMPP_handleResourceBind: (XMPPIQ*)iq
{ {
OFXMLElement *bindElement; OFXMLElement *bindElement;