Jean-Paul Calderone | 897bc25 | 2008-02-18 20:50:23 -0500 | [diff] [blame] | 1 | /* |
| 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 Calderone | 897bc25 | 2008-02-18 20:50:23 -0500 | [diff] [blame] | 14 | /* |
| 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 | */ |
| 21 | PyObject * |
| 22 | error_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 | */ |
| 47 | void |
| 48 | flush_error_queue(void) |
| 49 | { |
| 50 | Py_DECREF(error_queue_to_list()); |
| 51 | } |
| 52 | |