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
|
- (void)sendStanza: (OFXMLElement*)elem
|
||||||
{
|
{
|
||||||
of_log(@"Out: %@", elem);
|
of_log(@"Out: %@", elem);
|
||||||
[sock writeString: [elem stringValue]];
|
[sock writeString: [elem XMLString]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (OFString*)generateStanzaID
|
- (OFString*)generateStanzaID
|
||||||
|
@ -345,7 +345,7 @@
|
||||||
OFXMLElement *responseTag;
|
OFXMLElement *responseTag;
|
||||||
OFDataArray *challenge =
|
OFDataArray *challenge =
|
||||||
[OFDataArray dataArrayWithBase64EncodedString:
|
[OFDataArray dataArrayWithBase64EncodedString:
|
||||||
[[[elem children] firstObject] stringValue]];
|
[elem stringValue]];
|
||||||
OFDataArray *response = [authModule
|
OFDataArray *response = [authModule
|
||||||
calculateResponseWithChallenge: challenge];
|
calculateResponseWithChallenge: challenge];
|
||||||
|
|
||||||
|
@ -363,7 +363,7 @@
|
||||||
if ([[elem name] isEqual: @"success"]) {
|
if ([[elem name] isEqual: @"success"]) {
|
||||||
[authModule parseServerFinalMessage:
|
[authModule parseServerFinalMessage:
|
||||||
[OFDataArray dataArrayWithBase64EncodedString:
|
[OFDataArray dataArrayWithBase64EncodedString:
|
||||||
[[[elem children] firstObject] stringValue]]];
|
[elem stringValue]]];
|
||||||
|
|
||||||
if ([delegate respondsToSelector:
|
if ([delegate respondsToSelector:
|
||||||
@selector(connectionWasAuthenticated:)])
|
@selector(connectionWasAuthenticated:)])
|
||||||
|
@ -381,7 +381,7 @@
|
||||||
@throw [XMPPAuthFailedException
|
@throw [XMPPAuthFailedException
|
||||||
newWithClass: isa
|
newWithClass: isa
|
||||||
connection: self
|
connection: self
|
||||||
reason: [elem stringValue]];
|
reason: [elem XMLString]];
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(0);
|
assert(0);
|
||||||
|
@ -452,15 +452,13 @@
|
||||||
|
|
||||||
- (void)XMPP_handleFeatures: (OFXMLElement*)elem
|
- (void)XMPP_handleFeatures: (OFXMLElement*)elem
|
||||||
{
|
{
|
||||||
OFXMLElement *starttls =
|
OFXMLElement *starttls = [elem elementForName: @"starttls"
|
||||||
[[elem elementsForName: @"starttls"
|
namespace: XMPP_NS_STARTTLS];
|
||||||
namespace: XMPP_NS_STARTTLS] firstObject];
|
OFXMLElement *bind = [elem elementForName: @"bind"
|
||||||
OFXMLElement *bind = [[elem elementsForName: @"bind"
|
namespace: XMPP_NS_BIND];
|
||||||
namespace: XMPP_NS_BIND] firstObject];
|
OFXMLElement *session = [elem elementForName: @"session"
|
||||||
OFXMLElement *session =
|
namespace: XMPP_NS_SESSION];
|
||||||
[[elem elementsForName: @"session"
|
OFXMLElement *mechs = [elem elementForName: @"mechanisms"
|
||||||
namespace: XMPP_NS_SESSION] firstObject];
|
|
||||||
OFArray *mechs = [elem elementsForName: @"mechanisms"
|
|
||||||
namespace: XMPP_NS_SASL];
|
namespace: XMPP_NS_SASL];
|
||||||
OFMutableArray *mechanisms = [OFMutableArray array];
|
OFMutableArray *mechanisms = [OFMutableArray array];
|
||||||
|
|
||||||
|
@ -471,14 +469,13 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([mechs count] > 0) {
|
if (mechs != nil) {
|
||||||
OFEnumerator *enumerator;
|
OFEnumerator *enumerator;
|
||||||
OFXMLElement *mech;
|
OFXMLElement *mech;
|
||||||
|
|
||||||
enumerator = [[[mechs firstObject] children] objectEnumerator];
|
enumerator = [[mechs children] objectEnumerator];
|
||||||
while ((mech = [enumerator nextObject]) != nil)
|
while ((mech = [enumerator nextObject]) != nil)
|
||||||
[mechanisms addObject:
|
[mechanisms addObject: [mech stringValue]];
|
||||||
[[[mech children] firstObject] stringValue]];
|
|
||||||
|
|
||||||
if ([mechanisms containsObject: @"SCRAM-SHA-1"]) {
|
if ([mechanisms containsObject: @"SCRAM-SHA-1"]) {
|
||||||
authModule = [[XMPPSCRAMAuth alloc]
|
authModule = [[XMPPSCRAMAuth alloc]
|
||||||
|
@ -551,18 +548,16 @@
|
||||||
OFXMLElement *bindElem;
|
OFXMLElement *bindElem;
|
||||||
OFXMLElement *jidElem;
|
OFXMLElement *jidElem;
|
||||||
|
|
||||||
if (![[iq type] isEqual: @"result"])
|
assert([[iq type] isEqual: @"result"]);
|
||||||
assert(0);
|
|
||||||
|
|
||||||
bindElem = [[iq children] firstObject];
|
bindElem = [iq elementForName: @"bind"
|
||||||
|
namespace: XMPP_NS_BIND];
|
||||||
|
|
||||||
if (![[bindElem name] isEqual: @"bind"] ||
|
assert(bindElem != nil);
|
||||||
![[bindElem namespace] isEqual: XMPP_NS_BIND])
|
|
||||||
assert(0);
|
|
||||||
|
|
||||||
jidElem = [[bindElem children] firstObject];
|
jidElem = [bindElem elementForName: @"jid"
|
||||||
JID = [[XMPPJID alloc] initWithString:
|
namespace: XMPP_NS_BIND];
|
||||||
[[[jidElem children] firstObject] stringValue]];
|
JID = [[XMPPJID alloc] initWithString: [jidElem stringValue]];
|
||||||
|
|
||||||
[bindID release];
|
[bindID release];
|
||||||
bindID = nil;
|
bindID = nil;
|
||||||
|
@ -623,14 +618,12 @@
|
||||||
OFEnumerator *enumerator;
|
OFEnumerator *enumerator;
|
||||||
OFXMLElement *elem;
|
OFXMLElement *elem;
|
||||||
|
|
||||||
if (![[iq type] isEqual: @"result"])
|
assert([[iq type] isEqual: @"result"]);
|
||||||
assert(0);
|
|
||||||
|
|
||||||
rosterElem = [[iq children] firstObject];
|
rosterElem = [iq elementForName: @"query"
|
||||||
|
namespace: XMPP_NS_ROSTER];
|
||||||
|
|
||||||
if (![[rosterElem name] isEqual: @"query"] ||
|
assert(rosterElem != nil);
|
||||||
![[rosterElem namespace] isEqual: XMPP_NS_ROSTER])
|
|
||||||
assert(0);
|
|
||||||
|
|
||||||
enumerator = [[rosterElem children] objectEnumerator];
|
enumerator = [[rosterElem children] objectEnumerator];
|
||||||
while ((elem = [enumerator nextObject]) != nil) {
|
while ((elem = [enumerator nextObject]) != nil) {
|
||||||
|
@ -655,8 +648,7 @@
|
||||||
[[elem elementsForName: @"group"
|
[[elem elementsForName: @"group"
|
||||||
namespace: XMPP_NS_ROSTER] objectEnumerator];
|
namespace: XMPP_NS_ROSTER] objectEnumerator];
|
||||||
while ((groupElem = [groupEnumerator nextObject]) != nil)
|
while ((groupElem = [groupEnumerator nextObject]) != nil)
|
||||||
[groups addObject:
|
[groups addObject: [groupElem stringValue]];
|
||||||
[[[groupElem children] firstObject] stringValue]];
|
|
||||||
|
|
||||||
if ([groups count] > 0)
|
if ([groups count] > 0)
|
||||||
[rosterItem setGroups: groups];
|
[rosterItem setGroups: groups];
|
||||||
|
|
|
@ -53,7 +53,7 @@ OF_APPLICATION_DELEGATE(AppDelegate)
|
||||||
[pres addPriority: 20];
|
[pres addPriority: 20];
|
||||||
[pres setTo: [XMPPJID JIDWithString: @"alice@example.com"]];
|
[pres setTo: [XMPPJID JIDWithString: @"alice@example.com"]];
|
||||||
[pres setFrom: [XMPPJID JIDWithString: @"bob@example.org"]];
|
[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>"
|
@"from='bob@example.org'><show>chat</show>"
|
||||||
@"<status>Bored</status><priority>20</priority>"
|
@"<status>Bored</status><priority>20</priority>"
|
||||||
@"</presence>"]);
|
@"</presence>"]);
|
||||||
|
@ -62,7 +62,7 @@ OF_APPLICATION_DELEGATE(AppDelegate)
|
||||||
[msg addBody: @"Hello everyone"];
|
[msg addBody: @"Hello everyone"];
|
||||||
[msg setTo: [XMPPJID JIDWithString: @"jdev@conference.jabber.org"]];
|
[msg setTo: [XMPPJID JIDWithString: @"jdev@conference.jabber.org"]];
|
||||||
[msg setFrom: [XMPPJID JIDWithString: @"alice@example.com"]];
|
[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' "
|
@"to='jdev@conference.jabber.org' "
|
||||||
@"from='alice@example.com'><body>Hello everyone</body>"
|
@"from='alice@example.com'><body>Hello everyone</body>"
|
||||||
@"</message>"]);
|
@"</message>"]);
|
||||||
|
@ -70,7 +70,7 @@ OF_APPLICATION_DELEGATE(AppDelegate)
|
||||||
XMPPIQ *iq = [XMPPIQ IQWithType: @"set" ID: @"128"];
|
XMPPIQ *iq = [XMPPIQ IQWithType: @"set" ID: @"128"];
|
||||||
[iq setTo: [XMPPJID JIDWithString: @"juliet@capulet.lit"]];
|
[iq setTo: [XMPPJID JIDWithString: @"juliet@capulet.lit"]];
|
||||||
[iq setFrom: [XMPPJID JIDWithString: @"romeo@montague.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' "
|
@"to='juliet@capulet.lit' "
|
||||||
@"from='romeo@montague.lit'/>"]);
|
@"from='romeo@montague.lit'/>"]);
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ OF_APPLICATION_DELEGATE(AppDelegate)
|
||||||
[elem addAttributeWithName: @"id"
|
[elem addAttributeWithName: @"id"
|
||||||
stringValue: @"42"];
|
stringValue: @"42"];
|
||||||
XMPPStanza *stanza = [XMPPStanza stanzaWithElement: elem];
|
XMPPStanza *stanza = [XMPPStanza stanzaWithElement: elem];
|
||||||
assert([[elem stringValue] isEqual: [stanza stringValue]]);
|
assert([[elem XMLString] isEqual: [stanza XMLString]]);
|
||||||
assert(([[OFString stringWithFormat: @"%@, %@, %@, %@",
|
assert(([[OFString stringWithFormat: @"%@, %@, %@, %@",
|
||||||
[[stanza from] fullJID], [[stanza to] fullJID], [stanza type],
|
[[stanza from] fullJID], [[stanza to] fullJID], [stanza type],
|
||||||
[stanza ID]] isEqual: @"bob@localhost, alice@localhost, get, 42"]));
|
[stanza ID]] isEqual: @"bob@localhost, alice@localhost, get, 42"]));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue