nsap_22.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004, 2005, 2007, 2009, 2013  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 1999-2002  Internet Software Consortium.
00004  *
00005  * Permission to use, copy, modify, and/or distribute this software for any
00006  * purpose with or without fee is hereby granted, provided that the above
00007  * copyright notice and this permission notice appear in all copies.
00008  *
00009  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00010  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00011  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00012  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00013  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00014  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00015  * PERFORMANCE OF THIS SOFTWARE.
00016  */
00017 
00018 /* $Id: nsap_22.c,v 1.44 2009/12/04 22:06:37 tbox Exp $ */
00019 
00020 /* Reviewed: Fri Mar 17 10:41:07 PST 2000 by gson */
00021 
00022 /* RFC1706 */
00023 
00024 #ifndef RDATA_IN_1_NSAP_22_C
00025 #define RDATA_IN_1_NSAP_22_C
00026 
00027 #define RRTYPE_NSAP_ATTRIBUTES (0)
00028 
00029 static inline isc_result_t
00030 fromtext_in_nsap(ARGS_FROMTEXT) {
00031         isc_token_t token;
00032         isc_textregion_t *sr;
00033         int n;
00034         int digits;
00035         unsigned char c = 0;
00036 
00037         REQUIRE(type == 22);
00038         REQUIRE(rdclass == 1);
00039 
00040         UNUSED(type);
00041         UNUSED(origin);
00042         UNUSED(options);
00043         UNUSED(rdclass);
00044         UNUSED(callbacks);
00045 
00046         /* 0x<hex.string.with.periods> */
00047         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
00048                                       ISC_FALSE));
00049         sr = &token.value.as_textregion;
00050         if (sr->length < 2)
00051                 RETTOK(ISC_R_UNEXPECTEDEND);
00052         if (sr->base[0] != '0' || (sr->base[1] != 'x' && sr->base[1] != 'X'))
00053                 RETTOK(DNS_R_SYNTAX);
00054         isc_textregion_consume(sr, 2);
00055         digits = 0;
00056         while (sr->length > 0) {
00057                 if (sr->base[0] == '.') {
00058                         isc_textregion_consume(sr, 1);
00059                         continue;
00060                 }
00061                 if ((n = hexvalue(sr->base[0])) == -1)
00062                         RETTOK(DNS_R_SYNTAX);
00063                 c <<= 4;
00064                 c += n;
00065                 if (++digits == 2) {
00066                         RETERR(mem_tobuffer(target, &c, 1));
00067                         digits = 0;
00068                 }
00069                 isc_textregion_consume(sr, 1);
00070         }
00071         if (digits)
00072                 RETTOK(ISC_R_UNEXPECTEDEND);
00073         return (ISC_R_SUCCESS);
00074 }
00075 
00076 static inline isc_result_t
00077 totext_in_nsap(ARGS_TOTEXT) {
00078         isc_region_t region;
00079         char buf[sizeof("xx")];
00080 
00081         REQUIRE(rdata->type == 22);
00082         REQUIRE(rdata->rdclass == 1);
00083         REQUIRE(rdata->length != 0);
00084 
00085         UNUSED(tctx);
00086 
00087         dns_rdata_toregion(rdata, &region);
00088         RETERR(str_totext("0x", target));
00089         while (region.length != 0) {
00090                 sprintf(buf, "%02x", region.base[0]);
00091                 isc_region_consume(&region, 1);
00092                 RETERR(str_totext(buf, target));
00093         }
00094         return (ISC_R_SUCCESS);
00095 }
00096 
00097 static inline isc_result_t
00098 fromwire_in_nsap(ARGS_FROMWIRE) {
00099         isc_region_t region;
00100 
00101         REQUIRE(type == 22);
00102         REQUIRE(rdclass == 1);
00103 
00104         UNUSED(type);
00105         UNUSED(dctx);
00106         UNUSED(options);
00107         UNUSED(rdclass);
00108 
00109         isc_buffer_activeregion(source, &region);
00110         if (region.length < 1)
00111                 return (ISC_R_UNEXPECTEDEND);
00112 
00113         RETERR(mem_tobuffer(target, region.base, region.length));
00114         isc_buffer_forward(source, region.length);
00115         return (ISC_R_SUCCESS);
00116 }
00117 
00118 static inline isc_result_t
00119 towire_in_nsap(ARGS_TOWIRE) {
00120         REQUIRE(rdata->type == 22);
00121         REQUIRE(rdata->rdclass == 1);
00122         REQUIRE(rdata->length != 0);
00123 
00124         UNUSED(cctx);
00125 
00126         return (mem_tobuffer(target, rdata->data, rdata->length));
00127 }
00128 
00129 static inline int
00130 compare_in_nsap(ARGS_COMPARE) {
00131         isc_region_t r1;
00132         isc_region_t r2;
00133 
00134         REQUIRE(rdata1->type == rdata2->type);
00135         REQUIRE(rdata1->rdclass == rdata2->rdclass);
00136         REQUIRE(rdata1->type == 22);
00137         REQUIRE(rdata1->rdclass == 1);
00138         REQUIRE(rdata1->length != 0);
00139         REQUIRE(rdata2->length != 0);
00140 
00141         dns_rdata_toregion(rdata1, &r1);
00142         dns_rdata_toregion(rdata2, &r2);
00143         return (isc_region_compare(&r1, &r2));
00144 }
00145 
00146 static inline isc_result_t
00147 fromstruct_in_nsap(ARGS_FROMSTRUCT) {
00148         dns_rdata_in_nsap_t *nsap = source;
00149 
00150         REQUIRE(type == 22);
00151         REQUIRE(rdclass == 1);
00152         REQUIRE(source != NULL);
00153         REQUIRE(nsap->common.rdtype == type);
00154         REQUIRE(nsap->common.rdclass == rdclass);
00155         REQUIRE(nsap->nsap != NULL || nsap->nsap_len == 0);
00156 
00157         UNUSED(type);
00158         UNUSED(rdclass);
00159 
00160         return (mem_tobuffer(target, nsap->nsap, nsap->nsap_len));
00161 }
00162 
00163 static inline isc_result_t
00164 tostruct_in_nsap(ARGS_TOSTRUCT) {
00165         dns_rdata_in_nsap_t *nsap = target;
00166         isc_region_t r;
00167 
00168         REQUIRE(rdata->type == 22);
00169         REQUIRE(rdata->rdclass == 1);
00170         REQUIRE(target != NULL);
00171         REQUIRE(rdata->length != 0);
00172 
00173         nsap->common.rdclass = rdata->rdclass;
00174         nsap->common.rdtype = rdata->type;
00175         ISC_LINK_INIT(&nsap->common, link);
00176 
00177         dns_rdata_toregion(rdata, &r);
00178         nsap->nsap_len = r.length;
00179         nsap->nsap = mem_maybedup(mctx, r.base, r.length);
00180         if (nsap->nsap == NULL)
00181                 return (ISC_R_NOMEMORY);
00182 
00183         nsap->mctx = mctx;
00184         return (ISC_R_SUCCESS);
00185 }
00186 
00187 static inline void
00188 freestruct_in_nsap(ARGS_FREESTRUCT) {
00189         dns_rdata_in_nsap_t *nsap = source;
00190 
00191         REQUIRE(source != NULL);
00192         REQUIRE(nsap->common.rdclass == 1);
00193         REQUIRE(nsap->common.rdtype == 22);
00194 
00195         if (nsap->mctx == NULL)
00196                 return;
00197 
00198         if (nsap->nsap != NULL)
00199                 isc_mem_free(nsap->mctx, nsap->nsap);
00200         nsap->mctx = NULL;
00201 }
00202 
00203 static inline isc_result_t
00204 additionaldata_in_nsap(ARGS_ADDLDATA) {
00205         REQUIRE(rdata->type == 22);
00206         REQUIRE(rdata->rdclass == 1);
00207 
00208         UNUSED(rdata);
00209         UNUSED(add);
00210         UNUSED(arg);
00211 
00212         return (ISC_R_SUCCESS);
00213 }
00214 
00215 static inline isc_result_t
00216 digest_in_nsap(ARGS_DIGEST) {
00217         isc_region_t r;
00218 
00219         REQUIRE(rdata->type == 22);
00220         REQUIRE(rdata->rdclass == 1);
00221 
00222         dns_rdata_toregion(rdata, &r);
00223 
00224         return ((digest)(arg, &r));
00225 }
00226 
00227 static inline isc_boolean_t
00228 checkowner_in_nsap(ARGS_CHECKOWNER) {
00229 
00230         REQUIRE(type == 22);
00231         REQUIRE(rdclass == 1);
00232 
00233         UNUSED(name);
00234         UNUSED(type);
00235         UNUSED(rdclass);
00236         UNUSED(wildcard);
00237 
00238         return (ISC_TRUE);
00239 }
00240 
00241 static inline isc_boolean_t
00242 checknames_in_nsap(ARGS_CHECKNAMES) {
00243 
00244         REQUIRE(rdata->type == 22);
00245         REQUIRE(rdata->rdclass == 1);
00246 
00247         UNUSED(rdata);
00248         UNUSED(owner);
00249         UNUSED(bad);
00250 
00251         return (ISC_TRUE);
00252 }
00253 
00254 static inline int
00255 casecompare_in_nsap(ARGS_COMPARE) {
00256         return (compare_in_nsap(rdata1, rdata2));
00257 }
00258 
00259 #endif  /* RDATA_IN_1_NSAP_22_C */

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