blob: 3ae72c654143b1014f26d846ec1813844192fb94 [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
14static char *CVSid = "@(#) $Id: util.c,v 1.5 2001/08/09 11:26:36 martin Exp $";
15
16
17/*
18 * Flush OpenSSL's error queue and return a list of errors (a (library,
19 * function, reason) string tuple)
20 *
21 * Arguments: None
22 * Returns: A list of errors (new reference)
23 */
24PyObject *
25error_queue_to_list(void)
26{
27 PyObject *errlist, *tuple;
28 long err;
29
30 errlist = PyList_New(0);
31
32 while ((err = ERR_get_error()) != 0)
33 {
34 tuple = Py_BuildValue("(sss)", ERR_lib_error_string(err),
35 ERR_func_error_string(err),
36 ERR_reason_error_string(err));
37 PyList_Append(errlist, tuple);
38 Py_DECREF(tuple);
39 }
40
41 return errlist;
42}
43
44/*
45 * Flush OpenSSL's error queue and ignore the result
46 *
47 * Arguments: None
48 * Returns: None
49 */
50void
51flush_error_queue(void)
52{
53 Py_DECREF(error_queue_to_list());
54}
55