2011-10-04 18:03:20 -04:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2020-12-31 04:11:49 -05:00
|
|
|
* Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2011-10-04 18:03:20 -04:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2020-11-04 08:02:01 -05:00
|
|
|
* are also available at https://curl.se/docs/copyright.html.
|
2011-10-04 18:03:20 -04:00
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
2012-04-06 17:35:15 -04:00
|
|
|
#include "tool_setup.h"
|
2011-10-04 18:03:20 -04:00
|
|
|
|
|
|
|
#ifdef HAVE_FCNTL_H
|
|
|
|
# include <fcntl.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_LOCALE_H
|
|
|
|
# include <locale.h>
|
|
|
|
#endif
|
|
|
|
|
2019-08-28 12:11:47 -04:00
|
|
|
#ifdef HAVE_SYS_SELECT_H
|
|
|
|
# include <sys/select.h>
|
2020-03-30 09:52:43 -04:00
|
|
|
#elif defined(HAVE_UNISTD_H)
|
|
|
|
# include <unistd.h>
|
2019-08-28 12:11:47 -04:00
|
|
|
#endif
|
|
|
|
|
2013-07-29 10:03:46 -04:00
|
|
|
#ifdef __VMS
|
|
|
|
# include <fabdef.h>
|
|
|
|
#endif
|
|
|
|
|
2019-03-10 12:13:40 -04:00
|
|
|
#ifdef __AMIGA__
|
|
|
|
# include <proto/dos.h>
|
|
|
|
#endif
|
|
|
|
|
2016-09-30 12:54:02 -04:00
|
|
|
#include "strcase.h"
|
2011-10-04 18:03:20 -04:00
|
|
|
|
|
|
|
#define ENABLE_CURLX_PRINTF
|
|
|
|
/* use our own printf() functions */
|
|
|
|
#include "curlx.h"
|
|
|
|
|
|
|
|
#include "tool_binmode.h"
|
|
|
|
#include "tool_cfgable.h"
|
|
|
|
#include "tool_cb_dbg.h"
|
|
|
|
#include "tool_cb_hdr.h"
|
|
|
|
#include "tool_cb_prg.h"
|
|
|
|
#include "tool_cb_rea.h"
|
|
|
|
#include "tool_cb_see.h"
|
|
|
|
#include "tool_cb_wrt.h"
|
|
|
|
#include "tool_dirhie.h"
|
2011-10-04 19:19:58 -04:00
|
|
|
#include "tool_doswin.h"
|
2011-10-04 18:03:20 -04:00
|
|
|
#include "tool_easysrc.h"
|
2018-02-05 15:57:39 -05:00
|
|
|
#include "tool_filetime.h"
|
2011-10-04 18:03:20 -04:00
|
|
|
#include "tool_getparam.h"
|
|
|
|
#include "tool_helpers.h"
|
2011-10-06 11:39:00 -04:00
|
|
|
#include "tool_homedir.h"
|
2011-10-04 18:03:20 -04:00
|
|
|
#include "tool_libinfo.h"
|
|
|
|
#include "tool_main.h"
|
|
|
|
#include "tool_msgs.h"
|
|
|
|
#include "tool_operate.h"
|
|
|
|
#include "tool_operhlp.h"
|
2013-08-27 11:39:16 -04:00
|
|
|
#include "tool_paramhlp.h"
|
2011-10-04 18:03:20 -04:00
|
|
|
#include "tool_parsecfg.h"
|
|
|
|
#include "tool_setopt.h"
|
|
|
|
#include "tool_sleep.h"
|
2011-10-05 14:16:16 -04:00
|
|
|
#include "tool_urlglob.h"
|
2011-10-06 11:39:00 -04:00
|
|
|
#include "tool_util.h"
|
|
|
|
#include "tool_writeout.h"
|
|
|
|
#include "tool_xattr.h"
|
2013-02-05 22:51:55 -05:00
|
|
|
#include "tool_vms.h"
|
2014-02-22 11:04:30 -05:00
|
|
|
#include "tool_help.h"
|
2014-02-23 05:37:44 -05:00
|
|
|
#include "tool_hugehelp.h"
|
2019-07-20 13:14:00 -04:00
|
|
|
#include "tool_progress.h"
|
2021-02-25 12:12:28 -05:00
|
|
|
#include "dynbuf.h"
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2013-01-03 20:50:28 -05:00
|
|
|
#include "memdebug.h" /* keep this as LAST include */
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2013-08-10 16:55:59 -04:00
|
|
|
#ifdef CURLDEBUG
|
|
|
|
/* libcurl's debug builds provide an extra function */
|
|
|
|
CURLcode curl_easy_perform_ev(CURL *easy);
|
|
|
|
#endif
|
|
|
|
|
2011-10-04 18:03:20 -04:00
|
|
|
#define CURLseparator "--_curl_--"
|
|
|
|
|
|
|
|
#ifndef O_BINARY
|
|
|
|
/* since O_BINARY as used in bitmasks, setting it to zero makes it usable in
|
|
|
|
source code but yet it doesn't ruin anything */
|
|
|
|
# define O_BINARY 0
|
|
|
|
#endif
|
|
|
|
|
2017-08-22 03:07:11 -04:00
|
|
|
#define CURL_CA_CERT_ERRORMSG \
|
2020-11-04 08:02:01 -05:00
|
|
|
"More details here: https://curl.se/docs/sslcerts.html\n\n" \
|
2017-08-22 03:07:11 -04:00
|
|
|
"curl failed to verify the legitimacy of the server and therefore " \
|
|
|
|
"could not\nestablish a secure connection to it. To learn more about " \
|
|
|
|
"this situation and\nhow to fix it, please visit the web page mentioned " \
|
|
|
|
"above.\n"
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2019-09-23 11:11:22 -04:00
|
|
|
static CURLcode single_transfer(struct GlobalConfig *global,
|
|
|
|
struct OperationConfig *config,
|
|
|
|
CURLSH *share,
|
|
|
|
bool capath_from_env,
|
|
|
|
bool *added);
|
2019-09-30 17:24:49 -04:00
|
|
|
static CURLcode create_transfer(struct GlobalConfig *global,
|
|
|
|
CURLSH *share,
|
|
|
|
bool *added);
|
2019-07-20 13:14:00 -04:00
|
|
|
|
2014-02-22 13:57:02 -05:00
|
|
|
static bool is_fatal_error(CURLcode code)
|
2012-02-07 16:06:03 -05:00
|
|
|
{
|
|
|
|
switch(code) {
|
|
|
|
case CURLE_FAILED_INIT:
|
|
|
|
case CURLE_OUT_OF_MEMORY:
|
|
|
|
case CURLE_UNKNOWN_OPTION:
|
|
|
|
case CURLE_FUNCTION_NOT_FOUND:
|
|
|
|
case CURLE_BAD_FUNCTION_ARGUMENT:
|
|
|
|
/* critical error */
|
2014-02-22 13:57:02 -05:00
|
|
|
return TRUE;
|
2012-02-07 16:06:03 -05:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-02-22 13:57:02 -05:00
|
|
|
|
2012-02-07 16:06:03 -05:00
|
|
|
/* no error or not critical */
|
2014-02-22 13:57:02 -05:00
|
|
|
return FALSE;
|
2012-02-07 16:06:03 -05:00
|
|
|
}
|
|
|
|
|
2018-02-19 08:31:06 -05:00
|
|
|
/*
|
|
|
|
* Check if a given string is a PKCS#11 URI
|
|
|
|
*/
|
|
|
|
static bool is_pkcs11_uri(const char *string)
|
|
|
|
{
|
|
|
|
if(curl_strnequal(string, "pkcs11:", 7)) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-22 16:15:27 -04:00
|
|
|
#ifdef __VMS
|
|
|
|
/*
|
|
|
|
* get_vms_file_size does what it takes to get the real size of the file
|
|
|
|
*
|
|
|
|
* For fixed files, find out the size of the EOF block and adjust.
|
|
|
|
*
|
|
|
|
* For all others, have to read the entire file in, discarding the contents.
|
|
|
|
* Most posted text files will be small, and binary files like zlib archives
|
|
|
|
* and CD/DVD images should be either a STREAM_LF format or a fixed format.
|
|
|
|
*
|
|
|
|
*/
|
2016-11-23 01:53:24 -05:00
|
|
|
static curl_off_t vms_realfilesize(const char *name,
|
|
|
|
const struct_stat *stat_buf)
|
2013-07-22 16:15:27 -04:00
|
|
|
{
|
|
|
|
char buffer[8192];
|
|
|
|
curl_off_t count;
|
|
|
|
int ret_stat;
|
|
|
|
FILE * file;
|
|
|
|
|
2016-04-19 02:42:55 -04:00
|
|
|
/* !checksrc! disable FOPENMODE 1 */
|
2015-06-02 02:28:10 -04:00
|
|
|
file = fopen(name, "r"); /* VMS */
|
2021-04-19 04:46:11 -04:00
|
|
|
if(!file) {
|
2013-07-22 16:15:27 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
count = 0;
|
|
|
|
ret_stat = 1;
|
|
|
|
while(ret_stat > 0) {
|
|
|
|
ret_stat = fread(buffer, 1, sizeof(buffer), file);
|
2021-04-19 04:46:11 -04:00
|
|
|
if(ret_stat)
|
2013-07-22 16:15:27 -04:00
|
|
|
count += ret_stat;
|
|
|
|
}
|
|
|
|
fclose(file);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* VmsSpecialSize checks to see if the stat st_size can be trusted and
|
|
|
|
* if not to call a routine to get the correct size.
|
|
|
|
*
|
|
|
|
*/
|
2016-11-23 01:53:24 -05:00
|
|
|
static curl_off_t VmsSpecialSize(const char *name,
|
|
|
|
const struct_stat *stat_buf)
|
2013-07-22 16:15:27 -04:00
|
|
|
{
|
|
|
|
switch(stat_buf->st_fab_rfm) {
|
|
|
|
case FAB$C_VAR:
|
|
|
|
case FAB$C_VFC:
|
|
|
|
return vms_realfilesize(name, stat_buf);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return stat_buf->st_size;
|
|
|
|
}
|
|
|
|
}
|
2013-07-29 10:32:29 -04:00
|
|
|
#endif /* __VMS */
|
2013-07-22 16:15:27 -04:00
|
|
|
|
2017-04-24 06:03:08 -04:00
|
|
|
#define BUFFER_SIZE (100*1024)
|
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
struct per_transfer *transfers; /* first node */
|
|
|
|
static struct per_transfer *transfersl; /* last node */
|
|
|
|
|
2019-09-30 17:24:49 -04:00
|
|
|
/* add_per_transfer creates a new 'per_transfer' node in the linked
|
|
|
|
list of transfers */
|
|
|
|
static CURLcode add_per_transfer(struct per_transfer **per)
|
2011-10-04 18:03:20 -04:00
|
|
|
{
|
2019-07-20 13:14:00 -04:00
|
|
|
struct per_transfer *p;
|
|
|
|
p = calloc(sizeof(struct per_transfer), 1);
|
|
|
|
if(!p)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
if(!transfers)
|
|
|
|
/* first entry */
|
|
|
|
transfersl = transfers = p;
|
|
|
|
else {
|
|
|
|
/* make the last node point to the new node */
|
|
|
|
transfersl->next = p;
|
|
|
|
/* make the new node point back to the formerly last node */
|
|
|
|
p->prev = transfersl;
|
|
|
|
/* move the last node pointer to the new entry */
|
|
|
|
transfersl = p;
|
|
|
|
}
|
|
|
|
*per = p;
|
|
|
|
all_xfers++; /* count total number of transfers added */
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
/* Remove the specified transfer from the list (and free it), return the next
|
|
|
|
in line */
|
2019-09-30 17:24:49 -04:00
|
|
|
static struct per_transfer *del_per_transfer(struct per_transfer *per)
|
2019-07-20 13:14:00 -04:00
|
|
|
{
|
|
|
|
struct per_transfer *n;
|
|
|
|
struct per_transfer *p;
|
|
|
|
DEBUGASSERT(transfers);
|
|
|
|
DEBUGASSERT(transfersl);
|
|
|
|
DEBUGASSERT(per);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
n = per->next;
|
|
|
|
p = per->prev;
|
2012-04-28 09:53:34 -04:00
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
if(p)
|
|
|
|
p->next = n;
|
|
|
|
else
|
|
|
|
transfers = n;
|
|
|
|
|
|
|
|
if(n)
|
|
|
|
n->prev = p;
|
|
|
|
else
|
|
|
|
transfersl = p;
|
|
|
|
|
|
|
|
free(per);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CURLcode pre_transfer(struct GlobalConfig *global,
|
|
|
|
struct per_transfer *per)
|
|
|
|
{
|
|
|
|
curl_off_t uploadfilesize = -1;
|
|
|
|
struct_stat fileinfo;
|
2014-12-16 02:35:47 -05:00
|
|
|
CURLcode result = CURLE_OK;
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
if(per->separator_err)
|
|
|
|
fprintf(global->errors, "%s\n", per->separator_err);
|
|
|
|
if(per->separator)
|
|
|
|
printf("%s\n", per->separator);
|
2012-06-20 12:00:53 -04:00
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
if(per->uploadfile && !stdin_upload(per->uploadfile)) {
|
|
|
|
/* VMS Note:
|
|
|
|
*
|
|
|
|
* Reading binary from files can be a problem... Only FIXED, VAR
|
|
|
|
* etc WITHOUT implied CC will work Others need a \n appended to a
|
|
|
|
* line
|
|
|
|
*
|
|
|
|
* - Stat gives a size but this is UNRELIABLE in VMS As a f.e. a
|
|
|
|
* fixed file with implied CC needs to have a byte added for every
|
|
|
|
* record processed, this can by derived from Filesize & recordsize
|
|
|
|
* for VARiable record files the records need to be counted! for
|
|
|
|
* every record add 1 for linefeed and subtract 2 for the record
|
|
|
|
* header for VARIABLE header files only the bare record data needs
|
|
|
|
* to be considered with one appended if implied CC
|
|
|
|
*/
|
|
|
|
#ifdef __VMS
|
|
|
|
/* Calculate the real upload size for VMS */
|
|
|
|
per->infd = -1;
|
|
|
|
if(stat(per->uploadfile, &fileinfo) == 0) {
|
|
|
|
fileinfo.st_size = VmsSpecialSize(uploadfile, &fileinfo);
|
|
|
|
switch(fileinfo.st_fab_rfm) {
|
|
|
|
case FAB$C_VAR:
|
|
|
|
case FAB$C_VFC:
|
|
|
|
case FAB$C_STMCR:
|
|
|
|
per->infd = open(per->uploadfile, O_RDONLY | O_BINARY);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
per->infd = open(per->uploadfile, O_RDONLY | O_BINARY,
|
|
|
|
"rfm=stmlf", "ctx=stm");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(per->infd == -1)
|
|
|
|
#else
|
|
|
|
per->infd = open(per->uploadfile, O_RDONLY | O_BINARY);
|
|
|
|
if((per->infd == -1) || fstat(per->infd, &fileinfo))
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
helpf(global->errors, "Can't open '%s'!\n", per->uploadfile);
|
|
|
|
if(per->infd != -1) {
|
|
|
|
close(per->infd);
|
|
|
|
per->infd = STDIN_FILENO;
|
|
|
|
}
|
|
|
|
return CURLE_READ_ERROR;
|
|
|
|
}
|
|
|
|
per->infdopen = TRUE;
|
2014-02-27 15:21:23 -05:00
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
/* we ignore file size for char/block devices, sockets, etc. */
|
|
|
|
if(S_ISREG(fileinfo.st_mode))
|
|
|
|
uploadfilesize = fileinfo.st_size;
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2020-10-01 16:59:30 -04:00
|
|
|
if(uploadfilesize != -1) {
|
|
|
|
struct OperationConfig *config = per->config; /* for the macro below */
|
2020-10-15 16:57:27 -04:00
|
|
|
#ifdef CURL_DISABLE_LIBCURL_OPTION
|
|
|
|
(void)config;
|
|
|
|
#endif
|
2019-07-20 13:14:00 -04:00
|
|
|
my_setopt(per->curl, CURLOPT_INFILESIZE_LARGE, uploadfilesize);
|
2020-10-01 16:59:30 -04:00
|
|
|
}
|
2019-07-20 13:14:00 -04:00
|
|
|
per->input.fd = per->infd;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
/*
|
|
|
|
* Call this after a transfer has completed.
|
|
|
|
*/
|
2019-09-30 17:24:49 -04:00
|
|
|
static CURLcode post_per_transfer(struct GlobalConfig *global,
|
|
|
|
struct per_transfer *per,
|
|
|
|
CURLcode result,
|
2020-09-05 11:44:24 -04:00
|
|
|
bool *retryp,
|
|
|
|
long *delay) /* milliseconds! */
|
2019-07-20 13:14:00 -04:00
|
|
|
{
|
|
|
|
struct OutStruct *outs = &per->outs;
|
|
|
|
CURL *curl = per->curl;
|
|
|
|
struct OperationConfig *config = per->config;
|
|
|
|
|
2019-09-23 11:11:22 -04:00
|
|
|
if(!curl || !config)
|
|
|
|
return result;
|
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
*retryp = FALSE;
|
2020-09-05 11:44:24 -04:00
|
|
|
*delay = 0; /* for no retry, keep it zero */
|
2019-07-20 13:14:00 -04:00
|
|
|
|
|
|
|
if(per->infdopen)
|
|
|
|
close(per->infd);
|
|
|
|
|
|
|
|
#ifdef __VMS
|
|
|
|
if(is_vms_shell()) {
|
|
|
|
/* VMS DCL shell behavior */
|
|
|
|
if(!global->showerror)
|
|
|
|
vms_show = VMSSTS_HIDE;
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
2019-07-20 13:14:00 -04:00
|
|
|
else
|
|
|
|
#endif
|
2020-12-26 09:43:25 -05:00
|
|
|
if(!config->synthetic_error && result && global->showerror) {
|
2019-07-20 13:14:00 -04:00
|
|
|
fprintf(global->errors, "curl: (%d) %s\n", result,
|
|
|
|
(per->errorbuffer[0]) ? per->errorbuffer :
|
|
|
|
curl_easy_strerror(result));
|
|
|
|
if(result == CURLE_PEER_FAILED_VERIFICATION)
|
|
|
|
fputs(CURL_CA_CERT_ERRORMSG, global->errors);
|
|
|
|
}
|
2021-02-11 02:30:39 -05:00
|
|
|
else if(config->failwithbody) {
|
|
|
|
/* if HTTP response >= 400, return error */
|
|
|
|
long code = 0;
|
|
|
|
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
|
|
|
|
if(code >= 400) {
|
|
|
|
if(global->showerror)
|
|
|
|
fprintf(global->errors,
|
|
|
|
"curl: (%d) The requested URL returned error: %ld\n",
|
|
|
|
CURLE_HTTP_RETURNED_ERROR, code);
|
|
|
|
result = CURLE_HTTP_RETURNED_ERROR;
|
|
|
|
}
|
|
|
|
}
|
2019-07-20 13:14:00 -04:00
|
|
|
/* Set file extended attributes */
|
|
|
|
if(!result && config->xattr && outs->fopened && outs->stream) {
|
|
|
|
int rc = fwrite_xattr(curl, fileno(outs->stream));
|
|
|
|
if(rc)
|
2021-01-26 11:02:39 -05:00
|
|
|
warnf(config->global, "Error setting extended attributes on '%s': %s\n",
|
|
|
|
outs->filename, strerror(errno));
|
2019-07-20 13:14:00 -04:00
|
|
|
}
|
schannel: add support for CURLOPT_CAINFO
- Move verify_certificate functionality in schannel.c into a new
file called schannel_verify.c. Additionally, some structure defintions
from schannel.c have been moved to schannel.h to allow them to be
used in schannel_verify.c.
- Make verify_certificate functionality for Schannel available on
all versions of Windows instead of just Windows CE. verify_certificate
will be invoked on Windows CE or when the user specifies
CURLOPT_CAINFO and CURLOPT_SSL_VERIFYPEER.
- In verify_certificate, create a custom certificate chain engine that
exclusively trusts the certificate store backed by the CURLOPT_CAINFO
file.
- doc updates of --cacert/CAINFO support for schannel
- Use CERT_NAME_SEARCH_ALL_NAMES_FLAG when invoking CertGetNameString
when available. This implements a TODO in schannel.c to improve
handling of multiple SANs in a certificate. In particular, all SANs
will now be searched instead of just the first name.
- Update tool_operate.c to not search for the curl-ca-bundle.crt file
when using Schannel to maintain backward compatibility. Previously,
any curl-ca-bundle.crt file found in that search would have been
ignored by Schannel. But, with CAINFO support, the file found by
that search would have been used as the certificate store and
could cause issues for any users that have curl-ca-bundle.crt in
the search path.
- Update url.c to not set the build time CURL_CA_BUNDLE if the selected
SSL backend is Schannel. We allow setting CA location for schannel
only when explicitly specified by the user via CURLOPT_CAINFO /
--cacert.
- Add new test cases 3000 and 3001. These test cases check that the first
and last SAN, respectively, matches the connection hostname. New test
certificates have been added for these cases. For 3000, the certificate
prefix is Server-localhost-firstSAN and for 3001, the certificate
prefix is Server-localhost-secondSAN.
- Remove TODO 15.2 (Add support for custom server certificate
validation), this commit addresses it.
Closes https://github.com/curl/curl/pull/1325
2017-03-10 15:27:30 -05:00
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
if(!result && !outs->stream && !outs->bytes) {
|
|
|
|
/* we have received no data despite the transfer was successful
|
2021-01-14 07:40:12 -05:00
|
|
|
==> force creation of an empty output file (if an output file
|
2019-07-20 13:14:00 -04:00
|
|
|
was specified) */
|
|
|
|
long cond_unmet = 0L;
|
|
|
|
/* do not create (or even overwrite) the file in case we get no
|
|
|
|
data because of unmet condition */
|
|
|
|
curl_easy_getinfo(curl, CURLINFO_CONDITION_UNMET, &cond_unmet);
|
2020-01-11 16:53:34 -05:00
|
|
|
if(!cond_unmet && !tool_create_output_file(outs, config))
|
2019-07-20 13:14:00 -04:00
|
|
|
result = CURLE_WRITE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!outs->s_isreg && outs->stream) {
|
|
|
|
/* Dump standard stream buffered data */
|
|
|
|
int rc = fflush(outs->stream);
|
|
|
|
if(!result && rc) {
|
|
|
|
/* something went wrong in the writing process */
|
|
|
|
result = CURLE_WRITE_ERROR;
|
2021-01-02 03:40:24 -05:00
|
|
|
if(global->showerror)
|
|
|
|
fprintf(global->errors, "curl: (%d) Failed writing body\n", result);
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
2019-07-20 13:14:00 -04:00
|
|
|
}
|
schannel: add support for CURLOPT_CAINFO
- Move verify_certificate functionality in schannel.c into a new
file called schannel_verify.c. Additionally, some structure defintions
from schannel.c have been moved to schannel.h to allow them to be
used in schannel_verify.c.
- Make verify_certificate functionality for Schannel available on
all versions of Windows instead of just Windows CE. verify_certificate
will be invoked on Windows CE or when the user specifies
CURLOPT_CAINFO and CURLOPT_SSL_VERIFYPEER.
- In verify_certificate, create a custom certificate chain engine that
exclusively trusts the certificate store backed by the CURLOPT_CAINFO
file.
- doc updates of --cacert/CAINFO support for schannel
- Use CERT_NAME_SEARCH_ALL_NAMES_FLAG when invoking CertGetNameString
when available. This implements a TODO in schannel.c to improve
handling of multiple SANs in a certificate. In particular, all SANs
will now be searched instead of just the first name.
- Update tool_operate.c to not search for the curl-ca-bundle.crt file
when using Schannel to maintain backward compatibility. Previously,
any curl-ca-bundle.crt file found in that search would have been
ignored by Schannel. But, with CAINFO support, the file found by
that search would have been used as the certificate store and
could cause issues for any users that have curl-ca-bundle.crt in
the search path.
- Update url.c to not set the build time CURL_CA_BUNDLE if the selected
SSL backend is Schannel. We allow setting CA location for schannel
only when explicitly specified by the user via CURLOPT_CAINFO /
--cacert.
- Add new test cases 3000 and 3001. These test cases check that the first
and last SAN, respectively, matches the connection hostname. New test
certificates have been added for these cases. For 3000, the certificate
prefix is Server-localhost-firstSAN and for 3001, the certificate
prefix is Server-localhost-secondSAN.
- Remove TODO 15.2 (Add support for custom server certificate
validation), this commit addresses it.
Closes https://github.com/curl/curl/pull/1325
2017-03-10 15:27:30 -05:00
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
/* if retry-max-time is non-zero, make sure we haven't exceeded the
|
|
|
|
time */
|
|
|
|
if(per->retry_numretries &&
|
|
|
|
(!config->retry_maxtime ||
|
|
|
|
(tvdiff(tvnow(), per->retrystart) <
|
|
|
|
config->retry_maxtime*1000L)) ) {
|
|
|
|
enum {
|
|
|
|
RETRY_NO,
|
2020-04-04 16:16:18 -04:00
|
|
|
RETRY_ALL_ERRORS,
|
2019-07-20 13:14:00 -04:00
|
|
|
RETRY_TIMEOUT,
|
|
|
|
RETRY_CONNREFUSED,
|
|
|
|
RETRY_HTTP,
|
|
|
|
RETRY_FTP,
|
|
|
|
RETRY_LAST /* not used */
|
|
|
|
} retry = RETRY_NO;
|
2020-05-18 11:59:47 -04:00
|
|
|
long response = 0;
|
2019-07-20 13:14:00 -04:00
|
|
|
if((CURLE_OPERATION_TIMEDOUT == result) ||
|
|
|
|
(CURLE_COULDNT_RESOLVE_HOST == result) ||
|
|
|
|
(CURLE_COULDNT_RESOLVE_PROXY == result) ||
|
|
|
|
(CURLE_FTP_ACCEPT_TIMEOUT == result))
|
|
|
|
/* retry timeout always */
|
|
|
|
retry = RETRY_TIMEOUT;
|
|
|
|
else if(config->retry_connrefused &&
|
|
|
|
(CURLE_COULDNT_CONNECT == result)) {
|
2020-05-18 11:59:47 -04:00
|
|
|
long oserrno = 0;
|
2019-07-20 13:14:00 -04:00
|
|
|
curl_easy_getinfo(curl, CURLINFO_OS_ERRNO, &oserrno);
|
|
|
|
if(ECONNREFUSED == oserrno)
|
|
|
|
retry = RETRY_CONNREFUSED;
|
|
|
|
}
|
|
|
|
else if((CURLE_OK == result) ||
|
|
|
|
(config->failonerror &&
|
|
|
|
(CURLE_HTTP_RETURNED_ERROR == result))) {
|
|
|
|
/* If it returned OK. _or_ failonerror was enabled and it
|
|
|
|
returned due to such an error, check for HTTP transient
|
|
|
|
errors to retry on. */
|
2020-05-18 11:59:47 -04:00
|
|
|
long protocol = 0;
|
2019-08-06 05:49:03 -04:00
|
|
|
curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);
|
|
|
|
if((protocol == CURLPROTO_HTTP) || (protocol == CURLPROTO_HTTPS)) {
|
2019-07-20 13:14:00 -04:00
|
|
|
/* This was HTTP(S) */
|
|
|
|
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response);
|
|
|
|
|
|
|
|
switch(response) {
|
2020-11-01 18:04:22 -05:00
|
|
|
case 408: /* Request Timeout */
|
2019-10-04 11:18:23 -04:00
|
|
|
case 429: /* Too Many Requests (RFC6585) */
|
2019-07-20 13:14:00 -04:00
|
|
|
case 500: /* Internal Server Error */
|
|
|
|
case 502: /* Bad Gateway */
|
|
|
|
case 503: /* Service Unavailable */
|
|
|
|
case 504: /* Gateway Timeout */
|
|
|
|
retry = RETRY_HTTP;
|
|
|
|
/*
|
|
|
|
* At this point, we have already written data to the output
|
|
|
|
* file (or terminal). If we write to a file, we must rewind
|
|
|
|
* or close/re-open the file so that the next attempt starts
|
|
|
|
* over from the beginning.
|
|
|
|
*
|
|
|
|
* TODO: similar action for the upload case. We might need
|
|
|
|
* to start over reading from a previous point if we have
|
|
|
|
* uploaded something when this was returned.
|
|
|
|
*/
|
|
|
|
break;
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
|
|
|
}
|
2019-07-20 13:14:00 -04:00
|
|
|
} /* if CURLE_OK */
|
|
|
|
else if(result) {
|
2020-05-18 11:59:47 -04:00
|
|
|
long protocol = 0;
|
2019-07-20 13:14:00 -04:00
|
|
|
|
|
|
|
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response);
|
|
|
|
curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);
|
|
|
|
|
|
|
|
if((protocol == CURLPROTO_FTP || protocol == CURLPROTO_FTPS) &&
|
|
|
|
response / 100 == 4)
|
|
|
|
/*
|
|
|
|
* This is typically when the FTP server only allows a certain
|
|
|
|
* amount of users and we are not one of them. All 4xx codes
|
|
|
|
* are transient.
|
|
|
|
*/
|
|
|
|
retry = RETRY_FTP;
|
|
|
|
}
|
|
|
|
|
2020-04-04 16:16:18 -04:00
|
|
|
if(result && !retry && config->retry_all_errors)
|
|
|
|
retry = RETRY_ALL_ERRORS;
|
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
if(retry) {
|
2019-08-06 05:57:02 -04:00
|
|
|
long sleeptime = 0;
|
|
|
|
curl_off_t retry_after = 0;
|
2019-07-20 13:14:00 -04:00
|
|
|
static const char * const m[]={
|
|
|
|
NULL,
|
2020-04-04 16:16:18 -04:00
|
|
|
"(retrying all errors)",
|
2020-09-05 09:46:55 -04:00
|
|
|
": timeout",
|
|
|
|
": connection refused",
|
|
|
|
": HTTP error",
|
|
|
|
": FTP error"
|
2019-07-20 13:14:00 -04:00
|
|
|
};
|
|
|
|
|
2019-08-06 05:57:02 -04:00
|
|
|
sleeptime = per->retry_sleep;
|
|
|
|
if(RETRY_HTTP == retry) {
|
|
|
|
curl_easy_getinfo(curl, CURLINFO_RETRY_AFTER, &retry_after);
|
|
|
|
if(retry_after) {
|
|
|
|
/* store in a 'long', make sure it doesn't overflow */
|
|
|
|
if(retry_after > LONG_MAX/1000)
|
|
|
|
sleeptime = LONG_MAX;
|
|
|
|
else
|
|
|
|
sleeptime = (long)retry_after * 1000; /* milliseconds */
|
|
|
|
}
|
|
|
|
}
|
2020-09-05 09:46:55 -04:00
|
|
|
warnf(config->global, "Problem %s. "
|
2019-07-20 13:14:00 -04:00
|
|
|
"Will retry in %ld seconds. "
|
|
|
|
"%ld retries left.\n",
|
2019-10-16 09:35:56 -04:00
|
|
|
m[retry], sleeptime/1000L, per->retry_numretries);
|
2019-07-20 13:14:00 -04:00
|
|
|
|
|
|
|
per->retry_numretries--;
|
|
|
|
if(!config->retry_delay) {
|
|
|
|
per->retry_sleep *= 2;
|
|
|
|
if(per->retry_sleep > RETRY_SLEEP_MAX)
|
|
|
|
per->retry_sleep = RETRY_SLEEP_MAX;
|
|
|
|
}
|
|
|
|
if(outs->bytes && outs->filename && outs->stream) {
|
|
|
|
int rc;
|
|
|
|
/* We have written data to a output file, we truncate file
|
|
|
|
*/
|
|
|
|
if(!global->mute)
|
|
|
|
fprintf(global->errors, "Throwing away %"
|
|
|
|
CURL_FORMAT_CURL_OFF_T " bytes\n",
|
|
|
|
outs->bytes);
|
|
|
|
fflush(outs->stream);
|
|
|
|
/* truncate file at the position where we started appending */
|
|
|
|
#ifdef HAVE_FTRUNCATE
|
|
|
|
if(ftruncate(fileno(outs->stream), outs->init)) {
|
|
|
|
/* when truncate fails, we can't just append as then we'll
|
|
|
|
create something strange, bail out */
|
2021-01-02 03:40:24 -05:00
|
|
|
if(global->showerror)
|
2019-07-20 13:14:00 -04:00
|
|
|
fprintf(global->errors,
|
2021-01-02 03:40:24 -05:00
|
|
|
"curl: (23) Failed to truncate file\n");
|
2019-07-20 13:14:00 -04:00
|
|
|
return CURLE_WRITE_ERROR;
|
schannel: add support for CURLOPT_CAINFO
- Move verify_certificate functionality in schannel.c into a new
file called schannel_verify.c. Additionally, some structure defintions
from schannel.c have been moved to schannel.h to allow them to be
used in schannel_verify.c.
- Make verify_certificate functionality for Schannel available on
all versions of Windows instead of just Windows CE. verify_certificate
will be invoked on Windows CE or when the user specifies
CURLOPT_CAINFO and CURLOPT_SSL_VERIFYPEER.
- In verify_certificate, create a custom certificate chain engine that
exclusively trusts the certificate store backed by the CURLOPT_CAINFO
file.
- doc updates of --cacert/CAINFO support for schannel
- Use CERT_NAME_SEARCH_ALL_NAMES_FLAG when invoking CertGetNameString
when available. This implements a TODO in schannel.c to improve
handling of multiple SANs in a certificate. In particular, all SANs
will now be searched instead of just the first name.
- Update tool_operate.c to not search for the curl-ca-bundle.crt file
when using Schannel to maintain backward compatibility. Previously,
any curl-ca-bundle.crt file found in that search would have been
ignored by Schannel. But, with CAINFO support, the file found by
that search would have been used as the certificate store and
could cause issues for any users that have curl-ca-bundle.crt in
the search path.
- Update url.c to not set the build time CURL_CA_BUNDLE if the selected
SSL backend is Schannel. We allow setting CA location for schannel
only when explicitly specified by the user via CURLOPT_CAINFO /
--cacert.
- Add new test cases 3000 and 3001. These test cases check that the first
and last SAN, respectively, matches the connection hostname. New test
certificates have been added for these cases. For 3000, the certificate
prefix is Server-localhost-firstSAN and for 3001, the certificate
prefix is Server-localhost-secondSAN.
- Remove TODO 15.2 (Add support for custom server certificate
validation), this commit addresses it.
Closes https://github.com/curl/curl/pull/1325
2017-03-10 15:27:30 -05:00
|
|
|
}
|
2019-07-20 13:14:00 -04:00
|
|
|
/* now seek to the end of the file, the position where we
|
|
|
|
just truncated the file in a large file-safe way */
|
|
|
|
rc = fseek(outs->stream, 0, SEEK_END);
|
|
|
|
#else
|
|
|
|
/* ftruncate is not available, so just reposition the file
|
|
|
|
to the location we would have truncated it. This won't
|
|
|
|
work properly with large files on 32-bit systems, but
|
|
|
|
most of those will have ftruncate. */
|
|
|
|
rc = fseek(outs->stream, (long)outs->init, SEEK_SET);
|
|
|
|
#endif
|
|
|
|
if(rc) {
|
2021-01-02 03:40:24 -05:00
|
|
|
if(global->showerror)
|
2019-07-20 13:14:00 -04:00
|
|
|
fprintf(global->errors,
|
2021-01-02 03:40:24 -05:00
|
|
|
"curl: (23) Failed seeking to end of file\n");
|
2019-07-20 13:14:00 -04:00
|
|
|
return CURLE_WRITE_ERROR;
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
2019-07-20 13:14:00 -04:00
|
|
|
outs->bytes = 0; /* clear for next round */
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
2020-09-05 11:44:24 -04:00
|
|
|
*retryp = TRUE;
|
|
|
|
*delay = sleeptime;
|
2019-07-20 13:14:00 -04:00
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
} /* if retry_numretries */
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
if((global->progressmode == CURL_PROGRESS_BAR) &&
|
|
|
|
per->progressbar.calls)
|
|
|
|
/* if the custom progress bar has been displayed, we output a
|
|
|
|
newline here */
|
|
|
|
fputs("\n", per->progressbar.out);
|
|
|
|
|
|
|
|
/* Close the outs file */
|
|
|
|
if(outs->fopened && outs->stream) {
|
|
|
|
int rc = fclose(outs->stream);
|
|
|
|
if(!result && rc) {
|
|
|
|
/* something went wrong in the writing process */
|
|
|
|
result = CURLE_WRITE_ERROR;
|
2021-01-02 03:40:24 -05:00
|
|
|
if(global->showerror)
|
|
|
|
fprintf(global->errors, "curl: (%d) Failed writing body\n", result);
|
2019-07-20 13:14:00 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* File time can only be set _after_ the file has been closed */
|
|
|
|
if(!result && config->remote_time && outs->s_isreg && outs->filename) {
|
|
|
|
/* Ask libcurl if we got a remote file time */
|
|
|
|
curl_off_t filetime = -1;
|
|
|
|
curl_easy_getinfo(curl, CURLINFO_FILETIME_T, &filetime);
|
2021-01-26 10:52:03 -05:00
|
|
|
setfiletime(filetime, outs->filename, global);
|
2019-07-20 13:14:00 -04:00
|
|
|
}
|
|
|
|
|
2021-01-28 18:56:50 -05:00
|
|
|
/* Write the --write-out data before cleanup but after result is final */
|
|
|
|
if(config->writeout)
|
|
|
|
ourWriteOut(config->writeout, per, result);
|
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
/* Close function-local opened file descriptors */
|
|
|
|
if(per->heads.fopened && per->heads.stream)
|
|
|
|
fclose(per->heads.stream);
|
|
|
|
|
|
|
|
if(per->heads.alloc_filename)
|
|
|
|
Curl_safefree(per->heads.filename);
|
|
|
|
|
2019-10-30 04:43:14 -04:00
|
|
|
if(per->etag_save.fopened && per->etag_save.stream)
|
|
|
|
fclose(per->etag_save.stream);
|
|
|
|
|
|
|
|
if(per->etag_save.alloc_filename)
|
|
|
|
Curl_safefree(per->etag_save.filename);
|
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
curl_easy_cleanup(per->curl);
|
|
|
|
if(outs->alloc_filename)
|
|
|
|
free(outs->filename);
|
|
|
|
free(per->this_url);
|
|
|
|
free(per->separator_err);
|
|
|
|
free(per->separator);
|
|
|
|
free(per->outfile);
|
|
|
|
free(per->uploadfile);
|
|
|
|
|
2021-02-11 02:30:39 -05:00
|
|
|
return result;
|
2019-07-20 13:14:00 -04:00
|
|
|
}
|
|
|
|
|
2019-09-23 11:11:22 -04:00
|
|
|
static void single_transfer_cleanup(struct OperationConfig *config)
|
|
|
|
{
|
|
|
|
if(config) {
|
|
|
|
struct State *state = &config->state;
|
|
|
|
if(state->urls) {
|
|
|
|
/* Free list of remaining URLs */
|
|
|
|
glob_cleanup(state->urls);
|
|
|
|
state->urls = NULL;
|
|
|
|
}
|
|
|
|
Curl_safefree(state->outfiles);
|
|
|
|
Curl_safefree(state->httpgetfields);
|
|
|
|
Curl_safefree(state->uploadfile);
|
|
|
|
if(state->inglob) {
|
|
|
|
/* Free list of globbed upload files */
|
|
|
|
glob_cleanup(state->inglob);
|
|
|
|
state->inglob = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create the next (singular) transfer */
|
2019-07-20 13:14:00 -04:00
|
|
|
|
2019-09-23 11:11:22 -04:00
|
|
|
static CURLcode single_transfer(struct GlobalConfig *global,
|
|
|
|
struct OperationConfig *config,
|
|
|
|
CURLSH *share,
|
|
|
|
bool capath_from_env,
|
|
|
|
bool *added)
|
2019-07-20 13:14:00 -04:00
|
|
|
{
|
|
|
|
CURLcode result = CURLE_OK;
|
|
|
|
struct getout *urlnode;
|
|
|
|
bool orig_noprogress = global->noprogress;
|
|
|
|
bool orig_isatty = global->isatty;
|
2019-09-23 11:11:22 -04:00
|
|
|
struct State *state = &config->state;
|
|
|
|
char *httpgetfields = state->httpgetfields;
|
|
|
|
*added = FALSE; /* not yet */
|
2019-07-20 13:14:00 -04:00
|
|
|
|
2011-10-04 18:03:20 -04:00
|
|
|
if(config->postfields) {
|
|
|
|
if(config->use_httpget) {
|
2011-10-05 09:06:26 -04:00
|
|
|
if(!httpgetfields) {
|
2019-09-23 11:11:22 -04:00
|
|
|
/* Use the postfields data for a http get */
|
|
|
|
httpgetfields = state->httpgetfields = strdup(config->postfields);
|
|
|
|
Curl_safefree(config->postfields);
|
|
|
|
if(!httpgetfields) {
|
2019-12-09 10:15:37 -05:00
|
|
|
errorf(global, "out of memory\n");
|
2019-09-23 11:11:22 -04:00
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
else if(SetHTTPrequest(config,
|
|
|
|
(config->no_body?HTTPREQ_HEAD:HTTPREQ_GET),
|
|
|
|
&config->httpreq)) {
|
|
|
|
result = CURLE_FAILED_INIT;
|
|
|
|
}
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2019-09-23 11:11:22 -04:00
|
|
|
if(SetHTTPrequest(config, HTTPREQ_SIMPLEPOST, &config->httpreq))
|
2014-12-16 02:35:47 -05:00
|
|
|
result = CURLE_FAILED_INIT;
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
2019-12-29 14:18:48 -05:00
|
|
|
if(result) {
|
|
|
|
single_transfer_cleanup(config);
|
2019-09-23 11:11:22 -04:00
|
|
|
return result;
|
2019-12-29 14:18:48 -05:00
|
|
|
}
|
2019-09-23 11:11:22 -04:00
|
|
|
}
|
|
|
|
if(!state->urlnode) {
|
|
|
|
/* first time caller, setup things */
|
|
|
|
state->urlnode = config->url_list;
|
|
|
|
state->infilenum = 1;
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
|
|
|
|
2019-09-23 11:11:22 -04:00
|
|
|
while(config->state.urlnode) {
|
2011-10-04 18:03:20 -04:00
|
|
|
char *infiles; /* might be a glob pattern */
|
2020-05-13 18:05:04 -04:00
|
|
|
struct URLGlob *inglob = state->inglob;
|
2019-09-23 11:11:22 -04:00
|
|
|
urlnode = config->state.urlnode;
|
2012-04-28 08:48:56 -04:00
|
|
|
|
2011-10-04 18:03:20 -04:00
|
|
|
/* urlnode->url is the full URL (it might be NULL) */
|
|
|
|
|
|
|
|
if(!urlnode->url) {
|
|
|
|
/* This node has no URL. Free node data without destroying the
|
|
|
|
node itself nor modifying next pointer and continue to next */
|
|
|
|
Curl_safefree(urlnode->outfile);
|
|
|
|
Curl_safefree(urlnode->infile);
|
|
|
|
urlnode->flags = 0;
|
2019-09-23 11:11:22 -04:00
|
|
|
config->state.urlnode = urlnode->next;
|
|
|
|
state->up = 0;
|
2011-10-04 18:03:20 -04:00
|
|
|
continue; /* next URL please */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* save outfile pattern before expansion */
|
2019-09-23 11:11:22 -04:00
|
|
|
if(urlnode->outfile && !state->outfiles) {
|
|
|
|
state->outfiles = strdup(urlnode->outfile);
|
|
|
|
if(!state->outfiles) {
|
2019-12-09 10:15:37 -05:00
|
|
|
errorf(global, "out of memory\n");
|
2014-12-16 02:35:47 -05:00
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
2011-10-04 18:03:20 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
infiles = urlnode->infile;
|
|
|
|
|
2019-09-23 11:11:22 -04:00
|
|
|
if(!config->globoff && infiles && !inglob) {
|
2011-10-04 18:03:20 -04:00
|
|
|
/* Unless explicitly shut off */
|
2019-09-23 11:11:22 -04:00
|
|
|
result = glob_url(&inglob, infiles, &state->infilenum,
|
2014-12-16 02:35:47 -05:00
|
|
|
global->showerror?global->errors:NULL);
|
2019-09-23 11:11:22 -04:00
|
|
|
if(result)
|
2011-10-04 18:03:20 -04:00
|
|
|
break;
|
2019-09-23 11:11:22 -04:00
|
|
|
config->state.inglob = inglob;
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
|
|
|
|
2019-09-23 11:11:22 -04:00
|
|
|
{
|
2011-10-04 18:03:20 -04:00
|
|
|
int separator;
|
2013-08-15 07:05:25 -04:00
|
|
|
unsigned long urlnum;
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2019-09-23 11:11:22 -04:00
|
|
|
if(!state->up && !infiles)
|
2011-10-04 18:03:20 -04:00
|
|
|
Curl_nop_stmt;
|
|
|
|
else {
|
2019-09-23 11:11:22 -04:00
|
|
|
if(!state->uploadfile) {
|
|
|
|
if(inglob) {
|
|
|
|
result = glob_next_url(&state->uploadfile, inglob);
|
|
|
|
if(result == CURLE_OUT_OF_MEMORY)
|
2019-12-09 10:15:37 -05:00
|
|
|
errorf(global, "out of memory\n");
|
2019-09-23 11:11:22 -04:00
|
|
|
}
|
|
|
|
else if(!state->up) {
|
|
|
|
state->uploadfile = strdup(infiles);
|
|
|
|
if(!state->uploadfile) {
|
2019-12-09 10:15:37 -05:00
|
|
|
errorf(global, "out of memory\n");
|
2019-09-23 11:11:22 -04:00
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
2011-10-05 16:01:42 -04:00
|
|
|
}
|
|
|
|
}
|
2019-09-23 11:11:22 -04:00
|
|
|
if(result)
|
2011-10-04 18:03:20 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-09-23 11:11:22 -04:00
|
|
|
if(!state->urlnum) {
|
2021-06-01 10:24:00 -04:00
|
|
|
if(!config->globoff) {
|
2019-09-23 11:11:22 -04:00
|
|
|
/* Unless explicitly shut off, we expand '{...}' and '[...]'
|
|
|
|
expressions and return total number of URLs in pattern set */
|
|
|
|
result = glob_url(&state->urls, urlnode->url, &state->urlnum,
|
|
|
|
global->showerror?global->errors:NULL);
|
|
|
|
if(result)
|
|
|
|
break;
|
|
|
|
urlnum = state->urlnum;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
urlnum = 1; /* without globbing, this is a single URL */
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
|
|
|
else
|
2019-09-23 11:11:22 -04:00
|
|
|
urlnum = state->urlnum;
|
2011-10-04 18:03:20 -04:00
|
|
|
|
|
|
|
/* if multiple files extracted to stdout, insert separators! */
|
2019-09-23 11:11:22 -04:00
|
|
|
separator = ((!state->outfiles ||
|
|
|
|
!strcmp(state->outfiles, "-")) && urlnum > 1);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2019-09-23 11:11:22 -04:00
|
|
|
if(state->up < state->infilenum) {
|
2019-07-20 13:14:00 -04:00
|
|
|
struct per_transfer *per;
|
|
|
|
struct OutStruct *outs;
|
|
|
|
struct InStruct *input;
|
|
|
|
struct OutStruct *heads;
|
2019-10-30 04:43:14 -04:00
|
|
|
struct OutStruct *etag_save;
|
2019-07-20 13:14:00 -04:00
|
|
|
struct HdrCbData *hdrcbdata = NULL;
|
|
|
|
CURL *curl = curl_easy_init();
|
2019-09-30 17:24:49 -04:00
|
|
|
result = add_per_transfer(&per);
|
2019-07-20 13:14:00 -04:00
|
|
|
if(result || !curl) {
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
2019-09-23 11:11:22 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(state->uploadfile) {
|
|
|
|
per->uploadfile = strdup(state->uploadfile);
|
|
|
|
if(!per->uploadfile) {
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
2019-07-20 13:14:00 -04:00
|
|
|
}
|
2019-09-23 11:11:22 -04:00
|
|
|
*added = TRUE;
|
2019-07-20 13:14:00 -04:00
|
|
|
per->config = config;
|
|
|
|
per->curl = curl;
|
2020-12-14 04:09:51 -05:00
|
|
|
per->urlnum = urlnode->num;
|
2019-07-20 13:14:00 -04:00
|
|
|
|
|
|
|
/* default headers output stream is stdout */
|
|
|
|
heads = &per->heads;
|
|
|
|
heads->stream = stdout;
|
|
|
|
|
|
|
|
/* Single header file for all URLs */
|
|
|
|
if(config->headerfile) {
|
|
|
|
/* open file for output: */
|
|
|
|
if(strcmp(config->headerfile, "-")) {
|
2020-01-21 03:23:21 -05:00
|
|
|
FILE *newfile;
|
|
|
|
newfile = fopen(config->headerfile, per->prev == NULL?"wb":"ab");
|
2019-07-20 13:14:00 -04:00
|
|
|
if(!newfile) {
|
2021-01-26 10:55:50 -05:00
|
|
|
warnf(global, "Failed to open %s\n", config->headerfile);
|
2019-07-20 13:14:00 -04:00
|
|
|
result = CURLE_WRITE_ERROR;
|
2019-09-23 11:11:22 -04:00
|
|
|
break;
|
2019-07-20 13:14:00 -04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
heads->filename = config->headerfile;
|
|
|
|
heads->s_isreg = TRUE;
|
|
|
|
heads->fopened = TRUE;
|
|
|
|
heads->stream = newfile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* always use binary mode for protocol header output */
|
|
|
|
set_binmode(heads->stream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-11 16:53:34 -05:00
|
|
|
hdrcbdata = &per->hdrcbdata;
|
|
|
|
|
|
|
|
outs = &per->outs;
|
|
|
|
input = &per->input;
|
|
|
|
|
|
|
|
per->outfile = NULL;
|
|
|
|
per->infdopen = FALSE;
|
|
|
|
per->infd = STDIN_FILENO;
|
|
|
|
|
|
|
|
/* default output stream is stdout */
|
|
|
|
outs->stream = stdout;
|
|
|
|
|
2019-10-30 04:43:14 -04:00
|
|
|
/* --etag-compare */
|
|
|
|
if(config->etag_compare_file) {
|
|
|
|
char *etag_from_file = NULL;
|
|
|
|
char *header = NULL;
|
|
|
|
|
|
|
|
/* open file for reading: */
|
|
|
|
FILE *file = fopen(config->etag_compare_file, FOPEN_READTEXT);
|
2020-04-03 14:51:14 -04:00
|
|
|
if(!file && !config->etag_save_file) {
|
2021-01-26 10:55:50 -05:00
|
|
|
errorf(global,
|
2019-12-12 04:38:14 -05:00
|
|
|
"Failed to open %s\n", config->etag_compare_file);
|
2019-10-30 04:43:14 -04:00
|
|
|
result = CURLE_READ_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-12-06 11:24:52 -05:00
|
|
|
if((PARAM_OK == file2string(&etag_from_file, file)) &&
|
2019-12-12 04:38:14 -05:00
|
|
|
etag_from_file) {
|
2020-08-19 18:34:44 -04:00
|
|
|
header = aprintf("If-None-Match: %s", etag_from_file);
|
2019-12-12 04:38:14 -05:00
|
|
|
Curl_safefree(etag_from_file);
|
|
|
|
}
|
2019-12-06 11:24:52 -05:00
|
|
|
else
|
2019-10-30 04:43:14 -04:00
|
|
|
header = aprintf("If-None-Match: \"\"");
|
|
|
|
|
|
|
|
if(!header) {
|
2019-12-12 04:38:14 -05:00
|
|
|
if(file)
|
|
|
|
fclose(file);
|
2021-01-26 10:55:50 -05:00
|
|
|
errorf(global,
|
2019-12-12 04:38:14 -05:00
|
|
|
"Failed to allocate memory for custom etag header\n");
|
2019-10-30 04:43:14 -04:00
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add Etag from file to list of custom headers */
|
|
|
|
add2list(&config->headers, header);
|
|
|
|
|
|
|
|
Curl_safefree(header);
|
|
|
|
|
|
|
|
if(file) {
|
|
|
|
fclose(file);
|
|
|
|
}
|
|
|
|
}
|
2019-07-20 13:14:00 -04:00
|
|
|
|
2020-04-03 14:51:14 -04:00
|
|
|
/* --etag-save */
|
|
|
|
etag_save = &per->etag_save;
|
|
|
|
etag_save->stream = stdout;
|
|
|
|
|
|
|
|
if(config->etag_save_file) {
|
|
|
|
/* open file for output: */
|
|
|
|
if(strcmp(config->etag_save_file, "-")) {
|
|
|
|
FILE *newfile = fopen(config->etag_save_file, "wb");
|
|
|
|
if(!newfile) {
|
|
|
|
warnf(
|
2021-01-26 10:55:50 -05:00
|
|
|
global,
|
2020-04-03 14:51:14 -04:00
|
|
|
"Failed to open %s\n", config->etag_save_file);
|
|
|
|
|
|
|
|
result = CURLE_WRITE_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
etag_save->filename = config->etag_save_file;
|
|
|
|
etag_save->s_isreg = TRUE;
|
|
|
|
etag_save->fopened = TRUE;
|
|
|
|
etag_save->stream = newfile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* always use binary mode for protocol header output */
|
|
|
|
set_binmode(etag_save->stream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-01 10:24:00 -04:00
|
|
|
if(state->urls) {
|
|
|
|
result = glob_next_url(&per->this_url, state->urls);
|
|
|
|
if(result)
|
2019-09-23 11:11:22 -04:00
|
|
|
break;
|
2021-06-01 10:24:00 -04:00
|
|
|
}
|
|
|
|
else if(!state->li) {
|
|
|
|
per->this_url = strdup(urlnode->url);
|
2019-07-20 13:14:00 -04:00
|
|
|
if(!per->this_url) {
|
2014-12-16 02:35:47 -05:00
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
2019-09-23 11:11:22 -04:00
|
|
|
break;
|
2011-10-05 16:01:42 -04:00
|
|
|
}
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
2021-06-01 10:24:00 -04:00
|
|
|
else
|
|
|
|
per->this_url = NULL;
|
|
|
|
if(!per->this_url)
|
|
|
|
break;
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2021-06-01 10:24:00 -04:00
|
|
|
if(state->outfiles) {
|
|
|
|
per->outfile = strdup(state->outfiles);
|
|
|
|
if(!per->outfile) {
|
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
|
|
|
break;
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-20 11:51:06 -04:00
|
|
|
if(((urlnode->flags&GETOUT_USEREMOTE) ||
|
2021-06-01 10:24:00 -04:00
|
|
|
(per->outfile && strcmp("-", per->outfile)))) {
|
2011-10-04 18:03:20 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We have specified a file name to store the result in, or we have
|
|
|
|
* decided we want to use the remote file name.
|
|
|
|
*/
|
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
if(!per->outfile) {
|
2011-10-04 18:03:20 -04:00
|
|
|
/* extract the file name from the URL */
|
2019-07-20 13:14:00 -04:00
|
|
|
result = get_url_file_name(&per->outfile, per->this_url);
|
2014-12-16 02:35:47 -05:00
|
|
|
if(result)
|
2019-09-23 11:11:22 -04:00
|
|
|
break;
|
2019-07-20 13:14:00 -04:00
|
|
|
if(!*per->outfile && !config->content_disposition) {
|
2019-12-09 10:15:37 -05:00
|
|
|
errorf(global, "Remote file name has no length!\n");
|
2014-12-16 02:35:47 -05:00
|
|
|
result = CURLE_WRITE_ERROR;
|
2019-09-23 11:11:22 -04:00
|
|
|
break;
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
|
|
|
}
|
2019-09-23 11:11:22 -04:00
|
|
|
else if(state->urls) {
|
2011-10-04 18:03:20 -04:00
|
|
|
/* fill '#1' ... '#9' terms from URL pattern */
|
2019-07-20 13:14:00 -04:00
|
|
|
char *storefile = per->outfile;
|
2019-09-23 11:11:22 -04:00
|
|
|
result = glob_match_url(&per->outfile, storefile, state->urls);
|
2011-10-04 18:03:20 -04:00
|
|
|
Curl_safefree(storefile);
|
2014-12-16 02:35:47 -05:00
|
|
|
if(result) {
|
2011-10-04 18:03:20 -04:00
|
|
|
/* bad globbing */
|
2021-01-26 10:55:50 -05:00
|
|
|
warnf(global, "bad output glob!\n");
|
2019-09-23 11:11:22 -04:00
|
|
|
break;
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-24 02:31:36 -04:00
|
|
|
if(config->output_dir) {
|
|
|
|
char *d = aprintf("%s/%s", config->output_dir, per->outfile);
|
|
|
|
if(!d) {
|
|
|
|
result = CURLE_WRITE_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
free(per->outfile);
|
|
|
|
per->outfile = d;
|
|
|
|
}
|
2011-10-04 18:03:20 -04:00
|
|
|
/* Create the directory hierarchy, if not pre-existent to a multiple
|
|
|
|
file output call */
|
|
|
|
|
2021-06-01 10:24:00 -04:00
|
|
|
if(config->create_dirs) {
|
2019-07-20 13:14:00 -04:00
|
|
|
result = create_dir_hierarchy(per->outfile, global->errors);
|
2011-10-04 18:03:20 -04:00
|
|
|
/* create_dir_hierarchy shows error upon CURLE_WRITE_ERROR */
|
2019-09-23 11:11:22 -04:00
|
|
|
if(result)
|
|
|
|
break;
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if((urlnode->flags & GETOUT_USEREMOTE)
|
|
|
|
&& config->content_disposition) {
|
2011-11-20 17:33:46 -05:00
|
|
|
/* Our header callback MIGHT set the filename */
|
2019-07-20 13:14:00 -04:00
|
|
|
DEBUGASSERT(!outs->filename);
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
|
|
|
|
2011-11-20 17:33:46 -05:00
|
|
|
if(config->resume_from_current) {
|
|
|
|
/* We're told to continue from where we are now. Get the size
|
|
|
|
of the file as it is now and open it for append instead */
|
|
|
|
struct_stat fileinfo;
|
|
|
|
/* VMS -- Danger, the filesize is only valid for stream files */
|
2019-07-20 13:14:00 -04:00
|
|
|
if(0 == stat(per->outfile, &fileinfo))
|
2011-11-20 17:33:46 -05:00
|
|
|
/* set offset to current file size: */
|
|
|
|
config->resume_from = fileinfo.st_size;
|
|
|
|
else
|
|
|
|
/* let offset be 0 */
|
|
|
|
config->resume_from = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(config->resume_from) {
|
2013-07-29 10:32:29 -04:00
|
|
|
#ifdef __VMS
|
|
|
|
/* open file for output, forcing VMS output format into stream
|
|
|
|
mode which is needed for stat() call above to always work. */
|
2019-09-19 04:33:56 -04:00
|
|
|
FILE *file = fopen(outfile, "ab",
|
2013-07-22 16:15:27 -04:00
|
|
|
"ctx=stm", "rfm=stmlf", "rat=cr", "mrs=0");
|
2013-07-29 10:32:29 -04:00
|
|
|
#else
|
|
|
|
/* open file for output: */
|
2019-09-19 04:33:56 -04:00
|
|
|
FILE *file = fopen(per->outfile, "ab");
|
2013-07-22 16:15:27 -04:00
|
|
|
#endif
|
2011-11-20 17:33:46 -05:00
|
|
|
if(!file) {
|
2019-12-09 10:15:37 -05:00
|
|
|
errorf(global, "Can't open '%s'!\n", per->outfile);
|
2014-12-16 02:35:47 -05:00
|
|
|
result = CURLE_WRITE_ERROR;
|
2019-09-23 11:11:22 -04:00
|
|
|
break;
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
2019-07-20 13:14:00 -04:00
|
|
|
outs->fopened = TRUE;
|
|
|
|
outs->stream = file;
|
|
|
|
outs->init = config->resume_from;
|
2011-11-20 17:33:46 -05:00
|
|
|
}
|
|
|
|
else {
|
2019-07-20 13:14:00 -04:00
|
|
|
outs->stream = NULL; /* open when needed */
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
2019-07-20 13:14:00 -04:00
|
|
|
outs->filename = per->outfile;
|
|
|
|
outs->s_isreg = TRUE;
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
if(per->uploadfile && !stdin_upload(per->uploadfile)) {
|
2011-10-04 18:03:20 -04:00
|
|
|
/*
|
|
|
|
* We have specified a file to upload and it isn't "-".
|
|
|
|
*/
|
2019-07-20 13:14:00 -04:00
|
|
|
char *nurl = add_file_name_to_url(per->this_url, per->uploadfile);
|
|
|
|
if(!nurl) {
|
2014-12-16 02:35:47 -05:00
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
2019-09-23 11:11:22 -04:00
|
|
|
break;
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
2019-07-20 13:14:00 -04:00
|
|
|
per->this_url = nurl;
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
2019-07-20 13:14:00 -04:00
|
|
|
else if(per->uploadfile && stdin_upload(per->uploadfile)) {
|
2011-10-04 18:03:20 -04:00
|
|
|
/* count to see if there are more than one auth bit set
|
|
|
|
in the authtype field */
|
|
|
|
int authbits = 0;
|
|
|
|
int bitcheck = 0;
|
|
|
|
while(bitcheck < 32) {
|
2012-04-18 17:04:35 -04:00
|
|
|
if(config->authtype & (1UL << bitcheck++)) {
|
2011-10-04 18:03:20 -04:00
|
|
|
authbits++;
|
|
|
|
if(authbits > 1) {
|
|
|
|
/* more than one, we're done! */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the user has also selected --anyauth or --proxy-anyauth
|
|
|
|
* we should warn him/her.
|
|
|
|
*/
|
|
|
|
if(config->proxyanyauth || (authbits>1)) {
|
2021-01-26 10:55:50 -05:00
|
|
|
warnf(global,
|
2011-10-04 18:03:20 -04:00
|
|
|
"Using --anyauth or --proxy-anyauth with upload from stdin"
|
|
|
|
" involves a big risk of it not working. Use a temporary"
|
|
|
|
" file or a fixed auth type instead!\n");
|
|
|
|
}
|
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
DEBUGASSERT(per->infdopen == FALSE);
|
|
|
|
DEBUGASSERT(per->infd == STDIN_FILENO);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
|
|
|
set_binmode(stdin);
|
2019-07-20 13:14:00 -04:00
|
|
|
if(!strcmp(per->uploadfile, ".")) {
|
|
|
|
if(curlx_nonblock((curl_socket_t)per->infd, TRUE) < 0)
|
2021-01-26 10:55:50 -05:00
|
|
|
warnf(global,
|
2019-07-20 13:14:00 -04:00
|
|
|
"fcntl failed on fd=%d: %s\n", per->infd, strerror(errno));
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
if(per->uploadfile && config->resume_from_current)
|
2011-10-04 18:03:20 -04:00
|
|
|
config->resume_from = -1; /* -1 will then force get-it-yourself */
|
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
if(output_expected(per->this_url, per->uploadfile) && outs->stream &&
|
|
|
|
isatty(fileno(outs->stream)))
|
2011-10-04 18:03:20 -04:00
|
|
|
/* we send the output to a tty, therefore we switch off the progress
|
|
|
|
meter */
|
2019-11-26 03:16:19 -05:00
|
|
|
per->noprogress = global->noprogress = global->isatty = TRUE;
|
2012-06-20 12:00:53 -04:00
|
|
|
else {
|
|
|
|
/* progress meter is per download, so restore config
|
|
|
|
values */
|
2019-11-26 03:16:19 -05:00
|
|
|
per->noprogress = global->noprogress = orig_noprogress;
|
2014-03-01 08:49:28 -05:00
|
|
|
global->isatty = orig_isatty;
|
2012-06-20 12:00:53 -04:00
|
|
|
}
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2014-02-27 15:21:23 -05:00
|
|
|
if(urlnum > 1 && !global->mute) {
|
2019-07-20 13:14:00 -04:00
|
|
|
per->separator_err =
|
|
|
|
aprintf("\n[%lu/%lu]: %s --> %s",
|
2019-09-23 11:11:22 -04:00
|
|
|
state->li + 1, urlnum, per->this_url,
|
2019-07-20 13:14:00 -04:00
|
|
|
per->outfile ? per->outfile : "<stdout>");
|
2011-10-04 18:03:20 -04:00
|
|
|
if(separator)
|
2019-07-20 13:14:00 -04:00
|
|
|
per->separator = aprintf("%s%s", CURLseparator, per->this_url);
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
|
|
|
if(httpgetfields) {
|
|
|
|
char *urlbuffer;
|
|
|
|
/* Find out whether the url contains a file name */
|
2019-07-20 13:14:00 -04:00
|
|
|
const char *pc = strstr(per->this_url, "://");
|
2011-10-04 18:03:20 -04:00
|
|
|
char sep = '?';
|
|
|
|
if(pc)
|
|
|
|
pc += 3;
|
|
|
|
else
|
2019-07-20 13:14:00 -04:00
|
|
|
pc = per->this_url;
|
2011-10-04 18:03:20 -04:00
|
|
|
|
|
|
|
pc = strrchr(pc, '/'); /* check for a slash */
|
|
|
|
|
|
|
|
if(pc) {
|
|
|
|
/* there is a slash present in the URL */
|
|
|
|
|
|
|
|
if(strchr(pc, '?'))
|
|
|
|
/* Ouch, there's already a question mark in the URL string, we
|
|
|
|
then append the data with an ampersand separator instead! */
|
2017-09-09 17:09:06 -04:00
|
|
|
sep = '&';
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Then append ? followed by the get fields to the url.
|
|
|
|
*/
|
|
|
|
if(pc)
|
2019-07-20 13:14:00 -04:00
|
|
|
urlbuffer = aprintf("%s%c%s", per->this_url, sep, httpgetfields);
|
2011-10-04 18:03:20 -04:00
|
|
|
else
|
|
|
|
/* Append / before the ? to create a well-formed url
|
|
|
|
if the url contains a hostname only
|
|
|
|
*/
|
2019-07-20 13:14:00 -04:00
|
|
|
urlbuffer = aprintf("%s/?%s", per->this_url, httpgetfields);
|
2013-03-06 07:27:51 -05:00
|
|
|
|
|
|
|
if(!urlbuffer) {
|
2014-12-16 02:35:47 -05:00
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
2019-09-23 11:11:22 -04:00
|
|
|
break;
|
2013-03-06 07:27:51 -05:00
|
|
|
}
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
Curl_safefree(per->this_url); /* free previous URL */
|
|
|
|
per->this_url = urlbuffer; /* use our new URL instead! */
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
|
|
|
|
2014-03-01 08:00:31 -05:00
|
|
|
if(!global->errors)
|
|
|
|
global->errors = stderr;
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
if((!per->outfile || !strcmp(per->outfile, "-")) &&
|
|
|
|
!config->use_ascii) {
|
2011-10-04 18:03:20 -04:00
|
|
|
/* We get the output to stdout and we have not got the ASCII/text
|
|
|
|
flag, then set stdout to be binary */
|
|
|
|
set_binmode(stdout);
|
|
|
|
}
|
|
|
|
|
2017-06-16 05:30:36 -04:00
|
|
|
/* explicitly passed to stdout means okaying binary gunk */
|
2019-07-20 13:14:00 -04:00
|
|
|
config->terminal_binary_ok =
|
|
|
|
(per->outfile && !strcmp(per->outfile, "-"));
|
|
|
|
|
2019-09-23 11:11:22 -04:00
|
|
|
/* Avoid having this setopt added to the --libcurl source output. */
|
2019-07-21 07:21:13 -04:00
|
|
|
result = curl_easy_setopt(curl, CURLOPT_SHARE, share);
|
|
|
|
if(result)
|
2019-09-23 11:11:22 -04:00
|
|
|
break;
|
2017-06-16 05:30:36 -04:00
|
|
|
|
2016-06-30 08:56:02 -04:00
|
|
|
if(!config->tcp_nodelay)
|
|
|
|
my_setopt(curl, CURLOPT_TCP_NODELAY, 0L);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2016-02-16 07:21:34 -05:00
|
|
|
if(config->tcp_fastopen)
|
|
|
|
my_setopt(curl, CURLOPT_TCP_FASTOPEN, 1L);
|
|
|
|
|
2011-10-04 18:03:20 -04:00
|
|
|
/* where to store */
|
2019-07-20 13:14:00 -04:00
|
|
|
my_setopt(curl, CURLOPT_WRITEDATA, per);
|
|
|
|
my_setopt(curl, CURLOPT_INTERLEAVEDATA, per);
|
2019-06-18 16:30:54 -04:00
|
|
|
|
2021-06-01 10:24:00 -04:00
|
|
|
/* what call to write */
|
|
|
|
my_setopt(curl, CURLOPT_WRITEFUNCTION, tool_write_cb);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
|
|
|
/* for uploads */
|
2019-07-20 13:14:00 -04:00
|
|
|
input->config = config;
|
2012-01-04 06:24:49 -05:00
|
|
|
/* Note that if CURLOPT_READFUNCTION is fread (the default), then
|
2013-01-03 20:50:28 -05:00
|
|
|
* lib/telnet.c will Curl_poll() on the input file descriptor
|
2012-01-04 06:24:49 -05:00
|
|
|
* rather then calling the READFUNCTION at regular intervals.
|
|
|
|
* The circumstances in which it is preferable to enable this
|
2020-12-31 04:11:49 -05:00
|
|
|
* behavior, by omitting to set the READFUNCTION & READDATA options,
|
2012-01-04 06:24:49 -05:00
|
|
|
* have not been determined.
|
|
|
|
*/
|
2019-07-20 13:14:00 -04:00
|
|
|
my_setopt(curl, CURLOPT_READDATA, input);
|
2011-10-04 18:03:20 -04:00
|
|
|
/* what call to read */
|
2012-01-04 06:24:49 -05:00
|
|
|
my_setopt(curl, CURLOPT_READFUNCTION, tool_read_cb);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
|
|
|
/* in 7.18.0, the CURLOPT_SEEKFUNCTION/DATA pair is taking over what
|
|
|
|
CURLOPT_IOCTLFUNCTION/DATA pair previously provided for seeking */
|
2019-07-20 13:14:00 -04:00
|
|
|
my_setopt(curl, CURLOPT_SEEKDATA, input);
|
2011-10-04 18:03:20 -04:00
|
|
|
my_setopt(curl, CURLOPT_SEEKFUNCTION, tool_seek_cb);
|
|
|
|
|
2017-04-24 06:03:08 -04:00
|
|
|
if(config->recvpersecond &&
|
|
|
|
(config->recvpersecond < BUFFER_SIZE))
|
|
|
|
/* use a smaller sized buffer for better sleeps */
|
2013-07-22 12:08:23 -04:00
|
|
|
my_setopt(curl, CURLOPT_BUFFERSIZE, (long)config->recvpersecond);
|
2017-04-24 06:03:08 -04:00
|
|
|
else
|
|
|
|
my_setopt(curl, CURLOPT_BUFFERSIZE, (long)BUFFER_SIZE);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
my_setopt_str(curl, CURLOPT_URL, per->this_url);
|
2014-03-01 08:20:20 -05:00
|
|
|
my_setopt(curl, CURLOPT_NOPROGRESS, global->noprogress?1L:0L);
|
2018-05-17 07:56:35 -04:00
|
|
|
if(config->no_body)
|
2013-07-22 12:08:23 -04:00
|
|
|
my_setopt(curl, CURLOPT_NOBODY, 1L);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2015-09-04 02:11:09 -04:00
|
|
|
if(config->oauth_bearer)
|
|
|
|
my_setopt_str(curl, CURLOPT_XOAUTH2_BEARER, config->oauth_bearer);
|
2013-08-25 13:18:59 -04:00
|
|
|
|
2011-10-04 18:03:20 -04:00
|
|
|
{
|
|
|
|
my_setopt_str(curl, CURLOPT_PROXY, config->proxy);
|
2016-12-16 09:34:14 -05:00
|
|
|
/* new in libcurl 7.5 */
|
|
|
|
if(config->proxy)
|
|
|
|
my_setopt_enum(curl, CURLOPT_PROXYTYPE, config->proxyver);
|
|
|
|
|
2011-10-04 18:03:20 -04:00
|
|
|
my_setopt_str(curl, CURLOPT_PROXYUSERPWD, config->proxyuserpwd);
|
|
|
|
|
|
|
|
/* new in libcurl 7.3 */
|
2013-07-22 12:08:23 -04:00
|
|
|
my_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, config->proxytunnel?1L:0L);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2016-12-16 09:10:19 -05:00
|
|
|
/* new in libcurl 7.52.0 */
|
2016-12-16 10:02:08 -05:00
|
|
|
if(config->preproxy)
|
|
|
|
my_setopt_str(curl, CURLOPT_PRE_PROXY, config->preproxy);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
|
|
|
/* new in libcurl 7.10.6 */
|
|
|
|
if(config->proxyanyauth)
|
2012-04-19 10:31:11 -04:00
|
|
|
my_setopt_bitmask(curl, CURLOPT_PROXYAUTH,
|
2013-07-22 12:08:23 -04:00
|
|
|
(long)CURLAUTH_ANY);
|
2011-10-04 18:03:20 -04:00
|
|
|
else if(config->proxynegotiate)
|
2012-04-19 10:31:11 -04:00
|
|
|
my_setopt_bitmask(curl, CURLOPT_PROXYAUTH,
|
2013-07-22 12:08:23 -04:00
|
|
|
(long)CURLAUTH_GSSNEGOTIATE);
|
2011-10-04 18:03:20 -04:00
|
|
|
else if(config->proxyntlm)
|
2012-04-19 10:31:11 -04:00
|
|
|
my_setopt_bitmask(curl, CURLOPT_PROXYAUTH,
|
2013-07-22 12:08:23 -04:00
|
|
|
(long)CURLAUTH_NTLM);
|
2011-10-04 18:03:20 -04:00
|
|
|
else if(config->proxydigest)
|
2012-04-19 10:31:11 -04:00
|
|
|
my_setopt_bitmask(curl, CURLOPT_PROXYAUTH,
|
2013-07-22 12:08:23 -04:00
|
|
|
(long)CURLAUTH_DIGEST);
|
2011-10-04 18:03:20 -04:00
|
|
|
else if(config->proxybasic)
|
2012-04-19 10:31:11 -04:00
|
|
|
my_setopt_bitmask(curl, CURLOPT_PROXYAUTH,
|
2013-07-22 12:08:23 -04:00
|
|
|
(long)CURLAUTH_BASIC);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
|
|
|
/* new in libcurl 7.19.4 */
|
2015-11-13 10:59:09 -05:00
|
|
|
my_setopt_str(curl, CURLOPT_NOPROXY, config->noproxy);
|
2016-04-28 05:33:25 -04:00
|
|
|
|
|
|
|
my_setopt(curl, CURLOPT_SUPPRESS_CONNECT_HEADERS,
|
|
|
|
config->suppress_connect_headers?1L:0L);
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
|
|
|
|
2013-07-22 12:08:23 -04:00
|
|
|
my_setopt(curl, CURLOPT_FAILONERROR, config->failonerror?1L:0L);
|
2017-06-21 17:35:08 -04:00
|
|
|
my_setopt(curl, CURLOPT_REQUEST_TARGET, config->request_target);
|
2019-07-20 13:14:00 -04:00
|
|
|
my_setopt(curl, CURLOPT_UPLOAD, per->uploadfile?1L:0L);
|
2013-07-22 12:08:23 -04:00
|
|
|
my_setopt(curl, CURLOPT_DIRLISTONLY, config->dirlistonly?1L:0L);
|
|
|
|
my_setopt(curl, CURLOPT_APPEND, config->ftp_append?1L:0L);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
|
|
|
if(config->netrc_opt)
|
2013-07-22 14:03:27 -04:00
|
|
|
my_setopt_enum(curl, CURLOPT_NETRC, (long)CURL_NETRC_OPTIONAL);
|
2011-10-04 18:03:20 -04:00
|
|
|
else if(config->netrc || config->netrc_file)
|
2013-07-22 14:03:27 -04:00
|
|
|
my_setopt_enum(curl, CURLOPT_NETRC, (long)CURL_NETRC_REQUIRED);
|
2011-10-04 18:03:20 -04:00
|
|
|
else
|
2013-07-22 14:03:27 -04:00
|
|
|
my_setopt_enum(curl, CURLOPT_NETRC, (long)CURL_NETRC_IGNORED);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
|
|
|
if(config->netrc_file)
|
2015-11-13 10:59:09 -05:00
|
|
|
my_setopt_str(curl, CURLOPT_NETRC_FILE, config->netrc_file);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2013-07-22 12:08:23 -04:00
|
|
|
my_setopt(curl, CURLOPT_TRANSFERTEXT, config->use_ascii?1L:0L);
|
2013-12-14 16:39:27 -05:00
|
|
|
if(config->login_options)
|
|
|
|
my_setopt_str(curl, CURLOPT_LOGIN_OPTIONS, config->login_options);
|
2011-10-04 18:03:20 -04:00
|
|
|
my_setopt_str(curl, CURLOPT_USERPWD, config->userpwd);
|
|
|
|
my_setopt_str(curl, CURLOPT_RANGE, config->range);
|
2019-07-20 13:14:00 -04:00
|
|
|
my_setopt(curl, CURLOPT_ERRORBUFFER, per->errorbuffer);
|
2013-04-30 10:23:39 -04:00
|
|
|
my_setopt(curl, CURLOPT_TIMEOUT_MS, (long)(config->timeout * 1000));
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2017-09-29 19:20:56 -04:00
|
|
|
switch(config->httpreq) {
|
|
|
|
case HTTPREQ_SIMPLEPOST:
|
|
|
|
my_setopt_str(curl, CURLOPT_POSTFIELDS,
|
|
|
|
config->postfields);
|
|
|
|
my_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE,
|
|
|
|
config->postfieldsize);
|
|
|
|
break;
|
|
|
|
case HTTPREQ_MIMEPOST:
|
2020-01-04 15:40:49 -05:00
|
|
|
/* free previous remainders */
|
|
|
|
curl_mime_free(config->mimepost);
|
|
|
|
config->mimepost = NULL;
|
2019-02-19 11:08:58 -05:00
|
|
|
result = tool2curlmime(curl, config->mimeroot, &config->mimepost);
|
|
|
|
if(result)
|
2019-09-23 11:11:22 -04:00
|
|
|
break;
|
2017-09-29 19:20:56 -04:00
|
|
|
my_setopt_mimepost(curl, CURLOPT_MIMEPOST, config->mimepost);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2019-09-23 11:11:22 -04:00
|
|
|
if(result)
|
|
|
|
break;
|
2017-09-29 19:20:56 -04:00
|
|
|
|
|
|
|
/* new in libcurl 7.10.6 (default is Basic) */
|
|
|
|
if(config->authtype)
|
|
|
|
my_setopt_bitmask(curl, CURLOPT_HTTPAUTH, (long)config->authtype);
|
|
|
|
|
|
|
|
my_setopt_slist(curl, CURLOPT_HTTPHEADER, config->headers);
|
|
|
|
|
|
|
|
if(built_in_protos & (CURLPROTO_HTTP | CURLPROTO_RTSP)) {
|
|
|
|
my_setopt_str(curl, CURLOPT_REFERER, config->referer);
|
|
|
|
my_setopt_str(curl, CURLOPT_USERAGENT, config->useragent);
|
|
|
|
}
|
|
|
|
|
2011-10-04 18:03:20 -04:00
|
|
|
if(built_in_protos & CURLPROTO_HTTP) {
|
|
|
|
|
2012-04-12 14:41:03 -04:00
|
|
|
long postRedir = 0;
|
|
|
|
|
2011-10-04 18:03:20 -04:00
|
|
|
my_setopt(curl, CURLOPT_FOLLOWLOCATION,
|
2013-07-22 12:08:23 -04:00
|
|
|
config->followlocation?1L:0L);
|
2011-10-04 18:03:20 -04:00
|
|
|
my_setopt(curl, CURLOPT_UNRESTRICTED_AUTH,
|
2013-07-22 12:08:23 -04:00
|
|
|
config->unrestricted_auth?1L:0L);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2013-07-22 12:08:23 -04:00
|
|
|
my_setopt(curl, CURLOPT_AUTOREFERER, config->autoreferer?1L:0L);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2014-02-04 17:48:16 -05:00
|
|
|
/* new in libcurl 7.36.0 */
|
|
|
|
if(config->proxyheaders) {
|
|
|
|
my_setopt_slist(curl, CURLOPT_PROXYHEADER, config->proxyheaders);
|
|
|
|
my_setopt(curl, CURLOPT_HEADEROPT, CURLHEADER_SEPARATE);
|
|
|
|
}
|
|
|
|
|
2011-10-04 18:03:20 -04:00
|
|
|
/* new in libcurl 7.5 */
|
|
|
|
my_setopt(curl, CURLOPT_MAXREDIRS, config->maxredirs);
|
|
|
|
|
|
|
|
if(config->httpversion)
|
2012-02-23 04:43:37 -05:00
|
|
|
my_setopt_enum(curl, CURLOPT_HTTP_VERSION, config->httpversion);
|
2015-12-13 03:24:08 -05:00
|
|
|
else if(curlinfo->features & CURL_VERSION_HTTP2) {
|
|
|
|
my_setopt_enum(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2TLS);
|
|
|
|
}
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2012-04-05 17:34:12 -04:00
|
|
|
/* curl 7.19.1 (the 301 version existed in 7.18.2),
|
|
|
|
303 was added in 7.26.0 */
|
2012-04-12 14:41:03 -04:00
|
|
|
if(config->post301)
|
|
|
|
postRedir |= CURL_REDIR_POST_301;
|
|
|
|
if(config->post302)
|
|
|
|
postRedir |= CURL_REDIR_POST_302;
|
|
|
|
if(config->post303)
|
|
|
|
postRedir |= CURL_REDIR_POST_303;
|
|
|
|
my_setopt(curl, CURLOPT_POSTREDIR, postRedir);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
|
|
|
/* new in libcurl 7.21.6 */
|
|
|
|
if(config->encoding)
|
|
|
|
my_setopt_str(curl, CURLOPT_ACCEPT_ENCODING, "");
|
|
|
|
|
|
|
|
/* new in libcurl 7.21.6 */
|
|
|
|
if(config->tr_encoding)
|
2013-07-22 12:08:23 -04:00
|
|
|
my_setopt(curl, CURLOPT_TRANSFER_ENCODING, 1L);
|
2018-12-17 09:46:56 -05:00
|
|
|
/* new in libcurl 7.64.0 */
|
2019-02-06 08:59:15 -05:00
|
|
|
my_setopt(curl, CURLOPT_HTTP09_ALLOWED,
|
|
|
|
config->http09_allowed ? 1L : 0L);
|
2021-03-11 09:37:52 -05:00
|
|
|
if(result) {
|
|
|
|
errorf(global, "HTTP/0.9 is not supported in this build!\n");
|
|
|
|
return result;
|
|
|
|
}
|
2011-10-04 18:03:20 -04:00
|
|
|
|
|
|
|
} /* (built_in_protos & CURLPROTO_HTTP) */
|
|
|
|
|
|
|
|
my_setopt_str(curl, CURLOPT_FTPPORT, config->ftpport);
|
|
|
|
my_setopt(curl, CURLOPT_LOW_SPEED_LIMIT,
|
|
|
|
config->low_speed_limit);
|
|
|
|
my_setopt(curl, CURLOPT_LOW_SPEED_TIME, config->low_speed_time);
|
|
|
|
my_setopt(curl, CURLOPT_MAX_SEND_SPEED_LARGE,
|
|
|
|
config->sendpersecond);
|
|
|
|
my_setopt(curl, CURLOPT_MAX_RECV_SPEED_LARGE,
|
|
|
|
config->recvpersecond);
|
|
|
|
|
2013-07-22 12:08:23 -04:00
|
|
|
if(config->use_resume)
|
|
|
|
my_setopt(curl, CURLOPT_RESUME_FROM_LARGE, config->resume_from);
|
|
|
|
else
|
|
|
|
my_setopt(curl, CURLOPT_RESUME_FROM_LARGE, CURL_OFF_T_C(0));
|
|
|
|
|
2011-10-04 18:03:20 -04:00
|
|
|
my_setopt_str(curl, CURLOPT_KEYPASSWD, config->key_passwd);
|
2016-11-16 12:49:15 -05:00
|
|
|
my_setopt_str(curl, CURLOPT_PROXY_KEYPASSWD, config->proxy_key_passwd);
|
2019-06-18 16:30:54 -04:00
|
|
|
|
2011-10-04 18:03:20 -04:00
|
|
|
if(built_in_protos & (CURLPROTO_SCP|CURLPROTO_SFTP)) {
|
|
|
|
|
|
|
|
/* SSH and SSL private key uses same command-line option */
|
|
|
|
/* new in libcurl 7.16.1 */
|
|
|
|
my_setopt_str(curl, CURLOPT_SSH_PRIVATE_KEYFILE, config->key);
|
|
|
|
/* new in libcurl 7.16.1 */
|
|
|
|
my_setopt_str(curl, CURLOPT_SSH_PUBLIC_KEYFILE, config->pubkey);
|
|
|
|
|
|
|
|
/* new in libcurl 7.17.1: SSH host key md5 checking allows us
|
|
|
|
to fail if we are not talking to who we think we should */
|
|
|
|
my_setopt_str(curl, CURLOPT_SSH_HOST_PUBLIC_KEY_MD5,
|
|
|
|
config->hostpubmd5);
|
2017-08-05 05:26:04 -04:00
|
|
|
|
|
|
|
/* new in libcurl 7.56.0 */
|
|
|
|
if(config->ssh_compression)
|
|
|
|
my_setopt(curl, CURLOPT_SSH_COMPRESSION, 1L);
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if(config->cacert)
|
|
|
|
my_setopt_str(curl, CURLOPT_CAINFO, config->cacert);
|
2016-11-16 12:49:15 -05:00
|
|
|
if(config->proxy_cacert)
|
|
|
|
my_setopt_str(curl, CURLOPT_PROXY_CAINFO, config->proxy_cacert);
|
2017-02-21 22:21:17 -05:00
|
|
|
|
2016-03-28 14:28:23 -04:00
|
|
|
if(config->capath) {
|
|
|
|
result = res_setopt_str(curl, CURLOPT_CAPATH, config->capath);
|
|
|
|
if(result == CURLE_NOT_BUILT_IN) {
|
2021-01-26 10:55:50 -05:00
|
|
|
warnf(global, "ignoring %s, not supported by libcurl\n",
|
2016-03-28 14:28:23 -04:00
|
|
|
capath_from_env?
|
|
|
|
"SSL_CERT_DIR environment variable":"--capath");
|
|
|
|
}
|
|
|
|
else if(result)
|
2019-09-23 11:11:22 -04:00
|
|
|
break;
|
2016-03-28 14:28:23 -04:00
|
|
|
}
|
2017-02-21 22:21:17 -05:00
|
|
|
/* For the time being if --proxy-capath is not set then we use the
|
|
|
|
--capath value for it, if any. See #1257 */
|
2019-06-24 06:45:01 -04:00
|
|
|
if((config->proxy_capath || config->capath) &&
|
|
|
|
!tool_setopt_skip(CURLOPT_PROXY_CAPATH)) {
|
2017-02-21 22:21:17 -05:00
|
|
|
result = res_setopt_str(curl, CURLOPT_PROXY_CAPATH,
|
|
|
|
(config->proxy_capath ?
|
|
|
|
config->proxy_capath :
|
|
|
|
config->capath));
|
|
|
|
if(result == CURLE_NOT_BUILT_IN) {
|
|
|
|
if(config->proxy_capath) {
|
2021-01-26 10:55:50 -05:00
|
|
|
warnf(global,
|
2017-02-21 22:21:17 -05:00
|
|
|
"ignoring --proxy-capath, not supported by libcurl\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(result)
|
2019-09-23 11:11:22 -04:00
|
|
|
break;
|
2017-02-21 22:21:17 -05:00
|
|
|
}
|
2016-11-16 12:49:15 -05:00
|
|
|
|
2011-10-04 18:03:20 -04:00
|
|
|
if(config->crlfile)
|
|
|
|
my_setopt_str(curl, CURLOPT_CRLFILE, config->crlfile);
|
2016-11-16 12:49:15 -05:00
|
|
|
if(config->proxy_crlfile)
|
|
|
|
my_setopt_str(curl, CURLOPT_PROXY_CRLFILE, config->proxy_crlfile);
|
|
|
|
else if(config->crlfile) /* CURLOPT_PROXY_CRLFILE default is crlfile */
|
|
|
|
my_setopt_str(curl, CURLOPT_PROXY_CRLFILE, config->crlfile);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2014-09-30 22:31:17 -04:00
|
|
|
if(config->pinnedpubkey)
|
|
|
|
my_setopt_str(curl, CURLOPT_PINNEDPUBLICKEY, config->pinnedpubkey);
|
|
|
|
|
2020-08-29 08:09:24 -04:00
|
|
|
if(config->ssl_ec_curves)
|
|
|
|
my_setopt_str(curl, CURLOPT_SSL_EC_CURVES, config->ssl_ec_curves);
|
|
|
|
|
2011-10-04 18:03:20 -04:00
|
|
|
if(curlinfo->features & CURL_VERSION_SSL) {
|
2018-02-19 08:31:06 -05:00
|
|
|
/* Check if config->cert is a PKCS#11 URI and set the
|
|
|
|
* config->cert_type if necessary */
|
|
|
|
if(config->cert) {
|
|
|
|
if(!config->cert_type) {
|
|
|
|
if(is_pkcs11_uri(config->cert)) {
|
|
|
|
config->cert_type = strdup("ENG");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if config->key is a PKCS#11 URI and set the
|
|
|
|
* config->key_type if necessary */
|
|
|
|
if(config->key) {
|
|
|
|
if(!config->key_type) {
|
|
|
|
if(is_pkcs11_uri(config->key)) {
|
|
|
|
config->key_type = strdup("ENG");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if config->proxy_cert is a PKCS#11 URI and set the
|
|
|
|
* config->proxy_type if necessary */
|
|
|
|
if(config->proxy_cert) {
|
|
|
|
if(!config->proxy_cert_type) {
|
|
|
|
if(is_pkcs11_uri(config->proxy_cert)) {
|
|
|
|
config->proxy_cert_type = strdup("ENG");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if config->proxy_key is a PKCS#11 URI and set the
|
|
|
|
* config->proxy_key_type if necessary */
|
|
|
|
if(config->proxy_key) {
|
|
|
|
if(!config->proxy_key_type) {
|
|
|
|
if(is_pkcs11_uri(config->proxy_key)) {
|
|
|
|
config->proxy_key_type = strdup("ENG");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-15 04:47:46 -04:00
|
|
|
/* In debug build of curl tool, using
|
|
|
|
* --cert loadmem=<filename>:<password> --cert-type p12
|
|
|
|
* must do the same thing than classic:
|
|
|
|
* --cert <filename>:<password> --cert-type p12
|
|
|
|
* but is designed to test blob */
|
|
|
|
#if defined(CURLDEBUG) || defined(DEBUGBUILD)
|
|
|
|
if(config->cert && (strlen(config->cert) > 8) &&
|
|
|
|
(memcmp(config->cert, "loadmem=",8) == 0)) {
|
|
|
|
FILE *fInCert = fopen(config->cert + 8, "rb");
|
|
|
|
void *certdata = NULL;
|
|
|
|
long filesize = 0;
|
|
|
|
bool continue_reading = fInCert != NULL;
|
|
|
|
if(continue_reading)
|
|
|
|
continue_reading = fseek(fInCert, 0, SEEK_END) == 0;
|
|
|
|
if(continue_reading)
|
|
|
|
filesize = ftell(fInCert);
|
|
|
|
if(filesize < 0)
|
|
|
|
continue_reading = FALSE;
|
|
|
|
if(continue_reading)
|
|
|
|
continue_reading = fseek(fInCert, 0, SEEK_SET) == 0;
|
|
|
|
if(continue_reading)
|
|
|
|
certdata = malloc(((size_t)filesize) + 1);
|
|
|
|
if((!certdata) ||
|
|
|
|
((int)fread(certdata, (size_t)filesize, 1, fInCert) != 1))
|
|
|
|
continue_reading = FALSE;
|
|
|
|
if(fInCert)
|
|
|
|
fclose(fInCert);
|
|
|
|
if((filesize > 0) && continue_reading) {
|
|
|
|
struct curl_blob structblob;
|
|
|
|
structblob.data = certdata;
|
|
|
|
structblob.len = (size_t)filesize;
|
|
|
|
structblob.flags = CURL_BLOB_COPY;
|
|
|
|
my_setopt_str(curl, CURLOPT_SSLCERT_BLOB, &structblob);
|
|
|
|
/* if test run well, we are sure we don't reuse
|
|
|
|
* original mem pointer */
|
|
|
|
memset(certdata, 0, (size_t)filesize);
|
|
|
|
}
|
|
|
|
free(certdata);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
2015-03-28 06:51:05 -04:00
|
|
|
my_setopt_str(curl, CURLOPT_SSLCERT, config->cert);
|
2016-11-16 12:49:15 -05:00
|
|
|
my_setopt_str(curl, CURLOPT_PROXY_SSLCERT, config->proxy_cert);
|
2015-03-28 06:51:05 -04:00
|
|
|
my_setopt_str(curl, CURLOPT_SSLCERTTYPE, config->cert_type);
|
2016-11-16 12:49:15 -05:00
|
|
|
my_setopt_str(curl, CURLOPT_PROXY_SSLCERTTYPE,
|
|
|
|
config->proxy_cert_type);
|
2020-05-15 04:47:46 -04:00
|
|
|
|
|
|
|
|
|
|
|
#if defined(CURLDEBUG) || defined(DEBUGBUILD)
|
|
|
|
if(config->key && (strlen(config->key) > 8) &&
|
|
|
|
(memcmp(config->key, "loadmem=",8) == 0)) {
|
|
|
|
FILE *fInCert = fopen(config->key + 8, "rb");
|
|
|
|
void *certdata = NULL;
|
|
|
|
long filesize = 0;
|
|
|
|
bool continue_reading = fInCert != NULL;
|
|
|
|
if(continue_reading)
|
|
|
|
continue_reading = fseek(fInCert, 0, SEEK_END) == 0;
|
|
|
|
if(continue_reading)
|
|
|
|
filesize = ftell(fInCert);
|
|
|
|
if(filesize < 0)
|
|
|
|
continue_reading = FALSE;
|
|
|
|
if(continue_reading)
|
|
|
|
continue_reading = fseek(fInCert, 0, SEEK_SET) == 0;
|
|
|
|
if(continue_reading)
|
|
|
|
certdata = malloc(((size_t)filesize) + 1);
|
|
|
|
if((!certdata) ||
|
|
|
|
((int)fread(certdata, (size_t)filesize, 1, fInCert) != 1))
|
|
|
|
continue_reading = FALSE;
|
|
|
|
if(fInCert)
|
|
|
|
fclose(fInCert);
|
|
|
|
if((filesize > 0) && continue_reading) {
|
|
|
|
struct curl_blob structblob;
|
|
|
|
structblob.data = certdata;
|
|
|
|
structblob.len = (size_t)filesize;
|
|
|
|
structblob.flags = CURL_BLOB_COPY;
|
|
|
|
my_setopt_str(curl, CURLOPT_SSLKEY_BLOB, &structblob);
|
|
|
|
/* if test run well, we are sure we don't reuse
|
|
|
|
* original mem pointer */
|
|
|
|
memset(certdata, 0, (size_t)filesize);
|
|
|
|
}
|
|
|
|
free(certdata);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
2015-03-28 06:51:05 -04:00
|
|
|
my_setopt_str(curl, CURLOPT_SSLKEY, config->key);
|
2016-11-16 12:49:15 -05:00
|
|
|
my_setopt_str(curl, CURLOPT_PROXY_SSLKEY, config->proxy_key);
|
2015-03-28 06:51:05 -04:00
|
|
|
my_setopt_str(curl, CURLOPT_SSLKEYTYPE, config->key_type);
|
2016-11-16 12:49:15 -05:00
|
|
|
my_setopt_str(curl, CURLOPT_PROXY_SSLKEYTYPE,
|
|
|
|
config->proxy_key_type);
|
2020-07-09 06:04:55 -04:00
|
|
|
my_setopt_str(curl, CURLOPT_AWS_SIGV4,
|
2021-01-25 09:02:09 -05:00
|
|
|
config->aws_sigv4);
|
2015-03-28 06:51:05 -04:00
|
|
|
|
2011-10-04 18:03:20 -04:00
|
|
|
if(config->insecure_ok) {
|
|
|
|
my_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
2012-11-06 16:27:25 -05:00
|
|
|
my_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
my_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
|
|
|
|
/* libcurl default is strict verifyhost -> 2L */
|
|
|
|
/* my_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L); */
|
|
|
|
}
|
2021-02-11 17:09:59 -05:00
|
|
|
|
|
|
|
if(config->doh_insecure_ok) {
|
|
|
|
my_setopt(curl, CURLOPT_DOH_SSL_VERIFYPEER, 0L);
|
|
|
|
my_setopt(curl, CURLOPT_DOH_SSL_VERIFYHOST, 0L);
|
|
|
|
}
|
|
|
|
|
2016-11-16 12:49:15 -05:00
|
|
|
if(config->proxy_insecure_ok) {
|
|
|
|
my_setopt(curl, CURLOPT_PROXY_SSL_VERIFYPEER, 0L);
|
|
|
|
my_setopt(curl, CURLOPT_PROXY_SSL_VERIFYHOST, 0L);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
my_setopt(curl, CURLOPT_PROXY_SSL_VERIFYPEER, 1L);
|
|
|
|
}
|
2014-06-16 14:47:26 -04:00
|
|
|
|
|
|
|
if(config->verifystatus)
|
|
|
|
my_setopt(curl, CURLOPT_SSL_VERIFYSTATUS, 1L);
|
2015-02-14 12:17:04 -05:00
|
|
|
|
2021-02-11 17:09:59 -05:00
|
|
|
if(config->doh_verifystatus)
|
|
|
|
my_setopt(curl, CURLOPT_DOH_SSL_VERIFYSTATUS, 1L);
|
|
|
|
|
2015-02-14 12:17:04 -05:00
|
|
|
if(config->falsestart)
|
|
|
|
my_setopt(curl, CURLOPT_SSL_FALSESTART, 1L);
|
2015-03-28 06:51:05 -04:00
|
|
|
|
2016-12-13 15:10:00 -05:00
|
|
|
my_setopt_enum(curl, CURLOPT_SSLVERSION,
|
|
|
|
config->ssl_version | config->ssl_version_max);
|
2016-11-16 12:49:15 -05:00
|
|
|
my_setopt_enum(curl, CURLOPT_PROXY_SSLVERSION,
|
|
|
|
config->proxy_ssl_version);
|
2020-05-10 05:51:42 -04:00
|
|
|
|
|
|
|
{
|
|
|
|
long mask =
|
2021-02-27 16:27:31 -05:00
|
|
|
(config->ssl_allow_beast ?
|
|
|
|
CURLSSLOPT_ALLOW_BEAST : 0) |
|
|
|
|
(config->ssl_no_revoke ?
|
|
|
|
CURLSSLOPT_NO_REVOKE : 0) |
|
2020-05-10 05:51:42 -04:00
|
|
|
(config->ssl_revoke_best_effort ?
|
|
|
|
CURLSSLOPT_REVOKE_BEST_EFFORT : 0) |
|
|
|
|
(config->native_ca_store ?
|
|
|
|
CURLSSLOPT_NATIVE_CA : 0) |
|
2021-02-27 16:27:31 -05:00
|
|
|
(config->ssl_auto_client_cert ?
|
|
|
|
CURLSSLOPT_AUTO_CLIENT_CERT : 0);
|
2020-05-10 05:51:42 -04:00
|
|
|
|
|
|
|
if(mask)
|
|
|
|
my_setopt_bitmask(curl, CURLOPT_SSL_OPTIONS, mask);
|
|
|
|
}
|
|
|
|
|
2021-02-27 16:27:31 -05:00
|
|
|
{
|
|
|
|
long mask =
|
|
|
|
(config->proxy_ssl_allow_beast ?
|
|
|
|
CURLSSLOPT_ALLOW_BEAST : 0) |
|
|
|
|
(config->proxy_ssl_auto_client_cert ?
|
|
|
|
CURLSSLOPT_AUTO_CLIENT_CERT : 0);
|
|
|
|
|
|
|
|
if(mask)
|
|
|
|
my_setopt_bitmask(curl, CURLOPT_PROXY_SSL_OPTIONS, mask);
|
|
|
|
}
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
2020-05-10 05:51:42 -04:00
|
|
|
|
2015-03-23 05:51:49 -04:00
|
|
|
if(config->path_as_is)
|
|
|
|
my_setopt(curl, CURLOPT_PATH_AS_IS, 1L);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2020-11-12 18:37:21 -05:00
|
|
|
if((built_in_protos & (CURLPROTO_SCP|CURLPROTO_SFTP)) &&
|
|
|
|
!config->insecure_ok) {
|
|
|
|
char *home = homedir(NULL);
|
|
|
|
if(home) {
|
|
|
|
char *file = aprintf("%s/.ssh/known_hosts", home);
|
|
|
|
if(file) {
|
|
|
|
/* new in curl 7.19.6 */
|
|
|
|
result = res_setopt_str(curl, CURLOPT_SSH_KNOWNHOSTS, file);
|
|
|
|
curl_free(file);
|
|
|
|
if(result == CURLE_UNKNOWN_OPTION)
|
|
|
|
/* libssh2 version older than 1.1.1 */
|
|
|
|
result = CURLE_OK;
|
2019-12-02 06:00:41 -05:00
|
|
|
}
|
2020-11-12 18:37:21 -05:00
|
|
|
Curl_safefree(home);
|
2014-12-16 02:35:47 -05:00
|
|
|
if(result)
|
2019-09-23 11:11:22 -04:00
|
|
|
break;
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
2020-11-12 18:37:21 -05:00
|
|
|
else
|
|
|
|
warnf(global, "No home dir, couldn't find known_hosts file!");
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if(config->no_body || config->remote_time) {
|
|
|
|
/* no body or use remote time */
|
2013-07-22 12:08:23 -04:00
|
|
|
my_setopt(curl, CURLOPT_FILETIME, 1L);
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
|
|
|
|
2013-07-22 12:08:23 -04:00
|
|
|
my_setopt(curl, CURLOPT_CRLF, config->crlf?1L:0L);
|
2012-02-23 04:43:37 -05:00
|
|
|
my_setopt_slist(curl, CURLOPT_QUOTE, config->quote);
|
|
|
|
my_setopt_slist(curl, CURLOPT_POSTQUOTE, config->postquote);
|
|
|
|
my_setopt_slist(curl, CURLOPT_PREQUOTE, config->prequote);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2021-02-25 12:12:28 -05:00
|
|
|
if(config->cookies) {
|
|
|
|
struct curlx_dynbuf cookies;
|
|
|
|
struct curl_slist *cl;
|
|
|
|
CURLcode ret;
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2021-02-25 12:12:28 -05:00
|
|
|
/* The maximum size needs to match MAX_NAME in cookie.h */
|
|
|
|
curlx_dyn_init(&cookies, 4096);
|
|
|
|
for(cl = config->cookies; cl; cl = cl->next) {
|
|
|
|
if(cl == config->cookies)
|
|
|
|
ret = curlx_dyn_addf(&cookies, "%s", cl->data);
|
|
|
|
else
|
|
|
|
ret = curlx_dyn_addf(&cookies, ";%s", cl->data);
|
|
|
|
|
|
|
|
if(ret) {
|
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
my_setopt_str(curl, CURLOPT_COOKIE, curlx_dyn_ptr(&cookies));
|
|
|
|
curlx_dyn_free(&cookies);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(config->cookiefiles) {
|
|
|
|
struct curl_slist *cfl;
|
|
|
|
|
|
|
|
for(cfl = config->cookiefiles; cfl; cfl = cfl->next)
|
|
|
|
my_setopt_str(curl, CURLOPT_COOKIEFILE, cfl->data);
|
|
|
|
}
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2014-05-05 08:16:43 -04:00
|
|
|
/* new in libcurl 7.9 */
|
|
|
|
if(config->cookiejar)
|
|
|
|
my_setopt_str(curl, CURLOPT_COOKIEJAR, config->cookiejar);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2014-05-05 08:16:43 -04:00
|
|
|
/* new in libcurl 7.9.7 */
|
|
|
|
my_setopt(curl, CURLOPT_COOKIESESSION, config->cookiesession?1L:0L);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2013-07-22 12:08:23 -04:00
|
|
|
my_setopt_enum(curl, CURLOPT_TIMECONDITION, (long)config->timecond);
|
2018-02-05 15:57:39 -05:00
|
|
|
my_setopt(curl, CURLOPT_TIMEVALUE_LARGE, config->condtime);
|
2011-10-04 18:03:20 -04:00
|
|
|
my_setopt_str(curl, CURLOPT_CUSTOMREQUEST, config->customrequest);
|
2015-08-29 17:56:28 -04:00
|
|
|
customrequest_helper(config, config->httpreq, config->customrequest);
|
2014-03-01 08:00:31 -05:00
|
|
|
my_setopt(curl, CURLOPT_STDERR, global->errors);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
|
|
|
/* three new ones in libcurl 7.3: */
|
|
|
|
my_setopt_str(curl, CURLOPT_INTERFACE, config->iface);
|
|
|
|
my_setopt_str(curl, CURLOPT_KRBLEVEL, config->krblevel);
|
2019-07-20 13:14:00 -04:00
|
|
|
progressbarinit(&per->progressbar, config);
|
2019-06-18 16:30:54 -04:00
|
|
|
|
2014-03-01 08:20:20 -05:00
|
|
|
if((global->progressmode == CURL_PROGRESS_BAR) &&
|
|
|
|
!global->noprogress && !global->mute) {
|
2011-10-04 18:03:20 -04:00
|
|
|
/* we want the alternative style, then we have to implement it
|
|
|
|
ourselves! */
|
2013-10-13 13:39:41 -04:00
|
|
|
my_setopt(curl, CURLOPT_XFERINFOFUNCTION, tool_progress_cb);
|
2019-11-26 03:16:19 -05:00
|
|
|
my_setopt(curl, CURLOPT_XFERINFODATA, per);
|
|
|
|
}
|
|
|
|
else if(per->uploadfile && !strcmp(per->uploadfile, ".")) {
|
|
|
|
/* when reading from stdin in non-blocking mode, we use the progress
|
|
|
|
function to unpause a busy read */
|
|
|
|
my_setopt(curl, CURLOPT_NOPROGRESS, 0L);
|
|
|
|
my_setopt(curl, CURLOPT_XFERINFOFUNCTION, tool_readbusy_cb);
|
|
|
|
my_setopt(curl, CURLOPT_XFERINFODATA, per);
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
|
|
|
|
2013-09-13 13:50:11 -04:00
|
|
|
/* new in libcurl 7.24.0: */
|
|
|
|
if(config->dns_servers)
|
|
|
|
my_setopt_str(curl, CURLOPT_DNS_SERVERS, config->dns_servers);
|
|
|
|
|
2013-02-09 16:18:02 -05:00
|
|
|
/* new in libcurl 7.33.0: */
|
2013-09-13 13:50:11 -04:00
|
|
|
if(config->dns_interface)
|
|
|
|
my_setopt_str(curl, CURLOPT_DNS_INTERFACE, config->dns_interface);
|
|
|
|
if(config->dns_ipv4_addr)
|
|
|
|
my_setopt_str(curl, CURLOPT_DNS_LOCAL_IP4, config->dns_ipv4_addr);
|
|
|
|
if(config->dns_ipv6_addr)
|
2013-02-09 16:18:02 -05:00
|
|
|
my_setopt_str(curl, CURLOPT_DNS_LOCAL_IP6, config->dns_ipv6_addr);
|
|
|
|
|
2011-10-04 18:03:20 -04:00
|
|
|
/* new in libcurl 7.6.2: */
|
2012-02-23 04:43:37 -05:00
|
|
|
my_setopt_slist(curl, CURLOPT_TELNETOPTIONS, config->telnet_options);
|
2019-06-18 16:30:54 -04:00
|
|
|
|
2011-10-04 18:03:20 -04:00
|
|
|
/* new in libcurl 7.7: */
|
|
|
|
my_setopt_str(curl, CURLOPT_RANDOM_FILE, config->random_file);
|
2013-07-22 12:08:23 -04:00
|
|
|
my_setopt_str(curl, CURLOPT_EGDSOCKET, config->egd_file);
|
2013-04-30 10:23:39 -04:00
|
|
|
my_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS,
|
|
|
|
(long)(config->connecttimeout * 1000));
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2018-09-06 03:16:02 -04:00
|
|
|
if(config->doh_url)
|
|
|
|
my_setopt_str(curl, CURLOPT_DOH_URL, config->doh_url);
|
|
|
|
|
2011-10-04 18:03:20 -04:00
|
|
|
if(config->cipher_list)
|
|
|
|
my_setopt_str(curl, CURLOPT_SSL_CIPHER_LIST, config->cipher_list);
|
|
|
|
|
2016-11-16 12:49:15 -05:00
|
|
|
if(config->proxy_cipher_list)
|
|
|
|
my_setopt_str(curl, CURLOPT_PROXY_SSL_CIPHER_LIST,
|
|
|
|
config->proxy_cipher_list);
|
|
|
|
|
2018-05-29 10:12:52 -04:00
|
|
|
if(config->cipher13_list)
|
|
|
|
my_setopt_str(curl, CURLOPT_TLS13_CIPHERS, config->cipher13_list);
|
|
|
|
|
|
|
|
if(config->proxy_cipher13_list)
|
2018-08-31 19:40:55 -04:00
|
|
|
my_setopt_str(curl, CURLOPT_PROXY_TLS13_CIPHERS,
|
2018-05-29 10:12:52 -04:00
|
|
|
config->proxy_cipher13_list);
|
|
|
|
|
2011-10-04 18:03:20 -04:00
|
|
|
/* new in libcurl 7.9.2: */
|
|
|
|
if(config->disable_epsv)
|
|
|
|
/* disable it */
|
2013-07-22 12:08:23 -04:00
|
|
|
my_setopt(curl, CURLOPT_FTP_USE_EPSV, 0L);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
|
|
|
/* new in libcurl 7.10.5 */
|
|
|
|
if(config->disable_eprt)
|
|
|
|
/* disable it */
|
2013-07-22 12:08:23 -04:00
|
|
|
my_setopt(curl, CURLOPT_FTP_USE_EPRT, 0L);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2014-02-27 15:51:49 -05:00
|
|
|
if(global->tracetype != TRACE_NONE) {
|
2011-10-04 18:03:20 -04:00
|
|
|
my_setopt(curl, CURLOPT_DEBUGFUNCTION, tool_debug_cb);
|
|
|
|
my_setopt(curl, CURLOPT_DEBUGDATA, config);
|
2013-07-22 12:08:23 -04:00
|
|
|
my_setopt(curl, CURLOPT_VERBOSE, 1L);
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* new in curl 7.9.3 */
|
|
|
|
if(config->engine) {
|
2014-12-16 02:35:47 -05:00
|
|
|
result = res_setopt_str(curl, CURLOPT_SSLENGINE, config->engine);
|
|
|
|
if(result)
|
2019-09-23 11:11:22 -04:00
|
|
|
break;
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
|
|
|
|
2016-04-22 09:25:13 -04:00
|
|
|
/* new in curl 7.10.7, extended in 7.19.4. Modified to use
|
|
|
|
CREATE_DIR_RETRY in 7.49.0 */
|
2011-10-04 18:03:20 -04:00
|
|
|
my_setopt(curl, CURLOPT_FTP_CREATE_MISSING_DIRS,
|
2016-04-22 09:25:13 -04:00
|
|
|
(long)(config->ftp_create_dirs?
|
|
|
|
CURLFTP_CREATE_DIR_RETRY:
|
|
|
|
CURLFTP_CREATE_DIR_NONE));
|
2011-10-04 18:03:20 -04:00
|
|
|
|
|
|
|
/* new in curl 7.10.8 */
|
|
|
|
if(config->max_filesize)
|
|
|
|
my_setopt(curl, CURLOPT_MAXFILESIZE_LARGE,
|
|
|
|
config->max_filesize);
|
|
|
|
|
2020-10-04 17:05:21 -04:00
|
|
|
my_setopt(curl, CURLOPT_IPRESOLVE, config->ip_version);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
|
|
|
/* new in curl 7.15.5 */
|
|
|
|
if(config->ftp_ssl_reqd)
|
2013-07-22 13:43:08 -04:00
|
|
|
my_setopt_enum(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
|
|
|
/* new in curl 7.11.0 */
|
|
|
|
else if(config->ftp_ssl)
|
2013-07-22 13:43:08 -04:00
|
|
|
my_setopt_enum(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_TRY);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
|
|
|
/* new in curl 7.16.0 */
|
|
|
|
else if(config->ftp_ssl_control)
|
2013-07-22 13:43:08 -04:00
|
|
|
my_setopt_enum(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_CONTROL);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
|
|
|
/* new in curl 7.16.1 */
|
|
|
|
if(config->ftp_ssl_ccc)
|
2013-07-22 12:08:23 -04:00
|
|
|
my_setopt_enum(curl, CURLOPT_FTP_SSL_CCC,
|
|
|
|
(long)config->ftp_ssl_ccc_mode);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2015-06-18 10:57:38 -04:00
|
|
|
/* new in curl 7.19.4 */
|
|
|
|
if(config->socks5_gssapi_nec)
|
|
|
|
my_setopt_str(curl, CURLOPT_SOCKS5_GSSAPI_NEC,
|
|
|
|
config->socks5_gssapi_nec);
|
|
|
|
|
2017-05-19 12:11:47 -04:00
|
|
|
/* new in curl 7.55.0 */
|
|
|
|
if(config->socks5_auth)
|
|
|
|
my_setopt_bitmask(curl, CURLOPT_SOCKS5_AUTH,
|
|
|
|
(long)config->socks5_auth);
|
|
|
|
|
2015-06-18 10:57:38 -04:00
|
|
|
/* new in curl 7.43.0 */
|
|
|
|
if(config->proxy_service_name)
|
|
|
|
my_setopt_str(curl, CURLOPT_PROXY_SERVICE_NAME,
|
|
|
|
config->proxy_service_name);
|
|
|
|
|
|
|
|
/* new in curl 7.43.0 */
|
|
|
|
if(config->service_name)
|
|
|
|
my_setopt_str(curl, CURLOPT_SERVICE_NAME,
|
|
|
|
config->service_name);
|
2015-03-29 08:52:31 -04:00
|
|
|
|
2011-10-04 18:03:20 -04:00
|
|
|
/* curl 7.13.0 */
|
|
|
|
my_setopt_str(curl, CURLOPT_FTP_ACCOUNT, config->ftp_account);
|
2013-07-22 12:08:23 -04:00
|
|
|
my_setopt(curl, CURLOPT_IGNORE_CONTENT_LENGTH, config->ignorecl?1L:0L);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
|
|
|
/* curl 7.14.2 */
|
2013-07-22 12:08:23 -04:00
|
|
|
my_setopt(curl, CURLOPT_FTP_SKIP_PASV_IP, config->ftp_skip_ip?1L:0L);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
|
|
|
/* curl 7.15.1 */
|
2013-07-22 12:08:23 -04:00
|
|
|
my_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long)config->ftp_filemethod);
|
2019-06-18 16:30:54 -04:00
|
|
|
|
2011-10-04 18:03:20 -04:00
|
|
|
/* curl 7.15.2 */
|
|
|
|
if(config->localport) {
|
2018-11-05 05:57:29 -05:00
|
|
|
my_setopt(curl, CURLOPT_LOCALPORT, config->localport);
|
|
|
|
my_setopt_str(curl, CURLOPT_LOCALPORTRANGE, config->localportrange);
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* curl 7.15.5 */
|
|
|
|
my_setopt_str(curl, CURLOPT_FTP_ALTERNATIVE_TO_USER,
|
|
|
|
config->ftp_alternative_to_user);
|
2019-06-18 16:30:54 -04:00
|
|
|
|
2011-10-04 18:03:20 -04:00
|
|
|
/* curl 7.16.0 */
|
|
|
|
if(config->disable_sessionid)
|
2013-07-22 12:08:23 -04:00
|
|
|
/* disable it */
|
|
|
|
my_setopt(curl, CURLOPT_SSL_SESSIONID_CACHE, 0L);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
|
|
|
/* curl 7.16.2 */
|
|
|
|
if(config->raw) {
|
2013-07-22 12:08:23 -04:00
|
|
|
my_setopt(curl, CURLOPT_HTTP_CONTENT_DECODING, 0L);
|
|
|
|
my_setopt(curl, CURLOPT_HTTP_TRANSFER_DECODING, 0L);
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* curl 7.17.1 */
|
|
|
|
if(!config->nokeepalive) {
|
2012-02-09 13:04:08 -05:00
|
|
|
my_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L);
|
2021-04-19 04:46:11 -04:00
|
|
|
if(config->alivetime) {
|
2012-02-09 13:04:08 -05:00
|
|
|
my_setopt(curl, CURLOPT_TCP_KEEPIDLE, config->alivetime);
|
|
|
|
my_setopt(curl, CURLOPT_TCP_KEEPINTVL, config->alivetime);
|
|
|
|
}
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
2012-02-09 13:04:08 -05:00
|
|
|
else
|
|
|
|
my_setopt(curl, CURLOPT_TCP_KEEPALIVE, 0L);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
|
|
|
/* curl 7.20.0 */
|
|
|
|
if(config->tftp_blksize)
|
|
|
|
my_setopt(curl, CURLOPT_TFTP_BLKSIZE, config->tftp_blksize);
|
|
|
|
|
|
|
|
if(config->mail_from)
|
|
|
|
my_setopt_str(curl, CURLOPT_MAIL_FROM, config->mail_from);
|
|
|
|
|
|
|
|
if(config->mail_rcpt)
|
2012-02-23 04:43:37 -05:00
|
|
|
my_setopt_slist(curl, CURLOPT_MAIL_RCPT, config->mail_rcpt);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2020-01-14 17:22:38 -05:00
|
|
|
/* curl 7.69.x */
|
|
|
|
my_setopt(curl, CURLOPT_MAIL_RCPT_ALLLOWFAILS,
|
|
|
|
config->mail_rcpt_allowfails ? 1L : 0L);
|
|
|
|
|
2011-10-04 18:03:20 -04:00
|
|
|
/* curl 7.20.x */
|
|
|
|
if(config->ftp_pret)
|
2013-07-22 12:08:23 -04:00
|
|
|
my_setopt(curl, CURLOPT_FTP_USE_PRET, 1L);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2021-02-26 05:18:09 -05:00
|
|
|
if(config->create_file_mode)
|
|
|
|
my_setopt(curl, CURLOPT_NEW_FILE_PERMS, config->create_file_mode);
|
|
|
|
|
2011-10-04 18:03:20 -04:00
|
|
|
if(config->proto_present)
|
2012-02-23 04:43:37 -05:00
|
|
|
my_setopt_flags(curl, CURLOPT_PROTOCOLS, config->proto);
|
2011-10-04 18:03:20 -04:00
|
|
|
if(config->proto_redir_present)
|
2012-02-23 04:43:37 -05:00
|
|
|
my_setopt_flags(curl, CURLOPT_REDIR_PROTOCOLS, config->proto_redir);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2012-06-08 23:42:39 -04:00
|
|
|
if(config->content_disposition
|
2016-05-01 16:07:04 -04:00
|
|
|
&& (urlnode->flags & GETOUT_USEREMOTE))
|
2019-07-20 13:14:00 -04:00
|
|
|
hdrcbdata->honor_cd_filename = TRUE;
|
2012-06-08 23:42:39 -04:00
|
|
|
else
|
2019-07-20 13:14:00 -04:00
|
|
|
hdrcbdata->honor_cd_filename = FALSE;
|
2012-06-08 23:42:39 -04:00
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
hdrcbdata->outs = outs;
|
|
|
|
hdrcbdata->heads = heads;
|
2019-10-30 04:43:14 -04:00
|
|
|
hdrcbdata->etag_save = etag_save;
|
2019-07-20 13:14:00 -04:00
|
|
|
hdrcbdata->global = global;
|
|
|
|
hdrcbdata->config = config;
|
2012-05-25 04:33:28 -04:00
|
|
|
|
|
|
|
my_setopt(curl, CURLOPT_HEADERFUNCTION, tool_header_cb);
|
2019-07-20 13:14:00 -04:00
|
|
|
my_setopt(curl, CURLOPT_HEADERDATA, per);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
|
|
|
if(config->resolve)
|
|
|
|
/* new in 7.21.3 */
|
2012-02-23 04:43:37 -05:00
|
|
|
my_setopt_slist(curl, CURLOPT_RESOLVE, config->resolve);
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2016-01-25 08:37:24 -05:00
|
|
|
if(config->connect_to)
|
|
|
|
/* new in 7.49.0 */
|
|
|
|
my_setopt_slist(curl, CURLOPT_CONNECT_TO, config->connect_to);
|
|
|
|
|
2011-10-04 18:03:20 -04:00
|
|
|
/* new in 7.21.4 */
|
|
|
|
if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP) {
|
|
|
|
if(config->tls_username)
|
|
|
|
my_setopt_str(curl, CURLOPT_TLSAUTH_USERNAME,
|
|
|
|
config->tls_username);
|
|
|
|
if(config->tls_password)
|
|
|
|
my_setopt_str(curl, CURLOPT_TLSAUTH_PASSWORD,
|
|
|
|
config->tls_password);
|
|
|
|
if(config->tls_authtype)
|
|
|
|
my_setopt_str(curl, CURLOPT_TLSAUTH_TYPE,
|
|
|
|
config->tls_authtype);
|
2016-11-16 12:49:15 -05:00
|
|
|
if(config->proxy_tls_username)
|
|
|
|
my_setopt_str(curl, CURLOPT_PROXY_TLSAUTH_USERNAME,
|
|
|
|
config->proxy_tls_username);
|
|
|
|
if(config->proxy_tls_password)
|
|
|
|
my_setopt_str(curl, CURLOPT_PROXY_TLSAUTH_PASSWORD,
|
|
|
|
config->proxy_tls_password);
|
|
|
|
if(config->proxy_tls_authtype)
|
|
|
|
my_setopt_str(curl, CURLOPT_PROXY_TLSAUTH_TYPE,
|
|
|
|
config->proxy_tls_authtype);
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* new in 7.22.0 */
|
|
|
|
if(config->gssapi_delegation)
|
|
|
|
my_setopt_str(curl, CURLOPT_GSSAPI_DELEGATION,
|
|
|
|
config->gssapi_delegation);
|
|
|
|
|
2012-02-16 07:19:47 -05:00
|
|
|
if(config->mail_auth)
|
|
|
|
my_setopt_str(curl, CURLOPT_MAIL_AUTH, config->mail_auth);
|
|
|
|
|
2019-04-19 09:26:47 -04:00
|
|
|
/* new in 7.66.0 */
|
|
|
|
if(config->sasl_authzid)
|
|
|
|
my_setopt_str(curl, CURLOPT_SASL_AUTHZID, config->sasl_authzid);
|
|
|
|
|
2013-04-27 18:02:20 -04:00
|
|
|
/* new in 7.31.0 */
|
2013-04-27 04:54:14 -04:00
|
|
|
if(config->sasl_ir)
|
2013-07-22 12:08:23 -04:00
|
|
|
my_setopt(curl, CURLOPT_SASL_IR, 1L);
|
2013-04-27 04:54:14 -04:00
|
|
|
|
2014-02-10 02:38:55 -05:00
|
|
|
if(config->nonpn) {
|
|
|
|
my_setopt(curl, CURLOPT_SSL_ENABLE_NPN, 0L);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(config->noalpn) {
|
|
|
|
my_setopt(curl, CURLOPT_SSL_ENABLE_ALPN, 0L);
|
|
|
|
}
|
|
|
|
|
2017-01-08 17:51:08 -05:00
|
|
|
/* new in 7.40.0, abstract support added in 7.53.0 */
|
|
|
|
if(config->unix_socket_path) {
|
|
|
|
if(config->abstract_unix_socket) {
|
|
|
|
my_setopt_str(curl, CURLOPT_ABSTRACT_UNIX_SOCKET,
|
|
|
|
config->unix_socket_path);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
my_setopt_str(curl, CURLOPT_UNIX_SOCKET_PATH,
|
|
|
|
config->unix_socket_path);
|
|
|
|
}
|
|
|
|
}
|
2019-04-19 09:26:47 -04:00
|
|
|
|
2015-08-22 21:49:26 -04:00
|
|
|
/* new in 7.45.0 */
|
|
|
|
if(config->proto_default)
|
|
|
|
my_setopt_str(curl, CURLOPT_DEFAULT_PROTOCOL, config->proto_default);
|
|
|
|
|
2015-12-14 07:29:13 -05:00
|
|
|
/* new in 7.47.0 */
|
|
|
|
if(config->expect100timeout > 0)
|
|
|
|
my_setopt_str(curl, CURLOPT_EXPECT_100_TIMEOUT_MS,
|
|
|
|
(long)(config->expect100timeout*1000));
|
|
|
|
|
2015-08-24 00:15:01 -04:00
|
|
|
/* new in 7.48.0 */
|
|
|
|
if(config->tftp_no_options)
|
|
|
|
my_setopt(curl, CURLOPT_TFTP_NO_OPTIONS, 1L);
|
|
|
|
|
2018-01-30 19:33:51 -05:00
|
|
|
/* new in 7.59.0 */
|
|
|
|
if(config->happy_eyeballs_timeout_ms != CURL_HET_DEFAULT)
|
2018-02-21 15:16:50 -05:00
|
|
|
my_setopt(curl, CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS,
|
2018-01-30 19:33:51 -05:00
|
|
|
config->happy_eyeballs_timeout_ms);
|
|
|
|
|
2016-12-01 07:05:04 -05:00
|
|
|
/* new in 7.60.0 */
|
|
|
|
if(config->haproxy_protocol)
|
|
|
|
my_setopt(curl, CURLOPT_HAPROXYPROTOCOL, 1L);
|
|
|
|
|
2018-02-25 14:17:25 -05:00
|
|
|
if(config->disallow_username_in_url)
|
|
|
|
my_setopt(curl, CURLOPT_DISALLOW_USERNAME_IN_URL, 1L);
|
|
|
|
|
2019-03-03 05:17:52 -05:00
|
|
|
if(config->altsvc)
|
|
|
|
my_setopt_str(curl, CURLOPT_ALTSVC, config->altsvc);
|
|
|
|
|
2020-11-02 17:17:01 -05:00
|
|
|
if(config->hsts)
|
2020-11-05 03:17:58 -05:00
|
|
|
my_setopt_str(curl, CURLOPT_HSTS, config->hsts);
|
2020-11-02 17:17:01 -05:00
|
|
|
|
2019-07-21 07:11:23 -04:00
|
|
|
/* initialize retry vars for loop below */
|
|
|
|
per->retry_sleep_default = (config->retry_delay) ?
|
|
|
|
config->retry_delay*1000L : RETRY_SLEEP_DEFAULT; /* ms */
|
|
|
|
per->retry_numretries = config->req_retry;
|
|
|
|
per->retry_sleep = per->retry_sleep_default; /* ms */
|
|
|
|
per->retrystart = tvnow();
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2019-09-23 11:11:22 -04:00
|
|
|
state->li++;
|
2019-11-13 05:33:29 -05:00
|
|
|
/* Here's looping around each globbed URL */
|
|
|
|
if(state->li >= urlnum) {
|
|
|
|
state->li = 0;
|
|
|
|
state->urlnum = 0; /* forced reglob of URLs */
|
|
|
|
glob_cleanup(state->urls);
|
|
|
|
state->urls = NULL;
|
|
|
|
state->up++;
|
|
|
|
Curl_safefree(state->uploadfile); /* clear it to get the next */
|
|
|
|
}
|
2019-09-23 11:11:22 -04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Free this URL node data without destroying the
|
|
|
|
the node itself nor modifying next pointer. */
|
|
|
|
Curl_safefree(urlnode->outfile);
|
|
|
|
Curl_safefree(urlnode->infile);
|
|
|
|
urlnode->flags = 0;
|
|
|
|
glob_cleanup(state->urls);
|
|
|
|
state->urls = NULL;
|
|
|
|
state->urlnum = 0;
|
|
|
|
|
|
|
|
Curl_safefree(state->outfiles);
|
|
|
|
Curl_safefree(state->uploadfile);
|
|
|
|
if(state->inglob) {
|
|
|
|
/* Free list of globbed upload files */
|
|
|
|
glob_cleanup(state->inglob);
|
|
|
|
state->inglob = NULL;
|
|
|
|
}
|
|
|
|
config->state.urlnode = urlnode->next;
|
|
|
|
state->up = 0;
|
|
|
|
continue;
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
|
|
|
}
|
2019-09-23 11:11:22 -04:00
|
|
|
break;
|
|
|
|
}
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2019-09-23 11:11:22 -04:00
|
|
|
if(!*added || result) {
|
|
|
|
*added = FALSE;
|
|
|
|
single_transfer_cleanup(config);
|
|
|
|
}
|
2019-07-20 13:14:00 -04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static long all_added; /* number of easy handles currently added */
|
|
|
|
|
2019-09-10 07:37:38 -04:00
|
|
|
/*
|
|
|
|
* add_parallel_transfers() sets 'morep' to TRUE if there are more transfers
|
|
|
|
* to add even after this call returns. sets 'addedp' to TRUE if one or more
|
|
|
|
* transfers were added.
|
|
|
|
*/
|
2019-09-23 11:11:22 -04:00
|
|
|
static CURLcode add_parallel_transfers(struct GlobalConfig *global,
|
|
|
|
CURLM *multi,
|
|
|
|
CURLSH *share,
|
|
|
|
bool *morep,
|
|
|
|
bool *addedp)
|
2019-07-20 13:14:00 -04:00
|
|
|
{
|
|
|
|
struct per_transfer *per;
|
2019-09-23 11:11:22 -04:00
|
|
|
CURLcode result = CURLE_OK;
|
2019-07-20 13:14:00 -04:00
|
|
|
CURLMcode mcode;
|
2020-09-05 11:44:24 -04:00
|
|
|
bool sleeping = FALSE;
|
2019-09-10 07:37:38 -04:00
|
|
|
*addedp = FALSE;
|
|
|
|
*morep = FALSE;
|
2019-09-30 17:24:49 -04:00
|
|
|
result = create_transfer(global, share, addedp);
|
2020-03-16 04:33:27 -04:00
|
|
|
if(result)
|
2019-09-23 11:11:22 -04:00
|
|
|
return result;
|
2019-07-20 13:14:00 -04:00
|
|
|
for(per = transfers; per && (all_added < global->parallel_max);
|
|
|
|
per = per->next) {
|
2019-09-23 11:11:22 -04:00
|
|
|
bool getadded = FALSE;
|
2019-07-20 13:14:00 -04:00
|
|
|
if(per->added)
|
|
|
|
/* already added */
|
|
|
|
continue;
|
2020-09-05 11:44:24 -04:00
|
|
|
if(per->startat && (time(NULL) < per->startat)) {
|
|
|
|
/* this is still delaying */
|
|
|
|
sleeping = TRUE;
|
|
|
|
continue;
|
|
|
|
}
|
2019-07-20 13:14:00 -04:00
|
|
|
|
|
|
|
result = pre_transfer(global, per);
|
|
|
|
if(result)
|
2020-10-28 06:00:31 -04:00
|
|
|
return result;
|
2019-07-20 13:14:00 -04:00
|
|
|
|
2019-10-17 04:05:53 -04:00
|
|
|
/* parallel connect means that we don't set PIPEWAIT since pipewait
|
|
|
|
will make libcurl prefer multiplexing */
|
|
|
|
(void)curl_easy_setopt(per->curl, CURLOPT_PIPEWAIT,
|
|
|
|
global->parallel_connect ? 0L : 1L);
|
2019-07-20 13:14:00 -04:00
|
|
|
(void)curl_easy_setopt(per->curl, CURLOPT_PRIVATE, per);
|
|
|
|
(void)curl_easy_setopt(per->curl, CURLOPT_XFERINFOFUNCTION, xferinfo_cb);
|
|
|
|
(void)curl_easy_setopt(per->curl, CURLOPT_XFERINFODATA, per);
|
|
|
|
|
|
|
|
mcode = curl_multi_add_handle(multi, per->curl);
|
|
|
|
if(mcode)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
2019-09-30 17:24:49 -04:00
|
|
|
|
|
|
|
result = create_transfer(global, share, &getadded);
|
2019-09-23 11:11:22 -04:00
|
|
|
if(result)
|
|
|
|
return result;
|
2019-07-20 13:14:00 -04:00
|
|
|
per->added = TRUE;
|
|
|
|
all_added++;
|
2019-09-10 07:37:38 -04:00
|
|
|
*addedp = TRUE;
|
2019-07-20 13:14:00 -04:00
|
|
|
}
|
2020-09-05 11:44:24 -04:00
|
|
|
*morep = (per || sleeping) ? TRUE : FALSE;
|
2019-07-20 13:14:00 -04:00
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CURLcode parallel_transfers(struct GlobalConfig *global,
|
|
|
|
CURLSH *share)
|
|
|
|
{
|
|
|
|
CURLM *multi;
|
|
|
|
CURLMcode mcode = CURLM_OK;
|
|
|
|
CURLcode result = CURLE_OK;
|
|
|
|
int still_running = 1;
|
|
|
|
struct timeval start = tvnow();
|
2019-09-10 07:37:38 -04:00
|
|
|
bool more_transfers;
|
|
|
|
bool added_transfers;
|
2020-09-05 11:44:24 -04:00
|
|
|
time_t tick = time(NULL);
|
2019-07-20 13:14:00 -04:00
|
|
|
|
|
|
|
multi = curl_multi_init();
|
|
|
|
if(!multi)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
|
2019-09-23 11:11:22 -04:00
|
|
|
result = add_parallel_transfers(global, multi, share,
|
2019-09-10 07:37:38 -04:00
|
|
|
&more_transfers, &added_transfers);
|
2020-01-04 10:27:56 -05:00
|
|
|
if(result) {
|
|
|
|
curl_multi_cleanup(multi);
|
2019-07-20 13:14:00 -04:00
|
|
|
return result;
|
2020-01-04 10:27:56 -05:00
|
|
|
}
|
2019-07-20 13:14:00 -04:00
|
|
|
|
2019-09-19 04:35:25 -04:00
|
|
|
while(!mcode && (still_running || more_transfers)) {
|
2019-07-29 07:41:00 -04:00
|
|
|
mcode = curl_multi_poll(multi, NULL, 0, 1000, NULL);
|
|
|
|
if(!mcode)
|
2019-07-20 13:14:00 -04:00
|
|
|
mcode = curl_multi_perform(multi, &still_running);
|
|
|
|
|
|
|
|
progress_meter(global, &start, FALSE);
|
|
|
|
|
|
|
|
if(!mcode) {
|
|
|
|
int rc;
|
|
|
|
CURLMsg *msg;
|
2020-09-05 11:44:24 -04:00
|
|
|
bool checkmore = FALSE;
|
2019-07-20 13:14:00 -04:00
|
|
|
do {
|
|
|
|
msg = curl_multi_info_read(multi, &rc);
|
|
|
|
if(msg) {
|
|
|
|
bool retry;
|
2020-09-05 11:44:24 -04:00
|
|
|
long delay;
|
2019-07-20 13:14:00 -04:00
|
|
|
struct per_transfer *ended;
|
|
|
|
CURL *easy = msg->easy_handle;
|
2021-04-20 01:51:56 -04:00
|
|
|
CURLcode tres = msg->data.result;
|
2019-07-20 13:14:00 -04:00
|
|
|
curl_easy_getinfo(easy, CURLINFO_PRIVATE, (void *)&ended);
|
|
|
|
curl_multi_remove_handle(multi, easy);
|
|
|
|
|
2021-04-20 01:51:56 -04:00
|
|
|
tres = post_per_transfer(global, ended, tres, &retry, &delay);
|
2019-07-20 13:14:00 -04:00
|
|
|
progress_finalize(ended); /* before it goes away */
|
|
|
|
all_added--; /* one fewer added */
|
2020-09-05 11:44:24 -04:00
|
|
|
checkmore = TRUE;
|
|
|
|
if(retry) {
|
2020-09-05 11:04:03 -04:00
|
|
|
ended->added = FALSE; /* add it again */
|
2020-09-05 11:44:24 -04:00
|
|
|
/* we delay retries in full integer seconds only */
|
|
|
|
ended->startat = delay ? time(NULL) + delay/1000 : 0;
|
|
|
|
}
|
2021-04-20 01:51:56 -04:00
|
|
|
else {
|
|
|
|
if(tres)
|
|
|
|
result = tres;
|
2020-09-05 11:04:03 -04:00
|
|
|
(void)del_per_transfer(ended);
|
2021-04-20 01:51:56 -04:00
|
|
|
}
|
2019-07-20 13:14:00 -04:00
|
|
|
}
|
|
|
|
} while(msg);
|
2020-09-05 11:44:24 -04:00
|
|
|
if(!checkmore) {
|
|
|
|
time_t tock = time(NULL);
|
|
|
|
if(tick != tock) {
|
|
|
|
checkmore = TRUE;
|
|
|
|
tick = tock;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(checkmore) {
|
2019-07-20 13:14:00 -04:00
|
|
|
/* one or more transfers completed, add more! */
|
2021-04-20 01:51:56 -04:00
|
|
|
CURLcode tres = add_parallel_transfers(global, multi, share,
|
|
|
|
&more_transfers,
|
|
|
|
&added_transfers);
|
|
|
|
if(tres)
|
|
|
|
result = tres;
|
2019-09-10 07:37:38 -04:00
|
|
|
if(added_transfers)
|
|
|
|
/* we added new ones, make sure the loop doesn't exit yet */
|
|
|
|
still_running = 1;
|
|
|
|
}
|
2019-07-20 13:14:00 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
(void)progress_meter(global, &start, TRUE);
|
|
|
|
|
|
|
|
/* Make sure to return some kind of error if there was a multi problem */
|
|
|
|
if(mcode) {
|
|
|
|
result = (mcode == CURLM_OUT_OF_MEMORY) ? CURLE_OUT_OF_MEMORY :
|
|
|
|
/* The other multi errors should never happen, so return
|
|
|
|
something suitably generic */
|
|
|
|
CURLE_BAD_FUNCTION_ARGUMENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
curl_multi_cleanup(multi);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CURLcode serial_transfers(struct GlobalConfig *global,
|
|
|
|
CURLSH *share)
|
|
|
|
{
|
|
|
|
CURLcode returncode = CURLE_OK;
|
|
|
|
CURLcode result = CURLE_OK;
|
|
|
|
struct per_transfer *per;
|
2019-09-23 11:11:22 -04:00
|
|
|
bool added = FALSE;
|
|
|
|
|
2019-09-30 17:24:49 -04:00
|
|
|
result = create_transfer(global, share, &added);
|
2019-09-23 11:11:22 -04:00
|
|
|
if(result || !added)
|
|
|
|
return result;
|
2019-07-20 13:14:00 -04:00
|
|
|
for(per = transfers; per;) {
|
|
|
|
bool retry;
|
2020-09-05 11:44:24 -04:00
|
|
|
long delay;
|
2019-09-23 11:11:22 -04:00
|
|
|
bool bailout = FALSE;
|
2019-07-20 13:14:00 -04:00
|
|
|
result = pre_transfer(global, per);
|
|
|
|
if(result)
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifndef CURL_DISABLE_LIBCURL_OPTION
|
|
|
|
if(global->libcurl) {
|
|
|
|
result = easysrc_perform();
|
|
|
|
if(result)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef CURLDEBUG
|
|
|
|
if(global->test_event_based)
|
|
|
|
result = curl_easy_perform_ev(per->curl);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
result = curl_easy_perform(per->curl);
|
|
|
|
|
2021-02-11 02:30:39 -05:00
|
|
|
returncode = post_per_transfer(global, per, result, &retry, &delay);
|
2020-09-05 11:44:24 -04:00
|
|
|
if(retry) {
|
|
|
|
tool_go_sleep(delay);
|
2019-07-20 13:14:00 -04:00
|
|
|
continue;
|
2020-09-05 11:44:24 -04:00
|
|
|
}
|
2019-09-11 10:32:11 -04:00
|
|
|
|
2019-09-23 11:11:22 -04:00
|
|
|
/* Bail out upon critical errors or --fail-early */
|
2021-02-11 02:30:39 -05:00
|
|
|
if(is_fatal_error(returncode) || (returncode && global->fail_early))
|
2019-09-23 11:11:22 -04:00
|
|
|
bailout = TRUE;
|
|
|
|
else {
|
|
|
|
/* setup the next one just before we delete this */
|
2019-09-30 17:24:49 -04:00
|
|
|
result = create_transfer(global, share, &added);
|
2019-09-23 11:11:22 -04:00
|
|
|
if(result)
|
|
|
|
bailout = TRUE;
|
|
|
|
}
|
|
|
|
|
2019-09-30 17:24:49 -04:00
|
|
|
per = del_per_transfer(per);
|
2019-07-20 13:14:00 -04:00
|
|
|
|
2019-09-23 11:11:22 -04:00
|
|
|
if(bailout)
|
2019-07-20 13:14:00 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(returncode)
|
|
|
|
/* returncode errors have priority */
|
|
|
|
result = returncode;
|
2019-09-23 11:11:22 -04:00
|
|
|
|
|
|
|
if(result)
|
|
|
|
single_transfer_cleanup(global->current);
|
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-09-30 17:24:49 -04:00
|
|
|
/* setup a transfer for the given config */
|
|
|
|
static CURLcode transfer_per_config(struct GlobalConfig *global,
|
|
|
|
struct OperationConfig *config,
|
|
|
|
CURLSH *share,
|
|
|
|
bool *added)
|
2019-07-20 13:14:00 -04:00
|
|
|
{
|
|
|
|
CURLcode result = CURLE_OK;
|
|
|
|
bool capath_from_env;
|
2019-09-23 11:11:22 -04:00
|
|
|
*added = FALSE;
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
/* Check we have a url */
|
|
|
|
if(!config->url_list || !config->url_list->url) {
|
|
|
|
helpf(global->errors, "no URL specified!\n");
|
|
|
|
return CURLE_FAILED_INIT;
|
|
|
|
}
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
/* On WIN32 we can't set the path to curl-ca-bundle.crt
|
|
|
|
* at compile time. So we look here for the file in two ways:
|
|
|
|
* 1: look at the environment variable CURL_CA_BUNDLE for a path
|
|
|
|
* 2: if #1 isn't found, use the windows API function SearchPath()
|
|
|
|
* to find it along the app's path (includes app's dir and CWD)
|
|
|
|
*
|
|
|
|
* We support the environment variable thing for non-Windows platforms
|
|
|
|
* too. Just for the sake of it.
|
|
|
|
*/
|
|
|
|
capath_from_env = false;
|
|
|
|
if(!config->cacert &&
|
|
|
|
!config->capath &&
|
2021-02-11 17:09:59 -05:00
|
|
|
(!config->insecure_ok || (config->doh_url && !config->doh_insecure_ok))) {
|
2019-07-20 13:14:00 -04:00
|
|
|
CURL *curltls = curl_easy_init();
|
|
|
|
struct curl_tlssessioninfo *tls_backend_info = NULL;
|
2014-03-01 08:49:28 -05:00
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
/* With the addition of CAINFO support for Schannel, this search could find
|
|
|
|
* a certificate bundle that was previously ignored. To maintain backward
|
|
|
|
* compatibility, only perform this search if not using Schannel.
|
|
|
|
*/
|
|
|
|
result = curl_easy_getinfo(curltls, CURLINFO_TLS_SSL_PTR,
|
|
|
|
&tls_backend_info);
|
|
|
|
if(result)
|
|
|
|
return result;
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
/* Set the CA cert locations specified in the environment. For Windows if
|
|
|
|
* no environment-specified filename is found then check for CA bundle
|
|
|
|
* default filename curl-ca-bundle.crt in the user's PATH.
|
|
|
|
*
|
|
|
|
* If Schannel is the selected SSL backend then these locations are
|
|
|
|
* ignored. We allow setting CA location for schannel only when explicitly
|
|
|
|
* specified by the user via CURLOPT_CAINFO / --cacert.
|
|
|
|
*/
|
|
|
|
if(tls_backend_info->backend != CURLSSLBACKEND_SCHANNEL) {
|
|
|
|
char *env;
|
|
|
|
env = curlx_getenv("CURL_CA_BUNDLE");
|
|
|
|
if(env) {
|
|
|
|
config->cacert = strdup(env);
|
|
|
|
if(!config->cacert) {
|
|
|
|
curl_free(env);
|
2019-12-09 10:15:37 -05:00
|
|
|
errorf(global, "out of memory\n");
|
2019-07-20 13:14:00 -04:00
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
env = curlx_getenv("SSL_CERT_DIR");
|
|
|
|
if(env) {
|
|
|
|
config->capath = strdup(env);
|
|
|
|
if(!config->capath) {
|
|
|
|
curl_free(env);
|
|
|
|
helpf(global->errors, "out of memory\n");
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
capath_from_env = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
env = curlx_getenv("SSL_CERT_FILE");
|
|
|
|
if(env) {
|
|
|
|
config->cacert = strdup(env);
|
|
|
|
if(!config->cacert) {
|
|
|
|
curl_free(env);
|
2019-12-09 10:15:37 -05:00
|
|
|
errorf(global, "out of memory\n");
|
2019-07-20 13:14:00 -04:00
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(env)
|
|
|
|
curl_free(env);
|
|
|
|
#ifdef WIN32
|
|
|
|
else {
|
|
|
|
result = FindWin32CACert(config, tls_backend_info->backend,
|
2020-07-23 15:28:14 -04:00
|
|
|
TEXT("curl-ca-bundle.crt"));
|
2019-07-20 13:14:00 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
curl_easy_cleanup(curltls);
|
|
|
|
}
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
if(!result)
|
2019-09-23 11:11:22 -04:00
|
|
|
result = single_transfer(global, config, share, capath_from_env, added);
|
2012-06-08 23:42:39 -04:00
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-09-23 11:11:22 -04:00
|
|
|
/*
|
2019-09-30 17:24:49 -04:00
|
|
|
* 'create_transfer' gets the details and sets up a new transfer if 'added'
|
2019-09-23 11:11:22 -04:00
|
|
|
* returns TRUE.
|
|
|
|
*/
|
2019-09-30 17:24:49 -04:00
|
|
|
static CURLcode create_transfer(struct GlobalConfig *global,
|
|
|
|
CURLSH *share,
|
|
|
|
bool *added)
|
2019-09-23 11:11:22 -04:00
|
|
|
{
|
|
|
|
CURLcode result = CURLE_OK;
|
|
|
|
*added = FALSE;
|
|
|
|
while(global->current) {
|
2019-09-30 17:24:49 -04:00
|
|
|
result = transfer_per_config(global, global->current, share, added);
|
2019-09-23 11:11:22 -04:00
|
|
|
if(!result && !*added) {
|
|
|
|
/* when one set is drained, continue to next */
|
|
|
|
global->current = global->current->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-09-30 17:24:49 -04:00
|
|
|
static CURLcode run_all_transfers(struct GlobalConfig *global,
|
2019-07-20 13:14:00 -04:00
|
|
|
CURLSH *share,
|
|
|
|
CURLcode result)
|
|
|
|
{
|
|
|
|
/* Save the values of noprogress and isatty to restore them later on */
|
|
|
|
bool orig_noprogress = global->noprogress;
|
|
|
|
bool orig_isatty = global->isatty;
|
|
|
|
struct per_transfer *per;
|
|
|
|
|
|
|
|
/* Time to actually do the transfers */
|
|
|
|
if(!result) {
|
|
|
|
if(global->parallel)
|
|
|
|
result = parallel_transfers(global, share);
|
|
|
|
else
|
|
|
|
result = serial_transfers(global, share);
|
|
|
|
}
|
2014-03-02 04:28:17 -05:00
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
/* cleanup if there are any left */
|
|
|
|
for(per = transfers; per;) {
|
|
|
|
bool retry;
|
2020-09-05 11:44:24 -04:00
|
|
|
long delay;
|
|
|
|
CURLcode result2 = post_per_transfer(global, per, result, &retry, &delay);
|
2019-09-23 11:11:22 -04:00
|
|
|
if(!result)
|
|
|
|
/* don't overwrite the original error */
|
|
|
|
result = result2;
|
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
/* Free list of given URLs */
|
|
|
|
clean_getout(per->config);
|
|
|
|
|
2019-09-30 17:24:49 -04:00
|
|
|
per = del_per_transfer(per);
|
2019-07-20 13:14:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset the global config variables */
|
|
|
|
global->noprogress = orig_noprogress;
|
|
|
|
global->isatty = orig_isatty;
|
2011-10-04 18:03:20 -04:00
|
|
|
|
2014-02-23 10:10:18 -05:00
|
|
|
|
2014-12-16 02:35:47 -05:00
|
|
|
return result;
|
2011-10-04 18:03:20 -04:00
|
|
|
}
|
2014-02-02 10:20:37 -05:00
|
|
|
|
2019-09-23 11:11:22 -04:00
|
|
|
CURLcode operate(struct GlobalConfig *global, int argc, argv_item_t argv[])
|
2014-02-02 10:20:37 -05:00
|
|
|
{
|
2014-02-22 13:57:02 -05:00
|
|
|
CURLcode result = CURLE_OK;
|
2021-02-26 09:00:51 -05:00
|
|
|
char *first_arg = argc > 1 ? curlx_convert_tchar_to_UTF8(argv[1]) : NULL;
|
2014-02-02 10:28:25 -05:00
|
|
|
|
2014-02-23 09:32:22 -05:00
|
|
|
/* Setup proper locale from environment */
|
|
|
|
#ifdef HAVE_SETLOCALE
|
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
#endif
|
2014-02-02 10:28:25 -05:00
|
|
|
|
2014-02-05 15:28:36 -05:00
|
|
|
/* Parse .curlrc if necessary */
|
2016-04-28 16:32:05 -04:00
|
|
|
if((argc == 1) ||
|
2020-12-26 10:20:54 -05:00
|
|
|
(first_arg && strncmp(first_arg, "-q", 2) &&
|
2019-04-12 16:59:40 -04:00
|
|
|
!curl_strequal(first_arg, "--disable"))) {
|
2019-09-23 11:11:22 -04:00
|
|
|
parseconfig(NULL, global); /* ignore possible failure */
|
2014-02-05 15:28:36 -05:00
|
|
|
|
|
|
|
/* If we had no arguments then make sure a url was specified in .curlrc */
|
2019-09-23 11:11:22 -04:00
|
|
|
if((argc < 2) && (!global->first->url_list)) {
|
|
|
|
helpf(global->errors, NULL);
|
2014-02-05 15:28:36 -05:00
|
|
|
result = CURLE_FAILED_INIT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-12 16:59:40 -04:00
|
|
|
curlx_unicodefree(first_arg);
|
|
|
|
|
2014-02-06 14:31:44 -05:00
|
|
|
if(!result) {
|
|
|
|
/* Parse the command line arguments */
|
2019-09-23 11:11:22 -04:00
|
|
|
ParameterError res = parse_args(global, argc, argv);
|
2014-02-06 14:31:44 -05:00
|
|
|
if(res) {
|
2014-02-22 15:58:43 -05:00
|
|
|
result = CURLE_OK;
|
|
|
|
|
2014-02-23 05:58:56 -05:00
|
|
|
/* Check if we were asked for the help */
|
|
|
|
if(res == PARAM_HELP_REQUESTED)
|
2020-09-02 14:11:20 -04:00
|
|
|
tool_help(global->help_category);
|
2014-02-23 05:37:44 -05:00
|
|
|
/* Check if we were asked for the manual */
|
2014-02-23 05:58:56 -05:00
|
|
|
else if(res == PARAM_MANUAL_REQUESTED)
|
2014-02-23 05:37:44 -05:00
|
|
|
hugehelp();
|
2014-02-23 05:16:36 -05:00
|
|
|
/* Check if we were asked for the version information */
|
2014-02-23 05:37:44 -05:00
|
|
|
else if(res == PARAM_VERSION_INFO_REQUESTED)
|
2014-02-23 05:16:36 -05:00
|
|
|
tool_version_info();
|
2014-02-22 15:58:43 -05:00
|
|
|
/* Check if we were asked to list the SSL engines */
|
2014-02-23 07:10:42 -05:00
|
|
|
else if(res == PARAM_ENGINES_REQUESTED)
|
2019-07-20 13:14:00 -04:00
|
|
|
tool_list_engines();
|
2015-08-22 21:49:26 -04:00
|
|
|
else if(res == PARAM_LIBCURL_UNSUPPORTED_PROTOCOL)
|
|
|
|
result = CURLE_UNSUPPORTED_PROTOCOL;
|
2014-02-23 05:58:56 -05:00
|
|
|
else
|
2014-02-06 14:31:44 -05:00
|
|
|
result = CURLE_FAILED_INIT;
|
2014-02-06 14:43:50 -05:00
|
|
|
}
|
2014-02-09 06:01:36 -05:00
|
|
|
else {
|
2014-03-02 04:28:17 -05:00
|
|
|
#ifndef CURL_DISABLE_LIBCURL_OPTION
|
2019-09-23 11:11:22 -04:00
|
|
|
if(global->libcurl) {
|
2015-09-21 02:21:38 -04:00
|
|
|
/* Initialise the libcurl source output */
|
2015-09-20 02:16:23 -04:00
|
|
|
result = easysrc_init();
|
2015-09-21 02:21:38 -04:00
|
|
|
}
|
2014-03-02 04:28:17 -05:00
|
|
|
#endif
|
2014-02-09 06:01:36 -05:00
|
|
|
|
2014-03-02 04:28:17 -05:00
|
|
|
/* Perform the main operations */
|
|
|
|
if(!result) {
|
|
|
|
size_t count = 0;
|
2019-09-23 11:11:22 -04:00
|
|
|
struct OperationConfig *operation = global->first;
|
2019-07-20 13:14:00 -04:00
|
|
|
CURLSH *share = curl_share_init();
|
|
|
|
if(!share) {
|
2019-07-22 15:43:41 -04:00
|
|
|
#ifndef CURL_DISABLE_LIBCURL_OPTION
|
2019-09-23 11:11:22 -04:00
|
|
|
if(global->libcurl) {
|
2019-07-22 15:43:41 -04:00
|
|
|
/* Cleanup the libcurl source output */
|
|
|
|
easysrc_cleanup();
|
|
|
|
}
|
|
|
|
#endif
|
2019-07-20 13:14:00 -04:00
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);
|
|
|
|
curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS);
|
|
|
|
curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION);
|
|
|
|
curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT);
|
|
|
|
curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_PSL);
|
2014-02-14 17:05:27 -05:00
|
|
|
|
2018-03-15 22:51:03 -04:00
|
|
|
/* Get the required arguments for each operation */
|
2019-07-20 13:14:00 -04:00
|
|
|
do {
|
2014-03-02 04:28:17 -05:00
|
|
|
result = get_args(operation, count++);
|
|
|
|
|
|
|
|
operation = operation->next;
|
2019-07-20 13:14:00 -04:00
|
|
|
} while(!result && operation);
|
2014-03-02 04:28:17 -05:00
|
|
|
|
|
|
|
/* Set the current operation pointer */
|
2019-09-23 11:11:22 -04:00
|
|
|
global->current = global->first;
|
2014-02-09 06:01:36 -05:00
|
|
|
|
2019-07-20 13:14:00 -04:00
|
|
|
/* now run! */
|
2019-09-30 17:24:49 -04:00
|
|
|
result = run_all_transfers(global, share, result);
|
2019-07-20 13:14:00 -04:00
|
|
|
|
|
|
|
curl_share_cleanup(share);
|
2014-03-02 04:28:17 -05:00
|
|
|
#ifndef CURL_DISABLE_LIBCURL_OPTION
|
2019-09-23 11:11:22 -04:00
|
|
|
if(global->libcurl) {
|
2015-09-21 02:21:38 -04:00
|
|
|
/* Cleanup the libcurl source output */
|
|
|
|
easysrc_cleanup();
|
2014-03-02 04:50:36 -05:00
|
|
|
|
2015-09-21 02:21:38 -04:00
|
|
|
/* Dump the libcurl code if previously enabled */
|
2019-09-23 11:11:22 -04:00
|
|
|
dumpeasysrc(global);
|
2015-09-21 02:21:38 -04:00
|
|
|
}
|
2014-03-02 04:28:17 -05:00
|
|
|
#endif
|
2014-02-09 06:01:36 -05:00
|
|
|
}
|
2014-03-02 04:28:17 -05:00
|
|
|
else
|
2019-12-09 10:15:37 -05:00
|
|
|
errorf(global, "out of memory\n");
|
2014-02-09 06:01:36 -05:00
|
|
|
}
|
2014-02-06 14:31:44 -05:00
|
|
|
}
|
2014-02-02 10:37:28 -05:00
|
|
|
|
|
|
|
return result;
|
2014-02-02 10:20:37 -05:00
|
|
|
}
|