logging.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* logging.h
  2. *
  3. * Copyright (C) 2006-2017 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. /* submitted by eof */
  22. #ifndef WOLFSSL_LOGGING_H
  23. #define WOLFSSL_LOGGING_H
  24. #include <wolfssl/wolfcrypt/types.h>
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. enum wc_LogLevels {
  29. ERROR_LOG = 0,
  30. INFO_LOG,
  31. ENTER_LOG,
  32. LEAVE_LOG,
  33. OTHER_LOG
  34. };
  35. typedef void (*wolfSSL_Logging_cb)(const int logLevel,
  36. const char *const logMessage);
  37. WOLFSSL_API int wolfSSL_SetLoggingCb(wolfSSL_Logging_cb log_function);
  38. /* turn logging on, only if compiled in */
  39. WOLFSSL_API int wolfSSL_Debugging_ON(void);
  40. /* turn logging off */
  41. WOLFSSL_API void wolfSSL_Debugging_OFF(void);
  42. #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
  43. WOLFSSL_LOCAL int wc_LoggingInit(void);
  44. WOLFSSL_LOCAL int wc_LoggingCleanup(void);
  45. WOLFSSL_LOCAL int wc_AddErrorNode(int error, int line, char* buf,
  46. char* file);
  47. WOLFSSL_LOCAL int wc_PeekErrorNode(int index, const char **file,
  48. const char **reason, int *line);
  49. WOLFSSL_LOCAL void wc_RemoveErrorNode(int index);
  50. WOLFSSL_LOCAL void wc_ClearErrorNodes(void);
  51. WOLFSSL_LOCAL int wc_PullErrorNode(const char **file, const char **reason,
  52. int *line);
  53. WOLFSSL_API int wc_SetLoggingHeap(void* h);
  54. WOLFSSL_API int wc_ERR_remove_state(void);
  55. #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM)
  56. WOLFSSL_API void wc_ERR_print_errors_fp(FILE* fp);
  57. #endif
  58. #endif /* OPENSSL_EXTRA || DEBUG_WOLFSSL_VERBOSE */
  59. #if defined(DEBUG_WOLFSSL) && !defined(WOLFSSL_DEBUG_ERRORS_ONLY)
  60. #if defined(_WIN32)
  61. #if defined(INTIME_RTOS)
  62. #define __func__ NULL
  63. #else
  64. #define __func__ __FUNCTION__
  65. #endif
  66. #endif
  67. /* a is prepended to m and b is appended, creating a log msg a + m + b */
  68. #define WOLFSSL_LOG_CAT(a, m, b) #a " " m " " #b
  69. WOLFSSL_API void WOLFSSL_ENTER(const char* msg);
  70. WOLFSSL_API void WOLFSSL_LEAVE(const char* msg, int ret);
  71. #define WOLFSSL_STUB(m) \
  72. WOLFSSL_MSG(WOLFSSL_LOG_CAT(wolfSSL Stub, m, not implemented))
  73. WOLFSSL_API void WOLFSSL_MSG(const char* msg);
  74. WOLFSSL_API void WOLFSSL_BUFFER(const byte* buffer, word32 length);
  75. #else
  76. #define WOLFSSL_ENTER(m)
  77. #define WOLFSSL_LEAVE(m, r)
  78. #define WOLFSSL_STUB(m)
  79. #define WOLFSSL_MSG(m)
  80. #define WOLFSSL_BUFFER(b, l)
  81. #endif /* DEBUG_WOLFSSL && !WOLFSSL_DEBUG_ERRORS_ONLY */
  82. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)
  83. #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
  84. WOLFSSL_API void WOLFSSL_ERROR_LINE(int err, const char* func, unsigned int line,
  85. const char* file, void* ctx);
  86. #define WOLFSSL_ERROR(x) \
  87. WOLFSSL_ERROR_LINE((x), __func__, __LINE__, __FILE__, NULL)
  88. #else
  89. WOLFSSL_API void WOLFSSL_ERROR(int err);
  90. #endif
  91. WOLFSSL_API void WOLFSSL_ERROR_MSG(const char* msg);
  92. #else
  93. #define WOLFSSL_ERROR(e)
  94. #define WOLFSSL_ERROR_MSG(m)
  95. #endif
  96. #ifdef __cplusplus
  97. }
  98. #endif
  99. #endif /* WOLFSSL_LOGGING_H */