Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: net/socket/socks_client_socket.cc

Issue 1535363003: Switch to standard integer types in net/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: stddef Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/socket/socks_client_socket.h ('k') | net/socket/socks_client_socket_pool.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/socket/socks_client_socket.h" 5 #include "net/socket/socks_client_socket.h"
6 6
7 #include "base/basictypes.h"
8 #include "base/bind.h" 7 #include "base/bind.h"
9 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
10 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
11 #include "base/sys_byteorder.h" 10 #include "base/sys_byteorder.h"
12 #include "net/base/io_buffer.h" 11 #include "net/base/io_buffer.h"
13 #include "net/base/net_util.h" 12 #include "net/base/net_util.h"
14 #include "net/log/net_log.h" 13 #include "net/log/net_log.h"
15 #include "net/socket/client_socket_handle.h" 14 #include "net/socket/client_socket_handle.h"
16 15
17 namespace net { 16 namespace net {
18 17
19 // Every SOCKS server requests a user-id from the client. It is optional 18 // Every SOCKS server requests a user-id from the client. It is optional
20 // and we send an empty string. 19 // and we send an empty string.
21 static const char kEmptyUserId[] = ""; 20 static const char kEmptyUserId[] = "";
22 21
23 // For SOCKS4, the client sends 8 bytes plus the size of the user-id. 22 // For SOCKS4, the client sends 8 bytes plus the size of the user-id.
24 static const unsigned int kWriteHeaderSize = 8; 23 static const unsigned int kWriteHeaderSize = 8;
25 24
26 // For SOCKS4 the server sends 8 bytes for acknowledgement. 25 // For SOCKS4 the server sends 8 bytes for acknowledgement.
27 static const unsigned int kReadHeaderSize = 8; 26 static const unsigned int kReadHeaderSize = 8;
28 27
29 // Server Response codes for SOCKS. 28 // Server Response codes for SOCKS.
30 static const uint8 kServerResponseOk = 0x5A; 29 static const uint8_t kServerResponseOk = 0x5A;
31 static const uint8 kServerResponseRejected = 0x5B; 30 static const uint8_t kServerResponseRejected = 0x5B;
32 static const uint8 kServerResponseNotReachable = 0x5C; 31 static const uint8_t kServerResponseNotReachable = 0x5C;
33 static const uint8 kServerResponseMismatchedUserId = 0x5D; 32 static const uint8_t kServerResponseMismatchedUserId = 0x5D;
34 33
35 static const uint8 kSOCKSVersion4 = 0x04; 34 static const uint8_t kSOCKSVersion4 = 0x04;
36 static const uint8 kSOCKSStreamRequest = 0x01; 35 static const uint8_t kSOCKSStreamRequest = 0x01;
37 36
38 // A struct holding the essential details of the SOCKS4 Server Request. 37 // A struct holding the essential details of the SOCKS4 Server Request.
39 // The port in the header is stored in network byte order. 38 // The port in the header is stored in network byte order.
40 struct SOCKS4ServerRequest { 39 struct SOCKS4ServerRequest {
41 uint8 version; 40 uint8_t version;
42 uint8 command; 41 uint8_t command;
43 uint16 nw_port; 42 uint16_t nw_port;
44 uint8 ip[4]; 43 uint8_t ip[4];
45 }; 44 };
46 static_assert(sizeof(SOCKS4ServerRequest) == kWriteHeaderSize, 45 static_assert(sizeof(SOCKS4ServerRequest) == kWriteHeaderSize,
47 "socks4 server request struct has incorrect size"); 46 "socks4 server request struct has incorrect size");
48 47
49 // A struct holding details of the SOCKS4 Server Response. 48 // A struct holding details of the SOCKS4 Server Response.
50 struct SOCKS4ServerResponse { 49 struct SOCKS4ServerResponse {
51 uint8 reserved_null; 50 uint8_t reserved_null;
52 uint8 code; 51 uint8_t code;
53 uint16 port; 52 uint16_t port;
54 uint8 ip[4]; 53 uint8_t ip[4];
55 }; 54 };
56 static_assert(sizeof(SOCKS4ServerResponse) == kReadHeaderSize, 55 static_assert(sizeof(SOCKS4ServerResponse) == kReadHeaderSize,
57 "socks4 server response struct has incorrect size"); 56 "socks4 server response struct has incorrect size");
58 57
59 SOCKSClientSocket::SOCKSClientSocket( 58 SOCKSClientSocket::SOCKSClientSocket(
60 scoped_ptr<ClientSocketHandle> transport_socket, 59 scoped_ptr<ClientSocketHandle> transport_socket,
61 const HostResolver::RequestInfo& req_info, 60 const HostResolver::RequestInfo& req_info,
62 RequestPriority priority, 61 RequestPriority priority,
63 HostResolver* host_resolver) 62 HostResolver* host_resolver)
64 : transport_(transport_socket.Pass()), 63 : transport_(transport_socket.Pass()),
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 210
212 int rv = transport_->socket()->Write( 211 int rv = transport_->socket()->Write(
213 buf, buf_len, 212 buf, buf_len,
214 base::Bind(&SOCKSClientSocket::OnReadWriteComplete, 213 base::Bind(&SOCKSClientSocket::OnReadWriteComplete,
215 base::Unretained(this), callback)); 214 base::Unretained(this), callback));
216 if (rv > 0) 215 if (rv > 0)
217 was_ever_used_ = true; 216 was_ever_used_ = true;
218 return rv; 217 return rv;
219 } 218 }
220 219
221 int SOCKSClientSocket::SetReceiveBufferSize(int32 size) { 220 int SOCKSClientSocket::SetReceiveBufferSize(int32_t size) {
222 return transport_->socket()->SetReceiveBufferSize(size); 221 return transport_->socket()->SetReceiveBufferSize(size);
223 } 222 }
224 223
225 int SOCKSClientSocket::SetSendBufferSize(int32 size) { 224 int SOCKSClientSocket::SetSendBufferSize(int32_t size) {
226 return transport_->socket()->SetSendBufferSize(size); 225 return transport_->socket()->SetSendBufferSize(size);
227 } 226 }
228 227
229 void SOCKSClientSocket::DoCallback(int result) { 228 void SOCKSClientSocket::DoCallback(int result) {
230 DCHECK_NE(ERR_IO_PENDING, result); 229 DCHECK_NE(ERR_IO_PENDING, result);
231 DCHECK(!user_callback_.is_null()); 230 DCHECK(!user_callback_.is_null());
232 231
233 // Since Run() may result in Read being called, 232 // Since Run() may result in Read being called,
234 // clear user_callback_ up front. 233 // clear user_callback_ up front.
235 DVLOG(1) << "Finished setting up SOCKS handshake"; 234 DVLOG(1) << "Finished setting up SOCKS handshake";
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 452
454 int SOCKSClientSocket::GetPeerAddress(IPEndPoint* address) const { 453 int SOCKSClientSocket::GetPeerAddress(IPEndPoint* address) const {
455 return transport_->socket()->GetPeerAddress(address); 454 return transport_->socket()->GetPeerAddress(address);
456 } 455 }
457 456
458 int SOCKSClientSocket::GetLocalAddress(IPEndPoint* address) const { 457 int SOCKSClientSocket::GetLocalAddress(IPEndPoint* address) const {
459 return transport_->socket()->GetLocalAddress(address); 458 return transport_->socket()->GetLocalAddress(address);
460 } 459 }
461 460
462 } // namespace net 461 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/socks_client_socket.h ('k') | net/socket/socks_client_socket_pool.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698