00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef OSCAP_LIST_
00029 #define OSCAP_LIST_
00030
00031 #include <stdlib.h>
00032 #include <stdbool.h>
00033
00034 #include "util.h"
00035 #include "public/oscap.h"
00036 #include "public/oscap_text.h"
00037
00038 OSCAP_HIDDEN_START;
00039
00040
00041 typedef void (*oscap_dump_func) ();
00042
00043 typedef bool (*oscap_cmp_func) (void *, void *);
00044
00045
00046
00047
00048
00049 struct oscap_list_item {
00050 void *data;
00051 struct oscap_list_item *next;
00052 };
00053
00054 struct oscap_list {
00055 struct oscap_list_item *first;
00056 struct oscap_list_item *last;
00057 size_t itemcount;
00058 };
00059
00060
00061 OSCAP_HIDDEN_END;
00062
00063 struct oscap_list *oscap_list_new(void);
00064 void oscap_create_lists(struct oscap_list **first, ...);
00065 bool oscap_list_add(struct oscap_list *list, void *value);
00066 bool oscap_list_push(struct oscap_list *list, void *value);
00067 bool oscap_list_pop(struct oscap_list *list, oscap_destruct_func destructor);
00068 bool oscap_list_remove(struct oscap_list *list, void *value, oscap_cmp_func compare, oscap_destruct_func destructor);
00069 struct oscap_list *oscap_list_clone(const struct oscap_list * list, oscap_clone_func cloner);
00070 void oscap_list_free(struct oscap_list *list, oscap_destruct_func destructor);
00071 void oscap_list_free0(struct oscap_list *list);
00072 void oscap_list_dump(struct oscap_list *list, oscap_dump_func dumper, int depth);
00073 int oscap_list_get_itemcount(struct oscap_list *list);
00074 bool oscap_list_contains(struct oscap_list *list, void *what, oscap_cmp_func compare);
00075 struct oscap_list *oscap_list_destructive_join(struct oscap_list *list1, struct oscap_list *list2);
00076
00077 OSCAP_HIDDEN_START;
00078
00079
00080
00081
00082 typedef bool(*oscap_filter_func) (void *, void *);
00083
00084 struct oscap_iterator {
00085 struct oscap_list_item *cur;
00086 struct oscap_list *list;
00087 oscap_filter_func filter;
00088 void *user_data;
00089 };
00090
00091
00092 OSCAP_HIDDEN_END;
00093
00094 void *oscap_iterator_new(struct oscap_list *list);
00095 void *oscap_iterator_new_filter(struct oscap_list *list, oscap_filter_func filter, void *user_data);
00096 void *oscap_iterator_next(struct oscap_iterator *it);
00097 size_t oscap_iterator_get_itemcount(const struct oscap_iterator *it);
00098 bool oscap_iterator_has_more(struct oscap_iterator *it);
00099 void oscap_iterator_reset(struct oscap_iterator *it);
00100 void *oscap_iterator_detach(struct oscap_iterator *it);
00101 void oscap_iterator_free(struct oscap_iterator *it);
00102
00103 OSCAP_HIDDEN_START;
00104
00105 void *oscap_list_find(struct oscap_list *list, void *what, oscap_cmp_func compare);
00106
00113 #define OSCAP_FOREACH_GENERIC(itype, vtype, val, init_val, code) \
00114 { \
00115 struct itype##_iterator *val##_iter = (init_val); \
00116 vtype val; \
00117 while (itype##_iterator_has_more(val##_iter)) { \
00118 val = itype##_iterator_next(val##_iter); \
00119 code \
00120 } \
00121 itype##_iterator_free(val##_iter); \
00122 }
00123
00132 #define OSCAP_FOREACH(type, val, init_val, code) \
00133 OSCAP_FOREACH_GENERIC(type, struct type *, val, init_val, code)
00134
00146 #define OSCAP_FOR_GENERIC(itype, vtype, val, init_val) \
00147 vtype val = NULL; struct itype##_iterator *val##_iter = (init_val); \
00148 while (itype##_iterator_has_more(val##_iter) \
00149 ? (val = itype##_iterator_next(val##_iter), true) \
00150 : (itype##_iterator_free(val##_iter), val##_iter = NULL, false))
00151
00159 #define OSCAP_FOR(type, val, init_val) OSCAP_FOR_GENERIC(type, struct type *, val, init_val)
00160
00167 #define OSCAP_FOR_STR(val, init_val) OSCAP_FOR_GENERIC(oscap_string, const char *, val, init_val)
00168
00169
00170
00171
00172
00173
00174 typedef int (*oscap_compare_func) (const char *, const char *);
00175
00176 struct oscap_htable_item {
00177 struct oscap_htable_item *next;
00178 char *key;
00179 void *value;
00180 };
00181
00182
00183 struct oscap_htable {
00184 size_t hsize;
00185 size_t itemcount;
00186 struct oscap_htable_item **table;
00187 oscap_compare_func cmp;
00188 };
00189
00190
00191
00192
00193
00194
00195
00196
00197 struct oscap_htable *oscap_htable_new1(oscap_compare_func cmp, size_t hsize);
00198
00199
00200
00201
00202
00203
00204
00205
00206 struct oscap_htable *oscap_htable_new(void);
00207
00208
00209
00210
00211
00212
00213 struct oscap_htable * oscap_htable_clone(const struct oscap_htable * table, oscap_clone_func cloner);
00214
00215
00216
00217
00218
00219 bool oscap_htable_add(struct oscap_htable *htable, const char *key, void *item);
00220
00221
00222
00223
00224
00225 void *oscap_htable_get(struct oscap_htable *htable, const char *key);
00226
00227 void *oscap_htable_detach(struct oscap_htable *htable, const char *key);
00228
00229 void oscap_htable_dump(struct oscap_htable *htable, oscap_dump_func dumper, int depth);
00230
00231
00232
00233
00234
00235
00236 void oscap_htable_free(struct oscap_htable *htable, oscap_destruct_func destructor);
00237
00238
00239
00240
00241 void oscap_htable_free0(struct oscap_htable *htable);
00242
00243
00247 struct oscap_htable_iterator;
00248
00254 struct oscap_htable_iterator *oscap_htable_iterator_new(struct oscap_htable *htable);
00255
00261 bool oscap_htable_iterator_has_more(struct oscap_htable_iterator *hit);
00262
00268 const struct oscap_htable_item *oscap_htable_iterator_next(struct oscap_htable_iterator *hit);
00269
00275 const char *oscap_htable_iterator_next_key(struct oscap_htable_iterator *hit);
00276
00282 void *oscap_htable_iterator_next_value(struct oscap_htable_iterator *hit);
00283
00291 void oscap_htable_iterator_next_kv(struct oscap_htable_iterator *hit, const char **key, void **value);
00292
00297 void oscap_htable_iterator_reset(struct oscap_htable_iterator *hit);
00298
00303 void oscap_htable_iterator_free(struct oscap_htable_iterator *hit);
00304
00305 void oscap_print_depth(int depth);
00306
00307 OSCAP_HIDDEN_END;
00308
00309 #endif