| 1 | /* |
| 2 | * Copyright 2009 Red Hat Inc., Durham, North Carolina. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2.1 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Lesser General Public |
| 16 | * License along with this library; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | /** |
| 21 | * @file |
| 22 | * |
| 23 | * @addtogroup COMMON |
| 24 | * @{ |
| 25 | * @addtogroup ERRORS |
| 26 | * @{ |
| 27 | * Error checking mechanism. Purse of this mechanism is to inform user about problems that occurred |
| 28 | * during executaion of library functions. Mechanism is similar to linux errno variable. When the problem |
| 29 | * raise, the information about it is stored in library buffer. This information consists of error family, |
| 30 | * and textual description. Example of usage: |
| 31 | * |
| 32 | * @code |
| 33 | * syschar = oval_probe_object_eval (pctx, object); |
| 34 | * if (syschar == NULL && oscap_err()) { |
| 35 | * printf("Error: (%d) %s\n", oscap_err_family(), oscap_err_desc()); |
| 36 | * } |
| 37 | * oscap_clearerr() |
| 38 | * @endcode |
| 39 | * |
| 40 | */ |
| 41 | #pragma once |
| 42 | #ifndef OSCAP_ERROR_H |
| 43 | #define OSCAP_ERROR_H |
| 44 | |
| 45 | #include <stdint.h> |
| 46 | #include <stdbool.h> |
| 47 | |
| 48 | #include "oscap_export.h" |
| 49 | |
| 50 | /// Error family type |
| 51 | typedef uint16_t oscap_errfamily_t; |
| 52 | |
| 53 | /** |
| 54 | * @name OpenSCAP error families |
| 55 | * @{ |
| 56 | */ |
| 57 | #define OSCAP_EFAMILY_NONE 0 /**< None */ |
| 58 | #define OSCAP_EFAMILY_GLIBC 1 /**< Errno errors */ |
| 59 | #define OSCAP_EFAMILY_XML 2 /**< Libxml errors */ |
| 60 | #define OSCAP_EFAMILY_OSCAP 3 /**< OSCAP general errors */ |
| 61 | #define OSCAP_EFAMILY_OVAL 4 /**< OVAL errors (OVAL & probes) */ |
| 62 | #define OSCAP_EFAMILY_XCCDF 5 /**< XCCDF errors */ |
| 63 | #define OSCAP_EFAMILY_SCE 6 /**< SCE errors */ |
| 64 | #define OSCAP_EFAMILY_NET 7 /**< Errors from network communication. Presumably from libcurl. */ |
| 65 | #define OSCAP_EFAMILY_WINDOWS 8 /**< Windows API Errors */ |
| 66 | /** @} */ |
| 67 | |
| 68 | /** |
| 69 | * Clear an error. |
| 70 | */ |
| 71 | OSCAP_API void oscap_clearerr(void); |
| 72 | |
| 73 | /** |
| 74 | * Check for an error. |
| 75 | */ |
| 76 | OSCAP_API bool oscap_err(void); |
| 77 | |
| 78 | /** |
| 79 | * Get last error family. |
| 80 | */ |
| 81 | OSCAP_API oscap_errfamily_t oscap_err_family(void); |
| 82 | |
| 83 | /** |
| 84 | * Get last error description. |
| 85 | */ |
| 86 | OSCAP_API const char *oscap_err_desc(void); |
| 87 | |
| 88 | /** |
| 89 | * Get the full description for all the errors which has occurred in this |
| 90 | * thread since the last call of this function or \ref oscap_clearerr. |
| 91 | * This function is destructive. Subsequent call shall return NULL. |
| 92 | * @returns zero terminated string describing these errors, which shall |
| 93 | * be disposed by caller. |
| 94 | * @retval NULL if there are no errors. |
| 95 | */ |
| 96 | OSCAP_API char *oscap_err_get_full_error(void); |
| 97 | |
| 98 | /// @} |
| 99 | /// @} |
| 100 | #endif /* OSCAP_ERROR_H */ |