forked from wolfSSL/wolfssl
remove extern variables and use error queue instead
This commit is contained in:
@@ -44,13 +44,9 @@
|
|||||||
#if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
|
#if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
|
||||||
static wolfSSL_Mutex debug_mutex; /* mutex for access to debug structure */
|
static wolfSSL_Mutex debug_mutex; /* mutex for access to debug structure */
|
||||||
|
|
||||||
/* accessing any of these global variables should be wrapped in a lock of
|
/* accessing any node from the queue should be wrapped in a lock of
|
||||||
* debug_mutex */
|
* debug_mutex */
|
||||||
volatile char wc_last_error_file[WOLFSSL_MAX_ERROR_SZ];
|
static void* wc_error_heap;
|
||||||
volatile unsigned long wc_last_error_line;
|
|
||||||
volatile unsigned long wc_last_error;
|
|
||||||
volatile void* wc_error_heap;
|
|
||||||
|
|
||||||
struct wc_error_queue {
|
struct wc_error_queue {
|
||||||
void* heap; /* the heap hint used with nodes creation */
|
void* heap; /* the heap hint used with nodes creation */
|
||||||
struct wc_error_queue* next;
|
struct wc_error_queue* next;
|
||||||
@@ -245,16 +241,12 @@ void WOLFSSL_ERROR(int error)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (error < 0) error = error - (2*error); /*get absolute value*/
|
if (error < 0) error = error - (2*error); /*get absolute value*/
|
||||||
wc_last_error = (unsigned long)error;
|
|
||||||
wc_last_error_line = (unsigned long)line;
|
|
||||||
XMEMSET((char*)wc_last_error_file, 0, sizeof(wc_last_error_file));
|
|
||||||
if (XSTRLEN(file) < sizeof(wc_last_error_file)) {
|
|
||||||
XSTRNCPY((char*)wc_last_error_file, file, XSTRLEN(file));
|
|
||||||
}
|
|
||||||
sprintf(buffer, "wolfSSL error occurred, error = %d line:%d file:%s",
|
sprintf(buffer, "wolfSSL error occurred, error = %d line:%d file:%s",
|
||||||
error, line, file);
|
error, line, file);
|
||||||
if (wc_AddErrorNode(error, line, buffer, (char*)file) != 0) {
|
if (wc_AddErrorNode(error, line, buffer, (char*)file) != 0) {
|
||||||
WOLFSSL_MSG("Error creating logging node");
|
WOLFSSL_MSG("Error creating logging node");
|
||||||
|
/* with void function there is no return here, continue on
|
||||||
|
* to unlock mutex and log what buffer was created. */
|
||||||
}
|
}
|
||||||
|
|
||||||
wc_UnLockMutex(&debug_mutex);
|
wc_UnLockMutex(&debug_mutex);
|
||||||
@@ -276,11 +268,7 @@ int wc_LoggingInit(void)
|
|||||||
WOLFSSL_MSG("Bad Init Mutex");
|
WOLFSSL_MSG("Bad Init Mutex");
|
||||||
return BAD_MUTEX_E;
|
return BAD_MUTEX_E;
|
||||||
}
|
}
|
||||||
XMEMSET((char*)wc_last_error_file, 0, sizeof(wc_last_error_file));
|
|
||||||
wc_last_error_line = 0;
|
|
||||||
wc_last_error = 0;
|
|
||||||
wc_errors = NULL;
|
wc_errors = NULL;
|
||||||
wc_error_heap = NULL;
|
|
||||||
wc_last_node = NULL;
|
wc_last_node = NULL;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -381,7 +369,7 @@ int wc_PeekErrorNode(int index, const char **file, const char **reason,
|
|||||||
|
|
||||||
/* create new error node and add it to the queue
|
/* create new error node and add it to the queue
|
||||||
* buffers are assumed to be of size WOLFSSL_MAX_ERROR_SZ for this internal
|
* buffers are assumed to be of size WOLFSSL_MAX_ERROR_SZ for this internal
|
||||||
* function */
|
* function. debug_mutex should be locked before a call to this function. */
|
||||||
int wc_AddErrorNode(int error, int line, char* buf, char* file)
|
int wc_AddErrorNode(int error, int line, char* buf, char* file)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -397,7 +385,7 @@ int wc_AddErrorNode(int error, int line, char* buf, char* file)
|
|||||||
int sz;
|
int sz;
|
||||||
|
|
||||||
XMEMSET(err, 0, sizeof(struct wc_error_queue));
|
XMEMSET(err, 0, sizeof(struct wc_error_queue));
|
||||||
err->heap = (void*)wc_error_heap;
|
err->heap = wc_error_heap;
|
||||||
sz = (int)XSTRLEN(buf);
|
sz = (int)XSTRLEN(buf);
|
||||||
if (sz > WOLFSSL_MAX_ERROR_SZ - 1) {
|
if (sz > WOLFSSL_MAX_ERROR_SZ - 1) {
|
||||||
sz = WOLFSSL_MAX_ERROR_SZ - 1;
|
sz = WOLFSSL_MAX_ERROR_SZ - 1;
|
||||||
|
@@ -47,15 +47,6 @@ typedef void (*wolfSSL_Logging_cb)(const int logLevel,
|
|||||||
WOLFSSL_API int wolfSSL_SetLoggingCb(wolfSSL_Logging_cb log_function);
|
WOLFSSL_API int wolfSSL_SetLoggingCb(wolfSSL_Logging_cb log_function);
|
||||||
|
|
||||||
#if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
|
#if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
|
||||||
typedef struct wc_error_queue wc_error_queue;
|
|
||||||
|
|
||||||
/* make these variables global and declare them in logging.c */
|
|
||||||
extern volatile char wc_last_error_file[80];
|
|
||||||
extern volatile unsigned long wc_last_error_line;
|
|
||||||
extern volatile unsigned long wc_last_error;
|
|
||||||
extern volatile void* wc_error_heap;
|
|
||||||
extern volatile wc_error_queue* wc_errors;
|
|
||||||
|
|
||||||
WOLFSSL_LOCAL int wc_LoggingInit(void);
|
WOLFSSL_LOCAL int wc_LoggingInit(void);
|
||||||
WOLFSSL_LOCAL int wc_LoggingCleanup(void);
|
WOLFSSL_LOCAL int wc_LoggingCleanup(void);
|
||||||
WOLFSSL_LOCAL int wc_AddErrorNode(int error, int line, char* buf,
|
WOLFSSL_LOCAL int wc_AddErrorNode(int error, int line, char* buf,
|
||||||
|
Reference in New Issue
Block a user