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