Skip to content

Commit

Permalink
Bug fix for issue #81 - framework stops receiving responses in renego…
Browse files Browse the repository at this point in the history
…tiate
  • Loading branch information
robbiehanson committed Aug 2, 2012
1 parent c4d42e1 commit f533eb8
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions Core/XMPPStream.m
Expand Up @@ -215,8 +215,6 @@ - (void)commonInit
numberOfBytesSent = 0;
numberOfBytesReceived = 0;

parser = [[XMPPParser alloc] initWithDelegate:self delegateQueue:xmppQueue];

hostPort = 5222;
keepAliveInterval = DEFAULT_KEEPALIVE_INTERVAL;
keepAliveData = [@" " dataUsingEncoding:NSUTF8StringEncoding];
Expand Down Expand Up @@ -1374,6 +1372,17 @@ - (BOOL)secureConnection:(NSError **)errPtr
return_from_block;
}

if ([self isSecure])
{
NSString *errMsg = @"The connection is already secure.";
NSDictionary *info = [NSDictionary dictionaryWithObject:errMsg forKey:NSLocalizedDescriptionKey];

err = [NSError errorWithDomain:XMPPStreamErrorDomain code:XMPPStreamInvalidState userInfo:info];

result = NO;
return_from_block;
}

if (![self supportsStartTLS])
{
NSString *errMsg = @"The server does not support startTLS.";
Expand Down Expand Up @@ -2671,25 +2680,19 @@ - (void)sendOpeningNegotiation
[self setDidStartNegotiation:YES];
}

if (state != STATE_XMPP_CONNECTING)
{
XMPPLogVerbose(@"%@: Resetting parser...", THIS_FILE);

// We're restarting our negotiation, so we need to reset the parser.
[parser setDelegate:nil delegateQueue:NULL];

parser = [[XMPPParser alloc] initWithDelegate:self delegateQueue:xmppQueue];
}
else if (parser == nil)
if (parser == nil)
{
XMPPLogVerbose(@"%@: Initializing parser...", THIS_FILE);

// Need to create parser (it was destroyed when the socket was last disconnected)
// Need to create the parser.
parser = [[XMPPParser alloc] initWithDelegate:self delegateQueue:xmppQueue];
}
else
{
XMPPLogVerbose(@"%@: Not touching parser...", THIS_FILE);
XMPPLogVerbose(@"%@: Resetting parser...", THIS_FILE);

// We're restarting our negotiation, so we need to reset the parser.
parser = [[XMPPParser alloc] initWithDelegate:self delegateQueue:xmppQueue];
}

NSString *xmlns = @"jabber:client";
Expand Down Expand Up @@ -3047,6 +3050,16 @@ - (void)handleAuth:(NSXMLElement *)authResponse
{
// Now we start our negotiation over again...
[self sendOpeningNegotiation];

if (![self isSecure])
{
// Normally we requeue our read operation in xmppParserDidParseData:.
// But we just reset the parser, so that code path isn't going to happen.
// So start read request here.
// The state is STATE_XMPP_OPENING, set via sendOpeningNegotiation method.

[asyncSocket readDataWithTimeout:TIMEOUT_XMPP_READ_START tag:TAG_XMPP_READ_START];
}
}
else
{
Expand Down Expand Up @@ -3447,7 +3460,7 @@ - (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)t
{
[asyncSocket readDataWithTimeout:TIMEOUT_XMPP_READ_START tag:TAG_XMPP_READ_START];
}
else if (state != STATE_XMPP_STARTTLS_2)
else
{
[asyncSocket readDataWithTimeout:TIMEOUT_XMPP_READ_STREAM tag:TAG_XMPP_READ_STREAM];
}
Expand Down Expand Up @@ -3748,7 +3761,7 @@ - (void)xmppParserDidParseData:(XMPPParser *)sender
{
[asyncSocket readDataWithTimeout:TIMEOUT_XMPP_READ_START tag:TAG_XMPP_READ_START];
}
else if (state != STATE_XMPP_STARTTLS_2)
else if (state != STATE_XMPP_STARTTLS_2) // Don't queue read operation prior to [asyncSocket startTLS:]
{
[asyncSocket readDataWithTimeout:TIMEOUT_XMPP_READ_STREAM tag:TAG_XMPP_READ_STREAM];
}
Expand Down

0 comments on commit f533eb8

Please sign in to comment.