txt_16.c revision 1.3
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/* Reviewed: Thu Mar 16 15:40:00 PST 2000 by bwelling */ 18 19#ifndef RDATA_GENERIC_TXT_16_C 20#define RDATA_GENERIC_TXT_16_C 21 22#define RRTYPE_TXT_ATTRIBUTES (0) 23 24static inline isc_result_t 25generic_totext_txt(ARGS_TOTEXT) { 26 isc_region_t region; 27 28 UNUSED(tctx); 29 30 dns_rdata_toregion(rdata, ®ion); 31 32 while (region.length > 0) { 33 RETERR(txt_totext(®ion, ISC_TRUE, target)); 34 if (region.length > 0) 35 RETERR(str_totext(" ", target)); 36 } 37 38 return (ISC_R_SUCCESS); 39} 40 41static inline isc_result_t 42generic_fromwire_txt(ARGS_FROMWIRE) { 43 isc_result_t result; 44 45 UNUSED(type); 46 UNUSED(dctx); 47 UNUSED(rdclass); 48 UNUSED(options); 49 50 do { 51 result = txt_fromwire(source, target); 52 if (result != ISC_R_SUCCESS) 53 return (result); 54 } while (!buffer_empty(source)); 55 return (ISC_R_SUCCESS); 56} 57 58static inline isc_result_t 59totext_txt(ARGS_TOTEXT) { 60 61 REQUIRE(rdata->type == dns_rdatatype_txt); 62 63 return (generic_totext_txt(rdata, tctx, target)); 64} 65 66static inline isc_result_t 67fromwire_txt(ARGS_FROMWIRE) { 68 69 REQUIRE(type == dns_rdatatype_txt); 70 71 return (generic_fromwire_txt(rdclass, type, source, dctx, options, 72 target)); 73} 74 75static inline isc_result_t 76towire_txt(ARGS_TOWIRE) { 77 78 REQUIRE(rdata->type == dns_rdatatype_txt); 79 80 UNUSED(cctx); 81 82 return (mem_tobuffer(target, rdata->data, rdata->length)); 83} 84 85static inline int 86compare_txt(ARGS_COMPARE) { 87 isc_region_t r1; 88 isc_region_t r2; 89 90 REQUIRE(rdata1->type == rdata2->type); 91 REQUIRE(rdata1->rdclass == rdata2->rdclass); 92 REQUIRE(rdata1->type == dns_rdatatype_txt); 93 94 dns_rdata_toregion(rdata1, &r1); 95 dns_rdata_toregion(rdata2, &r2); 96 return (isc_region_compare(&r1, &r2)); 97} 98 99static inline isc_result_t 100generic_fromstruct_txt(ARGS_FROMSTRUCT) { 101 dns_rdata_txt_t *txt = source; 102 isc_region_t region; 103 uint8_t length; 104 105 REQUIRE(source != NULL); 106 REQUIRE(txt->common.rdtype == type); 107 REQUIRE(txt->common.rdclass == rdclass); 108 REQUIRE(txt->txt != NULL && txt->txt_len != 0); 109 110 UNUSED(type); 111 UNUSED(rdclass); 112 113 region.base = txt->txt; 114 region.length = txt->txt_len; 115 while (region.length > 0) { 116 length = uint8_fromregion(®ion); 117 isc_region_consume(®ion, 1); 118 if (region.length < length) 119 return (ISC_R_UNEXPECTEDEND); 120 isc_region_consume(®ion, length); 121 } 122 123 return (mem_tobuffer(target, txt->txt, txt->txt_len)); 124} 125 126static inline isc_result_t 127generic_tostruct_txt(ARGS_TOSTRUCT) { 128 dns_rdata_txt_t *txt = target; 129 isc_region_t r; 130 131 REQUIRE(target != NULL); 132 REQUIRE(txt->common.rdclass == rdata->rdclass); 133 REQUIRE(txt->common.rdtype == rdata->type); 134 REQUIRE(!ISC_LINK_LINKED(&txt->common, link)); 135 136 dns_rdata_toregion(rdata, &r); 137 txt->txt_len = r.length; 138 txt->txt = mem_maybedup(r.base, r.length); 139 if (txt->txt == NULL) 140 return (ISC_R_NOMEMORY); 141 142 txt->offset = 0; 143 return (ISC_R_SUCCESS); 144} 145 146static inline void 147generic_freestruct_txt(ARGS_FREESTRUCT) { 148 dns_rdata_txt_t *txt = source; 149 150 REQUIRE(source != NULL); 151 152 if (txt->txt != NULL) 153 free(txt->txt); 154} 155 156static inline isc_result_t 157fromstruct_txt(ARGS_FROMSTRUCT) { 158 159 REQUIRE(type == dns_rdatatype_txt); 160 161 return (generic_fromstruct_txt(rdclass, type, source, target)); 162} 163 164static inline isc_result_t 165tostruct_txt(ARGS_TOSTRUCT) { 166 dns_rdata_txt_t *txt = target; 167 168 REQUIRE(rdata->type == dns_rdatatype_txt); 169 REQUIRE(target != NULL); 170 171 txt->common.rdclass = rdata->rdclass; 172 txt->common.rdtype = rdata->type; 173 ISC_LINK_INIT(&txt->common, link); 174 175 return (generic_tostruct_txt(rdata, target)); 176} 177 178static inline void 179freestruct_txt(ARGS_FREESTRUCT) { 180 dns_rdata_txt_t *txt = source; 181 182 REQUIRE(source != NULL); 183 REQUIRE(txt->common.rdtype == dns_rdatatype_txt); 184 185 generic_freestruct_txt(source); 186} 187 188static inline isc_result_t 189additionaldata_txt(ARGS_ADDLDATA) { 190 REQUIRE(rdata->type == dns_rdatatype_txt); 191 192 UNUSED(rdata); 193 UNUSED(add); 194 UNUSED(arg); 195 196 return (ISC_R_SUCCESS); 197} 198 199static inline isc_result_t 200digest_txt(ARGS_DIGEST) { 201 isc_region_t r; 202 203 REQUIRE(rdata->type == dns_rdatatype_txt); 204 205 dns_rdata_toregion(rdata, &r); 206 207 return ((digest)(arg, &r)); 208} 209 210static inline isc_boolean_t 211checkowner_txt(ARGS_CHECKOWNER) { 212 213 REQUIRE(type == dns_rdatatype_txt); 214 215 UNUSED(name); 216 UNUSED(type); 217 UNUSED(rdclass); 218 UNUSED(wildcard); 219 220 return (ISC_TRUE); 221} 222 223static inline isc_boolean_t 224checknames_txt(ARGS_CHECKNAMES) { 225 226 REQUIRE(rdata->type == dns_rdatatype_txt); 227 228 UNUSED(rdata); 229 UNUSED(owner); 230 UNUSED(bad); 231 232 return (ISC_TRUE); 233} 234 235static inline int 236casecompare_txt(ARGS_COMPARE) { 237 return (compare_txt(rdata1, rdata2)); 238} 239 240#endif /* RDATA_GENERIC_TXT_16_C */ 241