30 #elif defined(HAVE_SYS_UTIME_H) 31 # include <sys/utime.h> 44 #define ENABLE_CURLX_PRINTF 87 #define CURLseparator "--_curl_--" 95 #define CURL_CA_CERT_ERRORMSG \ 96 "More details here: https://curl.haxx.se/docs/sslcerts.html\n\n" \ 97 "curl failed to verify the legitimacy of the server and therefore " \ 98 "could not\nestablish a secure connection to it. To learn more about " \ 99 "this situation and\nhow to fix it, please visit the web page mentioned " \ 141 file = fopen(
name,
"r");
147 while(ret_stat > 0) {
148 ret_stat =
fread(buffer, 1,
sizeof(buffer), file);
166 switch(stat_buf->st_fab_rfm) {
169 return vms_realfilesize(
name, stat_buf);
172 return stat_buf->st_size;
177 #if defined(HAVE_UTIME) || \ 178 (defined(WIN32) && (SIZEOF_CURL_OFF_T >= 8)) 179 static void setfiletime(
long filetime,
const char *
filename,
186 #if defined(WIN32) && (SIZEOF_CURL_OFF_T >= 8) 189 #if (SIZEOF_LONG >= 8) 194 "Failed to set filetime %ld on outfile: overflow\n",
200 hfile = CreateFileA(
filename, FILE_WRITE_ATTRIBUTES,
201 (FILE_SHARE_READ | FILE_SHARE_WRITE |
203 NULL, OPEN_EXISTING, 0, NULL);
204 if(hfile != INVALID_HANDLE_VALUE) {
208 ft.dwLowDateTime = (DWORD)(converted & 0xFFFFFFFF);
209 ft.dwHighDateTime = (DWORD)(converted >> 32);
210 if(!SetFileTime(hfile, NULL, &ft, &ft)) {
212 "Failed to set filetime %ld on outfile: " 213 "SetFileTime failed: GetLastError %u\n",
214 filetime, GetLastError());
220 "Failed to set filetime %ld on outfile: " 221 "CreateFile failed: GetLastError %u\n",
222 filetime, GetLastError());
225 #elif defined(HAVE_UTIMES) 231 "Failed to set filetime %ld on outfile: errno %d\n",
235 #elif defined(HAVE_UTIME) 236 struct utimbuf times;
237 times.actime = (time_t)filetime;
238 times.modtime = (time_t)filetime;
241 "Failed to set filetime %ld on outfile: errno %d\n",
250 #define BUFFER_SIZE (100*1024) 265 char *httpgetfields = NULL;
269 bool capath_from_env;
273 bool orig_isatty = global->
isatty;
275 errorbuffer[0] =
'\0';
278 memset(&hdrcbdata, 0,
sizeof(
struct HdrCbData));
279 memset(&heads, 0,
sizeof(
struct OutStruct));
305 capath_from_env =
false;
330 capath_from_env =
true;
350 result = FindWin32CACert(config,
"curl-ca-bundle.crt");
386 FILE *newfile = fopen(config->
headerfile,
"wb");
411 for(urlnode = config->
url_list; urlnode; urlnode = urlnode->
next) {
416 unsigned long infilenum;
429 if(mlfile_last == NULL) {
432 mlfile = mlfile_last;
433 mlfile_last = mlfile_last->
next;
462 infiles = urlnode->
infile;
464 if(!config->
globoff && infiles) {
466 result =
glob_url(&inglob, infiles, &infilenum,
476 for(up = 0 ; up < infilenum; up++) {
481 unsigned long urlnum;
496 uploadfile =
strdup(infiles);
528 separator = ((!outfiles || !strcmp(outfiles,
"-")) && urlnum > 1);
531 for(li = 0 ; li < urlnum; li++) {
540 long retry_numretries;
541 long retry_sleep_default;
543 char *this_url = NULL;
544 int metalink_next_res = 0;
552 memset(&outs, 0,
sizeof(
struct OutStruct));
589 outfile =
strdup(outfiles);
598 (outfile && strcmp(
"-", outfile))) &&
612 helpf(global->
errors,
"Remote file name has no length!\n");
619 char *storefile = outfile;
653 if(0 ==
stat(outfile, &fileinfo))
665 FILE *file = fopen(outfile, config->
resume_from?
"ab":
"wb",
666 "ctx=stm",
"rfm=stmlf",
"rat=cr",
"mrs=0");
669 FILE *file = fopen(outfile, config->
resume_from?
"ab":
"wb");
672 helpf(global->
errors,
"Can't open '%s'!\n", outfile);
715 if(
stat(uploadfile, &fileinfo) == 0) {
716 fileinfo.st_size = VmsSpecialSize(uploadfile, &fileinfo);
717 switch(fileinfo.st_fab_rfm) {
721 infd = open(uploadfile, O_RDONLY |
O_BINARY);
724 infd = open(uploadfile, O_RDONLY |
O_BINARY,
725 "rfm=stmlf",
"ctx=stm");
730 infd = open(uploadfile, O_RDONLY |
O_BINARY);
731 if((infd == -1) || fstat(infd, &fileinfo))
734 helpf(global->
errors,
"Can't open '%s'!\n", uploadfile);
745 if(S_ISREG(fileinfo.st_mode))
746 uploadfilesize = fileinfo.st_size;
754 while(bitcheck < 32) {
755 if(config->
authtype & (1UL << bitcheck++)) {
770 "Using --anyauth or --proxy-anyauth with upload from stdin" 771 " involves a big risk of it not working. Use a temporary" 772 " file or a fixed auth type instead!\n");
779 if(!strcmp(uploadfile,
".")) {
782 "fcntl failed on fd=%d: %s\n", infd, strerror(errno));
798 global->
isatty = orig_isatty;
801 if(urlnum > 1 && !global->
mute) {
803 li + 1, urlnum, this_url, outfile ? outfile :
"<stdout>");
810 const char *pc = strstr(this_url,
"://");
817 pc = strrchr(pc,
'/');
831 urlbuffer =
aprintf(
"%s%c%s", this_url, sep, httpgetfields);
836 urlbuffer =
aprintf(
"%s/?%s", this_url, httpgetfields);
844 this_url = urlbuffer;
850 if((!outfile || !strcmp(outfile,
"-")) && !config->
use_ascii) {
860 my_setopt(curl, CURLOPT_TCP_NODELAY, 0L);
863 my_setopt(curl, CURLOPT_TCP_FASTOPEN, 1L);
866 my_setopt(curl, CURLOPT_WRITEDATA, &outs);
867 my_setopt(curl, CURLOPT_INTERLEAVEDATA, &outs);
875 my_setopt(curl, CURLOPT_WRITEFUNCTION, metalink_write_cb);
888 my_setopt(curl, CURLOPT_READDATA, &input);
894 my_setopt(curl, CURLOPT_SEEKDATA, &input);
905 if(uploadfilesize != -1)
906 my_setopt(curl, CURLOPT_INFILESIZE_LARGE, uploadfilesize);
922 #if !defined(CURL_DISABLE_PROXY) 960 my_setopt(curl, CURLOPT_SUPPRESS_CONNECT_HEADERS,
967 my_setopt(curl, CURLOPT_UPLOAD, uploadfile?1L:0L);
986 my_setopt(curl, CURLOPT_ERRORBUFFER, errorbuffer);
993 my_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE,
1020 my_setopt(curl, CURLOPT_UNRESTRICTED_AUTH,
1048 my_setopt(curl, CURLOPT_POSTREDIR, postRedir);
1056 my_setopt(curl, CURLOPT_TRANSFER_ENCODING, 1L);
1061 my_setopt(curl, CURLOPT_LOW_SPEED_LIMIT,
1064 my_setopt(curl, CURLOPT_MAX_SEND_SPEED_LARGE,
1066 my_setopt(curl, CURLOPT_MAX_RECV_SPEED_LARGE,
1092 my_setopt(curl, CURLOPT_SSH_COMPRESSION, 1L);
1103 warnf(config->
global,
"ignoring %s, not supported by libcurl\n",
1105 "SSL_CERT_DIR environment variable":
"--capath");
1120 "ignoring --proxy-capath, not supported by libcurl\n");
1150 my_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
1151 my_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
1154 my_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
1159 my_setopt(curl, CURLOPT_PROXY_SSL_VERIFYPEER, 0L);
1160 my_setopt(curl, CURLOPT_PROXY_SSL_VERIFYHOST, 0L);
1163 my_setopt(curl, CURLOPT_PROXY_SSL_VERIFYPEER, 1L);
1167 my_setopt(curl, CURLOPT_SSL_VERIFYSTATUS, 1L);
1170 my_setopt(curl, CURLOPT_SSL_FALSESTART, 1L);
1178 my_setopt(curl, CURLOPT_PATH_AS_IS, 1L);
1213 #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES) 1228 warnf(config->
global,
"cookie option(s) used even though cookie " 1229 "support is disabled!\n");
1271 my_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS,
1284 my_setopt(curl, CURLOPT_FTP_USE_EPSV, 0L);
1289 my_setopt(curl, CURLOPT_FTP_USE_EPRT, 0L);
1293 my_setopt(curl, CURLOPT_DEBUGDATA, config);
1306 my_setopt(curl, CURLOPT_FTP_CREATE_MISSING_DIRS,
1313 my_setopt(curl, CURLOPT_MAXFILESIZE_LARGE,
1385 my_setopt(curl, CURLOPT_SSL_SESSIONID_CACHE, 0L);
1389 my_setopt(curl, CURLOPT_HTTP_CONTENT_DECODING, 0L);
1390 my_setopt(curl, CURLOPT_HTTP_TRANSFER_DECODING, 0L);
1395 my_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L);
1402 my_setopt(curl, CURLOPT_TCP_KEEPALIVE, 0L);
1416 my_setopt(curl, CURLOPT_FTP_USE_PRET, 1L);
1429 hdrcbdata.
outs = &outs;
1430 hdrcbdata.
heads = &heads;
1433 my_setopt(curl, CURLOPT_HEADERDATA, &hdrcbdata);
1479 my_setopt(curl, CURLOPT_PROXY_SSL_OPTIONS,
1490 my_setopt(curl, CURLOPT_SSL_ENABLE_NPN, 0L);
1494 my_setopt(curl, CURLOPT_SSL_ENABLE_ALPN, 0L);
1519 my_setopt(curl, CURLOPT_TFTP_NO_OPTIONS, 1L);
1526 retry_sleep = retry_sleep_default;
1527 retrystart =
tvnow();
1529 #ifndef CURL_DISABLE_LIBCURL_OPTION 1541 if(outs.metalink_parser)
1542 metalink_parser_context_delete(outs.metalink_parser);
1543 outs.metalink_parser = metalink_parser_context_new();
1544 if(outs.metalink_parser == NULL) {
1549 "Metalink: parsing (%s) metalink/XML...\n", this_url);
1553 "Metalink: fetching (%s) from (%s)...\n",
1558 if(config->test_event_based)
1559 result = curl_easy_perform_ev(curl);
1568 long cond_unmet = 0L;
1582 if(retry_numretries &&
1600 retry = RETRY_TIMEOUT;
1605 if(ECONNREFUSED == oserrno)
1606 retry = RETRY_CONNREFUSED;
1614 char *effective_url = NULL;
1644 if(response/100 == 4)
1654 static const char *
const m[]={
1657 "connection refused",
1663 "Will retry in %ld seconds. " 1664 "%ld retries left.\n",
1665 m[retry], retry_sleep/1000L, retry_numretries);
1684 #ifdef HAVE_FTRUNCATE 1690 "failed to truncate, exiting\n");
1696 rc = fseek(outs.
stream, 0, SEEK_END);
1702 rc = fseek(outs.
stream, (
long)outs.
init, SEEK_SET);
1707 "failed seeking to end of file, exiting\n");
1724 char *effective_url = NULL;
1730 if(response != 200 && response != 206) {
1731 metalink_next_res = 1;
1733 "Metalink: fetching (%s) from (%s) FAILED " 1734 "(HTTP status code %ld)\n",
1735 mlfile->
filename, this_url, response);
1740 metalink_next_res = 1;
1742 "Metalink: fetching (%s) from (%s) FAILED (%s)\n",
1748 if(metalink && !metalink_next_res)
1749 fprintf(global->
errors,
"Metalink: fetching (%s) from (%s) OK\n",
1761 fputs(
"\n", progressbar.
out);
1776 if(is_vms_shell()) {
1779 vms_show = VMSSTS_HIDE;
1787 fprintf(global->
errors,
"curl: (%d) %s\n", result, (errorbuffer[0]) ?
1812 warnf(config->
global,
"Error setting extended attributes: %s\n",
1822 fprintf(global->
errors,
"(%d) Failed writing body\n", result);
1831 fprintf(global->
errors,
"(%d) Failed writing body\n", result);
1838 if(strlen(url) > 78)
1844 #if defined(HAVE_UTIME) || \ 1845 (defined(WIN32) && (SIZEOF_CURL_OFF_T >= 8)) 1859 int rv = parse_metalink(config, &outs, this_url);
1867 else if(metalink && result ==
CURLE_OK && !metalink_next_res) {
1868 int rv = metalink_check_hash(global, mlfile, outs.
filename);
1870 metalink_next_res = 1;
1879 if(outs.metalink_parser)
1880 metalink_parser_context_delete(outs.metalink_parser);
1882 memset(&outs, 0,
sizeof(
struct OutStruct));
1883 hdrcbdata.
outs = NULL;
1898 if(!metalink_next_res)
1900 mlres = mlres->
next;
1973 global->
isatty = orig_isatty;
1981 hdrcbdata.
heads = NULL;
2001 #ifdef HAVE_SETLOCALE 2002 setlocale(LC_ALL,
"");
2042 #ifndef CURL_DISABLE_LIBCURL_OPTION 2055 while(!result && operation) {
2056 result =
get_args(operation, count++);
2058 operation = operation->
next;
2065 while(!result && config->
current) {
2074 #ifndef CURL_DISABLE_LIBCURL_OPTION
#define CURL_IPRESOLVE_V6
static struct timeval tvnow(void)
struct curl_slist * quote
CURL_EXTERN void curl_free(void *p)
static long tvdiff(struct timeval newer, struct timeval older)
CURL_EXTERN void curl_easy_reset(CURL *curl)
#define CURL_IPRESOLVE_WHATEVER
struct curl_slist * telnet_options
int stat(const char *path, struct stat *buffer)
#define RETRY_SLEEP_DEFAULT
char * proxy_service_name
struct curl_slist * headers
#define CURL_IPRESOLVE_V4
#define CURLSSLOPT_NO_REVOKE
struct curl_slist * prequote
struct OperationConfig * config
#define CURLAUTH_GSSNEGOTIATE
#define CURL_VERSION_TLSAUTH_SRP
struct curl_slist * connect_to
struct GlobalConfig * global
#define CURLOPT_XFERINFODATA
UNITTEST_START int result
metalinkfile * metalinkfile_list
char * ftp_alternative_to_user
int curlx_nonblock(curl_socket_t sockfd, int nonblock)
curl_error synthetic_error
struct curl_slist * resolve
#define CURL_REDIR_POST_301
#define CURL_OFF_T_C(Val)
char * proxy_tls_password
#define curl_easy_getinfo(handle, info, arg)
struct OperationConfig * current
bool abstract_unix_socket
#define CURLHEADER_SEPARATE
CURL_TYPEOF_CURL_OFF_T curl_off_t
struct OperationConfig * config
struct OperationConfig * next
CURL_EXTERN int curl_strequal(const char *s1, const char *s2)
bool proxy_ssl_allow_beast
struct curl_slist * postquote
#define Curl_safefree(ptr)
char * proxy_tls_authtype
#define CURL_REDIR_POST_302
struct curl_slist * proxyheaders
static const char * urls[]
unsigned long socks5_auth
#define CURL_REDIR_POST_303
#define checkprefix(a, b)
static CURL * easy[MAX_EASY_HANDLES]
CURL_EXTERN const char * curl_easy_strerror(CURLcode)
#define CURLSSLOPT_ALLOW_BEAST
bool suppress_connect_headers
CURL_EXTERN int curl_strnequal(const char *s1, const char *s2, size_t n)
CURL_EXTERN CURLcode curl_easy_perform(CURL *curl)
struct OperationConfig * first
char * proxy_tls_username
#define CURL_VERSION_HTTP2
struct curl_slist * mail_rcpt
#define CURL_FORMAT_CURL_OFF_T