md_3.c revision 3d5cad69ec20157912e95cf3b79316dfb0a314f3
9178881e1bf6a4b01db886b355406c8bed61cc2aMichael Graff/*
a7038d1a0513c8e804937ebc95fc9cb3a46c04f5Mark Andrews * Copyright (C) 1998 Internet Software Consortium.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
9178881e1bf6a4b01db886b355406c8bed61cc2aMichael Graff * Permission to use, copy, modify, and distribute this software for any
9178881e1bf6a4b01db886b355406c8bed61cc2aMichael Graff * purpose with or without fee is hereby granted, provided that the above
9178881e1bf6a4b01db886b355406c8bed61cc2aMichael Graff * copyright notice and this permission notice appear in all copies.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
15a44745412679c30a6d022733925af70a38b715David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
15a44745412679c30a6d022733925af70a38b715David Lawrence * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
15a44745412679c30a6d022733925af70a38b715David Lawrence * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
15a44745412679c30a6d022733925af70a38b715David Lawrence * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
15a44745412679c30a6d022733925af70a38b715David Lawrence * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15a44745412679c30a6d022733925af70a38b715David Lawrence * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
15a44745412679c30a6d022733925af70a38b715David Lawrence * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
15a44745412679c30a6d022733925af70a38b715David Lawrence * SOFTWARE.
9178881e1bf6a4b01db886b355406c8bed61cc2aMichael Graff */
9178881e1bf6a4b01db886b355406c8bed61cc2aMichael Graff
806c235ecf533b98d068b3f8df9d7abbe1e30cf9Mark Andrews /* $Id: md_3.c,v 1.4 1999/01/20 05:20:20 marka Exp $ */
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
9178881e1bf6a4b01db886b355406c8bed61cc2aMichael Graff#ifndef RDATA_GENERIC_MD_3_H
9178881e1bf6a4b01db886b355406c8bed61cc2aMichael Graff#define RDATA_GENERIC_MD_3_H
9178881e1bf6a4b01db886b355406c8bed61cc2aMichael Graff
9178881e1bf6a4b01db886b355406c8bed61cc2aMichael Graffstatic dns_result_t
9178881e1bf6a4b01db886b355406c8bed61cc2aMichael Grafffromtext_md(dns_rdataclass_t class, dns_rdatatype_t type,
9178881e1bf6a4b01db886b355406c8bed61cc2aMichael Graff isc_lex_t *lexer, dns_name_t *origin,
ce24330566b66a5ca8522fa948fb36b94a4d6981Mark Andrews isc_boolean_t downcase, isc_buffer_t *target) {
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_token_t token;
ce24330566b66a5ca8522fa948fb36b94a4d6981Mark Andrews isc_result_t result;
6028d1ce0380d0ba7f6c6ecd1ad20b31ddd1becbDavid Lawrence dns_name_t name;
364a82f7c25b62967678027043425201a5e5171aBob Halley isc_buffer_t buffer;
9178881e1bf6a4b01db886b355406c8bed61cc2aMichael Graff unsigned int options = ISC_LEXOPT_EOL | ISC_LEXOPT_EOF;
09f22ac5b09e70bc526015f37168ba33e21ea91fDavid Lawrence
09f22ac5b09e70bc526015f37168ba33e21ea91fDavid Lawrence REQUIRE(type == 3);
7d823f705d9d3a8cb4d43fcf11249515e2845364Andreas Gustafsson
531eafa3026663020f4a2ac5587cce44341e3442Andreas Gustafsson class = class; /*unused*/
9178881e1bf6a4b01db886b355406c8bed61cc2aMichael Graff
5bd76af084edfdcd1cb4db9453ac781d32dde6f7Mark Andrews result = isc_lex_gettoken(lexer, options, &token);
f9df80f4348ef68043903efa08299480324f4823Michael Graff if (result != ISC_R_SUCCESS)
f9df80f4348ef68043903efa08299480324f4823Michael Graff return (DNS_R_UNEXPECTED);
09f22ac5b09e70bc526015f37168ba33e21ea91fDavid Lawrence if (token.type != isc_tokentype_string) {
0f80bfec687db08a6e6ce945ef1d818da06c7ca9Brian Wellington isc_lex_ungettoken(lexer, &token);
09f22ac5b09e70bc526015f37168ba33e21ea91fDavid Lawrence if (token.type == isc_tokentype_eol ||
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington token.type == isc_tokentype_eof)
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington return(DNS_R_UNEXPECTEDEND);
9178881e1bf6a4b01db886b355406c8bed61cc2aMichael Graff return (DNS_R_UNEXPECTED);
75ec9bc9c7b4f2485647414330122e7b8e188097Andreas Gustafsson }
ac77fece9a62537a9e0e5852498ebeda7b2978c3Bob Halley
97e7d389d54a9e3a1ba8313ed140b04afabc7081Michael Graff dns_name_init(&name, NULL);
97e7d389d54a9e3a1ba8313ed140b04afabc7081Michael Graff buffer_fromregion(&buffer, &token.value.as_region,
ac77fece9a62537a9e0e5852498ebeda7b2978c3Bob Halley ISC_BUFFERTYPE_TEXT);
ac77fece9a62537a9e0e5852498ebeda7b2978c3Bob Halley origin = (origin != NULL) ? origin : dns_rootname;
ac77fece9a62537a9e0e5852498ebeda7b2978c3Bob Halley return (dns_name_fromtext(&name, &buffer, origin, downcase, target));
ac77fece9a62537a9e0e5852498ebeda7b2978c3Bob Halley}
f9df80f4348ef68043903efa08299480324f4823Michael Graff
f9df80f4348ef68043903efa08299480324f4823Michael Graffstatic dns_result_t
f9df80f4348ef68043903efa08299480324f4823Michael Grafftotext_md(dns_rdata_t *rdata, dns_name_t *origin, isc_buffer_t *target) {
f9df80f4348ef68043903efa08299480324f4823Michael Graff isc_region_t region;
f9df80f4348ef68043903efa08299480324f4823Michael Graff dns_name_t name;
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington dns_name_t prefix;
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington isc_boolean_t sub;
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington REQUIRE(rdata->type == 3);
1ed4ba5a1fcb6aecd1c92fdcc75c6b4bbb7cc60fMichael Sawyer
1ed4ba5a1fcb6aecd1c92fdcc75c6b4bbb7cc60fMichael Sawyer dns_name_init(&name, NULL);
f9df80f4348ef68043903efa08299480324f4823Michael Graff dns_rdata_toregion(rdata, &region);
f9df80f4348ef68043903efa08299480324f4823Michael Graff dns_name_fromregion(&name, &region);
f9df80f4348ef68043903efa08299480324f4823Michael Graff
f9df80f4348ef68043903efa08299480324f4823Michael Graff sub = name_prefix(&name, origin, &prefix);
97e7d389d54a9e3a1ba8313ed140b04afabc7081Michael Graff
f9df80f4348ef68043903efa08299480324f4823Michael Graff return(dns_name_totext(&prefix, sub, target));
e223094b2248afa2697c531f75e6f84855638becMichael Graff}
b02262cbcd550c63f85df76edc6fff556ea5e95dMichael Graff
be066f0629a12e11bc17f27671036b3f451bd5eaBrian Wellingtonstatic dns_result_t
b02262cbcd550c63f85df76edc6fff556ea5e95dMichael Grafffromwire_md(dns_rdataclass_t class, dns_rdatatype_t type,
b02262cbcd550c63f85df76edc6fff556ea5e95dMichael Graff isc_buffer_t *source, dns_decompress_t *dctx,
b02262cbcd550c63f85df76edc6fff556ea5e95dMichael Graff isc_boolean_t downcase, isc_buffer_t *target) {
f9df80f4348ef68043903efa08299480324f4823Michael Graff dns_name_t name;
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer REQUIRE(type == 3);
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer class = class; /*unused*/
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer dns_name_init(&name, NULL);
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer return (dns_name_fromwire(&name, source, dctx, downcase, target));
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer}
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyerstatic dns_result_t
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyertowire_md(dns_rdata_t *rdata, dns_compress_t *cctx, isc_buffer_t *target) {
58c40ca8bda08458804d7f15cf97942dea2a17acMichael Sawyer dns_name_t name;
58c40ca8bda08458804d7f15cf97942dea2a17acMichael Sawyer isc_region_t region;
58c40ca8bda08458804d7f15cf97942dea2a17acMichael Sawyer
58c40ca8bda08458804d7f15cf97942dea2a17acMichael Sawyer REQUIRE(rdata->type == 3);
58c40ca8bda08458804d7f15cf97942dea2a17acMichael Sawyer
58c40ca8bda08458804d7f15cf97942dea2a17acMichael Sawyer dns_name_init(&name, NULL);
58c40ca8bda08458804d7f15cf97942dea2a17acMichael Sawyer dns_rdata_toregion(rdata, &region);
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence dns_name_fromregion(&name, &region);
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer return (dns_name_towire(&name, cctx, target));
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer}
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyerstatic int
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyercompare_md(dns_rdata_t *rdata1, dns_rdata_t *rdata2) {
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer dns_name_t name1;
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer dns_name_t name2;
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer isc_region_t region1;
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer isc_region_t region2;
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer REQUIRE(rdata1->type == rdata2->type);
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer REQUIRE(rdata1->class == rdata2->class);
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer REQUIRE(rdata1->type == 3);
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer dns_name_init(&name1, NULL);
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer dns_name_init(&name2, NULL);
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence dns_rdata_toregion(rdata1, &region1);
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer dns_rdata_toregion(rdata2, &region2);
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer dns_name_fromregion(&name1, &region1);
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer dns_name_fromregion(&name2, &region2);
da5d1cf1b1aa29ae53a0427be49291b04bd60549Mark Andrews
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer return (dns_name_compare(&name1, &name2));
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer}
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyerstatic dns_result_t
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyerfromstruct_md(dns_rdataclass_t class, dns_rdatatype_t type, void *source,
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer isc_buffer_t *target) {
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer REQUIRE(type == 3);
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer class = class; /*unused*/
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer source = source;
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer target = target;
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer
c95a89b433e42ecf9108b6c263f405fecc0d8a65Michael Sawyer return (DNS_R_NOTIMPLEMENTED);
f9df80f4348ef68043903efa08299480324f4823Michael Graff}
f9df80f4348ef68043903efa08299480324f4823Michael Graff
f9df80f4348ef68043903efa08299480324f4823Michael Graffstatic dns_result_t
f9df80f4348ef68043903efa08299480324f4823Michael Grafftostruct_md(dns_rdata_t *rdata, void *target) {
f9df80f4348ef68043903efa08299480324f4823Michael Graff
f9df80f4348ef68043903efa08299480324f4823Michael Graff REQUIRE(rdata->type == 3);
97e7d389d54a9e3a1ba8313ed140b04afabc7081Michael Graff
f9df80f4348ef68043903efa08299480324f4823Michael Graff target = target;
f9df80f4348ef68043903efa08299480324f4823Michael Graff
f9df80f4348ef68043903efa08299480324f4823Michael Graff return (DNS_R_NOTIMPLEMENTED);
9178881e1bf6a4b01db886b355406c8bed61cc2aMichael Graff}
97e7d389d54a9e3a1ba8313ed140b04afabc7081Michael Graff#endif /* RDATA_GENERIC_MD_3_H */
97e7d389d54a9e3a1ba8313ed140b04afabc7081Michael Graff