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