Skip to content

Commit 02094eb

Browse files
committed
Updates after review by JacobBarthelmeh.
- fix err/ret rename leftover for python builds - add documenetation to thread-local functions - move generic queue functions up
1 parent 45f9ef5 commit 02094eb

2 files changed

Lines changed: 65 additions & 15 deletions

File tree

src/ssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33213,7 +33213,7 @@ unsigned long wolfSSL_ERR_peek_error_line_data(const char **file, int *line,
3321333213
return (ERR_LIB_SSL << 24) | -SSL_R_HTTP_REQUEST;
3321433214
#endif
3321533215
#if defined(OPENSSL_ALL) && defined(WOLFSSL_PYTHON)
33216-
else if (ret == ASN1_R_HEADER_TOO_LONG)
33216+
else if (err == ASN1_R_HEADER_TOO_LONG)
3321733217
return (ERR_LIB_ASN1 << 24) | ASN1_R_HEADER_TOO_LONG;
3321833218
#endif
3321933219
return err;

wolfcrypt/src/logging.c

Lines changed: 64 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -463,20 +463,11 @@ static THREAD_LS_T struct wc_error_queue wc_errors;
463463
#define ERRQ_LOCK() 0
464464
#define ERRQ_UNLOCK() (void)0
465465

466-
/* Internal function that is called by wolfCrypt_Init() */
467-
int wc_LoggingInit(void)
468-
{
469-
return 0;
470-
}
471-
472-
/* internal function that is called by wolfCrypt_Cleanup */
473-
int wc_LoggingCleanup(void)
474-
{
475-
/* clear logging entries */
476-
wc_ClearErrorNodes();
477-
return 0;
478-
}
479-
466+
/**
467+
* Given a relative index (from head of the error list), return
468+
* the absolute index in the `wc_errors->entries` array for
469+
* the entry or -1 if no such entry exists/is present.
470+
*/
480471
static int get_abs_idx(int relative_idx)
481472
{
482473
if ((wc_errors.count == 0) || (relative_idx >= (int)wc_errors.count)) {
@@ -489,6 +480,10 @@ static int get_abs_idx(int relative_idx)
489480
return (int)((wc_errors.head_idx + relative_idx) % ERROR_QUEUE_MAX);
490481
}
491482

483+
/**
484+
* Return the error entry at the given relative index, if
485+
* it exists, e.g. `relative_idx` is in a valid range.
486+
*/
492487
static struct wc_error_entry *get_entry(int relative_idx)
493488
{
494489
int abs_idx;
@@ -500,6 +495,11 @@ static struct wc_error_entry *get_entry(int relative_idx)
500495
return &wc_errors.entries[abs_idx];
501496
}
502497

498+
/**
499+
* Return the error code in the given error `entry` and populate
500+
* `file`, `reason` and `line` with its values.
501+
* `entry` may be NULL, in which case BAD_STATE_E is returned.
502+
*/
503503
static int pass_entry(struct wc_error_entry *entry,
504504
const char **file, const char **reason,
505505
int *line)
@@ -520,6 +520,9 @@ static int pass_entry(struct wc_error_entry *entry,
520520
return entry->err;
521521
}
522522

523+
/**
524+
* Assign entry with values, resets all previously present values.
525+
*/
523526
static void set_entry(struct wc_error_entry *entry, int error,
524527
const char *file, const char *reason, int line)
525528
{
@@ -548,12 +551,34 @@ static void set_entry(struct wc_error_entry *entry, int error,
548551
}
549552
}
550553

554+
/* Internal function that is called by wolfCrypt_Init() */
555+
int wc_LoggingInit(void)
556+
{
557+
return 0;
558+
}
559+
560+
/* internal function that is called by wolfCrypt_Cleanup */
561+
int wc_LoggingCleanup(void)
562+
{
563+
/* clear logging entries */
564+
wc_ClearErrorNodes();
565+
return 0;
566+
}
567+
568+
/**
569+
* Get the values from the HEAD of the ERR queue, but keep it in place.
570+
* If the queue is empty, return BAD_STATE_E.
571+
*/
551572
int wc_PeekErrorNode(int idx, const char **file, const char **reason,
552573
int *line)
553574
{
554575
return pass_entry(get_entry(idx), file, reason, line);
555576
}
556577

578+
/**
579+
* Get the values from the HEAD of the ERR queue and remove it.
580+
* If the queue is empty, return BAD_STATE_E.
581+
*/
557582
int wc_PullErrorNode(const char **file, const char **reason, int *line)
558583
{
559584
struct wc_error_entry *entry;
@@ -589,6 +614,11 @@ int wc_AddErrorNode(int error, int line, char* reason, char* file)
589614
return 0;
590615
}
591616

617+
/**
618+
* Remove the entry at relative position `relative_idx` from the ERR queue.
619+
* For `relative_idx == 0` it removes the queue's head entry, for -1
620+
* it removes the last entry in the queue.
621+
*/
592622
void wc_RemoveErrorNode(int relative_idx)
593623
{
594624
int last_idx, abs_idx = get_abs_idx(relative_idx);
@@ -624,6 +654,9 @@ void wc_RemoveErrorNode(int relative_idx)
624654
}
625655
}
626656

657+
/**
658+
* Clear the ERR queue.
659+
*/
627660
void wc_ClearErrorNodes(void)
628661
{
629662
if (wc_errors.count > 0) {
@@ -643,6 +676,19 @@ int wc_ERR_remove_state(void)
643676
return 0;
644677
}
645678

679+
/**
680+
* Get the first entry's values in the ERR queue that is not filtered
681+
* by the provided `ignore_err` callback. All ignored entries are removed,
682+
* making the returned entry the head of the ERR queue afterwards.
683+
*
684+
* In case all entries are ignored, the ERR queue will be empty afterwards.
685+
* For an empty ERR queue 0 is returned.
686+
*
687+
* ìgnore_err` may be NULL, in which case this returns the HEAD values.
688+
*
689+
* `flags` is present for OpenSSL compatibility, but will always be
690+
* set to 0, since we do not keep flags at ERR entries.
691+
*/
646692
unsigned long wc_PeekErrorNodeLineData(const char **file, int *line,
647693
const char **data, int *flags,
648694
int (*ignore_err)(int err))
@@ -679,6 +725,10 @@ unsigned long wc_PeekErrorNodeLineData(const char **file, int *line,
679725
}
680726
}
681727

728+
/**
729+
* Get the error value at the HEAD of the ERR queue or 0 if the queue
730+
* is emtpy. The HEAD entry is removed by this call.
731+
*/
682732
unsigned long wc_GetErrorNodeErr(void)
683733
{
684734
int ret;

0 commit comments

Comments
 (0)