1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-24 17:18:48 -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,7 +156,6 @@ static CURLcode sendf(curl_socket_t sockfd, struct connectdata *conn,
if(result) if(result)
break; 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((size_t)bytes_written != write_len) {

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

View File

@ -1496,7 +1496,6 @@ static ssize_t http2_handle_stream_close(struct connectdata *conn,
break; break;
len = lf + 1 - trailp; 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 */ /* pass the trailers one by one to the callback */
result = Curl_client_write(conn, CLIENTWRITE_HEADER, trailp, len); result = Curl_client_write(conn, CLIENTWRITE_HEADER, trailp, len);

View File

@ -410,7 +410,6 @@ static CURLcode CONNECT(struct connectdata *conn,
return result; return result;
/* output debug if that is requested */ /* 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) { if(!data->set.suppress_connect_headers) {

View File

@ -99,7 +99,6 @@ static CURLcode ftpsend(struct connectdata *conn, const char *cmd)
if(result) if(result)
break; 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) { if(bytes_written != (ssize_t)write_len) {
@ -716,7 +715,7 @@ int Curl_sec_read_msg(struct connectdata *conn, char *buffer,
return -1; return -1;
} }
if(conn->data->set.verbose) { {
buf[decoded_len] = '\n'; buf[decoded_len] = '\n';
Curl_debug(conn->data, CURLINFO_HEADER_IN, buf, decoded_len + 1); 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; struct MQTT *mq = data->req.protop;
ssize_t n; ssize_t n;
result = Curl_write(conn, sockfd, buf, len, &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); Curl_debug(data, CURLINFO_HEADER_OUT, buf, (size_t)n);
if(len != (size_t)n) { if(len != (size_t)n) {
size_t nsend = len - n; size_t nsend = len - n;
@ -185,7 +185,6 @@ static CURLcode mqtt_verify_connack(struct connectdata *conn)
if(result) if(result)
goto fail; 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 */ /* fixme */
@ -298,7 +297,6 @@ static CURLcode mqtt_verify_suback(struct connectdata *conn)
if(result) if(result)
goto fail; 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 */ /* fixme */
@ -486,7 +484,6 @@ static CURLcode mqtt_read_publish(struct connectdata *conn,
result = CURLE_PARTIAL_FILE; result = CURLE_PARTIAL_FILE;
goto end; 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; mq->npacket -= nread;
@ -558,7 +555,6 @@ static CURLcode mqtt_doing(struct connectdata *conn, bool *done)
result = Curl_read(conn, sockfd, (char *)&mq->firstbyte, 1, &nread); result = Curl_read(conn, sockfd, (char *)&mq->firstbyte, 1, &nread);
if(result) if(result)
break; 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 */ /* remember the first byte */
mq->npacket = 0; mq->npacket = 0;
@ -569,7 +565,6 @@ static CURLcode mqtt_doing(struct connectdata *conn, bool *done)
result = Curl_read(conn, sockfd, (char *)&byte, 1, &nread); result = Curl_read(conn, sockfd, (char *)&byte, 1, &nread);
if(result) if(result)
break; 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; pkt[mq->npacket++] = byte;
} while((byte & 0x80) && (mq->npacket < 4)); } while((byte & 0x80) && (mq->npacket < 4));

View File

@ -218,7 +218,6 @@ CURLcode Curl_pp_vsendf(struct pingpong *pp,
conn->data_prot = data_sec; conn->data_prot = data_sec;
#endif #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) { if(bytes_written != (ssize_t)write_len) {
@ -364,7 +363,6 @@ CURLcode Curl_pp_readresp(curl_socket_t sockfd,
#ifdef HAVE_GSSAPI #ifdef HAVE_GSSAPI
if(!conn->sec_complete) if(!conn->sec_complete)
#endif #endif
if(data->set.verbose)
Curl_debug(data, CURLINFO_HEADER_IN, Curl_debug(data, CURLINFO_HEADER_IN,
pp->linestart_resp, (size_t)perline); pp->linestart_resp, (size_t)perline);

View File

@ -277,11 +277,8 @@ void Curl_failf(struct Curl_easy *data, const char *fmt, ...)
strcpy(data->set.errorbuffer, error); strcpy(data->set.errorbuffer, error);
data->state.errorbuf = TRUE; /* wrote error string */ data->state.errorbuf = TRUE; /* wrote error string */
} }
if(data->set.verbose) { error[len++] = '\n';
error[len] = '\n';
error[++len] = '\0';
Curl_debug(data, CURLINFO_TEXT, error, len); Curl_debug(data, CURLINFO_TEXT, error, len);
}
va_end(ap); va_end(ap);
} }
} }
@ -693,9 +690,10 @@ CURLcode Curl_read(struct connectdata *conn, /* connection data */
int Curl_debug(struct Curl_easy *data, curl_infotype type, int Curl_debug(struct Curl_easy *data, curl_infotype type,
char *ptr, size_t size) char *ptr, size_t size)
{ {
int rc = 0;
if(data->set.verbose) {
static const char s_infotype[CURLINFO_END][3] = { static const char s_infotype[CURLINFO_END][3] = {
"* ", "< ", "> ", "{ ", "} ", "{ ", "} " }; "* ", "< ", "> ", "{ ", "} ", "{ ", "} " };
int rc = 0;
#ifdef CURL_DOES_CONVERSIONS #ifdef CURL_DOES_CONVERSIONS
char *buf = NULL; char *buf = NULL;
@ -760,5 +758,6 @@ int Curl_debug(struct Curl_easy *data, curl_infotype type,
#ifdef CURL_DOES_CONVERSIONS #ifdef CURL_DOES_CONVERSIONS
free(buf); free(buf);
#endif #endif
}
return rc; return rc;
} }

View File

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

View File

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

View File

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