curl_trc.h 8.4 KB

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