︙ | | |
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
+
-
-
-
|
#ifdef OF_HAVE_BLOCKS
if (_block != NULL)
_block(_socket, _exception);
else {
#endif
[_socket setDelegate: _delegate];
if (_exception == nil) {
if ([_delegate respondsToSelector:
@selector(socket:didConnectToHost:port:)])
[_delegate socket: _socket
didConnectToHost: _host
port: _port];
if ([_delegate respondsToSelector:
@selector(socket:didConnectToHost:port:exception:)])
[_delegate socket: _socket
didConnectToHost: _host
port: _port
} else {
if ([_delegate respondsToSelector: @selector(socket:
didFailToConnectWithException:host:port:)])
[_delegate socket: _socket
didFailToConnectWithException: _exception
exception: _exception];
host: _host
port: _port];
}
#ifdef OF_HAVE_BLOCKS
}
#endif
}
- (void)of_socketDidConnect: (OF_KINDOF(OFTCPSocket *))sock
exception: (id)exception
|
︙ | | |
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
|
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
|
+
-
+
-
+
+
+
+
+
+
+
+
|
length: 3
runLoopMode: [[OFRunLoop currentRunLoop] currentMode]];
}
- (bool)stream: (OF_KINDOF(OFStream *))sock
didReadIntoBuffer: (void *)buffer
length: (size_t)length
exception: (id)exception
{
of_run_loop_mode_t runLoopMode =
of_run_loop_mode_t runLoopMode;
[[OFRunLoop currentRunLoop] currentMode];
unsigned char *SOCKSVersion;
uint8_t hostLength;
unsigned char port[2];
unsigned char *response, *addressLength;
if (exception != nil) {
_exception = [exception retain];
[self didConnect];
return false;
}
runLoopMode = [[OFRunLoop currentRunLoop] currentMode];
switch (_SOCKS5State) {
case SOCKS5_STATE_READ_VERSION:
SOCKSVersion = buffer;
if (SOCKSVersion[0] != 5 || SOCKSVersion[1] != 0) {
_exception = [[OFConnectionFailedException alloc]
initWithHost: _host
|
︙ | | |
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
|
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
|
+
-
-
+
+
+
+
+
+
+
+
+
|
return false;
}
}
- (size_t)stream: (OF_KINDOF(OFStream *))sock
didWriteBuffer: (const void **)buffer
length: (size_t)length
exception: (id)exception
{
of_run_loop_mode_t runLoopMode =
[[OFRunLoop currentRunLoop] currentMode];
of_run_loop_mode_t runLoopMode;
if (exception != nil) {
_exception = [exception retain];
[self didConnect];
return 0;
}
runLoopMode = [[OFRunLoop currentRunLoop] currentMode];
switch (_SOCKS5State) {
case SOCKS5_STATE_SEND_AUTHENTICATION:
_SOCKS5State = SOCKS5_STATE_READ_VERSION;
[_socket asyncReadIntoBuffer: _buffer
exactLength: 2
runLoopMode: runLoopMode];
|
︙ | | |
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
|
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
|
runLoopMode: runLoopMode];
return 0;
default:
assert(0);
return 0;
}
}
- (void)stream: (OF_KINDOF(OFStream *))sock
didFailToReadWithException: (id)exception
{
_exception = [exception retain];
[self didConnect];
}
- (void)stream: (OF_KINDOF(OFStream *))sock
didFailToWriteWithException: (id)exception
{
_exception = [exception retain];
[self didConnect];
}
@end
@implementation OFTCPSocket_ConnectDelegate
- (void)dealloc
{
[_exception release];
[super dealloc];
}
- (void)socket: (OF_KINDOF(OFTCPSocket *))sock
didConnectToHost: (OFString *)host
port: (uint16_t)port
{
_done = true;
}
- (void)socket: (OF_KINDOF(OFTCPSocket *))sock
didFailToConnectWithException: (id)exception
exception: (id)exception
{
_done = true;
_exception = [exception retain];
}
@end
@implementation OFTCPSocket
|
︙ | | |