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