Debian Codegraph @

src/DS/rds_asset_index.c

raw symbols SCIP
1 /*
2 * Copyright 2012--2016 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 * Authors:
20 * Martin Preisler <[email protected]>
21 */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include "public/scap_ds.h"
28 #include "public/oscap_text.h"
29
30 #include "common/list.h"
31 #include "common/_error.h"
32 #include "rds_index_priv.h"
33
34 #include <libxml/xmlreader.h>
35 #include <string.h>
36
37
38 struct rds_asset_index
39 {
40 char *id;
41 struct oscap_list *reports; //< rds_report_index
42 };
43
44 struct rds_asset_index *rds_asset_index_new(void)
45 {
46 struct rds_asset_index *ret = calloc(1, sizeof(struct rds_asset_index));
47 ret->id = NULL;
48 ret->reports = oscap_list_new();
49
50 return ret;
51 }
52
53 void rds_asset_index_free(struct rds_asset_index *s)
54 {
55 if (s != NULL) {
56 oscap_list_free0(s->reports);
57 free(s->id);
58 free(s);
59 }
60 }
61
62 const char *rds_asset_index_get_id(struct rds_asset_index *s)
63 {
64 return s->id;
65 }
66
67 void rds_asset_index_add_report_ref(struct rds_asset_index *s, struct rds_report_index *report)
68 {
69 oscap_list_add(s->reports, report);
70 }
71
72 struct rds_report_index_iterator *rds_asset_index_get_reports(struct rds_asset_index *s)
73 {
74 return (struct rds_report_index_iterator*)oscap_iterator_new(s->reports);
75 }
76
77 struct rds_asset_index *rds_asset_index_parse(xmlTextReaderPtr reader)
78 {
79 // sanity check
80 if (xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT ||
81 strcmp((const char*)xmlTextReaderConstLocalName(reader), "asset") != 0) {
82 oscap_seterr(OSCAP_EFAMILY_XML,
83 "Expected to have xmlTextReader at start of <arf:report>, "
84 "the current event is '%i' at '%s' instead. I refuse to parse!",
85 xmlTextReaderNodeType(reader), (const char*)xmlTextReaderConstLocalName(reader));
86 return NULL;
87 }
88
89 struct rds_asset_index *ret = rds_asset_index_new();
90
91 ret->id = (char*)xmlTextReaderGetAttribute(reader, BAD_CAST "id");
92 return ret;
93 }
94
95 struct rds_asset_index *rds_asset_index_iterator_next(struct rds_asset_index_iterator *it)
96 {
97 return (struct rds_asset_index*)(oscap_iterator_next((struct oscap_iterator*)it));
98 }
99
100 bool rds_asset_index_iterator_has_more(struct rds_asset_index_iterator *it)
101 {
102 return oscap_iterator_has_more((struct oscap_iterator*)it);
103 }
104
105 void rds_asset_index_iterator_free(struct rds_asset_index_iterator *it)
106 {
107 oscap_iterator_free((struct oscap_iterator*)it);
108 }