build: drop more forward function declarations

Most by moving functions around. Also delete unused ones.
Reducing their number from 83 to 33.

Remaining ones due to:
- circular dependencies.
- H3 code, that I did not attempt to update and likely the above applies.
- static declarations with attributes (`CURL_PRINTF`, `WARN_UNUSED_RESULT`).
- OS400 code.

Closes #20321
This commit is contained in:
Viktor Szakats 2026-01-14 17:11:55 +01:00
parent 6437bd79ae
commit 82e0d387a2
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
15 changed files with 1095 additions and 1250 deletions

View file

@ -29,10 +29,6 @@
#include "tool_util.h"
#include "toolx/tool_time.h"
static void dump(const char *timebuf, const char *idsbuf, const char *text,
FILE *stream, const unsigned char *ptr, size_t size,
trace tracetype, curl_infotype infotype);
/*
* Return the formatted HH:MM:SS for the tv_sec given.
*/
@ -69,6 +65,60 @@ static void log_line_start(FILE *log, const char *timebuf,
fputs(s_infotype[type], log);
}
static void dump(const char *timebuf, const char *idsbuf, const char *text,
FILE *stream, const unsigned char *ptr, size_t size,
trace tracetype, curl_infotype infotype)
{
size_t i;
size_t c;
unsigned int width = 0x10;
if(tracetype == TRACE_ASCII)
/* without the hex output, we can fit more on screen */
width = 0x40;
curl_mfprintf(stream, "%s%s%s, %zu bytes (0x%zx)\n", timebuf, idsbuf,
text, size, size);
for(i = 0; i < size; i += width) {
curl_mfprintf(stream, "%04zx: ", i);
if(tracetype == TRACE_BIN) {
/* hex not disabled, show it */
for(c = 0; c < width; c++)
if(i + c < size)
curl_mfprintf(stream, "%02x ", ptr[i + c]);
else
fputs(" ", stream);
}
for(c = 0; (c < width) && (i + c < size); c++) {
/* check for 0D0A; if found, skip past and start a new line of output */
if((tracetype == TRACE_ASCII) &&
(i + c + 1 < size) && (ptr[i + c] == 0x0D) &&
(ptr[i + c + 1] == 0x0A)) {
i += (c + 2 - width);
break;
}
(void)infotype;
curl_mfprintf(stream, "%c",
((ptr[i + c] >= 0x20) && (ptr[i + c] < 0x7F)) ?
ptr[i + c] : UNPRINTABLE_CHAR);
/* check again for 0D0A, to avoid an extra \n if it is at width */
if((tracetype == TRACE_ASCII) &&
(i + c + 2 < size) && (ptr[i + c + 1] == 0x0D) &&
(ptr[i + c + 2] == 0x0A)) {
i += (c + 3 - width);
break;
}
}
fputc('\n', stream); /* newline */
}
fflush(stream);
}
#define TRC_IDS_FORMAT_IDS_1 "[%" CURL_FORMAT_CURL_OFF_T "-x] "
#define TRC_IDS_FORMAT_IDS_2 "[%" CURL_FORMAT_CURL_OFF_T "-%" \
CURL_FORMAT_CURL_OFF_T "] "
@ -230,57 +280,3 @@ int tool_debug_cb(CURL *handle, curl_infotype type,
global->tracetype, type);
return 0;
}
static void dump(const char *timebuf, const char *idsbuf, const char *text,
FILE *stream, const unsigned char *ptr, size_t size,
trace tracetype, curl_infotype infotype)
{
size_t i;
size_t c;
unsigned int width = 0x10;
if(tracetype == TRACE_ASCII)
/* without the hex output, we can fit more on screen */
width = 0x40;
curl_mfprintf(stream, "%s%s%s, %zu bytes (0x%zx)\n", timebuf, idsbuf,
text, size, size);
for(i = 0; i < size; i += width) {
curl_mfprintf(stream, "%04zx: ", i);
if(tracetype == TRACE_BIN) {
/* hex not disabled, show it */
for(c = 0; c < width; c++)
if(i + c < size)
curl_mfprintf(stream, "%02x ", ptr[i + c]);
else
fputs(" ", stream);
}
for(c = 0; (c < width) && (i + c < size); c++) {
/* check for 0D0A; if found, skip past and start a new line of output */
if((tracetype == TRACE_ASCII) &&
(i + c + 1 < size) && (ptr[i + c] == 0x0D) &&
(ptr[i + c + 1] == 0x0A)) {
i += (c + 2 - width);
break;
}
(void)infotype;
curl_mfprintf(stream, "%c",
((ptr[i + c] >= 0x20) && (ptr[i + c] < 0x7F)) ?
ptr[i + c] : UNPRINTABLE_CHAR);
/* check again for 0D0A, to avoid an extra \n if it is at width */
if((tracetype == TRACE_ASCII) &&
(i + c + 2 < size) && (ptr[i + c + 1] == 0x0D) &&
(ptr[i + c + 2] == 0x0A)) {
i += (c + 3 - width);
break;
}
}
fputc('\n', stream); /* newline */
}
fflush(stream);
}

