203
/* Just a set of bits */
205
#define CONF_DEFAULT 0
208
#define CONF_ISATTY (1<<0) /* output to tty! */
209
#define CONF_AUTO_REFERER (1<<4) /* the automatic referer-system please! */
210
#define CONF_HEADER (1<<8) /* throw the header out too */
211
#define CONF_NOPROGRESS (1<<10) /* shut off the progress meter */
212
#define CONF_NOBODY (1<<11) /* get meta-data (headers) about the file
213
without transferring the body, use HEAD to
215
#define CONF_FAILONERROR (1<<12) /* no output on http error codes >= 300 */
216
#define CONF_DIRLISTONLY (1<<16) /* request nonverbose directory listing */
217
#define CONF_FTPAPPEND (1<<20) /* Append instead of overwrite on upload! */
218
#define CONF_NETRC (1<<22) /* read user+password from .netrc */
219
#define CONF_FOLLOWLOCATION (1<<23) /* use Location: Luke! */
220
#define CONF_GETTEXT (1<<24) /* use ASCII/text for transfer */
221
#define CONF_MUTE (1<<28) /* force NOPROGRESS */
223
#define CONF_NETRC_OPT (1<<29) /* read user+password from either
225
#define CONF_UNRESTRICTED_AUTH (1<<30)
226
/* Send authentication (user+password) when following
227
* locations, even when hostname changed */
230
198
#include <direct.h>
236
204
#include "curlmsg_vms.h"
239
/* Support uploading and resuming of >2GB files
241
#if defined(WIN32) && (SIZEOF_CURL_OFF_T > 4)
242
#define lseek(x,y,z) _lseeki64(x, y, z)
243
#define struct_stat struct _stati64
244
#define stat(file,st) _stati64(file,st)
246
#define struct_stat struct stat
208
* Large file support (>2Gb) using WIN32 functions.
211
#ifdef USE_WIN32_LARGE_FILES
213
# include <sys/types.h>
214
# include <sys/stat.h>
215
# define lseek(fdes,offset,whence) _lseeki64(fdes, offset, whence)
216
# define fstat(fdes,stp) _fstati64(fdes, stp)
217
# define stat(fname,stp) _stati64(fname, stp)
218
# define struct_stat struct _stati64
222
* Small file support (<2Gb) using WIN32 functions.
225
#ifdef USE_WIN32_SMALL_FILES
227
# include <sys/types.h>
228
# include <sys/stat.h>
229
# define lseek(fdes,offset,whence) _lseek(fdes, (long)offset, whence)
230
# define fstat(fdes,stp) _fstat(fdes, stp)
231
# define stat(fname,stp) _stat(fname, stp)
232
# define struct_stat struct _stat
236
# define struct_stat struct stat
240
* Default sizeof(off_t) in case it hasn't been defined in config file.
244
# if defined(__VMS) && (defined(__alpha) || defined(__ia64))
245
# if defined(_LARGEFILE)
246
# define SIZEOF_OFF_T 8
248
# elif defined(__OS400__) && defined(__ILEC400__)
249
# if defined(_LARGE_FILES)
250
# define SIZEOF_OFF_T 8
252
# elif defined(__MVS__) && defined(__IBMC__)
253
# if defined(_LP64) || defined(_LARGE_FILES)
254
# define SIZEOF_OFF_T 8
256
# elif defined(__370__) && defined(__IBMC__)
257
# if defined(_LP64) || defined(_LARGE_FILES)
258
# define SIZEOF_OFF_T 8
261
# ifndef SIZEOF_OFF_T
262
# define SIZEOF_OFF_T 4
249
266
#ifdef CURL_DOES_CONVERSIONS
431
449
char *proxyuserpwd;
451
int proxyver; /* set to CURLPROXY_HTTP* define */
433
453
bool proxytunnel;
454
bool ftp_append; /* APPE on ftp */
455
bool mute; /* shutup */
456
bool use_ascii; /* select ascii or text transfer */
457
bool autoreferer; /* automatically set referer */
458
bool failonerror; /* fail on (HTTP) errors */
459
bool include_headers; /* send headers to data output */
460
bool no_body; /* don't get the body */
461
bool dirlistonly; /* only get the FTP dir list */
462
bool followlocation; /* follow http redirects */
463
bool unrestricted_auth; /* Continue to send authentication (user+password)
464
when following ocations, even when hostname
469
bool isatty; /* updated internally only if the output is a tty */
435
470
struct getout *url_list; /* point to the first node */
436
471
struct getout *url_last; /* point to the last/current node */
437
472
struct getout *url_get; /* point to the node to fill in URL */
659
701
"Usage: curl [options...] <url>",
660
702
"Options: (H) means HTTP/HTTPS only, (F) means FTP only",
661
703
" --anyauth Pick \"any\" authentication method (H)",
662
" -a/--append Append to target file when uploading (F)",
704
" -a/--append Append to target file when uploading (F/SFTP)",
663
705
" --basic Use HTTP Basic Authentication (H)",
664
706
" --cacert <file> CA certificate to verify peer against (SSL)",
665
707
" --capath <directory> CA directory to verify peer against (SSL)",
667
709
" --cert-type <type> Certificate file type (DER/PEM/ENG) (SSL)",
668
710
" --ciphers <list> SSL ciphers to use (SSL)",
669
711
" --compressed Request compressed response (using deflate or gzip)",
670
" -K/--config Specify which config file to read",
712
" -K/--config <file> Specify which config file to read",
671
713
" --connect-timeout <seconds> Maximum time allowed for connection",
672
714
" -C/--continue-at <offset> Resumed transfer offset",
673
715
" -b/--cookie <name=string/file> Cookie string or file to read cookies from (H)",
691
733
" -F/--form <name=content> Specify HTTP multipart POST data (H)",
692
734
" --form-string <name=string> Specify HTTP multipart POST data (H)",
693
735
" --ftp-account <data> Account data to send when requested by server (F)",
694
" --ftp-alternative-to-user String to replace \"USER [name]\" (F)",
736
" --ftp-alternative-to-user <cmd> String to replace \"USER [name]\" (F)",
695
737
" --ftp-create-dirs Create the remote dirs if not present (F)",
696
738
" --ftp-method [multicwd/nocwd/singlecwd] Control CWD usage (F)",
697
739
" --ftp-pasv Use PASV/EPSV instead of PORT (F)",
719
761
" --keepalive-time <seconds> Interval between keepalive probes",
720
762
" --key <key> Private key file name (SSL/SSH)",
721
763
" --key-type <type> Private key file type (DER/PEM/ENG) (SSL)",
722
" --krb <level> Enable kerberos with specified security level (F)",
764
" --krb <level> Enable Kerberos with specified security level (F)",
723
765
" --libcurl <file> Dump libcurl equivalent code of this command line",
724
766
" --limit-rate <rate> Limit transfer speed to this rate",
725
767
" -l/--list-only List only names of an FTP directory (F)",
736
778
" -N/--no-buffer Disable buffering of the output stream",
737
779
" --no-keepalive Disable keepalive use on the connection",
738
780
" --no-sessionid Disable SSL session-ID reusing (SSL)",
781
" --noproxy Comma-separated list of hosts which do not use proxy",
739
782
" --ntlm Use HTTP NTLM authentication (H)",
740
783
" -o/--output <file> Write output to <file> instead of stdout",
741
784
" --pass <pass> Pass phrase for the private key (SSL/SSH)",
742
785
" --post301 Do not switch to GET after following a 301 redirect (H)",
786
" --post302 Do not switch to GET after following a 302 redirect (H)",
743
787
" -#/--progress-bar Display transfer progress as a progress bar",
744
788
" -x/--proxy <host[:port]> Use HTTP proxy on given port",
745
789
" --proxy-anyauth Pick \"any\" proxy authentication method (H)",
748
792
" --proxy-negotiate Use Negotiate authentication on the proxy (H)",
749
793
" --proxy-ntlm Use NTLM authentication on the proxy (H)",
750
794
" -U/--proxy-user <user[:password]> Set proxy user and password",
795
" --proxy1.0 <host[:port]> Use HTTP/1.0 proxy on given port",
751
796
" -p/--proxytunnel Operate through a HTTP proxy tunnel (using CONNECT)",
752
797
" --pubkey <key> Public key file name (SSH)",
753
798
" -Q/--quote <cmd> Send command(s) to server before file transfer (F/SFTP)",
754
799
" --random-file <file> File for reading random data from (SSL)",
755
" -r/--range <range> Retrieve a byte range from a HTTP/1.1 or FTP server",
800
" -r/--range <range> Retrieve only the bytes within a range",
756
801
" --raw Pass HTTP \"raw\", without any transfer decoding (H)",
757
802
" -e/--referer Referer URL (H)",
758
803
" -O/--remote-name Write output to a file named as the remote file",
804
" --remote-name-all Use the remote file name for all URLs",
759
805
" -R/--remote-time Set the remote file's time on the local output",
760
806
" -X/--request <command> Specify request command to use",
761
807
" --retry <num> Retry request <num> times if transient problems occur",
767
813
" --socks4a <host[:port]> SOCKS4a proxy on given host + port",
768
814
" --socks5 <host[:port]> SOCKS5 proxy on given host + port",
769
815
" --socks5-hostname <host[:port]> SOCKS5 proxy, pass host name to proxy",
816
#if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
817
" --socks5-gssapi-service <name> SOCKS5 proxy service name for gssapi",
818
" --socks5-gssapi-nec Compatibility with NEC SOCKS5 server",
770
820
" -Y/--speed-limit Stop transfer if below speed-limit for 'speed-time' secs",
771
821
" -y/--speed-time Time needed to trig speed-limit abort. Defaults to 30",
772
822
" -2/--sslv2 Use SSLv2 (SSL)",
787
837
" -v/--verbose Make the operation more talkative",
788
838
" -V/--version Show version number and quit",
791
" --wdebug Turn on Watt-32 debugging under DJGPP",
841
" --wdebug Turn on Watt-32 debugging",
793
" -w/--write-out [format] What to output after completion",
843
" -w/--write-out <format> What to output after completion",
794
844
" -q If used as the first parameter disables .curlrc",
1390
1441
* @param str the buffer containing the offset
1391
1442
* @return zero if successful, non-zero if failure.
1393
static int str2offset(curl_off_t *val, char *str)
1444
static int str2offset(curl_off_t *val, const char *str)
1395
#if SIZEOF_CURL_OFF_T > 4
1396
/* Ugly, but without going through a bunch of rigmarole, we don't have the
1397
* definitions for LLONG_{MIN,MAX} or LONG_LONG_{MIN,MAX}.
1400
#if defined(_MSC_VER)
1401
#define LLONG_MAX (curl_off_t)0x7FFFFFFFFFFFFFFFi64
1402
#define LLONG_MIN (curl_off_t)0x8000000000000000i64
1403
#elif defined(_CRAYC)
1404
#define LLONG_MAX (curl_off_t)0x7FFFFFFFFFFFFFFF
1405
#define LLONG_MIN (curl_off_t)0x8000000000000000
1407
#define LLONG_MAX (curl_off_t)0x7FFFFFFFFFFFFFFFLL
1408
#define LLONG_MIN (curl_off_t)0x8000000000000000LL
1412
/* this is a duplicate of the function that is also used in libcurl */
1446
#if (CURL_SIZEOF_CURL_OFF_T > CURL_SIZEOF_LONG)
1413
1447
*val = curlx_strtoofft(str, NULL, 0);
1415
if ((*val == LLONG_MAX || *val == LLONG_MIN) && ERRNO == ERANGE)
1448
if((*val == CURL_LLONG_MAX || *val == CURL_LLONG_MIN) && (ERRNO == ERANGE))
1418
1451
*val = strtol(str, NULL, 0);
1473
1506
return PARAM_OK;
1476
static int ftpfilemethod(struct Configurable *config, char *str)
1509
static int ftpfilemethod(struct Configurable *config, const char *str)
1478
if(curlx_strequal("singlecwd", str))
1511
if(curlx_raw_equal("singlecwd", str))
1479
1512
return CURLFTPMETHOD_SINGLECWD;
1480
if(curlx_strequal("nocwd", str))
1513
if(curlx_raw_equal("nocwd", str))
1481
1514
return CURLFTPMETHOD_NOCWD;
1482
if(curlx_strequal("multicwd", str))
1515
if(curlx_raw_equal("multicwd", str))
1483
1516
return CURLFTPMETHOD_MULTICWD;
1484
1517
warnf(config, "unrecognized ftp file method '%s', using default\n", str);
1485
1518
return CURLFTPMETHOD_MULTICWD;
1488
static int ftpcccmethod(struct Configurable *config, char *str)
1521
static int ftpcccmethod(struct Configurable *config, const char *str)
1490
if(curlx_strequal("passive", str))
1523
if(curlx_raw_equal("passive", str))
1491
1524
return CURLFTPSSL_CCC_PASSIVE;
1492
if(curlx_strequal("active", str))
1525
if(curlx_raw_equal("active", str))
1493
1526
return CURLFTPSSL_CCC_ACTIVE;
1494
1527
warnf(config, "unrecognized ftp CCC method '%s', using default\n", str);
1495
1528
return CURLFTPSSL_CCC_PASSIVE;
1602
1640
{"*x", "krb4" , TRUE}, /* this is the previous name */
1603
1641
{"*y", "max-filesize", TRUE},
1604
1642
{"*z", "disable-eprt", FALSE},
1643
{"*Z", "eprt", FALSE}, /* made like this to make --no-eprt and --eprt to
1644
work although --disable-eprt is the documented
1605
1646
{"$a", "ftp-ssl", FALSE},
1606
1647
{"$b", "ftp-pasv", FALSE},
1607
1648
{"$c", "socks5", TRUE},
1626
1667
{"$T", "socks4a", TRUE},
1627
1668
{"$u", "ftp-alternative-to-user", TRUE},
1628
1669
{"$v", "ftp-ssl-reqd", FALSE},
1629
{"$w", "no-sessionid", FALSE},
1670
{"$w", "sessionid", FALSE}, /* listed as --no-sessionid in the help */
1630
1671
{"$x", "ftp-ssl-control", FALSE},
1631
1672
{"$y", "ftp-ssl-ccc", FALSE},
1632
1673
{"$j", "ftp-ssl-ccc-mode", TRUE},
1633
1674
{"$z", "libcurl", TRUE},
1634
1675
{"$#", "raw", FALSE},
1635
1676
{"$0", "post301", FALSE},
1636
{"$1", "no-keepalive", FALSE},
1677
{"$1", "keepalive", FALSE}, /* listed as --no-keepalive in the help */
1637
1678
{"$2", "socks5-hostname", TRUE},
1638
1679
{"$3", "keepalive-time", TRUE},
1680
{"$4", "post302", FALSE},
1681
{"$5", "noproxy", TRUE},
1682
#if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
1683
{"$6", "socks5-gssapi-service", TRUE},
1684
{"$7", "socks5-gssapi-nec", FALSE},
1686
{"$8", "proxy1.0", TRUE},
1640
1688
{"0", "http1.0", FALSE},
1641
1689
{"1", "tlsv1", FALSE},
1684
1732
{"M", "manual", FALSE},
1685
1733
{"n", "netrc", FALSE},
1686
1734
{"no", "netrc-optional", FALSE},
1687
{"N", "no-buffer", FALSE},
1735
{"N", "buffer", FALSE}, /* listed as --no-buffer in the help */
1688
1736
{"o", "output", TRUE},
1689
{"O", "remote-name", FALSE},
1737
{"O", "remote-name", FALSE},
1738
{"Oa", "remote-name-all", FALSE},
1690
1739
{"p", "proxytunnel", FALSE},
1691
1740
{"P", "ftpport", TRUE}, /* older version */
1692
1741
{"P", "ftp-port", TRUE},
1696
1745
{"R", "remote-time", FALSE},
1697
1746
{"s", "silent", FALSE},
1698
1747
{"S", "show-error", FALSE},
1699
{"t", "telnet-options", TRUE},
1748
{"t", "telnet-options", TRUE}, /* this is documented as telnet-option */
1700
1749
{"T", "upload-file", TRUE},
1701
1750
{"u", "user", TRUE},
1702
1751
{"U", "proxy-user", TRUE},
1718
1767
char *word=('-' == flag[0])?flag+2:flag;
1719
1768
size_t fnam=strlen(word);
1771
if(!strncmp(word, "no-", 3)) {
1772
/* disable this option but ignore the "no-" part when looking for it */
1721
1777
for(j=0; j< sizeof(aliases)/sizeof(aliases[0]); j++) {
1722
1778
if(curlx_strnequal(aliases[j].lname, word, fnam)) {
1723
1779
longopt = TRUE;
1725
if(curlx_strequal(aliases[j].lname, word)) {
1781
if(curlx_raw_equal(aliases[j].lname, word)) {
1726
1782
parse = aliases[j].letter;
1728
1784
numhits = 1; /* a single unique hit */
1775
1831
return PARAM_OPTION_UNKNOWN;
1779
return PARAM_OPTION_UNKNOWN;
1781
if(!longopt && aliases[hit].extraparam && parse[1]) {
1782
nextarg=(char *)&parse[1]; /* this is the actual extra parameter */
1783
singleopt=TRUE; /* don't loop anymore after this */
1785
else if(!nextarg && aliases[hit].extraparam) {
1786
return PARAM_REQUIRES_PARAMETER;
1788
else if(nextarg && aliases[hit].extraparam)
1789
*usedarg = TRUE; /* mark it as used */
1835
if(aliases[hit].extraparam) {
1836
/* this option requires an extra parameter */
1837
if(!longopt && parse[1]) {
1838
nextarg=(char *)&parse[1]; /* this is the actual extra parameter */
1839
singleopt=TRUE; /* don't loop anymore after this */
1842
return PARAM_REQUIRES_PARAMETER;
1844
*usedarg = TRUE; /* mark it as used */
1791
1847
switch(letter) {
1792
1848
case '*': /* options without a short option */
1865
1924
case 'j': /* --compressed */
1866
config->encoding ^= TRUE;
1925
config->encoding = toggle;
1869
1928
case 'k': /* --digest */
1870
config->authtype = CURLAUTH_DIGEST;
1930
config->authtype |= CURLAUTH_DIGEST;
1932
config->authtype &= ~CURLAUTH_DIGEST;
1873
1935
case 'l': /* --negotiate */
1874
if(curlinfo->features & CURL_VERSION_GSSNEGOTIATE)
1875
config->authtype = CURLAUTH_GSSNEGOTIATE;
1937
if(curlinfo->features & CURL_VERSION_GSSNEGOTIATE)
1938
config->authtype |= CURLAUTH_GSSNEGOTIATE;
1940
return PARAM_LIBCURL_DOESNT_SUPPORT;
1877
return PARAM_LIBCURL_DOESNT_SUPPORT;
1943
config->authtype &= ~CURLAUTH_GSSNEGOTIATE;
1880
1946
case 'm': /* --ntlm */
1881
if(curlinfo->features & CURL_VERSION_NTLM)
1882
config->authtype = CURLAUTH_NTLM;
1948
if(curlinfo->features & CURL_VERSION_NTLM)
1949
config->authtype |= CURLAUTH_NTLM;
1951
return PARAM_LIBCURL_DOESNT_SUPPORT;
1884
return PARAM_LIBCURL_DOESNT_SUPPORT;
1954
config->authtype &= ~CURLAUTH_NTLM;
1887
1957
case 'n': /* --basic for completeness */
1888
config->authtype = CURLAUTH_BASIC;
1959
config->authtype |= CURLAUTH_BASIC;
1961
config->authtype &= ~CURLAUTH_BASIC;
1891
1964
case 'o': /* --anyauth, let libcurl pick it */
1892
config->authtype = CURLAUTH_ANY;
1966
config->authtype = CURLAUTH_ANY;
1967
/* --no-anyauth simply doesn't touch it */
1896
1971
case 'p': /* --wdebug */
1900
1975
case 'q': /* --ftp-create-dirs */
1901
config->ftp_create_dirs ^= TRUE;
1976
config->ftp_create_dirs = toggle;
1904
1979
case 'r': /* --create-dirs */
2012
2092
config->socksver = CURLPROXY_SOCKS5_HOSTNAME;
2014
2094
case 'd': /* --tcp-nodelay option */
2015
config->tcp_nodelay ^= TRUE;
2095
config->tcp_nodelay = toggle;
2017
2097
case 'e': /* --proxy-digest */
2018
config->proxydigest ^= TRUE;
2098
config->proxydigest = toggle;
2020
2100
case 'f': /* --proxy-basic */
2021
config->proxybasic ^= TRUE;
2101
config->proxybasic = toggle;
2023
2103
case 'g': /* --retry */
2024
2104
if(str2num(&config->req_retry, nextarg))
2043
2123
GetStr(&config->ftp_account, nextarg);
2045
2125
case 'n': /* --proxy-anyauth */
2046
config->proxyanyauth ^= TRUE;
2126
config->proxyanyauth = toggle;
2048
2128
case 'o': /* --trace-time */
2049
config->tracetime ^= TRUE;
2129
config->tracetime = toggle;
2051
2131
case 'p': /* --ignore-content-length */
2052
config->ignorecl ^= TRUE;
2132
config->ignorecl = toggle;
2054
2134
case 'q': /* --ftp-skip-pasv-ip */
2055
config->ftp_skip_ip ^= TRUE;
2135
config->ftp_skip_ip = toggle;
2057
2137
case 'r': /* --ftp-method (undocumented at this point) */
2058
2138
config->ftp_filemethod = ftpfilemethod(config, nextarg);
2077
2157
GetStr(&config->ftp_alternative_to_user, nextarg);
2079
2159
case 'v': /* --ftp-ssl-reqd */
2080
config->ftp_ssl_reqd ^= TRUE;
2160
config->ftp_ssl_reqd = toggle;
2082
2162
case 'w': /* --no-sessionid */
2083
config->disable_sessionid ^= TRUE;
2163
config->disable_sessionid = (bool)(!toggle);
2085
2165
case 'x': /* --ftp-ssl-control */
2086
config->ftp_ssl_control ^= TRUE;
2166
config->ftp_ssl_control = toggle;
2088
2168
case 'y': /* --ftp-ssl-ccc */
2089
config->ftp_ssl_ccc ^= TRUE;
2169
config->ftp_ssl_ccc = toggle;
2090
2170
if(!config->ftp_ssl_ccc_mode)
2091
2171
config->ftp_ssl_ccc_mode = CURLFTPSSL_CCC_PASSIVE;
2098
2178
GetStr(&config->libcurl, nextarg);
2100
2180
case '#': /* --raw */
2101
config->raw ^= TRUE;
2181
config->raw = toggle;
2103
2183
case '0': /* --post301 */
2104
config->post301 ^= TRUE;
2184
config->post301 = toggle;
2106
2186
case '1': /* --no-keepalive */
2107
config->nokeepalive ^= TRUE;
2187
config->nokeepalive = (bool)(!toggle);
2109
2189
case '3': /* --keepalive-time */
2110
2190
if(str2num(&config->alivetime, nextarg))
2111
2191
return PARAM_BAD_NUMERIC;
2193
case '4': /* --post302 */
2194
config->post302 = toggle;
2196
case '5': /* --noproxy */
2197
/* This specifies the noproxy list */
2198
GetStr(&config->noproxy, nextarg);
2200
#if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
2201
case '6': /* --socks5-gssapi-service */
2202
GetStr(&config->socks5_gssapi_service, nextarg);
2204
case '7': /* --socks5-gssapi-nec*/
2205
config->socks5_gssapi_nec = TRUE;
2208
case '8': /* --proxy1.0 */
2209
/* http 1.0 proxy */
2210
GetStr(&config->proxy, nextarg);
2211
config->proxyver = CURLPROXY_HTTP_1_0;
2115
2215
case '#': /* --progress-bar */
2116
config->progressmode ^= CURL_PROGRESS_BAR;
2216
config->progressmode = toggle?CURL_PROGRESS_BAR:0;
2119
2219
/* HTTP version 1.0 */
2459
config->conf ^= CONF_HEADER; /* include the HTTP header as well */
2565
config->include_headers = toggle; /* include the headers as well in the
2566
general output stream */
2462
config->cookiesession ^= TRUE;
2569
config->cookiesession = toggle;
2466
* CONF_BODY will imply CONF_HEADER later on
2573
* no_body will imply include_headers later on
2468
config->conf ^= CONF_NOBODY;
2575
config->no_body = toggle;
2469
2576
if(SetHTTPrequest(config,
2470
(config->conf & CONF_NOBODY)?HTTPREQ_HEAD:HTTPREQ_GET,
2577
(config->no_body)?HTTPREQ_HEAD:HTTPREQ_GET,
2471
2578
&config->httpreq))
2472
2579
return PARAM_BAD_USE;
2474
2581
case 'k': /* allow insecure SSL connects */
2475
config->insecure_ok ^= TRUE;
2582
config->insecure_ok = toggle;
2477
2584
case 'K': /* parse config file */
2478
2585
if(parseconfig(nextarg, config))
2498
2605
return PARAM_BAD_NUMERIC;
2500
2607
case 'M': /* M for manual, huge help */
2608
if(toggle) { /* --no-manual shows no manual... */
2501
2609
#ifdef USE_MANUAL
2503
return PARAM_HELP_REQUESTED;
2611
return PARAM_HELP_REQUESTED;
2506
"built-in manual was disabled at build-time!\n");
2507
return PARAM_OPTION_UNKNOWN;
2614
"built-in manual was disabled at build-time!\n");
2615
return PARAM_OPTION_UNKNOWN;
2510
2620
switch(subletter) {
2511
2621
case 'o': /* CA info PEM file */
2512
2622
/* use .netrc or URL */
2513
config->conf ^= CONF_NETRC_OPT;
2623
config->netrc_opt = toggle;
2516
2626
/* pick info from .netrc, if this is used for http, curl will
2517
2627
automatically enfore user+password with the request */
2518
config->conf ^= CONF_NETRC;
2628
config->netrc = toggle;
2523
2633
/* disable the output I/O buffering */
2524
config->nobuffer ^= 1;
2634
config->nobuffer = (bool)(!toggle);
2636
case 'O': /* --remote-name */
2637
if(subletter == 'a') { /* --remote-name-all */
2638
config->default_node_flags = toggle?GETOUT_USEREMOTE:0;
2642
case 'o': /* --output */
2528
2643
/* output file */
2530
2645
struct getout *url;
2630
2750
/* use remote file's time */
2631
config->remote_time ^= TRUE;
2751
config->remote_time = toggle;
2634
2754
/* don't show progress meter, don't show errors : */
2635
config->conf ^= (CONF_MUTE|CONF_NOPROGRESS);
2636
config->showerror ^= TRUE; /* toggle off */
2756
config->mute = config->noprogress = TRUE;
2758
config->mute = config->noprogress = FALSE;
2759
config->showerror = (bool)(!toggle); /* toggle off */
2639
2762
/* show errors */
2640
config->showerror ^= TRUE; /* toggle on if used with -s */
2763
config->showerror = toggle; /* toggle on if used with -s */
2643
2766
/* Telnet options */
2689
2812
checkpasswd("proxy", &config->proxyuserpwd);
2692
/* the '%' thing here will cause the trace get sent to stderr */
2693
GetStr(&config->trace_dump, (char *)"%");
2694
if(config->tracetype && (config->tracetype != TRACE_PLAIN))
2696
"-v/--verbose overrides an earlier trace/verbose option\n");
2697
config->tracetype = TRACE_PLAIN;
2816
/* the '%' thing here will cause the trace get sent to stderr */
2817
GetStr(&config->trace_dump, (char *)"%");
2818
if(config->tracetype && (config->tracetype != TRACE_PLAIN))
2820
"-v/--verbose overrides an earlier trace/verbose option\n");
2821
config->tracetype = TRACE_PLAIN;
2824
/* verbose is disabled here */
2825
config->tracetype = TRACE_NONE;
2701
2829
const char * const *proto;
2832
/* --no-version yields no output! */
2703
2835
printf(CURL_ID "%s\n", curl_version());
2704
2836
if (curlinfo->protocols) {
2705
2837
printf("Protocols: ");
2830
2963
return PARAM_OK;
2967
* Copies the string from line to the buffer at param, unquoting
2968
* backslash-quoted characters and NUL-terminating the output string.
2969
* Stops at the first non-backslash-quoted double quote character or the
2970
* end of the input string. param must be at least as long as the input
2971
* string. Returns the pointer after the last handled input character.
2973
static const char *unslashquote(const char *line, char *param)
2975
while(*line && (*line != '\"')) {
2980
/* default is to output the letter after the backslash */
2981
switch(out = *line) {
2983
continue; /* this'll break out of the loop */
3003
*param=0; /* always zero terminate */
2833
3007
/* return 0 on everything-is-fine, and non-zero otherwise */
2834
3008
static int parseconfig(const char *filename,
2835
3009
struct Configurable *config)
2957
3132
/* the parameter starts here (unless quoted) */
2958
3133
if(*line == '\"') {
2960
/* quoted parameter, do the qoute dance */
3134
/* quoted parameter, do the quote dance */
2962
param=strdup(line); /* parameter */
3136
param=malloc(strlen(line)+1); /* parameter */
2963
3143
alloced_param=TRUE;
2966
while(*line && (*line != '\"')) {
2971
/* default is to output the letter after the backslah */
2972
switch(out = *line) {
2974
continue; /* this'll break out of the loop */
2994
*ptr=0; /* always zero terminate */
3144
line = (char*) unslashquote(line, param);
2998
3147
param=line; /* parameter starts here */
3130
3273
struct InStruct *in=(struct InStruct *)stream;
3132
#if (SIZEOF_CURL_OFF_T > SIZEOF_OFF_T) && !defined(lseek)
3133
/* The sizeof check following here is only interesting if curl_off_t is
3134
larger than off_t, but also not on windows-like systems for which lseek
3135
is a defined macro that works around the 32bit off_t-problem and thus do
3136
64bit seeks correctly anyway */
3275
#if (CURL_SIZEOF_CURL_OFF_T > SIZEOF_OFF_T) && !defined(USE_WIN32_LARGE_FILES)
3276
/* The offset check following here is only interesting if curl_off_t is
3277
larger than off_t and we are not using the WIN32 large file support
3278
macros that provide the support to do 64bit seeks correctly */
3138
3280
if(offset > MAX_SEEK) {
3139
3281
/* Some precaution code to work around problems with different data sizes
3372
3514
secs = tv.tv_sec;
3373
3515
now = localtime(&secs); /* not multithread safe but we don't care */
3374
3516
if(config->tracetime)
3375
snprintf(timebuf, sizeof(timebuf), "%02d:%02d:%02d.%06d ",
3376
now->tm_hour, now->tm_min, now->tm_sec, tv.tv_usec);
3517
snprintf(timebuf, sizeof(timebuf), "%02d:%02d:%02d.%06ld ",
3518
now->tm_hour, now->tm_min, now->tm_sec, (long)tv.tv_usec);
3411
3558
for(i=0; i<size-1; i++) {
3412
3559
if(data[i] == '\n') { /* LF */
3414
fprintf(config->trace_stream, "%s%s ",
3415
timebuf, s_infotype[type]);
3561
fprintf(output, "%s%s ", timebuf, s_infotype[type]);
3417
fwrite(data+st, i-st+1, 1, config->trace_stream);
3563
fwrite(data+st, i-st+1, 1, output);
3423
fprintf(config->trace_stream, "%s%s ", timebuf, s_infotype[type]);
3424
fwrite(data+st, i-st+1, 1, config->trace_stream);
3569
fprintf(output, "%s%s ", timebuf, s_infotype[type]);
3570
fwrite(data+st, i-st+1, 1, output);
3425
3571
newl = (bool)(size && (data[size-1] != '\n'));
3426
3572
traced_data = FALSE;
3428
3574
case CURLINFO_TEXT:
3429
3575
case CURLINFO_HEADER_IN:
3431
fprintf(config->trace_stream, "%s%s ", timebuf, s_infotype[type]);
3432
fwrite(data, size, 1, config->trace_stream);
3577
fprintf(output, "%s%s ", timebuf, s_infotype[type]);
3578
fwrite(data, size, 1, output);
3433
3579
newl = (bool)(size && (data[size-1] != '\n'));
3434
3580
traced_data = FALSE;
3442
3588
to stderr or stdout, we don't display the alert about the data not
3443
3589
being shown as the data _is_ shown then just not via this
3445
if(!(config->conf&CONF_ISATTY) ||
3446
((config->trace_stream != stderr) &&
3447
(config->trace_stream != stdout))) {
3591
if(!config->isatty ||
3592
((output != stderr) && (output != stdout))) {
3449
fprintf(config->trace_stream, "%s%s ", timebuf, s_infotype[type]);
3450
fprintf(config->trace_stream, "[data not shown]\n");
3594
fprintf(output, "%s%s ", timebuf, s_infotype[type]);
3595
fprintf(output, "[data not shown]\n");
3452
3597
traced_data = TRUE;
3643
3796
static struct curl_slist *easycode;
3645
CURLcode _my_setopt(CURL *curl, struct Configurable *config, const char *name,
3646
CURLoption tag, ...);
3798
static CURLcode _my_setopt(CURL *curl, struct Configurable *config,
3799
const char *name, CURLoption tag, ...);
3648
CURLcode _my_setopt(CURL *curl, struct Configurable *config, const char *name,
3649
CURLoption tag, ...)
3801
static CURLcode _my_setopt(CURL *curl, struct Configurable *config,
3802
const char *name, CURLoption tag, ...)
4328
4490
&& outs.stream && isatty(fileno(outs.stream)))
4329
4491
/* we send the output to a tty, therefore we switch off the progress
4331
config->conf |= CONF_NOPROGRESS|CONF_ISATTY;
4493
config->noprogress = config->isatty = TRUE;
4333
if (urlnum > 1 && !(config->conf&CONF_MUTE)) {
4495
if (urlnum > 1 && !(config->mute)) {
4334
4496
fprintf(config->errors, "\n[%d/%d]: %s --> %s\n",
4335
4497
i+1, urlnum, url, outfile ? outfile : "<stdout>");
4414
4576
my_setopt(curl, CURLOPT_INFILESIZE_LARGE, uploadfilesize);
4415
4577
my_setopt(curl, CURLOPT_URL, url); /* what to fetch */
4416
4578
my_setopt(curl, CURLOPT_PROXY, config->proxy); /* proxy to use */
4417
my_setopt(curl, CURLOPT_NOPROGRESS, config->conf&CONF_NOPROGRESS);
4418
if(config->conf&CONF_NOBODY) {
4580
my_setopt(curl, CURLOPT_PROXYTYPE, config->proxyver);
4581
my_setopt(curl, CURLOPT_NOPROGRESS, config->noprogress);
4582
if(config->no_body) {
4419
4583
my_setopt(curl, CURLOPT_NOBODY, 1);
4420
4584
my_setopt(curl, CURLOPT_HEADER, 1);
4423
my_setopt(curl, CURLOPT_HEADER, config->conf&CONF_HEADER);
4587
my_setopt(curl, CURLOPT_HEADER, config->include_headers);
4425
my_setopt(curl, CURLOPT_FAILONERROR,
4426
config->conf&CONF_FAILONERROR);
4589
my_setopt(curl, CURLOPT_FAILONERROR, config->failonerror);
4427
4590
my_setopt(curl, CURLOPT_UPLOAD, uploadfile?TRUE:FALSE);
4428
my_setopt(curl, CURLOPT_DIRLISTONLY,
4429
config->conf&CONF_DIRLISTONLY);
4430
my_setopt(curl, CURLOPT_APPEND, config->conf&CONF_FTPAPPEND);
4591
my_setopt(curl, CURLOPT_DIRLISTONLY, config->dirlistonly);
4592
my_setopt(curl, CURLOPT_APPEND, config->ftp_append);
4432
if (config->conf&CONF_NETRC_OPT)
4594
if (config->netrc_opt)
4433
4595
my_setopt(curl, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
4434
else if (config->conf&CONF_NETRC)
4596
else if (config->netrc)
4435
4597
my_setopt(curl, CURLOPT_NETRC, CURL_NETRC_REQUIRED);
4437
4599
my_setopt(curl, CURLOPT_NETRC, CURL_NETRC_IGNORED);
4439
my_setopt(curl, CURLOPT_FOLLOWLOCATION,
4440
config->conf&CONF_FOLLOWLOCATION);
4441
my_setopt(curl, CURLOPT_UNRESTRICTED_AUTH,
4442
config->conf&CONF_UNRESTRICTED_AUTH);
4443
my_setopt(curl, CURLOPT_TRANSFERTEXT, config->conf&CONF_GETTEXT);
4601
my_setopt(curl, CURLOPT_FOLLOWLOCATION, config->followlocation);
4602
my_setopt(curl, CURLOPT_UNRESTRICTED_AUTH, config->unrestricted_auth);
4603
my_setopt(curl, CURLOPT_TRANSFERTEXT, config->use_ascii);
4444
4604
my_setopt(curl, CURLOPT_USERPWD, config->userpwd);
4445
4605
my_setopt(curl, CURLOPT_PROXYUSERPWD, config->proxyuserpwd);
4606
my_setopt(curl, CURLOPT_NOPROXY, config->noproxy);
4446
4607
my_setopt(curl, CURLOPT_RANGE, config->range);
4447
4608
my_setopt(curl, CURLOPT_ERRORBUFFER, errorbuffer);
4448
4609
my_setopt(curl, CURLOPT_TIMEOUT, config->timeout);
4461
4622
my_setopt(curl, CURLOPT_REFERER, config->referer);
4462
my_setopt(curl, CURLOPT_AUTOREFERER,
4463
config->conf&CONF_AUTO_REFERER);
4623
my_setopt(curl, CURLOPT_AUTOREFERER, config->autoreferer);
4464
4624
my_setopt(curl, CURLOPT_USERAGENT, config->useragent);
4465
4625
my_setopt(curl, CURLOPT_FTPPORT, config->ftpport);
4466
4626
my_setopt(curl, CURLOPT_LOW_SPEED_LIMIT,
4596
4754
/* new in curl 7.10 */
4597
4755
my_setopt(curl, CURLOPT_ENCODING,
4598
(config->encoding) ? "" : NULL);
4756
(config->encoding) ? "" : NULL);
4600
/* new in curl 7.10.7 */
4758
/* new in curl 7.10.7, extended in 7.19.4 but this only sets 0 or 1 */
4601
4759
my_setopt(curl, CURLOPT_FTP_CREATE_MISSING_DIRS,
4602
config->ftp_create_dirs);
4760
config->ftp_create_dirs);
4603
4761
if(config->proxyanyauth)
4604
4762
my_setopt(curl, CURLOPT_PROXYAUTH, CURLAUTH_ANY);
4605
4763
else if(config->proxynegotiate)
4645
4803
my_setopt(curl, CURLOPT_PROXYTYPE, config->socksver);
4806
#if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
4807
/* new in curl 7.19.4 */
4808
if(config->socks5_gssapi_service)
4809
my_setopt(curl, CURLOPT_SOCKS5_GSSAPI_SERVICE,
4810
config->socks5_gssapi_service);
4812
/* new in curl 7.19.4 */
4813
if(config->socks5_gssapi_nec)
4814
my_setopt(curl, CURLOPT_SOCKS5_GSSAPI_NEC, config->socks5_gssapi_nec);
4648
4816
/* curl 7.13.0 */
4649
4817
my_setopt(curl, CURLOPT_FTP_ACCOUNT, config->ftp_account);
4680
4848
/* curl 7.17.1 */
4681
my_setopt(curl, CURLOPT_POST301, config->post301);
4682
4849
if (!config->nokeepalive) {
4683
4850
my_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockoptcallback);
4684
4851
my_setopt(curl, CURLOPT_SOCKOPTDATA, config);
4854
/* curl 7.19.1 (the 301 version existed in 7.18.2) */
4855
my_setopt(curl, CURLOPT_POSTREDIR, config->post301 |
4856
(config->post302 ? CURL_REDIR_POST_302 : FALSE));
4687
4858
retry_numretries = config->req_retry;
4689
4860
retrystart = cutil_tvnow();
4829
4995
if((res!=CURLE_OK) && config->showerror) {
4830
fprintf(config->errors, "curl: (%d) %s\n", (int)res,
4996
fprintf(config->errors, "curl: (%d) %s\n", res,
4831
4997
errorbuffer[0]? errorbuffer:
4832
4998
curl_easy_strerror((CURLcode)res));
4833
4999
if(CURLE_SSL_CACERT == res) {
4834
5000
#define CURL_CA_CERT_ERRORMSG1 \
4835
5001
"More details here: http://curl.haxx.se/docs/sslcerts.html\n\n" \
4836
5002
"curl performs SSL certificate verification by default, using a \"bundle\"\n" \
4837
" of Certificate Authority (CA) public keys (CA certs). The default\n" \
4838
" bundle is named curl-ca-bundle.crt; you can specify an alternate file\n" \
5003
" of Certificate Authority (CA) public keys (CA certs). If the default\n" \
5004
" bundle file isn't adequate, you can specify an alternate file\n" \
4839
5005
" using the --cacert option.\n"
4841
5007
#define CURL_CA_CERT_ERRORMSG2 \
5163
5341
/* The following functions are taken with modification from the DJGPP
5164
5342
* port of tar 1.12. They use algorithms originally from DJTAR. */
5167
5345
msdosify (const char *file_name)
5169
5347
static char dos_name[PATH_MAX];
5170
static const char illegal_chars_dos[] = ".+, ;=[]|<>\\\":?*";
5348
static const char illegal_chars_dos[] = ".+, ;=[]" /* illegal in DOS */
5349
"|<>\\\":?*"; /* illegal in DOS & W95 */
5171
5350
static const char *illegal_chars_w95 = &illegal_chars_dos[8];
5172
5351
int idx, dot_idx;
5173
5352
const char *s = file_name;
5174
5353
char *d = dos_name;
5354
const char * const dlimit = dos_name + sizeof(dos_name) - 1;
5175
5355
const char *illegal_aliens = illegal_chars_dos;
5176
5356
size_t len = sizeof (illegal_chars_dos) - 1;