~ubuntu-branches/ubuntu/precise/curl/precise-proposed

« back to all changes in this revision

Viewing changes to lib/socks.c

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2011-11-25 17:30:45 UTC
  • mfrom: (3.4.23 sid)
  • Revision ID: package-import@ubuntu.com-20111125173045-2l3ni88jv16kath0
Tags: 7.22.0-3ubuntu1
* Merge from Debian unstable, remaining changes:
  - Drop dependencies not in main:
    + Build-Depends: Drop stunnel4 and libssh2-1-dev.
    + Drop libssh2-1-dev from libcurl4-openssl-dev's Depends.
  - Add new libcurl3-udeb package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include "setup.h"
24
24
 
25
25
#if !defined(CURL_DISABLE_PROXY) || defined(USE_WINDOWS_SSPI)
26
 
#include <string.h>
27
26
 
28
 
#ifdef HAVE_STDLIB_H
29
 
#include <stdlib.h>
30
 
#endif
31
27
#ifdef HAVE_SYS_SOCKET_H
32
28
#include <sys/socket.h>
33
29
#endif
60
56
                       curl_socket_t sockfd,     /* read from this socket */
61
57
                       char *buf,                /* store read data here */
62
58
                       ssize_t buffersize,       /* max amount to read */
63
 
                       ssize_t *n,               /* amount bytes read */
64
 
                       long conn_timeout)        /* timeout for data wait
65
 
                                                    relative to
66
 
                                                    conn->created */
 
59
                       ssize_t *n)               /* amount bytes read */
67
60
{
68
61
  ssize_t nread;
69
62
  ssize_t allread = 0;
70
63
  int result;
71
 
  struct timeval tvnow;
72
 
  long conntime;
 
64
  long timeleft;
73
65
  *n = 0;
74
66
  for(;;) {
75
 
    tvnow = Curl_tvnow();
76
 
    /* calculating how long connection is establishing */
77
 
    conntime = Curl_tvdiff(tvnow, conn->created);
78
 
    if(conntime > conn_timeout) {
 
67
    timeleft = Curl_timeleft(conn->data, NULL, TRUE);
 
68
    if(timeleft < 0) {
79
69
      /* we already got the timeout */
80
70
      result = CURLE_OPERATION_TIMEDOUT;
81
71
      break;
82
72
    }
83
 
    if(Curl_socket_ready(sockfd, CURL_SOCKET_BAD,
84
 
                         conn_timeout - conntime) <= 0) {
 
73
    if(Curl_socket_ready(sockfd, CURL_SOCKET_BAD, timeleft) <= 0) {
85
74
      result = ~CURLE_OK;
86
75
      break;
87
76
    }
133
122
  int result;
134
123
  CURLcode code;
135
124
  curl_socket_t sock = conn->sock[sockindex];
136
 
  long timeout;
137
125
  struct SessionHandle *data = conn->data;
138
126
 
139
 
  /* get timeout */
140
 
  timeout = Curl_timeleft(data, NULL, TRUE);
141
 
 
142
 
  if(timeout < 0) {
 
127
  if(Curl_timeleft(data, NULL, TRUE) < 0) {
143
128
    /* time-out, bail out, go home */
144
129
    failf(data, "Connection time-out");
145
130
    return CURLE_OPERATION_TIMEDOUT;
264
249
 
265
250
    /* Receive response */
266
251
    result = Curl_blockread_all(conn, sock, (char *)socksreq, packetsize,
267
 
                           &actualread, timeout);
 
252
                                &actualread);
268
253
    if((result != CURLE_OK) || (actualread != packetsize)) {
269
254
      failf(data, "Failed to receive SOCKS4 connect request ack.");
270
255
      return CURLE_COULDNT_CONNECT;
299
284
    /* Result */
300
285
    switch(socksreq[1]) {
301
286
    case 90:
302
 
      if(protocol4a)
303
 
        infof(data, "SOCKS4a request granted.\n");
304
 
      else
305
 
        infof(data, "SOCKS4 request granted.\n");
 
287
      infof(data, "SOCKS4%s request granted.\n", protocol4a?"a":"");
306
288
      break;
307
289
    case 91:
308
290
      failf(data,
386
368
  curl_socket_t sock = conn->sock[sockindex];
387
369
  struct SessionHandle *data = conn->data;
388
370
  long timeout;
389
 
  bool socks5_resolve_local = (bool)(conn->proxytype == CURLPROXY_SOCKS5);
 
371
  bool socks5_resolve_local = (conn->proxytype == CURLPROXY_SOCKS5)?TRUE:FALSE;
390
372
  const size_t hostname_len = strlen(hostname);
391
373
  ssize_t packetsize = 0;
392
374
 
466
448
 
467
449
  curlx_nonblock(sock, FALSE);
468
450
 
469
 
  result=Curl_blockread_all(conn, sock, (char *)socksreq, 2, &actualread,
470
 
                            timeout);
 
451
  result=Curl_blockread_all(conn, sock, (char *)socksreq, 2, &actualread);
471
452
  if((result != CURLE_OK) || (actualread != 2)) {
472
453
    failf(data, "Unable to receive initial SOCKS5 response.");
473
454
    return CURLE_COULDNT_CONNECT;
527
508
      return CURLE_COULDNT_CONNECT;
528
509
    }
529
510
 
530
 
    result=Curl_blockread_all(conn, sock, (char *)socksreq, 2, &actualread,
531
 
                         timeout);
 
511
    result=Curl_blockread_all(conn, sock, (char *)socksreq, 2, &actualread);
532
512
    if((result != CURLE_OK) || (actualread != 2)) {
533
513
      failf(data, "Unable to receive SOCKS5 sub-negotiation response.");
534
514
      return CURLE_COULDNT_CONNECT;
664
644
  else
665
645
#endif
666
646
    result = Curl_blockread_all(conn, sock, (char *)socksreq, packetsize,
667
 
                           &actualread, timeout);
 
647
                                &actualread);
668
648
  if((result != CURLE_OK) || (actualread != packetsize)) {
669
649
    failf(data, "Failed to receive SOCKS5 connect request ack.");
670
650
    return CURLE_COULDNT_CONNECT;
720
700
    if(packetsize > 10) {
721
701
      packetsize -= 10;
722
702
      result = Curl_blockread_all(conn, sock, (char *)&socksreq[10],
723
 
                                  packetsize, &actualread, timeout);
 
703
                                  packetsize, &actualread);
724
704
      if((result != CURLE_OK) || (actualread != packetsize)) {
725
705
        failf(data, "Failed to receive SOCKS5 connect request ack.");
726
706
        return CURLE_COULDNT_CONNECT;