10968b11c431702c54f643299350f831ea7cc5ba
[radsecproxy.git] / lib / rsp_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 #ifndef SYS_SOLARIS9
10 #include <stdint.h>
11 #endif
12
13 #if defined (__cplusplus)
14 extern "C" {
15 #endif
16
17 struct hash {
18     struct list *hashlist;
19     pthread_mutex_t mutex;
20 };
21
22 struct hash_entry {
23     void *key;
24     uint32_t keylen;
25     void *data;
26     struct list_node *next; /* used when walking through hash */
27 };
28
29 /* allocates and initialises hash structure; returns NULL if malloc fails */
30 struct hash *hash_create();
31
32 /* frees all memory associated with the hash */
33 void hash_destroy(struct hash *hash);
34
35 /* insert entry in hash; returns 1 if ok, 0 if malloc fails */
36 int hash_insert(struct hash *hash, void *key, uint32_t keylen, void *data);
37
38 /* reads entry from hash */
39 void *hash_read(struct hash *hash, void *key, uint32_t keylen);
40
41 /* extracts (read and remove) entry from hash */
42 void *hash_extract(struct hash *hash, void *key, uint32_t keylen);
43
44 /* returns first entry */
45 struct hash_entry *hash_first(struct hash *hash);
46
47 /* returns the next entry after the argument */
48 struct hash_entry *hash_next(struct hash_entry *entry);
49
50 #if defined (__cplusplus)
51 }
52 #endif
53
54 /* Local Variables: */
55 /* c-file-style: "stroustrup" */
56 /* End: */