uri_256.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011, 2012, 2014  Internet Systems Consortium, Inc. ("ISC")
00003  *
00004  * Permission to use, copy, modify, and/or distribute this software for any
00005  * purpose with or without fee is hereby granted, provided that the above
00006  * copyright notice and this permission notice appear in all copies.
00007  *
00008  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00009  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00010  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00011  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00012  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00013  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00014  * PERFORMANCE OF THIS SOFTWARE.
00015  */
00016 
00017 /* $Id$ */
00018 
00019 #ifndef GENERIC_URI_256_C
00020 #define GENERIC_URI_256_C 1
00021 
00022 #define RRTYPE_URI_ATTRIBUTES (0)
00023 
00024 static inline isc_result_t
00025 fromtext_uri(ARGS_FROMTEXT) {
00026         isc_token_t token;
00027 
00028         REQUIRE(type == 256);
00029 
00030         UNUSED(type);
00031         UNUSED(rdclass);
00032         UNUSED(origin);
00033         UNUSED(options);
00034         UNUSED(callbacks);
00035 
00036         /*
00037          * Priority
00038          */
00039         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
00040                                       ISC_FALSE));
00041         if (token.value.as_ulong > 0xffffU)
00042                 RETTOK(ISC_R_RANGE);
00043         RETERR(uint16_tobuffer(token.value.as_ulong, target));
00044 
00045         /*
00046          * Weight
00047          */
00048         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
00049                                       ISC_FALSE));
00050         if (token.value.as_ulong > 0xffffU)
00051                 RETTOK(ISC_R_RANGE);
00052         RETERR(uint16_tobuffer(token.value.as_ulong, target));
00053 
00054         /*
00055          * Target URI
00056          */
00057         RETERR(isc_lex_getmastertoken(lexer, &token,
00058                                       isc_tokentype_qstring, ISC_FALSE));
00059         if (token.type != isc_tokentype_qstring)
00060                 RETTOK(DNS_R_SYNTAX);
00061         RETTOK(multitxt_fromtext(&token.value.as_textregion, target));
00062         return (ISC_R_SUCCESS);
00063 }
00064 
00065 static inline isc_result_t
00066 totext_uri(ARGS_TOTEXT) {
00067         isc_region_t region;
00068         unsigned short priority, weight;
00069         char buf[sizeof("65000 ")];
00070 
00071         UNUSED(tctx);
00072 
00073         REQUIRE(rdata->type == 256);
00074         REQUIRE(rdata->length != 0);
00075 
00076         dns_rdata_toregion(rdata, &region);
00077 
00078         /*
00079          * Priority
00080          */
00081         priority = uint16_fromregion(&region);
00082         isc_region_consume(&region, 2);
00083         sprintf(buf, "%u ", priority);
00084         RETERR(str_totext(buf, target));
00085 
00086         /*
00087          * Weight
00088          */
00089         weight = uint16_fromregion(&region);
00090         isc_region_consume(&region, 2);
00091         sprintf(buf, "%u ", weight);
00092         RETERR(str_totext(buf, target));
00093 
00094         /*
00095          * Target URI
00096          */
00097         RETERR(multitxt_totext(&region, target));
00098         return (ISC_R_SUCCESS);
00099 }
00100 
00101 static inline isc_result_t
00102 fromwire_uri(ARGS_FROMWIRE) {
00103         isc_region_t region;
00104 
00105         REQUIRE(type == 256);
00106 
00107         UNUSED(type);
00108         UNUSED(rdclass);
00109         UNUSED(dctx);
00110         UNUSED(options);
00111 
00112         /*
00113          * Priority, weight
00114          */
00115         isc_buffer_activeregion(source, &region);
00116         if (region.length < 4)
00117                 return (ISC_R_UNEXPECTEDEND);
00118 
00119         /*
00120          * Priority, weight and target URI
00121          */
00122         isc_buffer_forward(source, region.length);
00123         return (mem_tobuffer(target, region.base, region.length));
00124 }
00125 
00126 static inline isc_result_t
00127 towire_uri(ARGS_TOWIRE) {
00128         isc_region_t region;
00129 
00130         REQUIRE(rdata->type == 256);
00131         REQUIRE(rdata->length != 0);
00132 
00133         UNUSED(cctx);
00134 
00135         dns_rdata_toregion(rdata, &region);
00136         return (mem_tobuffer(target, region.base, region.length));
00137 }
00138 
00139 static inline int
00140 compare_uri(ARGS_COMPARE) {
00141         isc_region_t r1;
00142         isc_region_t r2;
00143         int order;
00144 
00145         REQUIRE(rdata1->type == rdata2->type);
00146         REQUIRE(rdata1->rdclass == rdata2->rdclass);
00147         REQUIRE(rdata1->type == 256);
00148         REQUIRE(rdata1->length != 0);
00149         REQUIRE(rdata2->length != 0);
00150 
00151         dns_rdata_toregion(rdata1, &r1);
00152         dns_rdata_toregion(rdata2, &r2);
00153 
00154         /*
00155          * Priority
00156          */
00157         order = memcmp(r1.base, r2.base, 2);
00158         if (order != 0)
00159                 return (order < 0 ? -1 : 1);
00160         isc_region_consume(&r1, 2);
00161         isc_region_consume(&r2, 2);
00162 
00163         /*
00164          * Weight
00165          */
00166         order = memcmp(r1.base, r2.base, 2);
00167         if (order != 0)
00168                 return (order < 0 ? -1 : 1);
00169         isc_region_consume(&r1, 2);
00170         isc_region_consume(&r2, 2);
00171 
00172         return (isc_region_compare(&r1, &r2));
00173 }
00174 
00175 static inline isc_result_t
00176 fromstruct_uri(ARGS_FROMSTRUCT) {
00177         dns_rdata_uri_t *uri = source;
00178 
00179         REQUIRE(type == 256);
00180         REQUIRE(source != NULL);
00181         REQUIRE(uri->common.rdtype == type);
00182         REQUIRE(uri->common.rdclass == rdclass);
00183         REQUIRE(uri->target != NULL && uri->tgt_len != 0);
00184 
00185         UNUSED(type);
00186         UNUSED(rdclass);
00187 
00188         /*
00189          * Priority
00190          */
00191         RETERR(uint16_tobuffer(uri->priority, target));
00192 
00193         /*
00194          * Weight
00195          */
00196         RETERR(uint16_tobuffer(uri->weight, target));
00197 
00198         /*
00199          * Target URI
00200          */
00201         return (mem_tobuffer(target, uri->target, uri->tgt_len));
00202 }
00203 
00204 static inline isc_result_t
00205 tostruct_uri(ARGS_TOSTRUCT) {
00206         dns_rdata_uri_t *uri = target;
00207         isc_region_t sr;
00208 
00209         REQUIRE(rdata->type == 256);
00210         REQUIRE(target != NULL);
00211         REQUIRE(rdata->length != 0);
00212 
00213         uri->common.rdclass = rdata->rdclass;
00214         uri->common.rdtype = rdata->type;
00215         ISC_LINK_INIT(&uri->common, link);
00216 
00217         dns_rdata_toregion(rdata, &sr);
00218 
00219         /*
00220          * Priority
00221          */
00222         if (sr.length < 2)
00223                 return (ISC_R_UNEXPECTEDEND);
00224         uri->priority = uint16_fromregion(&sr);
00225         isc_region_consume(&sr, 2);
00226 
00227         /*
00228          * Weight
00229          */
00230         if (sr.length < 2)
00231                 return (ISC_R_UNEXPECTEDEND);
00232         uri->weight = uint16_fromregion(&sr);
00233         isc_region_consume(&sr, 2);
00234 
00235         /*
00236          * Target URI
00237          */
00238         uri->tgt_len = sr.length;
00239         uri->target = mem_maybedup(mctx, sr.base, sr.length);
00240         if (uri->target == NULL)
00241                 return (ISC_R_NOMEMORY);
00242 
00243         uri->mctx = mctx;
00244         return (ISC_R_SUCCESS);
00245 }
00246 
00247 static inline void
00248 freestruct_uri(ARGS_FREESTRUCT) {
00249         dns_rdata_uri_t *uri = (dns_rdata_uri_t *) source;
00250 
00251         REQUIRE(source != NULL);
00252         REQUIRE(uri->common.rdtype == 256);
00253 
00254         if (uri->mctx == NULL)
00255                 return;
00256 
00257         if (uri->target != NULL)
00258                 isc_mem_free(uri->mctx, uri->target);
00259         uri->mctx = NULL;
00260 }
00261 
00262 static inline isc_result_t
00263 additionaldata_uri(ARGS_ADDLDATA) {
00264         REQUIRE(rdata->type == 256);
00265 
00266         UNUSED(rdata);
00267         UNUSED(add);
00268         UNUSED(arg);
00269 
00270         return (ISC_R_SUCCESS);
00271 }
00272 
00273 static inline isc_result_t
00274 digest_uri(ARGS_DIGEST) {
00275         isc_region_t r;
00276 
00277         REQUIRE(rdata->type == 256);
00278 
00279         dns_rdata_toregion(rdata, &r);
00280 
00281         return ((digest)(arg, &r));
00282 }
00283 
00284 static inline isc_boolean_t
00285 checkowner_uri(ARGS_CHECKOWNER) {
00286 
00287         REQUIRE(type == 256);
00288 
00289         UNUSED(name);
00290         UNUSED(type);
00291         UNUSED(rdclass);
00292         UNUSED(wildcard);
00293 
00294         return (ISC_TRUE);
00295 }
00296 
00297 static inline isc_boolean_t
00298 checknames_uri(ARGS_CHECKNAMES) {
00299 
00300         REQUIRE(rdata->type == 256);
00301 
00302         UNUSED(rdata);
00303         UNUSED(owner);
00304         UNUSED(bad);
00305 
00306         return (ISC_TRUE);
00307 }
00308 
00309 static inline int
00310 casecompare_uri(ARGS_COMPARE) {
00311         return (compare_uri(rdata1, rdata2));
00312 }
00313 
00314 #endif /* GENERIC_URI_256_C */

Generated on Tue Apr 28 17:41:00 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha