ObjFW  Diff

Differences From Artifact [dd4630f033]:

To Artifact [d516c427cd]:


359
360
361
362
363
364
365



366
367

368
369

370
371
372
373
374
375
376
359
360
361
362
363
364
365
366
367
368
369

370


371
372
373
374
375
376
377
378







+
+
+

-
+
-
-
+







						    socketAddresses:context:
						    exception:)
				       context: nil];
}

- (void)sendSOCKS5Request
{
	OFData *data = [OFData dataWithItems: "\x05\x01\x00"
				       count: 3];

	_SOCKS5State = SOCKS5_STATE_SEND_AUTHENTICATION;
	[_socket asyncWriteBuffer: "\x05\x01\x00"
	[_socket asyncWriteData: data
			   length: 3
		      runLoopMode: [[OFRunLoop currentRunLoop] currentMode]];
		    runLoopMode: [[OFRunLoop currentRunLoop] currentMode]];
}

-      (bool)stream: (OF_KINDOF(OFStream *))sock
  didReadIntoBuffer: (void *)buffer
	     length: (size_t)length
	  exception: (id)exception
{
415
416
417
418
419
420
421
422

423
424

425
426
427
428
429
430
431
417
418
419
420
421
422
423

424


425
426
427
428
429
430
431
432







-
+
-
-
+








		port[0] = _port >> 8;
		port[1] = _port & 0xFF;
		[_request addItems: port
			    count: 2];

		_SOCKS5State = SOCKS5_STATE_SEND_REQUEST;
		[_socket asyncWriteBuffer: [_request items]
		[_socket asyncWriteData: _request
				   length: [_request count]
			      runLoopMode: runLoopMode];
			    runLoopMode: runLoopMode];
		return false;
	case SOCKS5_STATE_READ_RESPONSE:
		response = buffer;

		if (response[0] != 5 || response[2] != 0) {
			_exception = [[OFConnectionFailedException alloc]
			    initWithHost: _host
519
520
521
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
547

548
549
550
551
552
553
554
555
556

557
558
559

560
561
562
563
564
565
566
520
521
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
547

548
549
550
551
552
553
554
555
556

557
558
559

560
561
562
563
564
565
566
567







-
-
-
-
+
+
+
+






-
+










-
+








-
+


-
+







		return false;
	default:
		assert(0);
		return false;
	}
}

- (size_t)stream: (OF_KINDOF(OFStream *))sock
  didWriteBuffer: (const void **)buffer
	  length: (size_t)length
       exception: (id)exception
- (OFData *)stream: (OF_KINDOF(OFStream *))sock
      didWriteData: (OFData *)data
      bytesWritten: (size_t)bytesWritten
	 exception: (id)exception
{
	of_run_loop_mode_t runLoopMode;

	if (exception != nil) {
		_exception = [exception retain];
		[self didConnect];
		return 0;
		return nil;
	}

	runLoopMode = [[OFRunLoop currentRunLoop] currentMode];

	switch (_SOCKS5State) {
	case SOCKS5_STATE_SEND_AUTHENTICATION:
		_SOCKS5State = SOCKS5_STATE_READ_VERSION;
		[_socket asyncReadIntoBuffer: _buffer
				 exactLength: 2
				 runLoopMode: runLoopMode];
		return 0;
		return nil;
	case SOCKS5_STATE_SEND_REQUEST:
		[_request release];
		_request = nil;

		_SOCKS5State = SOCKS5_STATE_READ_RESPONSE;
		[_socket asyncReadIntoBuffer: _buffer
				 exactLength: 4
				 runLoopMode: runLoopMode];
		return 0;
		return nil;
	default:
		assert(0);
		return 0;
		return nil;
	}
}
@end

@implementation OFTCPSocket_ConnectDelegate
- (void)dealloc
{