ObjFW  Diff

Differences From Artifact [a4bbcb1257]:

To Artifact [777126a470]:


1
2
3
4

5
6
7
8
9
10
11
1



2
3
4
5
6
7
8
9

-
-
-
+







/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018, 2019, 2020
 *   Jonathan Schleifer <js@nil.im>
 * Copyright (c) 2008-2021 Jonathan Schleifer <js@nil.im>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
 * the packaging of this file.
 *
80
81
82
83
84
85
86
87

88
89
90
91
92
93
94
78
79
80
81
82
83
84

85
86
87
88
89
90
91
92







-
+







#ifdef OF_HAVE_BLOCKS
	if (_block != NULL)
		_block(_exception);
	else {
#endif
		if ([_delegate respondsToSelector:
		    @selector(socket:didConnectToHost:port:exception:)])
			[_delegate    socket: _socket
			[_delegate socket: _socket
			    didConnectToHost: _host
					port: _port
				   exception: _exception];
#ifdef OF_HAVE_BLOCKS
	}
#endif
}
102
103
104
105
106
107
108
109

110
111
112
113
114
115
116
117
100
101
102
103
104
105
106

107

108
109
110
111
112
113
114







-
+
-








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

	data = [OFData dataWithItems: "\x05\x01\x00"
	data = [OFData dataWithItems: "\x05\x01\x00" count: 3];
			       count: 3];

	_SOCKS5State = OF_SOCKS5_STATE_SEND_AUTHENTICATION;
	[_socket asyncWriteData: data
		    runLoopMode: [OFRunLoop currentRunLoop].currentMode];
}

-      (bool)stream: (OFStream *)sock
146
147
148
149
150
151
152
153

154
155
156
157
158

159
160
161
162
163

164
165
166
167

168
169
170
171
172
173
174
175
143
144
145
146
147
148
149

150

151
152
153

154

155
156
157

158

159
160

161

162
163
164
165
166
167
168







-
+
-



-
+
-



-
+
-


-
+
-







			[self didConnect];
			return false;
		}

		[_request release];
		_request = [[OFMutableData alloc] init];

		[_request addItems: "\x05\x01\x00\x03"
		[_request addItems: "\x05\x01\x00\x03" count: 4];
			     count: 4];

		hostLength = (uint8_t)_host.UTF8StringLength;
		[_request addItem: &hostLength];
		[_request addItems: _host.UTF8String
		[_request addItems: _host.UTF8String count: hostLength];
			     count: hostLength];

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

		_SOCKS5State = OF_SOCKS5_STATE_SEND_REQUEST;
		[_socket asyncWriteData: _request
		[_socket asyncWriteData: _request runLoopMode: runLoopMode];
			    runLoopMode: runLoopMode];
		return false;
	case OF_SOCKS5_STATE_READ_RESPONSE:
		response = buffer;

		if (response[0] != 5 || response[2] != 0) {
			_exception = [[OFConnectionFailedException alloc]
			    initWithHost: _host