minfo_14.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004, 2007, 2009  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 1998-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: minfo_14.c,v 1.47 2009/12/04 22:06:37 tbox Exp $ */
00019 
00020 /* reviewed: Wed Mar 15 17:45:32 PST 2000 by brister */
00021 
00022 #ifndef RDATA_GENERIC_MINFO_14_C
00023 #define RDATA_GENERIC_MINFO_14_C
00024 
00025 #define RRTYPE_MINFO_ATTRIBUTES (0)
00026 
00027 static inline isc_result_t
00028 fromtext_minfo(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 == 14);
00036 
00037         UNUSED(type);
00038         UNUSED(rdclass);
00039         UNUSED(callbacks);
00040 
00041         for (i = 0; i < 2; i++) {
00042                 RETERR(isc_lex_getmastertoken(lexer, &token,
00043                                               isc_tokentype_string,
00044                                               ISC_FALSE));
00045                 dns_name_init(&name, NULL);
00046                 buffer_fromregion(&buffer, &token.value.as_region);
00047                 origin = (origin != NULL) ? origin : dns_rootname;
00048                 RETTOK(dns_name_fromtext(&name, &buffer, origin,
00049                                          options, target));
00050                 ok = ISC_TRUE;
00051                 if ((options & DNS_RDATA_CHECKNAMES) != 0)
00052                         ok = dns_name_ismailbox(&name);
00053                 if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0)
00054                         RETTOK(DNS_R_BADNAME);
00055                 if (!ok && callbacks != NULL)
00056                         warn_badname(&name, lexer, callbacks);
00057         }
00058         return (ISC_R_SUCCESS);
00059 }
00060 
00061 static inline isc_result_t
00062 totext_minfo(ARGS_TOTEXT) {
00063         isc_region_t region;
00064         dns_name_t rmail;
00065         dns_name_t email;
00066         dns_name_t prefix;
00067         isc_boolean_t sub;
00068 
00069         REQUIRE(rdata->type == 14);
00070         REQUIRE(rdata->length != 0);
00071 
00072         dns_name_init(&rmail, NULL);
00073         dns_name_init(&email, NULL);
00074         dns_name_init(&prefix, NULL);
00075 
00076         dns_rdata_toregion(rdata, &region);
00077 
00078         dns_name_fromregion(&rmail, &region);
00079         isc_region_consume(&region, rmail.length);
00080 
00081         dns_name_fromregion(&email, &region);
00082         isc_region_consume(&region, email.length);
00083 
00084         sub = name_prefix(&rmail, tctx->origin, &prefix);
00085 
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_minfo(ARGS_FROMWIRE) {
00096         dns_name_t rmail;
00097         dns_name_t email;
00098 
00099         REQUIRE(type == 14);
00100 
00101         UNUSED(type);
00102         UNUSED(rdclass);
00103 
00104         dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
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_minfo(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 == 14);
00122         REQUIRE(rdata->length != 0);
00123 
00124         dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
00125 
00126         dns_name_init(&rmail, roffsets);
00127         dns_name_init(&email, eoffsets);
00128 
00129         dns_rdata_toregion(rdata, &region);
00130 
00131         dns_name_fromregion(&rmail, &region);
00132         isc_region_consume(&region, name_length(&rmail));
00133 
00134         RETERR(dns_name_towire(&rmail, cctx, target));
00135 
00136         dns_name_fromregion(&rmail, &region);
00137         isc_region_consume(&region, rmail.length);
00138 
00139         return (dns_name_towire(&rmail, cctx, target));
00140 }
00141 
00142 static inline int
00143 compare_minfo(ARGS_COMPARE) {
00144         isc_region_t region1;
00145         isc_region_t region2;
00146         dns_name_t name1;
00147         dns_name_t name2;
00148         int order;
00149 
00150         REQUIRE(rdata1->type == rdata2->type);
00151         REQUIRE(rdata1->rdclass == rdata2->rdclass);
00152         REQUIRE(rdata1->type == 14);
00153         REQUIRE(rdata1->length != 0);
00154         REQUIRE(rdata2->length != 0);
00155 
00156         dns_name_init(&name1, NULL);
00157         dns_name_init(&name2, NULL);
00158 
00159         dns_rdata_toregion(rdata1, &region1);
00160         dns_rdata_toregion(rdata2, &region2);
00161 
00162         dns_name_fromregion(&name1, &region1);
00163         dns_name_fromregion(&name2, &region2);
00164 
00165         order = dns_name_rdatacompare(&name1, &name2);
00166         if (order != 0)
00167                 return (order);
00168 
00169         isc_region_consume(&region1, name_length(&name1));
00170         isc_region_consume(&region2, name_length(&name2));
00171 
00172         dns_name_init(&name1, NULL);
00173         dns_name_init(&name2, NULL);
00174 
00175         dns_name_fromregion(&name1, &region1);
00176         dns_name_fromregion(&name2, &region2);
00177 
00178         order = dns_name_rdatacompare(&name1, &name2);
00179         return (order);
00180 }
00181 
00182 static inline isc_result_t
00183 fromstruct_minfo(ARGS_FROMSTRUCT) {
00184         dns_rdata_minfo_t *minfo = source;
00185         isc_region_t region;
00186 
00187         REQUIRE(type == 14);
00188         REQUIRE(source != NULL);
00189         REQUIRE(minfo->common.rdtype == type);
00190         REQUIRE(minfo->common.rdclass == rdclass);
00191 
00192         UNUSED(type);
00193         UNUSED(rdclass);
00194 
00195         dns_name_toregion(&minfo->rmailbox, &region);
00196         RETERR(isc_buffer_copyregion(target, &region));
00197         dns_name_toregion(&minfo->emailbox, &region);
00198         return (isc_buffer_copyregion(target, &region));
00199 }
00200 
00201 static inline isc_result_t
00202 tostruct_minfo(ARGS_TOSTRUCT) {
00203         dns_rdata_minfo_t *minfo = target;
00204         isc_region_t region;
00205         dns_name_t name;
00206         isc_result_t result;
00207 
00208         REQUIRE(rdata->type == 14);
00209         REQUIRE(target != NULL);
00210         REQUIRE(rdata->length != 0);
00211 
00212         minfo->common.rdclass = rdata->rdclass;
00213         minfo->common.rdtype = rdata->type;
00214         ISC_LINK_INIT(&minfo->common, link);
00215 
00216         dns_name_init(&name, NULL);
00217         dns_rdata_toregion(rdata, &region);
00218         dns_name_fromregion(&name, &region);
00219         dns_name_init(&minfo->rmailbox, NULL);
00220         RETERR(name_duporclone(&name, mctx, &minfo->rmailbox));
00221         isc_region_consume(&region, name_length(&name));
00222 
00223         dns_name_fromregion(&name, &region);
00224         dns_name_init(&minfo->emailbox, NULL);
00225         result = name_duporclone(&name, mctx, &minfo->emailbox);
00226         if (result != ISC_R_SUCCESS)
00227                 goto cleanup;
00228         minfo->mctx = mctx;
00229         return (ISC_R_SUCCESS);
00230 
00231  cleanup:
00232         if (mctx != NULL)
00233                 dns_name_free(&minfo->rmailbox, mctx);
00234         return (ISC_R_NOMEMORY);
00235 }
00236 
00237 static inline void
00238 freestruct_minfo(ARGS_FREESTRUCT) {
00239         dns_rdata_minfo_t *minfo = source;
00240 
00241         REQUIRE(source != NULL);
00242         REQUIRE(minfo->common.rdtype == 14);
00243 
00244         if (minfo->mctx == NULL)
00245                 return;
00246 
00247         dns_name_free(&minfo->rmailbox, minfo->mctx);
00248         dns_name_free(&minfo->emailbox, minfo->mctx);
00249         minfo->mctx = NULL;
00250 }
00251 
00252 static inline isc_result_t
00253 additionaldata_minfo(ARGS_ADDLDATA) {
00254         REQUIRE(rdata->type == 14);
00255 
00256         UNUSED(rdata);
00257         UNUSED(add);
00258         UNUSED(arg);
00259 
00260         return (ISC_R_SUCCESS);
00261 }
00262 
00263 static inline isc_result_t
00264 digest_minfo(ARGS_DIGEST) {
00265         isc_region_t r;
00266         dns_name_t name;
00267         isc_result_t result;
00268 
00269         REQUIRE(rdata->type == 14);
00270 
00271         dns_rdata_toregion(rdata, &r);
00272         dns_name_init(&name, NULL);
00273         dns_name_fromregion(&name, &r);
00274         result = dns_name_digest(&name, digest, arg);
00275         if (result != ISC_R_SUCCESS)
00276                 return (result);
00277         isc_region_consume(&r, name_length(&name));
00278         dns_name_init(&name, NULL);
00279         dns_name_fromregion(&name, &r);
00280 
00281         return (dns_name_digest(&name, digest, arg));
00282 }
00283 
00284 static inline isc_boolean_t
00285 checkowner_minfo(ARGS_CHECKOWNER) {
00286 
00287         REQUIRE(type == 14);
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_minfo(ARGS_CHECKNAMES) {
00299         isc_region_t region;
00300         dns_name_t name;
00301 
00302         REQUIRE(rdata->type == 14);
00303 
00304         UNUSED(owner);
00305 
00306         dns_rdata_toregion(rdata, &region);
00307         dns_name_init(&name, NULL);
00308         dns_name_fromregion(&name, &region);
00309         if (!dns_name_ismailbox(&name)) {
00310                 if (bad != NULL)
00311                         dns_name_clone(&name, bad);
00312                 return (ISC_FALSE);
00313         }
00314         isc_region_consume(&region, name_length(&name));
00315         dns_name_fromregion(&name, &region);
00316         if (!dns_name_ismailbox(&name)) {
00317                 if (bad != NULL)
00318                         dns_name_clone(&name, bad);
00319                 return (ISC_FALSE);
00320         }
00321         return (ISC_TRUE);
00322 }
00323 
00324 static inline int
00325 casecompare_minfo(ARGS_COMPARE) {
00326         return (compare_minfo(rdata1, rdata2));
00327 }
00328 
00329 #endif  /* RDATA_GENERIC_MINFO_14_C */

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