5
5
* | (__| |_| | _ <| |___
6
6
* \___|\___/|_| \_\_____|
8
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
8
* Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
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
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"
108
static int is_fatal_error(int 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:
122
/* no error or not critical */
105
126
int operate(struct Configurable *config, int argc, argv_item_t argv[])
107
128
char errorbuffer[CURL_ERROR_SIZE];
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();");
357
#ifndef CURL_DISABLE_LIBCURL_OPTION
358
res = easysrc_init();
339
360
helpf(config->errors, "out of memory\n");
340
res = CURLE_OUT_OF_MEMORY;
344
365
if(config->list_engines) {
345
366
struct curl_slist *engines = NULL;
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++) {
427
448
char *uploadfile; /* a single file, never a glob */
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);
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);
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);
835
856
/* new in libcurl 7.19.4 */
836
857
my_setopt(curl, CURLOPT_NOPROXY, config->noproxy);
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);
887
908
/* new in libcurl 7.5 */
888
909
my_setopt(curl, CURLOPT_MAXREDIRS, config->maxredirs);
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);
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);
898
919
/* curl 7.19.1 (the 301 version existed in 7.18.2) */
899
920
my_setopt(curl, CURLOPT_POSTREDIR, config->post301 |
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);
995
1016
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
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);
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);
1036
1057
/* new in libcurl 7.7: */
1037
1058
my_setopt_str(curl, CURLOPT_RANDOM_FILE, config->random_file);
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);
1100
1121
#if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
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");
1177
my_setopt(curl, CURLOPT_TCP_KEEPIDLE, config->alivetime);
1178
my_setopt(curl, CURLOPT_TCP_KEEPINTVL, config->alivetime);
1182
my_setopt(curl, CURLOPT_TCP_KEEPALIVE, 0L);
1154
1184
/* curl 7.20.0 */
1155
1185
if(config->tftp_blksize)
1159
1189
my_setopt_str(curl, CURLOPT_MAIL_FROM, config->mail_from);
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);
1164
1194
/* curl 7.20.x */
1165
1195
if(config->ftp_pret)
1166
1196
my_setopt(curl, CURLOPT_FTP_USE_PRET, TRUE);
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);
1173
1203
if((urlnode->flags & GETOUT_USEREMOTE)
1174
1204
&& config->content_disposition) {
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);
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);
1238
if(config->ssl_allow_beast)
1239
my_setopt(curl, CURLOPT_SSL_OPTIONS, (long)CURLSSLOPT_ALLOW_BEAST);
1241
if(config->mail_auth)
1242
my_setopt_str(curl, CURLOPT_MAIL_AUTH, config->mail_auth);
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();
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();
1217
1255
goto show_error;
1221
1260
res = curl_easy_perform(curl);
1463
1502
infd = STDIN_FILENO;
1466
/* upon error exit loop */
1506
/* when url globbing, exit loop upon critical error */
1507
if(is_fatal_error(res))
1511
/* when not url globbing, exit loop upon any error */
1470
1514
} /* loop to the next URL */
1482
/* upon error exit loop */
1527
/* when file globbing, exit loop upon critical error */
1528
if(is_fatal_error(res))
1532
/* when not file globbing, exit loop upon any error */
1486
1535
} /* loop to the next globbed upload file */
1502
1551
Curl_safefree(urlnode->infile);
1503
1552
urlnode->flags = 0;
1505
/* TODO: Should CURLE_SSL_CACERT be included as critical error ? */
1508
1555
** Bail out upon critical errors
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;
1517
/* Merrily loop to next URL */
1521
1560
} /* for-loop through all URLs */
1538
1577
curl_easy_cleanup(curl);
1539
1578
config->easy = curl = NULL;
1542
curl_slist_append(easysrc, "curl_easy_cleanup(hnd);");
1580
#ifndef CURL_DISABLE_LIBCURL_OPTION
1544
1584
/* Close function-local opened file descriptors */
1551
1591
if(config->trace_fopened && config->trace_stream)
1552
1592
fclose(config->trace_stream);
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);
1559
1601
if(config->errors_fopened && config->errors)
1560
1602
fclose(config->errors);