1 /* 2 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 13 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 * PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 #ifndef RDATA_GENERIC_DOA_259_C 18 #define RDATA_GENERIC_DOA_259_C 19 20 static inline isc_result_t 21 totext_doa(ARGS_TOTEXT) { 22 char buf[sizeof("4294967295 ")]; 23 isc_region_t region; 24 uint32_t n; 25 26 REQUIRE(rdata != NULL); 27 REQUIRE(rdata->type == dns_rdatatype_doa); 28 REQUIRE(rdata->length != 0); 29 30 UNUSED(tctx); 31 32 dns_rdata_toregion(rdata, ®ion); 33 34 /* 35 * DOA-ENTERPRISE 36 */ 37 n = uint32_fromregion(®ion); 38 isc_region_consume(®ion, 4); 39 snprintf(buf, sizeof(buf), "%u ", n); 40 RETERR(isc_str_tobuffer(buf, target)); 41 42 /* 43 * DOA-TYPE 44 */ 45 n = uint32_fromregion(®ion); 46 isc_region_consume(®ion, 4); 47 snprintf(buf, sizeof(buf), "%u ", n); 48 RETERR(isc_str_tobuffer(buf, target)); 49 50 /* 51 * DOA-LOCATION 52 */ 53 n = uint8_fromregion(®ion); 54 isc_region_consume(®ion, 1); 55 snprintf(buf, sizeof(buf), "%u ", n); 56 RETERR(isc_str_tobuffer(buf, target)); 57 58 /* 59 * DOA-MEDIA-TYPE 60 */ 61 RETERR(txt_totext(®ion, 1, target)); 62 RETERR(isc_str_tobuffer(" ", target)); 63 64 /* 65 * DOA-DATA 66 */ 67 if (region.length == 0) { 68 return (isc_str_tobuffer("-", target)); 69 } else { 70 return (isc_base64_totext(®ion, 60, "", target)); 71 } 72 } 73 74 static inline isc_result_t 75 fromwire_doa(ARGS_FROMWIRE) { 76 isc_region_t region; 77 78 UNUSED(rdclass); 79 UNUSED(dctx); 80 UNUSED(options); 81 82 REQUIRE(type == dns_rdatatype_doa); 83 84 isc_buffer_activeregion(source, ®ion); 85 /* 86 * DOA-MEDIA-TYPE may be an empty <character-string> (i.e., 87 * comprising of just the length octet) and DOA-DATA can have 88 * zero length. 89 */ 90 if (region.length < 4 + 4 + 1 + 1) { 91 return (ISC_R_UNEXPECTEDEND); 92 } 93 94 /* 95 * Check whether DOA-MEDIA-TYPE length is not malformed. 96 */ 97 if (region.base[9] > region.length - 10) { 98 return (ISC_R_UNEXPECTEDEND); 99 } 100 101 isc_buffer_forward(source, region.length); 102 return (isc_mem_tobuffer(target, region.base, region.length)); 103 } 104 105 static inline isc_result_t 106 towire_doa(ARGS_TOWIRE) { 107 isc_region_t region; 108 109 UNUSED(cctx); 110 111 REQUIRE(rdata != NULL); 112 REQUIRE(rdata->type == dns_rdatatype_doa); 113 REQUIRE(rdata->length != 0); 114 115 dns_rdata_toregion(rdata, ®ion); 116 return (isc_mem_tobuffer(target, region.base, region.length)); 117 } 118 119 #endif /* RDATA_GENERIC_DOA_259_C */ 120