Debian Codegraph @

src/OVAL/oval_behavior.c

raw symbols SCIP
1 /**
2 * @file oval_behavior.c
3 * \brief Open Vulnerability and Assessment Language
4 *
5 * See more details at http://oval.mitre.org/
6 */
7
8 /*
9 * Copyright 2009--2013 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 * "David Niemoller" <[email protected]>
28 */
29
30 #ifdef HAVE_CONFIG_H
31 #include <config.h>
32 #endif
33
34 #include <stdlib.h>
35 #include <stdio.h>
36 #include <string.h>
37
38 #include "oval_definitions_impl.h"
39 #include "adt/oval_collection_impl.h"
40 #include "adt/oval_string_map_impl.h"
41
42 #include "common/util.h"
43 #include "common/debug_priv.h"
44 #include "common/_error.h"
45
46 /***************************************************************************/
47 /* Variable definitions
48 * */
49
50 typedef struct oval_behavior {
51 struct oval_definition_model *model;
52 char *value;
53 char *key;
54 } oval_behavior_t;
55
56 /* End of variable definitions
57 * */
58 /***************************************************************************/
59
60 bool oval_behavior_iterator_has_more(struct oval_behavior_iterator *oc_behavior)
61 {
62 return oval_collection_iterator_has_more((struct oval_iterator *)
63 oc_behavior);
64 }
65
66 struct oval_behavior *oval_behavior_iterator_next(struct oval_behavior_iterator
67 *oc_behavior)
68 {
69 return (struct oval_behavior *)
70 oval_collection_iterator_next((struct oval_iterator *)oc_behavior);
71 }
72
73 void oval_behavior_iterator_free(struct oval_behavior_iterator
74 *oc_behavior)
75 {
76 oval_collection_iterator_free((struct oval_iterator *)oc_behavior);
77 }
78
79 char *oval_behavior_get_value(struct oval_behavior *behavior)
80 {
81 __attribute__nonnull__(behavior);
82
83 return behavior->value;
84 }
85
86 char *oval_behavior_get_key(struct oval_behavior *behavior)
87 {
88 __attribute__nonnull__(behavior);
89
90 return behavior->key;
91 }
92
93 struct oval_behavior *oval_behavior_new(struct oval_definition_model *model)
94 {
95 oval_behavior_t *behavior = (oval_behavior_t *) malloc(sizeof(oval_behavior_t));
96 if (behavior == NULL)
97 return NULL;
98
99 behavior->model = model;
100 behavior->value = NULL;
101 behavior->key = NULL;
102 return behavior;
103 }
104
105 struct oval_behavior *oval_behavior_clone(struct oval_definition_model *new_model, struct oval_behavior *old_behavior)
106 {
107 struct oval_behavior *new_behavior = oval_behavior_new(new_model);
108 oval_behavior_set_keyval
109 (new_behavior, oval_behavior_get_key(old_behavior), oval_behavior_get_value(old_behavior));
110 return new_behavior;
111 }
112
113 void oval_behavior_free(struct oval_behavior *behavior)
114 {
115 __attribute__nonnull__(behavior);
116
117 if (behavior->value)
118 free(behavior->value);
119 if (behavior->key)
120 free(behavior->key);
121 behavior->key = NULL;
122 behavior->value = NULL;
123 free(behavior);
124 }
125
126 void oval_behavior_set_keyval(struct oval_behavior *behavior, const char *key, const char *value)
127 {
128 __attribute__nonnull__(behavior);
129
130 behavior->key = oscap_strdup(key);
131 behavior->value = oscap_strdup(value);
132 }
133
134 //typedef void (*oval_behavior_consumer)(struct oval_behavior_node *, void*);
135 int oval_behavior_parse_tag(xmlTextReaderPtr reader,
136 struct oval_parser_context *context,
137 oval_family_t family, oval_behavior_consumer consumer, void *user)
138 {
139 __attribute__nonnull__(context);
140
141 while (xmlTextReaderMoveToNextAttribute(reader) == 1) {
142
143 const char *name = (const char *)xmlTextReaderConstName(reader);
144 const char *value = (const char *)xmlTextReaderConstValue(reader);
145
146 if (name && value) {
147 oval_behavior_t *behavior = oval_behavior_new(context->definition_model);
148 oval_behavior_set_keyval(behavior, name, value);
149 (*consumer) (behavior, user);
150 }
151 }
152 return 0;
153 }
154