1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-23 08:38:49 -05:00

sendf: move the verbose-check into Curl_debug

Saves us from having the same check done everywhere.

Closes #6159
This commit is contained in:
Daniel Stenberg 2020-11-02 17:34:04 +01:00
parent 606d213766
commit d70a5b5a0f
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
11 changed files with 103 additions and 138 deletions

View File

@ -156,8 +156,7 @@ static CURLcode sendf(curl_socket_t sockfd, struct connectdata *conn,
if(result)
break;
if(data->set.verbose)
Curl_debug(data, CURLINFO_DATA_OUT, sptr, (size_t)bytes_written);
Curl_debug(data, CURLINFO_DATA_OUT, sptr, (size_t)bytes_written);
if((size_t)bytes_written != write_len) {
/* if not all was written at once, we must advance the pointer, decrease

View File

@ -1254,16 +1254,12 @@ CURLcode Curl_buffer_send(struct dynbuf *in,
size_t headlen = (size_t)amount>headersize ? headersize : (size_t)amount;
size_t bodylen = amount - headlen;
if(data->set.verbose) {
/* this data _may_ contain binary stuff */
Curl_debug(data, CURLINFO_HEADER_OUT, ptr, headlen);
if(bodylen) {
/* there was body data sent beyond the initial header part, pass that
on to the debug callback too */
Curl_debug(data, CURLINFO_DATA_OUT,
ptr + headlen, bodylen);
}
}
/* this data _may_ contain binary stuff */
Curl_debug(data, CURLINFO_HEADER_OUT, ptr, headlen);
if(bodylen)
/* there was body data sent beyond the initial header part, pass that on
to the debug callback too */
Curl_debug(data, CURLINFO_DATA_OUT, ptr + headlen, bodylen);
/* 'amount' can never be a very large value here so typecasting it so a
signed 31 bit value should not cause problems even if ssize_t is
@ -3537,10 +3533,8 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
k->keepon &= ~KEEP_RECV;
}
if(data->set.verbose)
Curl_debug(data, CURLINFO_HEADER_IN,
str_start, headerlen);
break; /* exit header line loop */
Curl_debug(data, CURLINFO_HEADER_IN, str_start, headerlen);
break; /* exit header line loop */
}
/* We continue reading headers, reset the line-based header */
@ -4031,9 +4025,8 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
if(data->set.include_header)
writetype |= CLIENTWRITE_BODY;
if(data->set.verbose)
Curl_debug(data, CURLINFO_HEADER_IN, headp,
Curl_dyn_len(&data->state.headerb));
Curl_debug(data, CURLINFO_HEADER_IN, headp,
Curl_dyn_len(&data->state.headerb));
result = Curl_client_write(conn, writetype, headp,
Curl_dyn_len(&data->state.headerb));

View File

