243
243
#define ftruncate(fd,where) ftruncate64(fd,where)
247
TRACE_BIN, /* tcpdump inspired look */
248
TRACE_ASCII, /* like *BIN but without the hex output */
249
TRACE_PLAIN /* -v/--verbose type */
252
struct Configurable {
257
char *cookie; /* single line with specified cookies */
258
char *cookiejar; /* write to this file */
259
char *cookiefile; /* read from this file */
260
bool cookiesession; /* new session? */
261
bool encoding; /* Accept-Encoding please */
262
long authtype; /* auth bitmask */
264
bool resume_from_current;
267
curl_off_t resume_from;
274
curl_off_t max_filesize;
278
unsigned short porttouse;
280
long low_speed_limit;
288
struct getout *url_list; /* point to the first node */
289
struct getout *url_last; /* point to the last/current node */
290
struct getout *url_get; /* point to the node to fill in URL */
291
struct getout *url_out; /* point to the node to fill in outfile */
305
char *trace_dump; /* file to dump the network trace to, or NULL */
309
bool tracetime; /* include timestamp? */
315
bool insecure_ok; /* set TRUE to allow insecure SSL connects */
317
bool ftp_create_dirs;
323
char *writeout; /* %-styled format string to output */
324
bool writeenv; /* write results to environment, if available */
325
FILE *errors; /* if stderr redirect is requested */
327
struct curl_slist *quote;
328
struct curl_slist *postquote;
329
struct curl_slist *prequote;
332
curl_TimeCond timecond;
334
struct curl_slist *headers;
335
struct curl_httppost *httppost;
336
struct curl_httppost *last_post;
337
struct curl_slist *telnet_options;
340
/* for bandwidth limiting features: */
341
curl_off_t sendpersecond; /* send to peer */
342
curl_off_t recvpersecond; /* receive from peer */
343
struct timeval lastsendtime;
345
struct timeval lastrecvtime;
350
long req_retry; /* number of retries */
351
long retry_delay; /* delay between retries (in seconds) */
352
long retry_maxtime; /* maximum time to keep retrying */
354
char *tp_url; /* third party URL */
355
char *tp_user; /* third party userpwd */
356
struct curl_slist *tp_quote;
357
struct curl_slist *tp_postquote;
358
struct curl_slist *tp_prequote;
359
char *ftp_account; /* for ACCT */
362
bool ignorecl; /* --ignore-content-length */
365
#define WARN_PREFIX "Warning: "
366
#define WARN_TEXTWIDTH (79 - (int)strlen(WARN_PREFIX))
367
/* produce this text message to the user unless mute was selected */
368
static void warnf(struct Configurable *config, const char *fmt, ...)
370
if(!(config->conf & CONF_MUTE)) {
374
char print_buffer[256];
378
len = vsnprintf(print_buffer, sizeof(print_buffer), fmt, ap);
383
fputs(WARN_PREFIX, config->errors);
385
if(len > (int)WARN_TEXTWIDTH) {
386
int cut = WARN_TEXTWIDTH-1;
388
while(!isspace((int)ptr[cut]) && cut) {
392
fwrite(ptr, cut + 1, 1, config->errors);
393
fputs("\n", config->errors);
394
ptr += cut+1; /* skip the space too */
398
fputs(ptr, config->errors);
247
406
* This is the main global constructor for the app. Call this before
248
407
* _any_ libcurl usage. If this fails, *NO* libcurl functions may be
320
474
"Options: (H) means HTTP/HTTPS only, (F) means FTP only",
321
475
" -a/--append Append to target file when uploading (F)",
322
476
" -A/--user-agent <string> User-Agent to send to server (H)",
323
" --anyauth Tell curl to choose authentication method (H)",
477
" --anyauth Pick \"any\" authentication method (H)",
324
478
" -b/--cookie <name=string/file> Cookie string or file to read cookies from (H)",
325
" --basic Enable HTTP Basic Authentication (H)",
479
" --basic Use HTTP Basic Authentication (H)",
326
480
" -B/--use-ascii Use ASCII/text transfer",
327
481
" -c/--cookie-jar <file> Write cookies to this file after operation (H)",
328
482
" -C/--continue-at <offset> Resumed transfer offset",
329
483
" -d/--data <data> HTTP POST data (H)",
330
" --data-ascii <data> HTTP POST ASCII data (H)",
331
" --data-binary <data> HTTP POST binary data (H)",
332
" --negotiate Enable HTTP Negotiate Authentication (H)",
333
" --digest Enable HTTP Digest Authentication (H)",
334
" --disable-eprt Prevent curl from using EPRT or LPRT (F)",
335
" --disable-epsv Prevent curl from using EPSV (F)",
484
" --data-ascii <data> HTTP POST ASCII data (H)",
485
" --data-binary <data> HTTP POST binary data (H)",
486
" --negotiate Use HTTP Negotiate Authentication (H)",
487
" --digest Use HTTP Digest Authentication (H)",
488
" --disable-eprt Inhibit using EPRT or LPRT (F)",
489
" --disable-epsv Inhibit using EPSV (F)",
336
490
" -D/--dump-header <file> Write the headers to this file",
337
491
" --egd-file <file> EGD socket path for random data (SSL)",
338
" --tcp-nodelay Set the TCP_NODELAY option",
492
" --tcp-nodelay Use the TCP_NODELAY option",
339
493
#ifdef USE_ENVIRONMENT
340
" --environment Write result codes to environment variables (RISC OS)",
494
" --environment Write results to environment variables (RISC OS)",
342
496
" -e/--referer Referer URL (H)",
343
497
" -E/--cert <cert[:passwd]> Client certificate file and password (SSL)",
354
508
" --connect-timeout <seconds> Maximum time allowed for connection",
355
509
" --create-dirs Create necessary local directory hierarchy",
356
510
" --crlf Convert LF to CRLF in upload",
357
" -f/--fail Fail silently (no output at all) on errors (H)",
511
" -f/--fail Fail silently (no output at all) on HTTP errors (H)",
358
512
" --ftp-create-dirs Create the remote dirs if not present (F)",
359
" --ftp-pasv Use PASV instead of PORT (F)",
513
" --ftp-pasv Use PASV/EPSV instead of PORT (F)",
514
" --ftp-skip-pasv-ip Skip the IP address for PASV (F)\n"
360
515
" --ftp-ssl Enable SSL/TLS for the ftp transfer (F)",
361
516
" -F/--form <name=content> Specify HTTP multipart POST data (H)",
362
517
" --form-string <name=string> Specify HTTP multipart POST data (H)",
364
519
" -G/--get Send the -d data with a HTTP GET (H)",
365
520
" -h/--help This help text",
366
521
" -H/--header <line> Custom header to pass to server (H)",
522
" --ignore-content-length Ignore the HTTP Content-Length header",
367
523
" -i/--include Include protocol headers in the output (H/F)",
368
524
" -I/--head Show document info only",
369
525
" -j/--junk-session-cookies Ignore session cookies read from file (H)",
370
526
" --interface <interface> Specify network interface to use",
371
527
" --krb4 <level> Enable krb4 with specified security level (F)",
372
" -k/--insecure Allow curl to connect to SSL sites without certs (H)",
528
" -k/--insecure Allow connections to SSL sites without certs (H)",
373
529
" -K/--config Specify which config file to read",
374
530
" -l/--list-only List only names of an FTP directory (F)",
375
531
" --limit-rate <rate> Limit transfer speed to this rate",
382
538
" -M/--manual Display the full manual",
383
539
" -n/--netrc Must read .netrc for user name and password",
384
540
" --netrc-optional Use either .netrc or URL; overrides -n",
385
" --ntlm Enable HTTP NTLM authentication (H)",
541
" --ntlm Use HTTP NTLM authentication (H)",
386
542
" -N/--no-buffer Disable buffering of the output stream",
387
543
" -o/--output <file> Write output to <file> instead of stdout",
388
544
" -O/--remote-name Write output to a file named as the remote file",
389
545
" -p/--proxytunnel Operate through a HTTP proxy tunnel (using CONNECT)",
390
" --proxy-anyauth Let curl pick proxy authentication method (H)",
391
" --proxy-basic Enable Basic authentication on the proxy (H)",
392
" --proxy-digest Enable Digest authentication on the proxy (H)",
393
" --proxy-ntlm Enable NTLM authentication on the proxy (H)",
546
" --proxy-anyauth Pick \"any\" proxy authentication method (H)",
547
" --proxy-basic Use Basic authentication on the proxy (H)",
548
" --proxy-digest Use Digest authentication on the proxy (H)",
549
" --proxy-ntlm Use NTLM authentication on the proxy (H)",
394
550
" -P/--ftp-port <address> Use PORT with address instead of PASV (F)",
395
551
" -q If used as the first parameter disables .curlrc",
396
552
" -Q/--quote <cmd> Send command(s) to server before file transfer (F)",
453
struct Configurable {
458
char *cookie; /* single line with specified cookies */
459
char *cookiejar; /* write to this file */
460
char *cookiefile; /* read from this file */
461
bool cookiesession; /* new session? */
462
bool encoding; /* Accept-Encoding please */
463
long authtype; /* auth bitmask */
465
bool resume_from_current;
468
curl_off_t resume_from;
475
curl_off_t max_filesize;
479
unsigned short porttouse;
481
long low_speed_limit;
489
struct getout *url_list; /* point to the first node */
490
struct getout *url_last; /* point to the last/current node */
491
struct getout *url_get; /* point to the node to fill in URL */
492
struct getout *url_out; /* point to the node to fill in outfile */
506
char *trace_dump; /* file to dump the network trace to, or NULL */
510
bool tracetime; /* include timestamp? */
516
bool insecure_ok; /* set TRUE to allow insecure SSL connects */
518
bool ftp_create_dirs;
523
char *writeout; /* %-styled format string to output */
524
bool writeenv; /* write results to environment, if available */
525
FILE *errors; /* if stderr redirect is requested */
527
struct curl_slist *quote;
528
struct curl_slist *postquote;
529
struct curl_slist *prequote;
532
curl_TimeCond timecond;
534
struct curl_slist *headers;
535
struct curl_httppost *httppost;
536
struct curl_httppost *last_post;
537
struct curl_slist *telnet_options;
540
/* for bandwidth limiting features: */
541
curl_off_t sendpersecond; /* send to peer */
542
curl_off_t recvpersecond; /* receive from peer */
543
struct timeval lastsendtime;
545
struct timeval lastrecvtime;
550
long req_retry; /* number of retries */
551
long retry_delay; /* delay between retries (in seconds) */
552
long retry_maxtime; /* maximum time to keep retrying */
554
char *tp_url; /* third party URL */
555
char *tp_user; /* third party userpwd */
556
struct curl_slist *tp_quote;
557
struct curl_slist *tp_postquote;
558
struct curl_slist *tp_prequote;
559
char *ftp_account; /* for ACCT */
562
609
/* global variable to hold info about libcurl */
563
610
static curl_version_info_data *curlinfo;
1197
1245
return PARAM_OK;
1248
static int ftpfilemethod(struct Configurable *config, char *str)
1250
if(strequal("singlecwd", str))
1252
if(strequal("nocwd", str))
1254
if(strequal("multicwd", str))
1256
warnf(config, "unrecognized ftp file method '%s', using default\n", str);
1200
1260
static ParameterError getparameter(char *flag, /* f or -long-flag */
1201
1261
char *nextarg, /* NULL if unset */
1202
1262
bool *usedarg, /* set to TRUE if the arg
1267
1327
{"$m", "ftp-account", TRUE},
1268
1328
{"$n", "proxy-anyauth", FALSE},
1269
1329
{"$o", "trace-time", FALSE},
1330
{"$p", "ignore-content-length", FALSE},
1331
{"$q", "ftp-skip-pasv-ip", FALSE},
1332
{"$r", "ftp-method", TRUE},
1271
1334
{"0", "http1.0", FALSE},
1272
1335
{"1", "tlsv1", FALSE},
1741
1826
nextarg++; /* pass the @ */
1743
if(curlx_strequal("-", nextarg))
1828
if(curlx_strequal("-", nextarg)) {
1831
if(subletter == 'b') /* forced binary */
1832
setmode(fileno(stdin), O_BINARY);
1746
1836
file = fopen(nextarg, "rb");
1838
warnf(config, "Couldn't read data from file \"%s\", this makes "
1839
"an empty POST.\n", nextarg);
1748
1842
if(subletter == 'b') /* forced binary */
1749
1843
postdata = file2memory(file, &config->postfieldsize);
1751
1845
postdata = file2string(file);
1752
1847
if(file && (file != stdin))
1851
/* no data from the file, point to a zero byte string to make this
1852
get sent as a POST anyway */
1853
postdata=strdup("");
1756
1857
GetStr(&postdata, nextarg);
1897
1999
(config->conf&(CONF_HEADER|CONF_NOBODY)) ) {
1898
2000
/* one of them weren't set, set both */
1899
2001
config->conf |= (CONF_HEADER|CONF_NOBODY);
1900
if(SetHTTPrequest(HTTPREQ_HEAD, &config->httpreq))
2002
if(SetHTTPrequest(config, HTTPREQ_HEAD, &config->httpreq))
1901
2003
return PARAM_BAD_USE;
1904
2006
/* both were set, clear both */
1905
2007
config->conf &= ~(CONF_HEADER|CONF_NOBODY);
1906
if(SetHTTPrequest(HTTPREQ_GET, &config->httpreq))
2008
if(SetHTTPrequest(config, HTTPREQ_GET, &config->httpreq))
1907
2009
return PARAM_BAD_USE;
2031
/* byte range requested */
2032
GetStr(&config->range, nextarg);
2133
/* Specifying a range WITHOUT A DASH will create an illegal HTTP range
2134
(and won't actually be range by definition). The man page previously
2135
claimed that to be a good way, why this code is added to work-around
2137
if(!strchr(nextarg, '-')) {
2141
"A specfied range MUST include at least one dash (-). "
2142
"Appending one for you!\n");
2143
off = curlx_strtoofft(nextarg, NULL, 10);
2144
snprintf(buffer, sizeof(buffer), CURL_FORMAT_OFF_T "-", off);
2145
GetStr(&config->range, buffer);
2148
/* byte range requested */
2149
GetStr(&config->range, nextarg);
2035
2153
/* use remote file's time */
2817
2939
const char *text;
2818
2940
struct timeval tv;
2819
2941
struct tm *now;
2822
2944
(void)handle; /* prevent compiler warning */
2824
2946
tv = curlx_tvnow();
2825
2947
now = localtime(&tv.tv_sec); /* not multithread safe but we don't care */
2826
2948
if(config->tracetime)
2827
snprintf(timebuf, sizeof(timebuf), "%02d:%02d:%02d.%02d ",
2828
now->tm_hour, now->tm_min, now->tm_sec,
2949
snprintf(timebuf, sizeof(timebuf), "%02d:%02d:%02d.%06d ",
2950
now->tm_hour, now->tm_min, now->tm_sec, tv.tv_usec);
3234
3356
httpgetfields = strdup(config->postfields);
3235
3357
free(config->postfields);
3236
3358
config->postfields = NULL;
3237
if(SetHTTPrequest((config->conf&CONF_NOBODY?HTTPREQ_HEAD:HTTPREQ_GET),
3359
if(SetHTTPrequest(config,
3360
(config->conf&CONF_NOBODY?HTTPREQ_HEAD:HTTPREQ_GET),
3238
3361
&config->httpreq)) {
3239
3362
free(httpgetfields);
3240
3363
return PARAM_BAD_USE;
3244
if(SetHTTPrequest(HTTPREQ_SIMPLEPOST, &config->httpreq))
3367
if(SetHTTPrequest(config, HTTPREQ_SIMPLEPOST, &config->httpreq))
3245
3368
return PARAM_BAD_USE;
3706
3832
curl_easy_setopt(curl, CURLOPT_FILETIME, TRUE);
3709
if (config->maxredirs)
3710
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, config->maxredirs);
3712
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, DEFAULT_MAXREDIRS);
3835
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, config->maxredirs);
3714
3836
curl_easy_setopt(curl, CURLOPT_CRLF, config->crlf);
3715
3837
curl_easy_setopt(curl, CURLOPT_QUOTE, config->quote);
3716
3838
curl_easy_setopt(curl, CURLOPT_POSTQUOTE, config->postquote);
3836
3958
curl_easy_setopt(curl, CURLOPT_SOURCE_QUOTE, config->tp_quote);
3837
3959
curl_easy_setopt(curl, CURLOPT_FTP_ACCOUNT, config->ftp_account);
3961
curl_easy_setopt(curl, CURLOPT_IGNORE_CONTENT_LENGTH, config->ignorecl);
3964
curl_easy_setopt(curl, CURLOPT_FTP_SKIP_PASV_IP, config->ftp_skip_ip);
3967
curl_easy_setopt(curl, CURLOPT_FTP_FILEMETHOD, config->ftp_filemethod);
3839
3969
retry_numretries = config->req_retry;
3841
3971
retrystart = curlx_tvnow();