@@ -48,15 +48,16 @@ #define NS_SESSION @"urn:ietf:params:xml:ns:xmpp-session" #define NS_STREAM @"http://etherx.jabber.org/streams" @interface XMPPConnection () - (void)XMPP_startStream; +- (void)XMPP_handleStanza: (OFXMLElement*)elem; - (void)XMPP_sendAuth: (OFString*)name; -- (void)XMPP_handleFeatures: (OFXMLElement*)elem; - (void)XMPP_handleIQ: (XMPPIQ*)iq; - (void)XMPP_handleMessage: (XMPPMessage*)msg; - (void)XMPP_handlePresence: (XMPPPresence*)pres; +- (void)XMPP_handleFeatures: (OFXMLElement*)elem; - (void)XMPP_sendResourceBind; - (void)XMPP_handleResourceBind: (XMPPIQ*)iq; - (void)XMPP_sendSession; - (void)XMPP_handleSession: (XMPPIQ*)iq; - (void)XMPP_handleRoster: (XMPPIQ*)iq; @@ -262,10 +263,12 @@ didStartElement: (OFString*)name withPrefix: (OFString*)prefix namespace: (OFString*)ns attributes: (OFArray*)attrs { + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + if (![name isEqual: @"stream"] || ![prefix isEqual: @"stream"] || ![ns isEqual: NS_STREAM]) { of_log(@"Did not get expected stream start!"); assert(0); } @@ -277,21 +280,40 @@ assert(0); } } parser.delegate = elementBuilder; + + [pool release]; } - (void)elementBuilder: (OFXMLElementBuilder*)b didBuildElement: (OFXMLElement*)elem { + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + elem.defaultNamespace = NS_CLIENT; [elem setPrefix: @"stream" forNamespace: NS_STREAM]; of_log(@"In: %@", elem); + [self XMPP_handleStanza: elem]; + + [pool release]; +} + +- (void)XMPP_startStream +{ + [sock writeFormat: @"\n" + @"", server]; +} + +- (void)XMPP_handleStanza: (OFXMLElement*)elem +{ if ([elem.namespace isEqual: NS_CLIENT]) { if ([elem.name isEqual: @"iq"]) { [self XMPP_handleIQ: [XMPPIQ stanzaWithElement: elem]]; return; } @@ -341,20 +363,19 @@ if ([elem.namespace isEqual: NS_SASL]) { if ([elem.name isEqual: @"challenge"]) { OFXMLElement *responseTag; OFDataArray *challenge = [OFDataArray dataArrayWithBase64EncodedString: - [elem.children.firstObject stringValue]]; - OFDataArray *response = - [authModule - calculateResponseWithChallenge: challenge]; + [elem.children.firstObject stringValue]]; + OFDataArray *response = [authModule + calculateResponseWithChallenge: challenge]; responseTag = [OFXMLElement elementWithName: @"response" namespace: NS_SASL]; - [responseTag - addChild: [OFXMLElement elementWithCharacters: - [response stringByBase64Encoding]]]; + [responseTag addChild: + [OFXMLElement elementWithCharacters: + [response stringByBase64Encoding]]]; [self sendStanza: responseTag]; return; } @@ -377,27 +398,19 @@ of_log(@"Auth failed!"); // FIXME: Do more parsing/handling @throw [XMPPAuthFailedException newWithClass: isa connection: self - reason: [elem stringValue]]; + reason: elem.stringValue]; } assert(0); } assert(0); } -- (void)XMPP_startStream -{ - [sock writeFormat: @"\n" - @"", server]; -} - - (void)XMPP_handleIQ: (XMPPIQ*)iq { BOOL handled = NO; if ([iq.ID isEqual: bindID]) {