xref: /netbsd-src/external/mpl/bind/dist/lib/isccc/include/isccc/sexpr.h (revision bcda20f65a8566e103791ec395f7f499ef322704)
1 /*	$NetBSD: sexpr.h,v 1.8 2025/01/26 16:25:44 christos Exp $	*/
2 
3 /*
4  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
5  *
6  * SPDX-License-Identifier: MPL-2.0 AND ISC
7  *
8  * This Source Code Form is subject to the terms of the Mozilla Public
9  * License, v. 2.0. If a copy of the MPL was not distributed with this
10  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
11  *
12  * See the COPYRIGHT file distributed with this work for additional
13  * information regarding copyright ownership.
14  */
15 
16 /*
17  * 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 #pragma once
33 
34 /*! \file isccc/sexpr.h */
35 
36 #include <stdbool.h>
37 #include <stdio.h>
38 
39 #include <isc/lang.h>
40 
41 #include <isccc/types.h>
42 
43 ISC_LANG_BEGINDECLS
44 
45 /*% dotted pair structure */
46 struct isccc_dottedpair {
47 	isccc_sexpr_t *car;
48 	isccc_sexpr_t *cdr;
49 };
50 
51 /*% iscc_sexpr structure */
52 struct isccc_sexpr {
53 	unsigned int type;
54 	union {
55 		char		  *as_string;
56 		isccc_dottedpair_t as_dottedpair;
57 		isccc_region_t	   as_region;
58 	} value;
59 };
60 
61 #define ISCCC_SEXPRTYPE_NONE	   0x00 /*%< Illegal. */
62 #define ISCCC_SEXPRTYPE_T	   0x01
63 #define ISCCC_SEXPRTYPE_STRING	   0x02
64 #define ISCCC_SEXPRTYPE_DOTTEDPAIR 0x03
65 #define ISCCC_SEXPRTYPE_BINARY	   0x04
66 
67 #define ISCCC_SEXPR_CAR(s) (s)->value.as_dottedpair.car
68 #define ISCCC_SEXPR_CDR(s) (s)->value.as_dottedpair.cdr
69 
70 isccc_sexpr_t *
71 isccc_sexpr_cons(isccc_sexpr_t *car, isccc_sexpr_t *cdr);
72 
73 isccc_sexpr_t *
74 isccc_sexpr_tconst(void);
75 
76 isccc_sexpr_t *
77 isccc_sexpr_fromstring(const char *str);
78 
79 isccc_sexpr_t *
80 isccc_sexpr_frombinary(const isccc_region_t *region);
81 
82 void
83 isccc_sexpr_free(isccc_sexpr_t **sexprp);
84 
85 void
86 isccc_sexpr_print(isccc_sexpr_t *sexpr, FILE *stream);
87 
88 isccc_sexpr_t *
89 isccc_sexpr_car(isccc_sexpr_t *list);
90 
91 isccc_sexpr_t *
92 isccc_sexpr_cdr(isccc_sexpr_t *list);
93 
94 void
95 isccc_sexpr_setcar(isccc_sexpr_t *pair, isccc_sexpr_t *car);
96 
97 void
98 isccc_sexpr_setcdr(isccc_sexpr_t *pair, isccc_sexpr_t *cdr);
99 
100 isccc_sexpr_t *
101 isccc_sexpr_addtolist(isccc_sexpr_t **l1p, isccc_sexpr_t *l2);
102 
103 bool
104 isccc_sexpr_listp(isccc_sexpr_t *sexpr);
105 
106 bool
107 isccc_sexpr_emptyp(isccc_sexpr_t *sexpr);
108 
109 bool
110 isccc_sexpr_stringp(isccc_sexpr_t *sexpr);
111 
112 bool
113 isccc_sexpr_binaryp(isccc_sexpr_t *sexpr);
114 
115 char *
116 isccc_sexpr_tostring(isccc_sexpr_t *sexpr);
117 
118 isccc_region_t *
119 isccc_sexpr_tobinary(isccc_sexpr_t *sexpr);
120 
121 ISC_LANG_ENDDECLS
122