Skip to content

Commit d884c25

Browse files
committed
Adding a proper NSError for cases where the stream is disconnected due to the startTLSPolicy.
1 parent 3f87a40 commit d884c25

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

Core/XMPPStream.m

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ @interface XMPPStream ()
102102

103103
XMPPParser *parser;
104104
NSError *parserError;
105+
NSError *otherError;
105106

106107
Byte flags;
107108
Byte config;
@@ -3373,9 +3374,16 @@ - (void)handleStreamFeatures
33733374
return;
33743375
}
33753376
}
3376-
else if(![self isSecure] && [self startTLSPolicy] == XMPPStreamStartTLSPolicyRequired)
3377+
else if (![self isSecure] && [self startTLSPolicy] == XMPPStreamStartTLSPolicyRequired)
33773378
{
3378-
// We can close our TCP connection now as the server doesn't support TLS.
3379+
// We must abort the connection as the server doesn't support our requirements.
3380+
3381+
NSString *errMsg = @"The server does not support startTLS. And the startTLSPolicy is Required.";
3382+
NSDictionary *info = [NSDictionary dictionaryWithObject:errMsg forKey:NSLocalizedDescriptionKey];
3383+
3384+
otherError = [NSError errorWithDomain:XMPPStreamErrorDomain code:XMPPStreamUnsupportedAction userInfo:info];
3385+
3386+
// Close the TCP connection.
33793387
[self disconnect];
33803388

33813389
// The socketDidDisconnect:withError: method will handle everything else
@@ -4103,11 +4111,14 @@ - (void)socketDidDisconnect:(GCDAsyncSocket *)sock withError:(NSError *)err
41034111

41044112
// Notify delegate
41054113

4106-
if (parserError)
4114+
if (parserError || otherError)
41074115
{
4108-
[multicastDelegate xmppStreamDidDisconnect:self withError:parserError];
4116+
NSError *error = parserError ? parserError : otherError;
4117+
4118+
[multicastDelegate xmppStreamDidDisconnect:self withError:error];
41094119

41104120
parserError = nil;
4121+
otherError = nil;
41114122
}
41124123
else
41134124
{

0 commit comments

Comments
 (0)