curl_trc.h (7745B)
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 #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 /** 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 void Curl_trc_write(struct Curl_easy *data, 89 const char *fmt, ...) CURL_PRINTF(2, 3); 90 void Curl_trc_read(struct Curl_easy *data, 91 const char *fmt, ...) CURL_PRINTF(2, 3); 92 void Curl_trc_dns(struct Curl_easy *data, 93 const char *fmt, ...) CURL_PRINTF(2, 3); 94 95 #ifndef CURL_DISABLE_FTP 96 extern struct curl_trc_feat Curl_trc_feat_ftp; 97 void Curl_trc_ftp(struct Curl_easy *data, 98 const char *fmt, ...) CURL_PRINTF(2, 3); 99 #endif 100 #ifndef CURL_DISABLE_SMTP 101 extern struct curl_trc_feat Curl_trc_feat_smtp; 102 void Curl_trc_smtp(struct Curl_easy *data, 103 const char *fmt, ...) CURL_PRINTF(2, 3); 104 #endif 105 #ifdef USE_SSL 106 extern struct curl_trc_feat Curl_trc_feat_ssls; 107 void Curl_trc_ssls(struct Curl_easy *data, 108 const char *fmt, ...) CURL_PRINTF(2, 3); 109 #endif 110 #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) 111 extern struct curl_trc_feat Curl_trc_feat_ws; 112 void Curl_trc_ws(struct Curl_easy *data, 113 const char *fmt, ...) CURL_PRINTF(2, 3); 114 #endif 115 116 #if defined(CURL_HAVE_C99) && !defined(CURL_DISABLE_VERBOSE_STRINGS) 117 #define infof(data, ...) \ 118 do { if(Curl_trc_is_verbose(data)) \ 119 Curl_infof(data, __VA_ARGS__); } while(0) 120 #define CURL_TRC_M(data, ...) \ 121 do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_multi)) \ 122 Curl_trc_multi(data, __VA_ARGS__); } while(0) 123 #define CURL_TRC_CF(data, cf, ...) \ 124 do { if(Curl_trc_cf_is_verbose(cf, data)) \ 125 Curl_trc_cf_infof(data, cf, __VA_ARGS__); } while(0) 126 #define CURL_TRC_WRITE(data, ...) \ 127 do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_write)) \ 128 Curl_trc_write(data, __VA_ARGS__); } while(0) 129 #define CURL_TRC_READ(data, ...) \ 130 do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_read)) \ 131 Curl_trc_read(data, __VA_ARGS__); } while(0) 132 #define CURL_TRC_DNS(data, ...) \ 133 do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_dns)) \ 134 Curl_trc_dns(data, __VA_ARGS__); } while(0) 135 136 #ifndef CURL_DISABLE_FTP 137 #define CURL_TRC_FTP(data, ...) \ 138 do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ftp)) \ 139 Curl_trc_ftp(data, __VA_ARGS__); } while(0) 140 #endif /* !CURL_DISABLE_FTP */ 141 #ifndef CURL_DISABLE_SMTP 142 #define CURL_TRC_SMTP(data, ...) \ 143 do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_smtp)) \ 144 Curl_trc_smtp(data, __VA_ARGS__); } while(0) 145 #endif /* !CURL_DISABLE_SMTP */ 146 #ifdef USE_SSL 147 #define CURL_TRC_SSLS(data, ...) \ 148 do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ssls)) \ 149 Curl_trc_ssls(data, __VA_ARGS__); } while(0) 150 #endif /* USE_SSL */ 151 #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) 152 #define CURL_TRC_WS(data, ...) \ 153 do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ws)) \ 154 Curl_trc_ws(data, __VA_ARGS__); } while(0) 155 #endif /* !CURL_DISABLE_WEBSOCKETS && !CURL_DISABLE_HTTP */ 156 157 #else /* CURL_HAVE_C99 */ 158 159 #define infof Curl_infof 160 #define CURL_TRC_M Curl_trc_multi 161 #define CURL_TRC_CF Curl_trc_cf_infof 162 #define CURL_TRC_WRITE Curl_trc_write 163 #define CURL_TRC_READ Curl_trc_read 164 #define CURL_TRC_DNS Curl_trc_dns 165 166 #ifndef CURL_DISABLE_FTP 167 #define CURL_TRC_FTP Curl_trc_ftp 168 #endif 169 #ifndef CURL_DISABLE_SMTP 170 #define CURL_TRC_SMTP Curl_trc_smtp 171 #endif 172 #ifdef USE_SSL 173 #define CURL_TRC_SSLS Curl_trc_ssls 174 #endif 175 #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) 176 #define CURL_TRC_WS Curl_trc_ws 177 #endif 178 179 #endif /* !CURL_HAVE_C99 */ 180 181 struct curl_trc_feat { 182 const char *name; 183 int log_level; 184 }; 185 186 #ifndef CURL_DISABLE_VERBOSE_STRINGS 187 /* informational messages enabled */ 188 189 extern struct curl_trc_feat Curl_trc_feat_multi; 190 extern struct curl_trc_feat Curl_trc_feat_read; 191 extern struct curl_trc_feat Curl_trc_feat_write; 192 extern struct curl_trc_feat Curl_trc_feat_dns; 193 194 #define Curl_trc_is_verbose(data) \ 195 ((data) && (data)->set.verbose && \ 196 (!(data)->state.feat || \ 197 ((data)->state.feat->log_level >= CURL_LOG_LVL_INFO))) 198 #define Curl_trc_cf_is_verbose(cf, data) \ 199 (Curl_trc_is_verbose(data) && \ 200 (cf) && (cf)->cft->log_level >= CURL_LOG_LVL_INFO) 201 #define Curl_trc_ft_is_verbose(data, ft) \ 202 (Curl_trc_is_verbose(data) && \ 203 (ft)->log_level >= CURL_LOG_LVL_INFO) 204 #define CURL_MSTATE_NAME(s) Curl_trc_mstate_name((int)(s)) 205 206 #else /* defined(CURL_DISABLE_VERBOSE_STRINGS) */ 207 /* All informational messages are not compiled in for size savings */ 208 209 #define Curl_trc_is_verbose(d) (FALSE) 210 #define Curl_trc_cf_is_verbose(x,y) (FALSE) 211 #define Curl_trc_ft_is_verbose(x,y) (FALSE) 212 #define CURL_MSTATE_NAME(x) ((void)(x), "-") 213 214 #endif /* !defined(CURL_DISABLE_VERBOSE_STRINGS) */ 215 216 #endif /* HEADER_CURL_TRC_H */