~ubuntu-branches/ubuntu/saucy/curl/saucy-201307251546

« back to all changes in this revision

Viewing changes to src/tool_operate.c

  • Committer: Package Import Robot
  • Author(s): Alessandro Ghedini
  • Date: 2012-03-23 16:24:51 UTC
  • mto: (3.6.1 experimental) (1.3.1)
  • mto: This revision was merged to the branch mainline in revision 59.
  • Revision ID: package-import@ubuntu.com-20120323162451-z4gstlabjkgnrh7h
Tags: upstream-7.25.0
ImportĀ upstreamĀ versionĀ 7.25.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *                            | (__| |_| |  _ <| |___
6
6
 *                             \___|\___/|_| \_\_____|
7
7
 *
8
 
 * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
 
8
 * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
9
9
 *
10
10
 * This software is licensed as described in the file COPYING, which
11
11
 * you should have received as part of this distribution. The terms
41
41
#  include <locale.h>
42
42
#endif
43
43
 
 
44
#ifdef HAVE_NETINET_TCP_H
 
45
#  include <netinet/tcp.h>
 
46
#endif
 
47
 
44
48
#include "rawstr.h"
45
49
 
46
50
#define ENABLE_CURLX_PRINTF
54
58
#include "tool_cb_prg.h"
55
59
#include "tool_cb_rea.h"
56
60
#include "tool_cb_see.h"
57
 
#include "tool_cb_skt.h"
58
61
#include "tool_cb_wrt.h"
59
62
#include "tool_dirhie.h"
60
63
#include "tool_doswin.h"
102
105
  "If you'd like to turn off curl's verification of the certificate, use\n" \
103
106
  " the -k (or --insecure) option.\n"
104
107
 
 
108
static int is_fatal_error(int code)
 
109
{
 
110
  switch(code) {
 
111
  /* TODO: Should CURLE_SSL_CACERT be included as critical error ? */
 
112
  case CURLE_FAILED_INIT:
 
113
  case CURLE_OUT_OF_MEMORY:
 
114
  case CURLE_UNKNOWN_OPTION:
 
115
  case CURLE_FUNCTION_NOT_FOUND:
 
116
  case CURLE_BAD_FUNCTION_ARGUMENT:
 
117
    /* critical error */
 
118
    return 1;
 
119
  default:
 
120
    break;
 
121
  }
 
122
  /* no error or not critical */
 
123
  return 0;
 
124
}
 
125
 
105
126
int operate(struct Configurable *config, int argc, argv_item_t argv[])
106
127
{
107
128
  char errorbuffer[CURL_ERROR_SIZE];
333
354
    }
334
355
  }
335
356
 
336
 
  /* This is the first entry added to easysrc and it initializes the slist */
337
 
  easysrc = curl_slist_append(easysrc, "CURL *hnd = curl_easy_init();");
