fixed bug with multiple status server sent, some dtls fixes
[libradsec.git] / hash.h
1 /*
2  * Copyright (C) 2008 Stig Venaas <venaas@uninett.no>
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  */
8
9 #include <stdint.h>
10
11 struct hash {
12     struct list *hashlist;
13     pthread_mutex_t mutex;
14 };
15
16 struct hash_entry {
17     void *key;
18     uint32_t keylen;
19     void *data;
20     struct list_node *next; /* used when walking through hash */
21 };
22
23 /* allocates and initialises hash structure; returns NULL if malloc fails */
24 struct hash *hash_create();
25
26 /* frees all memory associated with the hash */
27 void hash_destroy(struct hash *hash);
28
29 /* insert entry in hash; returns 1 if ok, 0 if malloc fails */
30 int hash_insert(struct hash *hash, void *key, uint32_t keylen, void *data);
31
32 /* reads entry from hash */
33 void *hash_read(struct hash *hash, void *key, uint32_t keylen);
34
35 /* extracts (read and remove) entry from hash */
36 void *hash_extract(struct hash *hash, void *key, uint32_t keylen);
37
38 /* returns first entry */
39 struct hash_entry *hash_first(struct hash *hash);
40
41 /* returns the next entry after the argument */
42 struct hash_entry *hash_next(struct hash_entry *entry);