Commit deaaf943 authored by Mark Andrews's avatar Mark Andrews
Browse files

dns_rdata_compare checked for RFC 1035 types

	converted frometext* to use gettoken()
	converted:
		result = foo();
		if (result != DNS_R_SUCCESS)
			return (result);
	to
		RETERR(foo());
parent 53057070
......@@ -45,6 +45,7 @@ main(int argc, char *argv[]) {
unsigned int options = 0;
unsigned int parens = 0;
dns_rdatatype_t type;
dns_rdatatype_t lasttype = 0;
char outbuf[16*1024];
char inbuf[16*1024];
char wirebuf[16*1024];
......@@ -52,6 +53,7 @@ main(int argc, char *argv[]) {
isc_buffer_t tbuf;
isc_buffer_t wbuf;
dns_rdata_t rdata;
dns_rdata_t last;
int need_eol = 0;
int wire = 0;
dns_compress_t cctx;
......@@ -61,6 +63,8 @@ main(int argc, char *argv[]) {
int len;
int zero = 0;
int debug = 0;
isc_region_t region;
int first = 1;
while ((c = getopt(argc, argv, "dqswtaz")) != -1) {
switch (c) {
......@@ -107,6 +111,7 @@ main(int argc, char *argv[]) {
RUNTIME_CHECK(isc_lex_openstream(lex, stdin) == ISC_R_SUCCESS);
dns_rdata_init(&last);
while ((result = isc_lex_gettoken(lex, options | ISC_LEXOPT_NUMBER,
&token)) == ISC_R_SUCCESS) {
if (debug) fprintf(stdout, "token.type = %d\n", token.type);
......@@ -219,6 +224,24 @@ main(int argc, char *argv[]) {
fprintf(stdout, "\"%.*s\"\n",
(int)tbuf.used, (char*)tbuf.base);
fflush(stdout);
if (lasttype == type) {
fprintf(stdout, "dns_rdata_compare = %d\n",
dns_rdata_compare(&rdata, &last));
}
if (!first) {
free(last.data);
}
dns_rdata_init(&last);
region.base = malloc(region.length = rdata.length);
if (region.base) {
memcpy(region.base, rdata.data, rdata.length);
dns_rdata_fromregion(&last, 1, type, &region);
lasttype = type;
first = 0;
} else
first = 1;
}
if (result != ISC_R_EOF)
printf("Result: %s\n", isc_result_totext(result));
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: rdata.c,v 1.8 1999/01/21 06:02:13 marka Exp $ */
/* $Id: rdata.c,v 1.9 1999/01/22 00:36:54 marka Exp $ */
#include <isc/buffer.h>
#include <isc/lex.h>
......@@ -28,6 +28,12 @@
#include <stdio.h>
#include <isc/assertions.h>
#define RETERR(x) { \
dns_result_t __r = (x); \
if (__r != DNS_R_SUCCESS) \
return (__r); \
}
static dns_result_t txt_totext(isc_region_t *source, isc_buffer_t *target);
static dns_result_t txt_fromtext(isc_textregion_t *source,
isc_buffer_t *target);
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: cname_5.c,v 1.4 1999/01/20 05:20:19 marka Exp $ */
/* $Id: cname_5.c,v 1.5 1999/01/22 00:36:55 marka Exp $ */
#ifndef RDATA_GENERIC_CNAME_5_H
#define RDATA_GENERIC_CNAME_5_H
......@@ -27,21 +27,11 @@ fromtext_cname(dns_rdataclass_t class, dns_rdatatype_t type,
isc_token_t token;
dns_name_t name;
isc_buffer_t buffer;
unsigned int options = ISC_LEXOPT_EOL | ISC_LEXOPT_EOF;
REQUIRE(type == 5);
class = class; /*unused*/
if (isc_lex_gettoken(lexer, options, &token) != ISC_R_SUCCESS)
return (DNS_R_UNEXPECTED);
if (token.type != isc_tokentype_string) {
isc_lex_ungettoken(lexer, &token);
if (token.type == isc_tokentype_eol ||
token.type == isc_tokentype_eof)
return(DNS_R_UNEXPECTEDEND);
return (DNS_R_UNEXPECTED);
}
RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
dns_name_init(&name, NULL);
buffer_fromregion(&buffer, &token.value.as_region,
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: cname_5.h,v 1.4 1999/01/20 05:20:19 marka Exp $ */
/* $Id: cname_5.h,v 1.5 1999/01/22 00:36:55 marka Exp $ */
#ifndef RDATA_GENERIC_CNAME_5_H
#define RDATA_GENERIC_CNAME_5_H
......@@ -27,21 +27,11 @@ fromtext_cname(dns_rdataclass_t class, dns_rdatatype_t type,
isc_token_t token;
dns_name_t name;
isc_buffer_t buffer;
unsigned int options = ISC_LEXOPT_EOL | ISC_LEXOPT_EOF;
REQUIRE(type == 5);
class = class; /*unused*/
if (isc_lex_gettoken(lexer, options, &token) != ISC_R_SUCCESS)
return (DNS_R_UNEXPECTED);
if (token.type != isc_tokentype_string) {
isc_lex_ungettoken(lexer, &token);
if (token.type == isc_tokentype_eol ||
token.type == isc_tokentype_eof)
return(DNS_R_UNEXPECTEDEND);
return (DNS_R_UNEXPECTED);
}
RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
dns_name_init(&name, NULL);
buffer_fromregion(&buffer, &token.value.as_region,
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: hinfo_13.c,v 1.5 1999/01/20 05:20:20 marka Exp $ */
/* $Id: hinfo_13.c,v 1.6 1999/01/22 00:36:55 marka Exp $ */
#ifndef RDATA_GENERIC_HINFO_13_H
#define RDATA_GENERIC_HINFO_13_H
......@@ -25,8 +25,7 @@ fromtext_hinfo(dns_rdataclass_t class, dns_rdatatype_t type,
isc_lex_t *lexer, dns_name_t *origin,
isc_boolean_t downcase, isc_buffer_t *target) {
isc_token_t token;
dns_result_t result;
unsigned int options = ISC_LEXOPT_EOL | ISC_LEXOPT_EOF;
int i;
REQUIRE(type == 13);
......@@ -34,60 +33,32 @@ fromtext_hinfo(dns_rdataclass_t class, dns_rdatatype_t type,
origin = origin; /*unused*/
downcase = downcase; /*unused*/
if (isc_lex_gettoken(lexer, options, &token) != ISC_R_SUCCESS)
return (DNS_R_UNEXPECTED);
if (token.type != isc_tokentype_string) {
isc_lex_ungettoken(lexer, &token);
if (token.type == isc_tokentype_eol ||
token.type == isc_tokentype_eof)
return(DNS_R_UNEXPECTEDEND);
return (DNS_R_UNEXPECTED);
for (i = 0; i < 2 ; i++) {
RETERR(gettoken(lexer, &token, isc_tokentype_string,
ISC_FALSE));
RETERR(txt_fromtext(&token.value.as_textregion, target));
}
result = txt_fromtext(&token.value.as_textregion, target);
if (result != DNS_R_SUCCESS)
return (result);
if (isc_lex_gettoken(lexer, options, &token) != ISC_R_SUCCESS)
return (DNS_R_UNEXPECTED);
if (token.type != isc_tokentype_string) {
isc_lex_ungettoken(lexer, &token);
if (token.type == isc_tokentype_eol ||
token.type == isc_tokentype_eof)
return(DNS_R_UNEXPECTEDEND);
return (DNS_R_UNEXPECTED);
}
return (txt_fromtext(&token.value.as_textregion, target));
return (DNS_R_SUCCESS);
}
static dns_result_t
totext_hinfo(dns_rdata_t *rdata, dns_name_t *origin, isc_buffer_t *target) {
isc_region_t region;
dns_result_t result;
REQUIRE(rdata->type == 13);
origin = origin; /*unused*/
dns_rdata_toregion(rdata, &region);
result = txt_totext(&region, target);
if (result != DNS_R_SUCCESS)
return (result);
result = str_totext(" ", target);
if (result != DNS_R_SUCCESS)
return (result);
result = txt_totext(&region, target);
return (DNS_R_SUCCESS);
RETERR(txt_totext(&region, target));
RETERR(str_totext(" ", target));
return (txt_totext(&region, target));
}
static dns_result_t
fromwire_hinfo(dns_rdataclass_t class, dns_rdatatype_t type,
isc_buffer_t *source, dns_decompress_t *dctx,
isc_boolean_t downcase, isc_buffer_t *target) {
dns_result_t result;
REQUIRE(type == 13);
......@@ -95,10 +66,7 @@ fromwire_hinfo(dns_rdataclass_t class, dns_rdatatype_t type,
class = class; /* unused */
downcase = downcase; /* unused */
result = txt_fromwire(source, target);
if (result != DNS_R_SUCCESS)
return (result);
RETERR(txt_fromwire(source, target));
return (txt_fromwire(source, target));
}
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: hinfo_13.h,v 1.5 1999/01/20 05:20:20 marka Exp $ */
/* $Id: hinfo_13.h,v 1.6 1999/01/22 00:36:55 marka Exp $ */
#ifndef RDATA_GENERIC_HINFO_13_H
#define RDATA_GENERIC_HINFO_13_H
......@@ -25,8 +25,7 @@ fromtext_hinfo(dns_rdataclass_t class, dns_rdatatype_t type,
isc_lex_t *lexer, dns_name_t *origin,
isc_boolean_t downcase, isc_buffer_t *target) {
isc_token_t token;
dns_result_t result;
unsigned int options = ISC_LEXOPT_EOL | ISC_LEXOPT_EOF;
int i;
REQUIRE(type == 13);
......@@ -34,60 +33,32 @@ fromtext_hinfo(dns_rdataclass_t class, dns_rdatatype_t type,
origin = origin; /*unused*/
downcase = downcase; /*unused*/
if (isc_lex_gettoken(lexer, options, &token) != ISC_R_SUCCESS)
return (DNS_R_UNEXPECTED);
if (token.type != isc_tokentype_string) {
isc_lex_ungettoken(lexer, &token);
if (token.type == isc_tokentype_eol ||
token.type == isc_tokentype_eof)
return(DNS_R_UNEXPECTEDEND);
return (DNS_R_UNEXPECTED);
for (i = 0; i < 2 ; i++) {
RETERR(gettoken(lexer, &token, isc_tokentype_string,
ISC_FALSE));
RETERR(txt_fromtext(&token.value.as_textregion, target));
}
result = txt_fromtext(&token.value.as_textregion, target);
if (result != DNS_R_SUCCESS)
return (result);
if (isc_lex_gettoken(lexer, options, &token) != ISC_R_SUCCESS)
return (DNS_R_UNEXPECTED);
if (token.type != isc_tokentype_string) {
isc_lex_ungettoken(lexer, &token);
if (token.type == isc_tokentype_eol ||
token.type == isc_tokentype_eof)
return(DNS_R_UNEXPECTEDEND);
return (DNS_R_UNEXPECTED);
}
return (txt_fromtext(&token.value.as_textregion, target));
return (DNS_R_SUCCESS);
}
static dns_result_t
totext_hinfo(dns_rdata_t *rdata, dns_name_t *origin, isc_buffer_t *target) {
isc_region_t region;
dns_result_t result;
REQUIRE(rdata->type == 13);
origin = origin; /*unused*/
dns_rdata_toregion(rdata, &region);
result = txt_totext(&region, target);
if (result != DNS_R_SUCCESS)
return (result);
result = str_totext(" ", target);
if (result != DNS_R_SUCCESS)
return (result);
result = txt_totext(&region, target);
return (DNS_R_SUCCESS);
RETERR(txt_totext(&region, target));
RETERR(str_totext(" ", target));
return (txt_totext(&region, target));
}
static dns_result_t
fromwire_hinfo(dns_rdataclass_t class, dns_rdatatype_t type,
isc_buffer_t *source, dns_decompress_t *dctx,
isc_boolean_t downcase, isc_buffer_t *target) {
dns_result_t result;
REQUIRE(type == 13);
......@@ -95,10 +66,7 @@ fromwire_hinfo(dns_rdataclass_t class, dns_rdatatype_t type,
class = class; /* unused */
downcase = downcase; /* unused */
result = txt_fromwire(source, target);
if (result != DNS_R_SUCCESS)
return (result);
RETERR(txt_fromwire(source, target));
return (txt_fromwire(source, target));
}
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: mb_7.c,v 1.4 1999/01/20 05:20:20 marka Exp $ */
/* $Id: mb_7.c,v 1.5 1999/01/22 00:36:55 marka Exp $ */
#ifndef RDATA_GENERIC_MB_7_H
#define RDATA_GENERIC_MB_7_H
......@@ -27,21 +27,12 @@ fromtext_mb(dns_rdataclass_t class, dns_rdatatype_t type,
isc_token_t token;
dns_name_t name;
isc_buffer_t buffer;
unsigned int options = ISC_LEXOPT_EOL | ISC_LEXOPT_EOF;
REQUIRE(type == 7);
class = class; /*unused*/
if (isc_lex_gettoken(lexer, options, &token) != ISC_R_SUCCESS)
return (DNS_R_UNEXPECTED);
if (token.type != isc_tokentype_string) {
isc_lex_ungettoken(lexer, &token);
if (token.type == isc_tokentype_eol ||
token.type == isc_tokentype_eof)
return(DNS_R_UNEXPECTEDEND);
return (DNS_R_UNEXPECTED);
}
RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
dns_name_init(&name, NULL);
buffer_fromregion(&buffer, &token.value.as_region,
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: mb_7.h,v 1.4 1999/01/20 05:20:20 marka Exp $ */
/* $Id: mb_7.h,v 1.5 1999/01/22 00:36:55 marka Exp $ */
#ifndef RDATA_GENERIC_MB_7_H
#define RDATA_GENERIC_MB_7_H
......@@ -27,21 +27,12 @@ fromtext_mb(dns_rdataclass_t class, dns_rdatatype_t type,
isc_token_t token;
dns_name_t name;
isc_buffer_t buffer;
unsigned int options = ISC_LEXOPT_EOL | ISC_LEXOPT_EOF;
REQUIRE(type == 7);
class = class; /*unused*/
if (isc_lex_gettoken(lexer, options, &token) != ISC_R_SUCCESS)
return (DNS_R_UNEXPECTED);
if (token.type != isc_tokentype_string) {
isc_lex_ungettoken(lexer, &token);
if (token.type == isc_tokentype_eol ||
token.type == isc_tokentype_eof)
return(DNS_R_UNEXPECTEDEND);
return (DNS_R_UNEXPECTED);
}
RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
dns_name_init(&name, NULL);
buffer_fromregion(&buffer, &token.value.as_region,
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: md_3.c,v 1.4 1999/01/20 05:20:20 marka Exp $ */
/* $Id: md_3.c,v 1.5 1999/01/22 00:36:55 marka Exp $ */
#ifndef RDATA_GENERIC_MD_3_H
#define RDATA_GENERIC_MD_3_H
......@@ -25,25 +25,14 @@ fromtext_md(dns_rdataclass_t class, dns_rdatatype_t type,
isc_lex_t *lexer, dns_name_t *origin,
isc_boolean_t downcase, isc_buffer_t *target) {
isc_token_t token;
isc_result_t result;
dns_name_t name;
isc_buffer_t buffer;
unsigned int options = ISC_LEXOPT_EOL | ISC_LEXOPT_EOF;
REQUIRE(type == 3);
class = class; /*unused*/
result = isc_lex_gettoken(lexer, options, &token);
if (result != ISC_R_SUCCESS)
return (DNS_R_UNEXPECTED);
if (token.type != isc_tokentype_string) {
isc_lex_ungettoken(lexer, &token);
if (token.type == isc_tokentype_eol ||
token.type == isc_tokentype_eof)
return(DNS_R_UNEXPECTEDEND);
return (DNS_R_UNEXPECTED);
}
RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
dns_name_init(&name, NULL);
buffer_fromregion(&buffer, &token.value.as_region,
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: md_3.h,v 1.4 1999/01/20 05:20:20 marka Exp $ */
/* $Id: md_3.h,v 1.5 1999/01/22 00:36:55 marka Exp $ */
#ifndef RDATA_GENERIC_MD_3_H
#define RDATA_GENERIC_MD_3_H
......@@ -25,25 +25,14 @@ fromtext_md(dns_rdataclass_t class, dns_rdatatype_t type,
isc_lex_t *lexer, dns_name_t *origin,
isc_boolean_t downcase, isc_buffer_t *target) {
isc_token_t token;
isc_result_t result;
dns_name_t name;
isc_buffer_t buffer;
unsigned int options = ISC_LEXOPT_EOL | ISC_LEXOPT_EOF;
REQUIRE(type == 3);
class = class; /*unused*/
result = isc_lex_gettoken(lexer, options, &token);
if (result != ISC_R_SUCCESS)
return (DNS_R_UNEXPECTED);
if (token.type != isc_tokentype_string) {
isc_lex_ungettoken(lexer, &token);
if (token.type == isc_tokentype_eol ||
token.type == isc_tokentype_eof)
return(DNS_R_UNEXPECTEDEND);
return (DNS_R_UNEXPECTED);
}
RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
dns_name_init(&name, NULL);
buffer_fromregion(&buffer, &token.value.as_region,
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: mf_4.c,v 1.4 1999/01/20 05:20:20 marka Exp $ */
/* $Id: mf_4.c,v 1.5 1999/01/22 00:36:56 marka Exp $ */
#ifndef RDATA_GENERIC_MF_4_H
#define RDATA_GENERIC_MF_4_H
......@@ -27,21 +27,12 @@ fromtext_mf(dns_rdataclass_t class, dns_rdatatype_t type,
isc_token_t token;
dns_name_t name;
isc_buffer_t buffer;
unsigned int options = ISC_LEXOPT_EOL | ISC_LEXOPT_EOF;
REQUIRE(type == 4);
class = class; /*unused*/
if (isc_lex_gettoken(lexer, options, &token) != ISC_R_SUCCESS)
return (DNS_R_UNEXPECTED);
if (token.type != isc_tokentype_string) {
isc_lex_ungettoken(lexer, &token);
if (token.type == isc_tokentype_eol ||
token.type == isc_tokentype_eof)
return(DNS_R_UNEXPECTEDEND);
return (DNS_R_UNEXPECTED);
}
RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
dns_name_init(&name, NULL);
buffer_fromregion(&buffer, &token.value.as_region,
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: mf_4.h,v 1.4 1999/01/20 05:20:20 marka Exp $ */
/* $Id: mf_4.h,v 1.5 1999/01/22 00:36:56 marka Exp $ */
#ifndef RDATA_GENERIC_MF_4_H
#define RDATA_GENERIC_MF_4_H
......@@ -27,21 +27,12 @@ fromtext_mf(dns_rdataclass_t class, dns_rdatatype_t type,
isc_token_t token;
dns_name_t name;
isc_buffer_t buffer;
unsigned int options = ISC_LEXOPT_EOL | ISC_LEXOPT_EOF;
REQUIRE(type == 4);
class = class; /*unused*/
if (isc_lex_gettoken(lexer, options, &token) != ISC_R_SUCCESS)
return (DNS_R_UNEXPECTED);
if (token.type != isc_tokentype_string) {
isc_lex_ungettoken(lexer, &token);
if (token.type == isc_tokentype_eol ||
token.type == isc_tokentype_eof)
return(DNS_R_UNEXPECTEDEND);
return (DNS_R_UNEXPECTED);
}
RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
dns_name_init(&name, NULL);
buffer_fromregion(&buffer, &token.value.as_region,
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: mg_8.c,v 1.4 1999/01/20 05:20:21 marka Exp $ */
/* $Id: mg_8.c,v 1.5 1999/01/22 00:36:56 marka Exp $ */
#ifndef RDATA_GENERIC_MG_8_H
#define RDATA_GENERIC_MG_8_H
......@@ -27,21 +27,12 @@ fromtext_mg(dns_rdataclass_t class, dns_rdatatype_t type,
isc_token_t token;
dns_name_t name;
isc_buffer_t buffer;
unsigned int options = ISC_LEXOPT_EOL | ISC_LEXOPT_EOF;
REQUIRE(type == 8);
class = class; /*unused*/
if (isc_lex_gettoken(lexer, options, &token) != ISC_R_SUCCESS)
return (DNS_R_UNEXPECTED);
if (token.type != isc_tokentype_string) {
isc_lex_ungettoken(lexer, &token);
if (token.type == isc_tokentype_eol ||
token.type == isc_tokentype_eof)
return(DNS_R_UNEXPECTEDEND);
return (DNS_R_UNEXPECTED);
}
RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
dns_name_init(&name, NULL);
buffer_fromregion(&buffer, &token.value.as_region,
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: mg_8.h,v 1.4 1999/01/20 05:20:21 marka Exp $ */
/* $Id: mg_8.h,v 1.5 1999/01/22 00:36:56 marka Exp $ */
#ifndef RDATA_GENERIC_MG_8_H
#define RDATA_GENERIC_MG_8_H
......@@ -27,21 +27,12 @@ fromtext_mg(dns_rdataclass_t class, dns_rdatatype_t type,
isc_token_t token;
dns_name_t name;
isc_buffer_t buffer;
unsigned int options = ISC_LEXOPT_EOL | ISC_LEXOPT_EOF;
REQUIRE(type == 8);
class = class; /*unused*/
if (isc_lex_gettoken(lexer, options, &token) != ISC_R_SUCCESS)
return (DNS_R_UNEXPECTED);
if (token.type != isc_tokentype_string) {
isc_lex_ungettoken(lexer, &token);
if (token.type == isc_tokentype_eol ||
token.type == isc_tokentype_eof)
return(DNS_R_UNEXPECTEDEND);
return (DNS_R_UNEXPECTED);
}
RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
dns_name_init(&name, NULL);
buffer_fromregion(&buffer, &token.value.as_region,
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: minfo_14.c,v 1.4 1999/01/20 05:20:21 marka Exp $ */
/* $Id: minfo_14.c,v 1.5 1999/01/22 00:36:56 marka Exp $ */
#ifndef RDATA_GENERIC_MINFO_14_H
#define RDATA_GENERIC_MINFO_14_H
......@@ -25,48 +25,25 @@ fromtext_minfo(dns_rdataclass_t class, dns_rdatatype_t type,