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