Skip to content

Commit f533eb8

Browse files
committed
Bug fix for issue robbiehanson#81 - framework stops receiving responses in renegotiate
1 parent c4d42e1 commit f533eb8

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

Core/XMPPStream.m

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,6 @@ - (void)commonInit
215215
numberOfBytesSent = 0;
216216
numberOfBytesReceived = 0;
217217

218-
parser = [[XMPPParser alloc] initWithDelegate:self delegateQueue:xmppQueue];
219-
220218
hostPort = 5222;
221219
keepAliveInterval = DEFAULT_KEEPALIVE_INTERVAL;
222220
keepAliveData = [@" " dataUsingEncoding:NSUTF8StringEncoding];
@@ -1374,6 +1372,17 @@ - (BOOL)secureConnection:(NSError **)errPtr
13741372
return_from_block;
13751373
}
13761374

1375+
if ([self isSecure])
1376+
{
1377+
NSString *errMsg = @"The connection is already secure.";
1378+
NSDictionary *info = [NSDictionary dictionaryWithObject:errMsg forKey:NSLocalizedDescriptionKey];
1379+
1380+
err = [NSError errorWithDomain:XMPPStreamErrorDomain code:XMPPStreamInvalidState userInfo:info];
1381+
1382+
result = NO;
1383+
return_from_block;
1384+
}
1385+
13771386
if (![self supportsStartTLS])
13781387
{
13791388
NSString *errMsg = @"The server does not support startTLS.";
@@ -2671,25 +2680,19 @@ - (void)sendOpeningNegotiation
26712680
[self setDidStartNegotiation:YES];
26722681
}
26732682

2674-
if (state != STATE_XMPP_CONNECTING)
2675-
{
2676-
XMPPLogVerbose(@"%@: Resetting parser...", THIS_FILE);
2677-
2678-
// We're restarting our negotiation, so we need to reset the parser.
2679-
[parser setDelegate:nil delegateQueue:NULL];
2680-
2681-
parser = [[XMPPParser alloc] initWithDelegate:self delegateQueue:xmppQueue];
2682-
}
2683-
else if (parser == nil)
2683+
if (parser == nil)
26842684
{
26852685
XMPPLogVerbose(@"%@: Initializing parser...", THIS_FILE);
26862686

2687-
// Need to create parser (it was destroyed when the socket was last disconnected)
2687+
// Need to create the parser.
26882688
parser = [[XMPPParser alloc] initWithDelegate:self delegateQueue:xmppQueue];
26892689
}
26902690
else
26912691
{
2692-
XMPPLogVerbose(@"%@: Not touching parser...", THIS_FILE);
2692+
XMPPLogVerbose(@"%@: Resetting parser...", THIS_FILE);
2693+
2694+
// We're restarting our negotiation, so we need to reset the parser.
2695+
parser = [[XMPPParser alloc] initWithDelegate:self delegateQueue:xmppQueue];
26932696
}
26942697

26952698
NSString *xmlns = @"jabber:client";
@@ -3047,6 +3050,16 @@ - (void)handleAuth:(NSXMLElement *)authResponse
30473050
{
30483051
// Now we start our negotiation over again...
30493052
[self sendOpeningNegotiation];
3053+
3054+
if (![self isSecure])
3055+
{
3056+
// Normally we requeue our read operation in xmppParserDidParseData:.
3057+
// But we just reset the parser, so that code path isn't going to happen.
3058+
// So start read request here.
3059+
// The state is STATE_XMPP_OPENING, set via sendOpeningNegotiation method.
3060+
3061+
[asyncSocket readDataWithTimeout:TIMEOUT_XMPP_READ_START tag:TAG_XMPP_READ_START];
3062+
}
30503063
}
30513064
else
30523065
{
@@ -3447,7 +3460,7 @@ - (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)t
34473460
{
34483461
[asyncSocket readDataWithTimeout:TIMEOUT_XMPP_READ_START tag:TAG_XMPP_READ_START];
34493462
}
3450-
else if (state != STATE_XMPP_STARTTLS_2)
3463+
else
34513464
{
34523465
[asyncSocket readDataWithTimeout:TIMEOUT_XMPP_READ_STREAM tag:TAG_XMPP_READ_STREAM];
34533466
}
@@ -3748,7 +3761,7 @@ - (void)xmppParserDidParseData:(XMPPParser *)sender
37483761
{
37493762
[asyncSocket readDataWithTimeout:TIMEOUT_XMPP_READ_START tag:TAG_XMPP_READ_START];
37503763
}
3751-
else if (state != STATE_XMPP_STARTTLS_2)
3764+
else if (state != STATE_XMPP_STARTTLS_2) // Don't queue read operation prior to [asyncSocket startTLS:]
37523765
{
37533766
[asyncSocket readDataWithTimeout:TIMEOUT_XMPP_READ_STREAM tag:TAG_XMPP_READ_STREAM];
37543767
}

0 commit comments

Comments
 (0)