curl_log: for failf/infof and debug logging implementations

- new functions and macros for cfilter debugging
 - set CURL_DEBUG with names of cfilters where debug logging should be
   enabled
 - use GNUC __attribute__ to enable printf format checks during compile

Closes #10271
This commit is contained in:
Stefan Eissing 2023-01-11 10:30:42 +01:00 committed by Daniel Stenberg
parent 5cf5bfcd13
commit db91dbbf2c
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
29 changed files with 656 additions and 466 deletions

View file

@ -82,13 +82,6 @@
#include "curl_memory.h"
#include "memdebug.h"
#define DEBUG_CF 0
#if DEBUG_CF
#define CF_DEBUGF(x) x
#else
#define CF_DEBUGF(x) do { } while(0)
#endif
/*
* Curl_timeleft() returns the amount of milliseconds left allowed for the
@ -473,7 +466,7 @@ static void baller_initiate(struct Curl_cfilter *cf,
out:
if(result) {
CF_DEBUGF(infof(data, "eyeballer[%s] failed", baller->name));
DEBUGF(LOG_CF(data, cf, "%s failed", baller->name));
baller_close(baller, data);
}
if(cf_prev)
@ -597,8 +590,8 @@ evaluate:
continue;
}
baller->result = baller_connect(cf, data, baller, &now, connected);
CF_DEBUGF(infof(data, CFMSG(cf, "eyeballer[%s] connect -> %d, "
"connected=%d"), baller->name, baller->result, *connected));
DEBUGF(LOG_CF(data, cf, "%s connect -> %d, connected=%d",
baller->name, baller->result, *connected));
if(!baller->result) {
if(*connected) {
@ -621,12 +614,11 @@ evaluate:
baller->timeoutms = baller->addr->ai_next == NULL ? allow : allow / 2;
baller_start_next(cf, data, baller);
if(baller->is_done) {
CF_DEBUGF(infof(data, CFMSG(cf, "eyeballer[%s] done"), baller->name));
DEBUGF(LOG_CF(data, cf, "%s done", baller->name));
}
else {
/* next attempt was started */
CF_DEBUGF(infof(data, CFMSG(cf, "eyeballer[%s] trying next"),
baller->name));
DEBUGF(LOG_CF(data, cf, "%s trying next", baller->name));
++ongoing;
}
}
@ -660,12 +652,10 @@ evaluate:
Curl_timediff(now, ctx->started) >= baller->delay_ms) {
baller_start(cf, data, baller);
if(baller->is_done) {
CF_DEBUGF(infof(data, CFMSG(cf, "eyeballer[%s] done"),
baller->name));
DEBUGF(LOG_CF(data, cf, "%s done", baller->name));
}
else {
CF_DEBUGF(infof(data, CFMSG(cf, "eyeballer[%s] starting"),
baller->name));
DEBUGF(LOG_CF(data, cf, "%s starting", baller->name));
++ongoing;
++added;
}
@ -682,13 +672,12 @@ evaluate:
}
/* all ballers have failed to connect. */
CF_DEBUGF(infof(data, CFMSG(cf, "all eyeballers failed")));
DEBUGF(LOG_CF(data, cf, "all eyeballers failed"));
result = CURLE_COULDNT_CONNECT;
for(i = 0; i < sizeof(ctx->baller)/sizeof(ctx->baller[0]); i++) {
struct eyeballer *baller = ctx->baller[i];
CF_DEBUGF(infof(data, CFMSG(cf, "eyeballer[%s] assess started=%d, "
"result=%d"),
baller->name, baller->has_started, baller->result));
DEBUGF(LOG_CF(data, cf, "%s assess started=%d, result=%d",
baller->name, baller->has_started, baller->result));
if(baller && baller->has_started && baller->result) {
result = baller->result;
break;
@ -926,7 +915,7 @@ static void cf_he_close(struct Curl_cfilter *cf,
{
struct cf_he_ctx *ctx = cf->ctx;
CF_DEBUGF(infof(data, CFMSG(cf, "close")));
DEBUGF(LOG_CF(data, cf, "close"));
cf_he_ctx_clear(cf, data);
cf->connected = FALSE;
ctx->state = SCFST_INIT;
@ -960,7 +949,7 @@ static void cf_he_destroy(struct Curl_cfilter *cf, struct Curl_easy *data)
{
struct cf_he_ctx *ctx = cf->ctx;
CF_DEBUGF(infof(data, CFMSG(cf, "destroy")));
DEBUGF(LOG_CF(data, cf, "destroy"));
if(ctx) {
cf_he_ctx_clear(cf, data);
}
@ -968,9 +957,10 @@ static void cf_he_destroy(struct Curl_cfilter *cf, struct Curl_easy *data)
Curl_safefree(ctx);
}
static const struct Curl_cftype cft_happy_eyeballs = {
struct Curl_cftype Curl_cft_happy_eyeballs = {
"HAPPY-EYEBALLS",
0,
CURL_LOG_DEFAULT,
cf_he_destroy,
cf_he_connect,
cf_he_close,
@ -1005,7 +995,7 @@ CURLcode Curl_cf_happy_eyeballs_create(struct Curl_cfilter **pcf,
ctx->cf_create = cf_create;
ctx->remotehost = remotehost;
result = Curl_cf_create(pcf, &cft_happy_eyeballs, ctx);
result = Curl_cf_create(pcf, &Curl_cft_happy_eyeballs, ctx);
out:
if(result) {
@ -1046,8 +1036,7 @@ static CURLcode cf_he_insert_after(struct Curl_cfilter *cf_at,
DEBUGASSERT(cf_at);
cf_create = get_cf_create(transport);
if(!cf_create) {
CF_DEBUGF(infof(data, DMSG(data, "unsupported transport type %d"),
transport));
DEBUGF(LOG_CF(data, cf_at, "unsupported transport type %d", transport));
return CURLE_UNSUPPORTED_PROTOCOL;
}
result = Curl_cf_happy_eyeballs_create(&cf, data, cf_at->conn,
@ -1184,7 +1173,7 @@ static void cf_setup_close(struct Curl_cfilter *cf,
{
struct cf_setup_ctx *ctx = cf->ctx;
CF_DEBUGF(infof(data, CFMSG(cf, "close")));
DEBUGF(LOG_CF(data, cf, "close"));
cf->connected = FALSE;
ctx->state = CF_SETUP_INIT;
@ -1199,14 +1188,15 @@ static void cf_setup_destroy(struct Curl_cfilter *cf, struct Curl_easy *data)
struct cf_setup_ctx *ctx = cf->ctx;
(void)data;
CF_DEBUGF(infof(data, CFMSG(cf, "destroy")));
DEBUGF(LOG_CF(data, cf, "destroy"));
Curl_safefree(ctx);
}
static const struct Curl_cftype cft_setup = {
struct Curl_cftype Curl_cft_setup = {
"SETUP",
0,
CURL_LOG_DEFAULT,
cf_setup_destroy,
cf_setup_connect,
cf_setup_close,
@ -1245,7 +1235,7 @@ CURLcode Curl_conn_setup(struct Curl_easy *data,
ctx->remotehost = remotehost;
ctx->ssl_mode = ssl_mode;
result = Curl_cf_create(&cf, &cft_setup, ctx);
result = Curl_cf_create(&cf, &Curl_cft_setup, ctx);
if(result)
goto out;
ctx = NULL;