Debian Codegraph @

src/DS/rds_report_index.c

raw symbols SCIP
1 /*
2 * Copyright 2013--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 "common/list.h"
29 #include "common/_error.h"
30 #include "rds_index_priv.h"
31
32
33 #include <libxml/xmlreader.h>
34 #include <string.h>
35
36 struct rds_report_index
37 {
38 char *id;
39 struct rds_report_request_index *request;
40 };
41
42 struct rds_report_index* rds_report_index_new(void)
43 {
44 struct rds_report_index *ret = calloc(1, sizeof(struct rds_report_index));
45 ret->id = NULL;
46
47 return ret;
48 }
49
50 void rds_report_index_free(struct rds_report_index *s)
51 {
52 if (s != NULL) {
53 free(s->id);
54 free(s);
55 }
56 }
57
58 const char *rds_report_index_get_id(struct rds_report_index *s)
59 {
60 return s->id;
61 }
62
63 void rds_report_index_set_request(struct rds_report_index *s, struct rds_report_request_index *request)
64 {
65 s->request = request;
66 }
67
68 struct rds_report_request_index *rds_report_index_get_request(struct rds_report_index *s)
69 {
70 return s->request;
71 }
72
73 struct rds_report_index *rds_report_index_parse(xmlTextReaderPtr reader)
74 {
75 // sanity check
76 if (xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT ||
77 strcmp((const char*)xmlTextReaderConstLocalName(reader), "report") != 0) {
78 oscap_seterr(OSCAP_EFAMILY_XML,
79 "Expected to have xmlTextReader at start of <arf:report>, "
80 "the current event is '%i' at '%s' instead. I refuse to parse!",
81 xmlTextReaderNodeType(reader), (const char*)xmlTextReaderConstLocalName(reader));
82
83 return NULL;
84 }
85
86 struct rds_report_index *ret = rds_report_index_new();
87
88 ret->id = (char*)xmlTextReaderGetAttribute(reader, BAD_CAST "id");
89 return ret;
90 }
91
92 struct rds_report_index *rds_report_index_iterator_next(struct rds_report_index_iterator *it)
93 {
94 return (struct rds_report_index*)(oscap_iterator_next((struct oscap_iterator*)it));
95 }
96
97 bool rds_report_index_iterator_has_more(struct rds_report_index_iterator *it)
98 {
99 return oscap_iterator_has_more((struct oscap_iterator*)it);
100 }
101
102 void rds_report_index_iterator_free(struct rds_report_index_iterator *it)
103 {
104 oscap_iterator_free((struct oscap_iterator*)it);
105 }
106