lp_107.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2013  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 #ifndef RDATA_GENERIC_LP_107_C
00018 #define RDATA_GENERIC_LP_107_C
00019 
00020 #include <string.h>
00021 
00022 #include <isc/net.h>
00023 
00024 #define RRTYPE_LP_ATTRIBUTES (0)
00025 
00026 static inline isc_result_t
00027 fromtext_lp(ARGS_FROMTEXT) {
00028         isc_token_t token;
00029         dns_name_t name;
00030         isc_buffer_t buffer;
00031 
00032         REQUIRE(type == 107);
00033 
00034         UNUSED(type);
00035         UNUSED(rdclass);
00036         UNUSED(callbacks);
00037 
00038         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
00039                                       ISC_FALSE));
00040         if (token.value.as_ulong > 0xffffU)
00041                 RETTOK(ISC_R_RANGE);
00042         RETERR(uint16_tobuffer(token.value.as_ulong, target));
00043 
00044         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
00045                                       ISC_FALSE));
00046 
00047         dns_name_init(&name, NULL);
00048         buffer_fromregion(&buffer, &token.value.as_region);
00049         origin = (origin != NULL) ? origin : dns_rootname;
00050         return (dns_name_fromtext(&name, &buffer, origin, options, target));
00051 }
00052 
00053 static inline isc_result_t
00054 totext_lp(ARGS_TOTEXT) {
00055         isc_region_t region;
00056         dns_name_t name;
00057         dns_name_t prefix;
00058         isc_boolean_t sub;
00059         char buf[sizeof("64000")];
00060         unsigned short num;
00061 
00062         REQUIRE(rdata->type == 107);
00063         REQUIRE(rdata->length != 0);
00064 
00065         dns_name_init(&name, NULL);
00066         dns_name_init(&prefix, NULL);
00067 
00068         dns_rdata_toregion(rdata, &region);
00069         num = uint16_fromregion(&region);
00070         isc_region_consume(&region, 2);
00071         sprintf(buf, "%u", num);
00072         RETERR(str_totext(buf, target));
00073 
00074         RETERR(str_totext(" ", target));
00075 
00076         dns_name_fromregion(&name, &region);
00077         sub = name_prefix(&name, tctx->origin, &prefix);
00078         return (dns_name_totext(&prefix, sub, target));
00079 }
00080 
00081 static inline isc_result_t
00082 fromwire_lp(ARGS_FROMWIRE) {
00083         dns_name_t name;
00084         isc_region_t sregion;
00085 
00086         REQUIRE(type == 107);
00087 
00088         UNUSED(type);
00089         UNUSED(rdclass);
00090 
00091         dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
00092 
00093         dns_name_init(&name, NULL);
00094 
00095         isc_buffer_activeregion(source, &sregion);
00096         if (sregion.length < 2)
00097                 return (ISC_R_UNEXPECTEDEND);
00098         RETERR(mem_tobuffer(target, sregion.base, 2));
00099         isc_buffer_forward(source, 2);
00100         return (dns_name_fromwire(&name, source, dctx, options, target));
00101 }
00102 
00103 static inline isc_result_t
00104 towire_lp(ARGS_TOWIRE) {
00105 
00106         REQUIRE(rdata->type == 107);
00107         REQUIRE(rdata->length != 0);
00108 
00109         UNUSED(cctx);
00110 
00111         return (mem_tobuffer(target, rdata->data, rdata->length));
00112 }
00113 
00114 static inline int
00115 compare_lp(ARGS_COMPARE) {
00116         isc_region_t region1;
00117         isc_region_t region2;
00118 
00119         REQUIRE(rdata1->type == rdata2->type);
00120         REQUIRE(rdata1->rdclass == rdata2->rdclass);
00121         REQUIRE(rdata1->type == 107);
00122         REQUIRE(rdata1->length != 0);
00123         REQUIRE(rdata2->length != 0);
00124 
00125         dns_rdata_toregion(rdata1, &region1);
00126         dns_rdata_toregion(rdata2, &region2);
00127 
00128         return (isc_region_compare(&region1, &region2));
00129 }
00130 
00131 static inline isc_result_t
00132 fromstruct_lp(ARGS_FROMSTRUCT) {
00133         dns_rdata_lp_t *lp = source;
00134         isc_region_t region;
00135 
00136         REQUIRE(type == 107);
00137         REQUIRE(source != NULL);
00138         REQUIRE(lp->common.rdtype == type);
00139         REQUIRE(lp->common.rdclass == rdclass);
00140 
00141         UNUSED(type);
00142         UNUSED(rdclass);
00143 
00144         RETERR(uint16_tobuffer(lp->pref, target));
00145         dns_name_toregion(&lp->lp, &region);
00146         return (isc_buffer_copyregion(target, &region));
00147 }
00148 
00149 static inline isc_result_t
00150 tostruct_lp(ARGS_TOSTRUCT) {
00151         isc_region_t region;
00152         dns_rdata_lp_t *lp = target;
00153         dns_name_t name;
00154 
00155         REQUIRE(rdata->type == 107);
00156         REQUIRE(target != NULL);
00157         REQUIRE(rdata->length != 0);
00158 
00159         lp->common.rdclass = rdata->rdclass;
00160         lp->common.rdtype = rdata->type;
00161         ISC_LINK_INIT(&lp->common, link);
00162 
00163         dns_name_init(&name, NULL);
00164         dns_rdata_toregion(rdata, &region);
00165         lp->pref = uint16_fromregion(&region);
00166         isc_region_consume(&region, 2);
00167         dns_name_fromregion(&name, &region);
00168         dns_name_init(&lp->lp, NULL);
00169         RETERR(name_duporclone(&name, mctx, &lp->lp));
00170         lp->mctx = mctx;
00171         return (ISC_R_SUCCESS);
00172 }
00173 
00174 static inline void
00175 freestruct_lp(ARGS_FREESTRUCT) {
00176         dns_rdata_lp_t *lp = source;
00177 
00178         REQUIRE(source != NULL);
00179         REQUIRE(lp->common.rdtype == 107);
00180 
00181         if (lp->mctx == NULL)
00182                 return;
00183 
00184         dns_name_free(&lp->lp, lp->mctx);
00185         lp->mctx = NULL;
00186 }
00187 
00188 static inline isc_result_t
00189 additionaldata_lp(ARGS_ADDLDATA) {
00190         dns_name_t name;
00191         dns_offsets_t offsets;
00192         isc_region_t region;
00193         isc_result_t result;
00194 
00195         REQUIRE(rdata->type == 107);
00196 
00197         dns_name_init(&name, offsets);
00198         dns_rdata_toregion(rdata, &region);
00199         isc_region_consume(&region, 2);
00200         dns_name_fromregion(&name, &region);
00201 
00202         result = (add)(arg, &name, dns_rdatatype_l32);
00203         if (result != ISC_R_SUCCESS)
00204                 return (result);
00205         return ((add)(arg, &name, dns_rdatatype_l64));
00206 }
00207 
00208 static inline isc_result_t
00209 digest_lp(ARGS_DIGEST) {
00210         isc_region_t region;
00211 
00212         REQUIRE(rdata->type == 107);
00213 
00214         dns_rdata_toregion(rdata, &region);
00215         return ((digest)(arg, &region));
00216 }
00217 
00218 static inline isc_boolean_t
00219 checkowner_lp(ARGS_CHECKOWNER) {
00220 
00221         REQUIRE(type == 107);
00222 
00223         UNUSED(type);
00224         UNUSED(rdclass);
00225         UNUSED(name);
00226         UNUSED(wildcard);
00227 
00228         return (ISC_TRUE);
00229 }
00230 
00231 static inline isc_boolean_t
00232 checknames_lp(ARGS_CHECKNAMES) {
00233 
00234         REQUIRE(rdata->type == 107);
00235 
00236         UNUSED(bad);
00237         UNUSED(owner);
00238 
00239         return (ISC_TRUE);
00240 }
00241 
00242 static inline int
00243 casecompare_lp(ARGS_COMPARE) {
00244         dns_name_t name1;
00245         dns_name_t name2;
00246         isc_region_t region1;
00247         isc_region_t region2;
00248         int order;
00249 
00250         REQUIRE(rdata1->type == rdata2->type);
00251         REQUIRE(rdata1->rdclass == rdata2->rdclass);
00252         REQUIRE(rdata1->type == 107);
00253         REQUIRE(rdata1->length != 0);
00254         REQUIRE(rdata2->length != 0);
00255 
00256         order = memcmp(rdata1->data, rdata2->data, 2);
00257         if (order != 0)
00258                 return (order < 0 ? -1 : 1);
00259 
00260         dns_name_init(&name1, NULL);
00261         dns_name_init(&name2, NULL);
00262 
00263         dns_rdata_toregion(rdata1, &region1);
00264         dns_rdata_toregion(rdata2, &region2);
00265 
00266         isc_region_consume(&region1, 2);
00267         isc_region_consume(&region2, 2);
00268 
00269         dns_name_fromregion(&name1, &region1);
00270         dns_name_fromregion(&name2, &region2);
00271 
00272         return (dns_name_rdatacompare(&name1, &name2));
00273 }
00274 
00275 #endif  /* RDATA_GENERIC_LP_107_C */

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