00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef RDATA_GENERIC_TXT_16_C
00023 #define RDATA_GENERIC_TXT_16_C
00024
00025 #define RRTYPE_TXT_ATTRIBUTES (0)
00026
00027 static inline isc_result_t
00028 fromtext_txt(ARGS_FROMTEXT) {
00029 isc_token_t token;
00030 int strings;
00031
00032 REQUIRE(type == 16);
00033
00034 UNUSED(type);
00035 UNUSED(rdclass);
00036 UNUSED(origin);
00037 UNUSED(options);
00038 UNUSED(callbacks);
00039
00040 strings = 0;
00041 if ((options & DNS_RDATA_UNKNOWNESCAPE) != 0) {
00042 isc_textregion_t r;
00043 DE_CONST("#", r.base);
00044 r.length = 1;
00045 RETERR(txt_fromtext(&r, target));
00046 strings++;
00047 }
00048 for (;;) {
00049 RETERR(isc_lex_getmastertoken(lexer, &token,
00050 isc_tokentype_qstring,
00051 ISC_TRUE));
00052 if (token.type != isc_tokentype_qstring &&
00053 token.type != isc_tokentype_string)
00054 break;
00055 RETTOK(txt_fromtext(&token.value.as_textregion, target));
00056 strings++;
00057 }
00058
00059 isc_lex_ungettoken(lexer, &token);
00060 return (strings == 0 ? ISC_R_UNEXPECTEDEND : ISC_R_SUCCESS);
00061 }
00062
00063 static inline isc_result_t
00064 totext_txt(ARGS_TOTEXT) {
00065 isc_region_t region;
00066
00067 UNUSED(tctx);
00068
00069 REQUIRE(rdata->type == 16);
00070
00071 dns_rdata_toregion(rdata, ®ion);
00072
00073 while (region.length > 0) {
00074 RETERR(txt_totext(®ion, ISC_TRUE, target));
00075 if (region.length > 0)
00076 RETERR(str_totext(" ", target));
00077 }
00078
00079 return (ISC_R_SUCCESS);
00080 }
00081
00082 static inline isc_result_t
00083 fromwire_txt(ARGS_FROMWIRE) {
00084 isc_result_t result;
00085
00086 REQUIRE(type == 16);
00087
00088 UNUSED(type);
00089 UNUSED(dctx);
00090 UNUSED(rdclass);
00091 UNUSED(options);
00092
00093 do {
00094 result = txt_fromwire(source, target);
00095 if (result != ISC_R_SUCCESS)
00096 return (result);
00097 } while (!buffer_empty(source));
00098 return (ISC_R_SUCCESS);
00099 }
00100
00101 static inline isc_result_t
00102 towire_txt(ARGS_TOWIRE) {
00103 isc_region_t region;
00104
00105 REQUIRE(rdata->type == 16);
00106
00107 UNUSED(cctx);
00108
00109 isc_buffer_availableregion(target, ®ion);
00110 if (region.length < rdata->length)
00111 return (ISC_R_NOSPACE);
00112
00113 memmove(region.base, rdata->data, rdata->length);
00114 isc_buffer_add(target, rdata->length);
00115 return (ISC_R_SUCCESS);
00116 }
00117
00118 static inline int
00119 compare_txt(ARGS_COMPARE) {
00120 isc_region_t r1;
00121 isc_region_t r2;
00122
00123 REQUIRE(rdata1->type == rdata2->type);
00124 REQUIRE(rdata1->rdclass == rdata2->rdclass);
00125 REQUIRE(rdata1->type == 16);
00126
00127 dns_rdata_toregion(rdata1, &r1);
00128 dns_rdata_toregion(rdata2, &r2);
00129 return (isc_region_compare(&r1, &r2));
00130 }
00131
00132 static inline isc_result_t
00133 fromstruct_txt(ARGS_FROMSTRUCT) {
00134 dns_rdata_txt_t *txt = source;
00135 isc_region_t region;
00136 isc_uint8_t length;
00137
00138 REQUIRE(type == 16);
00139 REQUIRE(source != NULL);
00140 REQUIRE(txt->common.rdtype == type);
00141 REQUIRE(txt->common.rdclass == rdclass);
00142 REQUIRE(txt->txt != NULL && txt->txt_len != 0);
00143
00144 UNUSED(type);
00145 UNUSED(rdclass);
00146
00147 region.base = txt->txt;
00148 region.length = txt->txt_len;
00149 while (region.length > 0) {
00150 length = uint8_fromregion(®ion);
00151 isc_region_consume(®ion, 1);
00152 if (region.length < length)
00153 return (ISC_R_UNEXPECTEDEND);
00154 isc_region_consume(®ion, length);
00155 }
00156
00157 return (mem_tobuffer(target, txt->txt, txt->txt_len));
00158 }
00159
00160 static inline isc_result_t
00161 tostruct_txt(ARGS_TOSTRUCT) {
00162 dns_rdata_txt_t *txt = target;
00163 isc_region_t r;
00164
00165 REQUIRE(rdata->type == 16);
00166 REQUIRE(target != NULL);
00167
00168 txt->common.rdclass = rdata->rdclass;
00169 txt->common.rdtype = rdata->type;
00170 ISC_LINK_INIT(&txt->common, link);
00171
00172 dns_rdata_toregion(rdata, &r);
00173 txt->txt_len = r.length;
00174 txt->txt = mem_maybedup(mctx, r.base, r.length);
00175 if (txt->txt == NULL)
00176 return (ISC_R_NOMEMORY);
00177
00178 txt->offset = 0;
00179 txt->mctx = mctx;
00180 return (ISC_R_SUCCESS);
00181 }
00182
00183 static inline void
00184 freestruct_txt(ARGS_FREESTRUCT) {
00185 dns_rdata_txt_t *txt = source;
00186
00187 REQUIRE(source != NULL);
00188 REQUIRE(txt->common.rdtype == 16);
00189
00190 if (txt->mctx == NULL)
00191 return;
00192
00193 if (txt->txt != NULL)
00194 isc_mem_free(txt->mctx, txt->txt);
00195 txt->mctx = NULL;
00196 }
00197
00198 static inline isc_result_t
00199 additionaldata_txt(ARGS_ADDLDATA) {
00200 REQUIRE(rdata->type == 16);
00201
00202 UNUSED(rdata);
00203 UNUSED(add);
00204 UNUSED(arg);
00205
00206 return (ISC_R_SUCCESS);
00207 }
00208
00209 static inline isc_result_t
00210 digest_txt(ARGS_DIGEST) {
00211 isc_region_t r;
00212
00213 REQUIRE(rdata->type == 16);
00214
00215 dns_rdata_toregion(rdata, &r);
00216
00217 return ((digest)(arg, &r));
00218 }
00219
00220 static inline isc_boolean_t
00221 checkowner_txt(ARGS_CHECKOWNER) {
00222
00223 REQUIRE(type == 16);
00224
00225 UNUSED(name);
00226 UNUSED(type);
00227 UNUSED(rdclass);
00228 UNUSED(wildcard);
00229
00230 return (ISC_TRUE);
00231 }
00232
00233 static inline isc_boolean_t
00234 checknames_txt(ARGS_CHECKNAMES) {
00235
00236 REQUIRE(rdata->type == 16);
00237
00238 UNUSED(rdata);
00239 UNUSED(owner);
00240 UNUSED(bad);
00241
00242 return (ISC_TRUE);
00243 }
00244
00245 static inline isc_result_t
00246 casecompare_txt(ARGS_COMPARE) {
00247 return (compare_txt(rdata1, rdata2));
00248 }
00249
00250 isc_result_t
00251 dns_rdata_txt_first(dns_rdata_txt_t *txt) {
00252
00253 REQUIRE(txt != NULL);
00254 REQUIRE(txt->common.rdtype == 16);
00255 REQUIRE(txt->txt != NULL || txt->txt_len == 0);
00256
00257 if (txt->txt_len == 0)
00258 return (ISC_R_NOMORE);
00259
00260 txt->offset = 0;
00261 return (ISC_R_SUCCESS);
00262 }
00263
00264 isc_result_t
00265 dns_rdata_txt_next(dns_rdata_txt_t *txt) {
00266 isc_region_t r;
00267 isc_uint8_t length;
00268
00269 REQUIRE(txt != NULL);
00270 REQUIRE(txt->common.rdtype == 16);
00271 REQUIRE(txt->txt != NULL && txt->txt_len != 0);
00272
00273 INSIST(txt->offset + 1 <= txt->txt_len);
00274 r.base = txt->txt + txt->offset;
00275 r.length = txt->txt_len - txt->offset;
00276 length = uint8_fromregion(&r);
00277 INSIST(txt->offset + 1 + length <= txt->txt_len);
00278 txt->offset = txt->offset + 1 + length;
00279 if (txt->offset == txt->txt_len)
00280 return (ISC_R_NOMORE);
00281 return (ISC_R_SUCCESS);
00282 }
00283
00284 isc_result_t
00285 dns_rdata_txt_current(dns_rdata_txt_t *txt, dns_rdata_txt_string_t *string) {
00286 isc_region_t r;
00287
00288 REQUIRE(txt != NULL);
00289 REQUIRE(string != NULL);
00290 REQUIRE(txt->common.rdtype == 16);
00291 REQUIRE(txt->txt != NULL);
00292 REQUIRE(txt->offset < txt->txt_len);
00293
00294 INSIST(txt->offset + 1 <= txt->txt_len);
00295 r.base = txt->txt + txt->offset;
00296 r.length = txt->txt_len - txt->offset;
00297
00298 string->length = uint8_fromregion(&r);
00299 isc_region_consume(&r, 1);
00300 string->data = r.base;
00301 INSIST(txt->offset + 1 + string->length <= txt->txt_len);
00302
00303 return (ISC_R_SUCCESS);
00304 }
00305 #endif