Line | Count | Source |
1 | | #ifndef HEADER_CURL_TRC_H |
2 | | #define HEADER_CURL_TRC_H |
3 | | /*************************************************************************** |
4 | | * _ _ ____ _ |
5 | | * Project ___| | | | _ \| | |
6 | | * / __| | | | |_) | | |
7 | | * | (__| |_| | _ <| |___ |
8 | | * \___|\___/|_| \_\_____| |
9 | | * |
10 | | * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. |
11 | | * |
12 | | * This software is licensed as described in the file COPYING, which |
13 | | * you should have received as part of this distribution. The terms |
14 | | * are also available at https://curl.se/docs/copyright.html. |
15 | | * |
16 | | * You may opt to use, copy, modify, merge, publish, distribute and/or sell |
17 | | * copies of the Software, and permit persons to whom the Software is |
18 | | * furnished to do so, under the terms of the COPYING file. |
19 | | * |
20 | | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
21 | | * KIND, either express or implied. |
22 | | * |
23 | | * SPDX-License-Identifier: curl |
24 | | * |
25 | | ***************************************************************************/ |
26 | | struct Curl_easy; |
27 | | struct Curl_cfilter; |
28 | | |
29 | | /** |
30 | | * Init logging, return != 0 on failure. |
31 | | */ |
32 | | CURLcode Curl_trc_init(void); |
33 | | |
34 | | /** |
35 | | * Configure tracing. May be called several times during global |
36 | | * initialization. Later calls may not take effect. |
37 | | * |
38 | | * Configuration format supported: |
39 | | * - comma-separated list of component names to enable logging on. |
40 | | * E.g. 'http/2,ssl'. Unknown names are ignored. Names are compared |
41 | | * case-insensitive. |
42 | | * - component 'all' applies to all known log components |
43 | | * - prefixing a component with '+' or '-' will en-/disable logging for |
44 | | * that component |
45 | | * Example: 'all,-ssl' would enable logging for all components but the |
46 | | * SSL filters. |
47 | | * |
48 | | * @param config configuration string |
49 | | */ |
50 | | CURLcode Curl_trc_opt(const char *config); |
51 | | |
52 | | /* the function used to output verbose information */ |
53 | | void Curl_debug(struct Curl_easy *data, curl_infotype type, |
54 | | const char *ptr, size_t size); |
55 | | |
56 | | /** |
57 | | * Output a failure message on registered callbacks for transfer. |
58 | | */ |
59 | | void Curl_failf(struct Curl_easy *data, |
60 | | const char *fmt, ...) CURL_PRINTF(2, 3); |
61 | | |
62 | 20.9k | #define failf Curl_failf |
63 | | |
64 | | /* In case failf() reported into the errorbuf, clear it again. |
65 | | * This is used to clear information from happy eyeballing attempts |
66 | | * when ultimately a successful attempt was made. */ |
67 | | void Curl_reset_fail(struct Curl_easy *data); |
68 | | |
69 | 0 | #define CURL_LOG_LVL_NONE 0 |
70 | 0 | #define CURL_LOG_LVL_INFO 1 |
71 | | |
72 | | /** |
73 | | * Output an informational message when transfer's verbose logging is enabled. |
74 | | */ |
75 | | void Curl_infof(struct Curl_easy *data, |
76 | | const char *fmt, ...) CURL_PRINTF(2, 3); |
77 | | |
78 | | /** |
79 | | * Output an informational message when both transfer's verbose logging |
80 | | * and connection filters verbose logging are enabled. |
81 | | */ |
82 | | void Curl_trc_cf_infof(struct Curl_easy *data, const struct Curl_cfilter *cf, |
83 | | const char *fmt, ...) CURL_PRINTF(3, 4); |
84 | | void Curl_trc_multi(struct Curl_easy *data, |
85 | | const char *fmt, ...) CURL_PRINTF(2, 3); |
86 | | const char *Curl_trc_mstate_name(int state); |
87 | | const char *Curl_trc_timer_name(int tid); |
88 | | void Curl_trc_easy_timers(struct Curl_easy *data); |
89 | | |
90 | | void Curl_trc_write(struct Curl_easy *data, |
91 | | const char *fmt, ...) CURL_PRINTF(2, 3); |
92 | | void Curl_trc_read(struct Curl_easy *data, |
93 | | const char *fmt, ...) CURL_PRINTF(2, 3); |
94 | | void Curl_trc_dns(struct Curl_easy *data, |
95 | | const char *fmt, ...) CURL_PRINTF(2, 3); |
96 | | void Curl_trc_timer(struct Curl_easy *data, int tid, |
97 | | const char *fmt, ...) CURL_PRINTF(3, 4); |
98 | | |
99 | | struct curl_trc_feat { |
100 | | const char *name; |
101 | | int log_level; |
102 | | }; |
103 | | |
104 | | void Curl_trc_feat_infof(struct Curl_easy *data, |
105 | | struct curl_trc_feat *feat, |
106 | | const char *fmt, ...) CURL_PRINTF(3, 4); |
107 | | |
108 | | #ifndef CURL_DISABLE_FTP |
109 | | extern struct curl_trc_feat Curl_trc_feat_ftp; |
110 | | void Curl_trc_ftp(struct Curl_easy *data, |
111 | | const char *fmt, ...) CURL_PRINTF(2, 3); |
112 | | #endif |
113 | | #ifndef CURL_DISABLE_SMTP |
114 | | extern struct curl_trc_feat Curl_trc_feat_smtp; |
115 | | void Curl_trc_smtp(struct Curl_easy *data, |
116 | | const char *fmt, ...) CURL_PRINTF(2, 3); |
117 | | #endif |
118 | | #ifdef USE_SSL |
119 | | extern struct curl_trc_feat Curl_trc_feat_ssls; |
120 | | void Curl_trc_ssls(struct Curl_easy *data, |
121 | | const char *fmt, ...) CURL_PRINTF(2, 3); |
122 | | #endif |
123 | | #ifdef USE_SSH |
124 | | extern struct curl_trc_feat Curl_trc_feat_ssh; |
125 | | void Curl_trc_ssh(struct Curl_easy *data, |
126 | | const char *fmt, ...) CURL_PRINTF(2, 3); |
127 | | #endif |
128 | | #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) |
129 | | extern struct curl_trc_feat Curl_trc_feat_ws; |
130 | | void Curl_trc_ws(struct Curl_easy *data, |
131 | | const char *fmt, ...) CURL_PRINTF(2, 3); |
132 | | #endif |
133 | | |
134 | | #define CURL_TRC_M_is_verbose(data) \ |
135 | 756k | Curl_trc_ft_is_verbose(data, &Curl_trc_feat_multi) |
136 | | #define CURL_TRC_DNS_is_verbose(data) \ |
137 | 105k | Curl_trc_ft_is_verbose(data, &Curl_trc_feat_dns) |
138 | | #define CURL_TRC_TIMER_is_verbose(data) \ |
139 | 37.9k | Curl_trc_ft_is_verbose(data, &Curl_trc_feat_timer) |
140 | | |
141 | | #if defined(CURL_HAVE_MACRO_VARARG) && !defined(CURL_DISABLE_VERBOSE_STRINGS) |
142 | | #define infof(data, ...) \ |
143 | 278k | do { \ |
144 | 278k | if(Curl_trc_is_verbose(data)) \ |
145 | 278k | Curl_infof(data, __VA_ARGS__); \ |
146 | 278k | } while(0) |
147 | | #define CURL_TRC_M(data, ...) \ |
148 | 675k | do { \ |
149 | 675k | if(CURL_TRC_M_is_verbose(data)) \ |
150 | 675k | Curl_trc_multi(data, __VA_ARGS__); \ |
151 | 675k | } while(0) |
152 | | #define CURL_TRC_CF(data, cf, ...) \ |
153 | 805k | do { \ |
154 | 805k | if(Curl_trc_cf_is_verbose(cf, data)) \ |
155 | 805k | Curl_trc_cf_infof(data, cf, __VA_ARGS__); \ |
156 | 805k | } while(0) |
157 | | #define CURL_TRC_WRITE(data, ...) \ |
158 | 221k | do { \ |
159 | 221k | if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_write)) \ |
160 | 221k | Curl_trc_write(data, __VA_ARGS__); \ |
161 | 221k | } while(0) |
162 | | #define CURL_TRC_READ(data, ...) \ |
163 | 31.0k | do { \ |
164 | 31.0k | if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_read)) \ |
165 | 31.0k | Curl_trc_read(data, __VA_ARGS__); \ |
166 | 31.0k | } while(0) |
167 | | #define CURL_TRC_DNS(data, ...) \ |
168 | 105k | do { \ |
169 | 105k | if(CURL_TRC_DNS_is_verbose(data)) \ |
170 | 105k | Curl_trc_dns(data, __VA_ARGS__); \ |
171 | 105k | } while(0) |
172 | | #define CURL_TRC_TIMER(data, tid, ...) \ |
173 | 37.9k | do { \ |
174 | 37.9k | if(CURL_TRC_TIMER_is_verbose(data)) \ |
175 | 37.9k | Curl_trc_timer(data, tid, __VA_ARGS__); \ |
176 | 37.9k | } while(0) |
177 | | |
178 | | #ifndef CURL_DISABLE_FTP |
179 | | #define CURL_TRC_FTP(data, ...) \ |
180 | 0 | do { \ |
181 | 0 | if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ftp)) \ |
182 | 0 | Curl_trc_ftp(data, __VA_ARGS__); \ |
183 | 0 | } while(0) |
184 | | #endif /* !CURL_DISABLE_FTP */ |
185 | | #ifndef CURL_DISABLE_SMTP |
186 | | #define CURL_TRC_SMTP(data, ...) \ |
187 | 0 | do { \ |
188 | 0 | if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_smtp)) \ |
189 | 0 | Curl_trc_smtp(data, __VA_ARGS__); \ |
190 | 0 | } while(0) |
191 | | #endif /* !CURL_DISABLE_SMTP */ |
192 | | #ifdef USE_SSL |
193 | | #define CURL_TRC_SSLS(data, ...) \ |
194 | 5.61k | do { \ |
195 | 5.61k | if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ssls)) \ |
196 | 5.61k | Curl_trc_ssls(data, __VA_ARGS__); \ |
197 | 5.61k | } while(0) |
198 | | #endif /* USE_SSL */ |
199 | | #ifdef USE_SSH |
200 | | #define CURL_TRC_SSH(data, ...) \ |
201 | | do { \ |
202 | | if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ssh)) \ |
203 | | Curl_trc_ssh(data, __VA_ARGS__); \ |
204 | | } while(0) |
205 | | #endif /* USE_SSH */ |
206 | | #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) |
207 | | #define CURL_TRC_WS(data, ...) \ |
208 | 4 | do { \ |
209 | 4 | if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ws)) \ |
210 | 4 | Curl_trc_ws(data, __VA_ARGS__); \ |
211 | 4 | } while(0) |
212 | | #endif /* !CURL_DISABLE_WEBSOCKETS && !CURL_DISABLE_HTTP */ |
213 | | |
214 | | #elif defined(CURL_HAVE_MACRO_VARARG) && defined(CURL_DISABLE_VERBOSE_STRINGS) |
215 | | |
216 | | #define infof(data, ...) \ |
217 | | do { \ |
218 | | (void)(data); \ |
219 | | } while(0) |
220 | | #define CURL_TRC_M(data, ...) \ |
221 | | do { \ |
222 | | (void)(data); \ |
223 | | } while(0) |
224 | | #define CURL_TRC_CF(data, cf, ...) \ |
225 | | do { \ |
226 | | (void)(data); \ |
227 | | (void)(cf); \ |
228 | | } while(0) |
229 | | #define CURL_TRC_WRITE(data, ...) \ |
230 | | do { \ |
231 | | (void)(data); \ |
232 | | } while(0) |
233 | | #define CURL_TRC_READ(data, ...) \ |
234 | | do { \ |
235 | | (void)(data); \ |
236 | | } while(0) |
237 | | #define CURL_TRC_DNS(data, ...) \ |
238 | | do { \ |
239 | | (void)(data); \ |
240 | | } while(0) |
241 | | #define CURL_TRC_TIMER(data, tid, ...) \ |
242 | | do { \ |
243 | | (void)(data); \ |
244 | | (void)(tid); \ |
245 | | } while(0) |
246 | | #ifndef CURL_DISABLE_FTP |
247 | | #define CURL_TRC_FTP(data, ...) \ |
248 | | do { \ |
249 | | (void)(data); \ |
250 | | } while(0) |
251 | | #endif /* !CURL_DISABLE_FTP */ |
252 | | #ifndef CURL_DISABLE_SMTP |
253 | | #define CURL_TRC_SMTP(data, ...) \ |
254 | | do { \ |
255 | | (void)(data); \ |
256 | | } while(0) |
257 | | #endif /* !CURL_DISABLE_SMTP */ |
258 | | #ifdef USE_SSL |
259 | | #define CURL_TRC_SSLS(data, ...) \ |
260 | | do { \ |
261 | | (void)(data); \ |
262 | | } while(0) |
263 | | #endif /* USE_SSL */ |
264 | | #ifdef USE_SSH |
265 | | #define CURL_TRC_SSH(data, ...) \ |
266 | | do { \ |
267 | | (void)(data); \ |
268 | | } while(0) |
269 | | #endif /* USE_SSH */ |
270 | | #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) |
271 | | #define CURL_TRC_WS(data, ...) \ |
272 | | do { \ |
273 | | (void)(data); \ |
274 | | } while(0) |
275 | | #endif |
276 | | |
277 | | #else /* !CURL_HAVE_MACRO_VARARG */ |
278 | | |
279 | | #define infof Curl_infof |
280 | | #define CURL_TRC_M Curl_trc_multi |
281 | | #define CURL_TRC_CF Curl_trc_cf_infof |
282 | | #define CURL_TRC_WRITE Curl_trc_write |
283 | | #define CURL_TRC_READ Curl_trc_read |
284 | | #define CURL_TRC_DNS Curl_trc_dns |
285 | | #define CURL_TRC_TIMER Curl_trc_timer |
286 | | |
287 | | #ifndef CURL_DISABLE_FTP |
288 | | #define CURL_TRC_FTP Curl_trc_ftp |
289 | | #endif |
290 | | #ifndef CURL_DISABLE_SMTP |
291 | | #define CURL_TRC_SMTP Curl_trc_smtp |
292 | | #endif |
293 | | #ifdef USE_SSL |
294 | | #define CURL_TRC_SSLS Curl_trc_ssls |
295 | | #endif |
296 | | #ifdef USE_SSH |
297 | | #define CURL_TRC_SSH Curl_trc_ssh |
298 | | #endif |
299 | | #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) |
300 | | #define CURL_TRC_WS Curl_trc_ws |
301 | | #endif |
302 | | |
303 | | #endif /* CURL_HAVE_MACRO_VARARG */ |
304 | | |
305 | | #ifdef CURLVERBOSE |
306 | | extern struct curl_trc_feat Curl_trc_feat_multi; |
307 | | extern struct curl_trc_feat Curl_trc_feat_read; |
308 | | extern struct curl_trc_feat Curl_trc_feat_write; |
309 | | extern struct curl_trc_feat Curl_trc_feat_dns; |
310 | | #ifndef CURL_DISABLE_DOH |
311 | | extern struct curl_trc_feat Curl_trc_feat_doh; |
312 | | #endif |
313 | | extern struct curl_trc_feat Curl_trc_feat_timer; |
314 | | #ifdef USE_THREADS |
315 | | extern struct curl_trc_feat Curl_trc_feat_threads; |
316 | | #endif |
317 | | #endif |
318 | | |
319 | | #ifndef CURL_DISABLE_VERBOSE_STRINGS |
320 | | /* informational messages enabled */ |
321 | | #define Curl_trc_is_verbose(data) \ |
322 | 4.48M | ((data) && (data)->set.verbose && \ |
323 | 4.48M | (!(data)->state.feat || \ |
324 | 0 | ((data)->state.feat->log_level >= CURL_LOG_LVL_INFO))) |
325 | | #define Curl_trc_cf_is_verbose(cf, data) \ |
326 | 872k | (Curl_trc_is_verbose(data) && \ |
327 | 872k | (cf) && (cf)->cft->log_level >= CURL_LOG_LVL_INFO) |
328 | | #define Curl_trc_ft_is_verbose(data, ft) \ |
329 | 1.27M | (Curl_trc_is_verbose(data) && \ |
330 | 1.27M | (ft)->log_level >= CURL_LOG_LVL_INFO) |
331 | | #define CURL_MSTATE_NAME(s) Curl_trc_mstate_name((int)(s)) |
332 | | #define CURL_TRC_EASY_TIMERS(data) \ |
333 | 0 | do { \ |
334 | 0 | if(CURL_TRC_TIMER_is_verbose(data)) \ |
335 | 0 | Curl_trc_easy_timers(data); \ |
336 | 0 | } while(0) |
337 | | |
338 | | #else /* CURL_DISABLE_VERBOSE_STRINGS */ |
339 | | /* All informational messages are not compiled in for size savings */ |
340 | | #define Curl_trc_is_verbose(d) FALSE |
341 | | #define Curl_trc_cf_is_verbose(x, y) FALSE |
342 | | #define Curl_trc_ft_is_verbose(x, y) FALSE |
343 | | #define CURL_MSTATE_NAME(x) ((void)(x), "-") |
344 | | #define CURL_TRC_EASY_TIMERS(x) Curl_nop_stmt |
345 | | #endif /* !CURL_DISABLE_VERBOSE_STRINGS */ |
346 | | |
347 | | #endif /* HEADER_CURL_TRC_H */ |