x25_19.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004, 2005, 2007, 2009, 2014  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: x25_19.c,v 1.41 2009/12/04 22:06:37 tbox Exp $ */
00019 
00020 /* Reviewed: Thu Mar 16 16:15:57 PST 2000 by bwelling */
00021 
00022 /* RFC1183 */
00023 
00024 #ifndef RDATA_GENERIC_X25_19_C
00025 #define RDATA_GENERIC_X25_19_C
00026 
00027 #define RRTYPE_X25_ATTRIBUTES (0)
00028 
00029 static inline isc_result_t
00030 fromtext_x25(ARGS_FROMTEXT) {
00031         isc_token_t token;
00032         unsigned int i;
00033 
00034         REQUIRE(type == 19);
00035 
00036         UNUSED(type);
00037         UNUSED(rdclass);
00038         UNUSED(origin);
00039         UNUSED(options);
00040         UNUSED(callbacks);
00041 
00042         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring,
00043                                       ISC_FALSE));
00044         if (token.value.as_textregion.length < 4)
00045                 RETTOK(DNS_R_SYNTAX);
00046         for (i = 0; i < token.value.as_textregion.length; i++)
00047                 if (!isdigit(token.value.as_textregion.base[i] & 0xff))
00048                         RETTOK(ISC_R_RANGE);
00049         RETTOK(txt_fromtext(&token.value.as_textregion, target));
00050         return (ISC_R_SUCCESS);
00051 }
00052 
00053 static inline isc_result_t
00054 totext_x25(ARGS_TOTEXT) {
00055         isc_region_t region;
00056 
00057         UNUSED(tctx);
00058 
00059         REQUIRE(rdata->type == 19);
00060         REQUIRE(rdata->length != 0);
00061 
00062         dns_rdata_toregion(rdata, &region);
00063         return (txt_totext(&region, ISC_TRUE, target));
00064 }
00065 
00066 static inline isc_result_t
00067 fromwire_x25(ARGS_FROMWIRE) {
00068         isc_region_t sr;
00069 
00070         REQUIRE(type == 19);
00071 
00072         UNUSED(type);
00073         UNUSED(dctx);
00074         UNUSED(rdclass);
00075         UNUSED(options);
00076 
00077         isc_buffer_activeregion(source, &sr);
00078         if (sr.length < 5)
00079                 return (DNS_R_FORMERR);
00080         return (txt_fromwire(source, target));
00081 }
00082 
00083 static inline isc_result_t
00084 towire_x25(ARGS_TOWIRE) {
00085         UNUSED(cctx);
00086 
00087         REQUIRE(rdata->type == 19);
00088         REQUIRE(rdata->length != 0);
00089 
00090         return (mem_tobuffer(target, rdata->data, rdata->length));
00091 }
00092 
00093 static inline int
00094 compare_x25(ARGS_COMPARE) {
00095         isc_region_t r1;
00096         isc_region_t r2;
00097 
00098         REQUIRE(rdata1->type == rdata2->type);
00099         REQUIRE(rdata1->rdclass == rdata2->rdclass);
00100         REQUIRE(rdata1->type == 19);
00101         REQUIRE(rdata1->length != 0);
00102         REQUIRE(rdata2->length != 0);
00103 
00104         dns_rdata_toregion(rdata1, &r1);
00105         dns_rdata_toregion(rdata2, &r2);
00106         return (isc_region_compare(&r1, &r2));
00107 }
00108 
00109 static inline isc_result_t
00110 fromstruct_x25(ARGS_FROMSTRUCT) {
00111         dns_rdata_x25_t *x25 = source;
00112         isc_uint8_t i;
00113 
00114         REQUIRE(type == 19);
00115         REQUIRE(source != NULL);
00116         REQUIRE(x25->common.rdtype == type);
00117         REQUIRE(x25->common.rdclass == rdclass);
00118         REQUIRE(x25->x25 != NULL && x25->x25_len != 0);
00119 
00120         UNUSED(type);
00121         UNUSED(rdclass);
00122 
00123         if (x25->x25_len < 4)
00124                 return (ISC_R_RANGE);
00125 
00126         for (i = 0; i < x25->x25_len; i++)
00127                 if (!isdigit(x25->x25[i] & 0xff))
00128                         return (ISC_R_RANGE);
00129 
00130         RETERR(uint8_tobuffer(x25->x25_len, target));
00131         return (mem_tobuffer(target, x25->x25, x25->x25_len));
00132 }
00133 
00134 static inline isc_result_t
00135 tostruct_x25(ARGS_TOSTRUCT) {
00136         dns_rdata_x25_t *x25 = target;
00137         isc_region_t r;
00138 
00139         REQUIRE(rdata->type == 19);
00140         REQUIRE(target != NULL);
00141         REQUIRE(rdata->length != 0);
00142 
00143         x25->common.rdclass = rdata->rdclass;
00144         x25->common.rdtype = rdata->type;
00145         ISC_LINK_INIT(&x25->common, link);
00146 
00147         dns_rdata_toregion(rdata, &r);
00148         x25->x25_len = uint8_fromregion(&r);
00149         isc_region_consume(&r, 1);
00150         x25->x25 = mem_maybedup(mctx, r.base, x25->x25_len);
00151         if (x25->x25 == NULL)
00152                 return (ISC_R_NOMEMORY);
00153 
00154         x25->mctx = mctx;
00155         return (ISC_R_SUCCESS);
00156 }
00157 
00158 static inline void
00159 freestruct_x25(ARGS_FREESTRUCT) {
00160         dns_rdata_x25_t *x25 = source;
00161         REQUIRE(source != NULL);
00162         REQUIRE(x25->common.rdtype == 19);
00163 
00164         if (x25->mctx == NULL)
00165                 return;
00166 
00167         if (x25->x25 != NULL)
00168                 isc_mem_free(x25->mctx, x25->x25);
00169         x25->mctx = NULL;
00170 }
00171 
00172 static inline isc_result_t
00173 additionaldata_x25(ARGS_ADDLDATA) {
00174         REQUIRE(rdata->type == 19);
00175 
00176         UNUSED(rdata);
00177         UNUSED(add);
00178         UNUSED(arg);
00179 
00180         return (ISC_R_SUCCESS);
00181 }
00182 
00183 static inline isc_result_t
00184 digest_x25(ARGS_DIGEST) {
00185         isc_region_t r;
00186 
00187         REQUIRE(rdata->type == 19);
00188 
00189         dns_rdata_toregion(rdata, &r);
00190 
00191         return ((digest)(arg, &r));
00192 }
00193 
00194 static inline isc_boolean_t
00195 checkowner_x25(ARGS_CHECKOWNER) {
00196 
00197         REQUIRE(type == 19);
00198 
00199         UNUSED(name);
00200         UNUSED(type);
00201         UNUSED(rdclass);
00202         UNUSED(wildcard);
00203 
00204         return (ISC_TRUE);
00205 }
00206 
00207 static inline isc_boolean_t
00208 checknames_x25(ARGS_CHECKNAMES) {
00209 
00210         REQUIRE(rdata->type == 19);
00211 
00212         UNUSED(rdata);
00213         UNUSED(owner);
00214         UNUSED(bad);
00215 
00216         return (ISC_TRUE);
00217 }
00218 
00219 static inline int
00220 casecompare_x25(ARGS_COMPARE) {
00221         return (compare_x25(rdata1, rdata2));
00222 }
00223 
00224 #endif  /* RDATA_GENERIC_X25_19_C */

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