components/openssl: refacetor the SSL debug function

Add the "ssl_opt.h" file to make user able t add its platform interface
This commit is contained in:
Dong Heng 2016-11-01 14:59:50 +08:00
parent 8d1f360ca6
commit bc710e5b88
3 changed files with 20 additions and 10 deletions

View File

@ -38,10 +38,17 @@
#define SSL_DEBUG_LOCATION_ENABLE 0 #define SSL_DEBUG_LOCATION_ENABLE 0
#endif #endif
#ifndef SSL_PRINT #if SSL_DEBUG_ENBALE
#include "stdio.h" #ifndef SSL_PRINT
extern int printf(const char *fmt, ...); #include "stdio.h"
#define SSL_PRINT printf extern int printf(const char *fmt, ...);
#define SSL_PRINT printf
#endif
#else
#ifdef SSL_PRINT
#undef SSL_PRINT
#define SSL_PRINT(...)
#endif
#endif #endif
#if SSL_DEBUG_LOCATION_ENABLE #if SSL_DEBUG_LOCATION_ENABLE
@ -56,11 +63,11 @@
#define SSL_ASSERT(s) #define SSL_ASSERT(s)
#endif #endif
#define SSL_ERR(err, go, ...) { SSL_DEBUG_LOCATION(); SSL_PRINT(__VA_ARGS__); ret = err; goto go; } #define SSL_ERR(err, go, fmt, ...) { SSL_DEBUG_LOCATION(); SSL_PRINT(fmt, ##__VA_ARGS__); ret = err; goto go; }
#define SSL_RET(go, ...) { SSL_DEBUG_LOCATION(); SSL_PRINT(__VA_ARGS__); goto go; } #define SSL_RET(go, fmt, ...) { SSL_DEBUG_LOCATION(); SSL_PRINT(fmt, ##__VA_ARGS__); goto go; }
#define SSL_DEBUG(level, ...) { if (level > SSL_DEBUG_LEVEL) {SSL_PRINT(__VA_ARGS__);} } #define SSL_DEBUG(level, fmt, ...) { if (level > SSL_DEBUG_LEVEL) {SSL_PRINT(fmt, ##__VA_ARGS__);} }
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -24,6 +24,7 @@
#ifdef ESP32_IDF_PLATFORM #ifdef ESP32_IDF_PLATFORM
#include "esp_types.h" #include "esp_types.h"
#include "esp_log.h"
void *ssl_mem_zalloc(size_t size); void *ssl_mem_zalloc(size_t size);
void *ssl_mem_malloc(size_t size); void *ssl_mem_malloc(size_t size);
@ -35,6 +36,8 @@ size_t ssl_strlen(const char *src);
void ssl_speed_up_enter(void); void ssl_speed_up_enter(void);
void ssl_speed_up_exit(void); void ssl_speed_up_exit(void);
#define SSL_PRINT(fmt, ...) ESP_LOGD("OpenSSL", fmt, ##__VA_ARGS__)
#elif defined(SSL_PLATFORM_USER_INCLUDE) #elif defined(SSL_PLATFORM_USER_INCLUDE)
SSL_PLATFORM_USER_INCLUDE SSL_PLATFORM_USER_INCLUDE

View File

@ -22,7 +22,7 @@
/*********************************************************************************************/ /*********************************************************************************************/
/********************************* SSL general interface *************************************/ /********************************* SSL general interface *************************************/
void* ssl_zalloc(size_t size) void* ssl_mem_zalloc(size_t size)
{ {
void *p = malloc(size); void *p = malloc(size);
@ -32,12 +32,12 @@ void* ssl_zalloc(size_t size)
return p; return p;
} }
void *ssl_malloc(size_t size) void *ssl_mem_malloc(size_t size)
{ {
return malloc(size); return malloc(size);
} }
void ssl_free(void *p) void ssl_mem_free(void *p)
{ {
free(p); free(p);
} }