Adjust to newest ObjFW and greatly improve XML handling.
This commit is contained in:
parent
59cb0a7954
commit
b35525fd2b
2 changed files with 31 additions and 39 deletions
|
@ -227,7 +227,7 @@
|
|||
- (void)sendStanza: (OFXMLElement*)elem
|
||||
{
|
||||
of_log(@"Out: %@", elem);
|
||||
[sock writeString: [elem stringValue]];
|
||||
[sock writeString: [elem XMLString]];
|
||||
}
|
||||
|
||||
- (OFString*)generateStanzaID
|
||||
|
@ -345,7 +345,7 @@
|
|||
OFXMLElement *responseTag;
|
||||
OFDataArray *challenge =
|
||||
[OFDataArray dataArrayWithBase64EncodedString:
|
||||
[[[elem children] firstObject] stringValue]];
|
||||
[elem stringValue]];
|
||||
OFDataArray *response = [authModule
|
||||
calculateResponseWithChallenge: challenge];
|
||||
|
||||
|
@ -363,7 +363,7 @@
|
|||
if ([[elem name] isEqual: @"success"]) {
|
||||
[authModule parseServerFinalMessage:
|
||||
[OFDataArray dataArrayWithBase64EncodedString:
|
||||
[[[elem children] firstObject] stringValue]]];
|
||||
[elem stringValue]]];
|
||||
|
||||
if ([delegate respondsToSelector:
|
||||
@selector(connectionWasAuthenticated:)])
|
||||
|
@ -381,7 +381,7 @@
|
|||
@throw [XMPPAuthFailedException
|
||||
newWithClass: isa
|
||||
connection: self
|
||||
reason: [elem stringValue]];
|
||||
reason: [elem XMLString]];
|
||||
}
|
||||
|
||||
assert(0);
|
||||
|
@ -452,15 +452,13 @@
|
|||
|
||||
- (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"
|
||||
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];
|
||||
|
||||
|
@ -471,14 +469,13 @@
|
|||
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]
|
||||
|
@ -551,18 +548,16 @@
|
|||
OFXMLElement *bindElem;
|
||||
OFXMLElement *jidElem;
|
||||
|
||||
if (![[iq type] isEqual: @"result"])
|
||||
assert(0);
|
||||
assert([[iq type] isEqual: @"result"]);
|
||||
|
||||
bindElem = [[iq children] firstObject];
|
||||
bindElem = [iq elementForName: @"bind"
|
||||
namespace: XMPP_NS_BIND];
|
||||
|
||||
if (![[bindElem name] isEqual: @"bind"] ||
|
||||
![[bindElem namespace] isEqual: XMPP_NS_BIND])
|
||||
assert(0);
|
||||
assert(bindElem != nil);
|
||||
|
||||
jidElem = [[bindElem children] firstObject];
|
||||
JID = [[XMPPJID alloc] initWithString:
|
||||
[[[jidElem children] firstObject] stringValue]];
|
||||
jidElem = [bindElem elementForName: @"jid"
|
||||
namespace: XMPP_NS_BIND];
|
||||
JID = [[XMPPJID alloc] initWithString: [jidElem stringValue]];
|
||||
|
||||
[bindID release];
|
||||
bindID = nil;
|
||||
|
@ -623,14 +618,12 @@
|
|||
OFEnumerator *enumerator;
|
||||
OFXMLElement *elem;
|
||||
|
||||
if (![[iq type] isEqual: @"result"])
|
||||
assert(0);
|
||||
assert([[iq type] isEqual: @"result"]);
|
||||
|
||||
rosterElem = [[iq children] firstObject];
|
||||
rosterElem = [iq elementForName: @"query"
|
||||
namespace: XMPP_NS_ROSTER];
|
||||
|
||||
if (![[rosterElem name] isEqual: @"query"] ||
|
||||
![[rosterElem namespace] isEqual: XMPP_NS_ROSTER])
|
||||
assert(0);
|
||||
assert(rosterElem != nil);
|
||||
|
||||
enumerator = [[rosterElem children] objectEnumerator];
|
||||
while ((elem = [enumerator nextObject]) != nil) {
|
||||
|
@ -655,8 +648,7 @@
|
|||
[[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];
|
||||
|
|
|
@ -53,7 +53,7 @@ OF_APPLICATION_DELEGATE(AppDelegate)
|
|||
[pres addPriority: 20];
|
||||
[pres setTo: [XMPPJID JIDWithString: @"alice@example.com"]];
|
||||
[pres setFrom: [XMPPJID JIDWithString: @"bob@example.org"]];
|
||||
assert([[pres stringValue] isEqual: @"<presence to='alice@example.com' "
|
||||
assert([[pres XMLString] isEqual: @"<presence to='alice@example.com' "
|
||||
@"from='bob@example.org'><show>chat</show>"
|
||||
@"<status>Bored</status><priority>20</priority>"
|
||||
@"</presence>"]);
|
||||
|
@ -62,7 +62,7 @@ OF_APPLICATION_DELEGATE(AppDelegate)
|
|||
[msg addBody: @"Hello everyone"];
|
||||
[msg setTo: [XMPPJID JIDWithString: @"jdev@conference.jabber.org"]];
|
||||
[msg setFrom: [XMPPJID JIDWithString: @"alice@example.com"]];
|
||||
assert([[msg stringValue] isEqual: @"<message type='chat' "
|
||||
assert([[msg XMLString] isEqual: @"<message type='chat' "
|
||||
@"to='jdev@conference.jabber.org' "
|
||||
@"from='alice@example.com'><body>Hello everyone</body>"
|
||||
@"</message>"]);
|
||||
|
@ -70,7 +70,7 @@ OF_APPLICATION_DELEGATE(AppDelegate)
|
|||
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: @"<iq type='set' id='128' "
|
||||
assert([[iq XMLString] isEqual: @"<iq type='set' id='128' "
|
||||
@"to='juliet@capulet.lit' "
|
||||
@"from='romeo@montague.lit'/>"]);
|
||||
|
||||
|
@ -84,7 +84,7 @@ OF_APPLICATION_DELEGATE(AppDelegate)
|
|||
[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"]));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue