@@ -215,8 +215,6 @@ - (void)commonInit
215
215
numberOfBytesSent = 0 ;
216
216
numberOfBytesReceived = 0 ;
217
217
218
- parser = [[XMPPParser alloc ] initWithDelegate: self delegateQueue: xmppQueue];
219
-
220
218
hostPort = 5222 ;
221
219
keepAliveInterval = DEFAULT_KEEPALIVE_INTERVAL;
222
220
keepAliveData = [@" " dataUsingEncoding: NSUTF8StringEncoding];
@@ -1374,6 +1372,17 @@ - (BOOL)secureConnection:(NSError **)errPtr
1374
1372
return_from_block;
1375
1373
}
1376
1374
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
+
1377
1386
if (![self supportsStartTLS ])
1378
1387
{
1379
1388
NSString *errMsg = @" The server does not support startTLS." ;
@@ -2671,25 +2680,19 @@ - (void)sendOpeningNegotiation
2671
2680
[self setDidStartNegotiation: YES ];
2672
2681
}
2673
2682
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 )
2684
2684
{
2685
2685
XMPPLogVerbose (@" %@ : Initializing parser..." , THIS_FILE);
2686
2686
2687
- // Need to create parser (it was destroyed when the socket was last disconnected)
2687
+ // Need to create the parser.
2688
2688
parser = [[XMPPParser alloc ] initWithDelegate: self delegateQueue: xmppQueue];
2689
2689
}
2690
2690
else
2691
2691
{
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];
2693
2696
}
2694
2697
2695
2698
NSString *xmlns = @" jabber:client" ;
@@ -3047,6 +3050,16 @@ - (void)handleAuth:(NSXMLElement *)authResponse
3047
3050
{
3048
3051
// Now we start our negotiation over again...
3049
3052
[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
+ }
3050
3063
}
3051
3064
else
3052
3065
{
@@ -3447,7 +3460,7 @@ - (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)t
3447
3460
{
3448
3461
[asyncSocket readDataWithTimeout: TIMEOUT_XMPP_READ_START tag: TAG_XMPP_READ_START];
3449
3462
}
3450
- else if (state != STATE_XMPP_STARTTLS_2)
3463
+ else
3451
3464
{
3452
3465
[asyncSocket readDataWithTimeout: TIMEOUT_XMPP_READ_STREAM tag: TAG_XMPP_READ_STREAM];
3453
3466
}
@@ -3748,7 +3761,7 @@ - (void)xmppParserDidParseData:(XMPPParser *)sender
3748
3761
{
3749
3762
[asyncSocket readDataWithTimeout: TIMEOUT_XMPP_READ_START tag: TAG_XMPP_READ_START];
3750
3763
}
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:]
3752
3765
{
3753
3766
[asyncSocket readDataWithTimeout: TIMEOUT_XMPP_READ_STREAM tag: TAG_XMPP_READ_STREAM];
3754
3767
}
0 commit comments