@@ -2,10 +2,11 @@ #include #import "XMPPConnection.h" #import "XMPPStanza.h" +#import "XMPPJID.h" #import "XMPPIQ.h" #define NS_BIND @"urn:ietf:params:xml:ns:xmpp-bind" #define NS_CLIENT @"jabber:client" #define NS_SASL @"urn:ietf:params:xml:ns:xmpp-sasl" @@ -53,12 +54,12 @@ { OFString *old = username; char *node; Stringprep_rc rc; - if ((rc = stringprep_profile([username_ cString], &node, "SASLprep", 0)) - != STRINGPREP_OK) { + if ((rc = stringprep_profile([username_ cString], &node, + "SASLprep", 0)) != STRINGPREP_OK) { of_log(@"SASLprep failed: %s", stringprep_strerror(rc)); assert(0); } @try { @@ -74,12 +75,12 @@ { OFString *old = resource; char *res; Stringprep_rc rc; - if ((rc = stringprep_profile([resource_ cString], &res, "Resourceprep", 0)) - != STRINGPREP_OK) { + if ((rc = stringprep_profile([resource_ cString], &res, + "Resourceprep", 0)) != STRINGPREP_OK) { of_log(@"Resourceprep failed: %s", stringprep_strerror(rc)); assert(0); } @try { @@ -95,12 +96,12 @@ { OFString *old = server; char *srv; Stringprep_rc rc; - if ((rc = stringprep_profile([server_ cString], &srv, "Nameprep", 0)) - != STRINGPREP_OK) { + if ((rc = stringprep_profile([server_ cString], &srv, + "Nameprep", 0)) != STRINGPREP_OK) { of_log(@"Nameprep failed: %s", stringprep_strerror(rc)); assert(0); } @try { @@ -116,12 +117,12 @@ { OFString *old = password; char *pass; Stringprep_rc rc; - if ((rc = stringprep_profile([password_ cString], &pass, "SASLprep", 0)) - != STRINGPREP_OK) { + if ((rc = stringprep_profile([password_ cString], &pass, + "SASLprep", 0)) != STRINGPREP_OK) { of_log(@"SASLprep failed: %s", stringprep_strerror(rc)); assert(0); } @try { @@ -143,11 +144,12 @@ - (void)connect { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - [sock connectToHost: server onPort: port]; + [sock connectToHost: server + onPort: port]; [self _startStream]; [pool release]; } @@ -179,17 +181,22 @@ withPrefix: (OFString*)prefix namespace: (OFString*)ns attributes: (OFArray*)attrs { if (![name isEqual: @"stream"] || ![prefix isEqual: @"stream"] || - ![ns isEqual: NS_STREAM]) + ![ns isEqual: NS_STREAM]) { of_log(@"Did not get expected stream start!"); + assert(0); + } - for (OFXMLAttribute *attr in attrs) + for (OFXMLAttribute *attr in attrs) { if ([attr.name isEqual: @"from"] && - ![attr.stringValue isEqual: server]) + ![attr.stringValue isEqual: server]) { of_log(@"Got invalid from in stream start!"); + assert(0); + } + } parser.delegate = elementBuilder; } - (void)_addAuthMechanisms: (OFXMLElement*)mechanisms_ @@ -242,15 +249,16 @@ } - (void)_handleResourceBind: (XMPPIQ*)iq { OFXMLElement *bindElem = iq.children.firstObject; + if ([bindElem.name isEqual: @"bind"] && [bindElem.namespace isEqual: NS_BIND]) { OFXMLElement *jidElem = bindElem.children.firstObject; JID = [[XMPPJID alloc] initWithString: - [jidElem.children.firstObject stringValue]]; + [jidElem.children.firstObject stringValue]]; of_log(@"Bound to JID: %@", [JID fullJID]); } } - (void)_handleFeatures: (OFXMLElement*)elem @@ -300,13 +308,14 @@ } if ([elem.name isEqual: @"iq"] && [elem.namespace isEqual: NS_CLIENT]) { XMPPIQ *iq = [XMPPIQ stanzaWithElement: elem]; - if ([iq.ID isEqual: @"bind0"] && [iq.type isEqual: @"result"]) { + + // FIXME: More checking! + if ([iq.ID isEqual: @"bind0"] && [iq.type isEqual: @"result"]) [self _handleResourceBind: iq]; - } } } - (void)elementBuilder: (OFXMLElementBuilder*)b didNotExpectCloseTag: (OFString*)name