add the function ERR remove state and test for it

pull/1319/head
Jacob Barthelmeh 2017-03-08 13:50:38 -07:00
parent 2e6f97621a
commit e9f3d7f898
4 changed files with 78 additions and 7 deletions

View File

@ -14138,6 +14138,21 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
}
/* frees all nodes in the current threads error queue
*
* id thread id. ERR_remove_state is depriciated and id is ignored. The
* current threads queue will be free'd.
*/
void wolfSSL_ERR_remove_state(unsigned long id)
{
WOLFSSL_ENTER("wolfSSL_ERR_remove_state");
(void)id;
if (wc_ERR_remove_state() != 0) {
WOLFSSL_MSG("Error with removing the state");
}
}
int wolfSSL_RAND_status(void)
{
return WOLFSSL_SUCCESS; /* wolfCrypt provides enough seed internally */
@ -14313,13 +14328,6 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
}
void wolfSSL_ERR_remove_state(unsigned long state)
{
/* TODO: GetErrors().Remove(); */
(void)state;
}
void wolfSSL_EVP_cleanup(void)
{
/* nothing to do here */

View File

@ -14189,6 +14189,36 @@ static void test_wolfSSL_ERR_peek_last_error_line(void)
FreeTcpReady(&ready);
/* check clearing error state */
ERR_remove_state(0);
AssertIntEQ((int)ERR_peek_last_error_line(NULL, NULL), 0);
ERR_peek_last_error_line(NULL, &line);
AssertIntEQ(line, 0);
ERR_peek_last_error_line(&file, NULL);
AssertNull(file);
/* retry connection to fill error queue */
XMEMSET(&client_args, 0, sizeof(func_args));
XMEMSET(&server_args, 0, sizeof(func_args));
StartTCP();
InitTcpReady(&ready);
client_cb.method = wolfTLSv1_1_client_method;
server_cb.method = wolfTLSv1_2_server_method;
server_args.signal = &ready;
server_args.callbacks = &server_cb;
client_args.signal = &ready;
client_args.callbacks = &client_cb;
start_thread(test_server_nofail, &server_args, &serverThread);
wait_tcp_ready(&server_args);
test_client_nofail(&client_args);
join_thread(serverThread);
FreeTcpReady(&ready);
/* check that error code was stored */
AssertIntNE((int)ERR_peek_last_error_line(NULL, NULL), 0);
ERR_peek_last_error_line(NULL, &line);

View File

@ -570,6 +570,38 @@ int wc_SetLoggingHeap(void* h)
return 0;
}
/* frees all nodes in the queue
*
* id this is the thread id
*/
int wc_ERR_remove_state(void)
{
struct wc_error_queue* current;
struct wc_error_queue* next;
if (wc_LockMutex(&debug_mutex) != 0) {
WOLFSSL_MSG("Lock debug mutex failed");
return BAD_MUTEX_E;
}
/* free all nodes from error queue */
current = (struct wc_error_queue*)wc_errors;
while (current != NULL) {
next = current->next;
XFREE(current, current->heap, DYNAMIC_TYPE_LOG);
current = next;
}
wc_errors = NULL;
wc_last_node = NULL;
wc_UnLockMutex(&debug_mutex);
return 0;
}
#if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM)
/* empties out the error queue into the file */
void wc_ERR_print_errors_fp(FILE* fp)

View File

@ -64,6 +64,7 @@ WOLFSSL_API void wolfSSL_Debugging_OFF(void);
WOLFSSL_LOCAL int wc_PullErrorNode(const char **file, const char **reason,
int *line);
WOLFSSL_API int wc_SetLoggingHeap(void* h);
WOLFSSL_API int wc_ERR_remove_state(void);
#if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM)
WOLFSSL_API void wc_ERR_print_errors_fp(FILE* fp);
#endif