curl_trc.h 7.3 KB

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