~ubuntu-branches/ubuntu/raring/curl/raring-updates

« back to all changes in this revision

Viewing changes to lib/transfer.c

  • Committer: Package Import Robot
  • Author(s): Alessandro Ghedini
  • Date: 2011-11-13 21:07:32 UTC
  • mto: (3.6.1 experimental) (1.3.1)
  • mto: This revision was merged to the branch mainline in revision 55.
  • Revision ID: package-import@ubuntu.com-20111113210732-bk5n25x2tu7aplur
Tags: upstream-7.22.0
ImportĀ upstreamĀ versionĀ 7.22.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
#include "setup.h"
24
24
 
25
 
/* -- WIN32 approved -- */
26
 
#include <stdio.h>
27
 
#include <string.h>
28
 
#include <stdarg.h>
29
 
#include <stdlib.h>
30
 
#include <ctype.h>
31
 
#include <errno.h>
32
 
 
33
25
#include "strtoofft.h"
34
26
#include "strequal.h"
35
27
#include "rawstr.h"
36
28
 
37
 
#ifdef WIN32
38
 
#include <time.h>
39
 
#include <io.h>
40
 
#else
41
29
#ifdef HAVE_SYS_SOCKET_H
42
30
#include <sys/socket.h>
43
31
#endif
44
32
#ifdef HAVE_NETINET_IN_H
45
33
#include <netinet/in.h>
46
34
#endif
47
 
#ifdef HAVE_SYS_TIME_H
48
 
#include <sys/time.h>
49
 
#endif
50
35
#ifdef HAVE_UNISTD_H
51
36
#include <unistd.h>
52
37
#endif
78
63
#error "We can't compile without socket() support!"
79
64
#endif
80
65
 
81
 
#endif  /* WIN32 */
82
 
 
83
66
#include "urldata.h"
84
67
#include <curl/curl.h>
85
68
#include "netrc.h"
95
78
#include "getinfo.h"
96
79
#include "sslgen.h"
97
80
#include "http_digest.h"
98
 
#include "http_ntlm.h"
 
81
#include "curl_ntlm.h"
99
82
#include "http_negotiate.h"
100
83
#include "share.h"
101
84
#include "curl_memory.h"
186
169
    const char *endofline_native;
187
170
    const char *endofline_network;
188
171
    int hexlen;
 
