| 1 | /** |
| 2 | * @file oval_parser.c |
| 3 | * \brief Open Vulnerability and Assessment Language |
| 4 | * |
| 5 | * See more details at http://oval.mitre.org/ |
| 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * Copyright 2011 Red Hat Inc., Durham, North Carolina. |
| 10 | * All Rights Reserved. |
| 11 | * |
| 12 | * This library is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU Lesser General Public |
| 14 | * License as published by the Free Software Foundation; either |
| 15 | * version 2.1 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * This library is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 20 | * Lesser General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU Lesser General Public |
| 23 | * License along with this library; if not, write to the Free Software |
| 24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 25 | * |
| 26 | * Authors: |
| 27 | * "Peter Vrabec" <[email protected] |
| 28 | * "David Niemoller" <[email protected]> |
| 29 | */ |
| 30 | |
| 31 | #ifdef HAVE_CONFIG_H |
| 32 | #include <config.h> |
| 33 | #endif |
| 34 | |
| 35 | #include <string.h> |
| 36 | #include <libxml/xmlreader.h> |
| 37 | #include <stddef.h> |
| 38 | |
| 39 | #include "public/oval_agent_api.h" |
| 40 | #include "oval_agent_api_impl.h" |
| 41 | #include "oval_parser_impl.h" |
| 42 | #include "oval_definitions_impl.h" |
| 43 | #include "oval_system_characteristics_impl.h" |
| 44 | #include "common/util.h" |
| 45 | #include "common/elements.h" |
| 46 | #include "common/debug_priv.h" |
| 47 | #include "common/_error.h" |
| 48 | |
| 49 | int oval_syschar_model_parse(xmlTextReaderPtr reader, struct oval_parser_context *context) |
| 50 | { |
| 51 | int depth = xmlTextReaderDepth(reader); |
| 52 | int ret = 0; |
| 53 | |
| 54 | xmlTextReaderRead(reader); |
| 55 | while ((xmlTextReaderDepth(reader) > depth) && (ret != -1 )) { |
| 56 | if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_ELEMENT) { |
| 57 | char *tagname = (char *)xmlTextReaderLocalName(reader); |
| 58 | char *namespace = (char *)xmlTextReaderNamespaceUri(reader); |
| 59 | |
| 60 | int is_ovalsys = 0; |
| 61 | if (namespace != NULL) { |
| 62 | is_ovalsys = strcmp((const char*)OVAL_SYSCHAR_NAMESPACE, namespace) == 0; |
| 63 | } |
| 64 | if (is_ovalsys && (strcmp(tagname, "generator") == 0)) { |
| 65 | struct oval_generator *gen; |
| 66 | gen = oval_syschar_model_get_generator(context->syschar_model); |
| 67 | ret = oval_parser_parse_tag(reader, context, &oval_generator_parse_tag, gen); |
| 68 | } else if (is_ovalsys && (strcmp(tagname, "system_info") == 0)) { |
| 69 | ret = oval_sysinfo_parse_tag(reader, context); |
| 70 | } else if (is_ovalsys && (strcmp(tagname, "collected_objects") == 0)) { |
| 71 | ret = oval_parser_parse_tag(reader, context, &oval_syschar_parse_tag, NULL); |
| 72 | } else if (is_ovalsys && (strcmp(tagname, "system_data") == 0)) { |
| 73 | ret = oval_parser_parse_tag(reader, context, &oval_sysitem_parse_tag, NULL); |
| 74 | } else { |
| 75 | dW("Unprocessed tag: <%s:%s>.", namespace, tagname); |
| 76 | oval_parser_skip_tag(reader, context); |
| 77 | } |
| 78 | |
| 79 | free(tagname); |
| 80 | free(namespace); |
| 81 | } else { |
| 82 | if (xmlTextReaderRead(reader) != 1) { |
| 83 | ret = -1; |
| 84 | break; |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | return ret; |
| 90 | } |
| 91 |