Index: src/XMPPConnection.m ================================================================== --- src/XMPPConnection.m +++ src/XMPPConnection.m @@ -225,11 +225,11 @@ } - (void)sendStanza: (OFXMLElement*)elem { of_log(@"Out: %@", elem); - [sock writeString: [elem stringValue]]; + [sock writeString: [elem XMLString]]; } - (OFString*)generateStanzaID { return [OFString stringWithFormat: @"objxmpp_%u", lastID++]; @@ -343,11 +343,11 @@ if ([[elem namespace] isEqual: XMPP_NS_SASL]) { if ([[elem name] isEqual: @"challenge"]) { OFXMLElement *responseTag; OFDataArray *challenge = [OFDataArray dataArrayWithBase64EncodedString: - [[[elem children] firstObject] stringValue]]; + [elem stringValue]]; OFDataArray *response = [authModule calculateResponseWithChallenge: challenge]; responseTag = [OFXMLElement elementWithName: @"response" @@ -361,11 +361,11 @@ } if ([[elem name] isEqual: @"success"]) { [authModule parseServerFinalMessage: [OFDataArray dataArrayWithBase64EncodedString: - [[[elem children] firstObject] stringValue]]]; + [elem stringValue]]]; if ([delegate respondsToSelector: @selector(connectionWasAuthenticated:)]) [delegate connectionWasAuthenticated: self]; @@ -379,11 +379,11 @@ of_log(@"Auth failed!"); // FIXME: Do more parsing/handling @throw [XMPPAuthFailedException newWithClass: isa connection: self - reason: [elem stringValue]]; + reason: [elem XMLString]]; } assert(0); } @@ -450,37 +450,34 @@ didReceivePresence: pres]; } - (void)XMPP_handleFeatures: (OFXMLElement*)elem { - OFXMLElement *starttls = - [[elem elementsForName: @"starttls" - namespace: XMPP_NS_STARTTLS] firstObject]; - OFXMLElement *bind = [[elem elementsForName: @"bind" - namespace: XMPP_NS_BIND] firstObject]; - OFXMLElement *session = - [[elem elementsForName: @"session" - namespace: XMPP_NS_SESSION] firstObject]; - OFArray *mechs = [elem elementsForName: @"mechanisms" - namespace: XMPP_NS_SASL]; + OFXMLElement *starttls = [elem elementForName: @"starttls" + namespace: XMPP_NS_STARTTLS]; + OFXMLElement *bind = [elem elementForName: @"bind" + namespace: XMPP_NS_BIND]; + OFXMLElement *session = [elem elementForName: @"session" + namespace: XMPP_NS_SESSION]; + OFXMLElement *mechs = [elem elementForName: @"mechanisms" + namespace: XMPP_NS_SASL]; OFMutableArray *mechanisms = [OFMutableArray array]; if (starttls != nil) { [self sendStanza: [OFXMLElement elementWithName: @"starttls" namespace: XMPP_NS_STARTTLS]]; return; } - if ([mechs count] > 0) { + if (mechs != nil) { OFEnumerator *enumerator; OFXMLElement *mech; - enumerator = [[[mechs firstObject] children] objectEnumerator]; + enumerator = [[mechs children] objectEnumerator]; while ((mech = [enumerator nextObject]) != nil) - [mechanisms addObject: - [[[mech children] firstObject] stringValue]]; + [mechanisms addObject: [mech stringValue]]; if ([mechanisms containsObject: @"SCRAM-SHA-1"]) { authModule = [[XMPPSCRAMAuth alloc] initWithAuthcid: username password: password @@ -549,22 +546,20 @@ - (void)XMPP_handleResourceBind: (XMPPIQ*)iq { OFXMLElement *bindElem; OFXMLElement *jidElem; - if (![[iq type] isEqual: @"result"]) - assert(0); - - bindElem = [[iq children] firstObject]; - - if (![[bindElem name] isEqual: @"bind"] || - ![[bindElem namespace] isEqual: XMPP_NS_BIND]) - assert(0); - - jidElem = [[bindElem children] firstObject]; - JID = [[XMPPJID alloc] initWithString: - [[[jidElem children] firstObject] stringValue]]; + assert([[iq type] isEqual: @"result"]); + + bindElem = [iq elementForName: @"bind" + namespace: XMPP_NS_BIND]; + + assert(bindElem != nil); + + jidElem = [bindElem elementForName: @"jid" + namespace: XMPP_NS_BIND]; + JID = [[XMPPJID alloc] initWithString: [jidElem stringValue]]; [bindID release]; bindID = nil; if (needsSession) { @@ -621,18 +616,16 @@ { OFXMLElement *rosterElem; OFEnumerator *enumerator; OFXMLElement *elem; - if (![[iq type] isEqual: @"result"]) - assert(0); - - rosterElem = [[iq children] firstObject]; - - if (![[rosterElem name] isEqual: @"query"] || - ![[rosterElem namespace] isEqual: XMPP_NS_ROSTER]) - assert(0); + assert([[iq type] isEqual: @"result"]); + + rosterElem = [iq elementForName: @"query" + namespace: XMPP_NS_ROSTER]; + + assert(rosterElem != nil); enumerator = [[rosterElem children] objectEnumerator]; while ((elem = [enumerator nextObject]) != nil) { XMPPRosterItem *rosterItem; OFMutableArray *groups = [OFMutableArray array]; @@ -653,12 +646,11 @@ groupEnumerator = [[elem elementsForName: @"group" namespace: XMPP_NS_ROSTER] objectEnumerator]; while ((groupElem = [groupEnumerator nextObject]) != nil) - [groups addObject: - [[[groupElem children] firstObject] stringValue]]; + [groups addObject: [groupElem stringValue]]; if ([groups count] > 0) [rosterItem setGroups: groups]; [roster XMPP_addRosterItem: rosterItem]; Index: tests/test.m ================================================================== --- tests/test.m +++ tests/test.m @@ -51,28 +51,28 @@ [pres addShow: @"chat"]; [pres addStatus: @"Bored"]; [pres addPriority: 20]; [pres setTo: [XMPPJID JIDWithString: @"alice@example.com"]]; [pres setFrom: [XMPPJID JIDWithString: @"bob@example.org"]]; - assert([[pres stringValue] isEqual: @"chat" @"Bored20" @""]); XMPPMessage *msg = [XMPPMessage messageWithType: @"chat"]; [msg addBody: @"Hello everyone"]; [msg setTo: [XMPPJID JIDWithString: @"jdev@conference.jabber.org"]]; [msg setFrom: [XMPPJID JIDWithString: @"alice@example.com"]]; - assert([[msg stringValue] isEqual: @"Hello everyone" @""]); XMPPIQ *iq = [XMPPIQ IQWithType: @"set" ID: @"128"]; [iq setTo: [XMPPJID JIDWithString: @"juliet@capulet.lit"]]; [iq setFrom: [XMPPJID JIDWithString: @"romeo@montague.lit"]]; - assert([[iq stringValue] isEqual: @""]); OFXMLElement *elem = [OFXMLElement elementWithName: @"iq"]; [elem addAttributeWithName: @"from" @@ -82,11 +82,11 @@ [elem addAttributeWithName: @"type" stringValue: @"get"]; [elem addAttributeWithName: @"id" stringValue: @"42"]; XMPPStanza *stanza = [XMPPStanza stanzaWithElement: elem]; - assert([[elem stringValue] isEqual: [stanza stringValue]]); + assert([[elem XMLString] isEqual: [stanza XMLString]]); assert(([[OFString stringWithFormat: @"%@, %@, %@, %@", [[stanza from] fullJID], [[stanza to] fullJID], [stanza type], [stanza ID]] isEqual: @"bob@localhost, alice@localhost, get, 42"])); conn = [[XMPPConnection alloc] init];