/contrib/bind9/lib/dns/rdata/generic/minfo_14.c
C | 329 lines | 237 code | 74 blank | 18 comment | 50 complexity | b1df454c5dc7938e681f08ee9f9adefb MD5 | raw file
1/* 2 * Copyright (C) 2004, 2007, 2009 Internet Systems Consortium, Inc. ("ISC") 3 * Copyright (C) 1998-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 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: minfo_14.c,v 1.47 2009/12/04 22:06:37 tbox Exp $ */ 19 20/* reviewed: Wed Mar 15 17:45:32 PST 2000 by brister */ 21 22#ifndef RDATA_GENERIC_MINFO_14_C 23#define RDATA_GENERIC_MINFO_14_C 24 25#define RRTYPE_MINFO_ATTRIBUTES (0) 26 27static inline isc_result_t 28fromtext_minfo(ARGS_FROMTEXT) { 29 isc_token_t token; 30 dns_name_t name; 31 isc_buffer_t buffer; 32 int i; 33 isc_boolean_t ok; 34 35 REQUIRE(type == 14); 36 37 UNUSED(type); 38 UNUSED(rdclass); 39 UNUSED(callbacks); 40 41 for (i = 0; i < 2; i++) { 42 RETERR(isc_lex_getmastertoken(lexer, &token, 43 isc_tokentype_string, 44 ISC_FALSE)); 45 dns_name_init(&name, NULL); 46 buffer_fromregion(&buffer, &token.value.as_region); 47 origin = (origin != NULL) ? origin : dns_rootname; 48 RETTOK(dns_name_fromtext(&name, &buffer, origin, 49 options, target)); 50 ok = ISC_TRUE; 51 if ((options & DNS_RDATA_CHECKNAMES) != 0) 52 ok = dns_name_ismailbox(&name); 53 if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) 54 RETTOK(DNS_R_BADNAME); 55 if (!ok && callbacks != NULL) 56 warn_badname(&name, lexer, callbacks); 57 } 58 return (ISC_R_SUCCESS); 59} 60 61static inline isc_result_t 62totext_minfo(ARGS_TOTEXT) { 63 isc_region_t region; 64 dns_name_t rmail; 65 dns_name_t email; 66 dns_name_t prefix; 67 isc_boolean_t sub; 68 69 REQUIRE(rdata->type == 14); 70 REQUIRE(rdata->length != 0); 71 72 dns_name_init(&rmail, NULL); 73 dns_name_init(&email, NULL); 74 dns_name_init(&prefix, NULL); 75 76 dns_rdata_toregion(rdata, ®ion); 77 78 dns_name_fromregion(&rmail, ®ion); 79 isc_region_consume(®ion, rmail.length); 80 81 dns_name_fromregion(&email, ®ion); 82 isc_region_consume(®ion, email.length); 83 84 sub = name_prefix(&rmail, tctx->origin, &prefix); 85 86 RETERR(dns_name_totext(&prefix, sub, target)); 87 88 RETERR(str_totext(" ", target)); 89 90 sub = name_prefix(&email, tctx->origin, &prefix); 91 return (dns_name_totext(&prefix, sub, target)); 92} 93 94static inline isc_result_t 95fromwire_minfo(ARGS_FROMWIRE) { 96 dns_name_t rmail; 97 dns_name_t email; 98 99 REQUIRE(type == 14); 100 101 UNUSED(type); 102 UNUSED(rdclass); 103 104 dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14); 105 106 dns_name_init(&rmail, NULL); 107 dns_name_init(&email, NULL); 108 109 RETERR(dns_name_fromwire(&rmail, source, dctx, options, target)); 110 return (dns_name_fromwire(&email, source, dctx, options, target)); 111} 112 113static inline isc_result_t 114towire_minfo(ARGS_TOWIRE) { 115 isc_region_t region; 116 dns_name_t rmail; 117 dns_name_t email; 118 dns_offsets_t roffsets; 119 dns_offsets_t eoffsets; 120 121 REQUIRE(rdata->type == 14); 122 REQUIRE(rdata->length != 0); 123 124 dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14); 125 126 dns_name_init(&rmail, roffsets); 127 dns_name_init(&email, eoffsets); 128 129 dns_rdata_toregion(rdata, ®ion); 130 131 dns_name_fromregion(&rmail, ®ion); 132 isc_region_consume(®ion, name_length(&rmail)); 133 134 RETERR(dns_name_towire(&rmail, cctx, target)); 135 136 dns_name_fromregion(&rmail, ®ion); 137 isc_region_consume(®ion, rmail.length); 138 139 return (dns_name_towire(&rmail, cctx, target)); 140} 141 142static inline int 143compare_minfo(ARGS_COMPARE) { 144 isc_region_t region1; 145 isc_region_t region2; 146 dns_name_t name1; 147 dns_name_t name2; 148 int order; 149 150 REQUIRE(rdata1->type == rdata2->type); 151 REQUIRE(rdata1->rdclass == rdata2->rdclass); 152 REQUIRE(rdata1->type == 14); 153 REQUIRE(rdata1->length != 0); 154 REQUIRE(rdata2->length != 0); 155 156 dns_name_init(&name1, NULL); 157 dns_name_init(&name2, NULL); 158 159 dns_rdata_toregion(rdata1, ®ion1); 160 dns_rdata_toregion(rdata2, ®ion2); 161 162 dns_name_fromregion(&name1, ®ion1); 163 dns_name_fromregion(&name2, ®ion2); 164 165 order = dns_name_rdatacompare(&name1, &name2); 166 if (order != 0) 167 return (order); 168 169 isc_region_consume(®ion1, name_length(&name1)); 170 isc_region_consume(®ion2, name_length(&name2)); 171 172 dns_name_init(&name1, NULL); 173 dns_name_init(&name2, NULL); 174 175 dns_name_fromregion(&name1, ®ion1); 176 dns_name_fromregion(&name2, ®ion2); 177 178 order = dns_name_rdatacompare(&name1, &name2); 179 return (order); 180} 181 182static inline isc_result_t 183fromstruct_minfo(ARGS_FROMSTRUCT) { 184 dns_rdata_minfo_t *minfo = source; 185 isc_region_t region; 186 187 REQUIRE(type == 14); 188 REQUIRE(source != NULL); 189 REQUIRE(minfo->common.rdtype == type); 190 REQUIRE(minfo->common.rdclass == rdclass); 191 192 UNUSED(type); 193 UNUSED(rdclass); 194 195 dns_name_toregion(&minfo->rmailbox, ®ion); 196 RETERR(isc_buffer_copyregion(target, ®ion)); 197 dns_name_toregion(&minfo->emailbox, ®ion); 198 return (isc_buffer_copyregion(target, ®ion)); 199} 200 201static inline isc_result_t 202tostruct_minfo(ARGS_TOSTRUCT) { 203 dns_rdata_minfo_t *minfo = target; 204 isc_region_t region; 205 dns_name_t name; 206 isc_result_t result; 207 208 REQUIRE(rdata->type == 14); 209 REQUIRE(target != NULL); 210 REQUIRE(rdata->length != 0); 211 212 minfo->common.rdclass = rdata->rdclass; 213 minfo->common.rdtype = rdata->type; 214 ISC_LINK_INIT(&minfo->common, link); 215 216 dns_name_init(&name, NULL); 217 dns_rdata_toregion(rdata, ®ion); 218 dns_name_fromregion(&name, ®ion); 219 dns_name_init(&minfo->rmailbox, NULL); 220 RETERR(name_duporclone(&name, mctx, &minfo->rmailbox)); 221 isc_region_consume(®ion, name_length(&name)); 222 223 dns_name_fromregion(&name, ®ion); 224 dns_name_init(&minfo->emailbox, NULL); 225 result = name_duporclone(&name, mctx, &minfo->emailbox); 226 if (result != ISC_R_SUCCESS) 227 goto cleanup; 228 minfo->mctx = mctx; 229 return (ISC_R_SUCCESS); 230 231 cleanup: 232 if (mctx != NULL) 233 dns_name_free(&minfo->rmailbox, mctx); 234 return (ISC_R_NOMEMORY); 235} 236 237static inline void 238freestruct_minfo(ARGS_FREESTRUCT) { 239 dns_rdata_minfo_t *minfo = source; 240 241 REQUIRE(source != NULL); 242 REQUIRE(minfo->common.rdtype == 14); 243 244 if (minfo->mctx == NULL) 245 return; 246 247 dns_name_free(&minfo->rmailbox, minfo->mctx); 248 dns_name_free(&minfo->emailbox, minfo->mctx); 249 minfo->mctx = NULL; 250} 251 252static inline isc_result_t 253additionaldata_minfo(ARGS_ADDLDATA) { 254 REQUIRE(rdata->type == 14); 255 256 UNUSED(rdata); 257 UNUSED(add); 258 UNUSED(arg); 259 260 return (ISC_R_SUCCESS); 261} 262 263static inline isc_result_t 264digest_minfo(ARGS_DIGEST) { 265 isc_region_t r; 266 dns_name_t name; 267 isc_result_t result; 268 269 REQUIRE(rdata->type == 14); 270 271 dns_rdata_toregion(rdata, &r); 272 dns_name_init(&name, NULL); 273 dns_name_fromregion(&name, &r); 274 result = dns_name_digest(&name, digest, arg); 275 if (result != ISC_R_SUCCESS) 276 return (result); 277 isc_region_consume(&r, name_length(&name)); 278 dns_name_init(&name, NULL); 279 dns_name_fromregion(&name, &r); 280 281 return (dns_name_digest(&name, digest, arg)); 282} 283 284static inline isc_boolean_t 285checkowner_minfo(ARGS_CHECKOWNER) { 286 287 REQUIRE(type == 14); 288 289 UNUSED(name); 290 UNUSED(type); 291 UNUSED(rdclass); 292 UNUSED(wildcard); 293 294 return (ISC_TRUE); 295} 296 297static inline isc_boolean_t 298checknames_minfo(ARGS_CHECKNAMES) { 299 isc_region_t region; 300 dns_name_t name; 301 302 REQUIRE(rdata->type == 14); 303 304 UNUSED(owner); 305 306 dns_rdata_toregion(rdata, ®ion); 307 dns_name_init(&name, NULL); 308 dns_name_fromregion(&name, ®ion); 309 if (!dns_name_ismailbox(&name)) { 310 if (bad != NULL) 311 dns_name_clone(&name, bad); 312 return (ISC_FALSE); 313 } 314 isc_region_consume(®ion, name_length(&name)); 315 dns_name_fromregion(&name, ®ion); 316 if (!dns_name_ismailbox(&name)) { 317 if (bad != NULL) 318 dns_name_clone(&name, bad); 319 return (ISC_FALSE); 320 } 321 return (ISC_TRUE); 322} 323 324static inline int 325casecompare_minfo(ARGS_COMPARE) { 326 return (compare_minfo(rdata1, rdata2)); 327} 328 329#endif /* RDATA_GENERIC_MINFO_14_C */