smtp: add tracing feature

Add `smtp` as tracing feature, use CURL_TRC_SMTP() in code to
trace operations.

Closes #14531
This commit is contained in:
Stefan Eissing 2024-08-13 13:49:07 +02:00 committed by Daniel Stenberg
parent 8058bbae52
commit 1c42ea4066
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
4 changed files with 61 additions and 14 deletions

View File

@ -105,6 +105,10 @@ Tracing of DNS-over-HTTP operations to resolve hostnames.
Traces reading of upload data from the application in order to send it to the server.
## `smtp`
Tracing of SMTP operations when this protocol is enabled in your build.
## `write`
Traces writing of download data, received from the server, to the application.

View File

@ -221,6 +221,24 @@ void Curl_trc_ftp(struct Curl_easy *data, const char *fmt, ...)
}
#endif /* !CURL_DISABLE_FTP */
#ifndef CURL_DISABLE_SMTP
struct curl_trc_feat Curl_trc_feat_smtp = {
"SMTP",
CURL_LOG_LVL_NONE,
};
void Curl_trc_smtp(struct Curl_easy *data, const char *fmt, ...)
{
DEBUGASSERT(!strchr(fmt, '\n'));
if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_smtp)) {
va_list ap;
va_start(ap, fmt);
trc_infof(data, &Curl_trc_feat_smtp, fmt, ap);
va_end(ap);
}
}
#endif /* !CURL_DISABLE_SMTP */
#if defined(USE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP)
struct curl_trc_feat Curl_trc_feat_ws = {
"WS",
@ -258,6 +276,9 @@ static struct trc_feat_def trc_feats[] = {
#ifndef CURL_DISABLE_DOH
{ &Curl_doh_trc, TRC_CT_NETWORK },
#endif
#ifndef CURL_DISABLE_SMTP
{ &Curl_trc_feat_smtp, TRC_CT_PROTOCOL },
#endif
#if defined(USE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP)
{ &Curl_trc_feat_ws, TRC_CT_PROTOCOL },
#endif

View File

@ -89,6 +89,11 @@ void Curl_failf(struct Curl_easy *data,
do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ftp)) \
Curl_trc_ftp(data, __VA_ARGS__); } while(0)
#endif /* !CURL_DISABLE_FTP */
#ifndef CURL_DISABLE_SMTP
#define CURL_TRC_SMTP(data, ...) \
do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_smtp)) \
Curl_trc_smtp(data, __VA_ARGS__); } while(0)
#endif /* !CURL_DISABLE_SMTP */
#if defined(USE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP)
#define CURL_TRC_WS(data, ...) \
do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ws)) \
@ -105,6 +110,9 @@ void Curl_failf(struct Curl_easy *data,
#ifndef CURL_DISABLE_FTP
#define CURL_TRC_FTP Curl_trc_ftp
#endif
#ifndef CURL_DISABLE_SMTP
#define CURL_TRC_SMTP Curl_trc_smtp
#endif
#if defined(USE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP)
#define CURL_TRC_WS Curl_trc_ws
#endif
@ -156,6 +164,11 @@ extern struct curl_trc_feat Curl_trc_feat_ftp;
void Curl_trc_ftp(struct Curl_easy *data,
const char *fmt, ...) CURL_PRINTF(2, 3);
#endif
#ifndef CURL_DISABLE_SMTP
extern struct curl_trc_feat Curl_trc_feat_smtp;
void Curl_trc_smtp(struct Curl_easy *data,
const char *fmt, ...) CURL_PRINTF(2, 3);
#endif
#if defined(USE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP)
extern struct curl_trc_feat Curl_trc_feat_ws;
void Curl_trc_ws(struct Curl_easy *data,
@ -207,6 +220,12 @@ static void Curl_trc_ftp(struct Curl_easy *data, const char *fmt, ...)
(void)data; (void)fmt;
}
#endif
#ifndef CURL_DISABLE_SMTP
static void Curl_trc_smtp(struct Curl_easy *data, const char *fmt, ...)
{
(void)data; (void)fmt;
}
#endif
#endif /* !defined(CURL_DISABLE_VERBOSE_STRINGS) */

View File

@ -288,7 +288,7 @@ static CURLcode smtp_get_message(struct Curl_easy *data, struct bufref *out)
static void smtp_state(struct Curl_easy *data, smtpstate newstate)
{
struct smtp_conn *smtpc = &data->conn->proto.smtpc;
#if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS)
#if !defined(CURL_DISABLE_VERBOSE_STRINGS)
/* for debug purposes */
static const char * const names[] = {
"STOP",
@ -308,8 +308,8 @@ static void smtp_state(struct Curl_easy *data, smtpstate newstate)
};
if(smtpc->state != newstate)
infof(data, "SMTP %p state change from %s to %s",
(void *)smtpc, names[smtpc->state], names[newstate]);
CURL_TRC_SMTP(data, "state change from %s to %s",
names[smtpc->state], names[newstate]);
#endif
smtpc->state = newstate;
@ -1422,7 +1422,8 @@ static CURLcode smtp_done(struct Curl_easy *data, CURLcode status,
/* Clear the transfer mode for the next request */
smtp->transfer = PPTRANSFER_BODY;
CURL_TRC_SMTP(data, "smtp_done(status=%d, premature=%d) -> %d",
status, premature, result);
return result;
}
@ -1440,7 +1441,7 @@ static CURLcode smtp_perform(struct Curl_easy *data, bool *connected,
CURLcode result = CURLE_OK;
struct SMTP *smtp = data->req.p.smtp;
DEBUGF(infof(data, "DO phase starts"));
CURL_TRC_SMTP(data, "smtp_perform(), start");
if(data->req.no_body) {
/* Requested no body means no transfer */
@ -1472,16 +1473,16 @@ static CURLcode smtp_perform(struct Curl_easy *data, bool *connected,
result = smtp_perform_command(data);
if(result)
return result;
goto out;
/* Run the state-machine */
result = smtp_multi_statemach(data, dophase_done);
*connected = Curl_conn_is_connected(data->conn, FIRSTSOCKET);
if(*dophase_done)
DEBUGF(infof(data, "DO phase is complete"));
out:
CURL_TRC_SMTP(data, "smtp_perform() -> %d, connected=%d, done=%d",
result, *connected, *dophase_done);
return result;
}
@ -1507,7 +1508,7 @@ static CURLcode smtp_do(struct Curl_easy *data, bool *done)
return result;
result = smtp_regular_transfer(data, done);
CURL_TRC_SMTP(data, "smtp_do() -> %d, done=%d", result, *done);
return result;
}
@ -1542,6 +1543,7 @@ static CURLcode smtp_disconnect(struct Curl_easy *data,
/* Cleanup our connection based variables */
Curl_safefree(smtpc->domain);
CURL_TRC_SMTP(data, "smtp_disconnect(), finished");
return CURLE_OK;
}
@ -1573,6 +1575,7 @@ static CURLcode smtp_doing(struct Curl_easy *data, bool *dophase_done)
DEBUGF(infof(data, "DO phase is complete"));
}
CURL_TRC_SMTP(data, "smtp_doing() -> %d, done=%d", result, *dophase_done);
return result;
}
@ -1607,6 +1610,8 @@ static CURLcode smtp_regular_transfer(struct Curl_easy *data,
if(!result && *dophase_done)
result = smtp_dophase_done(data, connected);
CURL_TRC_SMTP(data, "smtp_regular_transfer() -> %d, done=%d",
result, *dophase_done);
return result;
}
@ -1620,10 +1625,8 @@ static CURLcode smtp_setup_connection(struct Curl_easy *data,
/* Initialise the SMTP layer */
result = smtp_init(data);
if(result)
return result;
return CURLE_OK;
CURL_TRC_SMTP(data, "smtp_setup_connection() -> %d", result);
return result;
}
/***********************************************************************