| 1 | /** |
| 2 | * @addtogroup OVAL |
| 3 | * @{ |
| 4 | * @addtogroup OVALSESSION |
| 5 | * OVAL Session |
| 6 | * |
| 7 | * This is a high level API for OVAL Definition content evaluation, collection |
| 8 | * of OVAL System Characteristics and analysing of OVAL Definitions and |
| 9 | * collected OVAL System Characteristics. |
| 10 | * @{ |
| 11 | * |
| 12 | * @file |
| 13 | */ |
| 14 | |
| 15 | /* |
| 16 | * Copyright 2015 Red Hat Inc., Durham, North Carolina. |
| 17 | * All Rights Reserved. |
| 18 | * |
| 19 | * This library is free software; you can redistribute it and/or |
| 20 | * modify it under the terms of the GNU Lesser General Public |
| 21 | * License as published by the Free Software Foundation; either |
| 22 | * version 2.1 of the License, or (at your option) any later version. |
| 23 | * |
| 24 | * This library is distributed in the hope that it will be useful, |
| 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 27 | * Lesser General Public License for more details. |
| 28 | * |
| 29 | * You should have received a copy of the GNU Lesser General Public |
| 30 | * License along with this library; if not, write to the Free Software |
| 31 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 32 | * |
| 33 | * Author: |
| 34 | * Michal Šrubař <[email protected]> |
| 35 | */ |
| 36 | |
| 37 | #ifndef OVAL_SESSION_H_ |
| 38 | #define OVAL_SESSION_H_ |
| 39 | #include "oscap_download_cb.h" |
| 40 | #include "oscap_export.h" |
| 41 | |
| 42 | /** |
| 43 | * @struct oval_session |
| 44 | * A structure encapsulating the context of OVAL operations. |
| 45 | */ |
| 46 | struct oval_session; |
| 47 | |
| 48 | /** |
| 49 | * Costructor of an \ref oval_session. It attempts to recognize a type of the |
| 50 | * filename which has to be a source datastream or OVAL Definitions. |
| 51 | * |
| 52 | * @memberof oval_session |
| 53 | * @param filename a path to an OVAL or source datastream file |
| 54 | * |
| 55 | * @returns a newly created \ref oval_session |
| 56 | * @retval NULL in case of an error (use \ref oscap_err_desc or \ref |
| 57 | * oscap_err_get_full_error to get more details) |
| 58 | */ |
| 59 | OSCAP_API struct oval_session *oval_session_new(const char *filename); |
| 60 | |
| 61 | /** |
| 62 | * Set OVAL Variables. |
| 63 | * |
| 64 | * If a filename has been already set then it will be overwritten. If you pass |
| 65 | * NULL as filename argument then the currently set variables will be freed. |
| 66 | * Validation of the format will be perforemed when the \ref oval_session_load |
| 67 | * is called. |
| 68 | * |
| 69 | * @memberof oval_session |
| 70 | * @param session an \ref oval_session |
| 71 | * @param filename a path to an OVAL Variables file |
| 72 | */ |
| 73 | OSCAP_API void oval_session_set_variables(struct oval_session *session, const char *filename); |
| 74 | |
| 75 | /** |
| 76 | * Set OVAL Directives |
| 77 | * |
| 78 | * If a filename has been already set then it will be overwritten. If you pass |
| 79 | * NULL as filename argument then the currently set variables will be freed. |
| 80 | * Validation of the format will be perforemed when the \ref oval_session_load |
| 81 | * is called. |
| 82 | * |
| 83 | * @memberof oval_session |
| 84 | * @param session an \ref oval_session |
| 85 | * @param filename a path to an OVAL Directives file |
| 86 | */ |
| 87 | OSCAP_API void oval_session_set_directives(struct oval_session *session, const char *filename); |
| 88 | |
| 89 | /** |
| 90 | * Set XSD validation level. |
| 91 | * |
| 92 | * @memberof oval_session |
| 93 | * @param session an \ref oval_session |
| 94 | * @param validate false value indicates to skip any XSD validation |
| 95 | * @param full_validation true value indicates that every possible step will be validated by XSD |
| 96 | */ |
| 97 | OSCAP_API void oval_session_set_validation(struct oval_session *session, bool validate, bool full_validation); |
| 98 | |
| 99 | /** |
| 100 | * Set ID of a specific OVAL Definition in an source datastream. |
| 101 | * |
| 102 | * If the ID has been already set then it will be overwritten. In case where |
| 103 | * there are two OVALs in one datastream use \ref oval_session_set_component_id. |
| 104 | * |
| 105 | * @memberof oval_session |
| 106 | * @param session an \ref oval_session |
| 107 | * @param id an id of a definition |
| 108 | */ |
| 109 | OSCAP_API void oval_session_set_datastream_id(struct oval_session *session, const char *id); |
| 110 | |
| 111 | /** |
| 112 | * Set ID of a particular OVAL component if there are two OVALs in one |
| 113 | * source datastream. If the ID has been already set then it will be |
| 114 | * overwritten. |
| 115 | * |
| 116 | * @memberof oval_session |
| 117 | * @param session an \ref oval_session |
| 118 | * @param id an id of a definition |
| 119 | */ |
| 120 | OSCAP_API void oval_session_set_component_id(struct oval_session *session, const char *id); |
| 121 | |
| 122 | /** |
| 123 | * Set a name of the file that the the OVAL Results will be written into. If the |
| 124 | * file's name has been already set for the current session then it will be |
| 125 | * overwritten. |
| 126 | * |
| 127 | * @memberof oval_session |
| 128 | * @param session an \ref oval_session |
| 129 | * @param filename a path to a new file |
| 130 | */ |
| 131 | OSCAP_API void oval_session_set_results_export(struct oval_session *session, const char *filename); |
| 132 | |
| 133 | /** |
| 134 | * Set a name of the file that the the OVAL Results, converted to HTML format, |
| 135 | * will be written into. If the file's name has been already set for the current |
| 136 | * session then it will be overwritten. |
| 137 | * |
| 138 | * @memberof oval_session |
| 139 | * @param session an \ref oval_session |
| 140 | * @param filename a path to a new file |
| 141 | */ |
| 142 | OSCAP_API void oval_session_set_report_export(struct oval_session *session, const char *filename); |
| 143 | |
| 144 | /** |
| 145 | * Set XML validation reporter. |
| 146 | * |
| 147 | * This function is called when there is something invalid in input/output XML |
| 148 | * file. |
| 149 | * |
| 150 | * @memberof oval_session |
| 151 | * @param session an \ref oval_session |
| 152 | * @param fn pointer to XML reporter function |
| 153 | */ |
| 154 | OSCAP_API void oval_session_set_xml_reporter(struct oval_session *session, xml_reporter fn); |
| 155 | |
| 156 | /** |
| 157 | * Load OVAL Definitions and bind OVAL Variables to it if provided. Validation |
| 158 | * if performed automatically if you've set it with \ref |
| 159 | * oval_session_set_validation. if the validation failed then the function will |
| 160 | * print information about what line in what file isn't valid and why not. |
| 161 | * |
| 162 | * @memberof oval_session |
| 163 | * @param session an \ref oval_session |
| 164 | * |
| 165 | * @retval 0 on success |
| 166 | * @retval 1 on an internal error (use \ref oscap_err_desc or \ref |
| 167 | * oscap_err_get_full_error to get more details) |
| 168 | */ |
| 169 | OSCAP_API int oval_session_load(struct oval_session *session); |
| 170 | |
| 171 | /** |
| 172 | * Evaluate a specific OVAL Definition. The result of the evaluation will be |
| 173 | * written into the result argument. You can convert it into a string |
| 174 | * representation with \ref oval_result_get_text. |
| 175 | * |
| 176 | * @memberof oval_session |
| 177 | * @param session an \ref oval_session |
| 178 | * @param id id of an OVAL Definition |
| 179 | * @param result variable to write the result into |
| 180 | * |
| 181 | * @retval 0 on success |
| 182 | * @retval 1 on an internal error (use \ref oscap_err_desc or \ref |
| 183 | * oscap_err_get_full_error to get more details) |
| 184 | */ |
| 185 | OSCAP_API int oval_session_evaluate_id(struct oval_session *session, const char *id, oval_result_t *result); |
| 186 | |
| 187 | /** |
| 188 | * Evaluate OVAL Definitions. Optionally you can set a callback function which |
| 189 | * will be called upon single evaluation. Use \ref oval_result_definition_get_id |
| 190 | * to get the ID of the evaluated OVAL Definion and \ref |
| 191 | * oval_result_definition_get_result, \ref oval_result_get_text to get a text |
| 192 | * representation of the result. |
| 193 | * |
| 194 | * @memberof oval_session |
| 195 | * @param session an \ref oval_session |
| 196 | * @param fn a callback function |
| 197 | * @param arg an optional argument for your callback function |
| 198 | * |
| 199 | * @retval 0 on success |
| 200 | * @retval 1 on an internal error (use \ref oscap_err_desc or \ref |
| 201 | * oscap_err_get_full_error to get more details) |
| 202 | */ |
| 203 | OSCAP_API int oval_session_evaluate(struct oval_session *session, agent_reporter fn, void *arg); |
| 204 | |
| 205 | /** |
| 206 | * Export result to a file. Results can be represented as OVAL System |
| 207 | * Characteristics if analyse has been done or OVAL Results if evaluation or |
| 208 | * collect has been done. If there aren't any filenames set or no operation was |
| 209 | * performed then this function has no effect. |
| 210 | * |
| 211 | * Alse see: |
| 212 | * \ref oval_session_set_results_export |
| 213 | * \ref oval_session_set_report_export |
| 214 | * |
| 215 | * @memberof oval_session |
| 216 | * @param session an \ref oval_session |
| 217 | * |
| 218 | * @retval 0 on success |
| 219 | * @retval 1 on an internal error (use \ref oscap_err_desc or \ref |
| 220 | * oscap_err_get_full_error to get more details) |
| 221 | */ |
| 222 | OSCAP_API int oval_session_export(struct oval_session *session); |
| 223 | |
| 224 | /** |
| 225 | * Set exporting of system characteristics in OVAL results |
| 226 | * |
| 227 | * |
| 228 | * @memberof oval_session |
| 229 | * @param session an \ref oval_session |
| 230 | * @param export false values indicated no system_characteristics in OVAL Results |
| 231 | */ |
| 232 | OSCAP_API void oval_session_set_export_system_characteristics(struct oval_session *session, bool export); |
| 233 | |
| 234 | /** |
| 235 | * Set property of remote content. |
| 236 | * @memberof oval_session |
| 237 | * @param session an \ref oval_session |
| 238 | * @param allowed Whether is download of remote resources allowed in this session (defaults to false) |
| 239 | * @param callback used to notify user about download proceeds. This might be safely set |
| 240 | * to NULL -- ignoring user notification. |
| 241 | */ |
| 242 | OSCAP_API OSCAP_DEPRECATED(void oval_session_set_remote_resources(struct oval_session *session, bool allowed, download_progress_calllback_t callback)); |
| 243 | |
| 244 | /** |
| 245 | * Set property of remote content. |
| 246 | * @memberof oval_session |
| 247 | * @param session an \ref oval_session |
| 248 | * @param allowed Whether is download of remote resources allowed in this |
| 249 | * session (defaults to false) |
| 250 | * @param local_files Allows to use a locally downloaded copy of the remote |
| 251 | * resources. Contains a path to a directory where the files are stored |
| 252 | * (defaults to NULL). |
| 253 | * @param callback used to notify user about download proceeds. This might be |
| 254 | * safely set to NULL -- ignoring user notification. |
| 255 | */ |
| 256 | OSCAP_API void oval_session_configure_remote_resources(struct oval_session *session, bool allowed, const char *local_files, download_progress_calllback_t callback); |
| 257 | |
| 258 | /** |
| 259 | * Destructor of an \ref oval_session. |
| 260 | * @memberof oval_session |
| 261 | * @param session an \ref oval_session to destroy |
| 262 | */ |
| 263 | OSCAP_API void oval_session_free(struct oval_session *session); |
| 264 | |
| 265 | #endif |