| 1 | /* |
| 2 | * Copyright 2009--2014 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 | |
| 22 | #ifdef HAVE_CONFIG_H |
| 23 | #include <config.h> |
| 24 | #endif |
| 25 | |
| 26 | #include <libxml/xmlreader.h> |
| 27 | #include <string.h> |
| 28 | |
| 29 | #include "common/debug_priv.h" |
| 30 | #include "common/_error.h" |
| 31 | #include "common/public/oscap.h" |
| 32 | #include "doc_type_priv.h" |
| 33 | |
| 34 | int oscap_determine_document_type_reader(xmlTextReader *reader, oscap_document_type_t *doc_type) |
| 35 | { |
| 36 | const char* elm_name = NULL; |
| 37 | *doc_type = 0; |
| 38 | |
| 39 | /* find root element */ |
| 40 | while (xmlTextReaderRead(reader) == 1 |
| 41 | && xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT); |
| 42 | |
| 43 | /* identify document type */ |
| 44 | elm_name = (const char *) xmlTextReaderConstLocalName(reader); |
| 45 | if (!elm_name) { |
| 46 | oscap_setxmlerr(xmlGetLastError()); |
| 47 | return -1; |
| 48 | } |
| 49 | else if (!strcmp("oval_definitions", elm_name)) { |
| 50 | *doc_type = OSCAP_DOCUMENT_OVAL_DEFINITIONS; |
| 51 | } |
| 52 | else if (!strcmp("oval_directives", elm_name)) { |
| 53 | *doc_type = OSCAP_DOCUMENT_OVAL_DIRECTIVES; |
| 54 | } |
| 55 | else if (!strcmp("oval_results", elm_name)) { |
| 56 | *doc_type = OSCAP_DOCUMENT_OVAL_RESULTS; |
| 57 | } |
| 58 | else if (!strcmp("oval_system_characteristics", elm_name)) { |
| 59 | *doc_type = OSCAP_DOCUMENT_OVAL_SYSCHAR; |
| 60 | } |
| 61 | else if (!strcmp("oval_variables", elm_name)) { |
| 62 | *doc_type = OSCAP_DOCUMENT_OVAL_VARIABLES; |
| 63 | } |
| 64 | else if (oscap_streq("Benchmark", elm_name) || oscap_streq("TestResult", elm_name)) { |
| 65 | *doc_type = OSCAP_DOCUMENT_XCCDF; |
| 66 | } |
| 67 | else if (!strcmp("Tailoring", elm_name)) { |
| 68 | *doc_type = OSCAP_DOCUMENT_XCCDF_TAILORING; |
| 69 | } |
| 70 | else if (!strcmp("cpe-list", elm_name)) { |
| 71 | *doc_type = OSCAP_DOCUMENT_CPE_DICTIONARY; |
| 72 | } |
| 73 | else if (!strcmp("platform-specification", elm_name)) { |
| 74 | *doc_type = OSCAP_DOCUMENT_CPE_LANGUAGE; |
| 75 | } |
| 76 | else if (!strcmp("data-stream-collection", elm_name)) { |
| 77 | *doc_type = OSCAP_DOCUMENT_SDS; |
| 78 | } |
| 79 | else if (!strcmp("asset-report-collection", elm_name)) { |
| 80 | *doc_type = OSCAP_DOCUMENT_ARF; |
| 81 | } |
| 82 | else if (!strcmp("sce_results", elm_name)) { |
| 83 | *doc_type = OSCAP_DOCUMENT_SCE_RESULT; |
| 84 | } else if (!strcmp("ocil", elm_name)) { |
| 85 | *doc_type = OSCAP_DOCUMENT_OCIL; |
| 86 | } else { |
| 87 | return -1; |
| 88 | } |
| 89 | |
| 90 | dI("Identified document type: %s", elm_name); |
| 91 | |
| 92 | return 0; |
| 93 | } |