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 struct oscap_list *oscap_list_new(void);
00061 void oscap_create_lists(struct oscap_list **first, ...);
00062 bool oscap_list_add(struct oscap_list *list, void *value);
00063 bool oscap_list_push(struct oscap_list *list, void *value);
00064 bool oscap_list_pop(struct oscap_list *list, oscap_destruct_func destructor);
00065 struct oscap_list *oscap_list_clone(const struct oscap_list * list, oscap_clone_func cloner);
00066 void oscap_list_free(struct oscap_list *list, oscap_destruct_func destructor);
00067 void oscap_list_free0(struct oscap_list *list);
00068 void oscap_list_dump(struct oscap_list *list, oscap_dump_func dumper, int depth);
00069 int oscap_list_get_itemcount(struct oscap_list *list);
00070 bool oscap_list_contains(struct oscap_list *list, void *what, oscap_cmp_func compare);
00071 struct oscap_list *oscap_list_destructive_join(struct oscap_list *list1, struct oscap_list *list2);
00072
00073
00074
00075
00076 typedef bool(*oscap_filter_func) (void *, void *);
00077
00078 struct oscap_iterator {
00079 struct oscap_list_item *cur;
00080 struct oscap_list *list;
00081 oscap_filter_func filter;
00082 void *user_data;
00083 };
00084
00085 void *oscap_iterator_new(struct oscap_list *list);
00086 void *oscap_iterator_new_filter(struct oscap_list *list, oscap_filter_func filter, void *user_data);
00087 void *oscap_iterator_next(struct oscap_iterator *it);
00088 size_t oscap_iterator_get_itemcount(const struct oscap_iterator *it);
00089 bool oscap_iterator_has_more(struct oscap_iterator *it);
00090 void oscap_iterator_reset(struct oscap_iterator *it);
00091 void *oscap_iterator_detach(struct oscap_iterator *it);
00092 void oscap_iterator_free(struct oscap_iterator *it);
00093
00094 void *oscap_list_find(struct oscap_list *list, void *what, oscap_cmp_func compare);
00095
00102 #define OSCAP_FOREACH_GENERIC(itype, vtype, val, init_val, code) \
00103 { \
00104 struct itype##_iterator *val##_iter = (init_val); \
00105 vtype val; \
00106 while (itype##_iterator_has_more(val##_iter)) { \
00107 val = itype##_iterator_next(val##_iter); \
00108 code \
00109 } \
00110 itype##_iterator_free(val##_iter); \
00111 }
00112
00121 #define OSCAP_FOREACH(type, val, init_val, code) \
00122 OSCAP_FOREACH_GENERIC(type, struct type *, val, init_val, code)
00123
00135 #define OSCAP_FOR_GENERIC(itype, vtype, val, init_val) \
00136 vtype val = NULL; struct itype##_iterator *val##_iter = (init_val); \
00137 while (itype##_iterator_has_more(val##_iter) \
00138 ? (val = itype##_iterator_next(val##_iter), true) \
00139 : (itype##_iterator_free(val##_iter), val##_iter = NULL, false))
00140
00148 #define OSCAP_FOR(type, val, init_val) OSCAP_FOR_GENERIC(type, struct type *, val, init_val)
00149
00156 #define OSCAP_FOR_STR(val, init_val) OSCAP_FOR_GENERIC(oscap_string, const char *, val, init_val)
00157
00158
00159
00160
00161
00162
00163 typedef int (*oscap_compare_func) (const char *, const char *);
00164
00165 struct oscap_htable_item {
00166 struct oscap_htable_item *next;
00167 char *key;
00168 void *value;
00169 };
00170
00171
00172 struct oscap_htable {
00173 size_t hsize;
00174 size_t itemcount;
00175 struct oscap_htable_item **table;
00176 oscap_compare_func cmp;
00177 };
00178
00179
00180
00181
00182
00183
00184
00185
00186 struct oscap_htable *oscap_htable_new1(oscap_compare_func cmp, size_t hsize);
00187
00188
00189
00190
00191
00192
00193
00194
00195 struct oscap_htable *oscap_htable_new(void);
00196
00197
00198
00199
00200
00201
00202 struct oscap_htable * oscap_htable_clone(const struct oscap_htable * table, oscap_clone_func cloner);
00203
00204
00205
00206
00207
00208 bool oscap_htable_add(struct oscap_htable *htable, const char *key, void *item);
00209
00210
00211
00212
00213
00214 void *oscap_htable_get(struct oscap_htable *htable, const char *key);
00215
00216 void *oscap_htable_detach(struct oscap_htable *htable, const char *key);
00217
00218 void oscap_htable_dump(struct oscap_htable *htable, oscap_dump_func dumper, int depth);
00219
00220
00221
00222
00223
00224
00225 void oscap_htable_free(struct oscap_htable *htable, oscap_destruct_func destructor);
00226
00227
00228
00229
00230 void oscap_htable_free0(struct oscap_htable *htable);
00231
00232
00236 struct oscap_htable_iterator;
00237
00243 struct oscap_htable_iterator *oscap_htable_iterator_new(struct oscap_htable *htable);
00244
00250 bool oscap_htable_iterator_has_more(struct oscap_htable_iterator *hit);
00251
00257 const struct oscap_htable_item *oscap_htable_iterator_next(struct oscap_htable_iterator *hit);
00258
00264 const char *oscap_htable_iterator_next_key(struct oscap_htable_iterator *hit);
00265
00271 void *oscap_htable_iterator_next_value(struct oscap_htable_iterator *hit);
00272
00280 void oscap_htable_iterator_next_kv(struct oscap_htable_iterator *hit, const char **key, void **value);
00281
00286 void oscap_htable_iterator_reset(struct oscap_htable_iterator *hit);
00287
00292 void oscap_htable_iterator_free(struct oscap_htable_iterator *hit);
00293
00294 void oscap_print_depth(int depth);
00295
00296 OSCAP_HIDDEN_END;
00297
00298 #endif