338
 
  if(!easysrc) {
 
357
#ifndef CURL_DISABLE_LIBCURL_OPTION
 
358
  res = easysrc_init();
 
359
  if(res) {
339
360
    helpf(config->errors, "out of memory\n");
340
 
    res = CURLE_OUT_OF_MEMORY;
341
361
    goto quit_curl;
342
362
  }
 
363
#endif
343
364
 
344
365
  if(config->list_engines) {
345
366
    struct curl_slist *engines = NULL;
384
405
    URLGlob *inglob;
385
406
 
386
407
    outfiles = NULL;
387
 
    infilenum = 0;
 
408
    infilenum = 1;
388
409
    inglob = NULL;
389
410
 
390
411
    /* urlnode->url is the full URL (it might be NULL) */
422
443
 
423
444
    /* Here's the loop for uploading multiple files within the same
424
445
       single globbed string. If no upload, we enter the loop once anyway. */
425
 
    for(up = 0 ;; up++) {
 
446
    for(up = 0 ; up < infilenum; up++) {
426
447
 
427
448
      char *uploadfile; /* a single file, never a glob */
428
449
      int separator;
472
493
      separator= ((!outfiles || curlx_strequal(outfiles, "-")) && urlnum > 1);
473
494
 
474
495
      /* Here's looping around each globbed URL */
475
 
      for(i = 0 ;; i++) {
 
496
      for(i = 0 ; i < urlnum; i++) {
476
497
 
477
498
        int infd;
478
499
        bool infdopen;
812
833
 
813
834
          /* new in libcurl 7.5 */
814
835
          if(config->proxy)
815
 
            my_setopt(curl, CURLOPT_PROXYTYPE, config->proxyver);
 
836
            my_setopt_enum(curl, CURLOPT_PROXYTYPE, config->proxyver);
816
837
 
817
838
          /* new in libcurl 7.10 */
818
839
          if(config->socksproxy) {
819
840
            my_setopt_str(curl, CURLOPT_PROXY, config->socksproxy);
820
 
            my_setopt(curl, CURLOPT_PROXYTYPE, config->socksver);
 
841
            my_setopt_enum(curl, CURLOPT_PROXYTYPE, config->socksver);
821
842
          }
822
843
 
823
844
          /* new in libcurl 7.10.6 */
824
845
          if(config->proxyanyauth)
825
 
            my_setopt(curl, CURLOPT_PROXYAUTH, CURLAUTH_ANY);
 
846
            my_setopt_flags(curl, CURLOPT_PROXYAUTH, CURLAUTH_ANY);
826
847
          else if(config->proxynegotiate)
827
 
            my_setopt(curl, CURLOPT_PROXYAUTH, CURLAUTH_GSSNEGOTIATE);
 
848
            my_setopt_flags(curl, CURLOPT_PROXYAUTH, CURLAUTH_GSSNEGOTIATE);
828
849
          else if(config->proxyntlm)
829
 
            my_setopt(curl, CURLOPT_PROXYAUTH, CURLAUTH_NTLM);
 
850
            my_setopt_flags(curl, CURLOPT_PROXYAUTH, CURLAUTH_NTLM);
830
851
          else if(config->proxydigest)
831
 
            my_setopt(curl, CURLOPT_PROXYAUTH, CURLAUTH_DIGEST);
 
852
            my_setopt_flags(curl, CURLOPT_PROXYAUTH, CURLAUTH_DIGEST);
832
853
          else if(config->proxybasic)
833
 
            my_setopt(curl, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
 
854
            my_setopt_flags(curl, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
834
855
 
835
856
          /* new in libcurl 7.19.4 */
836
857
          my_setopt(curl, CURLOPT_NOPROXY, config->noproxy);
873
894
                      config->postfieldsize);
874
895
            break;
875
896
          case HTTPREQ_POST:
876
 
            my_setopt(curl, CURLOPT_HTTPPOST, config->httppost);
 
897
            my_setopt_httppost(curl, CURLOPT_HTTPPOST, config->httppost);
877
898
            break;
878
899
          default:
879
900
            break;
882
903
          my_setopt_str(curl, CURLOPT_REFERER, config->referer);
883
904
          my_setopt(curl, CURLOPT_AUTOREFERER, config->autoreferer);
884
905
          my_setopt_str(curl, CURLOPT_USERAGENT, config->useragent);
885
 
          my_setopt(curl, CURLOPT_HTTPHEADER, config->headers);
 
906
          my_setopt_slist(curl, CURLOPT_HTTPHEADER, config->headers);
886
907
 
887
908
          /* new in libcurl 7.5 */
888
909
          my_setopt(curl, CURLOPT_MAXREDIRS, config->maxredirs);
889
910
 
890
911
          /* new in libcurl 7.9.1 */
891
912
          if(config->httpversion)
892
 
            my_setopt(curl, CURLOPT_HTTP_VERSION, config->httpversion);
 
913
            my_setopt_enum(curl, CURLOPT_HTTP_VERSION, config->httpversion);
893
914
 
894
915
          /* new in libcurl 7.10.6 (default is Basic) */
895
916
          if(config->authtype)
896
 
            my_setopt(curl, CURLOPT_HTTPAUTH, config->authtype);
 
917
            my_setopt_flags(curl, CURLOPT_HTTPAUTH, config->authtype);
897
918
 
898
919
          /* curl 7.19.1 (the 301 version existed in 7.18.2) */
899
920
          my_setopt(curl, CURLOPT_POSTREDIR, config->post301 |
988
1009
        }
989
1010
 
990
1011
        my_setopt(curl, CURLOPT_CRLF, config->crlf);
991
 
        my_setopt(curl, CURLOPT_QUOTE, config->quote);
992
 
        my_setopt(curl, CURLOPT_POSTQUOTE, config->postquote);
993
 
        my_setopt(curl, CURLOPT_PREQUOTE, config->prequote);
 
1012
        my_setopt_slist(curl, CURLOPT_QUOTE, config->quote);
 
1013
        my_setopt_slist(curl, CURLOPT_POSTQUOTE, config->postquote);
 
1014
        my_setopt_slist(curl, CURLOPT_PREQUOTE, config->prequote);
994
1015
 
995
1016
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
996
1017
        {
1011
1032
        }
1012
1033
#endif
1013
1034
 
1014
 
        my_setopt(curl, CURLOPT_SSLVERSION, config->ssl_version);
1015
 
        my_setopt(curl, CURLOPT_TIMECONDITION, config->timecond);
 
1035
        my_setopt_enum(curl, CURLOPT_SSLVERSION, config->ssl_version);
 
1036
        my_setopt_enum(curl, CURLOPT_TIMECONDITION, config->timecond);
1016
1037
        my_setopt(curl, CURLOPT_TIMEVALUE, config->condtime);
1017
1038
        my_setopt_str(curl, CURLOPT_CUSTOMREQUEST, config->customrequest);
1018
1039
        my_setopt(curl, CURLOPT_STDERR, config->errors);
1031
1052
        }
1032
1053
 
1033
1054
        /* new in libcurl 7.6.2: */
1034
 
        my_setopt(curl, CURLOPT_TELNETOPTIONS, config->telnet_options);
 
1055
        my_setopt_slist(curl, CURLOPT_TELNETOPTIONS, config->telnet_options);
1035
1056
 
1036
1057
        /* new in libcurl 7.7: */
1037
1058
        my_setopt_str(curl, CURLOPT_RANDOM_FILE, config->random_file);
1095
1116
 
1096
1117
        /* new in curl 7.16.1 */
1097
1118
        if(config->ftp_ssl_ccc)
1098
 
          my_setopt(curl, CURLOPT_FTP_SSL_CCC, config->ftp_ssl_ccc_mode);
 
1119
          my_setopt_enum(curl, CURLOPT_FTP_SSL_CCC, config->ftp_ssl_ccc_mode);
1099
1120
 
1100
1121
#if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
1101
1122
        {
1147
1168
 
1148
1169
        /* curl 7.17.1 */
1149
1170
        if(!config->nokeepalive) {
1150
 
          my_setopt(curl, CURLOPT_SOCKOPTFUNCTION, tool_sockopt_cb);
1151
 
          my_setopt(curl, CURLOPT_SOCKOPTDATA, config);
 
1171
          my_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L);
 
1172
          if(config->alivetime != 0) {
 
1173
#if !defined(TCP_KEEPIDLE) || !defined(TCP_KEEPINTVL)
 
1174
            warnf(config, "Keep-alive functionality somewhat crippled due to "
 
1175
                "missing support in your operating system!\n");
 
1176
#endif
 
1177
            my_setopt(curl, CURLOPT_TCP_KEEPIDLE, config->alivetime);
 
1178
            my_setopt(curl, CURLOPT_TCP_KEEPINTVL, config->alivetime);
 
1179
          }
1152
1180
        }
 
1181
        else
 
1182
          my_setopt(curl, CURLOPT_TCP_KEEPALIVE, 0L);
1153
1183
 
1154
1184
        /* curl 7.20.0 */
1155
1185
        if(config->tftp_blksize)
1159
1189
          my_setopt_str(curl, CURLOPT_MAIL_FROM, config->mail_from);
1160
1190
 
1161
1191
        if(config->mail_rcpt)
1162
 
          my_setopt(curl, CURLOPT_MAIL_RCPT, config->mail_rcpt);
 
1192
          my_setopt_slist(curl, CURLOPT_MAIL_RCPT, config->mail_rcpt);
1163
1193
 
1164
1194
        /* curl 7.20.x */
1165
1195
        if(config->ftp_pret)
1166
1196
          my_setopt(curl, CURLOPT_FTP_USE_PRET, TRUE);
1167
1197
 
1168
1198
        if(config->proto_present)
1169
 
          my_setopt(curl, CURLOPT_PROTOCOLS, config->proto);
 
1199
          my_setopt_flags(curl, CURLOPT_PROTOCOLS, config->proto);
1170
1200
        if(config->proto_redir_present)
1171
 
          my_setopt(curl, CURLOPT_REDIR_PROTOCOLS, config->proto_redir);
 
1201
          my_setopt_flags(curl, CURLOPT_REDIR_PROTOCOLS, config->proto_redir);
1172
1202
 
1173
1203
        if((urlnode->flags & GETOUT_USEREMOTE)
1174
1204
           && config->content_disposition) {
1184
1214
 
1185
1215
        if(config->resolve)
1186
1216
          /* new in 7.21.3 */
1187
 
          my_setopt(curl, CURLOPT_RESOLVE, config->resolve);
 
1217
          my_setopt_slist(curl, CURLOPT_RESOLVE, config->resolve);
1188
1218
 
1189
1219
        /* new in 7.21.4 */
1190
1220
        if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP) {
1204
1234
          my_setopt_str(curl, CURLOPT_GSSAPI_DELEGATION,
1205
1235
                        config->gssapi_delegation);
1206
1236
 
 
1237
        /* new in 7.25.0 */
 
1238
        if(config->ssl_allow_beast)
 
1239
          my_setopt(curl, CURLOPT_SSL_OPTIONS, (long)CURLSSLOPT_ALLOW_BEAST);
 
1240
 
 
1241
        if(config->mail_auth)
 
1242
          my_setopt_str(curl, CURLOPT_MAIL_AUTH, config->mail_auth);
 
1243
 
1207
1244
        /* initialize retry vars for loop below */
1208
1245
        retry_sleep_default = (config->retry_delay) ?
1209
1246
          config->retry_delay*1000L : RETRY_SLEEP_DEFAULT; /* ms */
1212
1249
        retry_sleep = retry_sleep_default; /* ms */
1213
1250
        retrystart = tvnow();
1214
1251
 
1215
 
        if(!curl_slist_append(easysrc, "ret = curl_easy_perform(hnd);")) {
1216
 
          res = CURLE_OUT_OF_MEMORY;
 
1252
#ifndef CURL_DISABLE_LIBCURL_OPTION
 
1253
        res = easysrc_perform();
 
1254
        if(res) {
1217
1255
          goto show_error;
1218
1256
        }
 
1257
#endif
1219
1258
 
1220
1259
        for(;;) {
1221
1260
          res = curl_easy_perform(curl);
1463
1502
          infd = STDIN_FILENO;
1464
1503
        }
1465
1504
 
1466
 
        /* upon error exit loop */
1467
 
        if(res)
 
1505
        if(urlnum > 1) {
 
1506
          /* when url globbing, exit loop upon critical error */
 
1507
          if(is_fatal_error(res))
 
1508
            break;
 
1509
        }
 
1510
        else if(res)
 
1511
          /* when not url globbing, exit loop upon any error */
1468
1512
          break;
1469
1513
 
1470
1514
      } /* loop to the next URL */
1479
1523
        urls = NULL;
1480
1524
      }
1481
1525
 
1482
 
      /* upon error exit loop */
1483
 
      if(res)
 
1526
      if(infilenum > 1) {
 
1527
        /* when file globbing, exit loop upon critical error */
 
1528
        if(is_fatal_error(res))
 
1529
          break;
 
1530
      }
 
1531
      else if(res)
 
1532
        /* when not file globbing, exit loop upon any error */
1484
1533
        break;
1485
1534
 
1486
1535
    } /* loop to the next globbed upload file */
1502
1551
    Curl_safefree(urlnode->infile);
1503
1552
    urlnode->flags = 0;
1504
1553
 
1505
 
    /* TODO: Should CURLE_SSL_CACERT be included as critical error ? */
1506
 
 
1507
1554
    /*
1508
1555
    ** Bail out upon critical errors
1509
1556
    */
1510
 
    switch(res) {
1511
 
    case CURLE_FAILED_INIT:
1512
 
    case CURLE_OUT_OF_MEMORY:
1513
 
    case CURLE_FUNCTION_NOT_FOUND:
1514
 
    case CURLE_BAD_FUNCTION_ARGUMENT:
 
1557
    if(is_fatal_error(res))
1515
1558
      goto quit_curl;
1516
 
    default:
1517
 
      /* Merrily loop to next URL */
1518
 
      break;
1519
 
    }
1520
1559
 
1521
1560
  } /* for-loop through all URLs */
1522
1561
 
1538
1577
    curl_easy_cleanup(curl);
1539
1578
    config->easy = curl = NULL;
1540
1579
  }
1541
 
  if(easysrc)
1542
 
    curl_slist_append(easysrc, "curl_easy_cleanup(hnd);");
 
1580
#ifndef CURL_DISABLE_LIBCURL_OPTION
 
1581
  easysrc_cleanup();
 
1582
#endif
1543
1583
 
1544
1584
  /* Close function-local opened file descriptors */
1545
1585
 
1551
1591
  if(config->trace_fopened && config->trace_stream)
1552
1592
    fclose(config->trace_stream);
1553
1593
 
 
1594
#ifndef CURL_DISABLE_LIBCURL_OPTION
1554
1595
  /* Dump the libcurl code if previously enabled.
1555
1596
     NOTE: that this function relies on config->errors amongst other things
1556
1597
     so not everything can be closed and cleaned before this is called */
1557
1598
  dumpeasysrc(config);
 
1599
#endif
1558
1600
 
1559
1601
  if(config->errors_fopened && config->errors)
1560
1602
    fclose(config->errors);