diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/tool_cb_dbg.c | 4 | ||||
-rw-r--r-- | src/tool_cb_prg.c | 2 | ||||
-rw-r--r-- | src/tool_cfgable.c | 5 | ||||
-rw-r--r-- | src/tool_cfgable.h | 4 | ||||
-rw-r--r-- | src/tool_formparse.c | 4 | ||||
-rw-r--r-- | src/tool_getparam.c | 14 | ||||
-rw-r--r-- | src/tool_main.c | 5 | ||||
-rw-r--r-- | src/tool_metalink.c | 15 | ||||
-rw-r--r-- | src/tool_metalink.h | 2 | ||||
-rw-r--r-- | src/tool_msgs.c | 8 | ||||
-rw-r--r-- | src/tool_operate.c | 72 | ||||
-rw-r--r-- | src/tool_paramhlp.c | 2 |
12 files changed, 69 insertions, 68 deletions
diff --git a/src/tool_cb_dbg.c b/src/tool_cb_dbg.c index e92116532..8a75fb693 100644 --- a/src/tool_cb_dbg.c +++ b/src/tool_cb_dbg.c @@ -46,7 +46,7 @@ int tool_debug_cb(CURL *handle, curl_infotype type, { struct OperationConfig *operation = userdata; struct GlobalConfig *config = operation->global; - FILE *output = operation->errors; + FILE *output = config->errors; const char *text; struct timeval tv; struct tm *now; @@ -77,7 +77,7 @@ int tool_debug_cb(CURL *handle, curl_infotype type, config->trace_stream = stdout; else if(curlx_strequal("%", config->trace_dump)) /* Ok, this is somewhat hackish but we do it undocumented for now */ - config->trace_stream = operation->errors; /* aka stderr */ + config->trace_stream = config->errors; /* aka stderr */ else { config->trace_stream = fopen(config->trace_dump, "w"); config->trace_fopened = TRUE; diff --git a/src/tool_cb_prg.c b/src/tool_cb_prg.c index 2b0611ca9..9e3c5fb4e 100644 --- a/src/tool_cb_prg.c +++ b/src/tool_cb_prg.c @@ -146,5 +146,5 @@ void progressbarinit(struct ProgressData *bar, bar->width = scr_size[0] - 1; #endif - bar->out = config->errors; + bar->out = config->global->errors; } diff --git a/src/tool_cfgable.c b/src/tool_cfgable.c index 6ca06ff01..444cddc42 100644 --- a/src/tool_cfgable.c +++ b/src/tool_cfgable.c @@ -30,7 +30,6 @@ void config_init(struct OperationConfig* config) { memset(config, 0, sizeof(struct OperationConfig)); - config->errors = stderr; /* default errors to stderr */ config->postfieldsize = -1; config->use_httpget = FALSE; config->create_dirs = FALSE; @@ -116,10 +115,6 @@ static void free_config_fields(struct OperationConfig *config) Curl_safefree(config->writeout); - if(config->errors_fopened && config->errors) - fclose(config->errors); - config->errors = NULL; - curl_slist_free_all(config->quote); curl_slist_free_all(config->postquote); curl_slist_free_all(config->prequote); diff --git a/src/tool_cfgable.h b/src/tool_cfgable.h index d7493431a..efbba0f2f 100644 --- a/src/tool_cfgable.h +++ b/src/tool_cfgable.h @@ -138,8 +138,6 @@ struct OperationConfig { bool proxyanyauth; char *writeout; /* %-styled format string to output */ bool writeenv; /* write results to environment, if available */ - FILE *errors; /* errors stream, defaults to stderr */ - bool errors_fopened; /* whether errors stream isn't stderr */ struct curl_slist *quote; struct curl_slist *postquote; struct curl_slist *prequote; @@ -220,6 +218,8 @@ struct GlobalConfig { 0 => -s is used to NOT show errors 1 => -S has been used to show errors */ bool mute; /* don't show messages, --silent given */ + FILE *errors; /* Error stream, defaults to stderr */ + bool errors_fopened; /* Whether error stream isn't stderr */ char *trace_dump; /* file to dump the network trace to */ FILE *trace_stream; bool trace_fopened; diff --git a/src/tool_formparse.c b/src/tool_formparse.c index 5198822fd..d8fc8fd6c 100644 --- a/src/tool_formparse.c +++ b/src/tool_formparse.c @@ -163,7 +163,7 @@ int formparse(struct OperationConfig *config, /* Allocate the contents */ contents = strdup(contp+1); if(!contents) { - fprintf(config->errors, "out of memory\n"); + fprintf(config->global->errors, "out of memory\n"); return 1; } contp = contents; @@ -277,7 +277,7 @@ int formparse(struct OperationConfig *config, } forms = malloc((count+1)*sizeof(struct curl_forms)); if(!forms) { - fprintf(config->errors, "Error building form post!\n"); + fprintf(config->global->errors, "Error building form post!\n"); Curl_safefree(contents); FreeMultiInfo(&multi_start, &multi_current); return 4; diff --git a/src/tool_getparam.c b/src/tool_getparam.c index d858ff5f3..c6377ed60 100644 --- a/src/tool_getparam.c +++ b/src/tool_getparam.c @@ -681,14 +681,14 @@ ParameterError getparameter(char *flag, /* f or -long-flag */ if(!newfile) warnf(config, "Failed to open %s!\n", nextarg); else { - if(config->errors_fopened) - fclose(config->errors); - config->errors = newfile; - config->errors_fopened = TRUE; + if(global->errors_fopened) + fclose(global->errors); + global->errors = newfile; + global->errors_fopened = TRUE; } } else - config->errors = stdout; + global->errors = stdout; break; case 'w': /* --interface */ /* interface */ @@ -1875,9 +1875,9 @@ ParameterError parse_args(struct GlobalConfig *config, int argc, const char *reason = param2text(result); if(!curlx_strequal(":", orig_opt)) - helpf(operation->errors, "option %s: %s\n", orig_opt, reason); + helpf(config->errors, "option %s: %s\n", orig_opt, reason); else - helpf(operation->errors, "%s\n", reason); + helpf(config->errors, "%s\n", reason); } return result; diff --git a/src/tool_main.c b/src/tool_main.c index 1e9156aca..8a613cb21 100644 --- a/src/tool_main.c +++ b/src/tool_main.c @@ -132,6 +132,7 @@ static CURLcode main_init(struct GlobalConfig *config) /* Initialise the global config */ config->showerror = -1; /* Will show errors */ + config->errors = stderr; /* Default errors to stderr */ /* Allocate the initial operate config */ config->first = config->last = malloc(sizeof(struct OperationConfig)); @@ -179,6 +180,10 @@ static void free_config_fields(struct GlobalConfig *config) { Curl_safefree(config->trace_dump); + if(config->errors_fopened && config->errors) + fclose(config->errors); + config->errors = NULL; + if(config->trace_fopened && config->trace_stream) fclose(config->trace_stream); config->trace_stream = NULL; diff --git a/src/tool_metalink.c b/src/tool_metalink.c index a9fdf62e9..cd8df41f9 100644 --- a/src/tool_metalink.c +++ b/src/tool_metalink.c @@ -594,7 +594,7 @@ static int check_hash(const char *filename, return check_ok; } -int metalink_check_hash(struct OperationConfig *config, +int metalink_check_hash(struct GlobalConfig *config, metalinkfile *mlfile, const char *filename) { @@ -602,8 +602,7 @@ int metalink_check_hash(struct OperationConfig *config, fprintf(config->errors, "Metalink: validating (%s)...\n", filename); if(mlfile->checksum == NULL) { fprintf(config->errors, - "Metalink: validating (%s) FAILED (digest missing)\n", - filename); + "Metalink: validating (%s) FAILED (digest missing)\n", filename); return -2; } rv = check_hash(filename, mlfile->checksum->digest_def, @@ -727,7 +726,7 @@ int parse_metalink(struct OperationConfig *config, struct OutStruct *outs, return -1; } if(metalink->files == NULL) { - fprintf(config->errors, "Metalink: parsing (%s) WARNING " + fprintf(config->global->errors, "Metalink: parsing (%s) WARNING " "(missing or invalid file name)\n", metalink_url); metalink_delete(metalink); @@ -737,7 +736,7 @@ int parse_metalink(struct OperationConfig *config, struct OutStruct *outs, struct getout *url; /* Skip an entry which has no resource. */ if(!(*files)->resources) { - fprintf(config->errors, "Metalink: parsing (%s) WARNING " + fprintf(config->global->errors, "Metalink: parsing (%s) WARNING " "(missing or invalid resource)\n", metalink_url, (*files)->name); continue; @@ -764,8 +763,8 @@ int parse_metalink(struct OperationConfig *config, struct OutStruct *outs, mlfile = new_metalinkfile(*files); if(!mlfile->checksum) { warnings = TRUE; - fprintf(config->errors, "Metalink: parsing (%s) WARNING " - "(digest missing)\n", + fprintf(config->global->errors, + "Metalink: parsing (%s) WARNING (digest missing)\n", metalink_url); } /* Set name as url */ @@ -809,7 +808,7 @@ size_t metalink_write_cb(void *buffer, size_t sz, size_t nmemb, if(rv == 0) return sz * nmemb; else { - fprintf(config->errors, "Metalink: parsing FAILED\n"); + fprintf(config->global->errors, "Metalink: parsing FAILED\n"); return failure; } } diff --git a/src/tool_metalink.h b/src/tool_metalink.h index 7dc21e53d..339fdac0f 100644 --- a/src/tool_metalink.h +++ b/src/tool_metalink.h @@ -142,7 +142,7 @@ int check_metalink_content_type(const char *content_type); * No checksum in Metalink supported, hash algorithm not available, or * Metalink does not contain checksum. */ -int metalink_check_hash(struct OperationConfig *config, +int metalink_check_hash(struct GlobalConfig *config, metalinkfile *mlfile, const char *filename); diff --git a/src/tool_msgs.c b/src/tool_msgs.c index c92fbace2..3311b55f5 100644 --- a/src/tool_msgs.c +++ b/src/tool_msgs.c @@ -52,7 +52,7 @@ void warnf(struct OperationConfig *config, const char *fmt, ...) ptr = print_buffer; while(len > 0) { - fputs(WARN_PREFIX, config->errors); + fputs(WARN_PREFIX, config->global->errors); if(len > (int)WARN_TEXTWIDTH) { int cut = WARN_TEXTWIDTH-1; @@ -65,13 +65,13 @@ void warnf(struct OperationConfig *config, const char *fmt, ...) max text width then! */ cut = WARN_TEXTWIDTH-1; - (void)fwrite(ptr, cut + 1, 1, config->errors); - fputs("\n", config->errors); + (void)fwrite(ptr, cut + 1, 1, config->global->errors); + fputs("\n", config->global->errors); ptr += cut+1; /* skip the space too */ len -= cut; } else { - fputs(ptr, config->errors); + fputs(ptr, config->global->errors); len = 0; } } diff --git a/src/tool_operate.c b/src/tool_operate.c index 67808d442..9683f3d91 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -224,7 +224,7 @@ static CURLcode operate_do(struct GlobalConfig *global, /* Check we have a url */ if(!config->url_list || !config->url_list->url) { - helpf(config->errors, "no URL specified!\n"); + helpf(global->errors, "no URL specified!\n"); res = CURLE_FAILED_INIT; goto quit_curl; } @@ -247,7 +247,7 @@ static CURLcode operate_do(struct GlobalConfig *global, config->cacert = strdup(env); if(!config->cacert) { curl_free(env); - helpf(config->errors, "out of memory\n"); + helpf(global->errors, "out of memory\n"); res = CURLE_OUT_OF_MEMORY; goto quit_curl; } @@ -258,7 +258,7 @@ static CURLcode operate_do(struct GlobalConfig *global, config->capath = strdup(env); if(!config->capath) { curl_free(env); - helpf(config->errors, "out of memory\n"); + helpf(global->errors, "out of memory\n"); res = CURLE_OUT_OF_MEMORY; goto quit_curl; } @@ -269,7 +269,7 @@ static CURLcode operate_do(struct GlobalConfig *global, config->cacert = strdup(env); if(!config->cacert) { curl_free(env); - helpf(config->errors, "out of memory\n"); + helpf(global->errors, "out of memory\n"); res = CURLE_OUT_OF_MEMORY; goto quit_curl; } @@ -294,7 +294,7 @@ static CURLcode operate_do(struct GlobalConfig *global, httpgetfields = strdup(config->postfields); Curl_safefree(config->postfields); if(!httpgetfields) { - helpf(config->errors, "out of memory\n"); + helpf(global->errors, "out of memory\n"); res = CURLE_OUT_OF_MEMORY; goto quit_curl; } @@ -316,7 +316,7 @@ static CURLcode operate_do(struct GlobalConfig *global, #ifndef CURL_DISABLE_LIBCURL_OPTION res = easysrc_init(); if(res) { - helpf(config->errors, "out of memory\n"); + helpf(global->errors, "out of memory\n"); goto quit_curl; } #endif @@ -399,7 +399,7 @@ static CURLcode operate_do(struct GlobalConfig *global, if(urlnode->outfile) { outfiles = strdup(urlnode->outfile); if(!outfiles) { - helpf(config->errors, "out of memory\n"); + helpf(global->errors, "out of memory\n"); res = CURLE_OUT_OF_MEMORY; break; } @@ -410,7 +410,7 @@ static CURLcode operate_do(struct GlobalConfig *global, if(!config->globoff && infiles) { /* Unless explicitly shut off */ res = glob_url(&inglob, infiles, &infilenum, - global->showerror?config->errors:NULL); + global->showerror?global->errors:NULL); if(res) { Curl_safefree(outfiles); break; @@ -436,12 +436,12 @@ static CURLcode operate_do(struct GlobalConfig *global, if(inglob) { res = glob_next_url(&uploadfile, inglob); if(res == CURLE_OUT_OF_MEMORY) - helpf(config->errors, "out of memory\n"); + helpf(global->errors, "out of memory\n"); } else if(!up) { uploadfile = strdup(infiles); if(!uploadfile) { - helpf(config->errors, "out of memory\n"); + helpf(global->errors, "out of memory\n"); res = CURLE_OUT_OF_MEMORY; } } @@ -461,7 +461,7 @@ static CURLcode operate_do(struct GlobalConfig *global, /* Unless explicitly shut off, we expand '{...}' and '[...]' expressions and return total number of URLs in pattern set */ res = glob_url(&urls, urlnode->url, &urlnum, - global->showerror?config->errors:NULL); + global->showerror?global->errors:NULL); if(res) { Curl_safefree(uploadfile); break; @@ -555,7 +555,7 @@ static CURLcode operate_do(struct GlobalConfig *global, if(res) goto show_error; if((!outfile || !*outfile) && !config->content_disposition) { - helpf(config->errors, "Remote file name has no length!\n"); + helpf(global->errors, "Remote file name has no length!\n"); res = CURLE_WRITE_ERROR; goto quit_urls; } @@ -585,7 +585,7 @@ static CURLcode operate_do(struct GlobalConfig *global, file output call */ if(config->create_dirs || metalink) { - res = create_dir_hierarchy(outfile, config->errors); + res = create_dir_hierarchy(outfile, global->errors); /* create_dir_hierarchy shows error upon CURLE_WRITE_ERROR */ if(res == CURLE_WRITE_ERROR) goto quit_urls; @@ -624,7 +624,7 @@ static CURLcode operate_do(struct GlobalConfig *global, FILE *file = fopen(outfile, config->resume_from?"ab":"wb"); #endif if(!file) { - helpf(config->errors, "Can't open '%s'!\n", outfile); + helpf(global->errors, "Can't open '%s'!\n", outfile); res = CURLE_WRITE_ERROR; goto quit_urls; } @@ -686,7 +686,7 @@ static CURLcode operate_do(struct GlobalConfig *global, if((infd == -1) || fstat(infd, &fileinfo)) #endif { - helpf(config->errors, "Can't open '%s'!\n", uploadfile); + helpf(global->errors, "Can't open '%s'!\n", uploadfile); if(infd != -1) { close(infd); infd = STDIN_FILENO; @@ -754,7 +754,7 @@ static CURLcode operate_do(struct GlobalConfig *global, } if(urlnum > 1 && !global->mute) { - fprintf(config->errors, "\n[%lu/%lu]: %s --> %s\n", + fprintf(global->errors, "\n[%lu/%lu]: %s --> %s\n", li+1, urlnum, this_url, outfile ? outfile : "<stdout>"); if(separator) printf("%s%s\n", CURLseparator, this_url); @@ -799,8 +799,8 @@ static CURLcode operate_do(struct GlobalConfig *global, this_url = urlbuffer; /* use our new URL instead! */ } - if(!config->errors) - config->errors = stderr; + if(!global->errors) + global->errors = stderr; if((!outfile || !strcmp(outfile, "-")) && !config->use_ascii) { /* We get the output to stdout and we have not got the ASCII/text @@ -1098,7 +1098,7 @@ static CURLcode operate_do(struct GlobalConfig *global, my_setopt_enum(curl, CURLOPT_TIMECONDITION, (long)config->timecond); my_setopt(curl, CURLOPT_TIMEVALUE, (long)config->condtime); my_setopt_str(curl, CURLOPT_CUSTOMREQUEST, config->customrequest); - my_setopt(curl, CURLOPT_STDERR, config->errors); + my_setopt(curl, CURLOPT_STDERR, global->errors); /* three new ones in libcurl 7.3: */ my_setopt_str(curl, CURLOPT_INTERFACE, config->iface); @@ -1357,11 +1357,12 @@ static CURLcode operate_do(struct GlobalConfig *global, res = CURLE_OUT_OF_MEMORY; goto show_error; } - fprintf(config->errors, "Metalink: parsing (%s) metalink/XML...\n", - this_url); + fprintf(config->global->errors, + "Metalink: parsing (%s) metalink/XML...\n", this_url); } else if(metalink) - fprintf(config->errors, "Metalink: fetching (%s) from (%s)...\n", + fprintf(config->global->errors, + "Metalink: fetching (%s) from (%s)...\n", mlfile->filename, this_url); #endif /* USE_METALINK */ @@ -1461,7 +1462,7 @@ static CURLcode operate_do(struct GlobalConfig *global, /* We have written data to a output file, we truncate file */ if(!global->mute) - fprintf(config->errors, "Throwing away %" + fprintf(global->errors, "Throwing away %" CURL_FORMAT_CURL_OFF_T " bytes\n", outs.bytes); fflush(outs.stream); @@ -1471,7 +1472,7 @@ static CURLcode operate_do(struct GlobalConfig *global, /* when truncate fails, we can't just append as then we'll create something strange, bail out */ if(!global->mute) - fprintf(config->errors, + fprintf(global->errors, "failed to truncate, exiting\n"); res = CURLE_WRITE_ERROR; goto quit_urls; @@ -1507,7 +1508,7 @@ static CURLcode operate_do(struct GlobalConfig *global, curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response); if(response != 200 && response != 206) { metalink_next_res = 1; - fprintf(config->errors, + fprintf(global->errors, "Metalink: fetching (%s) from (%s) FAILED " "(HTTP status code %d)\n", mlfile->filename, this_url, response); @@ -1516,7 +1517,7 @@ static CURLcode operate_do(struct GlobalConfig *global, } else { metalink_next_res = 1; - fprintf(config->errors, + fprintf(global->errors, "Metalink: fetching (%s) from (%s) FAILED (%s)\n", mlfile->filename, this_url, (errorbuffer[0]) ? @@ -1524,7 +1525,7 @@ static CURLcode operate_do(struct GlobalConfig *global, } } if(metalink && !metalink_next_res) - fprintf(config->errors, "Metalink: fetching (%s) from (%s) OK\n", + fprintf(global->errors, "Metalink: fetching (%s) from (%s) OK\n", mlfile->filename, this_url); /* In all ordinary cases, just break out of loop here */ @@ -1562,10 +1563,10 @@ static CURLcode operate_do(struct GlobalConfig *global, else #endif if(res && global->showerror) { - fprintf(config->errors, "curl: (%d) %s\n", res, (errorbuffer[0]) ? + fprintf(global->errors, "curl: (%d) %s\n", res, (errorbuffer[0]) ? errorbuffer : curl_easy_strerror((CURLcode)res)); if(res == CURLE_SSL_CACERT) - fprintf(config->errors, "%s%s", + fprintf(global->errors, "%s%s", CURL_CA_CERT_ERRORMSG1, CURL_CA_CERT_ERRORMSG2); } @@ -1598,7 +1599,7 @@ static CURLcode operate_do(struct GlobalConfig *global, if(!res && rc) { /* something went wrong in the writing process */ res = CURLE_WRITE_ERROR; - fprintf(config->errors, "(%d) Failed writing body\n", res); + fprintf(global->errors, "(%d) Failed writing body\n", res); } } else if(!outs.s_isreg && outs.stream) { @@ -1607,7 +1608,7 @@ static CURLcode operate_do(struct GlobalConfig *global, if(!res && rc) { /* something went wrong in the writing process */ res = CURLE_WRITE_ERROR; - fprintf(config->errors, "(%d) Failed writing body\n", res); + fprintf(global->errors, "(%d) Failed writing body\n", res); } } @@ -1639,13 +1640,14 @@ static CURLcode operate_do(struct GlobalConfig *global, if(!metalink && config->use_metalink && res == CURLE_OK) { int rv = parse_metalink(config, &outs, this_url); if(rv == 0) - fprintf(config->errors, "Metalink: parsing (%s) OK\n", this_url); + fprintf(config->global->errors, "Metalink: parsing (%s) OK\n", + this_url); else if(rv == -1) - fprintf(config->errors, "Metalink: parsing (%s) FAILED\n", + fprintf(config->global->errors, "Metalink: parsing (%s) FAILED\n", this_url); } else if(metalink && res == CURLE_OK && !metalink_next_res) { - int rv = metalink_check_hash(config, mlfile, outs.filename); + int rv = metalink_check_hash(global, mlfile, outs.filename); if(rv == 0) { metalink_next_res = 1; } @@ -1795,7 +1797,7 @@ CURLcode operate(struct GlobalConfig *config, int argc, argv_item_t argv[]) /* If we had no arguments then make sure a url was specified in .curlrc */ if((argc < 2) && (!config->first->url_list)) { - helpf(config->first->errors, NULL); + helpf(config->errors, NULL); result = CURLE_FAILED_INIT; } } diff --git a/src/tool_paramhlp.c b/src/tool_paramhlp.c index 0bbede996..18da0265e 100644 --- a/src/tool_paramhlp.c +++ b/src/tool_paramhlp.c @@ -504,7 +504,7 @@ CURLcode get_args(struct OperationConfig *config, const size_t i) if(!config->useragent) { config->useragent = my_useragent(); if(!config->useragent) { - helpf(config->errors, "out of memory\n"); + helpf(config->global->errors, "out of memory\n"); result = CURLE_OUT_OF_MEMORY; } } |