1 /*	$NetBSD: sexpr.h,v 1.4 2014/12/10 04:38:01 christos Exp $	*/
2 
3 /*
4  * Portions Copyright (C) 2004-2007  Internet Systems Consortium, Inc. ("ISC")
5  * Portions Copyright (C) 2001  Internet Software Consortium.
6  *
7  * Permission to use, copy, modify, and/or 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 ISC AND NOMINUM DISCLAIMS ALL
12  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
13  * OF MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY
14  * 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  * Portions Copyright (C) 2001  Nominum, Inc.
20  *
21  * Permission to use, copy, modify, and/or distribute this software for any
22  * purpose with or without fee is hereby granted, provided that the above
23  * copyright notice and this permission notice appear in all copies.
24  *
25  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NOMINUM DISCLAIMS ALL
26  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
27  * OF MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY
28  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
29  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
30  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
31  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
32  */
33 
34 /* Id: sexpr.h,v 1.11 2007/08/28 07:20:43 tbox Exp  */
35 
36 #ifndef ISCCC_SEXPR_H
37 #define ISCCC_SEXPR_H 1
38 
39 /*! \file isccc/sexpr.h */
40 
41 #include <stdio.h>
42 
43 #include <isc/lang.h>
44 #include <isccc/types.h>
45 
46 ISC_LANG_BEGINDECLS
47 
48 /*% dotted pair structure */
49 struct isccc_dottedpair {
50 	isccc_sexpr_t *car;
51 	isccc_sexpr_t *cdr;
52 };
53 
54 /*% iscc_sexpr structure */
55 struct isccc_sexpr {
56 	unsigned int			type;
57 	union {
58 		char *			as_string;
59 		isccc_dottedpair_t	as_dottedpair;
60 		isccc_region_t		as_region;
61 	}				value;
62 };
63 
64 #define ISCCC_SEXPRTYPE_NONE		0x00	/*%< Illegal. */
65 #define ISCCC_SEXPRTYPE_T			0x01
66 #define ISCCC_SEXPRTYPE_STRING		0x02
67 #define ISCCC_SEXPRTYPE_DOTTEDPAIR	0x03
68 #define ISCCC_SEXPRTYPE_BINARY		0x04
69 
70 #define ISCCC_SEXPR_CAR(s)		(s)->value.as_dottedpair.car
71 #define ISCCC_SEXPR_CDR(s)		(s)->value.as_dottedpair.cdr
72 
73 isccc_sexpr_t *
74 isccc_sexpr_cons(isccc_sexpr_t *car, isccc_sexpr_t *cdr);
75 
76 isccc_sexpr_t *
77 isccc_sexpr_tconst(void);
78 
79 isccc_sexpr_t *
80 isccc_sexpr_fromstring(const char *str);
81 
82 isccc_sexpr_t *
83 isccc_sexpr_frombinary(const isccc_region_t *region);
84 
85 void
86 isccc_sexpr_free(isccc_sexpr_t **sexprp);
87 
88 void
89 isccc_sexpr_print(isccc_sexpr_t *sexpr, FILE *stream);
90 
91 isccc_sexpr_t *
92 isccc_sexpr_car(isccc_sexpr_t *list);
93 
94 isccc_sexpr_t *
95 isccc_sexpr_cdr(isccc_sexpr_t *list);
96 
97 void
98 isccc_sexpr_setcar(isccc_sexpr_t *pair, isccc_sexpr_t *car);
99 
100 void
101 isccc_sexpr_setcdr(isccc_sexpr_t *pair, isccc_sexpr_t *cdr);
102 
103 isccc_sexpr_t *
104 isccc_sexpr_addtolist(isccc_sexpr_t **l1p, isccc_sexpr_t *l2);
105 
106 isc_boolean_t
107 isccc_sexpr_listp(isccc_sexpr_t *sexpr);
108 
109 isc_boolean_t
110 isccc_sexpr_emptyp(isccc_sexpr_t *sexpr);
111 
112 isc_boolean_t
113 isccc_sexpr_stringp(isccc_sexpr_t *sexpr);
114 
115 isc_boolean_t
116 isccc_sexpr_binaryp(isccc_sexpr_t *sexpr);
117 
118 char *
119 isccc_sexpr_tostring(isccc_sexpr_t *sexpr);
120 
121 isccc_region_t *
122 isccc_sexpr_tobinary(isccc_sexpr_t *sexpr);
123 
124 ISC_LANG_ENDDECLS
125 
126 #endif /* ISCCC_SEXPR_H */
127