forked from wolfSSL/wolfssl
add peek error node function to make use of debug mutex
This commit is contained in:
14
src/ssl.c
14
src/ssl.c
@ -20469,13 +20469,15 @@ unsigned long wolfSSL_ERR_peek_last_error_line(const char **file, int *line)
|
|||||||
(void)line;
|
(void)line;
|
||||||
(void)file;
|
(void)file;
|
||||||
#if defined(DEBUG_WOLFSSL)
|
#if defined(DEBUG_WOLFSSL)
|
||||||
if (line != NULL) {
|
{
|
||||||
*line = (int)wc_last_error_line;
|
int ret;
|
||||||
|
|
||||||
|
if ((ret = wc_PeekErrorNode(-1, file, NULL, line)) < 0) {
|
||||||
|
WOLFSSL_MSG("Issue peeking at error node in queue");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return (unsigned long)ret;
|
||||||
}
|
}
|
||||||
if (file != NULL) {
|
|
||||||
*file = (char*)wc_last_error_file;
|
|
||||||
}
|
|
||||||
return wc_last_error;
|
|
||||||
#else
|
#else
|
||||||
return (unsigned long)(0 - NOT_COMPILED_IN);
|
return (unsigned long)(0 - NOT_COMPILED_IN);
|
||||||
#endif
|
#endif
|
||||||
|
@ -2703,7 +2703,6 @@ static void test_wolfSSL_ERR_peek_last_error_line(void)
|
|||||||
ERR_print_errors_fp(stdout);
|
ERR_print_errors_fp(stdout);
|
||||||
printf("Done testing print out\n\n");
|
printf("Done testing print out\n\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
wolfSSL_Cleanup();
|
|
||||||
#endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
|
#endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
|
||||||
!defined(NO_FILESYSTEM) && !defined(DEBUG_WOLFSSL) */
|
!defined(NO_FILESYSTEM) && !defined(DEBUG_WOLFSSL) */
|
||||||
}
|
}
|
||||||
|
@ -273,7 +273,7 @@ void WOLFSSL_ERROR(int error)
|
|||||||
int wc_LoggingInit(void)
|
int wc_LoggingInit(void)
|
||||||
{
|
{
|
||||||
if (wc_InitMutex(&debug_mutex) != 0) {
|
if (wc_InitMutex(&debug_mutex) != 0) {
|
||||||
WOLFSSL_MSG("Bad Init Mutex frnih");
|
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));
|
XMEMSET((char*)wc_last_error_file, 0, sizeof(wc_last_error_file));
|
||||||
@ -310,7 +310,7 @@ int wc_LoggingCleanup(void)
|
|||||||
|
|
||||||
wc_UnLockMutex(&debug_mutex);
|
wc_UnLockMutex(&debug_mutex);
|
||||||
if (wc_FreeMutex(&debug_mutex) != 0) {
|
if (wc_FreeMutex(&debug_mutex) != 0) {
|
||||||
WOLFSSL_MSG("Bad Init Mutex frnih");
|
WOLFSSL_MSG("Bad Mutex free");
|
||||||
return BAD_MUTEX_E;
|
return BAD_MUTEX_E;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -318,6 +318,67 @@ int wc_LoggingCleanup(void)
|
|||||||
|
|
||||||
|
|
||||||
#ifdef DEBUG_WOLFSSL
|
#ifdef DEBUG_WOLFSSL
|
||||||
|
/* peek at an error node
|
||||||
|
*
|
||||||
|
* index : if -1 then the most recent node is looked at, otherwise search
|
||||||
|
* through queue for node at the given index
|
||||||
|
* file : pointer to internal file string
|
||||||
|
* reason : pointer to internal error reason
|
||||||
|
* line : line number that error happened at
|
||||||
|
*
|
||||||
|
* Returns a negative value in error case, on success returns the nodes error
|
||||||
|
* value which is positve (absolute value)
|
||||||
|
*/
|
||||||
|
int wc_PeekErrorNode(int index, const char **file, const char **reason,
|
||||||
|
int *line)
|
||||||
|
{
|
||||||
|
struct wc_error_queue* err;
|
||||||
|
|
||||||
|
if (wc_LockMutex(&debug_mutex) != 0) {
|
||||||
|
WOLFSSL_MSG("Lock debug mutex failed");
|
||||||
|
return BAD_MUTEX_E;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index < 0) {
|
||||||
|
err = wc_last_node;
|
||||||
|
if (err == NULL) {
|
||||||
|
WOLFSSL_MSG("No Errors in queue");
|
||||||
|
wc_UnLockMutex(&debug_mutex);
|
||||||
|
return BAD_STATE_E;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
err = (struct wc_error_queue*)wc_errors;
|
||||||
|
for (i = 0; i < index; i++) {
|
||||||
|
if (err == NULL) {
|
||||||
|
WOLFSSL_MSG("Error node not found. Bad index?");
|
||||||
|
wc_UnLockMutex(&debug_mutex);
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
|
err = err->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file != NULL) {
|
||||||
|
*file = err->file;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reason != NULL) {
|
||||||
|
*reason = err->error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (line != NULL) {
|
||||||
|
*line = err->line;
|
||||||
|
}
|
||||||
|
|
||||||
|
wc_UnLockMutex(&debug_mutex);
|
||||||
|
|
||||||
|
return err->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* 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 */
|
||||||
|
@ -60,6 +60,8 @@ WOLFSSL_API int wolfSSL_SetLoggingCb(wolfSSL_Logging_cb log_function);
|
|||||||
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,
|
||||||
char* file);
|
char* file);
|
||||||
|
WOLFSSL_LOCAL int wc_PeekErrorNode(int index, const char **file,
|
||||||
|
const char **reason, int *line);
|
||||||
WOLFSSL_API int wc_SetLoggingHeap(void* h);
|
WOLFSSL_API int wc_SetLoggingHeap(void* h);
|
||||||
#if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM)
|
#if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM)
|
||||||
WOLFSSL_API void wc_ERR_print_errors_fp(FILE* fp);
|
WOLFSSL_API void wc_ERR_print_errors_fp(FILE* fp);
|
||||||
|
Reference in New Issue
Block a user