diff options
author | Daniel Stenberg <daniel@haxx.se> | 2020-11-02 17:34:04 +0100 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2020-11-02 22:49:36 +0100 |
commit | d70a5b5a0f5e36781a39e2c955139c81d41355c1 (patch) | |
tree | 54bb308146bdbd9e8da1fd228b8757967ac8014e /lib/sendf.c | |
parent | 606d213766fb94a4653ec41ef3b91cc0a96b9570 (diff) | |
download | curl-d70a5b5a0f5e36781a39e2c955139c81d41355c1.tar.gz |
sendf: move the verbose-check into Curl_debug
Saves us from having the same check done everywhere.
Closes #6159
Diffstat (limited to 'lib/sendf.c')
-rw-r--r-- | lib/sendf.c | 117 |
1 files changed, 58 insertions, 59 deletions
diff --git a/lib/sendf.c b/lib/sendf.c index 6cfc89b69..d0f8faf35 100644 --- a/lib/sendf.c +++ b/lib/sendf.c @@ -277,11 +277,8 @@ void Curl_failf(struct Curl_easy *data, const char *fmt, ...) strcpy(data->set.errorbuffer, error); data->state.errorbuf = TRUE; /* wrote error string */ } - if(data->set.verbose) { - error[len] = '\n'; - error[++len] = '\0'; - Curl_debug(data, CURLINFO_TEXT, error, len); - } + error[len++] = '\n'; + Curl_debug(data, CURLINFO_TEXT, error, len); va_end(ap); } } @@ -693,72 +690,74 @@ CURLcode Curl_read(struct connectdata *conn, /* connection data */ int Curl_debug(struct Curl_easy *data, curl_infotype type, char *ptr, size_t size) { - static const char s_infotype[CURLINFO_END][3] = { - "* ", "< ", "> ", "{ ", "} ", "{ ", "} " }; int rc = 0; + if(data->set.verbose) { + static const char s_infotype[CURLINFO_END][3] = { + "* ", "< ", "> ", "{ ", "} ", "{ ", "} " }; #ifdef CURL_DOES_CONVERSIONS - char *buf = NULL; - size_t conv_size = 0; - - switch(type) { - case CURLINFO_HEADER_OUT: - buf = Curl_memdup(ptr, size); - if(!buf) - return 1; - conv_size = size; - - /* Special processing is needed for this block if it - * contains both headers and data (separated by CRLFCRLF). - * We want to convert just the headers, leaving the data as-is. - */ - if(size > 4) { - size_t i; - for(i = 0; i < size-4; i++) { - if(memcmp(&buf[i], "\x0d\x0a\x0d\x0a", 4) == 0) { - /* convert everything through this CRLFCRLF but no further */ - conv_size = i + 4; - break; + char *buf = NULL; + size_t conv_size = 0; + + switch(type) { + case CURLINFO_HEADER_OUT: + buf = Curl_memdup(ptr, size); + if(!buf) + return 1; + conv_size = size; + + /* Special processing is needed for this block if it + * contains both headers and data (separated by CRLFCRLF). + * We want to convert just the headers, leaving the data as-is. + */ + if(size > 4) { + size_t i; + for(i = 0; i < size-4; i++) { + if(memcmp(&buf[i], "\x0d\x0a\x0d\x0a", 4) == 0) { + /* convert everything through this CRLFCRLF but no further */ + conv_size = i + 4; + break; + } } } - } - Curl_convert_from_network(data, buf, conv_size); - /* Curl_convert_from_network calls failf if unsuccessful */ - /* we might as well continue even if it fails... */ - ptr = buf; /* switch pointer to use my buffer instead */ - break; - default: - /* leave everything else as-is */ - break; - } + Curl_convert_from_network(data, buf, conv_size); + /* Curl_convert_from_network calls failf if unsuccessful */ + /* we might as well continue even if it fails... */ + ptr = buf; /* switch pointer to use my buffer instead */ + break; + default: + /* leave everything else as-is */ + break; + } #endif /* CURL_DOES_CONVERSIONS */ - if(data->set.fdebug) { - Curl_set_in_callback(data, true); - rc = (*data->set.fdebug)(data, type, ptr, size, data->set.debugdata); - Curl_set_in_callback(data, false); - } - else { - switch(type) { - case CURLINFO_TEXT: - case CURLINFO_HEADER_OUT: - case CURLINFO_HEADER_IN: - fwrite(s_infotype[type], 2, 1, data->set.err); - fwrite(ptr, size, 1, data->set.err); + if(data->set.fdebug) { + Curl_set_in_callback(data, true); + rc = (*data->set.fdebug)(data, type, ptr, size, data->set.debugdata); + Curl_set_in_callback(data, false); + } + else { + switch(type) { + case CURLINFO_TEXT: + case CURLINFO_HEADER_OUT: + case CURLINFO_HEADER_IN: + fwrite(s_infotype[type], 2, 1, data->set.err); + fwrite(ptr, size, 1, data->set.err); #ifdef CURL_DOES_CONVERSIONS - if(size != conv_size) { - /* we had untranslated data so we need an explicit newline */ - fwrite("\n", 1, 1, data->set.err); - } + if(size != conv_size) { + /* we had untranslated data so we need an explicit newline */ + fwrite("\n", 1, 1, data->set.err); + } #endif - break; - default: /* nada */ - break; + break; + default: /* nada */ + break; + } } - } #ifdef CURL_DOES_CONVERSIONS - free(buf); + free(buf); #endif + } return rc; } |