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