View file

@ -27,22 +27,6 @@
#include "tool_writeout.h"
#include "tool_writeout_json.h"
static int writeTime(FILE *stream, const struct writeoutvar *wovar,
struct per_transfer *per, CURLcode per_result,
bool use_json);
static int writeString(FILE *stream, const struct writeoutvar *wovar,
struct per_transfer *per, CURLcode per_result,
bool use_json);
static int writeLong(FILE *stream, const struct writeoutvar *wovar,
struct per_transfer *per, CURLcode per_result,
bool use_json);
static int writeOffset(FILE *stream, const struct writeoutvar *wovar,
struct per_transfer *per, CURLcode per_result,
bool use_json);
struct httpmap {
const char *str;
int num;
@ -57,103 +41,6 @@ static const struct httpmap http_version[] = {
{ NULL, 0 } /* end of list */
};
/* The designated write function should be the same as the CURLINFO return type
with exceptions special cased in the respective function. For example,
http_version uses CURLINFO_HTTP_VERSION which returns the version as a long,
however it is output as a string and therefore is handled in writeString.
Yes: "http_version": "1.1"
No: "http_version": 1.1
Variable names MUST be in alphabetical order.
*/
static const struct writeoutvar variables[] = {
{ "certs", VAR_CERT, CURLINFO_NONE, writeString },
{ "conn_id", VAR_CONN_ID, CURLINFO_CONN_ID, writeOffset },
{ "content_type", VAR_CONTENT_TYPE, CURLINFO_CONTENT_TYPE, writeString },
{ "errormsg", VAR_ERRORMSG, CURLINFO_NONE, writeString },
{ "exitcode", VAR_EXITCODE, CURLINFO_NONE, writeLong },
{ "filename_effective", VAR_EFFECTIVE_FILENAME, CURLINFO_NONE, writeString },
{ "ftp_entry_path", VAR_FTP_ENTRY_PATH, CURLINFO_FTP_ENTRY_PATH,
writeString },
{ "header_json", VAR_HEADER_JSON, CURLINFO_NONE, NULL },
{ "http_code", VAR_HTTP_CODE, CURLINFO_RESPONSE_CODE, writeLong },
{ "http_connect", VAR_HTTP_CODE_PROXY, CURLINFO_HTTP_CONNECTCODE,
writeLong },
{ "http_version", VAR_HTTP_VERSION, CURLINFO_HTTP_VERSION, writeString },
{ "json", VAR_JSON, CURLINFO_NONE, NULL },
{ "local_ip", VAR_LOCAL_IP, CURLINFO_LOCAL_IP, writeString },
{ "local_port", VAR_LOCAL_PORT, CURLINFO_LOCAL_PORT, writeLong },
{ "method", VAR_EFFECTIVE_METHOD, CURLINFO_EFFECTIVE_METHOD, writeString },
{ "num_certs", VAR_NUM_CERTS, CURLINFO_NONE, writeLong },
{ "num_connects", VAR_NUM_CONNECTS, CURLINFO_NUM_CONNECTS, writeLong },
{ "num_headers", VAR_NUM_HEADERS, CURLINFO_NONE, writeLong },
{ "num_redirects", VAR_REDIRECT_COUNT, CURLINFO_REDIRECT_COUNT, writeLong },
{ "num_retries", VAR_NUM_RETRY, CURLINFO_NONE, writeLong },
{ "onerror", VAR_ONERROR, CURLINFO_NONE, NULL },
{ "proxy_ssl_verify_result", VAR_PROXY_SSL_VERIFY_RESULT,
CURLINFO_PROXY_SSL_VERIFYRESULT, writeLong },
{ "proxy_used", VAR_PROXY_USED, CURLINFO_USED_PROXY, writeLong },
{ "redirect_url", VAR_REDIRECT_URL, CURLINFO_REDIRECT_URL, writeString },
{ "referer", VAR_REFERER, CURLINFO_REFERER, writeString },
{ "remote_ip", VAR_PRIMARY_IP, CURLINFO_PRIMARY_IP, writeString },
{ "remote_port", VAR_PRIMARY_PORT, CURLINFO_PRIMARY_PORT, writeLong },
{ "response_code", VAR_HTTP_CODE, CURLINFO_RESPONSE_CODE, writeLong },
{ "scheme", VAR_SCHEME, CURLINFO_SCHEME, writeString },
{ "size_download", VAR_SIZE_DOWNLOAD, CURLINFO_SIZE_DOWNLOAD_T,
writeOffset },
{ "size_header", VAR_HEADER_SIZE, CURLINFO_HEADER_SIZE, writeLong },
{ "size_request", VAR_REQUEST_SIZE, CURLINFO_REQUEST_SIZE, writeLong },
{ "size_upload", VAR_SIZE_UPLOAD, CURLINFO_SIZE_UPLOAD_T, writeOffset },
{ "speed_download", VAR_SPEED_DOWNLOAD, CURLINFO_SPEED_DOWNLOAD_T,
writeOffset },
{ "speed_upload", VAR_SPEED_UPLOAD, CURLINFO_SPEED_UPLOAD_T, writeOffset },
{ "ssl_verify_result", VAR_SSL_VERIFY_RESULT, CURLINFO_SSL_VERIFYRESULT,
writeLong },
{ "stderr", VAR_STDERR, CURLINFO_NONE, NULL },
{ "stdout", VAR_STDOUT, CURLINFO_NONE, NULL },
{ "time_appconnect", VAR_APPCONNECT_TIME, CURLINFO_APPCONNECT_TIME_T,
writeTime },
{ "time_connect", VAR_CONNECT_TIME, CURLINFO_CONNECT_TIME_T, writeTime },
{ "time_namelookup", VAR_NAMELOOKUP_TIME, CURLINFO_NAMELOOKUP_TIME_T,
writeTime },
{ "time_posttransfer", VAR_POSTTRANSFER_TIME, CURLINFO_POSTTRANSFER_TIME_T,
writeTime },
{ "time_pretransfer", VAR_PRETRANSFER_TIME, CURLINFO_PRETRANSFER_TIME_T,
writeTime },
{ "time_queue", VAR_QUEUE_TIME, CURLINFO_QUEUE_TIME_T, writeTime },
{ "time_redirect", VAR_REDIRECT_TIME, CURLINFO_REDIRECT_TIME_T, writeTime },
{ "time_starttransfer", VAR_STARTTRANSFER_TIME,
CURLINFO_STARTTRANSFER_TIME_T, writeTime },
{ "time_total", VAR_TOTAL_TIME, CURLINFO_TOTAL_TIME_T, writeTime },
{ "tls_earlydata", VAR_TLS_EARLYDATA_SENT, CURLINFO_EARLYDATA_SENT_T,
writeOffset },
{ "url", VAR_INPUT_URL, CURLINFO_NONE, writeString },
{ "url.fragment", VAR_INPUT_URLFRAGMENT, CURLINFO_NONE, writeString },
{ "url.host", VAR_INPUT_URLHOST, CURLINFO_NONE, writeString },
{ "url.options", VAR_INPUT_URLOPTIONS, CURLINFO_NONE, writeString },
{ "url.password", VAR_INPUT_URLPASSWORD, CURLINFO_NONE, writeString },
{ "url.path", VAR_INPUT_URLPATH, CURLINFO_NONE, writeString },
{ "url.port", VAR_INPUT_URLPORT, CURLINFO_NONE, writeString },
{ "url.query", VAR_INPUT_URLQUERY, CURLINFO_NONE, writeString },
{ "url.scheme", VAR_INPUT_URLSCHEME, CURLINFO_NONE, writeString },
{ "url.user", VAR_INPUT_URLUSER, CURLINFO_NONE, writeString },
{ "url.zoneid", VAR_INPUT_URLZONEID, CURLINFO_NONE, writeString },
{ "url_effective", VAR_EFFECTIVE_URL, CURLINFO_EFFECTIVE_URL, writeString },
{ "urle.fragment", VAR_INPUT_URLEFRAGMENT, CURLINFO_NONE, writeString },
{ "urle.host", VAR_INPUT_URLEHOST, CURLINFO_NONE, writeString },
{ "urle.options", VAR_INPUT_URLEOPTIONS, CURLINFO_NONE, writeString },
{ "urle.password", VAR_INPUT_URLEPASSWORD, CURLINFO_NONE, writeString },
{ "urle.path", VAR_INPUT_URLEPATH, CURLINFO_NONE, writeString },
{ "urle.port", VAR_INPUT_URLEPORT, CURLINFO_NONE, writeString },
{ "urle.query", VAR_INPUT_URLEQUERY, CURLINFO_NONE, writeString },
{ "urle.scheme", VAR_INPUT_URLESCHEME, CURLINFO_NONE, writeString },
{ "urle.user", VAR_INPUT_URLEUSER, CURLINFO_NONE, writeString },
{ "urle.zoneid", VAR_INPUT_URLEZONEID, CURLINFO_NONE, writeString },
{ "urlnum", VAR_URLNUM, CURLINFO_NONE, writeOffset },
{ "xfer_id", VAR_EASY_ID, CURLINFO_XFER_ID, writeOffset }
};
static int writeTime(FILE *stream, const struct writeoutvar *wovar,
struct per_transfer *per, CURLcode per_result,
bool use_json)
@ -530,13 +417,102 @@ static int writeOffset(FILE *stream, const struct writeoutvar *wovar,
return 1; /* return 1 if anything was written */
}
static int matchvar(const void *m1, const void *m2)
{
const struct writeoutvar *v1 = m1;
const struct writeoutvar *v2 = m2;
/* The designated write function should be the same as the CURLINFO return type
with exceptions special cased in the respective function. For example,
http_version uses CURLINFO_HTTP_VERSION which returns the version as a long,
however it is output as a string and therefore is handled in writeString.
return strcmp(v1->name, v2->name);
}
Yes: "http_version": "1.1"
No: "http_version": 1.1
Variable names MUST be in alphabetical order.
*/
static const struct writeoutvar variables[] = {
{ "certs", VAR_CERT, CURLINFO_NONE, writeString },
{ "conn_id", VAR_CONN_ID, CURLINFO_CONN_ID, writeOffset },
{ "content_type", VAR_CONTENT_TYPE, CURLINFO_CONTENT_TYPE, writeString },
{ "errormsg", VAR_ERRORMSG, CURLINFO_NONE, writeString },
{ "exitcode", VAR_EXITCODE, CURLINFO_NONE, writeLong },
{ "filename_effective", VAR_EFFECTIVE_FILENAME, CURLINFO_NONE, writeString },
{ "ftp_entry_path", VAR_FTP_ENTRY_PATH, CURLINFO_FTP_ENTRY_PATH,
writeString },
{ "header_json", VAR_HEADER_JSON, CURLINFO_NONE, NULL },
{ "http_code", VAR_HTTP_CODE, CURLINFO_RESPONSE_CODE, writeLong },
{ "http_connect", VAR_HTTP_CODE_PROXY, CURLINFO_HTTP_CONNECTCODE,
writeLong },
{ "http_version", VAR_HTTP_VERSION, CURLINFO_HTTP_VERSION, writeString },
{ "json", VAR_JSON, CURLINFO_NONE, NULL },
{ "local_ip", VAR_LOCAL_IP, CURLINFO_LOCAL_IP, writeString },
{ "local_port", VAR_LOCAL_PORT, CURLINFO_LOCAL_PORT, writeLong },
{ "method", VAR_EFFECTIVE_METHOD, CURLINFO_EFFECTIVE_METHOD, writeString },
{ "num_certs", VAR_NUM_CERTS, CURLINFO_NONE, writeLong },
{ "num_connects", VAR_NUM_CONNECTS, CURLINFO_NUM_CONNECTS, writeLong },
{ "num_headers", VAR_NUM_HEADERS, CURLINFO_NONE, writeLong },
{ "num_redirects", VAR_REDIRECT_COUNT, CURLINFO_REDIRECT_COUNT, writeLong },
{ "num_retries", VAR_NUM_RETRY, CURLINFO_NONE, writeLong },
{ "onerror", VAR_ONERROR, CURLINFO_NONE, NULL },
{ "proxy_ssl_verify_result", VAR_PROXY_SSL_VERIFY_RESULT,
CURLINFO_PROXY_SSL_VERIFYRESULT, writeLong },
{ "proxy_used", VAR_PROXY_USED, CURLINFO_USED_PROXY, writeLong },
{ "redirect_url", VAR_REDIRECT_URL, CURLINFO_REDIRECT_URL, writeString },
{ "referer", VAR_REFERER, CURLINFO_REFERER, writeString },
{ "remote_ip", VAR_PRIMARY_IP, CURLINFO_PRIMARY_IP, writeString },
{ "remote_port", VAR_PRIMARY_PORT, CURLINFO_PRIMARY_PORT, writeLong },
{ "response_code", VAR_HTTP_CODE, CURLINFO_RESPONSE_CODE, writeLong },
{ "scheme", VAR_SCHEME, CURLINFO_SCHEME, writeString },
{ "size_download", VAR_SIZE_DOWNLOAD, CURLINFO_SIZE_DOWNLOAD_T,
writeOffset },
{ "size_header", VAR_HEADER_SIZE, CURLINFO_HEADER_SIZE, writeLong },
{ "size_request", VAR_REQUEST_SIZE, CURLINFO_REQUEST_SIZE, writeLong },
{ "size_upload", VAR_SIZE_UPLOAD, CURLINFO_SIZE_UPLOAD_T, writeOffset },
{ "speed_download", VAR_SPEED_DOWNLOAD, CURLINFO_SPEED_DOWNLOAD_T,
writeOffset },
{ "speed_upload", VAR_SPEED_UPLOAD, CURLINFO_SPEED_UPLOAD_T, writeOffset },
{ "ssl_verify_result", VAR_SSL_VERIFY_RESULT, CURLINFO_SSL_VERIFYRESULT,
writeLong },
{ "stderr", VAR_STDERR, CURLINFO_NONE, NULL },
{ "stdout", VAR_STDOUT, CURLINFO_NONE, NULL },
{ "time_appconnect", VAR_APPCONNECT_TIME, CURLINFO_APPCONNECT_TIME_T,
writeTime },
{ "time_connect", VAR_CONNECT_TIME, CURLINFO_CONNECT_TIME_T, writeTime },
{ "time_namelookup", VAR_NAMELOOKUP_TIME, CURLINFO_NAMELOOKUP_TIME_T,
writeTime },
{ "time_posttransfer", VAR_POSTTRANSFER_TIME, CURLINFO_POSTTRANSFER_TIME_T,
writeTime },
{ "time_pretransfer", VAR_PRETRANSFER_TIME, CURLINFO_PRETRANSFER_TIME_T,
writeTime },
{ "time_queue", VAR_QUEUE_TIME, CURLINFO_QUEUE_TIME_T, writeTime },
{ "time_redirect", VAR_REDIRECT_TIME, CURLINFO_REDIRECT_TIME_T, writeTime },
{ "time_starttransfer", VAR_STARTTRANSFER_TIME,
CURLINFO_STARTTRANSFER_TIME_T, writeTime },
{ "time_total", VAR_TOTAL_TIME, CURLINFO_TOTAL_TIME_T, writeTime },
{ "tls_earlydata", VAR_TLS_EARLYDATA_SENT, CURLINFO_EARLYDATA_SENT_T,
writeOffset },
{ "url", VAR_INPUT_URL, CURLINFO_NONE, writeString },
{ "url.fragment", VAR_INPUT_URLFRAGMENT, CURLINFO_NONE, writeString },
{ "url.host", VAR_INPUT_URLHOST, CURLINFO_NONE, writeString },
{ "url.options", VAR_INPUT_URLOPTIONS, CURLINFO_NONE, writeString },
{ "url.password", VAR_INPUT_URLPASSWORD, CURLINFO_NONE, writeString },
{ "url.path", VAR_INPUT_URLPATH, CURLINFO_NONE, writeString },
{ "url.port", VAR_INPUT_URLPORT, CURLINFO_NONE, writeString },
{ "url.query", VAR_INPUT_URLQUERY, CURLINFO_NONE, writeString },
{ "url.scheme", VAR_INPUT_URLSCHEME, CURLINFO_NONE, writeString },
{ "url.user", VAR_INPUT_URLUSER, CURLINFO_NONE, writeString },
{ "url.zoneid", VAR_INPUT_URLZONEID, CURLINFO_NONE, writeString },
{ "url_effective", VAR_EFFECTIVE_URL, CURLINFO_EFFECTIVE_URL, writeString },
{ "urle.fragment", VAR_INPUT_URLEFRAGMENT, CURLINFO_NONE, writeString },
{ "urle.host", VAR_INPUT_URLEHOST, CURLINFO_NONE, writeString },
{ "urle.options", VAR_INPUT_URLEOPTIONS, CURLINFO_NONE, writeString },
{ "urle.password", VAR_INPUT_URLEPASSWORD, CURLINFO_NONE, writeString },
{ "urle.path", VAR_INPUT_URLEPATH, CURLINFO_NONE, writeString },
{ "urle.port", VAR_INPUT_URLEPORT, CURLINFO_NONE, writeString },
{ "urle.query", VAR_INPUT_URLEQUERY, CURLINFO_NONE, writeString },
{ "urle.scheme", VAR_INPUT_URLESCHEME, CURLINFO_NONE, writeString },
{ "urle.user", VAR_INPUT_URLEUSER, CURLINFO_NONE, writeString },
{ "urle.zoneid", VAR_INPUT_URLEZONEID, CURLINFO_NONE, writeString },
{ "urlnum", VAR_URLNUM, CURLINFO_NONE, writeOffset },
{ "xfer_id", VAR_EASY_ID, CURLINFO_XFER_ID, writeOffset }
};
#define MAX_WRITEOUT_NAME_LENGTH 24
@ -720,6 +696,14 @@ static void output_header(struct per_transfer *per,
*pptr = ptr;
}
static int matchvar(const void *m1, const void *m2)
{
const struct writeoutvar *v1 = m1;
const struct writeoutvar *v2 = m2;
return strcmp(v1->name, v2->name);
}
void ourWriteOut(struct OperationConfig *config, struct per_transfer *per,
CURLcode per_result)
{