mirror of
https://github.com/curl/curl.git
synced 2026-05-30 06:47:28 +03:00
tool_operate: split single_transfer into sub functions
To make it more manageable and less complex Closes #20258
This commit is contained in:
parent
bd3b2a626a
commit
40fee505a0
1 changed files with 64 additions and 49 deletions
|
|
@ -1147,48 +1147,32 @@ static void check_stdin_upload(struct OperationConfig *config,
|
|||
}
|
||||
}
|
||||
|
||||
/* create the next (singular) transfer */
|
||||
static CURLcode single_transfer(struct OperationConfig *config,
|
||||
CURLSH *share, bool *added, bool *skipped)
|
||||
static void setup_header_cb(struct OperationConfig *config,
|
||||
struct HdrCbData *hdrcbdata,
|
||||
struct getout *u,
|
||||
struct OutStruct *outs,
|
||||
struct OutStruct *heads,
|
||||
struct OutStruct *etag)
|
||||
{
|
||||
hdrcbdata->honor_cd_filename = (config->content_disposition && u->useremote);
|
||||
hdrcbdata->outs = outs;
|
||||
hdrcbdata->heads = heads;
|
||||
hdrcbdata->etag_save = etag;
|
||||
hdrcbdata->config = config;
|
||||
}
|
||||
|
||||
/* create a transfer */
|
||||
static CURLcode create_single(struct OperationConfig *config,
|
||||
CURLSH *share, struct State *state,
|
||||
bool *added, bool *skipped)
|
||||
{
|
||||
const bool orig_isatty = global->isatty;
|
||||
const bool orig_noprogress = global->noprogress;
|
||||
CURLcode result = CURLE_OK;
|
||||
bool orig_noprogress = global->noprogress;
|
||||
bool orig_isatty = global->isatty;
|
||||
struct State *state = &global->state;
|
||||
char *httpgetfields = state->httpgetfields;
|
||||
|
||||
*skipped = *added = FALSE; /* not yet */
|
||||
|
||||
if(config->postfields) {
|
||||
if(config->use_httpget) {
|
||||
if(!httpgetfields) {
|
||||
/* Use the postfields data for an HTTP get */
|
||||
httpgetfields = state->httpgetfields = config->postfields;
|
||||
config->postfields = NULL;
|
||||
if(SetHTTPrequest((config->no_body ? TOOL_HTTPREQ_HEAD :
|
||||
TOOL_HTTPREQ_GET), &config->httpreq))
|
||||
return CURLE_FAILED_INIT;
|
||||
}
|
||||
}
|
||||
else if(SetHTTPrequest(TOOL_HTTPREQ_SIMPLEPOST, &config->httpreq))
|
||||
return CURLE_FAILED_INIT;
|
||||
}
|
||||
|
||||
result = set_cert_types(config);
|
||||
if(result)
|
||||
return result;
|
||||
|
||||
if(!state->urlnode) {
|
||||
/* first time caller, setup things */
|
||||
state->urlnode = config->url_list;
|
||||
state->upnum = 1;
|
||||
}
|
||||
|
||||
while(state->urlnode) {
|
||||
struct per_transfer *per = NULL;
|
||||
struct OutStruct *outs;
|
||||
struct OutStruct *heads;
|
||||
struct HdrCbData *hdrcbdata = NULL;
|
||||
struct OutStruct etag_first;
|
||||
CURL *curl;
|
||||
struct getout *u = state->urlnode;
|
||||
|
|
@ -1289,8 +1273,6 @@ static CURLcode single_transfer(struct OperationConfig *config,
|
|||
if(result)
|
||||
return result;
|
||||
}
|
||||
hdrcbdata = &per->hdrcbdata;
|
||||
|
||||
outs = &per->outs;
|
||||
|
||||
per->outfile = NULL;
|
||||
|
|
@ -1357,9 +1339,8 @@ static CURLcode single_transfer(struct OperationConfig *config,
|
|||
global->isatty = orig_isatty;
|
||||
}
|
||||
|
||||
if(httpgetfields || config->query) {
|
||||
result = append2query(config, per,
|
||||
httpgetfields ? httpgetfields : config->query);
|
||||
if(state->httpgetfields) {
|
||||
result = append2query(config, per, state->httpgetfields);
|
||||
if(result)
|
||||
return result;
|
||||
}
|
||||
|
|
@ -1374,12 +1355,7 @@ static CURLcode single_transfer(struct OperationConfig *config,
|
|||
/* explicitly passed to stdout means okaying binary gunk */
|
||||
config->terminal_binary_ok = (per->outfile && !strcmp(per->outfile, "-"));
|
||||
|
||||
hdrcbdata->honor_cd_filename =
|
||||
(config->content_disposition && u->useremote);
|
||||
hdrcbdata->outs = outs;
|
||||
hdrcbdata->heads = heads;
|
||||
hdrcbdata->etag_save = &etag_first;
|
||||
hdrcbdata->config = config;
|
||||
setup_header_cb(config, &per->hdrcbdata, u, outs, heads, &etag_first);
|
||||
|
||||
result = config2setopts(config, per, curl, share);
|
||||
if(result)
|
||||
|
|
@ -1391,9 +1367,8 @@ static CURLcode single_transfer(struct OperationConfig *config,
|
|||
per->retry_sleep = per->retry_sleep_default; /* ms */
|
||||
per->retrystart = curlx_now();
|
||||
|
||||
state->urlidx++;
|
||||
/* Here's looping around each globbed URL */
|
||||
if(state->urlidx >= state->urlnum) {
|
||||
if(++state->urlidx >= state->urlnum) {
|
||||
state->urlidx = state->urlnum = 0;
|
||||
glob_cleanup(&state->urlglob);
|
||||
state->upidx++;
|
||||
|
|
@ -1405,6 +1380,46 @@ static CURLcode single_transfer(struct OperationConfig *config,
|
|||
return result;
|
||||
}
|
||||
|
||||
/* create the next (singular) transfer */
|
||||
static CURLcode single_transfer(struct OperationConfig *config,
|
||||
CURLSH *share, bool *added, bool *skipped)
|
||||
{
|
||||
CURLcode result = CURLE_OK;
|
||||
struct State *state = &global->state;
|
||||
char *httpgetfields = state->httpgetfields;
|
||||
|
||||
*skipped = *added = FALSE; /* not yet */
|
||||
|
||||
if(config->postfields) {
|
||||
if(config->use_httpget) {
|
||||
if(!httpgetfields) {
|
||||
/* Use the postfields data for an HTTP get */
|
||||
httpgetfields = state->httpgetfields = config->postfields;
|
||||
config->postfields = NULL;
|
||||
if(SetHTTPrequest((config->no_body ? TOOL_HTTPREQ_HEAD :
|
||||
TOOL_HTTPREQ_GET), &config->httpreq))
|
||||
return CURLE_FAILED_INIT;
|
||||
}
|
||||
}
|
||||
else if(SetHTTPrequest(TOOL_HTTPREQ_SIMPLEPOST, &config->httpreq))
|
||||
return CURLE_FAILED_INIT;
|
||||
}
|
||||
if(!httpgetfields)
|
||||
state->httpgetfields = config->query;
|
||||
|
||||
result = set_cert_types(config);
|
||||
if(result)
|
||||
return result;
|
||||
|
||||
if(!state->urlnode) {
|
||||
/* first time caller, setup things */
|
||||
state->urlnode = config->url_list;
|
||||
state->upnum = 1;
|
||||
}
|
||||
|
||||
return create_single(config, share, state, added, skipped);
|
||||
}
|
||||
|
||||
static long all_added; /* number of easy handles currently added */
|
||||
|
||||
/*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue