Coverage Report

Created: 2026-12-01 06:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/curl/lib/curl_trc.c
Line
Count
Source
1
/***************************************************************************
2
 *                                  _   _ ____  _
3
 *  Project                     ___| | | |  _ \| |
4
 *                             / __| | | | |_) | |
5
 *                            | (__| |_| |  _ <| |___
6
 *                             \___|\___/|_| \_\_____|
7
 *
8
 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9
 *
10
 * This software is licensed as described in the file COPYING, which
11
 * you should have received as part of this distribution. The terms
12
 * are also available at https://curl.se/docs/copyright.html.
13
 *
14
 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
 * copies of the Software, and permit persons to whom the Software is
16
 * furnished to do so, under the terms of the COPYING file.
17
 *
18
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
 * KIND, either express or implied.
20
 *
21
 * SPDX-License-Identifier: curl
22
 *
23
 ***************************************************************************/
24
#include "curl_setup.h"
25
26
#include "curl_trc.h"
27
#include "urldata.h"
28
#include "cfilters.h"
29
#include "multiif.h"
30
31
#include "cf-recvbuf.h"
32
#include "cf-socket.h"
33
#include "cf-setup.h"
34
#include "http2.h"
35
#include "http_proxy.h"
36
#include "cf-h1-proxy.h"
37
#include "cf-h2-proxy.h"
38
#include "cf-haproxy.h"
39
#include "cf-https-connect.h"
40
#include "cf-ip-happy.h"
41
#include "ftp.h"
42
#include "progress.h"
43
#include "socks.h"
44
#include "curlx/strparse.h"
45
#include "vdns/cf-dns.h"
46
#include "vtls/vtls.h"
47
#include "vquic/vquic.h"
48
#include "curlx/strcopy.h"
49
50
static void trc_write(struct Curl_easy *data, curl_infotype type,
51
                      const char *ptr, size_t size)
52
675
{
53
675
  if(data->set.verbose) {
54
675
    if(data->set.fdebug) {
55
0
      struct Curl_mapi_guard guard;
56
0
      CURL_CBAPI_START(&guard, data, easy_fdebug);
57
0
      (void)(*data->set.fdebug)(data, type, CURL_UNCONST(ptr), size,
58
0
                                data->set.debugdata);
59
0
      CURL_CBAPI_END(&guard);
60
0
    }
61
675
    else {
62
675
      static const char s_infotype[CURLINFO_END][3] = {
63
675
        "* ", "< ", "> ", "{ ", "} ", "{ ", "} " };
64
675
      switch(type) {
65
675
      case CURLINFO_TEXT:
66
675
      case CURLINFO_HEADER_OUT:
67
675
      case CURLINFO_HEADER_IN:
68
675
        fwrite(s_infotype[type], 2, 1, data->set.err);
69
675
        fwrite(ptr, size, 1, data->set.err);
70
675
        break;
71
0
      default: /* nada */
72
0
        break;
73
675
      }
74
675
    }
75
675
  }
76
675
}
77
78
/* max length we trace before ending in '...' */
79
926
#define TRC_LINE_MAX 2048
80
81
0
#define CURL_TRC_FMT_IDSC   "[x-%" CURL_FORMAT_CURL_OFF_T "] "
82
0
#define CURL_TRC_FMT_IDSD   "[%" CURL_FORMAT_CURL_OFF_T "-x] "
83
0
#define CURL_TRC_FMT_IDSDC  "[%" CURL_FORMAT_CURL_OFF_T "-%" \
84
0
                            CURL_FORMAT_CURL_OFF_T "] "
85
86
static struct curl_trc_feat Curl_trc_feat_ids = {
87
  "LIB-IDS",
88
  CURL_LOG_LVL_NONE,
89
};
90
#define CURL_TRC_IDS(data) \
91
463
  (Curl_trc_is_verbose(data) && \
92
463
  Curl_trc_feat_ids.log_level >= CURL_LOG_LVL_INFO)
93
94
static size_t trc_print_ids(struct Curl_easy *data, char *buf, size_t maxlen)
95
0
{
96
0
  curl_off_t cid = data->state.last_conn_id;
97
0
  if(data->id >= 0) {
98
0
    if(cid >= 0)
99
0
      return curl_msnprintf(buf, maxlen, CURL_TRC_FMT_IDSDC, data->id, cid);
100
0
    else
101
0
      return curl_msnprintf(buf, maxlen, CURL_TRC_FMT_IDSD, data->id);
102
0
  }
103
0
  else if(cid >= 0)
104
0
    return curl_msnprintf(buf, maxlen, CURL_TRC_FMT_IDSC, cid);
105
0
  else {
106
0
    return curl_msnprintf(buf, maxlen, "[x-x] ");
107
0
  }
108
0
}
109
110
static size_t trc_end_buf(char *buf, size_t len, size_t maxlen, bool addnl)
111
463
{
112
  /* make sure we end the trace line in `buf` properly. It needs
113
   * to end with a null-terminator '\0' or '\n\0' */
114
463
  if(len >= (maxlen - (addnl ? 2 : 1))) {
115
0
    len = maxlen - 5;
116
0
    buf[len++] = '.';
117
0
    buf[len++] = '.';
118
0
    buf[len++] = '.';
119
0
    buf[len++] = '\n';
120
0
  }
121
463
  else if(addnl)
122
463
    buf[len++] = '\n';
123
463
  buf[len] = '\0';
124
463
  return len;
125
463
}
126
127
void Curl_debug(struct Curl_easy *data, curl_infotype type,
128
                const char *ptr, size_t size)
129
0
{
130
0
  if(data->set.verbose) {
131
0
    static const char s_infotype[CURLINFO_END][3] = {
132
0
      "* ", "< ", "> ", "{ ", "} ", "{ ", "} " };
133
0
    char buf[TRC_LINE_MAX];
134
0
    size_t len;
135
0
    if(data->set.fdebug) {
136
0
      struct Curl_mapi_guard guard;
137
0
      if(CURL_TRC_IDS(data) && (size < TRC_LINE_MAX)) {
138
0
        len = trc_print_ids(data, buf, TRC_LINE_MAX);
139
0
        len += curl_msnprintf(buf + len, TRC_LINE_MAX - len, "%.*s",
140
0
                              (int)size, ptr);
141
0
        len = trc_end_buf(buf, len, TRC_LINE_MAX, FALSE);
142
0
        CURL_CBAPI_START(&guard, data, easy_fdebug);
143
0
        (void)(*data->set.fdebug)(data, type, buf, len, data->set.debugdata);
144
0
        CURL_CBAPI_END(&guard);
145
0
      }
146
0
      else {
147
0
        CURL_CBAPI_START(&guard, data, easy_fdebug);
148
0
        (void)(*data->set.fdebug)(data, type, CURL_UNCONST(ptr),
149
0
                                  size, data->set.debugdata);
150
0
        CURL_CBAPI_END(&guard);
151
0
      }
152
0
    }
153
0
    else {
154
0
      switch(type) {
155
0
      case CURLINFO_TEXT:
156
0
      case CURLINFO_HEADER_OUT:
157
0
      case CURLINFO_HEADER_IN:
158
0
#ifndef CURL_DISABLE_VERBOSE_STRINGS
159
0
        if(CURL_TRC_IDS(data)) {
160
0
          len = trc_print_ids(data, buf, TRC_LINE_MAX);
161
0
          fwrite(buf, len, 1, data->set.err);
162
0
        }
163
0
#endif
164
0
        fwrite(s_infotype[type], 2, 1, data->set.err);
165
0
        fwrite(ptr, size, 1, data->set.err);
166
0
        break;
167
0
      default: /* nada */
168
0
        break;
169
0
      }
170
0
    }
171
0
  }
172
0
}
173
174
/* Curl_failf() is for messages stating why we failed.
175
 * The message SHALL NOT include any LF or CR.
176
 */
177
void Curl_failf(struct Curl_easy *data, const char *fmt, ...)
178
10.4k
{
179
10.4k
  DEBUGASSERT(!strchr(fmt, '\n'));
180
10.4k
  if(data->set.verbose || data->set.errorbuffer) {
181
212
    va_list ap;
182
212
    size_t len;
183
212
    char error[CURL_ERROR_SIZE + 2];
184
212
    va_start(ap, fmt);
185
212
    len = curl_mvsnprintf(error, CURL_ERROR_SIZE, fmt, ap);
186
187
212
    if(data->set.errorbuffer && !data->state.errorbuf) {
188
0
      curlx_strcopy(data->set.errorbuffer, CURL_ERROR_SIZE, error, len);
189
0
      data->state.errorbuf = TRUE; /* wrote error string */
190
0
    }
191
212
    error[len++] = '\n';
192
212
    error[len] = '\0';
193
212
    trc_write(data, CURLINFO_TEXT, error, len);
194
212
    va_end(ap);
195
212
  }
196
10.4k
}
197
198
void Curl_reset_fail(struct Curl_easy *data)
199
0
{
200
0
  if(data->set.errorbuffer)
201
0
    data->set.errorbuffer[0] = 0;
202
0
  data->state.errorbuf = FALSE;
203
0
}
204
205
#ifdef CURLVERBOSE
206
struct curl_trc_feat Curl_trc_feat_multi = {
207
  "MULTI",
208
  CURL_LOG_LVL_NONE,
209
};
210
struct curl_trc_feat Curl_trc_feat_read = {
211
  "READ",
212
  CURL_LOG_LVL_NONE,
213
};
214
struct curl_trc_feat Curl_trc_feat_write = {
215
  "WRITE",
216
  CURL_LOG_LVL_NONE,
217
};
218
struct curl_trc_feat Curl_trc_feat_dns = {
219
  "DNS",
220
  CURL_LOG_LVL_NONE,
221
};
222
#ifndef CURL_DISABLE_DOH
223
struct curl_trc_feat Curl_trc_feat_doh = {
224
  "DoH",
225
  CURL_LOG_LVL_NONE,
226
};
227
#endif
228
struct curl_trc_feat Curl_trc_feat_timer = {
229
  "TIMER",
230
  CURL_LOG_LVL_NONE,
231
};
232
#ifdef USE_THREADS
233
struct curl_trc_feat Curl_trc_feat_threads = {
234
  "THREADS",
235
  CURL_LOG_LVL_NONE,
236
};
237
#endif
238
#endif
239
240
#ifndef CURL_DISABLE_VERBOSE_STRINGS
241
242
static void trc_infof(struct Curl_easy *data,
243
                      struct curl_trc_feat *feat,
244
                      const char *opt_id, int opt_id_idx,
245
                      const char * const fmt, va_list ap) CURL_PRINTF(5, 0);
246
247
static void trc_infof(struct Curl_easy *data,
248
                      struct curl_trc_feat *feat,
249
                      const char *opt_id, int opt_id_idx,
250
                      const char * const fmt, va_list ap)
251
463
{
252
463
  size_t len = 0;
253
463
  char buf[TRC_LINE_MAX];
254
255
463
  if(CURL_TRC_IDS(data))
256
0
    len += trc_print_ids(data, buf + len, TRC_LINE_MAX - len);
257
463
  if(feat)
258
0
    len += curl_msnprintf(buf + len, TRC_LINE_MAX - len, "[%s] ", feat->name);
259
463
  if(opt_id) {
260
0
    if(opt_id_idx > 0)
261
0
      len += curl_msnprintf(buf + len, TRC_LINE_MAX - len, "[%s-%d] ",
262
0
                            opt_id, opt_id_idx);
263
0
    else
264
0
      len += curl_msnprintf(buf + len, TRC_LINE_MAX - len, "[%s] ", opt_id);
265
0
  }
266
463
  len += curl_mvsnprintf(buf + len, TRC_LINE_MAX - len, fmt, ap);
267
463
  len = trc_end_buf(buf, len, TRC_LINE_MAX, TRUE);
268
463
  trc_write(data, CURLINFO_TEXT, buf, len);
269
463
}
270
271
void Curl_infof(struct Curl_easy *data, const char *fmt, ...)
272
463
{
273
463
  DEBUGASSERT(!strchr(fmt, '\n'));
274
463
  if(Curl_trc_is_verbose(data)) {
275
463
    va_list ap;
276
463
    va_start(ap, fmt);
277
463
    trc_infof(data, data->state.feat, NULL, 0, fmt, ap);
278
463
    va_end(ap);
279
463
  }
280
463
}
281
282
void Curl_trc_cf_infof(struct Curl_easy *data, const struct Curl_cfilter *cf,
283
                       const char *fmt, ...)
284
0
{
285
0
  DEBUGASSERT(cf);
286
0
  if(Curl_trc_cf_is_verbose(cf, data)) {
287
0
    va_list ap;
288
0
    va_start(ap, fmt);
289
0
    trc_infof(data, data->state.feat, cf->cft->name,
290
0
              (cf->chain && !CF_IS_PRIMARY(cf)) ? 1 : 0, fmt, ap);
291
0
    va_end(ap);
292
0
  }
293
0
}
294
295
void Curl_trc_feat_infof(struct Curl_easy *data,
296
                         struct curl_trc_feat *feat,
297
                         const char *fmt, ...)
298
0
{
299
0
  DEBUGASSERT(feat);
300
0
  if(Curl_trc_ft_is_verbose(data, feat)) {
301
0
    va_list ap;
302
0
    va_start(ap, fmt);
303
0
    trc_infof(data, feat, NULL, 0, fmt, ap);
304
0
    va_end(ap);
305
0
  }
306
0
}
307
308
static const char * const Curl_trc_timer_names[] = {
309
  "100_TIMEOUT",
310
  "ASYNC_NAME",
311
  "CONNECTTIMEOUT",
312
  "HAPPY_EYEBALLS",
313
  "MULTI_PENDING",
314
  "SPEEDCHECK",
315
  "TIMEOUT",
316
  "TOOFAST",
317
  "QUIC",
318
  "FTP_ACCEPT",
319
  "ALPN_EYEBALLS",
320
  "SHUTDOWN",
321
  "SERVER_RESPONSE",
322
};
323
324
static const char *trc_timer_name(int tid)
325
0
{
326
0
  if((tid >= 0) && ((size_t)tid < CURL_ARRAYSIZE(Curl_trc_timer_names)))
327
0
    return Curl_trc_timer_names[(size_t)tid];
328
0
  return "TIMER-???";
329
0
}
330
331
void Curl_trc_timer(struct Curl_easy *data, int tid, const char *fmt, ...)
332
0
{
333
0
  DEBUGASSERT(!strchr(fmt, '\n'));
334
0
  if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_timer)) {
335
0
    const char *tname = trc_timer_name(tid);
336
0
    va_list ap;
337
0
    va_start(ap, fmt);
338
0
    trc_infof(data, &Curl_trc_feat_timer, tname, 0, fmt, ap);
339
0
    va_end(ap);
340
0
  }
341
0
}
342
343
void Curl_trc_easy_timers(struct Curl_easy *data)
344
0
{
345
0
  if(CURL_TRC_TIMER_is_verbose(data) && data->multi) {
346
0
    if(data->state.timeouts.first < EXPIRE_LAST) {
347
0
      struct expire_timers *timeouts = &data->state.timeouts;
348
0
      timediff_t base_us =
349
0
        Curl_timeouts_offset_us(&data->multi->timeouts, Curl_pgrs_now(data));
350
0
      uint8_t id = data->state.timeouts.first;
351
0
      for(; id < EXPIRE_LAST; id = timeouts->next[id]) {
352
0
        CURL_TRC_TIMER(data, id, "expires in %" FMT_TIMEDIFF_T "us",
353
0
                       timeouts->offset_us[id] - base_us);
354
0
      }
355
0
    }
356
0
  }
357
0
}
358
359
static const char * const Curl_trc_mstate_names[] = {
360
  "INIT",
361
  "PENDING",
362
  "SETUP",
363
  "CONNECT",
364
  "CONNECTING",
365
  "PROTOCONNECT",
366
  "PROTOCONNECTING",
367
  "DO",
368
  "DOING",
369
  "DOING_MORE",
370
  "DID",
371
  "PERFORMING",
372
  "RATELIMITING",
373
  "DONE",
374
  "COMPLETED",
375
  "MSGSENT",
376
};
377
378
const char *Curl_trc_mstate_name(int state)
379
0
{
380
0
  if((state >= 0) && ((size_t)state < CURL_ARRAYSIZE(Curl_trc_mstate_names)))
381
0
    return Curl_trc_mstate_names[(size_t)state];
382
0
  return "?";
383
0
}
384
385
void Curl_trc_multi(struct Curl_easy *data, const char *fmt, ...)
386
0
{
387
0
  DEBUGASSERT(!strchr(fmt, '\n'));
388
0
  if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_multi)) {
389
0
    const char *sname = (data->id >= 0) ?
390
0
                        Curl_trc_mstate_name(data->mstate) : NULL;
391
0
    va_list ap;
392
0
    va_start(ap, fmt);
393
0
    trc_infof(data, &Curl_trc_feat_multi, sname, 0, fmt, ap);
394
0
    va_end(ap);
395
0
  }
396
0
}
397
398
void Curl_trc_read(struct Curl_easy *data, const char *fmt, ...)
399
0
{
400
0
  DEBUGASSERT(!strchr(fmt, '\n'));
401
0
  if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_read)) {
402
0
    va_list ap;
403
0
    va_start(ap, fmt);
404
0
    trc_infof(data, &Curl_trc_feat_read, NULL, 0, fmt, ap);
405
0
    va_end(ap);
406
0
  }
407
0
}
408
409
void Curl_trc_write(struct Curl_easy *data, const char *fmt, ...)
410
0
{
411
0
  DEBUGASSERT(!strchr(fmt, '\n'));
412
0
  if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_write)) {
413
0
    va_list ap;
414
0
    va_start(ap, fmt);
415
0
    trc_infof(data, &Curl_trc_feat_write, NULL, 0, fmt, ap);
416
0
    va_end(ap);
417
0
  }
418
0
}
419
420
void Curl_trc_dns(struct Curl_easy *data, const char *fmt, ...)
421
0
{
422
0
  DEBUGASSERT(!strchr(fmt, '\n'));
423
0
  if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_dns)) {
424
0
    va_list ap;
425
0
    va_start(ap, fmt);
426
0
    trc_infof(data, &Curl_trc_feat_dns, NULL, 0, fmt, ap);
427
0
    va_end(ap);
428
0
  }
429
0
}
430
431
#ifndef CURL_DISABLE_FTP
432
struct curl_trc_feat Curl_trc_feat_ftp = {
433
  "FTP",
434
  CURL_LOG_LVL_NONE,
435
};
436
437
void Curl_trc_ftp(struct Curl_easy *data, const char *fmt, ...)
438
0
{
439
0
  DEBUGASSERT(!strchr(fmt, '\n'));
440
0
  if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ftp)) {
441
0
    va_list ap;
442
0
    va_start(ap, fmt);
443
0
    trc_infof(data, &Curl_trc_feat_ftp, NULL, 0, fmt, ap);
444
0
    va_end(ap);
445
0
  }
446
0
}
447
#endif /* !CURL_DISABLE_FTP */
448
449
#ifndef CURL_DISABLE_SMTP
450
struct curl_trc_feat Curl_trc_feat_smtp = {
451
  "SMTP",
452
  CURL_LOG_LVL_NONE,
453
};
454
455
void Curl_trc_smtp(struct Curl_easy *data, const char *fmt, ...)
456
0
{
457
0
  DEBUGASSERT(!strchr(fmt, '\n'));
458
0
  if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_smtp)) {
459
0
    va_list ap;
460
0
    va_start(ap, fmt);
461
0
    trc_infof(data, &Curl_trc_feat_smtp, NULL, 0, fmt, ap);
462
0
    va_end(ap);
463
0
  }
464
0
}
465
#endif /* !CURL_DISABLE_SMTP */
466
467
#ifdef USE_SSL
468
struct curl_trc_feat Curl_trc_feat_ssls = {
469
  "SSLS",
470
  CURL_LOG_LVL_NONE,
471
};
472
473
void Curl_trc_ssls(struct Curl_easy *data, const char *fmt, ...)
474
0
{
475
0
  DEBUGASSERT(!strchr(fmt, '\n'));
476
0
  if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ssls)) {
477
0
    va_list ap;
478
0
    va_start(ap, fmt);
479
0
    trc_infof(data, &Curl_trc_feat_ssls, NULL, 0, fmt, ap);
480
0
    va_end(ap);
481
0
  }
482
0
}
483
#endif /* USE_SSL */
484
485
#ifdef USE_SSH
486
struct curl_trc_feat Curl_trc_feat_ssh = {
487
  "SSH",
488
  CURL_LOG_LVL_NONE,
489
};
490
491
void Curl_trc_ssh(struct Curl_easy *data, const char *fmt, ...)
492
{
493
  DEBUGASSERT(!strchr(fmt, '\n'));
494
  if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ssh)) {
495
    va_list ap;
496
    va_start(ap, fmt);
497
    trc_infof(data, &Curl_trc_feat_ssh, NULL, 0, fmt, ap);
498
    va_end(ap);
499
  }
500
}
501
#endif /* USE_SSH */
502
503
#if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP)
504
struct curl_trc_feat Curl_trc_feat_ws = {
505
  "WS",
506
  CURL_LOG_LVL_NONE,
507
};
508
509
void Curl_trc_ws(struct Curl_easy *data, const char *fmt, ...)
510
0
{
511
0
  DEBUGASSERT(!strchr(fmt, '\n'));
512
0
  if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ws)) {
513
0
    va_list ap;
514
0
    va_start(ap, fmt);
515
0
    trc_infof(data, &Curl_trc_feat_ws, NULL, 0, fmt, ap);
516
0
    va_end(ap);
517
0
  }
518
0
}
519
#endif /* !CURL_DISABLE_WEBSOCKETS && !CURL_DISABLE_HTTP */
520
521
0
#define TRC_CT_NONE        0
522
0
#define TRC_CT_PROTOCOL    (1 << 0)
523
0
#define TRC_CT_NETWORK     (1 << 1)
524
0
#define TRC_CT_PROXY       (1 << 2)
525
#define TRC_CT_INTERNALS   (1 << 3)
526
527
struct trc_feat_def {
528
  struct curl_trc_feat *feat;
529
  unsigned int category;
530
};
531
532
static struct trc_feat_def trc_feats[] = {
533
  { &Curl_trc_feat_ids,       TRC_CT_INTERNALS },
534
  { &Curl_trc_feat_multi,     TRC_CT_NETWORK },
535
  { &Curl_trc_feat_read,      TRC_CT_NONE },
536
  { &Curl_trc_feat_write,     TRC_CT_NONE },
537
  { &Curl_trc_feat_dns,       TRC_CT_NETWORK },
538
#ifndef CURL_DISABLE_DOH
539
  { &Curl_trc_feat_doh,       TRC_CT_NETWORK },
540
#endif
541
  { &Curl_trc_feat_timer,     TRC_CT_NETWORK },
542
#ifdef USE_THREADS
543
  { &Curl_trc_feat_threads,   TRC_CT_NONE },
544
#endif
545
#ifndef CURL_DISABLE_FTP
546
  { &Curl_trc_feat_ftp,       TRC_CT_PROTOCOL },
547
#endif
548
#ifndef CURL_DISABLE_SMTP
549
  { &Curl_trc_feat_smtp,      TRC_CT_PROTOCOL },
550
#endif
551
#ifdef USE_SSL
552
  { &Curl_trc_feat_ssls,      TRC_CT_NETWORK },
553
#endif
554
#ifdef USE_SSH
555
  { &Curl_trc_feat_ssh,       TRC_CT_PROTOCOL },
556
#endif
557
#if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP)
558
  { &Curl_trc_feat_ws,        TRC_CT_PROTOCOL },
559
#endif
560
};
561
562
struct trc_cft_def {
563
  struct Curl_cftype *cft;
564
  unsigned int category;
565
};
566
567
static struct trc_cft_def trc_cfts[] = {
568
  { &Curl_cft_dns,            TRC_CT_NETWORK },
569
  { &Curl_cft_tcp,            TRC_CT_NETWORK },
570
  { &Curl_cft_udp,            TRC_CT_NETWORK },
571
  { &Curl_cft_unix,           TRC_CT_NETWORK },
572
  { &Curl_cft_tcp_accept,     TRC_CT_NETWORK },
573
  { &Curl_cft_ip_happy,       TRC_CT_NETWORK },
574
#ifndef CURL_DISABLE_WEBSOCKETS
575
  { &Curl_cft_recvbuf,        TRC_CT_PROTOCOL },
576
#endif
577
  { &Curl_cft_setup,          TRC_CT_PROTOCOL },
578
#if !defined(CURL_DISABLE_HTTP) && defined(USE_NGHTTP2)
579
  { &Curl_cft_nghttp2,        TRC_CT_PROTOCOL },
580
#endif
581
#ifdef USE_SSL
582
  { &Curl_cft_ssl,            TRC_CT_NETWORK },
583
#ifndef CURL_DISABLE_PROXY
584
  { &Curl_cft_ssl_proxy,      TRC_CT_PROXY },
585
#endif
586
#endif
587
#ifndef CURL_DISABLE_PROXY
588
#ifndef CURL_DISABLE_HTTP
589
  { &Curl_cft_h1_proxy,       TRC_CT_PROXY },
590
#ifdef USE_NGHTTP2
591
  { &Curl_cft_h2_proxy,       TRC_CT_PROXY },
592
#endif
593
#if defined(USE_PROXY_HTTP3) && defined(USE_NGHTTP3)
594
  { &Curl_cft_h3_proxy,       TRC_CT_PROXY },
595
#endif
596
  { &Curl_cft_http_proxy,     TRC_CT_PROXY },
597
#endif /* !CURL_DISABLE_HTTP */
598
  { &Curl_cft_haproxy,        TRC_CT_PROXY },
599
  { &Curl_cft_socks_proxy,    TRC_CT_PROXY },
600
#endif /* !CURL_DISABLE_PROXY */
601
#if !defined(CURL_DISABLE_HTTP) && defined(USE_HTTP3)
602
  { &Curl_cft_http3,          TRC_CT_PROTOCOL },
603
#endif
604
#ifndef CURL_DISABLE_HTTP
605
  { &Curl_cft_http_connect,   TRC_CT_PROTOCOL },
606
#endif
607
#ifndef CURL_DISABLE_FTP
608
  { &Curl_cft_ftp,            TRC_CT_PROTOCOL },
609
#endif
610
};
611
612
static void trc_apply_level_by_name(struct Curl_str *token, int lvl)
613
0
{
614
0
  size_t i;
615
616
0
  for(i = 0; i < CURL_ARRAYSIZE(trc_cfts); ++i) {
617
0
    if(curlx_str_casecompare(token, trc_cfts[i].cft->name)) {
618
0
      trc_cfts[i].cft->log_level = lvl;
619
0
      break;
620
0
    }
621
0
  }
622
0
  for(i = 0; i < CURL_ARRAYSIZE(trc_feats); ++i) {
623
0
    if(curlx_str_casecompare(token, trc_feats[i].feat->name)) {
624
0
      trc_feats[i].feat->log_level = lvl;
625
0
      break;
626
0
    }
627
0
  }
628
0
}
629
630
static void trc_apply_level_by_category(unsigned int category, int lvl)
631
0
{
632
0
  size_t i;
633
634
0
  for(i = 0; i < CURL_ARRAYSIZE(trc_cfts); ++i) {
635
0
    if(!category || (trc_cfts[i].category & category))
636
0
      trc_cfts[i].cft->log_level = lvl;
637
0
  }
638
0
  for(i = 0; i < CURL_ARRAYSIZE(trc_feats); ++i) {
639
0
    if(!category || (trc_feats[i].category & category))
640
0
      trc_feats[i].feat->log_level = lvl;
641
0
  }
642
0
}
643
644
static CURLcode trc_opt(const char *config)
645
0
{
646
0
  struct Curl_str out;
647
0
  while(!curlx_str_until(&config, &out, 32, ',')) {
648
0
    int lvl = CURL_LOG_LVL_INFO;
649
0
    const char *token = curlx_str(&out);
650
651
0
    if(*token == '-') {
652
0
      lvl = CURL_LOG_LVL_NONE;
653
0
      curlx_str_nudge(&out, 1);
654
0
    }
655
0
    else if(*token == '+')
656
0
      curlx_str_nudge(&out, 1);
657
658
0
    if(curlx_str_casecompare2(&out, STRCONST("all")))
659
0
      trc_apply_level_by_category(TRC_CT_NONE, lvl);
660
0
    else if(curlx_str_casecompare2(&out, STRCONST("protocol")))
661
0
      trc_apply_level_by_category(TRC_CT_PROTOCOL, lvl);
662
0
    else if(curlx_str_casecompare2(&out, STRCONST("network")))
663
0
      trc_apply_level_by_category(TRC_CT_NETWORK, lvl);
664
0
    else if(curlx_str_casecompare2(&out, STRCONST("proxy")))
665
0
      trc_apply_level_by_category(TRC_CT_PROXY, lvl);
666
0
    else
667
0
      trc_apply_level_by_name(&out, lvl);
668
669
0
    if(curlx_str_single(&config, ','))
670
0
      break;
671
0
  }
672
0
  return CURLE_OK;
673
0
}
674
675
CURLcode Curl_trc_opt(const char *config)
676
2
{
677
2
  CURLcode result = config ? trc_opt(config) : CURLE_OK;
678
2
#ifdef DEBUGBUILD
679
  /* CURL_DEBUG can override anything */
680
2
  if(!result) {
681
2
    const char *dbg_config = getenv("CURL_DEBUG");
682
2
    if(dbg_config)
683
0
      result = trc_opt(dbg_config);
684
2
  }
685
2
#endif /* DEBUGBUILD */
686
2
  return result;
687
2
}
688
689
CURLcode Curl_trc_init(void)
690
2
{
691
2
#ifdef DEBUGBUILD
692
2
  return Curl_trc_opt(NULL);
693
#else
694
  return CURLE_OK;
695
#endif
696
2
}
697
698
#else /* CURL_DISABLE_VERBOSE_STRINGS */
699
700
CURLcode Curl_trc_init(void)
701
{
702
  return CURLE_OK;
703
}
704
705
void Curl_infof(struct Curl_easy *data, const char *fmt, ...)
706
{
707
  (void)data;
708
  (void)fmt;
709
}
710
711
void Curl_trc_cf_infof(struct Curl_easy *data, const struct Curl_cfilter *cf,
712
                       const char *fmt, ...)
713
{
714
  (void)data;
715
  (void)cf;
716
  (void)fmt;
717
}
718
719
void Curl_trc_multi(struct Curl_easy *data, const char *fmt, ...)
720
{
721
  (void)data;
722
  (void)fmt;
723
}
724
725
void Curl_trc_write(struct Curl_easy *data, const char *fmt, ...)
726
{
727
  (void)data;
728
  (void)fmt;
729
}
730
731
void Curl_trc_dns(struct Curl_easy *data, const char *fmt, ...)
732
{
733
  (void)data;
734
  (void)fmt;
735
}
736
737
void Curl_trc_timer(struct Curl_easy *data, int tid, const char *fmt, ...)
738
{
739
  (void)data;
740
  (void)tid;
741
  (void)fmt;
742
}
743
744
void Curl_trc_read(struct Curl_easy *data, const char *fmt, ...)
745
{
746
  (void)data;
747
  (void)fmt;
748
}
749
750
#ifndef CURL_DISABLE_FTP
751
void Curl_trc_ftp(struct Curl_easy *data, const char *fmt, ...)
752
{
753
  (void)data;
754
  (void)fmt;
755
}
756
#endif
757
#ifndef CURL_DISABLE_SMTP
758
void Curl_trc_smtp(struct Curl_easy *data, const char *fmt, ...)
759
{
760
  (void)data;
761
  (void)fmt;
762
}
763
#endif
764
#if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP)
765
void Curl_trc_ws(struct Curl_easy *data, const char *fmt, ...)
766
{
767
  (void)data;
768
  (void)fmt;
769
}
770
#endif
771
#ifdef USE_SSH
772
void Curl_trc_ssh(struct Curl_easy *data, const char *fmt, ...)
773
{
774
  (void)data;
775
  (void)fmt;
776
}
777
#endif
778
#ifdef USE_SSL
779
void Curl_trc_ssls(struct Curl_easy *data, const char *fmt, ...)
780
{
781
  (void)data;
782
  (void)fmt;
783
}
784
#endif
785
786
#endif /* !CURL_DISABLE_VERBOSE_STRINGS */