Debian Codegraph @

src/OVAL/adt/oval_smc.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 * Structure providing 1--N mapping, by integrating two structures:
24 * oval_string_map and oval_collection.
25 */
26
27 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:409:9`!
28 #include <config.h>cxx . . $ `<file>/build/config.h`/
29 #endif
30
31 #include "oval_smc_impl.h"cxx . . $ `<file>/src/OVAL/adt/oval_smc_impl.h`/
32 #include "oval_string_map_impl.h"cxx . . $ `<file>/src/OVAL/adt/oval_string_map_impl.h`/
33 #include "common/util.h"cxx . . $ `<file>/src/common/util.h`/
34 #include "oval_adt.h"cxx . . $ `<file>/src/OVAL/public/oval_adt.h`/
35
36 struct oval_smccxx . . $ oval_smc# *oval_smc_newcxx . . $ oval_smc_new(920555aa5cf6aa11).(void)
37 {
38 return (struct oval_smccxx . . $ oval_smc# *) oval_string_map_newcxx . . $ oval_string_map_new(c786b134e882bd29).();
39 }
40
41 static inline struct oval_collectioncxx . . $ oval_collection# *_oval_smc_get_allcxx . . $ _oval_smc_get_all(60f8f66ce35dc706).(struct oval_smccxx . . $ oval_smc# *map, const char *key)
42 {
43 return (struct oval_collectioncxx . . $ oval_collection# *) oval_string_map_get_valuecxx . . $ oval_string_map_get_value(c9e9819de236f3d5).((struct oval_string_mapcxx . . $ oval_string_map# *)map, key);
44 }
45
46 void oval_smc_put_lastcxx . . $ oval_smc_put_last(cc2e655dbb18f6b9).(struct oval_smccxx . . $ oval_smc# *map, const char *key, void *item)
47 {
48 __attribute__nonnull__cxx . . $ `src/common/util.h:39:9`!(map);
49
50 if (item != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
51 struct oval_collectioncxx . . $ oval_collection# *list_col = _oval_smc_get_allcxx . . $ _oval_smc_get_all(60f8f66ce35dc706).(map, key);
52 if (list_col == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
53 list_col = oval_collection_newcxx . . $ oval_collection_new(18476da3f812812d).();
54 oval_string_map_putcxx . . $ oval_string_map_put(95b46de789826acc).((struct oval_string_mapcxx . . $ oval_string_map# *) map, key, list_col);
55 }
56 oval_collection_addcxx . . $ oval_collection_add(3c6bf54730c0284).(list_col, item);
57 }
58 }
59
60 void oval_smc_put_last_if_not_existscxx . . $ oval_smc_put_last_if_not_exists(cc2e655dbb18f6b9).(struct oval_smccxx . . $ oval_smc# *map, const char *key, void *item)
61 {
62 __attribute__nonnull__cxx . . $ `src/common/util.h:39:9`!(map);
63
64 if (item != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
65 struct oval_collectioncxx . . $ oval_collection# *list_col = _oval_smc_get_allcxx . . $ _oval_smc_get_all(60f8f66ce35dc706).(map, key);
66 if (list_col == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
67 list_col = oval_collection_newcxx . . $ oval_collection_new(18476da3f812812d).();
68 oval_string_map_putcxx . . $ oval_string_map_put(95b46de789826acc).((struct oval_string_mapcxx . . $ oval_string_map# *) map, key, list_col);
69 }
70
71 struct oval_iteratorcxx . . $ oval_iterator# *list_it = oval_collection_iteratorcxx . . $ oval_collection_iterator(8bdeb6a25e21af3e).(list_col);
72 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! found = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
73 while (!found && oval_collection_iterator_has_morecxx . . $ oval_collection_iterator_has_more(de0650ab9b639739).(list_it)) {
74 if (item == oval_collection_iterator_nextcxx . . $ oval_collection_iterator_next(344074693c9690a9).(list_it)) {
75 found = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
76 }
77 }
78 oval_collection_iterator_freecxx . . $ oval_collection_iterator_free(ee496816570b41f7).(list_it);
79 if (!found) {
80 oval_collection_addcxx . . $ oval_collection_add(3c6bf54730c0284).(list_col, item);
81 }
82 }
83 }
84
85 struct oval_iteratorcxx . . $ oval_iterator# *oval_smc_get_all_itcxx . . $ oval_smc_get_all_it(b0d368e8c30d4bbe).(struct oval_smccxx . . $ oval_smc# *map, const char *key)
86 {
87 struct oval_collectioncxx . . $ oval_collection# *col = _oval_smc_get_allcxx . . $ _oval_smc_get_all(60f8f66ce35dc706).(map, key);
88 return (col == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) ? NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! : oval_collection_iteratorcxx . . $ oval_collection_iterator(8bdeb6a25e21af3e).(col);
89 }
90
91 void *oval_smc_get_lastcxx . . $ oval_smc_get_last(1b0ae60c4d6decaf).(struct oval_smccxx . . $ oval_smc# *map, const char *key)
92 {
93 struct oval_iteratorcxx . . $ oval_iterator# *list_it = oval_smc_get_all_itcxx . . $ oval_smc_get_all_it(b0d368e8c30d4bbe).(map, key);
94 if (list_it == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
95 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
96 void *found = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
97 while (oval_collection_iterator_has_morecxx . . $ oval_collection_iterator_has_more(de0650ab9b639739).(list_it)) {
98 found = oval_collection_iterator_nextcxx . . $ oval_collection_iterator_next(344074693c9690a9).(list_it);
99 }
100 oval_collection_iterator_freecxx . . $ oval_collection_iterator_free(ee496816570b41f7).(list_it);
101 return found;
102 }
103
104 void oval_smc_free0cxx . . $ oval_smc_free0(83a4c04ef3e307e7).(struct oval_smccxx . . $ oval_smc# *map)
105 {
106 if (map == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
107 return;
108 oval_string_map_freecxx . . $ oval_string_map_free(e4310474f4dc2f59).((struct oval_string_mapcxx . . $ oval_string_map# *) map, (oscap_destruct_funccxx . . $ oscap_destruct_func#) oval_collection_freecxx . . $ oval_collection_free(7f543398a7666e77).);
109 }
110
111 void oval_smc_freecxx . . $ oval_smc_free(f3a9d3973e79da8d).(struct oval_smccxx . . $ oval_smc# *map, oscap_destruct_funccxx . . $ oscap_destruct_func# destructor)
112 {
113 if (map == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
114 return;
115 struct oval_iteratorcxx . . $ oval_iterator# *map_it = oval_string_map_valuescxx . . $ oval_string_map_values(52dd2feb99c28df0).((struct oval_string_mapcxx . . $ oval_string_map# *) map);
116 while (oval_collection_iterator_has_morecxx . . $ oval_collection_iterator_has_more(de0650ab9b639739).(map_it)) {
117 struct oval_collectioncxx . . $ oval_collection# *list_col = (struct oval_collectioncxx . . $ oval_collection# *) oval_collection_iterator_nextcxx . . $ oval_collection_iterator_next(344074693c9690a9).(map_it);
118 oval_collection_free_itemscxx . . $ oval_collection_free_items(637ec69504f927f1).(list_col, destructor);
119 }
120 oval_collection_iterator_freecxx . . $ oval_collection_iterator_free(ee496816570b41f7).(map_it);
121 oval_string_map_freecxx . . $ oval_string_map_free(e4310474f4dc2f59).((struct oval_string_mapcxx . . $ oval_string_map# *) map, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
122 }
123
124 static inline struct oval_collectioncxx . . $ oval_collection# *_oval_collection_clone_usercxx . . $ _oval_collection_clone_user(fd71bc61933a28e4).(struct oval_collectioncxx . . $ oval_collection# *oldcol, oval_smc_user_clone_funccxx . . $ oval_smc_user_clone_func# cloner, void *user_data)
125 {
126 if (oldcol == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || cloner == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
127 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
128
129 struct oval_collectioncxx . . $ oval_collection# *newcol = oval_collection_newcxx . . $ oval_collection_new(18476da3f812812d).();
130 struct oval_iteratorcxx . . $ oval_iterator# *col_it = oval_collection_iteratorcxx . . $ oval_collection_iterator(8bdeb6a25e21af3e).(oldcol);
131 while (oval_collection_iterator_has_morecxx . . $ oval_collection_iterator_has_more(de0650ab9b639739).(col_it)) {
132 void *item = oval_collection_iterator_nextcxx . . $ oval_collection_iterator_next(344074693c9690a9).(col_it);
133 void *new_item = (*cloner) (user_data, item);
134 oval_collection_addcxx . . $ oval_collection_add(3c6bf54730c0284).(newcol, new_item);
135 }
136 oval_collection_iterator_freecxx . . $ oval_collection_iterator_free(ee496816570b41f7).(col_it);
137 return newcol;
138 }
139
140 struct oval_smccxx . . $ oval_smc# *oval_smc_clone_usercxx . . $ oval_smc_clone_user(62a0e13a7cf92fc4).(struct oval_smccxx . . $ oval_smc# *oldmap, oval_smc_user_clone_funccxx . . $ oval_smc_user_clone_func# cloner, void *user_data)
141 {
142 if (oldmap == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || cloner == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
143 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
144
145 struct oval_smccxx . . $ oval_smc# *newmap = oval_smc_newcxx . . $ oval_smc_new(920555aa5cf6aa11).();
146 struct oval_string_iteratorcxx . . $ oval_string_iterator# *key_it = (struct oval_string_iteratorcxx . . $ oval_string_iterator# *) oval_string_map_keyscxx . . $ oval_string_map_keys(52dd2feb99c28df0).((struct oval_string_mapcxx . . $ oval_string_map# *) oldmap);
147 while (oval_string_iterator_has_morecxx . . $ oval_string_iterator_has_more(41a15bd829ecb6dd).(key_it)) {
148 const char *key = oval_string_iterator_nextcxx . . $ oval_string_iterator_next(fc393b19611653f6).(key_it);
149 struct oval_collectioncxx . . $ oval_collection# *list_col = _oval_smc_get_allcxx . . $ _oval_smc_get_all(60f8f66ce35dc706).(oldmap, key);
150 struct oval_collectioncxx . . $ oval_collection# *cloned = _oval_collection_clone_usercxx . . $ _oval_collection_clone_user(fd71bc61933a28e4).(list_col, cloner, user_data);
151 oval_string_map_putcxx . . $ oval_string_map_put(95b46de789826acc).((struct oval_string_mapcxx . . $ oval_string_map# *) newmap, key, cloned);
152 }
153 oval_string_iterator_freecxx . . $ oval_string_iterator_free(eccafcd0705f3c29).(key_it);
154 return newmap;
155 }