@ -1496,8 +1496,7 @@ static ssize_t http2_handle_stream_close(struct connectdata *conn,
break;
len = lf + 1 - trailp;
if(data->set.verbose)
Curl_debug(data, CURLINFO_HEADER_IN, trailp, len);
Curl_debug(data, CURLINFO_HEADER_IN, trailp, len);
/* pass the trailers one by one to the callback */
result = Curl_client_write(conn, CLIENTWRITE_HEADER, trailp, len);
if(result) {

View File

@ -410,8 +410,7 @@ static CURLcode CONNECT(struct connectdata *conn,
return result;
/* output debug if that is requested */
if(data->set.verbose)
Curl_debug(data, CURLINFO_HEADER_IN, linep, perline);
Curl_debug(data, CURLINFO_HEADER_IN, linep, perline);
if(!data->set.suppress_connect_headers) {
/* send the header to the callback */

View File

@ -99,8 +99,7 @@ static CURLcode ftpsend(struct connectdata *conn, const char *cmd)
if(result)
break;
if(conn->data->set.verbose)
Curl_debug(conn->data, CURLINFO_HEADER_OUT, sptr, (size_t)bytes_written);
Curl_debug(conn->data, CURLINFO_HEADER_OUT, sptr, (size_t)bytes_written);
if(bytes_written != (ssize_t)write_len) {
write_len -= bytes_written;
@ -716,7 +715,7 @@ int Curl_sec_read_msg(struct connectdata *conn, char *buffer,
return -1;
}
if(conn->data->set.verbose) {
{
buf[decoded_len] = '\n';
Curl_debug(conn->data, CURLINFO_HEADER_IN, buf, decoded_len + 1);
}

View File

@ -114,7 +114,7 @@ static CURLcode mqtt_send(struct connectdata *conn,
struct MQTT *mq = data->req.protop;
ssize_t n;
result = Curl_write(conn, sockfd, buf, len, &n);
if(!result && data->set.verbose)
if(!result)
Curl_debug(data, CURLINFO_HEADER_OUT, buf, (size_t)n);
if(len != (size_t)n) {
size_t nsend = len - n;
@ -185,8 +185,7 @@ static CURLcode mqtt_verify_connack(struct connectdata *conn)
if(result)
goto fail;
if(data->set.verbose)
Curl_debug(data, CURLINFO_HEADER_IN, (char *)readbuf, (size_t)nread);
Curl_debug(data, CURLINFO_HEADER_IN, (char *)readbuf, (size_t)nread);
/* fixme */
if(nread < MQTT_CONNACK_LEN) {
@ -298,8 +297,7 @@ static CURLcode mqtt_verify_suback(struct connectdata *conn)
if(result)
goto fail;
if(conn->data->set.verbose)
Curl_debug(conn->data, CURLINFO_HEADER_IN, (char *)readbuf, (size_t)nread);
Curl_debug(conn->data, CURLINFO_HEADER_IN, (char *)readbuf, (size_t)nread);
/* fixme */
if(nread < MQTT_SUBACK_LEN) {
@ -486,8 +484,7 @@ static CURLcode mqtt_read_publish(struct connectdata *conn,
result = CURLE_PARTIAL_FILE;
goto end;
}
if(data->set.verbose)
Curl_debug(data, CURLINFO_DATA_IN, (char *)pkt, (size_t)nread);
Curl_debug(data, CURLINFO_DATA_IN, (char *)pkt, (size_t)nread);
mq->npacket -= nread;
k->bytecount += nread;
@ -558,8 +555,7 @@ static CURLcode mqtt_doing(struct connectdata *conn, bool *done)
result = Curl_read(conn, sockfd, (char *)&mq->firstbyte, 1, &nread);
if(result)
break;
if(data->set.verbose)
Curl_debug(data, CURLINFO_HEADER_IN, (char *)&mq->firstbyte, 1);
Curl_debug(data, CURLINFO_HEADER_IN, (char *)&mq->firstbyte, 1);
/* remember the first byte */
mq->npacket = 0;
mqstate(conn, MQTT_REMAINING_LENGTH, MQTT_NOSTATE);
@ -569,8 +565,7 @@ static CURLcode mqtt_doing(struct connectdata *conn, bool *done)
result = Curl_read(conn, sockfd, (char *)&byte, 1, &nread);
if(result)
break;
if(data->set.verbose)
Curl_debug(data, CURLINFO_HEADER_IN, (char *)&byte, 1);
Curl_debug(data, CURLINFO_HEADER_IN, (char *)&byte, 1);
pkt[mq->npacket++] = byte;
} while((byte & 0x80) && (mq->npacket < 4));
if(result)

View File

@ -218,8 +218,7 @@ CURLcode Curl_pp_vsendf(struct pingpong *pp,
conn->data_prot = data_sec;
#endif
if(data->set.verbose)
Curl_debug(data, CURLINFO_HEADER_OUT, s, (size_t)bytes_written);
Curl_debug(data, CURLINFO_HEADER_OUT, s, (size_t)bytes_written);
if(bytes_written != (ssize_t)write_len) {
/* the whole chunk was not sent, keep it around and adjust sizes */
@ -364,9 +363,8 @@ CURLcode Curl_pp_readresp(curl_socket_t sockfd,
#ifdef HAVE_GSSAPI
if(!conn->sec_complete)
#endif
if(data->set.verbose)
Curl_debug(data, CURLINFO_HEADER_IN,
pp->linestart_resp, (size_t)perline);
Curl_debug(data, CURLINFO_HEADER_IN,
pp->linestart_resp, (size_t)perline);
/*
* We pass all response-lines to the callback function registered

View File

@ -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;
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;
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;
/* 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);
#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);
}
#endif
break;
default: /* nada */
break;
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
free(buf);
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;
}
}
#ifdef CURL_DOES_CONVERSIONS
free(buf);
#endif
}
return rc;
}

View File

@ -1152,10 +1152,9 @@ static CURLcode readwrite_upload(struct Curl_easy *data,
win_update_buffer_size(conn->writesockfd);
if(data->set.verbose)
/* show the data before we change the pointer upload_fromhere */
Curl_debug(data, CURLINFO_DATA_OUT, k->upload_fromhere,
(size_t)bytes_written);
/* show the data before we change the pointer upload_fromhere */
Curl_debug(data, CURLINFO_DATA_OUT, k->upload_fromhere,
(size_t)bytes_written);
k->writebytecount += bytes_written;
Curl_pgrsSetUploadCounter(data, k->writebytecount);

View File

@ -1432,11 +1432,8 @@ static CURLcode myssh_statemach_act(struct connectdata *conn, bool *block)
data->req.bytecount += sshc->readdir_len + 1;
/* output debug output if that is requested */
if(data->set.verbose) {
Curl_debug(data, CURLINFO_DATA_OUT,
(char *)sshc->readdir_filename,
sshc->readdir_len);
}
Curl_debug(data, CURLINFO_DATA_OUT, (char *)sshc->readdir_filename,
sshc->readdir_len);
}
else {
sshc->readdir_currLen = strlen(sshc->readdir_longentry);
@ -1548,12 +1545,9 @@ static CURLcode myssh_statemach_act(struct connectdata *conn, bool *block)
sshc->readdir_currLen);
if(!result) {
/* output debug output if that is requested */
if(data->set.verbose) {
Curl_debug(data, CURLINFO_DATA_OUT, sshc->readdir_line,
sshc->readdir_currLen);
}
Curl_debug(data, CURLINFO_DATA_OUT, sshc->readdir_line,
sshc->readdir_currLen);
data->req.bytecount += sshc->readdir_currLen;
}
Curl_safefree(sshc->readdir_line);
@ -2638,10 +2632,9 @@ static void sftp_quote(struct connectdata *conn)
sshc->nextstate = SSH_NO_STATE;
return;
}
if(data->set.verbose) {
Curl_debug(data, CURLINFO_HEADER_OUT, (char *) "PWD\n", 4);
Curl_debug(data, CURLINFO_HEADER_IN, tmp, strlen(tmp));
}
Curl_debug(data, CURLINFO_HEADER_OUT, (char *) "PWD\n", 4);
Curl_debug(data, CURLINFO_HEADER_IN, tmp, strlen(tmp));
/* this sends an FTP-like "header" to the header callback so that the
current directory can be read very similar to how it is read when
using ordinary FTP. */

View File

@ -1343,10 +1343,9 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
sshc->nextstate = SSH_NO_STATE;
break;
}
if(data->set.verbose) {
Curl_debug(data, CURLINFO_HEADER_OUT, (char *)"PWD\n", 4);
Curl_debug(data, CURLINFO_HEADER_IN, tmp, strlen(tmp));
}
Curl_debug(data, CURLINFO_HEADER_OUT, (char *)"PWD\n", 4);
Curl_debug(data, CURLINFO_HEADER_IN, tmp, strlen(tmp));
/* this sends an FTP-like "header" to the header callback so that the
current directory can be read very similar to how it is read when
using ordinary FTP. */
@ -2167,11 +2166,9 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
data->req.bytecount += readdir_len + 1;
/* output debug output if that is requested */
if(data->set.verbose) {
Curl_debug(data, CURLINFO_DATA_IN, sshc->readdir_filename,
readdir_len);
Curl_debug(data, CURLINFO_DATA_IN, (char *)"\n", 1);
}
Curl_debug(data, CURLINFO_DATA_IN, sshc->readdir_filename,
readdir_len);
Curl_debug(data, CURLINFO_DATA_IN, (char *)"\n", 1);
}
else {
result = Curl_dyn_add(&sshc->readdir, sshc->readdir_longentry);
@ -2252,13 +2249,10 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
Curl_dyn_len(&sshc->readdir));
if(!result) {
/* output debug output if that is requested */
if(data->set.verbose) {
Curl_debug(data, CURLINFO_DATA_IN,
Curl_dyn_ptr(&sshc->readdir),
Curl_dyn_len(&sshc->readdir));
}
Curl_debug(data, CURLINFO_DATA_IN,
Curl_dyn_ptr(&sshc->readdir),
Curl_dyn_len(&sshc->readdir));
data->req.bytecount += Curl_dyn_len(&sshc->readdir);
}
if(result) {
@ -3037,8 +3031,7 @@ static ssize_t ssh_tls_recv(libssh2_socket_t sock, void *buffer,
return -EAGAIN; /* magic return code for libssh2 */
else if(result)
return -1; /* generic error */
if(conn->data->set.verbose)
Curl_debug(conn->data, CURLINFO_DATA_IN, (char *)buffer, (size_t)nread);
Curl_debug(conn->data, CURLINFO_DATA_IN, (char *)buffer, (size_t)nread);
return nread;
}
@ -3061,8 +3054,7 @@ static ssize_t ssh_tls_send(libssh2_socket_t sock, const void *buffer,
return -EAGAIN; /* magic return code for libssh2 */
else if(result)
return -1; /* error */
if(conn->data->set.verbose)
Curl_debug(conn->data, CURLINFO_DATA_OUT, (char *)buffer, (size_t)nwrite);
Curl_debug(conn->data, CURLINFO_DATA_OUT, (char *)buffer, (size_t)nwrite);
return nwrite;
}
#endif