| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
#include "curl_setup.h" |
| 26 |
|
| 27 |
#include <curl/curl.h> |
| 28 |
|
| 29 |
#include "curl_trc.h" |
| 30 |
#include "urldata.h" |
| 31 |
#include "easyif.h" |
| 32 |
#include "cfilters.h" |
| 33 |
#include "multiif.h" |
| 34 |
#include "strcase.h" |
| 35 |
|
| 36 |
#include "cf-socket.h" |
| 37 |
#include "connect.h" |
| 38 |
#include "doh.h" |
| 39 |
#include "http2.h" |
| 40 |
#include "http_proxy.h" |
| 41 |
#include "cf-h1-proxy.h" |
| 42 |
#include "cf-h2-proxy.h" |
| 43 |
#include "cf-haproxy.h" |
| 44 |
#include "cf-https-connect.h" |
| 45 |
#include "socks.h" |
| 46 |
#include "curlx/strparse.h" |
| 47 |
#include "vtls/vtls.h" |
| 48 |
#include "vquic/vquic.h" |
| 49 |
|
| 50 |
|
| 51 |
#include "curl_printf.h" |
| 52 |
#include "curl_memory.h" |
| 53 |
#include "memdebug.h" |
| 54 |
|
| 55 |
static void trc_write(struct Curl_easy *data, curl_infotype type, |
| 56 |
const char *ptr, size_t size) |
| 57 |
{ |
| 58 |
if(data->set.verbose) { |
| 59 |
if(data->set.fdebug) { |
| 60 |
bool inCallback = Curl_is_in_callback(data); |
| 61 |
Curl_set_in_callback(data, TRUE); |
| 62 |
(void)(*data->set.fdebug)(data, type, CURL_UNCONST(ptr), size, |
| 63 |
data->set.debugdata); |
| 64 |
Curl_set_in_callback(data, inCallback); |
| 65 |
} |
| 66 |
else { |
| 67 |
static const char s_infotype[CURLINFO_END][3] = { |
| 68 |
"* ", "< ", "> ", "{ ", "} ", "{ ", "} " }; |
| 69 |
switch(type) { |
| 70 |
case CURLINFO_TEXT: |
| 71 |
case CURLINFO_HEADER_OUT: |
| 72 |
case CURLINFO_HEADER_IN: |
| 73 |
fwrite(s_infotype[type], 2, 1, data->set.err); |
| 74 |
fwrite(ptr, size, 1, data->set.err); |
| 75 |
break; |
| 76 |
default: |
| 77 |
break; |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
#define TRC_LINE_MAX 2048 |
| 85 |
|
| 86 |
#define CURL_TRC_FMT_IDSC "[x-%" CURL_FORMAT_CURL_OFF_T "] " |
| 87 |
#define CURL_TRC_FMT_IDSD "[%" CURL_FORMAT_CURL_OFF_T "-x] " |
| 88 |
#define CURL_TRC_FMT_IDSDC "[%" CURL_FORMAT_CURL_OFF_T "-%" \ |
| 89 |
CURL_FORMAT_CURL_OFF_T "] " |
| 90 |
|
| 91 |
static struct curl_trc_feat Curl_trc_feat_ids = { |
| 92 |
"LIB-IDS", |
| 93 |
CURL_LOG_LVL_NONE, |
| 94 |
}; |
| 95 |
#define CURL_TRC_IDS(data) \ |
| 96 |
(Curl_trc_is_verbose(data) && \ |
| 97 |
Curl_trc_feat_ids.log_level >= CURL_LOG_LVL_INFO) |
| 98 |
|
| 99 |
static size_t trc_print_ids(struct Curl_easy *data, char *buf, size_t maxlen) |
| 100 |
{ |
| 101 |
curl_off_t cid = data->conn ? |
| 102 |
data->conn->connection_id : data->state.recent_conn_id; |
| 103 |
if(data->id >= 0) { |
| 104 |
if(cid >= 0) |
| 105 |
return msnprintf(buf, maxlen, CURL_TRC_FMT_IDSDC, data->id, cid); |
| 106 |
else |
| 107 |
return msnprintf(buf, maxlen, CURL_TRC_FMT_IDSD, data->id); |
| 108 |
} |
| 109 |
else if(cid >= 0) |
| 110 |
return msnprintf(buf, maxlen, CURL_TRC_FMT_IDSC, cid); |
| 111 |
else { |
| 112 |
return msnprintf(buf, maxlen, "[x-x] "); |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
static size_t trc_end_buf(char *buf, size_t len, size_t maxlen, bool addnl) |
| 117 |
{ |
| 118 |
|
| 119 |
|
| 120 |
if(len >= (maxlen - (addnl ? 2 : 1))) { |
| 121 |
len = maxlen - 5; |
| 122 |
buf[len++] = '.'; |
| 123 |
buf[len++] = '.'; |
| 124 |
buf[len++] = '.'; |
| 125 |
buf[len++] = '\n'; |
| 126 |
} |
| 127 |
else if(addnl) |
| 128 |
buf[len++] = '\n'; |
| 129 |
buf[len] = '\0'; |
| 130 |
return len; |
| 131 |
} |
| 132 |
|
| 133 |
void Curl_debug(struct Curl_easy *data, curl_infotype type, |
| 134 |
const char *ptr, size_t size) |
| 135 |
{ |
| 136 |
if(data->set.verbose) { |
| 137 |
static const char s_infotype[CURLINFO_END][3] = { |
| 138 |
"* ", "< ", "> ", "{ ", "} ", "{ ", "} " }; |
| 139 |
char buf[TRC_LINE_MAX]; |
| 140 |
size_t len; |
| 141 |
if(data->set.fdebug) { |
| 142 |
bool inCallback = Curl_is_in_callback(data); |
| 143 |
|
| 144 |
if(CURL_TRC_IDS(data) && (size < TRC_LINE_MAX)) { |
| 145 |
len = trc_print_ids(data, buf, TRC_LINE_MAX); |
| 146 |
len += msnprintf(buf + len, TRC_LINE_MAX - len, "%.*s", |
| 147 |
(int)size, ptr); |
| 148 |
len = trc_end_buf(buf, len, TRC_LINE_MAX, FALSE); |
| 149 |
Curl_set_in_callback(data, TRUE); |
| 150 |
(void)(*data->set.fdebug)(data, type, buf, len, data->set.debugdata); |
| 151 |
Curl_set_in_callback(data, inCallback); |
| 152 |
} |
| 153 |
else { |
| 154 |
Curl_set_in_callback(data, TRUE); |
| 155 |
(void)(*data->set.fdebug)(data, type, CURL_UNCONST(ptr), |
| 156 |
size, data->set.debugdata); |
| 157 |
Curl_set_in_callback(data, inCallback); |
| 158 |
} |
| 159 |
} |
| 160 |
else { |
| 161 |
switch(type) { |
| 162 |
case CURLINFO_TEXT: |
| 163 |
case CURLINFO_HEADER_OUT: |
| 164 |
case CURLINFO_HEADER_IN: |
| 165 |
if(CURL_TRC_IDS(data)) { |
| 166 |
len = trc_print_ids(data, buf, TRC_LINE_MAX); |
| 167 |
fwrite(buf, len, 1, data->set.err); |
| 168 |
} |
| 169 |
fwrite(s_infotype[type], 2, 1, data->set.err); |
| 170 |
fwrite(ptr, size, 1, data->set.err); |
| 171 |
break; |
| 172 |
default: |
| 173 |
break; |
| 174 |
} |
| 175 |
} |
| 176 |
} |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
void Curl_failf(struct Curl_easy *data, const char *fmt, ...) |
| 183 |
{ |
| 184 |
DEBUGASSERT(!strchr(fmt, '\n')); |
| 185 |
if(data->set.verbose || data->set.errorbuffer) { |
| 186 |
va_list ap; |
| 187 |
size_t len; |
| 188 |
char error[CURL_ERROR_SIZE + 2]; |
| 189 |
va_start(ap, fmt); |
| 190 |
len = mvsnprintf(error, CURL_ERROR_SIZE, fmt, ap); |
| 191 |
|
| 192 |
if(data->set.errorbuffer && !data->state.errorbuf) { |
| 193 |
strcpy(data->set.errorbuffer, error); |
| 194 |
data->state.errorbuf = TRUE; |
| 195 |
} |
| 196 |
error[len++] = '\n'; |
| 197 |
error[len] = '\0'; |
| 198 |
trc_write(data, CURLINFO_TEXT, error, len); |
| 199 |
va_end(ap); |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
#if !defined(CURL_DISABLE_VERBOSE_STRINGS) |
| 204 |
|
| 205 |
|
| 206 |
static void trc_infof(struct Curl_easy *data, |
| 207 |
struct curl_trc_feat *feat, |
| 208 |
const char *opt_id, int opt_id_idx, |
| 209 |
const char * const fmt, va_list ap) CURL_PRINTF(5, 0); |
| 210 |
|
| 211 |
static void trc_infof(struct Curl_easy *data, |
| 212 |
struct curl_trc_feat *feat, |
| 213 |
const char *opt_id, int opt_id_idx, |
| 214 |
const char * const fmt, va_list ap) |
| 215 |
{ |
| 216 |
size_t len = 0; |
| 217 |
char buf[TRC_LINE_MAX]; |
| 218 |
|
| 219 |
if(CURL_TRC_IDS(data)) |
| 220 |
len += trc_print_ids(data, buf + len, TRC_LINE_MAX - len); |
| 221 |
if(feat) |
| 222 |
len += msnprintf(buf + len, TRC_LINE_MAX - len, "[%s] ", feat->name); |
| 223 |
if(opt_id) { |
| 224 |
if(opt_id_idx > 0) |
| 225 |
len += msnprintf(buf + len, TRC_LINE_MAX - len, "[%s-%d] ", |
| 226 |
opt_id, opt_id_idx); |
| 227 |
else |
| 228 |
len += msnprintf(buf + len, TRC_LINE_MAX - len, "[%s] ", opt_id); |
| 229 |
} |
| 230 |
len += mvsnprintf(buf + len, TRC_LINE_MAX - len, fmt, ap); |
| 231 |
len = trc_end_buf(buf, len, TRC_LINE_MAX, TRUE); |
| 232 |
trc_write(data, CURLINFO_TEXT, buf, len); |
| 233 |
} |
| 234 |
|
| 235 |
void Curl_infof(struct Curl_easy *data, const char *fmt, ...) |
| 236 |
{ |
| 237 |
DEBUGASSERT(!strchr(fmt, '\n')); |
| 238 |
if(Curl_trc_is_verbose(data)) { |
| 239 |
va_list ap; |
| 240 |
va_start(ap, fmt); |
| 241 |
trc_infof(data, data->state.feat, NULL, 0, fmt, ap); |
| 242 |
va_end(ap); |
| 243 |
} |
| 244 |
} |
| 245 |
|
| 246 |
void Curl_trc_cf_infof(struct Curl_easy *data, const struct Curl_cfilter *cf, |
| 247 |
const char *fmt, ...) |
| 248 |
{ |
| 249 |
DEBUGASSERT(cf); |
| 250 |
if(Curl_trc_cf_is_verbose(cf, data)) { |
| 251 |
va_list ap; |
| 252 |
va_start(ap, fmt); |
| 253 |
trc_infof(data, data->state.feat, cf->cft->name, cf->sockindex, fmt, ap); |
| 254 |
va_end(ap); |
| 255 |
} |
| 256 |
} |
| 257 |
|
| 258 |
struct curl_trc_feat Curl_trc_feat_multi = { |
| 259 |
"MULTI", |
| 260 |
CURL_LOG_LVL_NONE, |
| 261 |
}; |
| 262 |
struct curl_trc_feat Curl_trc_feat_read = { |
| 263 |
"READ", |
| 264 |
CURL_LOG_LVL_NONE, |
| 265 |
}; |
| 266 |
struct curl_trc_feat Curl_trc_feat_write = { |
| 267 |
"WRITE", |
| 268 |
CURL_LOG_LVL_NONE, |
| 269 |
}; |
| 270 |
struct curl_trc_feat Curl_trc_feat_dns = { |
| 271 |
"DNS", |
| 272 |
CURL_LOG_LVL_NONE, |
| 273 |
}; |
| 274 |
|
| 275 |
|
| 276 |
static const char * const Curl_trc_mstate_names[]={ |
| 277 |
"INIT", |
| 278 |
"PENDING", |
| 279 |
"SETUP", |
| 280 |
"CONNECT", |
| 281 |
"RESOLVING", |
| 282 |
"CONNECTING", |
| 283 |
"TUNNELING", |
| 284 |
"PROTOCONNECT", |
| 285 |
"PROTOCONNECTING", |
| 286 |
"DO", |
| 287 |
"DOING", |
| 288 |
"DOING_MORE", |
| 289 |
"DID", |
| 290 |
"PERFORMING", |
| 291 |
"RATELIMITING", |
| 292 |
"DONE", |
| 293 |
"COMPLETED", |
| 294 |
"MSGSENT", |
| 295 |
}; |
| 296 |
|
| 297 |
const char *Curl_trc_mstate_name(int state) |
| 298 |
{ |
| 299 |
if((state >= 0) && ((size_t)state < CURL_ARRAYSIZE(Curl_trc_mstate_names))) |
| 300 |
return Curl_trc_mstate_names[(size_t)state]; |
| 301 |
return "?"; |
| 302 |
} |
| 303 |
|
| 304 |
void Curl_trc_multi(struct Curl_easy *data, const char *fmt, ...) |
| 305 |
{ |
| 306 |
DEBUGASSERT(!strchr(fmt, '\n')); |
| 307 |
if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_multi)) { |
| 308 |
const char *sname = (data->id >= 0) ? |
| 309 |
Curl_trc_mstate_name(data->mstate) : NULL; |
| 310 |
va_list ap; |
| 311 |
va_start(ap, fmt); |
| 312 |
trc_infof(data, &Curl_trc_feat_multi, sname, 0, fmt, ap); |
| 313 |
va_end(ap); |
| 314 |
} |
| 315 |
} |
| 316 |
|
| 317 |
void Curl_trc_read(struct Curl_easy *data, const char *fmt, ...) |
| 318 |
{ |
| 319 |
DEBUGASSERT(!strchr(fmt, '\n')); |
| 320 |
if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_read)) { |
| 321 |
va_list ap; |
| 322 |
va_start(ap, fmt); |
| 323 |
trc_infof(data, &Curl_trc_feat_read, NULL, 0, fmt, ap); |
| 324 |
va_end(ap); |
| 325 |
} |
| 326 |
} |
| 327 |
|
| 328 |
void Curl_trc_write(struct Curl_easy *data, const char *fmt, ...) |
| 329 |
{ |
| 330 |
DEBUGASSERT(!strchr(fmt, '\n')); |
| 331 |
if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_write)) { |
| 332 |
va_list ap; |
| 333 |
va_start(ap, fmt); |
| 334 |
trc_infof(data, &Curl_trc_feat_write, NULL, 0, fmt, ap); |
| 335 |
va_end(ap); |
| 336 |
} |
| 337 |
} |
| 338 |
|
| 339 |
void Curl_trc_dns(struct Curl_easy *data, const char *fmt, ...) |
| 340 |
{ |
| 341 |
DEBUGASSERT(!strchr(fmt, '\n')); |
| 342 |
if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_dns)) { |
| 343 |
va_list ap; |
| 344 |
va_start(ap, fmt); |
| 345 |
trc_infof(data, &Curl_trc_feat_dns, NULL, 0, fmt, ap); |
| 346 |
va_end(ap); |
| 347 |
} |
| 348 |
} |
| 349 |
|
| 350 |
#ifndef CURL_DISABLE_FTP |
| 351 |
struct curl_trc_feat Curl_trc_feat_ftp = { |
| 352 |
"FTP", |
| 353 |
CURL_LOG_LVL_NONE, |
| 354 |
}; |
| 355 |
|
| 356 |
void Curl_trc_ftp(struct Curl_easy *data, const char *fmt, ...) |
| 357 |
{ |
| 358 |
DEBUGASSERT(!strchr(fmt, '\n')); |
| 359 |
if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ftp)) { |
| 360 |
va_list ap; |
| 361 |
va_start(ap, fmt); |
| 362 |
trc_infof(data, &Curl_trc_feat_ftp, NULL, 0, fmt, ap); |
| 363 |
va_end(ap); |
| 364 |
} |
| 365 |
} |
| 366 |
#endif |
| 367 |
|
| 368 |
#ifndef CURL_DISABLE_SMTP |
| 369 |
struct curl_trc_feat Curl_trc_feat_smtp = { |
| 370 |
"SMTP", |
| 371 |
CURL_LOG_LVL_NONE, |
| 372 |
}; |
| 373 |
|
| 374 |
void Curl_trc_smtp(struct Curl_easy *data, const char *fmt, ...) |
| 375 |
{ |
| 376 |
DEBUGASSERT(!strchr(fmt, '\n')); |
| 377 |
if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_smtp)) { |
| 378 |
va_list ap; |
| 379 |
va_start(ap, fmt); |
| 380 |
trc_infof(data, &Curl_trc_feat_smtp, NULL, 0, fmt, ap); |
| 381 |
va_end(ap); |
| 382 |
} |
| 383 |
} |
| 384 |
#endif |
| 385 |
|
| 386 |
#ifdef USE_SSL |
| 387 |
struct curl_trc_feat Curl_trc_feat_ssls = { |
| 388 |
"SSLS", |
| 389 |
CURL_LOG_LVL_NONE, |
| 390 |
}; |
| 391 |
|
| 392 |
void Curl_trc_ssls(struct Curl_easy *data, const char *fmt, ...) |
| 393 |
{ |
| 394 |
DEBUGASSERT(!strchr(fmt, '\n')); |
| 395 |
if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ssls)) { |
| 396 |
va_list ap; |
| 397 |
va_start(ap, fmt); |
| 398 |
trc_infof(data, &Curl_trc_feat_ssls, NULL, 0, fmt, ap); |
| 399 |
va_end(ap); |
| 400 |
} |
| 401 |
} |
| 402 |
#endif |
| 403 |
|
| 404 |
#if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) |
| 405 |
struct curl_trc_feat Curl_trc_feat_ws = { |
| 406 |
"WS", |
| 407 |
CURL_LOG_LVL_NONE, |
| 408 |
}; |
| 409 |
|
| 410 |
void Curl_trc_ws(struct Curl_easy *data, const char *fmt, ...) |
| 411 |
{ |
| 412 |
DEBUGASSERT(!strchr(fmt, '\n')); |
| 413 |
if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ws)) { |
| 414 |
va_list ap; |
| 415 |
va_start(ap, fmt); |
| 416 |
trc_infof(data, &Curl_trc_feat_ws, NULL, 0, fmt, ap); |
| 417 |
va_end(ap); |
| 418 |
} |
| 419 |
} |
| 420 |
#endif |
| 421 |
|
| 422 |
#define TRC_CT_NONE (0) |
| 423 |
#define TRC_CT_PROTOCOL (1<<(0)) |
| 424 |
#define TRC_CT_NETWORK (1<<(1)) |
| 425 |
#define TRC_CT_PROXY (1<<(2)) |
| 426 |
#define TRC_CT_INTERNALS (1<<(3)) |
| 427 |
|
| 428 |
struct trc_feat_def { |
| 429 |
struct curl_trc_feat *feat; |
| 430 |
unsigned int category; |
| 431 |
}; |
| 432 |
|
| 433 |
static struct trc_feat_def trc_feats[] = { |
| 434 |
{ &Curl_trc_feat_ids, TRC_CT_INTERNALS }, |
| 435 |
{ &Curl_trc_feat_multi, TRC_CT_NETWORK }, |
| 436 |
{ &Curl_trc_feat_read, TRC_CT_NONE }, |
| 437 |
{ &Curl_trc_feat_write, TRC_CT_NONE }, |
| 438 |
{ &Curl_trc_feat_dns, TRC_CT_NETWORK }, |
| 439 |
#ifndef CURL_DISABLE_FTP |
| 440 |
{ &Curl_trc_feat_ftp, TRC_CT_PROTOCOL }, |
| 441 |
#endif |
| 442 |
#ifndef CURL_DISABLE_DOH |
| 443 |
#endif |
| 444 |
#ifndef CURL_DISABLE_SMTP |
| 445 |
{ &Curl_trc_feat_smtp, TRC_CT_PROTOCOL }, |
| 446 |
#endif |
| 447 |
#ifdef USE_SSL |
| 448 |
{ &Curl_trc_feat_ssls, TRC_CT_NETWORK }, |
| 449 |
#endif |
| 450 |
#if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) |
| 451 |
{ &Curl_trc_feat_ws, TRC_CT_PROTOCOL }, |
| 452 |
#endif |
| 453 |
}; |
| 454 |
|
| 455 |
struct trc_cft_def { |
| 456 |
struct Curl_cftype *cft; |
| 457 |
unsigned int category; |
| 458 |
}; |
| 459 |
|
| 460 |
static struct trc_cft_def trc_cfts[] = { |
| 461 |
{ &Curl_cft_tcp, TRC_CT_NETWORK }, |
| 462 |
{ &Curl_cft_udp, TRC_CT_NETWORK }, |
| 463 |
{ &Curl_cft_unix, TRC_CT_NETWORK }, |
| 464 |
{ &Curl_cft_tcp_accept, TRC_CT_NETWORK }, |
| 465 |
{ &Curl_cft_happy_eyeballs, TRC_CT_NETWORK }, |
| 466 |
{ &Curl_cft_setup, TRC_CT_PROTOCOL }, |
| 467 |
#ifdef USE_NGHTTP2 |
| 468 |
{ &Curl_cft_nghttp2, TRC_CT_PROTOCOL }, |
| 469 |
#endif |
| 470 |
#ifdef USE_SSL |
| 471 |
{ &Curl_cft_ssl, TRC_CT_NETWORK }, |
| 472 |
#ifndef CURL_DISABLE_PROXY |
| 473 |
{ &Curl_cft_ssl_proxy, TRC_CT_PROXY }, |
| 474 |
#endif |
| 475 |
#endif |
| 476 |
#if !defined(CURL_DISABLE_PROXY) |
| 477 |
#if !defined(CURL_DISABLE_HTTP) |
| 478 |
{ &Curl_cft_h1_proxy, TRC_CT_PROXY }, |
| 479 |
#ifdef USE_NGHTTP2 |
| 480 |
{ &Curl_cft_h2_proxy, TRC_CT_PROXY }, |
| 481 |
#endif |
| 482 |
{ &Curl_cft_http_proxy, TRC_CT_PROXY }, |
| 483 |
#endif |
| 484 |
{ &Curl_cft_haproxy, TRC_CT_PROXY }, |
| 485 |
{ &Curl_cft_socks_proxy, TRC_CT_PROXY }, |
| 486 |
#endif |
| 487 |
#ifdef USE_HTTP3 |
| 488 |
{ &Curl_cft_http3, TRC_CT_PROTOCOL }, |
| 489 |
#endif |
| 490 |
#if !defined(CURL_DISABLE_HTTP) |
| 491 |
{ &Curl_cft_http_connect, TRC_CT_PROTOCOL }, |
| 492 |
#endif |
| 493 |
}; |
| 494 |
|
| 495 |
static void trc_apply_level_by_name(struct Curl_str *token, int lvl) |
| 496 |
{ |
| 497 |
size_t i; |
| 498 |
|
| 499 |
for(i = 0; i < CURL_ARRAYSIZE(trc_cfts); ++i) { |
| 500 |
if(curlx_str_casecompare(token, trc_cfts[i].cft->name)) { |
| 501 |
trc_cfts[i].cft->log_level = lvl; |
| 502 |
break; |
| 503 |
} |
| 504 |
} |
| 505 |
for(i = 0; i < CURL_ARRAYSIZE(trc_feats); ++i) { |
| 506 |
if(curlx_str_casecompare(token, trc_feats[i].feat->name)) { |
| 507 |
trc_feats[i].feat->log_level = lvl; |
| 508 |
break; |
| 509 |
} |
| 510 |
} |
| 511 |
} |
| 512 |
|
| 513 |
static void trc_apply_level_by_category(int category, int lvl) |
| 514 |
{ |
| 515 |
size_t i; |
| 516 |
|
| 517 |
for(i = 0; i < CURL_ARRAYSIZE(trc_cfts); ++i) { |
| 518 |
if(!category || (trc_cfts[i].category & category)) |
| 519 |
trc_cfts[i].cft->log_level = lvl; |
| 520 |
} |
| 521 |
for(i = 0; i < CURL_ARRAYSIZE(trc_feats); ++i) { |
| 522 |
if(!category || (trc_feats[i].category & category)) |
| 523 |
trc_feats[i].feat->log_level = lvl; |
| 524 |
} |
| 525 |
} |
| 526 |
|
| 527 |
static CURLcode trc_opt(const char *config) |
| 528 |
{ |
| 529 |
struct Curl_str out; |
| 530 |
while(!curlx_str_until(&config, &out, 32, ',')) { |
| 531 |
int lvl = CURL_LOG_LVL_INFO; |
| 532 |
const char *token = curlx_str(&out); |
| 533 |
|
| 534 |
if(*token == '-') { |
| 535 |
lvl = CURL_LOG_LVL_NONE; |
| 536 |
curlx_str_nudge(&out, 1); |
| 537 |
} |
| 538 |
else if(*token == '+') |
| 539 |
curlx_str_nudge(&out, 1); |
| 540 |
|
| 541 |
if(curlx_str_casecompare(&out, "all")) |
| 542 |
trc_apply_level_by_category(TRC_CT_NONE, lvl); |
| 543 |
else if(curlx_str_casecompare(&out, "protocol")) |
| 544 |
trc_apply_level_by_category(TRC_CT_PROTOCOL, lvl); |
| 545 |
else if(curlx_str_casecompare(&out, "network")) |
| 546 |
trc_apply_level_by_category(TRC_CT_NETWORK, lvl); |
| 547 |
else if(curlx_str_casecompare(&out, "proxy")) |
| 548 |
trc_apply_level_by_category(TRC_CT_PROXY, lvl); |
| 549 |
else if(curlx_str_casecompare(&out, "doh")) { |
| 550 |
struct Curl_str dns = { "dns", 3 }; |
| 551 |
trc_apply_level_by_name(&dns, lvl); |
| 552 |
} |
| 553 |
else |
| 554 |
trc_apply_level_by_name(&out, lvl); |
| 555 |
|
| 556 |
if(curlx_str_single(&config, ',')) |
| 557 |
break; |
| 558 |
} |
| 559 |
return CURLE_OK; |
| 560 |
} |
| 561 |
|
| 562 |
CURLcode Curl_trc_opt(const char *config) |
| 563 |
{ |
| 564 |
CURLcode result = config ? trc_opt(config) : CURLE_OK; |
| 565 |
#ifdef DEBUGBUILD |
| 566 |
|
| 567 |
if(!result) { |
| 568 |
const char *dbg_config = getenv("CURL_DEBUG"); |
| 569 |
if(dbg_config) |
| 570 |
result = trc_opt(dbg_config); |
| 571 |
} |
| 572 |
#endif |
| 573 |
return result; |
| 574 |
} |
| 575 |
|
| 576 |
CURLcode Curl_trc_init(void) |
| 577 |
{ |
| 578 |
#ifdef DEBUGBUILD |
| 579 |
return Curl_trc_opt(NULL); |
| 580 |
#else |
| 581 |
return CURLE_OK; |
| 582 |
#endif |
| 583 |
} |
| 584 |
|
| 585 |
#else |
| 586 |
|
| 587 |
CURLcode Curl_trc_init(void) |
| 588 |
{ |
| 589 |
return CURLE_OK; |
| 590 |
} |
| 591 |
|
| 592 |
void Curl_infof(struct Curl_easy *data, const char *fmt, ...) |
| 593 |
{ |
| 594 |
(void)data; (void)fmt; |
| 595 |
} |
| 596 |
|
| 597 |
void Curl_trc_cf_infof(struct Curl_easy *data, const struct Curl_cfilter *cf, |
| 598 |
const char *fmt, ...) |
| 599 |
{ |
| 600 |
(void)data; (void)cf; (void)fmt; |
| 601 |
} |
| 602 |
|
| 603 |
struct curl_trc_feat; |
| 604 |
|
| 605 |
void Curl_trc_multi(struct Curl_easy *data, const char *fmt, ...) |
| 606 |
{ |
| 607 |
(void)data; (void)fmt; |
| 608 |
} |
| 609 |
|
| 610 |
void Curl_trc_write(struct Curl_easy *data, const char *fmt, ...) |
| 611 |
{ |
| 612 |
(void)data; (void)fmt; |
| 613 |
} |
| 614 |
|
| 615 |
void Curl_trc_dns(struct Curl_easy *data, const char *fmt, ...) |
| 616 |
{ |
| 617 |
(void)data; (void)fmt; |
| 618 |
} |
| 619 |
|
| 620 |
void Curl_trc_read(struct Curl_easy *data, const char *fmt, ...) |
| 621 |
{ |
| 622 |
(void)data; (void)fmt; |
| 623 |
} |
| 624 |
|
| 625 |
#ifndef CURL_DISABLE_FTP |
| 626 |
void Curl_trc_ftp(struct Curl_easy *data, const char *fmt, ...) |
| 627 |
{ |
| 628 |
(void)data; (void)fmt; |
| 629 |
} |
| 630 |
#endif |
| 631 |
#ifndef CURL_DISABLE_SMTP |
| 632 |
void Curl_trc_smtp(struct Curl_easy *data, const char *fmt, ...) |
| 633 |
{ |
| 634 |
(void)data; (void)fmt; |
| 635 |
} |
| 636 |
#endif |
| 637 |
#if !defined(CURL_DISABLE_WEBSOCKETS) || !defined(CURL_DISABLE_HTTP) |
| 638 |
void Curl_trc_ws(struct Curl_easy *data, const char *fmt, ...) |
| 639 |
{ |
| 640 |
(void)data; (void)fmt; |
| 641 |
} |
| 642 |
#endif |
| 643 |
|
| 644 |
void Curl_trc_ssls(struct Curl_easy *data, const char *fmt, ...) |
| 645 |
{ |
| 646 |
(void)data; |
| 647 |
(void)fmt; |
| 648 |
} |
| 649 |
|
| 650 |
#endif |