Stop caching authentication mechanisms

We don't need to do that. In fact we had to do additional work.
This commit is contained in:
Florian Zeitz 2011-03-10 22:14:32 +01:00
parent 54ffeac46b
commit b1439941ba
2 changed files with 22 additions and 29 deletions

View file

@ -63,7 +63,6 @@
/// Whether to use TLS /// Whether to use TLS
BOOL useTLS; BOOL useTLS;
id <XMPPConnectionDelegate> delegate; id <XMPPConnectionDelegate> delegate;
OFMutableArray *mechanisms;
XMPPAuthenticator *authModule; XMPPAuthenticator *authModule;
} }

View file

@ -56,8 +56,6 @@
port = 5222; port = 5222;
useTLS = YES; useTLS = YES;
mechanisms = [[OFMutableArray alloc] init];
parser.delegate = self; parser.delegate = self;
elementBuilder.delegate = self; elementBuilder.delegate = self;
@ -272,36 +270,37 @@
- (void)_handleFeatures: (OFXMLElement*)elem - (void)_handleFeatures: (OFXMLElement*)elem
{ {
OFArray *mechs = [elem elementsForName: @"mechanisms"
namespace: NS_SASL];
OFXMLElement *starttls = [elem OFXMLElement *starttls = [elem
elementsForName: @"starttls" elementsForName: @"starttls"
namespace: NS_STARTTLS].firstObject; namespace: NS_STARTTLS].firstObject;
OFXMLElement *bind = [elem elementsForName: @"bind" OFXMLElement *bind = [elem elementsForName: @"bind"
namespace: NS_BIND].firstObject; namespace: NS_BIND].firstObject;
OFArray *mechs = [elem elementsForName: @"mechanisms"
for (OFXMLElement *mech in [mechs.firstObject children]) namespace: NS_SASL];
[mechanisms addObject: [mech.children.firstObject stringValue]]; OFMutableArray *mechanisms = [OFMutableArray array];
if ([mechanisms containsObject: @"SCRAM-SHA-1"]) {
authModule = [[XMPPSCRAMAuth alloc]
initWithAuthcid: username
password: password
hash: [OFSHA1Hash class]];
[self _sendAuth: @"SCRAM-SHA-1"];
} else if ([mechanisms containsObject: @"PLAIN"]) {
authModule = [[XMPPPLAINAuth alloc]
initWithAuthcid: username
password: password];
[self _sendAuth: @"PLAIN"];
}
if (bind != nil)
[self _sendResourceBind];
if (starttls != nil) if (starttls != nil)
[self sendStanza: [OFXMLElement elementWithName: @"starttls" [self sendStanza: [OFXMLElement elementWithName: @"starttls"
namespace: NS_STARTTLS]]; namespace: NS_STARTTLS]];
else if ([mechs count]) {
for (OFXMLElement *mech in [mechs.firstObject children])
[mechanisms addObject:
[mech.children.firstObject stringValue]];
if ([mechanisms containsObject: @"SCRAM-SHA-1"]) {
authModule = [[XMPPSCRAMAuth alloc]
initWithAuthcid: username
password: password
hash: [OFSHA1Hash class]];
[self _sendAuth: @"SCRAM-SHA-1"];
} else if ([mechanisms containsObject: @"PLAIN"]) {
authModule = [[XMPPPLAINAuth alloc]
initWithAuthcid: username
password: password];
[self _sendAuth: @"PLAIN"];
}
} else if (bind != nil)
[self _sendResourceBind];
} }
- (void)elementBuilder: (OFXMLElementBuilder*)b - (void)elementBuilder: (OFXMLElementBuilder*)b
@ -323,8 +322,6 @@
sock = [[GTLSSocket alloc] initWithSocket: sock]; sock = [[GTLSSocket alloc] initWithSocket: sock];
/* Stream restart */ /* Stream restart */
[mechanisms release];
mechanisms = [[OFMutableArray alloc] init];
parser.delegate = self; parser.delegate = self;
[self _startStream]; [self _startStream];
} else if ([elem.name isEqual: @"failure"]) } else if ([elem.name isEqual: @"failure"])
@ -356,10 +353,7 @@
of_log(@"Auth successful"); of_log(@"Auth successful");
/* Stream restart */ /* Stream restart */
[mechanisms release];
mechanisms = [[OFMutableArray alloc] init];
parser.delegate = self; parser.delegate = self;
[self _startStream]; [self _startStream];
} else if ([elem.name isEqual: @"failure"]) { } else if ([elem.name isEqual: @"failure"]) {
of_log(@"Auth failed!"); of_log(@"Auth failed!");