Debian Codegraph @

src/OVAL/oval_probe_hint.c

raw symbols SCIP
1 /*
2 * Copyright 2013 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 * Šimon Lukašík
21 */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include "public/oval_definitions.h"
28 #include "public/oval_system_characteristics.h"
29 #include "oval_system_characteristics_impl.h"
30 #include "oval_probe_impl.h"
31 #include "_oval_probe_session.h"
32
33 static int _oval_probe_hint_criteria(oval_probe_session_t *sess, struct oval_criteria_node *cnode, int variable_instance_hint);
34 static int _oval_probe_hint_object(oval_probe_session_t *psess, struct oval_object *object, int variable_instance_hint);
35
36 /**
37 * Finds all the oval_syschars (collected objects) assigned with a given definition
38 * and sets the variable_instance_hint attribute thereof. That is to mark these
39 * collected objects with the hint that a new round of collection might be needed
40 * when these objects are again probed by @ref oval_probe_query_object. That is
41 * usefull when a new variable instance is injected into the oval_agent_session.
42 * @param variable_instance_hint new hint to set
43 * @returns 0 on success; -1 on error; 1 on warning
44 */
45 int oval_probe_hint_definition(oval_probe_session_t *sess, struct oval_definition *definition, int variable_instance_hint)
46 {
47 if (definition == NULL)
48 return -1;
49 struct oval_criteria_node *cnode = oval_definition_get_criteria(definition);
50 if (cnode == NULL)
51 return -1;
52
53 return _oval_probe_hint_criteria(sess, cnode, variable_instance_hint);
54 }
55
56 int _oval_probe_hint_criteria(oval_probe_session_t *sess, struct oval_criteria_node *cnode, int variable_instance_hint)
57 {
58 switch (oval_criteria_node_get_type(cnode)) {
59 case OVAL_NODETYPE_CRITERION:{
60 struct oval_test *test = oval_criteria_node_get_test(cnode);
61 if (test == NULL)
62 return 0;
63 struct oval_object *object = oval_test_get_object(test);
64 if (object == NULL)
65 return 0;
66 // TODO: Do we need to similarly hint all the object refereced like: test->state->variable->object?
67 return _oval_probe_hint_object(sess, object, variable_instance_hint);
68 }
69 case OVAL_NODETYPE_CRITERIA:{
70 struct oval_criteria_node_iterator *cnode_it = oval_criteria_node_get_subnodes(cnode);
71 if (cnode_it == NULL)
72 return 0;
73 int ret = 0;
74 while (ret == 0 && oval_criteria_node_iterator_has_more(cnode_it)) {
75 struct oval_criteria_node *node = oval_criteria_node_iterator_next(cnode_it);
76 ret = _oval_probe_hint_criteria(sess, node, variable_instance_hint);
77 }
78 oval_criteria_node_iterator_free(cnode_it);
79 return ret;
80 }
81 case OVAL_NODETYPE_EXTENDDEF:{
82 struct oval_definition *oval_def = oval_criteria_node_get_definition(cnode);
83 return oval_probe_hint_definition(sess, oval_def, variable_instance_hint);
84 }
85 case OVAL_NODETYPE_UNKNOWN:{
86 assert(false);
87 return -1;
88 }
89 }
90 return -1;
91 }
92
93 int _oval_probe_hint_object(oval_probe_session_t *psess, struct oval_object *object, int variable_instance_hint)
94 {
95 const char *oid = oval_object_get_id(object);
96 struct oval_syschar *syschar = oval_syschar_model_get_syschar(psess->sys_model, oid);
97 if (syschar != NULL) {
98 oval_syschar_set_variable_instance_hint(syschar, variable_instance_hint);
99 }
100 return 0;
101 }