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, <[email protected]>, 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 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 #define failf Curl_failf
64
65 #define CURL_LOG_LVL_NONE 0
66 #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 #ifdef CURL_HAVE_C99
74 #define infof(data, ...) \
75 do { if(Curl_trc_is_verbose(data)) \
76 Curl_infof(data, __VA_ARGS__); } while(0)
77 #define CURL_TRC_CF(data, cf, ...) \
78 do { if(Curl_trc_cf_is_verbose(cf, data)) \
79 Curl_trc_cf_infof(data, cf, __VA_ARGS__); } while(0)
80 #define CURL_TRC_WRITE(data, ...) \
81 do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_write)) \
82 Curl_trc_write(data, __VA_ARGS__); } while(0)
83 #define CURL_TRC_READ(data, ...) \
84 do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_read)) \
85 Curl_trc_read(data, __VA_ARGS__); } while(0)
86
87 #ifndef CURL_DISABLE_FTP
88 #define CURL_TRC_FTP(data, ...) \
89 do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ftp)) \
90 Curl_trc_ftp(data, __VA_ARGS__); } while(0)
91 #endif /* !CURL_DISABLE_FTP */
92 #ifndef CURL_DISABLE_SMTP
93 #define CURL_TRC_SMTP(data, ...) \
94 do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_smtp)) \
95 Curl_trc_smtp(data, __VA_ARGS__); } while(0)
96 #endif /* !CURL_DISABLE_SMTP */
97 #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP)
98 #define CURL_TRC_WS(data, ...) \
99 do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ws)) \
100 Curl_trc_ws(data, __VA_ARGS__); } while(0)
101 #endif /* !CURL_DISABLE_WEBSOCKETS && !CURL_DISABLE_HTTP */
102
103 #else /* CURL_HAVE_C99 */
104
105 #define infof Curl_infof
106 #define CURL_TRC_CF Curl_trc_cf_infof
107 #define CURL_TRC_WRITE Curl_trc_write
108 #define CURL_TRC_READ Curl_trc_read
109
110 #ifndef CURL_DISABLE_FTP
111 #define CURL_TRC_FTP Curl_trc_ftp
112 #endif
113 #ifndef CURL_DISABLE_SMTP
114 #define CURL_TRC_SMTP Curl_trc_smtp
115 #endif
116 #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP)
117 #define CURL_TRC_WS Curl_trc_ws
118 #endif
119
120 #endif /* !CURL_HAVE_C99 */
121
122 #ifndef CURL_DISABLE_VERBOSE_STRINGS
123 /* informational messages enabled */
124
125 struct curl_trc_feat {
126 const char *name;
127 int log_level;
128 };
129 extern struct curl_trc_feat Curl_trc_feat_read;
130 extern struct curl_trc_feat Curl_trc_feat_write;
131
132 #define Curl_trc_is_verbose(data) \
133 ((data) && (data)->set.verbose && \
134 (!(data)->state.feat || \
135 ((data)->state.feat->log_level >= CURL_LOG_LVL_INFO)))
136 #define Curl_trc_cf_is_verbose(cf, data) \
137 (Curl_trc_is_verbose(data) && \
138 (cf) && (cf)->cft->log_level >= CURL_LOG_LVL_INFO)
139 #define Curl_trc_ft_is_verbose(data, ft) \
140 (Curl_trc_is_verbose(data) && \
141 (ft)->log_level >= CURL_LOG_LVL_INFO)
142
143 /**
144 * Output an informational message when transfer's verbose logging is enabled.
145 */
146 void Curl_infof(struct Curl_easy *data,
147 const char *fmt, ...) CURL_PRINTF(2, 3);
148
149 /**
150 * Output an informational message when both transfer's verbose logging
151 * and connection filters verbose logging are enabled.
152 */
153 void Curl_trc_cf_infof(struct Curl_easy *data, struct Curl_cfilter *cf,
154 const char *fmt, ...) CURL_PRINTF(3, 4);
155 void Curl_trc_write(struct Curl_easy *data,
156 const char *fmt, ...) CURL_PRINTF(2, 3);
157 void Curl_trc_read(struct Curl_easy *data,
158 const char *fmt, ...) CURL_PRINTF(2, 3);
159
160 #ifndef CURL_DISABLE_FTP
161 extern struct curl_trc_feat Curl_trc_feat_ftp;
162 void Curl_trc_ftp(struct Curl_easy *data,
163 const char *fmt, ...) CURL_PRINTF(2, 3);
164 #endif
165 #ifndef CURL_DISABLE_SMTP
166 extern struct curl_trc_feat Curl_trc_feat_smtp;
167 void Curl_trc_smtp(struct Curl_easy *data,
168 const char *fmt, ...) CURL_PRINTF(2, 3);
169 #endif
170 #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP)
171 extern struct curl_trc_feat Curl_trc_feat_ws;
172 void Curl_trc_ws(struct Curl_easy *data,
173 const char *fmt, ...) CURL_PRINTF(2, 3);
174 #endif
175
176
177 #else /* defined(CURL_DISABLE_VERBOSE_STRINGS) */
178 /* All informational messages are not compiled in for size savings */
179
180 #define Curl_trc_is_verbose(d) (FALSE)
181 #define Curl_trc_cf_is_verbose(x,y) (FALSE)
182 #define Curl_trc_ft_is_verbose(x,y) (FALSE)
183
Curl_infof(struct Curl_easy * data,const char * fmt,...)184 static void Curl_infof(struct Curl_easy *data, const char *fmt, ...)
185 {
186 (void)data; (void)fmt;
187 }
188
Curl_trc_cf_infof(struct Curl_easy * data,struct Curl_cfilter * cf,const char * fmt,...)189 static void Curl_trc_cf_infof(struct Curl_easy *data,
190 struct Curl_cfilter *cf,
191 const char *fmt, ...)
192 {
193 (void)data; (void)cf; (void)fmt;
194 }
195
196 struct curl_trc_feat;
197
Curl_trc_write(struct Curl_easy * data,const char * fmt,...)198 static void Curl_trc_write(struct Curl_easy *data, const char *fmt, ...)
199 {
200 (void)data; (void)fmt;
201 }
202
Curl_trc_read(struct Curl_easy * data,const char * fmt,...)203 static void Curl_trc_read(struct Curl_easy *data, const char *fmt, ...)
204 {
205 (void)data; (void)fmt;
206 }
207
208 #ifndef CURL_DISABLE_FTP
Curl_trc_ftp(struct Curl_easy * data,const char * fmt,...)209 static void Curl_trc_ftp(struct Curl_easy *data, const char *fmt, ...)
210 {
211 (void)data; (void)fmt;
212 }
213 #endif
214 #ifndef CURL_DISABLE_SMTP
Curl_trc_smtp(struct Curl_easy * data,const char * fmt,...)215 static void Curl_trc_smtp(struct Curl_easy *data, const char *fmt, ...)
216 {
217 (void)data; (void)fmt;
218 }
219 #endif
220 #if !defined(CURL_DISABLE_WEBSOCKETS) || !defined(CURL_DISABLE_HTTP)
Curl_trc_ws(struct Curl_easy * data,const char * fmt,...)221 static void Curl_trc_ws(struct Curl_easy *data, const char *fmt, ...)
222 {
223 (void)data; (void)fmt;
224 }
225 #endif
226
227 #endif /* !defined(CURL_DISABLE_VERBOSE_STRINGS) */
228
229 #endif /* HEADER_CURL_TRC_H */
230