Add two delegates for TLS upgrades.

This way, an OFStreamObserver can be used even with TLS.
This commit is contained in:
Jonathan Schleifer 2011-04-03 13:48:59 +02:00
parent 05c2784b17
commit a9443417bc
2 changed files with 21 additions and 2 deletions

View file

@ -58,6 +58,8 @@
- (void)connection: (XMPPConnection*)conn
didReceiveMessage: (XMPPMessage*)msg;
- (void)connectionWasClosed: (XMPPConnection*)conn;
- (void)connectionWillUpgradeToTLS: (XMPPConnection*)conn;
- (void)connectionDidUpgradeToTLS: (XMPPConnection*)conn;
@end
/**

View file

@ -346,11 +346,20 @@
if ([[elem namespace] isEqual: XMPP_NS_STARTTLS]) {
if ([[elem name] isEqual: @"proceed"]) {
/* FIXME: Catch errors here */
SSLSocket *newSock = [[SSLSocket alloc]
initWithSocket: sock];
SSLSocket *newSock;
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];
@ -754,4 +763,12 @@
- (void)connectionWasClosed: (XMPPConnection*)conn
{
}
- (void)connectionWillUpgradeToTLS: (XMPPConnection*)conn
{
}
- (void)connectionDidUpgradeToTLS: (XMPPConnection*)conn
{
}
@end