rp_17.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004, 2005, 2007, 2009  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 1999-2001  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: rp_17.c,v 1.44 2009/12/04 22:06:37 tbox Exp $ */
00019 
00020 /* RFC1183 */
00021 
00022 #ifndef RDATA_GENERIC_RP_17_C
00023 #define RDATA_GENERIC_RP_17_C
00024 
00025 #define RRTYPE_RP_ATTRIBUTES (0)
00026 
00027 static inline isc_result_t
00028 fromtext_rp(ARGS_FROMTEXT) {
00029         isc_token_t token;
00030         dns_name_t name;
00031         isc_buffer_t buffer;
00032         int i;
00033         isc_boolean_t ok;
00034 
00035         REQUIRE(type == 17);
00036 
00037         UNUSED(type);
00038         UNUSED(rdclass);
00039         UNUSED(callbacks);
00040 
00041         origin = (origin != NULL) ? origin : dns_rootname;
00042 
00043         for (i = 0; i < 2; i++) {
00044                 RETERR(isc_lex_getmastertoken(lexer, &token,
00045                                               isc_tokentype_string,
00046                                               ISC_FALSE));
00047                 dns_name_init(&name, NULL);
00048                 buffer_fromregion(&buffer, &token.value.as_region);
00049                 RETTOK(dns_name_fromtext(&name, &buffer, origin,
00050                                          options, target));
00051                 ok = ISC_TRUE;
00052                 if ((options & DNS_RDATA_CHECKNAMES) != 0 && i == 0)
00053                         ok = dns_name_ismailbox(&name);
00054                 if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0)
00055                         RETTOK(DNS_R_BADNAME);
00056                 if (!ok && callbacks != NULL)
00057                         warn_badname(&name, lexer, callbacks);
00058         }
00059         return (ISC_R_SUCCESS);
00060 }
00061 
00062 static inline isc_result_t
00063 totext_rp(ARGS_TOTEXT) {
00064         isc_region_t region;
00065         dns_name_t rmail;
00066         dns_name_t email;
00067         dns_name_t prefix;
00068         isc_boolean_t sub;
00069 
00070         REQUIRE(rdata->type == 17);
00071         REQUIRE(rdata->length != 0);
00072 
00073         dns_name_init(&rmail, NULL);
00074         dns_name_init(&email, NULL);
00075         dns_name_init(&prefix, NULL);
00076 
00077         dns_rdata_toregion(rdata, &region);
00078 
00079         dns_name_fromregion(&rmail, &region);
00080         isc_region_consume(&region, rmail.length);
00081 
00082         dns_name_fromregion(&email, &region);
00083         isc_region_consume(&region, email.length);
00084 
00085         sub = name_prefix(&rmail, tctx->origin, &prefix);
00086         RETERR(dns_name_totext(&prefix, sub, target));
00087 
00088         RETERR(str_totext(" ", target));
00089 
00090         sub = name_prefix(&email, tctx->origin, &prefix);
00091         return (dns_name_totext(&prefix, sub, target));
00092 }
00093 
00094 static inline isc_result_t
00095 fromwire_rp(ARGS_FROMWIRE) {
00096         dns_name_t rmail;
00097         dns_name_t email;
00098 
00099         REQUIRE(type == 17);
00100 
00101         UNUSED(type);
00102         UNUSED(rdclass);
00103 
00104         dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
00105 
00106         dns_name_init(&rmail, NULL);
00107         dns_name_init(&email, NULL);
00108 
00109         RETERR(dns_name_fromwire(&rmail, source, dctx, options, target));
00110         return (dns_name_fromwire(&email, source, dctx, options, target));
00111 }
00112 
00113 static inline isc_result_t
00114 towire_rp(ARGS_TOWIRE) {
00115         isc_region_t region;
00116         dns_name_t rmail;
00117         dns_name_t email;
00118         dns_offsets_t roffsets;
00119         dns_offsets_t eoffsets;
00120 
00121         REQUIRE(rdata->type == 17);
00122         REQUIRE(rdata->length != 0);
00123 
00124         dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
00125         dns_name_init(&rmail, roffsets);
00126         dns_name_init(&email, eoffsets);
00127 
00128         dns_rdata_toregion(rdata, &region);
00129 
00130         dns_name_fromregion(&rmail, &region);
00131         isc_region_consume(&region, rmail.length);
00132 
00133         RETERR(dns_name_towire(&rmail, cctx, target));
00134 
00135         dns_name_fromregion(&rmail, &region);
00136         isc_region_consume(&region, rmail.length);
00137 
00138         return (dns_name_towire(&rmail, cctx, target));
00139 }
00140 
00141 static inline int
00142 compare_rp(ARGS_COMPARE) {
00143         isc_region_t region1;
00144         isc_region_t region2;
00145         dns_name_t name1;
00146         dns_name_t name2;
00147         int order;
00148 
00149         REQUIRE(rdata1->type == rdata2->type);
00150         REQUIRE(rdata1->rdclass == rdata2->rdclass);
00151         REQUIRE(rdata1->type == 17);
00152         REQUIRE(rdata1->length != 0);
00153         REQUIRE(rdata2->length != 0);
00154 
00155         dns_name_init(&name1, NULL);
00156         dns_name_init(&name2, NULL);
00157 
00158         dns_rdata_toregion(rdata1, &region1);
00159         dns_rdata_toregion(rdata2, &region2);
00160 
00161         dns_name_fromregion(&name1, &region1);
00162         dns_name_fromregion(&name2, &region2);
00163 
00164         order = dns_name_rdatacompare(&name1, &name2);
00165         if (order != 0)
00166                 return (order);
00167 
00168         isc_region_consume(&region1, name_length(&name1));
00169         isc_region_consume(&region2, name_length(&name2));
00170 
00171         dns_name_init(&name1, NULL);
00172         dns_name_init(&name2, NULL);
00173 
00174         dns_name_fromregion(&name1, &region1);
00175         dns_name_fromregion(&name2, &region2);
00176 
00177         return (dns_name_rdatacompare(&name1, &name2));
00178 }
00179 
00180 static inline isc_result_t
00181 fromstruct_rp(ARGS_FROMSTRUCT) {
00182         dns_rdata_rp_t *rp = source;
00183         isc_region_t region;
00184 
00185         REQUIRE(type == 17);
00186         REQUIRE(source != NULL);
00187         REQUIRE(rp->common.rdtype == type);
00188         REQUIRE(rp->common.rdclass == rdclass);
00189 
00190         UNUSED(type);
00191         UNUSED(rdclass);
00192 
00193         dns_name_toregion(&rp->mail, &region);
00194         RETERR(isc_buffer_copyregion(target, &region));
00195         dns_name_toregion(&rp->text, &region);
00196         return (isc_buffer_copyregion(target, &region));
00197 }
00198 
00199 static inline isc_result_t
00200 tostruct_rp(ARGS_TOSTRUCT) {
00201         isc_result_t result;
00202         isc_region_t region;
00203         dns_rdata_rp_t *rp = target;
00204         dns_name_t name;
00205 
00206         REQUIRE(rdata->type == 17);
00207         REQUIRE(target != NULL);
00208         REQUIRE(rdata->length != 0);
00209 
00210         rp->common.rdclass = rdata->rdclass;
00211         rp->common.rdtype = rdata->type;
00212         ISC_LINK_INIT(&rp->common, link);
00213 
00214         dns_name_init(&name, NULL);
00215         dns_rdata_toregion(rdata, &region);
00216         dns_name_fromregion(&name, &region);
00217         dns_name_init(&rp->mail, NULL);
00218         RETERR(name_duporclone(&name, mctx, &rp->mail));
00219         isc_region_consume(&region, name_length(&name));
00220         dns_name_fromregion(&name, &region);
00221         dns_name_init(&rp->text, NULL);
00222         result = name_duporclone(&name, mctx, &rp->text);
00223         if (result != ISC_R_SUCCESS)
00224                 goto cleanup;
00225 
00226         rp->mctx = mctx;
00227         return (ISC_R_SUCCESS);
00228 
00229  cleanup:
00230         if (mctx != NULL)
00231                 dns_name_free(&rp->mail, mctx);
00232         return (ISC_R_NOMEMORY);
00233 }
00234 
00235 static inline void
00236 freestruct_rp(ARGS_FREESTRUCT) {
00237         dns_rdata_rp_t *rp = source;
00238 
00239         REQUIRE(source != NULL);
00240         REQUIRE(rp->common.rdtype == 17);
00241 
00242         if (rp->mctx == NULL)
00243                 return;
00244 
00245         dns_name_free(&rp->mail, rp->mctx);
00246         dns_name_free(&rp->text, rp->mctx);
00247         rp->mctx = NULL;
00248 }
00249 
00250 static inline isc_result_t
00251 additionaldata_rp(ARGS_ADDLDATA) {
00252         REQUIRE(rdata->type == 17);
00253 
00254         UNUSED(rdata);
00255         UNUSED(add);
00256         UNUSED(arg);
00257 
00258         return (ISC_R_SUCCESS);
00259 }
00260 
00261 static inline isc_result_t
00262 digest_rp(ARGS_DIGEST) {
00263         isc_region_t r;
00264         dns_name_t name;
00265 
00266         REQUIRE(rdata->type == 17);
00267 
00268         dns_rdata_toregion(rdata, &r);
00269         dns_name_init(&name, NULL);
00270 
00271         dns_name_fromregion(&name, &r);
00272         RETERR(dns_name_digest(&name, digest, arg));
00273         isc_region_consume(&r, name_length(&name));
00274 
00275         dns_name_init(&name, NULL);
00276         dns_name_fromregion(&name, &r);
00277 
00278         return (dns_name_digest(&name, digest, arg));
00279 }
00280 
00281 static inline isc_boolean_t
00282 checkowner_rp(ARGS_CHECKOWNER) {
00283 
00284         REQUIRE(type == 17);
00285 
00286         UNUSED(name);
00287         UNUSED(type);
00288         UNUSED(rdclass);
00289         UNUSED(wildcard);
00290 
00291         return (ISC_TRUE);
00292 }
00293 
00294 static inline isc_boolean_t
00295 checknames_rp(ARGS_CHECKNAMES) {
00296         isc_region_t region;
00297         dns_name_t name;
00298 
00299         REQUIRE(rdata->type == 17);
00300 
00301         UNUSED(owner);
00302 
00303         dns_rdata_toregion(rdata, &region);
00304         dns_name_init(&name, NULL);
00305         dns_name_fromregion(&name, &region);
00306         if (!dns_name_ismailbox(&name)) {
00307                 if (bad != NULL)
00308                                 dns_name_clone(&name, bad);
00309                 return (ISC_FALSE);
00310         }
00311         return (ISC_TRUE);
00312 }
00313 
00314 static inline int
00315 casecompare_rp(ARGS_COMPARE) {
00316         return (compare_rp(rdata1, rdata2));
00317 }
00318 #endif  /* RDATA_GENERIC_RP_17_C */

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