mirror of
https://github.com/curl/curl.git
synced 2026-08-07 16:02:57 +03:00
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:
parent
5cf5bfcd13
commit
db91dbbf2c
29 changed files with 656 additions and 466 deletions
|
|
@ -50,14 +50,6 @@
|
|||
#include "memdebug.h"
|
||||
|
||||
|
||||
#define DEBUG_CF 0
|
||||
|
||||
#if DEBUG_CF
|
||||
#define CF_DEBUGF(x) x
|
||||
#else
|
||||
#define CF_DEBUGF(x) do { } while(0)
|
||||
#endif
|
||||
|
||||
#if !defined(CURL_DISABLE_HTTP)
|
||||
|
||||
typedef enum {
|
||||
|
|
@ -182,35 +174,35 @@ static void tunnel_go_state(struct Curl_cfilter *cf,
|
|||
/* entering this one */
|
||||
switch(new_state) {
|
||||
case TUNNEL_INIT:
|
||||
CF_DEBUGF(infof(data, CFMSG(cf, "new tunnel state 'init'")));
|
||||
DEBUGF(LOG_CF(data, cf, "new tunnel state 'init'"));
|
||||
tunnel_reinit(ts, cf->conn, data);
|
||||
break;
|
||||
|
||||
case TUNNEL_CONNECT:
|
||||
CF_DEBUGF(infof(data, CFMSG(cf, "new tunnel state 'connect'")));
|
||||
DEBUGF(LOG_CF(data, cf, "new tunnel state 'connect'"));
|
||||
ts->tunnel_state = TUNNEL_CONNECT;
|
||||
ts->keepon = KEEPON_CONNECT;
|
||||
Curl_dyn_reset(&ts->rcvbuf);
|
||||
break;
|
||||
|
||||
case TUNNEL_RECEIVE:
|
||||
CF_DEBUGF(infof(data, CFMSG(cf, "new tunnel state 'receive'")));
|
||||
DEBUGF(LOG_CF(data, cf, "new tunnel state 'receive'"));
|
||||
ts->tunnel_state = TUNNEL_RECEIVE;
|
||||
break;
|
||||
|
||||
case TUNNEL_RESPONSE:
|
||||
CF_DEBUGF(infof(data, CFMSG(cf, "new tunnel state 'response'")));
|
||||
DEBUGF(LOG_CF(data, cf, "new tunnel state 'response'"));
|
||||
ts->tunnel_state = TUNNEL_RESPONSE;
|
||||
break;
|
||||
|
||||
case TUNNEL_ESTABLISHED:
|
||||
CF_DEBUGF(infof(data, CFMSG(cf, "new tunnel state 'established'")));
|
||||
DEBUGF(LOG_CF(data, cf, "new tunnel state 'established'"));
|
||||
infof(data, "CONNECT phase completed");
|
||||
data->state.authproxy.done = TRUE;
|
||||
data->state.authproxy.multipass = FALSE;
|
||||
/* FALLTHROUGH */
|
||||
case TUNNEL_FAILED:
|
||||
CF_DEBUGF(infof(data, CFMSG(cf, "new tunnel state 'failed'")));
|
||||
DEBUGF(LOG_CF(data, cf, "new tunnel state 'failed'"));
|
||||
ts->tunnel_state = new_state;
|
||||
Curl_dyn_reset(&ts->rcvbuf);
|
||||
Curl_dyn_reset(&ts->req);
|
||||
|
|
@ -403,13 +395,15 @@ out:
|
|||
return result;
|
||||
}
|
||||
|
||||
static CURLcode on_resp_header(struct Curl_easy *data,
|
||||
static CURLcode on_resp_header(struct Curl_cfilter *cf,
|
||||
struct Curl_easy *data,
|
||||
struct tunnel_state *ts,
|
||||
const char *header)
|
||||
{
|
||||
CURLcode result = CURLE_OK;
|
||||
struct SingleRequest *k = &data->req;
|
||||
int subversion = 0;
|
||||
(void)cf;
|
||||
|
||||
if((checkprefix("WWW-Authenticate:", header) &&
|
||||
(401 == k->httpcode)) ||
|
||||
|
|
@ -421,8 +415,7 @@ static CURLcode on_resp_header(struct Curl_easy *data,
|
|||
if(!auth)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
|
||||
CF_DEBUGF(infof(data, "CONNECT: fwd auth header '%s'",
|
||||
header));
|
||||
DEBUGF(LOG_CF(data, cf, "CONNECT: fwd auth header '%s'", header));
|
||||
result = Curl_http_input_auth(data, proxy, auth);
|
||||
|
||||
free(auth);
|
||||
|
|
@ -476,14 +469,14 @@ static CURLcode on_resp_header(struct Curl_easy *data,
|
|||
return result;
|
||||
}
|
||||
|
||||
static CURLcode recv_CONNECT_resp(struct Curl_easy *data,
|
||||
struct connectdata *conn,
|
||||
static CURLcode recv_CONNECT_resp(struct Curl_cfilter *cf,
|
||||
struct Curl_easy *data,
|
||||
struct tunnel_state *ts,
|
||||
bool *done)
|
||||
{
|
||||
CURLcode result = CURLE_OK;
|
||||
struct SingleRequest *k = &data->req;
|
||||
curl_socket_t tunnelsocket = conn->sock[ts->sockindex];
|
||||
curl_socket_t tunnelsocket = cf->conn->sock[ts->sockindex];
|
||||
char *linep;
|
||||
size_t perline;
|
||||
int error;
|
||||
|
|
@ -639,7 +632,7 @@ static CURLcode recv_CONNECT_resp(struct Curl_easy *data,
|
|||
/* without content-length or chunked encoding, we
|
||||
can't keep the connection alive since the close is
|
||||
the end signal so we bail out at once instead */
|
||||
CF_DEBUGF(infof(data, "CONNECT: no content-length or chunked"));
|
||||
DEBUGF(LOG_CF(data, cf, "CONNECT: no content-length or chunked"));
|
||||
ts->keepon = KEEPON_DONE;
|
||||
}
|
||||
}
|
||||
|
|
@ -652,7 +645,7 @@ static CURLcode recv_CONNECT_resp(struct Curl_easy *data,
|
|||
continue;
|
||||
}
|
||||
|
||||
result = on_resp_header(data, ts, linep);
|
||||
result = on_resp_header(cf, data, ts, linep);
|
||||
if(result)
|
||||
return result;
|
||||
|
||||
|
|
@ -919,8 +912,8 @@ error:
|
|||
return result;
|
||||
}
|
||||
|
||||
static CURLcode recv_CONNECT_resp(struct Curl_easy *data,
|
||||
struct connectdata *conn,
|
||||
static CURLcode recv_CONNECT_resp(struct Curl_cfilter *cf,
|
||||
struct Curl_easy *data,
|
||||
struct tunnel_state *ts,
|
||||
bool *done)
|
||||
{
|
||||
|
|
@ -930,7 +923,7 @@ static CURLcode recv_CONNECT_resp(struct Curl_easy *data,
|
|||
|
||||
(void)ts;
|
||||
*done = FALSE;
|
||||
result = Curl_hyper_stream(data, conn, &didwhat, done,
|
||||
result = Curl_hyper_stream(data, cf->conn, &didwhat, done,
|
||||
CURL_CSELECT_IN | CURL_CSELECT_OUT);
|
||||
if(result || !*done)
|
||||
return result;
|
||||
|
|
@ -977,7 +970,7 @@ static CURLcode CONNECT(struct Curl_cfilter *cf,
|
|||
switch(ts->tunnel_state) {
|
||||
case TUNNEL_INIT:
|
||||
/* Prepare the CONNECT request and make a first attempt to send. */
|
||||
CF_DEBUGF(infof(data, CFMSG(cf, "CONNECT start")));
|
||||
DEBUGF(LOG_CF(data, cf, "CONNECT start"));
|
||||
result = start_CONNECT(data, cf->conn, ts);
|
||||
if(result)
|
||||
goto out;
|
||||
|
|
@ -986,7 +979,7 @@ static CURLcode CONNECT(struct Curl_cfilter *cf,
|
|||
|
||||
case TUNNEL_CONNECT:
|
||||
/* see that the request is completely sent */
|
||||
CF_DEBUGF(infof(data, CFMSG(cf, "CONNECT send")));
|
||||
DEBUGF(LOG_CF(data, cf, "CONNECT send"));
|
||||
result = send_CONNECT(data, cf->conn, ts, &done);
|
||||
if(result || !done)
|
||||
goto out;
|
||||
|
|
@ -995,8 +988,8 @@ static CURLcode CONNECT(struct Curl_cfilter *cf,
|
|||
|
||||
case TUNNEL_RECEIVE:
|
||||
/* read what is there */
|
||||
CF_DEBUGF(infof(data, CFMSG(cf, "CONNECT receive")));
|
||||
result = recv_CONNECT_resp(data, cf->conn, ts, &done);
|
||||
DEBUGF(LOG_CF(data, cf, "CONNECT receive"));
|
||||
result = recv_CONNECT_resp(cf, data, ts, &done);
|
||||
if(Curl_pgrsUpdate(data)) {
|
||||
result = CURLE_ABORTED_BY_CALLBACK;
|
||||
goto out;
|
||||
|
|
@ -1009,7 +1002,7 @@ static CURLcode CONNECT(struct Curl_cfilter *cf,
|
|||
/* FALLTHROUGH */
|
||||
|
||||
case TUNNEL_RESPONSE:
|
||||
CF_DEBUGF(infof(data, CFMSG(cf, "CONNECT response")));
|
||||
DEBUGF(LOG_CF(data, cf, "CONNECT response"));
|
||||
if(data->req.newurl) {
|
||||
/* not the "final" response, we need to do a follow up request.
|
||||
* If the other side indicated a connection close, or if someone
|
||||
|
|
@ -1021,7 +1014,7 @@ static CURLcode CONNECT(struct Curl_cfilter *cf,
|
|||
* reset our tunnel state. To avoid recursion, we return
|
||||
* and expect to be called again.
|
||||
*/
|
||||
CF_DEBUGF(infof(data, CFMSG(cf, "CONNECT need to close+open")));
|
||||
DEBUGF(LOG_CF(data, cf, "CONNECT need to close+open"));
|
||||
infof(data, "Connect me again please");
|
||||
Curl_conn_cf_close(cf, data);
|
||||
connkeep(conn, "HTTP proxy CONNECT");
|
||||
|
|
@ -1076,12 +1069,12 @@ static CURLcode http_proxy_cf_connect(struct Curl_cfilter *cf,
|
|||
return CURLE_OK;
|
||||
}
|
||||
|
||||
CF_DEBUGF(infof(data, CFMSG(cf, "connect")));
|
||||
DEBUGF(LOG_CF(data, cf, "connect"));
|
||||
result = cf->next->cft->connect(cf->next, data, blocking, done);
|
||||
if(result || !*done)
|
||||
return result;
|
||||
|
||||
CF_DEBUGF(infof(data, CFMSG(cf, "subchain is connected")));
|
||||
DEBUGF(LOG_CF(data, cf, "subchain is connected"));
|
||||
/* TODO: can we do blocking? */
|
||||
/* We want "seamless" operations through HTTP proxy tunnel */
|
||||
|
||||
|
|
@ -1159,7 +1152,7 @@ static int http_proxy_cf_get_select_socks(struct Curl_cfilter *cf,
|
|||
static void http_proxy_cf_destroy(struct Curl_cfilter *cf,
|
||||
struct Curl_easy *data)
|
||||
{
|
||||
CF_DEBUGF(infof(data, CFMSG(cf, "destroy")));
|
||||
DEBUGF(LOG_CF(data, cf, "destroy"));
|
||||
tunnel_free(cf, data);
|
||||
}
|
||||
|
||||
|
|
@ -1167,7 +1160,7 @@ static void http_proxy_cf_close(struct Curl_cfilter *cf,
|
|||
struct Curl_easy *data)
|
||||
{
|
||||
DEBUGASSERT(cf->next);
|
||||
CF_DEBUGF(infof(data, CFMSG(cf, "close")));
|
||||
DEBUGF(LOG_CF(data, cf, "close"));
|
||||
cf->connected = FALSE;
|
||||
cf->next->cft->close(cf->next, data);
|
||||
if(cf->ctx) {
|
||||
|
|
@ -1176,9 +1169,10 @@ static void http_proxy_cf_close(struct Curl_cfilter *cf,
|
|||
}
|
||||
|
||||
|
||||
static const struct Curl_cftype cft_http_proxy = {
|
||||
struct Curl_cftype Curl_cft_http_proxy = {
|
||||
"HTTP-PROXY",
|
||||
CF_TYPE_IP_CONNECT,
|
||||
0,
|
||||
http_proxy_cf_destroy,
|
||||
http_proxy_cf_connect,
|
||||
http_proxy_cf_close,
|
||||
|
|
@ -1200,7 +1194,7 @@ CURLcode Curl_conn_http_proxy_add(struct Curl_easy *data,
|
|||
struct Curl_cfilter *cf;
|
||||
CURLcode result;
|
||||
|
||||
result = Curl_cf_create(&cf, &cft_http_proxy, NULL);
|
||||
result = Curl_cf_create(&cf, &Curl_cft_http_proxy, NULL);
|
||||
if(!result)
|
||||
Curl_conn_cf_add(data, conn, sockindex, cf);
|
||||
return result;
|
||||
|
|
@ -1213,7 +1207,7 @@ CURLcode Curl_cf_http_proxy_insert_after(struct Curl_cfilter *cf_at,
|
|||
CURLcode result;
|
||||
|
||||
(void)data;
|
||||
result = Curl_cf_create(&cf, &cft_http_proxy, NULL);
|
||||
result = Curl_cf_create(&cf, &Curl_cft_http_proxy, NULL);
|
||||
if(!result)
|
||||
Curl_conn_cf_insert_after(cf_at, cf);
|
||||
return result;
|
||||
|
|
@ -1335,14 +1329,14 @@ static void cf_haproxy_destroy(struct Curl_cfilter *cf,
|
|||
struct Curl_easy *data)
|
||||
{
|
||||
(void)data;
|
||||
CF_DEBUGF(infof(data, CFMSG(cf, "destroy")));
|
||||
DEBUGF(LOG_CF(data, cf, "destroy"));
|
||||
cf_haproxy_ctx_free(cf->ctx);
|
||||
}
|
||||
|
||||
static void cf_haproxy_close(struct Curl_cfilter *cf,
|
||||
struct Curl_easy *data)
|
||||
{
|
||||
CF_DEBUGF(infof(data, CFMSG(cf, "close")));
|
||||
DEBUGF(LOG_CF(data, cf, "close"));
|
||||
cf->connected = FALSE;
|
||||
cf_haproxy_ctx_reset(cf->ctx);
|
||||
if(cf->next)
|
||||
|
|
@ -1368,9 +1362,10 @@ static int cf_haproxy_get_select_socks(struct Curl_cfilter *cf,
|
|||
}
|
||||
|
||||
|
||||
static const struct Curl_cftype cft_haproxy = {
|
||||
struct Curl_cftype Curl_cft_haproxy = {
|
||||
"HAPROXY",
|
||||
0,
|
||||
0,
|
||||
cf_haproxy_destroy,
|
||||
cf_haproxy_connect,
|
||||
cf_haproxy_close,
|
||||
|
|
@ -1401,7 +1396,7 @@ static CURLcode cf_haproxy_create(struct Curl_cfilter **pcf,
|
|||
ctx->state = HAPROXY_INIT;
|
||||
Curl_dyn_init(&ctx->data_out, DYN_HAXPROXY);
|
||||
|
||||
result = Curl_cf_create(&cf, &cft_haproxy, ctx);
|
||||
result = Curl_cf_create(&cf, &Curl_cft_haproxy, ctx);
|
||||
if(result)
|
||||
goto out;
|
||||
ctx = NULL;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue