curl_trc.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 an informational message when transfer's verbose logging is enabled.
  54. */
  55. void Curl_infof(struct Curl_easy *data,
  56. #if defined(__GNUC__) && !defined(printf) && \
  57. defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
  58. !defined(__MINGW32__)
  59. const char *fmt, ...)
  60. __attribute__((format(printf, 2, 3)));
  61. #else
  62. const char *fmt, ...);
  63. #endif
  64. /**
  65. * Output a failure message on registered callbacks for transfer.
  66. */
  67. void Curl_failf(struct Curl_easy *data,
  68. #if defined(__GNUC__) && !defined(printf) && \
  69. defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
  70. !defined(__MINGW32__)
  71. const char *fmt, ...)
  72. __attribute__((format(printf, 2, 3)));
  73. #else
  74. const char *fmt, ...);
  75. #endif
  76. #define failf Curl_failf
  77. /**
  78. * Output an informational message when both transfer's verbose logging
  79. * and connection filters verbose logging are enabled.
  80. */
  81. void Curl_trc_cf_infof(struct Curl_easy *data, struct Curl_cfilter *cf,
  82. #if defined(__GNUC__) && !defined(printf) && \
  83. defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
  84. !defined(__MINGW32__)
  85. const char *fmt, ...)
  86. __attribute__((format(printf, 3, 4)));
  87. #else
  88. const char *fmt, ...);
  89. #endif
  90. #define CURL_LOG_LVL_NONE 0
  91. #define CURL_LOG_LVL_INFO 1
  92. #if !defined(CURL_DISABLE_VERBOSE_STRINGS)
  93. /* informational messages enabled */
  94. #define Curl_trc_is_verbose(data) ((data) && (data)->set.verbose)
  95. #define Curl_trc_cf_is_verbose(cf, data) \
  96. ((data) && (data)->set.verbose && \
  97. (cf) && (cf)->cft->log_level >= CURL_LOG_LVL_INFO)
  98. /* explainer: we have some mix configuration and werror settings
  99. * that define HAVE_VARIADIC_MACROS_C99 even though C89 is enforced
  100. * on gnuc and some other compiler. Need to treat carefully.
  101. */
  102. #if defined(HAVE_VARIADIC_MACROS_C99) && \
  103. defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
  104. #define infof(data, ...) \
  105. do { if(Curl_trc_is_verbose(data)) \
  106. Curl_infof(data, __VA_ARGS__); } while(0)
  107. #define CURL_TRC_CF(data, cf, ...) \
  108. do { if(Curl_trc_cf_is_verbose(cf, data)) \
  109. Curl_trc_cf_infof(data, cf, __VA_ARGS__); } while(0)
  110. #else /* no variadic macro args */
  111. #define infof Curl_infof
  112. #define CURL_TRC_CF Curl_trc_cf_infof
  113. #endif /* variadic macro args */
  114. #else /* !CURL_DISABLE_VERBOSE_STRINGS */
  115. /* All informational messages are not compiled in for size savings */
  116. #define Curl_trc_is_verbose(d) ((void)(d), FALSE)
  117. #define Curl_trc_cf_is_verbose(x,y) ((void)(x), (void)(y), FALSE)
  118. #if defined(HAVE_VARIADIC_MACROS_C99)
  119. #define infof(...) Curl_nop_stmt
  120. #define CURL_TRC_CF(...) Curl_nop_stmt
  121. #define Curl_trc_cf_infof(...) Curl_nop_stmt
  122. #elif defined(HAVE_VARIADIC_MACROS_GCC)
  123. #define infof(x...) Curl_nop_stmt
  124. #define CURL_TRC_CF(x...) Curl_nop_stmt
  125. #define Curl_trc_cf_infof(x...) Curl_nop_stmt
  126. #else
  127. #error "missing VARIADIC macro define, fix and rebuild!"
  128. #endif
  129. #endif /* CURL_DISABLE_VERBOSE_STRINGS */
  130. #endif /* HEADER_CURL_TRC_H */