xref: /openbsd/usr.sbin/smtpd/dict.h (revision 274d7c50)
1 /*	$OpenBSD: dict.h,v 1.1 2018/12/23 16:06:24 gilles Exp $	*/
2 
3 /*
4  * Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
5  * Copyright (c) 2011 Gilles Chehade <gilles@poolp.org>
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef	_DICT_H_
21 #define	_DICT_H_
22 
23 SPLAY_HEAD(_dict, dictentry);
24 
25 struct dict {
26 	struct _dict	dict;
27 	size_t		count;
28 };
29 
30 
31 /* dict.c */
32 #define dict_init(d) do { SPLAY_INIT(&((d)->dict)); (d)->count = 0; } while(0)
33 #define dict_empty(d) SPLAY_EMPTY(&((d)->dict))
34 #define dict_count(d) ((d)->count)
35 int dict_check(struct dict *, const char *);
36 void *dict_set(struct dict *, const char *, void *);
37 void dict_xset(struct dict *, const char *, void *);
38 void *dict_get(struct dict *, const char *);
39 void *dict_xget(struct dict *, const char *);
40 void *dict_pop(struct dict *, const char *);
41 void *dict_xpop(struct dict *, const char *);
42 int dict_poproot(struct dict *, void **);
43 int dict_root(struct dict *, const char **, void **);
44 int dict_iter(struct dict *, void **, const char **, void **);
45 int dict_iterfrom(struct dict *, void **, const char *, const char **, void **);
46 void dict_merge(struct dict *, struct dict *);
47 
48 #endif
49