Generate stanza errors
This commit is contained in:
parent
446490ebc5
commit
71b02af421
2 changed files with 51 additions and 8 deletions
|
@ -216,11 +216,13 @@ withCallbackBlock: (void(^)(XMPPIQ*))callback;
|
|||
- (void)XMPP_handleSASL: (OFXMLElement*)element;
|
||||
- (void)XMPP_handleStanza: (OFXMLElement*)element;
|
||||
- (void)XMPP_sendAuth: (OFString*)authName;
|
||||
- (void)XMPP_sendResourceBind;
|
||||
- (void)XMPP_sendStreamError: (OFString*)condition
|
||||
text: (OFString*)text;
|
||||
- (void)XMPP_handleIQ: (XMPPIQ*)iq;
|
||||
- (void)XMPP_handleMessage: (XMPPMessage*)message;
|
||||
- (void)XMPP_handlePresence: (XMPPPresence*)presence;
|
||||
- (void)XMPP_handleFeatures: (OFXMLElement*)element;
|
||||
- (void)XMPP_sendResourceBind;
|
||||
- (void)XMPP_handleResourceBind: (XMPPIQ*)iq;
|
||||
- (void)XMPP_sendSession;
|
||||
- (void)XMPP_handleSession: (XMPPIQ*)iq;
|
||||
|
|
|
@ -414,18 +414,38 @@ withCallbackBlock: (xmpp_callback_block)callback;
|
|||
OFEnumerator *enumerator;
|
||||
OFXMLAttribute *attribute;
|
||||
|
||||
if (![name isEqual: @"stream"] || ![prefix isEqual: @"stream"] ||
|
||||
![ns isEqual: XMPP_NS_STREAM]) {
|
||||
of_log(@"Did not get expected stream start!");
|
||||
assert(0);
|
||||
if (![name isEqual: @"stream"]) {
|
||||
// No dedicated stream error for this, may not even be XMPP
|
||||
[self close];
|
||||
[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];
|
||||
while ((attribute = [enumerator nextObject]) != nil) {
|
||||
if ([[attribute name] isEqual: @"from"] &&
|
||||
![[attribute stringValue] isEqual: domain]) {
|
||||
of_log(@"Got invalid from in stream start!");
|
||||
assert(0);
|
||||
[self XMPP_sendStreamError: @"invalid-from"
|
||||
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;
|
||||
}
|
||||
|
||||
assert(0);
|
||||
[self XMPP_sendStreamError: @"unsupported-stanza-type"
|
||||
text: nil];
|
||||
}
|
||||
|
||||
|
||||
|
@ -885,6 +906,26 @@ withCallbackBlock: (xmpp_callback_block)callback;
|
|||
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
|
||||
{
|
||||
OFXMLElement *bindElement;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue