1/* 2 * Copyright (C) 2004, 2005, 2007, 2009 Internet Systems Consortium, Inc. ("ISC") 3 * Copyright (C) 1999-2002 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 DISCLAIMS ALL WARRANTIES WITH 10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 * PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18/* $Id: isdn_20.c,v 1.40 2009/12/04 22:06:37 tbox Exp $ */ 19 20/* Reviewed: Wed Mar 15 16:53:11 PST 2000 by bwelling */ 21 22/* RFC1183 */ 23 24#ifndef RDATA_GENERIC_ISDN_20_C 25#define RDATA_GENERIC_ISDN_20_C 26 27#define RRTYPE_ISDN_ATTRIBUTES (0) 28 29static inline isc_result_t 30fromtext_isdn(ARGS_FROMTEXT) { 31 isc_token_t token; 32 33 REQUIRE(type == 20); 34 35 UNUSED(type); 36 UNUSED(rdclass); 37 UNUSED(origin); 38 UNUSED(options); 39 UNUSED(callbacks); 40 41 /* ISDN-address */ 42 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring, 43 ISC_FALSE)); 44 RETTOK(txt_fromtext(&token.value.as_textregion, target)); 45 46 /* sa: optional */ 47 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring, 48 ISC_TRUE)); 49 if (token.type != isc_tokentype_string && 50 token.type != isc_tokentype_qstring) { 51 isc_lex_ungettoken(lexer, &token); 52 return (ISC_R_SUCCESS); 53 } 54 RETTOK(txt_fromtext(&token.value.as_textregion, target)); 55 return (ISC_R_SUCCESS); 56} 57 58static inline isc_result_t 59totext_isdn(ARGS_TOTEXT) { 60 isc_region_t region; 61 62 REQUIRE(rdata->type == 20); 63 REQUIRE(rdata->length != 0); 64 65 UNUSED(tctx); 66 67 dns_rdata_toregion(rdata, ®ion); 68 RETERR(txt_totext(®ion, target)); 69 if (region.length == 0) 70 return (ISC_R_SUCCESS); 71 RETERR(str_totext(" ", target)); 72 return (txt_totext(®ion, target)); 73} 74 75static inline isc_result_t 76fromwire_isdn(ARGS_FROMWIRE) { 77 REQUIRE(type == 20); 78 79 UNUSED(type); 80 UNUSED(dctx); 81 UNUSED(rdclass); 82 UNUSED(options); 83 84 RETERR(txt_fromwire(source, target)); 85 if (buffer_empty(source)) 86 return (ISC_R_SUCCESS); 87 return (txt_fromwire(source, target)); 88} 89 90static inline isc_result_t 91towire_isdn(ARGS_TOWIRE) { 92 UNUSED(cctx); 93 94 REQUIRE(rdata->type == 20); 95 REQUIRE(rdata->length != 0); 96 97 return (mem_tobuffer(target, rdata->data, rdata->length)); 98} 99 100static inline int 101compare_isdn(ARGS_COMPARE) { 102 isc_region_t r1; 103 isc_region_t r2; 104 105 REQUIRE(rdata1->type == rdata2->type); 106 REQUIRE(rdata1->rdclass == rdata2->rdclass); 107 REQUIRE(rdata1->type == 20); 108 REQUIRE(rdata1->length != 0); 109 REQUIRE(rdata2->length != 0); 110 111 dns_rdata_toregion(rdata1, &r1); 112 dns_rdata_toregion(rdata2, &r2); 113 return (isc_region_compare(&r1, &r2)); 114} 115 116static inline isc_result_t 117fromstruct_isdn(ARGS_FROMSTRUCT) { 118 dns_rdata_isdn_t *isdn = source; 119 120 REQUIRE(type == 20); 121 REQUIRE(source != NULL); 122 REQUIRE(isdn->common.rdtype == type); 123 REQUIRE(isdn->common.rdclass == rdclass); 124 125 UNUSED(type); 126 UNUSED(rdclass); 127 128 RETERR(uint8_tobuffer(isdn->isdn_len, target)); 129 RETERR(mem_tobuffer(target, isdn->isdn, isdn->isdn_len)); 130 RETERR(uint8_tobuffer(isdn->subaddress_len, target)); 131 return (mem_tobuffer(target, isdn->subaddress, isdn->subaddress_len)); 132} 133 134static inline isc_result_t 135tostruct_isdn(ARGS_TOSTRUCT) { 136 dns_rdata_isdn_t *isdn = target; 137 isc_region_t r; 138 139 REQUIRE(rdata->type == 20); 140 REQUIRE(target != NULL); 141 REQUIRE(rdata->length != 0); 142 143 isdn->common.rdclass = rdata->rdclass; 144 isdn->common.rdtype = rdata->type; 145 ISC_LINK_INIT(&isdn->common, link); 146 147 dns_rdata_toregion(rdata, &r); 148 149 isdn->isdn_len = uint8_fromregion(&r); 150 isc_region_consume(&r, 1); 151 isdn->isdn = mem_maybedup(mctx, r.base, isdn->isdn_len); 152 if (isdn->isdn == NULL) 153 return (ISC_R_NOMEMORY); 154 isc_region_consume(&r, isdn->isdn_len); 155 156 isdn->subaddress_len = uint8_fromregion(&r); 157 isc_region_consume(&r, 1); 158 isdn->subaddress = mem_maybedup(mctx, r.base, isdn->subaddress_len); 159 if (isdn->subaddress == NULL) 160 goto cleanup; 161 162 isdn->mctx = mctx; 163 return (ISC_R_SUCCESS); 164 165 cleanup: 166 if (mctx != NULL && isdn->isdn != NULL) 167 isc_mem_free(mctx, isdn->isdn); 168 return (ISC_R_NOMEMORY); 169} 170 171static inline void 172freestruct_isdn(ARGS_FREESTRUCT) { 173 dns_rdata_isdn_t *isdn = source; 174 175 REQUIRE(source != NULL); 176 177 if (isdn->mctx == NULL) 178 return; 179 180 if (isdn->isdn != NULL) 181 isc_mem_free(isdn->mctx, isdn->isdn); 182 if (isdn->subaddress != NULL) 183 isc_mem_free(isdn->mctx, isdn->subaddress); 184 isdn->mctx = NULL; 185} 186 187static inline isc_result_t 188additionaldata_isdn(ARGS_ADDLDATA) { 189 REQUIRE(rdata->type == 20); 190 191 UNUSED(rdata); 192 UNUSED(add); 193 UNUSED(arg); 194 195 return (ISC_R_SUCCESS); 196} 197 198static inline isc_result_t 199digest_isdn(ARGS_DIGEST) { 200 isc_region_t r; 201 202 REQUIRE(rdata->type == 20); 203 204 dns_rdata_toregion(rdata, &r); 205 206 return ((digest)(arg, &r)); 207} 208 209static inline isc_boolean_t 210checkowner_isdn(ARGS_CHECKOWNER) { 211 212 REQUIRE(type == 20); 213 214 UNUSED(name); 215 UNUSED(type); 216 UNUSED(rdclass); 217 UNUSED(wildcard); 218 219 return (ISC_TRUE); 220} 221 222static inline isc_boolean_t 223checknames_isdn(ARGS_CHECKNAMES) { 224 225 REQUIRE(rdata->type == 20); 226 227 UNUSED(rdata); 228 UNUSED(owner); 229 UNUSED(bad); 230 231 return (ISC_TRUE); 232} 233 234static inline int 235casecompare_isdn(ARGS_COMPARE) { 236 return (compare_isdn(rdata1, rdata2)); 237} 238 239#endif /* RDATA_GENERIC_ISDN_20_C */ 240