diff options
author | 2015-09-04 07:35:06 +0000 | |
---|---|---|
committer | 2015-09-04 07:35:06 +0000 | |
commit | ca6aa8198d2335f8c326c3dd4d26bf5899064214 (patch) | |
tree | 6274a2d971fc0cac0896efe8583927d0190e3d20 /moon-abe/pbc-0.5.14/misc/symtab.c | |
parent | 92fd2dbfb672d7b2b1cdfd5dd5cf89f7716b3e12 (diff) | |
parent | 3baeb11a8fbcfcdbc31976d421f17b85503b3ecd (diff) |
Merge "init attribute-based encryption"
Diffstat (limited to 'moon-abe/pbc-0.5.14/misc/symtab.c')
-rw-r--r-- | moon-abe/pbc-0.5.14/misc/symtab.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/moon-abe/pbc-0.5.14/misc/symtab.c b/moon-abe/pbc-0.5.14/misc/symtab.c new file mode 100644 index 00000000..9d62f590 --- /dev/null +++ b/moon-abe/pbc-0.5.14/misc/symtab.c @@ -0,0 +1,67 @@ +#include <stdlib.h> +#include <string.h> +#include "pbc_memory.h" + +#include "symtab.h" + +struct entry_s { + char *key; + void *data; +}; +typedef struct entry_s *entry_ptr; +typedef struct entry_s entry_t[1]; + +void symtab_init(symtab_t t) { + darray_init(t->list); +} + +static void clear(void *data) { + entry_ptr e = data; + pbc_free(e->key); + pbc_free(e); +} + +void symtab_clear(symtab_t t) { + darray_forall(t->list, clear); + darray_clear(t->list); +} + +void symtab_put(symtab_t t, void *data, const char *key) { + int i, n = t->list->count; + entry_ptr e; + for (i=0; i<n; i++) { + e = t->list->item[i]; + if (!strcmp(e->key, key)) goto doit; + } + e = pbc_malloc(sizeof(entry_t)); + e->key = pbc_strdup(key); + darray_append(t->list, e); +doit: + e->data = data; +} + +int symtab_has(symtab_t t, const char *key) { + int i, n = t->list->count; + for (i = 0; i < n; i++) { + entry_ptr e = t->list->item[i]; + if (!strcmp(e->key, key)) return 1; + } + return 0; +} + +void *symtab_at(symtab_t t, const char *key) { + int i, n = t->list->count; + for (i=0; i<n; i++) { + entry_ptr e = t->list->item[i]; + if (!strcmp(e->key, key)) return e->data; + } + return NULL; +} + +void symtab_forall_data(symtab_t t, void (*func)(void *)) { + int i, n = t->list->count; + for (i=0; i<n; i++) { + entry_ptr e = t->list->item[i]; + func(e->data); + } +} |