minfo_14.c revision 5d51e67c3b4f35c1be742574aacc1d88fe6ed444
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews/*
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Copyright (C) 1998 Internet Software Consortium.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews *
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Permission to use, copy, modify, and distribute this software for any
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * purpose with or without fee is hereby granted, provided that the above
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * copyright notice and this permission notice appear in all copies.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews *
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * SOFTWARE.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#ifndef RDATA_TYPE_14_MINFO_H
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#define RDATA_TYPE_14_MINFO_H
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic dns_result_t
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsfromtext_minfo(dns_rdataclass_t class, dns_rdatatype_t type,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_lex_t *lexer, dns_name_t *origin,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_boolean_t downcase, isc_buffer_t *target) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_token_t token;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_result_t result;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_t name;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_buffer_t buffer;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews class = class; /*unused*/
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (isc_lex_gettoken(lexer, 0, &token) != ISC_R_SUCCESS)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (DNS_R_UNKNOWN);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (token.type != isc_tokentype_string)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (DNS_R_UNKNOWN);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_init(&name, NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews buffer_fromregion(&buffer, &token.value.as_region,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews ISC_BUFFERTYPE_TEXT);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews origin = (origin != NULL) ? origin : dns_rootname;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = dns_name_fromtext(&name, &buffer, origin, downcase, target);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (result != DNS_R_SUCCESS)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (result);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (isc_lex_gettoken(lexer, 0, &token) != ISC_R_SUCCESS)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (DNS_R_UNKNOWN);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (token.type != isc_tokentype_string)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (DNS_R_UNKNOWN);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_init(&name, NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews buffer_fromregion(&buffer, &token.value.as_region,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews ISC_BUFFERTYPE_TEXT);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews origin = (origin != NULL) ? origin : dns_rootname;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (dns_name_fromtext(&name, &buffer, origin, downcase, target));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic dns_result_t
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewstotext_minfo(dns_rdata_t *rdata, dns_name_t *origin, isc_buffer_t *target) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_t region;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_t rmail;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_t email;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_t prefix;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_result_t result;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_boolean_t sub;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews INSIST(rdata->type == 14);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_init(&rmail, NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_init(&email, NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_init(&prefix, NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_rdata_toregion(rdata, &region);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_fromregion(&rmail, &region);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_consume(&region, rmail.length);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_fromregion(&email, &region);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_consume(&region, email.length);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews sub = name_prefix(&rmail, origin, &prefix);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = dns_name_totext(&prefix, sub, target);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (result != DNS_R_SUCCESS)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (result);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = str_totext(" ", target);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (result != DNS_R_SUCCESS)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (result);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews sub = name_prefix(&email, origin, &prefix);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = dns_name_totext(&prefix, sub, target);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (result != DNS_R_SUCCESS)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (result);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (DNS_R_SUCCESS);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic dns_result_t
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsfromwire_minfo(dns_rdataclass_t class, dns_rdatatype_t type,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_buffer_t *source, dns_decompress_t *dctx,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_boolean_t downcase, isc_buffer_t *target) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_t rmail;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_t email;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_result_t result;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews INSIST(type == 14);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews class = class; /*unused*/
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_init(&rmail, NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_init(&email, NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = dns_name_fromwire(&rmail, source, dctx, downcase, target);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (result != DNS_R_SUCCESS)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (result);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (dns_name_fromwire(&email, source, dctx, downcase, target));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic dns_result_t
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewstowire_minfo(dns_rdata_t *rdata, dns_compress_t *cctx, isc_buffer_t *target) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_t region;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_t rmail;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_t email;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_result_t result;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews INSIST(rdata->type == 14);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_init(&rmail, NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_init(&email, NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_rdata_toregion(rdata, &region);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_fromregion(&rmail, &region);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_consume(&region, rmail.length);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = dns_name_towire(&rmail, cctx, target);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (result != DNS_R_SUCCESS)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (result);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_fromregion(&rmail, &region);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_consume(&region, rmail.length);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = dns_name_towire(&rmail, cctx, target);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (DNS_R_SUCCESS);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic int
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewscompare_minfo(dns_rdata_t *rdata1, dns_rdata_t *rdata2) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_t region1;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_t region2;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_t name1;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_t name2;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews int result;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews INSIST(rdata1->type == 14);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews INSIST(rdata2->type == 14);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_init(&name1, NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_init(&name2, NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_rdata_toregion(rdata1, &region1);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_rdata_toregion(rdata2, &region1);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_fromregion(&name1, &region1);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_fromregion(&name2, &region2);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = dns_name_compare(&name1, &name2);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (result != 0)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (result);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_consume(&region1, name1.length);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_consume(&region2, name2.length);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_init(&name1, NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_init(&name2, NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_fromregion(&name1, &region1);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_fromregion(&name2, &region2);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = dns_name_compare(&name1, &name2);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (result);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic dns_result_t
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsfromstruct_minfo(dns_rdataclass_t class, dns_rdatatype_t type, void *source,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_buffer_t *target) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews class = class;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews type = type;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews source = source;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews target = target;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (DNS_R_NOTIMPLEMENTED);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic dns_result_t
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewstostruct_minfo(dns_rdata_t *rdata, void *target) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews rdata = rdata;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews target = target;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (DNS_R_NOTIMPLEMENTED);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#endif