sexpr.c revision 271c4c7ffafeb0bda21278af6cac4535c0193f18
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs * Portions Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs * Portions Copyright (C) 2001 Internet Software Consortium.
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs * Permission to use, copy, modify, and/or distribute this software for any
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs * purpose with or without fee is hereby granted, provided that the above
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs * copyright notice and this permission notice appear in all copies.
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs * THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NOMINUM DISCLAIMS ALL
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs * Portions Copyright (C) 2001 Nominum, Inc.
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs * Permission to use, copy, modify, and/or distribute this software for any
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs * purpose with or without fee is hereby granted, provided that the above
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs * copyright notice and this permission notice appear in all copies.
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs * THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NOMINUM DISCLAIMS ALL
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs/* $Id: sexpr.c,v 1.9 2007/08/28 07:20:43 tbox Exp $ */
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacsstatic isccc_sexpr_t sexpr_t = { ISCCC_SEXPRTYPE_T, { NULL } };
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacsisccc_sexpr_cons(isccc_sexpr_t *car, isccc_sexpr_t *cdr)
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacsisccc_sexpr_frombinary(const isccc_region_t *region)
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs * We add an extra byte when we malloc so we can NUL terminate
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs * the binary data. This allows the caller to use it as a C
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs * string. It's up to the caller to ensure this is safe. We don't
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs * add 1 to the length of the binary region, because the NUL is
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs * not part of the binary data.
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs sexpr->value.as_region.rstart = malloc(region_size + 1);
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs sexpr->value.as_region.rend = sexpr->value.as_region.rstart +
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs memcpy(sexpr->value.as_region.rstart, region->rstart, region_size);
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs * NUL terminate.
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs sexpr->value.as_region.rstart[region_size] = '\0';
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs unsigned char *curr;
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacsisccc_sexpr_print(isccc_sexpr_t *sexpr, FILE *stream)
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs unsigned int size, i;
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs unsigned char *curr;
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs fprintf(stream, "\"%s\"", sexpr->value.as_string);
1bbfd08d1d3f7f7ce1f775d469063cbedb6c26cdMareks Malnacs if (cdr->type != ISCCC_SEXPRTYPE_DOTTEDPAIR) {
for (i = 0; i < size; i++)
INSIST(0);
return (NULL);
return (elt);
return (elt);
return (ISC_TRUE);
return (ISC_FALSE);
return (ISC_TRUE);
return (ISC_FALSE);
return (ISC_TRUE);
return (ISC_FALSE);
return (ISC_TRUE);
return (ISC_FALSE);