diff options
-rw-r--r-- | src/tool_getparam.c | 28 | ||||
-rw-r--r-- | src/tool_getparam.h | 2 | ||||
-rw-r--r-- | src/tool_main.c | 17 | ||||
-rw-r--r-- | src/tool_operate.c | 39 | ||||
-rw-r--r-- | src/tool_operate.h | 2 |
5 files changed, 42 insertions, 46 deletions
diff --git a/src/tool_getparam.c b/src/tool_getparam.c index f6b889804..c64169c76 100644 --- a/src/tool_getparam.c +++ b/src/tool_getparam.c @@ -1798,32 +1798,36 @@ ParameterError getparameter(char *flag, /* f or -long-flag */ return PARAM_OK; } -ParameterError parse_args(struct OperationConfig *config, int argc, +ParameterError parse_args(struct GlobalConfig *config, int argc, argv_item_t argv[]) { int i; bool stillflags; char *orig_opt; ParameterError result = PARAM_OK; + struct OperationConfig *operation = config->first; for(i = 1, stillflags = TRUE; i < argc && !result; i++) { orig_opt = 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 */ - config->next = malloc(sizeof(struct OperationConfig)); - if(config->next) { + operation->next = malloc(sizeof(struct OperationConfig)); + if(operation->next) { /* Initialise the newly created config */ - config_init(config->next); + config_init(operation->next); /* 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 */ - config->next->prev = config; - config = config->next; + operation->next->prev = operation; + operation = operation->next; /* Reset the flag indicator */ stillflags = TRUE; @@ -1843,7 +1847,7 @@ ParameterError parse_args(struct OperationConfig *config, int argc, else { nextarg = (i < (argc - 1)) ? argv[i + 1] : NULL; - result = getparameter(flag, nextarg, &passarg, config); + result = getparameter(flag, nextarg, &passarg, operation); if(!result && passarg) i++; /* we're supposed to skip this */ } @@ -1852,7 +1856,7 @@ ParameterError parse_args(struct OperationConfig *config, int argc, bool used; /* 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); 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 - helpf(config->errors, "%s\n", reason); + helpf(operation->errors, "%s\n", reason); } return result; diff --git a/src/tool_getparam.h b/src/tool_getparam.h index 159319072..23628c00f 100644 --- a/src/tool_getparam.h +++ b/src/tool_getparam.h @@ -54,7 +54,7 @@ void parse_cert_parameter(const char *cert_parameter, char **passphrase); #endif -ParameterError parse_args(struct OperationConfig *config, int argc, +ParameterError parse_args(struct GlobalConfig *config, int argc, argv_item_t argv[]); #endif /* HEADER_CURL_TOOL_GETPARAM_H */ diff --git a/src/tool_main.c b/src/tool_main.c index bceb65c7b..009790493 100644 --- a/src/tool_main.c +++ b/src/tool_main.c @@ -131,7 +131,7 @@ static CURLcode main_init(struct GlobalConfig *config) #endif /* Allocate the initial operate config */ - config->first = malloc(sizeof(struct OperationConfig)); + config->first = config->last = malloc(sizeof(struct OperationConfig)); if(config->first) { /* Perform the libcurl initialization */ result = curl_global_init(CURL_GLOBAL_DEFAULT); @@ -140,8 +140,17 @@ static CURLcode main_init(struct GlobalConfig *config) result = get_libcurl_info(); if(!result) { - /* Initialise the config */ - config_init(config->first); + /* Get a curl handle to use for all forthcoming curl transfers */ + 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 helpf(stderr, "error retrieving curl library information\n"); @@ -197,7 +206,7 @@ int main(int argc, char *argv[]) result = main_init(&global); if(!result) { /* Start our curl operation */ - result = operate(global.first, argc, argv); + result = operate(&global, argc, argv); #ifdef __SYMBIAN32__ if(global.first->showerror) diff --git a/src/tool_operate.c b/src/tool_operate.c index 783d86cce..4bbf29538 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -187,23 +187,6 @@ static curl_off_t VmsSpecialSize(const char * name, } #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) { char errorbuffer[CURL_ERROR_SIZE]; @@ -1803,22 +1786,22 @@ static void operate_free(struct OperationConfig *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; - /* Initialize the easy interface */ - result = operate_init(config); - if(result) - return result; + /* Setup proper locale from environment */ +#ifdef HAVE_SETLOCALE + setlocale(LC_ALL, ""); +#endif /* Parse .curlrc if necessary */ 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((argc < 2) && (!config->url_list)) { - helpf(config->errors, NULL); + if((argc < 2) && (!config->first->url_list)) { + helpf(config->first->errors, NULL); result = CURLE_FAILED_INIT; } } @@ -1847,7 +1830,7 @@ CURLcode operate(struct OperationConfig *config, int argc, argv_item_t argv[]) /* Perform the main operations */ else { size_t count = 0; - struct OperationConfig *operation = config; + struct OperationConfig *operation = config->first; /* Get the required aguments for each operation */ while(!result && operation) { @@ -1857,7 +1840,7 @@ CURLcode operate(struct OperationConfig *config, int argc, argv_item_t argv[]) } /* Reset the operation pointer */ - operation = config; + operation = config->first; /* Perform each operation */ while(!result && operation) { @@ -1869,7 +1852,7 @@ CURLcode operate(struct OperationConfig *config, int argc, argv_item_t argv[]) } /* Perform the cleanup */ - operate_free(config); + operate_free(config->first); return result; } diff --git a/src/tool_operate.h b/src/tool_operate.h index 86283f7a4..1d5c1a96f 100644 --- a/src/tool_operate.h +++ b/src/tool_operate.h @@ -23,7 +23,7 @@ ***************************************************************************/ #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 */ |