mirror of
https://github.com/curl/curl.git
synced 2024-11-21 01:16:58 +08:00
lib: apache style infof and trace macros/functions
- test for a simplified C99 variadic check - args to infof() in --disable-verbose are no longer disregarded but must compile. Closes #12167 Fixes #12083 Fixes #11880 Fixes #11891
This commit is contained in:
parent
d1a7da6531
commit
dac293cfb7
@ -56,12 +56,14 @@ static const char * const telnetoptions[]=
|
|||||||
"TERM SPEED", "LFLOW", "LINEMODE", "XDISPLOC",
|
"TERM SPEED", "LFLOW", "LINEMODE", "XDISPLOC",
|
||||||
"OLD-ENVIRON", "AUTHENTICATION", "ENCRYPT", "NEW-ENVIRON"
|
"OLD-ENVIRON", "AUTHENTICATION", "ENCRYPT", "NEW-ENVIRON"
|
||||||
};
|
};
|
||||||
|
#define CURL_TELOPT(x) telnetoptions[x]
|
||||||
|
#else
|
||||||
|
#define CURL_TELOPT(x) ""
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CURL_TELOPT_MAXIMUM CURL_TELOPT_NEW_ENVIRON
|
#define CURL_TELOPT_MAXIMUM CURL_TELOPT_NEW_ENVIRON
|
||||||
|
|
||||||
#define CURL_TELOPT_OK(x) ((x) <= CURL_TELOPT_MAXIMUM)
|
#define CURL_TELOPT_OK(x) ((x) <= CURL_TELOPT_MAXIMUM)
|
||||||
#define CURL_TELOPT(x) telnetoptions[x]
|
|
||||||
|
|
||||||
#define CURL_NTELOPTS 40
|
#define CURL_NTELOPTS 40
|
||||||
|
|
||||||
@ -103,7 +105,12 @@ static const char * const telnetcmds[]=
|
|||||||
|
|
||||||
#define CURL_TELCMD_OK(x) ( ((unsigned int)(x) >= CURL_TELCMD_MINIMUM) && \
|
#define CURL_TELCMD_OK(x) ( ((unsigned int)(x) >= CURL_TELCMD_MINIMUM) && \
|
||||||
((unsigned int)(x) <= CURL_TELCMD_MAXIMUM) )
|
((unsigned int)(x) <= CURL_TELCMD_MAXIMUM) )
|
||||||
|
|
||||||
|
#ifndef CURL_DISABLE_VERBOSE_STRINGS
|
||||||
#define CURL_TELCMD(x) telnetcmds[(x)-CURL_TELCMD_MINIMUM]
|
#define CURL_TELCMD(x) telnetcmds[(x)-CURL_TELCMD_MINIMUM]
|
||||||
|
#else
|
||||||
|
#define CURL_TELCMD(x) ""
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* CURL_DISABLE_TELNET */
|
#endif /* CURL_DISABLE_TELNET */
|
||||||
|
|
||||||
|
@ -102,11 +102,7 @@ static void tcpnodelay(struct Curl_easy *data, curl_socket_t sockfd)
|
|||||||
#if defined(TCP_NODELAY)
|
#if defined(TCP_NODELAY)
|
||||||
curl_socklen_t onoff = (curl_socklen_t) 1;
|
curl_socklen_t onoff = (curl_socklen_t) 1;
|
||||||
int level = IPPROTO_TCP;
|
int level = IPPROTO_TCP;
|
||||||
#if !defined(CURL_DISABLE_VERBOSE_STRINGS)
|
|
||||||
char buffer[STRERROR_LEN];
|
char buffer[STRERROR_LEN];
|
||||||
#else
|
|
||||||
(void) data;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if(setsockopt(sockfd, level, TCP_NODELAY, (void *)&onoff,
|
if(setsockopt(sockfd, level, TCP_NODELAY, (void *)&onoff,
|
||||||
sizeof(onoff)) < 0)
|
sizeof(onoff)) < 0)
|
||||||
|
@ -105,6 +105,8 @@ void Curl_failf(struct Curl_easy *data, const char *fmt, ...)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(CURL_DISABLE_VERBOSE_STRINGS)
|
||||||
|
|
||||||
/* Curl_infof() is for info message along the way */
|
/* Curl_infof() is for info message along the way */
|
||||||
#define MAXINFO 2048
|
#define MAXINFO 2048
|
||||||
|
|
||||||
@ -124,8 +126,6 @@ void Curl_infof(struct Curl_easy *data, const char *fmt, ...)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(CURL_DISABLE_VERBOSE_STRINGS)
|
|
||||||
|
|
||||||
void Curl_trc_cf_infof(struct Curl_easy *data, struct Curl_cfilter *cf,
|
void Curl_trc_cf_infof(struct Curl_easy *data, struct Curl_cfilter *cf,
|
||||||
const char *fmt, ...)
|
const char *fmt, ...)
|
||||||
{
|
{
|
||||||
@ -238,14 +238,4 @@ CURLcode Curl_trc_init(void)
|
|||||||
return CURLE_OK;
|
return CURLE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L)
|
|
||||||
void Curl_trc_cf_infof(struct Curl_easy *data, struct Curl_cfilter *cf,
|
|
||||||
const char *fmt, ...)
|
|
||||||
{
|
|
||||||
(void)data;
|
|
||||||
(void)cf;
|
|
||||||
(void)fmt;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* !DEBUGBUILD */
|
#endif /* !DEBUGBUILD */
|
||||||
|
104
lib/curl_trc.h
104
lib/curl_trc.h
@ -54,19 +54,6 @@ CURLcode Curl_trc_opt(const char *config);
|
|||||||
void Curl_debug(struct Curl_easy *data, curl_infotype type,
|
void Curl_debug(struct Curl_easy *data, curl_infotype type,
|
||||||
char *ptr, size_t size);
|
char *ptr, size_t size);
|
||||||
|
|
||||||
/**
|
|
||||||
* Output an informational message when transfer's verbose logging is enabled.
|
|
||||||
*/
|
|
||||||
void Curl_infof(struct Curl_easy *data,
|
|
||||||
#if defined(__GNUC__) && !defined(printf) && \
|
|
||||||
defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
|
|
||||||
!defined(__MINGW32__)
|
|
||||||
const char *fmt, ...)
|
|
||||||
__attribute__((format(printf, 2, 3)));
|
|
||||||
#else
|
|
||||||
const char *fmt, ...);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Output a failure message on registered callbacks for transfer.
|
* Output a failure message on registered callbacks for transfer.
|
||||||
*/
|
*/
|
||||||
@ -82,39 +69,15 @@ void Curl_failf(struct Curl_easy *data,
|
|||||||
|
|
||||||
#define failf Curl_failf
|
#define failf Curl_failf
|
||||||
|
|
||||||
/**
|
|
||||||
* Output an informational message when both transfer's verbose logging
|
|
||||||
* and connection filters verbose logging are enabled.
|
|
||||||
*/
|
|
||||||
void Curl_trc_cf_infof(struct Curl_easy *data, struct Curl_cfilter *cf,
|
|
||||||
#if defined(__GNUC__) && !defined(printf) && \
|
|
||||||
defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
|
|
||||||
!defined(__MINGW32__)
|
|
||||||
const char *fmt, ...)
|
|
||||||
__attribute__((format(printf, 3, 4)));
|
|
||||||
#else
|
|
||||||
const char *fmt, ...);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define CURL_LOG_LVL_NONE 0
|
#define CURL_LOG_LVL_NONE 0
|
||||||
#define CURL_LOG_LVL_INFO 1
|
#define CURL_LOG_LVL_INFO 1
|
||||||
|
|
||||||
|
|
||||||
#if !defined(CURL_DISABLE_VERBOSE_STRINGS)
|
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
|
||||||
/* informational messages enabled */
|
#define CURL_HAVE_C99
|
||||||
|
#endif
|
||||||
#define Curl_trc_is_verbose(data) ((data) && (data)->set.verbose)
|
|
||||||
#define Curl_trc_cf_is_verbose(cf, data) \
|
|
||||||
((data) && (data)->set.verbose && \
|
|
||||||
(cf) && (cf)->cft->log_level >= CURL_LOG_LVL_INFO)
|
|
||||||
|
|
||||||
/* explainer: we have some mix configuration and werror settings
|
|
||||||
* that define HAVE_VARIADIC_MACROS_C99 even though C89 is enforced
|
|
||||||
* on gnuc and some other compiler. Need to treat carefully.
|
|
||||||
*/
|
|
||||||
#if defined(HAVE_VARIADIC_MACROS_C99) && \
|
|
||||||
defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
|
|
||||||
|
|
||||||
|
#ifdef CURL_HAVE_C99
|
||||||
#define infof(data, ...) \
|
#define infof(data, ...) \
|
||||||
do { if(Curl_trc_is_verbose(data)) \
|
do { if(Curl_trc_is_verbose(data)) \
|
||||||
Curl_infof(data, __VA_ARGS__); } while(0)
|
Curl_infof(data, __VA_ARGS__); } while(0)
|
||||||
@ -122,10 +85,43 @@ void Curl_trc_cf_infof(struct Curl_easy *data, struct Curl_cfilter *cf,
|
|||||||
do { if(Curl_trc_cf_is_verbose(cf, data)) \
|
do { if(Curl_trc_cf_is_verbose(cf, data)) \
|
||||||
Curl_trc_cf_infof(data, cf, __VA_ARGS__); } while(0)
|
Curl_trc_cf_infof(data, cf, __VA_ARGS__); } while(0)
|
||||||
|
|
||||||
#else /* no variadic macro args */
|
#else
|
||||||
#define infof Curl_infof
|
#define infof Curl_infof
|
||||||
#define CURL_TRC_CF Curl_trc_cf_infof
|
#define CURL_TRC_CF Curl_trc_cf_infof
|
||||||
#endif /* variadic macro args */
|
#endif
|
||||||
|
|
||||||
|
#ifndef CURL_DISABLE_VERBOSE_STRINGS
|
||||||
|
/* informational messages enabled */
|
||||||
|
|
||||||
|
#define Curl_trc_is_verbose(data) ((data) && (data)->set.verbose)
|
||||||
|
#define Curl_trc_cf_is_verbose(cf, data) \
|
||||||
|
((data) && (data)->set.verbose && \
|
||||||
|
(cf) && (cf)->cft->log_level >= CURL_LOG_LVL_INFO)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Output an informational message when transfer's verbose logging is enabled.
|
||||||
|
*/
|
||||||
|
void Curl_infof(struct Curl_easy *data,
|
||||||
|
#if defined(__GNUC__) && !defined(printf) && defined(CURL_HAVE_C99) && \
|
||||||
|
!defined(__MINGW32__)
|
||||||
|
const char *fmt, ...)
|
||||||
|
__attribute__((format(printf, 2, 3)));
|
||||||
|
#else
|
||||||
|
const char *fmt, ...);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Output an informational message when both transfer's verbose logging
|
||||||
|
* and connection filters verbose logging are enabled.
|
||||||
|
*/
|
||||||
|
void Curl_trc_cf_infof(struct Curl_easy *data, struct Curl_cfilter *cf,
|
||||||
|
#if defined(__GNUC__) && !defined(printf) && defined(CURL_HAVE_C99) && \
|
||||||
|
!defined(__MINGW32__)
|
||||||
|
const char *fmt, ...)
|
||||||
|
__attribute__((format(printf, 3, 4)));
|
||||||
|
#else
|
||||||
|
const char *fmt, ...);
|
||||||
|
#endif
|
||||||
|
|
||||||
#else /* !CURL_DISABLE_VERBOSE_STRINGS */
|
#else /* !CURL_DISABLE_VERBOSE_STRINGS */
|
||||||
/* All informational messages are not compiled in for size savings */
|
/* All informational messages are not compiled in for size savings */
|
||||||
@ -133,17 +129,17 @@ void Curl_trc_cf_infof(struct Curl_easy *data, struct Curl_cfilter *cf,
|
|||||||
#define Curl_trc_is_verbose(d) ((void)(d), FALSE)
|
#define Curl_trc_is_verbose(d) ((void)(d), FALSE)
|
||||||
#define Curl_trc_cf_is_verbose(x,y) ((void)(x), (void)(y), FALSE)
|
#define Curl_trc_cf_is_verbose(x,y) ((void)(x), (void)(y), FALSE)
|
||||||
|
|
||||||
#if defined(HAVE_VARIADIC_MACROS_C99)
|
static void Curl_infof(struct Curl_easy *data, const char *fmt, ...)
|
||||||
#define infof(...) Curl_nop_stmt
|
{
|
||||||
#define CURL_TRC_CF(...) Curl_nop_stmt
|
(void)data; (void)fmt;
|
||||||
#define Curl_trc_cf_infof(...) Curl_nop_stmt
|
}
|
||||||
#elif defined(HAVE_VARIADIC_MACROS_GCC)
|
|
||||||
#define infof(x...) Curl_nop_stmt
|
static void Curl_trc_cf_infof(struct Curl_easy *data,
|
||||||
#define CURL_TRC_CF(x...) Curl_nop_stmt
|
struct Curl_cfilter *cf,
|
||||||
#define Curl_trc_cf_infof(x...) Curl_nop_stmt
|
const char *fmt, ...)
|
||||||
#else
|
{
|
||||||
#error "missing VARIADIC macro define, fix and rebuild!"
|
(void)data; (void)cf; (void)fmt;
|
||||||
#endif
|
}
|
||||||
|
|
||||||
#endif /* CURL_DISABLE_VERBOSE_STRINGS */
|
#endif /* CURL_DISABLE_VERBOSE_STRINGS */
|
||||||
|
|
||||||
|
@ -936,10 +936,12 @@ CURLcode Curl_doh_is_resolved(struct Curl_easy *data,
|
|||||||
p->dnstype,
|
p->dnstype,
|
||||||
&de);
|
&de);
|
||||||
Curl_dyn_free(&p->serverdoh);
|
Curl_dyn_free(&p->serverdoh);
|
||||||
|
#ifndef CURL_DISABLE_VERBOSE_STRINGS
|
||||||
if(rc[slot]) {
|
if(rc[slot]) {
|
||||||
infof(data, "DoH: %s type %s for %s", doh_strerror(rc[slot]),
|
infof(data, "DoH: %s type %s for %s", doh_strerror(rc[slot]),
|
||||||
type2name(p->dnstype), dohp->host);
|
type2name(p->dnstype), dohp->host);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
} /* next slot */
|
} /* next slot */
|
||||||
|
|
||||||
result = CURLE_COULDNT_RESOLVE_HOST; /* until we know better */
|
result = CURLE_COULDNT_RESOLVE_HOST; /* until we know better */
|
||||||
|
@ -1283,9 +1283,11 @@ err:
|
|||||||
Curl_freeaddrinfo(head);
|
Curl_freeaddrinfo(head);
|
||||||
return CURLE_OUT_OF_MEMORY;
|
return CURLE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
#ifndef CURL_DISABLE_VERBOSE_STRINGS
|
||||||
infof(data, "Added %.*s:%d:%s to DNS cache%s",
|
infof(data, "Added %.*s:%d:%s to DNS cache%s",
|
||||||
(int)hlen, host_begin, port, addresses,
|
(int)hlen, host_begin, port, addresses,
|
||||||
permanent ? "" : " (non-permanent)");
|
permanent ? "" : " (non-permanent)");
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Wildcard hostname */
|
/* Wildcard hostname */
|
||||||
if((hlen == 1) && (host_begin[0] == '*')) {
|
if((hlen == 1) && (host_begin[0] == '*')) {
|
||||||
|
Loading…
Reference in New Issue
Block a user