logging.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /* logging.h
  2. *
  3. * Copyright (C) 2006-2023 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. /*!
  22. \file wolfssl/wolfcrypt/logging.h
  23. */
  24. /* submitted by eof */
  25. #ifndef WOLFSSL_LOGGING_H
  26. #define WOLFSSL_LOGGING_H
  27. #include <wolfssl/wolfcrypt/types.h>
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. enum wc_LogLevels {
  32. ERROR_LOG = 0,
  33. INFO_LOG,
  34. ENTER_LOG,
  35. LEAVE_LOG,
  36. OTHER_LOG
  37. };
  38. #ifdef WOLFSSL_FUNC_TIME
  39. /* WARNING: This code is only to be used for debugging performance.
  40. * The code is not thread-safe.
  41. * Do not use WOLFSSL_FUNC_TIME in production code.
  42. */
  43. enum wc_FuncNum {
  44. WC_FUNC_HELLO_REQUEST_SEND = 0,
  45. WC_FUNC_HELLO_REQUEST_DO,
  46. WC_FUNC_CLIENT_HELLO_SEND,
  47. WC_FUNC_CLIENT_HELLO_DO,
  48. WC_FUNC_SERVER_HELLO_SEND,
  49. WC_FUNC_SERVER_HELLO_DO,
  50. WC_FUNC_ENCRYPTED_EXTENSIONS_SEND,
  51. WC_FUNC_ENCRYPTED_EXTENSIONS_DO,
  52. WC_FUNC_CERTIFICATE_REQUEST_SEND,
  53. WC_FUNC_CERTIFICATE_REQUEST_DO,
  54. WC_FUNC_CERTIFICATE_SEND,
  55. WC_FUNC_CERTIFICATE_DO,
  56. WC_FUNC_CERTIFICATE_VERIFY_SEND,
  57. WC_FUNC_CERTIFICATE_VERIFY_DO,
  58. WC_FUNC_FINISHED_SEND,
  59. WC_FUNC_FINISHED_DO,
  60. WC_FUNC_KEY_UPDATE_SEND,
  61. WC_FUNC_KEY_UPDATE_DO,
  62. WC_FUNC_EARLY_DATA_SEND,
  63. WC_FUNC_EARLY_DATA_DO,
  64. WC_FUNC_NEW_SESSION_TICKET_SEND,
  65. WC_FUNC_NEW_SESSION_TICKET_DO,
  66. WC_FUNC_SERVER_HELLO_DONE_SEND,
  67. WC_FUNC_SERVER_HELLO_DONE_DO,
  68. WC_FUNC_TICKET_SEND,
  69. WC_FUNC_TICKET_DO,
  70. WC_FUNC_CLIENT_KEY_EXCHANGE_SEND,
  71. WC_FUNC_CLIENT_KEY_EXCHANGE_DO,
  72. WC_FUNC_CERTIFICATE_STATUS_SEND,
  73. WC_FUNC_CERTIFICATE_STATUS_DO,
  74. WC_FUNC_SERVER_KEY_EXCHANGE_SEND,
  75. WC_FUNC_SERVER_KEY_EXCHANGE_DO,
  76. WC_FUNC_END_OF_EARLY_DATA_SEND,
  77. WC_FUNC_END_OF_EARLY_DATA_DO,
  78. WC_FUNC_COUNT
  79. };
  80. #endif
  81. typedef void (*wolfSSL_Logging_cb)(const int logLevel,
  82. const char *const logMessage);
  83. WOLFSSL_API int wolfSSL_SetLoggingCb(wolfSSL_Logging_cb log_function);
  84. WOLFSSL_API wolfSSL_Logging_cb wolfSSL_GetLoggingCb(void);
  85. /* turn logging on, only if compiled in */
  86. WOLFSSL_API int wolfSSL_Debugging_ON(void);
  87. /* turn logging off */
  88. WOLFSSL_API void wolfSSL_Debugging_OFF(void);
  89. #ifdef HAVE_WC_INTROSPECTION
  90. WOLFSSL_API const char *wolfSSL_configure_args(void);
  91. WOLFSSL_API const char *wolfSSL_global_cflags(void);
  92. #endif
  93. #if (defined(OPENSSL_EXTRA) && !defined(_WIN32) && \
  94. !defined(NO_ERROR_QUEUE)) || defined(DEBUG_WOLFSSL_VERBOSE)
  95. #define WOLFSSL_HAVE_ERROR_QUEUE
  96. #endif
  97. #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
  98. WOLFSSL_LOCAL int wc_LoggingInit(void);
  99. WOLFSSL_LOCAL int wc_LoggingCleanup(void);
  100. WOLFSSL_LOCAL int wc_AddErrorNode(int error, int line, char* buf,
  101. char* file);
  102. WOLFSSL_LOCAL int wc_PeekErrorNode(int idx, const char **file,
  103. const char **reason, int *line);
  104. WOLFSSL_LOCAL void wc_RemoveErrorNode(int idx);
  105. WOLFSSL_LOCAL void wc_ClearErrorNodes(void);
  106. WOLFSSL_LOCAL int wc_PullErrorNode(const char **file, const char **reason,
  107. int *line);
  108. WOLFSSL_API int wc_SetLoggingHeap(void* h);
  109. WOLFSSL_API int wc_ERR_remove_state(void);
  110. WOLFSSL_LOCAL unsigned long wc_PeekErrorNodeLineData(
  111. const char **file, int *line, const char **data, int *flags,
  112. int (*ignore_err)(int err));
  113. WOLFSSL_LOCAL unsigned long wc_GetErrorNodeErr(void);
  114. #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM)
  115. WOLFSSL_API void wc_ERR_print_errors_fp(XFILE fp);
  116. WOLFSSL_API void wc_ERR_print_errors_cb(int (*cb)(const char *str,
  117. size_t len, void *u), void *u);
  118. #endif
  119. #endif /* OPENSSL_EXTRA || DEBUG_WOLFSSL_VERBOSE */
  120. #ifdef WOLFSSL_FUNC_TIME
  121. /* WARNING: This code is only to be used for debugging performance.
  122. * The code is not thread-safe.
  123. * Do not use WOLFSSL_FUNC_TIME in production code.
  124. */
  125. WOLFSSL_API void WOLFSSL_START(int funcNum);
  126. WOLFSSL_API void WOLFSSL_END(int funcNum);
  127. WOLFSSL_API void WOLFSSL_TIME(int count);
  128. #else
  129. #define WOLFSSL_START(n) WC_DO_NOTHING
  130. #define WOLFSSL_END(n) WC_DO_NOTHING
  131. #define WOLFSSL_TIME(n) WC_DO_NOTHING
  132. #endif
  133. #if defined(DEBUG_WOLFSSL) && !defined(WOLFSSL_DEBUG_ERRORS_ONLY)
  134. #if defined(_WIN32)
  135. #if defined(INTIME_RTOS)
  136. #define __func__ NULL
  137. #else
  138. #define __func__ __FUNCTION__
  139. #endif
  140. #endif
  141. /* a is prepended to m and b is appended, creating a log msg a + m + b */
  142. #define WOLFSSL_LOG_CAT(a, m, b) #a " " m " " #b
  143. WOLFSSL_API void WOLFSSL_ENTER(const char* msg);
  144. WOLFSSL_API void WOLFSSL_LEAVE(const char* msg, int ret);
  145. #define WOLFSSL_STUB(m) \
  146. WOLFSSL_MSG(WOLFSSL_LOG_CAT(wolfSSL Stub, m, not implemented))
  147. WOLFSSL_API int WOLFSSL_IS_DEBUG_ON(void);
  148. #if defined(XVSNPRINTF)
  149. WOLFSSL_API void WOLFSSL_MSG_EX(const char* fmt, ...);
  150. #define HAVE_WOLFSSL_MSG_EX
  151. #else
  152. #define WOLFSSL_MSG_EX(...) WC_DO_NOTHING
  153. #endif
  154. WOLFSSL_API void WOLFSSL_MSG(const char* msg);
  155. WOLFSSL_API void WOLFSSL_BUFFER(const byte* buffer, word32 length);
  156. #else
  157. #define WOLFSSL_ENTER(m) WC_DO_NOTHING
  158. #define WOLFSSL_LEAVE(m, r) WC_DO_NOTHING
  159. #define WOLFSSL_STUB(m) WC_DO_NOTHING
  160. #define WOLFSSL_IS_DEBUG_ON() 0
  161. #define WOLFSSL_MSG_EX(...) WC_DO_NOTHING
  162. #define WOLFSSL_MSG(m) WC_DO_NOTHING
  163. #define WOLFSSL_BUFFER(b, l) WC_DO_NOTHING
  164. #endif /* DEBUG_WOLFSSL && !WOLFSSL_DEBUG_ERRORS_ONLY */
  165. #if defined(DEBUG_WOLFSSL) || defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) ||\
  166. defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA)
  167. #ifdef WOLFSSL_HAVE_ERROR_QUEUE
  168. WOLFSSL_API void WOLFSSL_ERROR_LINE(int err, const char* func, unsigned int line,
  169. const char* file, void* ctx);
  170. #define WOLFSSL_ERROR(x) \
  171. WOLFSSL_ERROR_LINE((x), __func__, __LINE__, __FILE__, NULL)
  172. #else
  173. WOLFSSL_API void WOLFSSL_ERROR(int err);
  174. #endif /* WOLFSSL_HAVE_ERROR_QUEUE */
  175. WOLFSSL_API void WOLFSSL_ERROR_MSG(const char* msg);
  176. #else
  177. #define WOLFSSL_ERROR(e) (void)(e)
  178. #define WOLFSSL_ERROR_MSG(m) (void)(m)
  179. #endif /* DEBUG_WOLFSSL | OPENSSL_ALL || WOLFSSL_NGINX || WOLFSSL_HAPROXY ||
  180. OPENSSL_EXTRA */
  181. #ifdef WOLFSSL_VERBOSE_ERRORS
  182. #define WOLFSSL_ERROR_VERBOSE(e) WOLFSSL_ERROR(e)
  183. #else
  184. #define WOLFSSL_ERROR_VERBOSE(e) (void)(e)
  185. #endif /* WOLFSSL_VERBOSE_ERRORS */
  186. #ifdef HAVE_STACK_SIZE_VERBOSE
  187. extern WOLFSSL_API THREAD_LS_T unsigned char *StackSizeCheck_myStack;
  188. extern WOLFSSL_API THREAD_LS_T size_t StackSizeCheck_stackSize;
  189. extern WOLFSSL_API THREAD_LS_T size_t StackSizeCheck_stackSizeHWM;
  190. extern WOLFSSL_API THREAD_LS_T size_t *StackSizeCheck_stackSizeHWM_ptr;
  191. extern WOLFSSL_API THREAD_LS_T void *StackSizeCheck_stackOffsetPointer;
  192. #endif
  193. #ifdef __cplusplus
  194. }
  195. #endif
  196. #endif /* WOLFSSL_LOGGING_H */