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

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

Issue 567030: Add specific error codes for when SOCKS connect fails.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: rename ERR_SOCKS_CONNECT_* --> ERR_SOCKS_CONNECTION_* Created 10 years, 10 months 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 | Annotate | Revision Log
« no previous file with comments | « net/socket/socks5_client_socket_unittest.cc ('k') | net/socket/socks_client_socket_unittest.cc » ('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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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" 7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/trace_event.h" 9 #include "base/trace_event.h"
10 #include "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 int SOCKSClientSocket::DoHandshakeReadComplete(int result) { 348 int SOCKSClientSocket::DoHandshakeReadComplete(int result) {
349 DCHECK_NE(kSOCKS4Unresolved, socks_version_); 349 DCHECK_NE(kSOCKS4Unresolved, socks_version_);
350 350
351 if (result < 0) 351 if (result < 0)
352 return result; 352 return result;
353 353
354 // The underlying socket closed unexpectedly. 354 // The underlying socket closed unexpectedly.
355 if (result == 0) 355 if (result == 0)
356 return ERR_CONNECTION_CLOSED; 356 return ERR_CONNECTION_CLOSED;
357 357
358 if (bytes_received_ + result > kReadHeaderSize) 358 if (bytes_received_ + result > kReadHeaderSize) {
359 return ERR_INVALID_RESPONSE; 359 // TODO(eroman): Describe failure in LoadLog.
360 return ERR_SOCKS_CONNECTION_FAILED;
361 }
360 362
361 buffer_.append(handshake_buf_->data(), result); 363 buffer_.append(handshake_buf_->data(), result);
362 bytes_received_ += result; 364 bytes_received_ += result;
363 if (bytes_received_ < kReadHeaderSize) { 365 if (bytes_received_ < kReadHeaderSize) {
364 next_state_ = STATE_HANDSHAKE_READ; 366 next_state_ = STATE_HANDSHAKE_READ;
365 return OK; 367 return OK;
366 } 368 }
367 369
368 const SOCKS4ServerResponse* response = 370 const SOCKS4ServerResponse* response =
369 reinterpret_cast<const SOCKS4ServerResponse*>(buffer_.data()); 371 reinterpret_cast<const SOCKS4ServerResponse*>(buffer_.data());
370 372
371 if (response->reserved_null != 0x00) { 373 if (response->reserved_null != 0x00) {
372 LOG(ERROR) << "Unknown response from SOCKS server."; 374 LOG(ERROR) << "Unknown response from SOCKS server.";
373 return ERR_INVALID_RESPONSE; 375 return ERR_SOCKS_CONNECTION_FAILED;
374 } 376 }
375 377
376 // TODO(arindam): Add SOCKS specific failure codes in net_error_list.h
377 switch (response->code) { 378 switch (response->code) {
378 case kServerResponseOk: 379 case kServerResponseOk:
379 completed_handshake_ = true; 380 completed_handshake_ = true;
380 return OK; 381 return OK;
381 case kServerResponseRejected: 382 case kServerResponseRejected:
382 LOG(ERROR) << "SOCKS request rejected or failed"; 383 LOG(ERROR) << "SOCKS request rejected or failed";
383 return ERR_FAILED; 384 return ERR_SOCKS_CONNECTION_FAILED;
384 case kServerResponseNotReachable: 385 case kServerResponseNotReachable:
385 LOG(ERROR) << "SOCKS request failed because client is not running " 386 LOG(ERROR) << "SOCKS request failed because client is not running "
386 << "identd (or not reachable from the server)"; 387 << "identd (or not reachable from the server)";
387 return ERR_NAME_NOT_RESOLVED; 388 return ERR_SOCKS_CONNECTION_HOST_UNREACHABLE;
388 case kServerResponseMismatchedUserId: 389 case kServerResponseMismatchedUserId:
389 LOG(ERROR) << "SOCKS request failed because client's identd could " 390 LOG(ERROR) << "SOCKS request failed because client's identd could "
390 << "not confirm the user ID string in the request"; 391 << "not confirm the user ID string in the request";
391 return ERR_FAILED; 392 return ERR_SOCKS_CONNECTION_FAILED;
392 default: 393 default:
393 LOG(ERROR) << "SOCKS server sent unknown response"; 394 LOG(ERROR) << "SOCKS server sent unknown response";
394 return ERR_INVALID_RESPONSE; 395 return ERR_SOCKS_CONNECTION_FAILED;
395 } 396 }
396 397
397 // Note: we ignore the last 6 bytes as specified by the SOCKS protocol 398 // Note: we ignore the last 6 bytes as specified by the SOCKS protocol
398 } 399 }
399 400
400 int SOCKSClientSocket::GetPeerName(struct sockaddr* name, 401 int SOCKSClientSocket::GetPeerName(struct sockaddr* name,
401 socklen_t* namelen) { 402 socklen_t* namelen) {
402 return transport_->GetPeerName(name, namelen); 403 return transport_->GetPeerName(name, namelen);
403 } 404 }
404 405
405 } // namespace net 406 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/socks5_client_socket_unittest.cc ('k') | net/socket/socks_client_socket_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698