Index: src/XMPPConnection.h ================================================================== --- src/XMPPConnection.h +++ src/XMPPConnection.h @@ -71,11 +71,11 @@ XMPPJID *JID; uint16_t port; id delegate; XMPPAuthenticator *authModule; BOOL needsSession; - BOOL encrypted; + BOOL encryptionRequired, encrypted; unsigned int lastID; OFString *bindID, *sessionID; XMPPRoster *roster; } @@ -84,10 +84,11 @@ @property (copy, readonly) XMPPJID *JID; @property (assign) uint16_t port; @property (retain) id delegate; @property (readonly, retain) XMPPRoster *roster; @property (readonly, retain, getter=socket) OFTCPSocket *sock; +@property (assign) BOOL encryptionRequired; @property (readonly) BOOL encrypted; #endif /** * \return A new autoreleased XMPPConnection @@ -119,10 +120,22 @@ /** * \return The socket used by the XMPPConnection */ - (OFTCPSocket*)socket; +/** + * \return Whether encryption is encrypted + */ +- (BOOL)encryptionRequired; + +/** + * Sets whether encryption is required. + * + * \param required Whether encryption is required + */ +- (void)setEncryptionRequired: (BOOL)required; + /** * \return Whether the connection is encrypted */ - (BOOL)encrypted; Index: src/XMPPConnection.m ================================================================== --- src/XMPPConnection.m +++ src/XMPPConnection.m @@ -326,10 +326,20 @@ - (OFTCPSocket*)socket { return [[sock retain] autorelease]; } + +- (BOOL)encryptionRequired +{ + return encryptionRequired; +} + +- (void)setEncryptionRequired: (BOOL)required +{ + encryptionRequired = required; +} - (BOOL)encrypted { return encrypted; } @@ -709,10 +719,14 @@ [OFXMLElement elementWithName: @"starttls" namespace: XMPP_NS_STARTTLS]]; return; } + if (encryptionRequired && !encrypted) + /* TODO: Find/create an exception to throw here */ + @throw [OFException newWithClass: isa]; + if (mechs != nil) { OFEnumerator *enumerator; OFXMLElement *mech; enumerator = [[mechs children] objectEnumerator];