Commit 2bc0da0c authored by Mark Andrews's avatar Mark Andrews
Browse files

Added NXT

	Debugged SIG
parent 7c0eb86a
......@@ -43,7 +43,6 @@ main(int argc, char *argv[]) {
int c;
int stats = 0;
unsigned int options = 0;
unsigned int parens = 0;
dns_rdatatype_t type;
dns_rdatatype_t lasttype = 0;
char outbuf[16*1024];
......@@ -93,7 +92,7 @@ main(int argc, char *argv[]) {
zero = 1;
break;
case 'r':
raw = 1;
raw++;
break;
}
}
......@@ -110,7 +109,7 @@ main(int argc, char *argv[]) {
specials[')'] = 1;
specials['"'] = 1;
isc_lex_setspecials(lex, specials);
options = ISC_LEXOPT_EOL | ISC_LEXOPT_EOF;
options = ISC_LEXOPT_EOL;
isc_lex_setcomments(lex, ISC_LEXCOMMENT_DNSMASTERFILE);
RUNTIME_CHECK(isc_lex_openstream(lex, stdin) == ISC_R_SUCCESS);
......@@ -119,31 +118,13 @@ main(int argc, char *argv[]) {
while ((result = isc_lex_gettoken(lex, options | ISC_LEXOPT_NUMBER,
&token)) == ISC_R_SUCCESS) {
if (debug) fprintf(stdout, "token.type = %d\n", token.type);
if (token.type == isc_tokentype_special) {
if (token.value.as_char == '(') {
parens++;
options &= ~ISC_LEXOPT_EOL;
options &= ~ISC_LEXOPT_INITIALWS;
} else if (token.value.as_char == ')') {
if (parens == 0) {
printf("mismatched parens\n");
exit(1);
}
parens--;
if (parens == 0) {
options |= ISC_LEXOPT_EOL;
options |= ISC_LEXOPT_INITIALWS;
}
}
continue;
}
if (need_eol) {
if (token.type == isc_tokentype_eol ||
token.type == isc_tokentype_eof)
if (token.type == isc_tokentype_eol)
need_eol = 0;
continue;
}
if (token.type == isc_tokentype_eof)
break;
if (token.type == isc_tokentype_number) {
type = token.value.as_ulong;
......@@ -207,7 +188,22 @@ main(int argc, char *argv[]) {
dns_result_totext(result), result);
continue;
}
len = wbuf.used - dbuf.current;
len = wbuf.used - wbuf.current;
if (raw > 2) {
unsigned int i;
fputs("\n", stdout);
for (i = 0 ; i < (unsigned int)len ; /* */ ) {
fprintf(stdout, "%02x",
((unsigned char*)wbuf.base)[i + wbuf.current]);
if ((++i % 20) == 0)
fputs("\n", stdout);
else
if (i == wbuf.used)
fputs("\n", stdout);
else
fputs(" ", stdout);
}
}
if (zero)
len = 0;
if (trunc)
......@@ -216,6 +212,7 @@ main(int argc, char *argv[]) {
isc_buffer_add(&wbuf, len / 4 + 1);
len += len / 4 + 1;
}
isc_buffer_setactive(&wbuf, len);
dns_rdata_init(&rdata);
isc_buffer_init(&dbuf, inbuf, sizeof(inbuf),
......@@ -230,6 +227,20 @@ main(int argc, char *argv[]) {
continue;
}
}
if (raw > 1) {
unsigned int i;
fputs("\n", stdout);
for (i = 0 ; i < rdata.length ; /* */ ) {
fprintf(stdout, "%02x", rdata.data[i]);
if ((++i % 20) == 0)
fputs("\n", stdout);
else
if (i == rdata.length)
fputs("\n", stdout);
else
fputs(" ", stdout);
}
}
isc_buffer_init(&tbuf, outbuf, sizeof(outbuf),
ISC_BUFFERTYPE_TEXT);
......
......@@ -15,11 +15,12 @@
* SOFTWARE.
*/
/* $Id: rdata.c,v 1.16 1999/01/29 07:02:59 halley Exp $ */
/* $Id: rdata.c,v 1.17 1999/01/29 08:04:12 marka Exp $ */
#include <config.h>
#include <stdio.h>
#include <time.h>
#include <isc/buffer.h>
#include <isc/lex.h>
......@@ -69,6 +70,7 @@ static dns_result_t base64_tobuffer(isc_lex_t *lexer,
isc_buffer_t *target);
static dns_result_t time_totext(unsigned long value,
isc_buffer_t *target);
static dns_result_t time_tobuffer(char *source, isc_buffer_t *target);
static const char hexdigits[] = "0123456789abcdef";
static const char decdigits[] = "0123456789";
......@@ -246,7 +248,7 @@ dns_rdata_fromtext(dns_rdata_t *rdata,
isc_boolean_t use_default = ISC_FALSE;
isc_token_t token;
unsigned int options = ISC_LEXOPT_EOL | ISC_LEXOPT_EOF |
ISC_LEXOPT_DNSMULTILINE;
ISC_LEXOPT_DNSMULTILINE;
st = *target;
region.base = (unsigned char *)(target->base) + target->used;
......@@ -268,7 +270,6 @@ dns_rdata_fromtext(dns_rdata_t *rdata,
break;
} else if (token.type != isc_tokentype_eol &&
token.type != isc_tokentype_eof) {
fprintf(stderr, "token_type = %d\n", token.type);
if (result == DNS_R_SUCCESS)
result = DNS_R_EXTRATOKEN;
} else
......@@ -698,7 +699,7 @@ base64_totext(isc_region_t *source, isc_buffer_t *target) {
buf[0] = base64[(source->base[0]>>2)&0x3f];
buf[1] = base64[((source->base[0]<<4)&0x30)|
((source->base[1]>>4)&0x0f)];
buf[2] = base64[((source->base[1]<<4)&0x3c)|
buf[2] = base64[((source->base[1]<<2)&0x3c)|
((source->base[2]>>6)&0x03)];
buf[3] = base64[source->base[2]&0x3f];
RETERR(str_totext(buf, target));
......@@ -754,15 +755,20 @@ base64_tobuffer(isc_lex_t *lexer, isc_buffer_t *target) {
return (DNS_R_SYNTAX);
if (val[2] == 64 && val[3] != 64)
return (DNS_R_SYNTAX);
buf[0] = (val[0]<<2)|(val[1]>>4);
buf[1] = (val[1]<<4)|(val[2]>>2);
buf[2] = (val[2]<<2)|(val[3]);
n = (val[2] == 64) ? 1 :
(val[3] == 64) ? 2 : 3;
if (n != 3) {
seen_end = 1;
if (val[2] == 64)
val[2] = 0;
if (val[3] == 64)
val[3] = 0;
}
buf[0] = (val[0]<<2)|(val[1]>>4);
buf[1] = (val[1]<<4)|(val[2]>>2);
buf[2] = (val[2]<<6)|(val[3]);
RETERR(mem_tobuffer(target, buf, n));
digits = 0;
if (val[2] == 64 || val[3] != 64)
seen_end = 1;
}
}
}
......@@ -772,7 +778,101 @@ base64_tobuffer(isc_lex_t *lexer, isc_buffer_t *target) {
return (DNS_R_SUCCESS);
}
static int days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
static dns_result_t
time_totext(unsigned long value, isc_buffer_t *target) {
return (DNS_R_NOTIMPLEMENTED);
long long start;
long long base;
long long t;
struct tm tm;
char buf[sizeof "YYYYMMDDHHMMSS"];
int secs;
/* find the right epoch */
start = time(NULL);
start -= 0x7fffffff;
base = 0;
while ((t = (base + value)) < start) {
base += 0x80000000;
base += 0x80000000;
}
#define is_leap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)
#define year_secs(y) ((is_leap(y) ? 366 : 365 ) * 86400)
#define month_secs(m, y) ((days[m] + ((m == 1 && is_leap(y)) ? 1 : 0 )) * 86400)
tm.tm_year = 70;
while ((secs = year_secs(tm.tm_year + 1900 + 1)) <= t) {
t -= secs;
tm.tm_year++;
}
tm.tm_mon = 0;
while ((secs = month_secs(tm.tm_mon, tm.tm_year + 1900)) <= t) {
t -= secs;
tm.tm_mon++;
}
tm.tm_mday = 1;
while (86400 <= t) {
t -= 86400;
tm.tm_mday++;
}
tm.tm_hour = 0;
while (3600 <= t) {
t -= 3600;
tm.tm_hour++;
}
tm.tm_min = 0;
while (60 <= t) {
t -= 60;
tm.tm_min++;
}
tm.tm_sec = t;
/* yy mm dd HH MM SS */
sprintf(buf, "%04d%02d%02d%02d%02d%02d",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec);
return (str_totext(buf, target));
}
static dns_result_t
time_tobuffer(char *source, isc_buffer_t *target) {
int year, month, day, hour, minute, second;
unsigned long value;
int secs;
int i;
#define RANGE(min, max, value) \
do { \
if (value < (min) || value > (max)) \
return (DNS_R_RANGE); \
} while (0)
if (strlen(source) != 14)
return (DNS_R_SYNTAX);
if (sscanf(source, "%4d%2d%2d%2d%2d%2d",
&year, &month, &day, &hour, &minute, &second) != 6)
return (DNS_R_SYNTAX);
RANGE(1970, 9999, year);
RANGE(1, 12, month);
RANGE(1, days[month - 1] +
((month == 2 && is_leap(year)) ? 1 : 0), day);
RANGE(0, 23, hour);
RANGE(0, 59, minute);
RANGE(0, 60, second); /* leap second */
/* calulate seconds since epoch */
value = second + (60 * minute) + (3600 * hour) + ((day - 1) * 86400);
for (i = 0; i < (month - 1) ; i++)
value += days[i] * 86400;
if (is_leap(year) && month > 2)
value += 86400;
for (i = 1970; i < year; i++) {
secs = (is_leap(i) ? 366 : 365) * 86400;
value += secs;
}
return (uint32_tobuffer(value, target));
}
/*
* Copyright (C) 1999 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
/* $Id: nxt_30.c,v 1.1 1999/01/29 08:04:13 marka Exp $ */
/* RFC 2065 */
#ifndef RDATA_GENERIC_NXT_30_H
#define RDATA_GENERIC_NXT_30_H
static dns_result_t
fromtext_nxt(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_name_t name;
isc_buffer_t buffer;
char *e;
unsigned char bm[8*1024]; /* 64k bits */
dns_rdatatype_t covered;
long maxcovered = -1;
unsigned int n;
REQUIRE(type == 30);
class = class; /*unused*/
/* next domain */
RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
dns_name_init(&name, NULL);
buffer_fromregion(&buffer, &token.value.as_region,
ISC_BUFFERTYPE_TEXT);
origin = (origin != NULL) ? origin : dns_rootname;
RETERR(dns_name_fromtext(&name, &buffer, origin, downcase, target));
memset(bm, 0, sizeof bm);
while (1) {
RETERR(gettoken(lexer, &token, isc_tokentype_string,
ISC_TRUE));
if (token.type != isc_tokentype_string)
break;
covered = strtol(token.value.as_pointer, &e, 10);
if (*e == '\0')
(void) NULL;
else if (dns_rdatatype_fromtext(&covered,
&token.value.as_textregion) == DNS_R_UNKNOWN)
return (DNS_R_UNKNOWN);
if (covered > maxcovered)
maxcovered = covered;
bm[covered/8] |= (0x80>>(covered%8));
}
isc_lex_ungettoken(lexer, &token);
n = (maxcovered + 8) / 8;
return (mem_tobuffer(target, bm, n));
}
static dns_result_t
totext_nxt(dns_rdata_t *rdata, dns_name_t *origin, isc_buffer_t *target) {
isc_region_t sr;
char buf[sizeof "65535"];
unsigned int i, j;
dns_name_t name;
dns_name_t prefix;
dns_result_t result;
isc_boolean_t sub;
REQUIRE(rdata->type == 30);
dns_name_init(&name, NULL);
dns_name_init(&prefix, NULL);
dns_rdata_toregion(rdata, &sr);
dns_name_fromregion(&name, &sr);
isc_region_consume(&sr, name_length(&name));
sub = name_prefix(&name, origin, &prefix);
RETERR(dns_name_totext(&prefix, sub, target));
RETERR(str_totext(" ( ", target));
for (i = 0 ; i < sr.length ; i++) {
if (sr.base[i] != 0)
for (j = 0; j < 8; j++)
if ((sr.base[i] & (0x80>>j)) != 0) {
result = dns_rdatatype_totext(
i * 8 + j, target);
if (result == DNS_R_SUCCESS) {
RETERR(str_totext(" ",
target));
continue;
}
if (result != DNS_R_UNKNOWN)
return (result);
sprintf(buf, "%u", i * 8 + j);
RETERR(str_totext(" ", target));
RETERR(str_totext(buf, target));
}
}
return (str_totext(")", target));
}
static dns_result_t
fromwire_nxt(dns_rdataclass_t class, dns_rdatatype_t type,
isc_buffer_t *source, dns_decompress_t *dctx,
isc_boolean_t downcase, isc_buffer_t *target) {
isc_region_t sr;
dns_name_t name;
REQUIRE(type == 30);
class = class; /*unused*/
dns_name_init(&name, NULL);
RETERR(dns_name_fromwire(&name, source, dctx, downcase, target));
isc_buffer_active(source, &sr);
if (sr.length > 8 * 1024)
return (DNS_R_EXTRADATA);
RETERR(mem_tobuffer(target, sr.base, sr.length));
isc_buffer_forward(source, sr.length);
return (DNS_R_SUCCESS);
}
static dns_result_t
towire_nxt(dns_rdata_t *rdata, dns_compress_t *cctx, isc_buffer_t *target) {
isc_region_t sr;
dns_name_t name;
REQUIRE(rdata->type == 30);
dns_name_init(&name, NULL);
dns_rdata_toregion(rdata, &sr);
dns_name_fromregion(&name, &sr);
isc_region_consume(&sr, name_length(&name));
RETERR(dns_name_towire(&name, cctx, target));
return (mem_tobuffer(target, sr.base, sr.length));
}
static int
compare_nxt(dns_rdata_t *rdata1, dns_rdata_t *rdata2) {
isc_region_t r1;
isc_region_t r2;
dns_name_t name1;
dns_name_t name2;
int result;
REQUIRE(rdata1->type == rdata2->type);
REQUIRE(rdata1->class == rdata2->class);
REQUIRE(rdata1->type == 30);
dns_name_init(&name1, NULL);
dns_name_init(&name2, NULL);
dns_rdata_toregion(rdata1, &r1);
dns_rdata_toregion(rdata2, &r2);
dns_name_fromregion(&name1, &r1);
dns_name_fromregion(&name2, &r2);
result = dns_name_compare(&name1, &name2);
if (result != 0)
return (result);
return (compare_region(&r1, &r2));
}
static dns_result_t
fromstruct_nxt(dns_rdataclass_t class, dns_rdatatype_t type, void *source,
isc_buffer_t *target) {
REQUIRE(type == 30);
class = class; /*unused*/
source = source;
target = target;
return (DNS_R_NOTIMPLEMENTED);
}
static dns_result_t
tostruct_nxt(dns_rdata_t *rdata, void *target) {
REQUIRE(rdata->type == 30);
target = target;
return (DNS_R_NOTIMPLEMENTED);
}
#endif /* RDATA_GENERIC_NXT_30_H */
/*
* Copyright (C) 1999 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
/* $Id: nxt_30.h,v 1.1 1999/01/29 08:04:13 marka Exp $ */
/* RFC 2065 */
#ifndef RDATA_GENERIC_NXT_30_H
#define RDATA_GENERIC_NXT_30_H
static dns_result_t
fromtext_nxt(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_name_t name;
isc_buffer_t buffer;
char *e;
unsigned char bm[8*1024]; /* 64k bits */
dns_rdatatype_t covered;
long maxcovered = -1;
unsigned int n;
REQUIRE(type == 30);
class = class; /*unused*/
/* next domain */
RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
dns_name_init(&name, NULL);
buffer_fromregion(&buffer, &token.value.as_region,
ISC_BUFFERTYPE_TEXT);
origin = (origin != NULL) ? origin : dns_rootname;
RETERR(dns_name_fromtext(&name, &buffer, origin, downcase, target));
memset(bm, 0, sizeof bm);
while (1) {
RETERR(gettoken(lexer, &token, isc_tokentype_string,
ISC_TRUE));
if (token.type != isc_tokentype_string)
break;
covered = strtol(token.value.as_pointer, &e, 10);
if (*e == '\0')
(void) NULL;
else if (dns_rdatatype_fromtext(&covered,
&token.value.as_textregion) == DNS_R_UNKNOWN)
return (DNS_R_UNKNOWN);
if (covered > maxcovered)
maxcovered = covered;
bm[covered/8] |= (0x80>>(covered%8));
}
isc_lex_ungettoken(lexer, &token);
n = (maxcovered + 8) / 8;
return (mem_tobuffer(target, bm, n));
}
static dns_result_t
totext_nxt(dns_rdata_t *rdata, dns_name_t *origin, isc_buffer_t *target) {
isc_region_t sr;
char buf[sizeof "65535"];
unsigned int i, j;
dns_name_t name;
dns_name_t prefix;
dns_result_t result;
isc_boolean_t sub;
REQUIRE(rdata->type == 30);
dns_name_init(&name, NULL);
dns_name_init(&prefix, NULL);
dns_rdata_toregion(rdata, &sr);
dns_name_fromregion(&name, &sr);
isc_region_consume(&sr, name_length(&name));
sub = name_prefix(&name, origin, &prefix);
RETERR(dns_name_totext(&prefix, sub, target));
RETERR(str_totext(" ( ", target));
for (i = 0 ; i < sr.length ; i++) {
if (sr.base[i] != 0)
for (j = 0; j < 8; j++)
if ((sr.base[i] & (0x80>>j)) != 0) {
result = dns_rdatatype_totext(
i * 8 + j, target);
if (result == DNS_R_SUCCESS) {
RETERR(str_totext(" ",
target));
continue;
}
if (result != DNS_R_UNKNOWN)
return (result);
sprintf(buf, "%u", i * 8 + j);
RETERR(str_totext(" ", target));
RETERR(str_totext(buf, target));
}
}
return (str_totext(")", target));
}
static dns_result_t
fromwire_nxt(dns_rdataclass_t class, dns_rdatatype_t type,
isc_buffer_t *source, dns_decompress_t *dctx,
isc_boolean_t downcase, isc_buffer_t *target) {
isc_region_t sr;
dns_name_t name;
REQUIRE(type == 30);
class = class; /*unused*/
dns_name_init(&name, NULL);
RETERR(dns_name_fromwire(&name, source, dctx, downcase, target));