Split up XMPP_handleStanza.
Non-Stanzas are now handled in separate functions
This commit is contained in:
parent
91b2a0b119
commit
683fc1e3ae
2 changed files with 106 additions and 93 deletions
|
@ -163,6 +163,9 @@
|
||||||
- (XMPPRoster*)roster;
|
- (XMPPRoster*)roster;
|
||||||
|
|
||||||
- (void)XMPP_startStream;
|
- (void)XMPP_startStream;
|
||||||
|
- (void)XMPP_handleStream: (OFXMLElement*)elem;
|
||||||
|
- (void)XMPP_handleTLS: (OFXMLElement*)elem;
|
||||||
|
- (void)XMPP_handleSASL: (OFXMLElement*)elem;
|
||||||
- (void)XMPP_handleStanza: (OFXMLElement*)elem;
|
- (void)XMPP_handleStanza: (OFXMLElement*)elem;
|
||||||
- (void)XMPP_sendAuth: (OFString*)name;
|
- (void)XMPP_sendAuth: (OFString*)name;
|
||||||
- (void)XMPP_handleIQ: (XMPPIQ*)iq;
|
- (void)XMPP_handleIQ: (XMPPIQ*)iq;
|
||||||
|
|
|
@ -297,7 +297,17 @@
|
||||||
|
|
||||||
of_log(@"In: %@", elem);
|
of_log(@"In: %@", elem);
|
||||||
|
|
||||||
[self XMPP_handleStanza: elem];
|
if ([[elem namespace] isEqual: XMPP_NS_CLIENT])
|
||||||
|
[self XMPP_handleStanza: elem];
|
||||||
|
|
||||||
|
if ([[elem namespace] isEqual: XMPP_NS_STREAM])
|
||||||
|
[self XMPP_handleStream: elem];
|
||||||
|
|
||||||
|
if ([[elem namespace] isEqual: XMPP_NS_STARTTLS])
|
||||||
|
[self XMPP_handleTLS: elem];
|
||||||
|
|
||||||
|
if ([[elem namespace] isEqual: XMPP_NS_SASL])
|
||||||
|
[self XMPP_handleSASL: elem];
|
||||||
|
|
||||||
[pool release];
|
[pool release];
|
||||||
}
|
}
|
||||||
|
@ -313,111 +323,111 @@
|
||||||
|
|
||||||
- (void)XMPP_handleStanza: (OFXMLElement*)elem
|
- (void)XMPP_handleStanza: (OFXMLElement*)elem
|
||||||
{
|
{
|
||||||
if ([[elem namespace] isEqual: XMPP_NS_CLIENT]) {
|
if ([[elem name] isEqual: @"iq"]) {
|
||||||
if ([[elem name] isEqual: @"iq"]) {
|
[self XMPP_handleIQ: [XMPPIQ stanzaWithElement: elem]];
|
||||||
[self XMPP_handleIQ: [XMPPIQ stanzaWithElement: elem]];
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ([[elem name] isEqual: @"message"]) {
|
|
||||||
[self XMPP_handleMessage:
|
|
||||||
[XMPPMessage stanzaWithElement: elem]];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ([[elem name] isEqual: @"presence"]) {
|
|
||||||
[self XMPP_handlePresence:
|
|
||||||
[XMPPPresence stanzaWithElement: elem]];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([[elem namespace] isEqual: XMPP_NS_STREAM]) {
|
if ([[elem name] isEqual: @"message"]) {
|
||||||
if ([[elem name] isEqual: @"features"]) {
|
[self XMPP_handleMessage:
|
||||||
[self XMPP_handleFeatures: elem];
|
[XMPPMessage stanzaWithElement: elem]];
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
assert(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([[elem namespace] isEqual: XMPP_NS_STARTTLS]) {
|
if ([[elem name] isEqual: @"presence"]) {
|
||||||
if ([[elem name] isEqual: @"proceed"]) {
|
[self XMPP_handlePresence:
|
||||||
/* FIXME: Catch errors here */
|
[XMPPPresence stanzaWithElement: elem]];
|
||||||
SSLSocket *newSock;
|
return;
|
||||||
|
|
||||||
if ([delegate respondsToSelector:
|
|
||||||
@selector(connectionWillUpgradeToTLS:)])
|
|
||||||
[delegate connectionWillUpgradeToTLS: self];
|
|
||||||
|
|
||||||
newSock = [[SSLSocket alloc] initWithSocket: sock];
|
|
||||||
[sock release];
|
|
||||||
sock = newSock;
|
|
||||||
|
|
||||||
if ([delegate respondsToSelector:
|
|
||||||
@selector(connectionDidUpgradeToTLS:)])
|
|
||||||
[delegate connectionDidUpgradeToTLS: self];
|
|
||||||
|
|
||||||
/* Stream restart */
|
|
||||||
[parser setDelegate: self];
|
|
||||||
[self XMPP_startStream];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ([[elem name] isEqual: @"failure"])
|
|
||||||
/* TODO: Find/create an exception to throw here */
|
|
||||||
@throw [OFException newWithClass: isa];
|
|
||||||
|
|
||||||
assert(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([[elem namespace] isEqual: XMPP_NS_SASL]) {
|
assert(0);
|
||||||
if ([[elem name] isEqual: @"challenge"]) {
|
}
|
||||||
OFXMLElement *responseTag;
|
|
||||||
OFDataArray *challenge =
|
|
||||||
[OFDataArray dataArrayWithBase64EncodedString:
|
|
||||||
[elem stringValue]];
|
|
||||||
OFDataArray *response = [authModule
|
|
||||||
calculateResponseWithChallenge: challenge];
|
|
||||||
|
|
||||||
responseTag = [OFXMLElement
|
|
||||||
elementWithName: @"response"
|
|
||||||
namespace: XMPP_NS_SASL];
|
|
||||||
[responseTag addChild:
|
|
||||||
[OFXMLElement elementWithCharacters:
|
|
||||||
[response stringByBase64Encoding]]];
|
|
||||||
|
|
||||||
[self sendStanza: responseTag];
|
- (void)XMPP_handleStream: (OFXMLElement*)elem
|
||||||
return;
|
{
|
||||||
}
|
if ([[elem name] isEqual: @"features"]) {
|
||||||
|
[self XMPP_handleFeatures: elem];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ([[elem name] isEqual: @"success"]) {
|
assert(0);
|
||||||
[authModule parseServerFinalMessage:
|
}
|
||||||
[OFDataArray dataArrayWithBase64EncodedString:
|
|
||||||
[elem stringValue]]];
|
|
||||||
|
|
||||||
if ([delegate respondsToSelector:
|
- (void)XMPP_handleTLS: (OFXMLElement*)elem
|
||||||
@selector(connectionWasAuthenticated:)])
|
{
|
||||||
[delegate connectionWasAuthenticated: self];
|
if ([[elem name] isEqual: @"proceed"]) {
|
||||||
|
/* FIXME: Catch errors here */
|
||||||
|
SSLSocket *newSock;
|
||||||
|
|
||||||
/* Stream restart */
|
if ([delegate respondsToSelector:
|
||||||
[parser setDelegate: self];
|
@selector(connectionWillUpgradeToTLS:)])
|
||||||
[self XMPP_startStream];
|
[delegate connectionWillUpgradeToTLS: self];
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ([[elem name] isEqual: @"failure"]) {
|
newSock = [[SSLSocket alloc] initWithSocket: sock];
|
||||||
of_log(@"Auth failed!");
|
[sock release];
|
||||||
// FIXME: Do more parsing/handling
|
sock = newSock;
|
||||||
@throw [XMPPAuthFailedException
|
|
||||||
newWithClass: isa
|
|
||||||
connection: self
|
|
||||||
reason: [elem XMLString]];
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(0);
|
if ([delegate respondsToSelector:
|
||||||
|
@selector(connectionDidUpgradeToTLS:)])
|
||||||
|
[delegate connectionDidUpgradeToTLS: self];
|
||||||
|
|
||||||
|
/* Stream restart */
|
||||||
|
[parser setDelegate: self];
|
||||||
|
[self XMPP_startStream];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([[elem name] isEqual: @"failure"])
|
||||||
|
/* TODO: Find/create an exception to throw here */
|
||||||
|
@throw [OFException newWithClass: isa];
|
||||||
|
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)XMPP_handleSASL: (OFXMLElement*)elem
|
||||||
|
{
|
||||||
|
if ([[elem name] isEqual: @"challenge"]) {
|
||||||
|
OFXMLElement *responseTag;
|
||||||
|
OFDataArray *challenge =
|
||||||
|
[OFDataArray dataArrayWithBase64EncodedString:
|
||||||
|
[elem stringValue]];
|
||||||
|
OFDataArray *response = [authModule
|
||||||
|
calculateResponseWithChallenge: challenge];
|
||||||
|
|
||||||
|
responseTag = [OFXMLElement
|
||||||
|
elementWithName: @"response"
|
||||||
|
namespace: XMPP_NS_SASL];
|
||||||
|
[responseTag addChild:
|
||||||
|
[OFXMLElement elementWithCharacters:
|
||||||
|
[response stringByBase64Encoding]]];
|
||||||
|
|
||||||
|
[self sendStanza: responseTag];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([[elem name] isEqual: @"success"]) {
|
||||||
|
[authModule parseServerFinalMessage:
|
||||||
|
[OFDataArray dataArrayWithBase64EncodedString:
|
||||||
|
[elem stringValue]]];
|
||||||
|
|
||||||
|
if ([delegate respondsToSelector:
|
||||||
|
@selector(connectionWasAuthenticated:)])
|
||||||
|
[delegate connectionWasAuthenticated: self];
|
||||||
|
|
||||||
|
/* Stream restart */
|
||||||
|
[parser setDelegate: self];
|
||||||
|
[self XMPP_startStream];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([[elem name] isEqual: @"failure"]) {
|
||||||
|
of_log(@"Auth failed!");
|
||||||
|
// FIXME: Do more parsing/handling
|
||||||
|
@throw [XMPPAuthFailedException
|
||||||
|
newWithClass: isa
|
||||||
|
connection: self
|
||||||
|
reason: [elem XMLString]];
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(0);
|
assert(0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue