Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -1,6 +1,6 @@ all: objfw-compile -Wall --lib 0.0 -o objxmpp *.m \ - `pkg-config --cflags --libs libidn` + `pkg-config --cflags --libs libidn` -lobjgnutls clean: rm -f *.o *.so *.dylib *.dll Index: src/XMPPConnection.m ================================================================== --- src/XMPPConnection.m +++ src/XMPPConnection.m @@ -24,10 +24,12 @@ #include #include #include +#import + #import "XMPPConnection.h" #import "XMPPSCRAMAuth.h" #import "XMPPPLAINAuth.h" #import "XMPPStanza.h" #import "XMPPJID.h" @@ -35,10 +37,11 @@ #import "XMPPExceptions.h" #define NS_BIND @"urn:ietf:params:xml:ns:xmpp-bind" #define NS_CLIENT @"jabber:client" #define NS_SASL @"urn:ietf:params:xml:ns:xmpp-sasl" +#define NS_STARTTLS @"urn:ietf:params:xml:ns:xmpp-tls" #define NS_STREAM @"http://etherx.jabber.org/streams" @implementation XMPPConnection @synthesize username, password, server, resource, JID, port, useTLS, delegate; @@ -269,10 +272,13 @@ - (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]]; @@ -290,10 +296,14 @@ [self _sendAuth: @"PLAIN"]; } if (bind != nil) [self _sendResourceBind]; + + if (starttls != nil) + [self sendStanza: [OFXMLElement elementWithName: @"starttls" + namespace: NS_STARTTLS]]; } - (void)elementBuilder: (OFXMLElementBuilder*)b didBuildElement: (OFXMLElement*)elem { @@ -304,10 +314,25 @@ if ([elem.name isEqual: @"features"] && [elem.namespace isEqual: NS_STREAM]) { [self _handleFeatures: elem]; return; } + + if ([elem.namespace isEqual: NS_STARTTLS]) { + 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]; + } if ([elem.namespace isEqual: NS_SASL]) { if ([elem.name isEqual: @"challenge"]) { OFXMLElement *responseTag; OFDataArray *challenge =