mirror of
https://github.com/moparisthebest/curl
synced 2025-02-28 09:21:50 -05:00
tool_main: Moved easy handle into global config structure
This commit is contained in:
parent
0d9ddf91ca
commit
59b5ef444e
@ -1798,32 +1798,36 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
|
|||||||
return PARAM_OK;
|
return PARAM_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ParameterError parse_args(struct OperationConfig *config, int argc,
|
ParameterError parse_args(struct GlobalConfig *config, int argc,
|
||||||
argv_item_t argv[])
|
argv_item_t argv[])
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
bool stillflags;
|
bool stillflags;
|
||||||
char *orig_opt;
|
char *orig_opt;
|
||||||
ParameterError result = PARAM_OK;
|
ParameterError result = PARAM_OK;
|
||||||
|
struct OperationConfig *operation = config->first;
|
||||||
|
|
||||||
for(i = 1, stillflags = TRUE; i < argc && !result; i++) {
|
for(i = 1, stillflags = TRUE; i < argc && !result; i++) {
|
||||||
orig_opt = argv[i];
|
orig_opt = argv[i];
|
||||||
|
|
||||||
if(curlx_strequal(":", argv[i]) &&
|
if(curlx_strequal(":", argv[i]) &&
|
||||||
(config->url_list && config->url_list->url)) {
|
(operation->url_list && operation->url_list->url)) {
|
||||||
|
|
||||||
/* Allocate the next config */
|
/* Allocate the next config */
|
||||||
config->next = malloc(sizeof(struct OperationConfig));
|
operation->next = malloc(sizeof(struct OperationConfig));
|
||||||
if(config->next) {
|
if(operation->next) {
|
||||||
/* Initialise the newly created config */
|
/* Initialise the newly created config */
|
||||||
config_init(config->next);
|
config_init(operation->next);
|
||||||
|
|
||||||
/* Copy the easy handle */
|
/* Copy the easy handle */
|
||||||
config->next->easy = config->easy;
|
operation->next->easy = config->easy;
|
||||||
|
|
||||||
|
/* Update the last operation pointer */
|
||||||
|
config->last = operation->next;
|
||||||
|
|
||||||
/* Move onto the new config */
|
/* Move onto the new config */
|
||||||
config->next->prev = config;
|
operation->next->prev = operation;
|
||||||
config = config->next;
|
operation = operation->next;
|
||||||
|
|
||||||
/* Reset the flag indicator */
|
/* Reset the flag indicator */
|
||||||
stillflags = TRUE;
|
stillflags = TRUE;
|
||||||
@ -1843,7 +1847,7 @@ ParameterError parse_args(struct OperationConfig *config, int argc,
|
|||||||
else {
|
else {
|
||||||
nextarg = (i < (argc - 1)) ? argv[i + 1] : NULL;
|
nextarg = (i < (argc - 1)) ? argv[i + 1] : NULL;
|
||||||
|
|
||||||
result = getparameter(flag, nextarg, &passarg, config);
|
result = getparameter(flag, nextarg, &passarg, operation);
|
||||||
if(!result && passarg)
|
if(!result && passarg)
|
||||||
i++; /* we're supposed to skip this */
|
i++; /* we're supposed to skip this */
|
||||||
}
|
}
|
||||||
@ -1852,7 +1856,7 @@ ParameterError parse_args(struct OperationConfig *config, int argc,
|
|||||||
bool used;
|
bool used;
|
||||||
|
|
||||||
/* Just add the URL please */
|
/* Just add the URL please */
|
||||||
result = getparameter((char *)"--url", argv[i], &used, config);
|
result = getparameter((char *)"--url", argv[i], &used, operation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1863,9 +1867,9 @@ ParameterError parse_args(struct OperationConfig *config, int argc,
|
|||||||
const char *reason = param2text(result);
|
const char *reason = param2text(result);
|
||||||
|
|
||||||
if(!curlx_strequal(":", orig_opt))
|
if(!curlx_strequal(":", orig_opt))
|
||||||
helpf(config->errors, "option %s: %s\n", orig_opt, reason);
|
helpf(operation->errors, "option %s: %s\n", orig_opt, reason);
|
||||||
else
|
else
|
||||||
helpf(config->errors, "%s\n", reason);
|
helpf(operation->errors, "%s\n", reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -54,7 +54,7 @@ void parse_cert_parameter(const char *cert_parameter,
|
|||||||
char **passphrase);
|
char **passphrase);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ParameterError parse_args(struct OperationConfig *config, int argc,
|
ParameterError parse_args(struct GlobalConfig *config, int argc,
|
||||||
argv_item_t argv[]);
|
argv_item_t argv[]);
|
||||||
|
|
||||||
#endif /* HEADER_CURL_TOOL_GETPARAM_H */
|
#endif /* HEADER_CURL_TOOL_GETPARAM_H */
|
||||||
|
@ -131,7 +131,7 @@ static CURLcode main_init(struct GlobalConfig *config)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Allocate the initial operate config */
|
/* Allocate the initial operate config */
|
||||||
config->first = malloc(sizeof(struct OperationConfig));
|
config->first = config->last = malloc(sizeof(struct OperationConfig));
|
||||||
if(config->first) {
|
if(config->first) {
|
||||||
/* Perform the libcurl initialization */
|
/* Perform the libcurl initialization */
|
||||||
result = curl_global_init(CURL_GLOBAL_DEFAULT);
|
result = curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||||
@ -140,8 +140,17 @@ static CURLcode main_init(struct GlobalConfig *config)
|
|||||||
result = get_libcurl_info();
|
result = get_libcurl_info();
|
||||||
|
|
||||||
if(!result) {
|
if(!result) {
|
||||||
/* Initialise the config */
|
/* Get a curl handle to use for all forthcoming curl transfers */
|
||||||
config_init(config->first);
|
config->easy = curl_easy_init();
|
||||||
|
if(config->easy) {
|
||||||
|
/* Initialise the config */
|
||||||
|
config_init(config->first);
|
||||||
|
config->first->easy = config->easy;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
helpf(stderr, "error initializing curl easy handle\n");
|
||||||
|
result = CURLE_FAILED_INIT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
helpf(stderr, "error retrieving curl library information\n");
|
helpf(stderr, "error retrieving curl library information\n");
|
||||||
@ -197,7 +206,7 @@ int main(int argc, char *argv[])
|
|||||||
result = main_init(&global);
|
result = main_init(&global);
|
||||||
if(!result) {
|
if(!result) {
|
||||||
/* Start our curl operation */
|
/* Start our curl operation */
|
||||||
result = operate(global.first, argc, argv);
|
result = operate(&global, argc, argv);
|
||||||
|
|
||||||
#ifdef __SYMBIAN32__
|
#ifdef __SYMBIAN32__
|
||||||
if(global.first->showerror)
|
if(global.first->showerror)
|
||||||
|
@ -187,23 +187,6 @@ static curl_off_t VmsSpecialSize(const char * name,
|
|||||||
}
|
}
|
||||||
#endif /* __VMS */
|
#endif /* __VMS */
|
||||||
|
|
||||||
static CURLcode operate_init(struct OperationConfig *config)
|
|
||||||
{
|
|
||||||
/* Get a curl handle to use for all forthcoming curl transfers */
|
|
||||||
config->easy = curl_easy_init();
|
|
||||||
if(!config->easy) {
|
|
||||||
helpf(config->errors, "error initializing curl easy handle\n");
|
|
||||||
return CURLE_FAILED_INIT;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Setup proper locale from environment */
|
|
||||||
#ifdef HAVE_SETLOCALE
|
|
||||||
setlocale(LC_ALL, "");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return CURLE_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static CURLcode operate_do(struct OperationConfig *config)
|
static CURLcode operate_do(struct OperationConfig *config)
|
||||||
{
|
{
|
||||||
char errorbuffer[CURL_ERROR_SIZE];
|
char errorbuffer[CURL_ERROR_SIZE];
|
||||||
@ -1803,22 +1786,22 @@ static void operate_free(struct OperationConfig *config)
|
|||||||
clean_metalink(config);
|
clean_metalink(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
CURLcode operate(struct OperationConfig *config, int argc, argv_item_t argv[])
|
CURLcode operate(struct GlobalConfig *config, int argc, argv_item_t argv[])
|
||||||
{
|
{
|
||||||
CURLcode result = CURLE_OK;
|
CURLcode result = CURLE_OK;
|
||||||
|
|
||||||
/* Initialize the easy interface */
|
/* Setup proper locale from environment */
|
||||||
result = operate_init(config);
|
#ifdef HAVE_SETLOCALE
|
||||||
if(result)
|
setlocale(LC_ALL, "");
|
||||||
return result;
|
#endif
|
||||||
|
|
||||||
/* Parse .curlrc if necessary */
|
/* Parse .curlrc if necessary */
|
||||||
if((argc == 1) || (!curlx_strequal(argv[1], "-q"))) {
|
if((argc == 1) || (!curlx_strequal(argv[1], "-q"))) {
|
||||||
parseconfig(NULL, config); /* ignore possible failure */
|
parseconfig(NULL, config->first); /* ignore possible failure */
|
||||||
|
|
||||||
/* If we had no arguments then make sure a url was specified in .curlrc */
|
/* If we had no arguments then make sure a url was specified in .curlrc */
|
||||||
if((argc < 2) && (!config->url_list)) {
|
if((argc < 2) && (!config->first->url_list)) {
|
||||||
helpf(config->errors, NULL);
|
helpf(config->first->errors, NULL);
|
||||||
result = CURLE_FAILED_INIT;
|
result = CURLE_FAILED_INIT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1847,7 +1830,7 @@ CURLcode operate(struct OperationConfig *config, int argc, argv_item_t argv[])
|
|||||||
/* Perform the main operations */
|
/* Perform the main operations */
|
||||||
else {
|
else {
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
struct OperationConfig *operation = config;
|
struct OperationConfig *operation = config->first;
|
||||||
|
|
||||||
/* Get the required aguments for each operation */
|
/* Get the required aguments for each operation */
|
||||||
while(!result && operation) {
|
while(!result && operation) {
|
||||||
@ -1857,7 +1840,7 @@ CURLcode operate(struct OperationConfig *config, int argc, argv_item_t argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Reset the operation pointer */
|
/* Reset the operation pointer */
|
||||||
operation = config;
|
operation = config->first;
|
||||||
|
|
||||||
/* Perform each operation */
|
/* Perform each operation */
|
||||||
while(!result && operation) {
|
while(!result && operation) {
|
||||||
@ -1869,7 +1852,7 @@ CURLcode operate(struct OperationConfig *config, int argc, argv_item_t argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Perform the cleanup */
|
/* Perform the cleanup */
|
||||||
operate_free(config);
|
operate_free(config->first);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
#include "tool_setup.h"
|
#include "tool_setup.h"
|
||||||
|
|
||||||
CURLcode operate(struct OperationConfig *config, int argc, argv_item_t argv[]);
|
CURLcode operate(struct GlobalConfig *config, int argc, argv_item_t argv[]);
|
||||||
|
|
||||||
#endif /* HEADER_CURL_TOOL_OPERATE_H */
|
#endif /* HEADER_CURL_TOOL_OPERATE_H */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user