ssl_dbg.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef _SSL_DEBUG_H_
  14. #define _SSL_DEBUG_H_
  15. #include "platform/ssl_opt.h"
  16. #include "platform/ssl_port.h"
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #ifndef SSL_DEBUG_ENBALE
  21. #define SSL_DEBUG_ENBALE 0
  22. #endif
  23. #ifndef SSL_DEBUG_LEVEL
  24. #define SSL_DEBUG_LEVEL 0
  25. #endif
  26. #ifndef SSL_ASSERT_ENABLE
  27. #define SSL_ASSERT_ENABLE 0
  28. #endif
  29. #ifndef SSL_DEBUG_LOCATION_ENABLE
  30. #define SSL_DEBUG_LOCATION_ENABLE 0
  31. #endif
  32. #if SSL_DEBUG_ENBALE
  33. #if !defined(SSL_PRINT_LOG) || !defined(SSL_ERROR_LOG) || !defined(SSL_LOCAL_LOG)
  34. #include "stdio.h"
  35. extern int printf(const char *fmt, ...);
  36. #ifndef SSL_PRINT_LOG
  37. #define SSL_PRINT_LOG printf
  38. #endif
  39. #ifndef SSL_ERROR_LOG
  40. #define SSL_ERROR_LOG printf
  41. #endif
  42. #ifndef SSL_LOCAL_LOG
  43. #define SSL_LOCAL_LOG printf
  44. #endif
  45. #endif
  46. #else
  47. #ifdef SSL_PRINT_LOG
  48. #undef SSL_PRINT_LOG
  49. #endif
  50. #define SSL_PRINT_LOG(...)
  51. #ifdef SSL_ERROR_LOG
  52. #undef SSL_ERROR_LOG
  53. #endif
  54. #define SSL_ERROR_LOG(...)
  55. #ifdef SSL_LOCAL_LOG
  56. #undef SSL_LOCAL_LOG
  57. #endif
  58. #define SSL_LOCAL_LOG(...)
  59. #endif
  60. #if SSL_DEBUG_LOCATION_ENABLE
  61. #define SSL_DEBUG_LOCATION() SSL_LOCAL_LOG("%s %s line %d\n", __FILE__, __FUNCTION__, __LINE__)
  62. #else
  63. #define SSL_DEBUG_LOCATION()
  64. #endif
  65. #if SSL_ASSERT_ENABLE
  66. #define SSL_ASSERT(s) { if (!(s)) { SSL_DEBUG_LOCATION(); } }
  67. #else
  68. #define SSL_ASSERT(s)
  69. #endif
  70. #define SSL_ERR(err, go, fmt, ...) { SSL_DEBUG_LOCATION(); SSL_ERROR_LOG(fmt, ##__VA_ARGS__); ret = err; goto go; }
  71. #define SSL_RET(go, fmt, ...) { SSL_DEBUG_LOCATION(); SSL_ERROR_LOG(fmt, ##__VA_ARGS__); goto go; }
  72. #define SSL_DEBUG(level, fmt, ...) { if (level > SSL_DEBUG_LEVEL) {SSL_PRINT_LOG(fmt, ##__VA_ARGS__);} }
  73. #ifdef __cplusplus
  74. }
  75. #endif
  76. #endif