blob: aa9d2380fc76a5c8c5c2301fe05d8b290cc70b19 [file] [log] [blame]
Jean-Paul Calderone897bc252008-02-18 20:50:23 -05001/*
2 * util.c
3 *
4 * Copyright (C) AB Strakt 2001, All rights reserved
5 *
6 * Utility functions.
7 * See the file RATIONALE for a short explanation of why this module was written.
8 *
9 * Reviewed 2001-07-23
10 */
11#include <Python.h>
12#include "util.h"
13
Jean-Paul Calderone897bc252008-02-18 20:50:23 -050014/*
15 * Flush OpenSSL's error queue and return a list of errors (a (library,
16 * function, reason) string tuple)
17 *
18 * Arguments: None
19 * Returns: A list of errors (new reference)
20 */
21PyObject *
22error_queue_to_list(void)
23{
24 PyObject *errlist, *tuple;
25 long err;
26
27 errlist = PyList_New(0);
28
29 while ((err = ERR_get_error()) != 0)
30 {
31 tuple = Py_BuildValue("(sss)", ERR_lib_error_string(err),
32 ERR_func_error_string(err),
33 ERR_reason_error_string(err));
34 PyList_Append(errlist, tuple);
35 Py_DECREF(tuple);
36 }
37
38 return errlist;
39}
40
41/*
42 * Flush OpenSSL's error queue and ignore the result
43 *
44 * Arguments: None
45 * Returns: None
46 */
47void
48flush_error_queue(void)
49{
50 Py_DECREF(error_queue_to_list());
51}
52