Index: src/XMPPConnection.h ================================================================== --- src/XMPPConnection.h +++ src/XMPPConnection.h @@ -61,11 +61,10 @@ /// The port to connect to short port; /// Whether to use TLS BOOL useTLS; id delegate; - OFMutableArray *mechanisms; XMPPAuthenticator *authModule; } @property (copy) OFString *username; @property (copy) OFString *password; Index: src/XMPPConnection.m ================================================================== --- src/XMPPConnection.m +++ src/XMPPConnection.m @@ -54,12 +54,10 @@ elementBuilder = [[OFXMLElementBuilder alloc] init]; port = 5222; useTLS = YES; - mechanisms = [[OFMutableArray alloc] init]; - parser.delegate = self; elementBuilder.delegate = self; return self; } @@ -270,40 +268,41 @@ } } - (void)_handleFeatures: (OFXMLElement*)elem { - OFArray *mechs = [elem elementsForName: @"mechanisms" - namespace: NS_SASL]; OFXMLElement *starttls = [elem elementsForName: @"starttls" namespace: NS_STARTTLS].firstObject; OFXMLElement *bind = [elem elementsForName: @"bind" namespace: NS_BIND].firstObject; - - 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"]; - } - - if (bind != nil) - [self _sendResourceBind]; + OFArray *mechs = [elem elementsForName: @"mechanisms" + namespace: NS_SASL]; + OFMutableArray *mechanisms = [OFMutableArray array]; if (starttls != nil) [self sendStanza: [OFXMLElement elementWithName: @"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 didBuildElement: (OFXMLElement*)elem { @@ -321,12 +320,10 @@ if ([elem.name isEqual: @"proceed"]) { /* FIXME: Catch errors here */ sock = [[GTLSSocket alloc] initWithSocket: sock]; /* Stream restart */ - [mechanisms release]; - mechanisms = [[OFMutableArray alloc] init]; parser.delegate = self; [self _startStream]; } else if ([elem.name isEqual: @"failure"]) /* TODO: Find/create an exception to throw here */ @throw [OFException newWithClass: isa]; @@ -354,14 +351,11 @@ [OFDataArray dataArrayWithBase64EncodedString: [elem.children.firstObject stringValue]]]; of_log(@"Auth successful"); /* Stream restart */ - [mechanisms release]; - mechanisms = [[OFMutableArray alloc] init]; parser.delegate = self; - [self _startStream]; } else if ([elem.name isEqual: @"failure"]) { of_log(@"Auth failed!"); // FIXME: Do more parsing/handling @throw [XMPPAuthFailedException