172
 
 
173
    if(
189
174
#ifdef CURL_DO_LINEEND_CONV
190
 
    if((data->set.crlf) || (data->set.prefer_ascii)) {
191
 
#else
192
 
    if(data->set.crlf) {
193
 
#endif /* CURL_DO_LINEEND_CONV */
 
175
       (data->set.prefer_ascii) ||
 
176
#endif
 
177
       (data->set.crlf)) {
194
178
      /* \n will become \r\n later on */
195
179
      endofline_native  = "\n";
196
180
      endofline_network = "\x0a";
302
286
    else {
303
287
      /* If no CURLOPT_READFUNCTION is used, we know that we operate on a
304
288
         given FILE * stream and we can actually attempt to rewind that
305
 
         ourself with fseek() */
 
289
         ourselves with fseek() */
306
290
      if(data->set.fread_func == (curl_read_callback)fread) {
307
291
        if(-1 != fseek(data->set.in, 0, SEEK_SET))
308
292
          /* successful rewind */
446
430
 
447
431
    *didwhat |= KEEP_RECV;
448
432
    /* indicates data of zero size, i.e. empty file */
449
 
    is_empty_data = (bool)((nread == 0) && (k->bodywrites == 0));
 
433
    is_empty_data = ((nread == 0) && (k->bodywrites == 0)) ? TRUE : FALSE;
450
434
 
451
435
    /* NUL terminate, allowing string ops to be used */
452
436
    if(0 < nread || is_empty_data) {
522
506
       is non-headers. */
523
507
    if(k->str && !k->header && (nread > 0 || is_empty_data)) {
524
508
 
525
 
 
526
509
#ifndef CURL_DISABLE_HTTP
527
510
      if(0 == k->bodywrites && !is_empty_data) {
528
511
        /* These checks are only made the first time we are about to
570
553
            }
571
554
          } /* we have a time condition */
572
555
 
573
 
        } /* this is HTTP */
 
556
        } /* this is HTTP or RTSP */
574
557
      } /* this is the first time we write a body part */
575
558
#endif /* CURL_DISABLE_HTTP */
 
559
 
576
560
      k->bodywrites++;
577
561
 
578
562
      /* pass data to the debug function before it gets "dechunked" */
606
590
            failf(data, "Failed writing data");
607
591
            return CURLE_WRITE_ERROR;
608
592
          }
609
 
          failf(data, "Received problem %d in the chunky parser", (int)res);
 
593
          failf(data, "Problem (%d) in the Chunked-Encoded data", (int)res);
610
594
          return CURLE_RECV_ERROR;
611
595
        }
612
596
        else if(CHUNKE_STOP == res) {
816
800
  /*
817
801
   * We loop here to do the READ and SEND loop until we run out of
818
802
   * data to send or until we get EWOULDBLOCK back
 
803
   *
 
804
   * FIXME: above comment is misleading. Currently no looping is
 
805
   * actually done in do-while loop below.
819
806
   */
820
807
  do {
821
808
 
892
879
#endif /* CURL_DISABLE_SMTP */
893
880
 
894
881
      /* convert LF to CRLF if so asked */
895
 
      if((!sending_http_headers) &&
 
882
      if((!sending_http_headers) && (
896
883
#ifdef CURL_DO_LINEEND_CONV
897
 
        /* always convert if we're FTPing in ASCII mode */
898
 
         ((data->set.crlf) || (data->set.prefer_ascii))) {
899
 
#else
900
 
         (data->set.crlf)) {
 
884
         /* always convert if we're FTPing in ASCII mode */
 
885
         (data->set.prefer_ascii) ||
901
886
#endif
 
887
         (data->set.crlf))) {
902
888
        if(data->state.scratch == NULL)
903
889
          data->state.scratch = malloc(2*BUFSIZE);
904
890
        if(data->state.scratch == NULL) {
988
974
 
989
975
    Curl_pgrsSetUploadCounter(data, k->writebytecount);
990
976
 
991
 
  } while(0); /* just to break out from! */
 
977
  } WHILE_FALSE; /* just to break out from! */
992
978
 
993
979
  return CURLE_OK;
994
980
}
1043
1029
    if(result || *done)
1044
1030
      return result;
1045
1031
  }
 
1032
  else if(k->keepon & KEEP_RECV) {
 
1033
    DEBUGF(infof(data, "additional stuff not fine %s:%d: %d %d\n",
 
1034
                 __FILE__, __LINE__,
 
1035
                 select_res & CURL_CSELECT_IN,
 
1036
                 conn->bits.stream_was_rewound));
 
1037
  }
1046
1038
 
1047
1039
  /* If we still have writing to do, we check if we have a writable socket. */
1048
1040
  if((k->keepon & KEEP_SEND) && (select_res & CURL_CSELECT_OUT)) {
1136
1128
            (conn->chunk.state != CHUNK_STOP)) {
1137
1129
      /*
1138
1130
       * In chunked mode, return an error if the connection is closed prior to
1139
 
       * the empty (terminiating) chunk is read.
 
1131
       * the empty (terminating) chunk is read.
1140
1132
       *
1141
1133
       * The condition above used to check for
1142
1134
       * conn->proto.http->chunk.datasize != 0 which is true after reading
1151
1143
  }
1152
1144
 
1153
1145
  /* Now update the "done" boolean we return */
1154
 
  *done = (bool)(0 == (k->keepon&(KEEP_RECV|KEEP_SEND|
1155
 
                                  KEEP_RECV_PAUSE|KEEP_SEND_PAUSE)));
 
1146
  *done = (0 == (k->keepon&(KEEP_RECV|KEEP_SEND|
 
1147
                            KEEP_RECV_PAUSE|KEEP_SEND_PAUSE))) ? TRUE : FALSE;
1156
1148
 
1157
1149
  return CURLE_OK;
1158
1150
}
1213
1205
/*
1214
1206
 * Determine optimum sleep time based on configured rate, current rate,
1215
1207
 * and packet size.
1216
 
 * Returns value in mili-seconds.
 
1208
 * Returns value in milliseconds.
1217
1209
 *
1218
1210
 * The basic idea is to adjust the desired rate up/down in this method
1219
1211
 * based on whether we are running too slow or too fast.  Then, calculate
1220
 
 * how many miliseconds to wait for the next packet to achieve this new
 
1212
 * how many milliseconds to wait for the next packet to achieve this new
1221
1213
 * rate.
1222
1214
 */
1223
1215
long Curl_sleep_time(curl_off_t rate_bps, curl_off_t cur_rate_bps,
1243
1235
    rate_bps += rate_bps >> 6;
1244
1236
  }
1245
1237
 
1246
 
  /* Determine number of miliseconds to wait until we do
 
1238
  /* Determine number of milliseconds to wait until we do
1247
1239
   * the next packet at the adjusted rate.  We should wait
1248
1240
   * longer when using larger packets, for instance.
1249
1241
   */
1448
1440
      if(data->share)
1449
1441
        Curl_share_unlock(data, CURL_LOCK_DATA_DNS);
1450
1442
 
1451
 
      if(!dns)
 
1443
      if(!dns) {
 
1444
        Curl_freeaddrinfo(addr);
1452
1445
        return CURLE_OUT_OF_MEMORY;
 
1446
      }
1453
1447
    }
1454
1448
  }
1455
1449
  data->change.resolve = NULL; /* dealt with now */
1613
1607
  char prot[16]; /* URL protocol string storage */
1614
1608
  char letter;   /* used for a silly sscanf */
1615
1609
 
1616
 
  return (bool)(2 == sscanf(url, "%15[^?&/:]://%c", prot, &letter));
 
1610
  return (2 == sscanf(url, "%15[^?&/:]://%c", prot, &letter)) ? TRUE : FALSE;
1617
1611
}
1618
1612
 
1619
1613
/*
1889
1883
  case 301: /* Moved Permanently */
1890
1884
    /* (quote from RFC2616, section 10.3.2):
1891
1885
     *
1892
 
     * Note: When automatically redirecting a POST request after receiving a
1893
 
     * 301 status code, some existing HTTP/1.0 user agents will erroneously
1894
 
     * change it into a GET request.
 
1886
     * When automatically redirecting a POST request after receiving a 301
 
1887
     * status code, some existing HTTP/1.0 user agents will erroneously change
 
1888
     * it into a GET request.
1895
1889
     *
1896
1890
     * ----
1897
1891
     *
1898
 
     * Warning: Because most of importants user agents do this obvious RFC2616
1899
 
     * violation, many webservers expect this misbehavior. So these servers
1900
 
     * often answers to a POST request with an error page.  To be sure that
1901
 
     * libcurl gets the page that most user agents would get, libcurl has to
1902
 
     * force GET.
 
1892
     * As most of the important user agents do this obvious RFC2616 violation,
 
1893
     * many webservers expect this. So these servers often answers to a POST
 
1894
     * request with an error page.  To be sure that libcurl gets the page that
 
1895
     * most user agents would get, libcurl has to force GET.
1903
1896
     *
1904
 
     * This behaviour can be overridden with CURLOPT_POSTREDIR.
 
1897
     * This behavior can be overridden with CURLOPT_POSTREDIR.
1905
1898
     */
1906
1899
    if((data->set.httpreq == HTTPREQ_POST
1907
1900
        || data->set.httpreq == HTTPREQ_POST_FORM)
1929
1922
    302 status code may be used instead, since most user agents react
1930
1923
    to a 302 response as described here for 303.
1931
1924
 
1932
 
    This behaviour can be overriden with CURLOPT_POSTREDIR
 
1925
    This behavior can be overridden with CURLOPT_POSTREDIR
1933
1926
    */
1934
1927
    if((data->set.httpreq == HTTPREQ_POST
1935
1928
        || data->set.httpreq == HTTPREQ_POST_FORM)
2092
2085
                                transferred! */
2093
2086
 
2094
2087
    if(data->state.proto.http->writebytecount)
2095
 
      Curl_readrewind(conn);
 
2088
      return Curl_readrewind(conn);
2096
2089
  }
2097
2090
  return CURLE_OK;
2098
2091
}