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 | | |
27 | | struct Curl_easy; |
28 | | struct Curl_cfilter; |
29 | | |
30 | | /** |
31 | | * Init logging, return != 0 on failure. |
32 | | */ |
33 | | CURLcode Curl_trc_init(void); |
34 | | |
35 | | /** |
36 | | * Configure tracing. May be called several times during global |
37 | | * initialization. Later calls may not take effect. |
38 | | * |
39 | | * Configuration format supported: |
40 | | * - comma-separated list of component names to enable logging on. |
41 | | * E.g. 'http/2,ssl'. Unknown names are ignored. Names are compared |
42 | | * case-insensitive. |
43 | | * - component 'all' applies to all known log components |
44 | | * - prefixing a component with '+' or '-' will en-/disable logging for |
45 | | * that component |
46 | | * Example: 'all,-ssl' would enable logging for all components but the |
47 | | * SSL filters. |
48 | | * |
49 | | * @param config configuration string |
50 | | */ |
51 | | CURLcode Curl_trc_opt(const char *config); |
52 | | |
53 | | /* the function used to output verbose information */ |
54 | | void Curl_debug(struct Curl_easy *data, curl_infotype type, |
55 | | const char *ptr, size_t size); |
56 | | |
57 | | /** |
58 | | * Output a failure message on registered callbacks for transfer. |
59 | | */ |
60 | | void Curl_failf(struct Curl_easy *data, |
61 | | const char *fmt, ...) CURL_PRINTF(2, 3); |
62 | | |
63 | 814 | #define failf Curl_failf |
64 | | |
65 | 0 | #define CURL_LOG_LVL_NONE 0 |
66 | 0 | #define CURL_LOG_LVL_INFO 1 |
67 | | |
68 | | |
69 | | #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L |
70 | | #define CURL_HAVE_C99 |
71 | | #endif |
72 | | |
73 | | /** |
74 | | * Output an informational message when transfer's verbose logging is enabled. |
75 | | */ |
76 | | void Curl_infof(struct Curl_easy *data, |
77 | | const char *fmt, ...) CURL_PRINTF(2, 3); |
78 | | |
79 | | /** |
80 | | * Output an informational message when both transfer's verbose logging |
81 | | * and connection filters verbose logging are enabled. |
82 | | */ |
83 | | void Curl_trc_cf_infof(struct Curl_easy *data, const struct Curl_cfilter *cf, |
84 | | const char *fmt, ...) CURL_PRINTF(3, 4); |
85 | | void Curl_trc_multi(struct Curl_easy *data, |
86 | | const char *fmt, ...) CURL_PRINTF(2, 3); |
87 | | const char *Curl_trc_mstate_name(int state); |
88 | | const char *Curl_trc_timer_name(int tid); |
89 | | void Curl_trc_easy_timers(struct Curl_easy *data); |
90 | | |
91 | | void Curl_trc_write(struct Curl_easy *data, |
92 | | const char *fmt, ...) CURL_PRINTF(2, 3); |
93 | | void Curl_trc_read(struct Curl_easy *data, |
94 | | const char *fmt, ...) CURL_PRINTF(2, 3); |
95 | | void Curl_trc_dns(struct Curl_easy *data, |
96 | | const char *fmt, ...) CURL_PRINTF(2, 3); |
97 | | void Curl_trc_timer(struct Curl_easy *data, int tid, |
98 | | const char *fmt, ...) CURL_PRINTF(3, 4); |
99 | | |
100 | | struct curl_trc_feat { |
101 | | const char *name; |
102 | | int log_level; |
103 | | }; |
104 | | |
105 | | #ifndef CURL_DISABLE_FTP |
106 | | extern struct curl_trc_feat Curl_trc_feat_ftp; |
107 | | void Curl_trc_ftp(struct Curl_easy *data, |
108 | | const char *fmt, ...) CURL_PRINTF(2, 3); |
109 | | #endif |
110 | | #ifndef CURL_DISABLE_SMTP |
111 | | extern struct curl_trc_feat Curl_trc_feat_smtp; |
112 | | void Curl_trc_smtp(struct Curl_easy *data, |
113 | | const char *fmt, ...) CURL_PRINTF(2, 3); |
114 | | #endif |
115 | | #ifdef USE_SSL |
116 | | extern struct curl_trc_feat Curl_trc_feat_ssls; |
117 | | void Curl_trc_ssls(struct Curl_easy *data, |
118 | | const char *fmt, ...) CURL_PRINTF(2, 3); |
119 | | #endif |
120 | | #ifdef USE_SSH |
121 | | extern struct curl_trc_feat Curl_trc_feat_ssh; |
122 | | void Curl_trc_ssh(struct Curl_easy *data, |
123 | | const char *fmt, ...) CURL_PRINTF(2, 3); |
124 | | #endif |
125 | | #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) |
126 | | extern struct curl_trc_feat Curl_trc_feat_ws; |
127 | | void Curl_trc_ws(struct Curl_easy *data, |
128 | | const char *fmt, ...) CURL_PRINTF(2, 3); |
129 | | #endif |
130 | | |
131 | | #define CURL_TRC_M_is_verbose(data) \ |
132 | 0 | Curl_trc_ft_is_verbose(data, &Curl_trc_feat_multi) |
133 | | #define CURL_TRC_DNS_is_verbose(data) \ |
134 | 0 | Curl_trc_ft_is_verbose(data, &Curl_trc_feat_dns) |
135 | | #define CURL_TRC_TIMER_is_verbose(data) \ |
136 | 0 | Curl_trc_ft_is_verbose(data, &Curl_trc_feat_timer) |
137 | | |
138 | | #if defined(CURL_HAVE_C99) && !defined(CURL_DISABLE_VERBOSE_STRINGS) |
139 | | #define infof(data, ...) \ |
140 | 421 | do { if(Curl_trc_is_verbose(data)) \ |
141 | 421 | Curl_infof(data, __VA_ARGS__); } while(0) |
142 | | #define CURL_TRC_M(data, ...) \ |
143 | 0 | do { if(CURL_TRC_M_is_verbose(data)) \ |
144 | 0 | Curl_trc_multi(data, __VA_ARGS__); } while(0) |
145 | | #define CURL_TRC_CF(data, cf, ...) \ |
146 | 0 | do { if(Curl_trc_cf_is_verbose(cf, data)) \ |
147 | 0 | Curl_trc_cf_infof(data, cf, __VA_ARGS__); } while(0) |
148 | | #define CURL_TRC_WRITE(data, ...) \ |
149 | 0 | do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_write)) \ |
150 | 0 | Curl_trc_write(data, __VA_ARGS__); } while(0) |
151 | | #define CURL_TRC_READ(data, ...) \ |
152 | 0 | do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_read)) \ |
153 | 0 | Curl_trc_read(data, __VA_ARGS__); } while(0) |
154 | | #define CURL_TRC_DNS(data, ...) \ |
155 | 0 | do { if(CURL_TRC_DNS_is_verbose(data)) \ |
156 | 0 | Curl_trc_dns(data, __VA_ARGS__); } while(0) |
157 | | #define CURL_TRC_TIMER(data, tid, ...) \ |
158 | 0 | do { if(CURL_TRC_TIMER_is_verbose(data)) \ |
159 | 0 | Curl_trc_timer(data, tid, __VA_ARGS__); } while(0) |
160 | | |
161 | | #ifndef CURL_DISABLE_FTP |
162 | | #define CURL_TRC_FTP(data, ...) \ |
163 | 0 | do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ftp)) \ |
164 | 0 | Curl_trc_ftp(data, __VA_ARGS__); } while(0) |
165 | | #endif /* !CURL_DISABLE_FTP */ |
166 | | #ifndef CURL_DISABLE_SMTP |
167 | | #define CURL_TRC_SMTP(data, ...) \ |
168 | 0 | do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_smtp)) \ |
169 | 0 | Curl_trc_smtp(data, __VA_ARGS__); } while(0) |
170 | | #endif /* !CURL_DISABLE_SMTP */ |
171 | | #ifdef USE_SSL |
172 | | #define CURL_TRC_SSLS(data, ...) \ |
173 | 0 | do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ssls)) \ |
174 | 0 | Curl_trc_ssls(data, __VA_ARGS__); } while(0) |
175 | | #endif /* USE_SSL */ |
176 | | #ifdef USE_SSH |
177 | | #define CURL_TRC_SSH(data, ...) \ |
178 | | do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ssh)) \ |
179 | | Curl_trc_ssh(data, __VA_ARGS__); } while(0) |
180 | | #endif /* USE_SSH */ |
181 | | #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) |
182 | | #define CURL_TRC_WS(data, ...) \ |
183 | 0 | do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ws)) \ |
184 | 0 | Curl_trc_ws(data, __VA_ARGS__); } while(0) |
185 | | #endif /* !CURL_DISABLE_WEBSOCKETS && !CURL_DISABLE_HTTP */ |
186 | | |
187 | | #else /* CURL_HAVE_C99 */ |
188 | | |
189 | | #define infof Curl_infof |
190 | | #define CURL_TRC_M Curl_trc_multi |
191 | | #define CURL_TRC_CF Curl_trc_cf_infof |
192 | | #define CURL_TRC_WRITE Curl_trc_write |
193 | | #define CURL_TRC_READ Curl_trc_read |
194 | | #define CURL_TRC_DNS Curl_trc_dns |
195 | | #define CURL_TRC_TIMER Curl_trc_timer |
196 | | |
197 | | #ifndef CURL_DISABLE_FTP |
198 | | #define CURL_TRC_FTP Curl_trc_ftp |
199 | | #endif |
200 | | #ifndef CURL_DISABLE_SMTP |
201 | | #define CURL_TRC_SMTP Curl_trc_smtp |
202 | | #endif |
203 | | #ifdef USE_SSL |
204 | | #define CURL_TRC_SSLS Curl_trc_ssls |
205 | | #endif |
206 | | #ifdef USE_SSH |
207 | | #define CURL_TRC_SSH Curl_trc_ssh |
208 | | #endif |
209 | | #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) |
210 | | #define CURL_TRC_WS Curl_trc_ws |
211 | | #endif |
212 | | |
213 | | #endif /* !CURL_HAVE_C99 */ |
214 | | |
215 | | #ifndef CURL_DISABLE_VERBOSE_STRINGS |
216 | | /* informational messages enabled */ |
217 | | |
218 | | extern struct curl_trc_feat Curl_trc_feat_multi; |
219 | | extern struct curl_trc_feat Curl_trc_feat_read; |
220 | | extern struct curl_trc_feat Curl_trc_feat_write; |
221 | | extern struct curl_trc_feat Curl_trc_feat_dns; |
222 | | extern struct curl_trc_feat Curl_trc_feat_timer; |
223 | | |
224 | | #define Curl_trc_is_verbose(data) \ |
225 | 421 | ((data) && (data)->set.verbose && \ |
226 | 421 | (!(data)->state.feat || \ |
227 | 0 | ((data)->state.feat->log_level >= CURL_LOG_LVL_INFO))) |
228 | | #define Curl_trc_cf_is_verbose(cf, data) \ |
229 | 0 | (Curl_trc_is_verbose(data) && \ |
230 | 0 | (cf) && (cf)->cft->log_level >= CURL_LOG_LVL_INFO) |
231 | | #define Curl_trc_ft_is_verbose(data, ft) \ |
232 | 0 | (Curl_trc_is_verbose(data) && \ |
233 | 0 | (ft)->log_level >= CURL_LOG_LVL_INFO) |
234 | | #define CURL_MSTATE_NAME(s) Curl_trc_mstate_name((int)(s)) |
235 | | #define CURL_TRC_EASY_TIMERS(data) \ |
236 | 0 | do { if(CURL_TRC_TIMER_is_verbose(data)) \ |
237 | 0 | Curl_trc_easy_timers(data); } while(0) |
238 | | |
239 | | #else /* CURL_DISABLE_VERBOSE_STRINGS */ |
240 | | /* All informational messages are not compiled in for size savings */ |
241 | | |
242 | | #define Curl_trc_is_verbose(d) (FALSE) |
243 | | #define Curl_trc_cf_is_verbose(x, y) (FALSE) |
244 | | #define Curl_trc_ft_is_verbose(x, y) (FALSE) |
245 | | #define CURL_MSTATE_NAME(x) ((void)(x), "-") |
246 | | #define CURL_TRC_EASY_TIMERS(x) Curl_nop_stmt |
247 | | |
248 | | #endif /* !CURL_DISABLE_VERBOSE_STRINGS */ |
249 | | |
250 | | #endif /* HEADER_CURL_TRC_H */ |