2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 22:15:20 +00:00

Added NXT

Debugged SIG
This commit is contained in:
Mark Andrews
1999-01-29 08:04:13 +00:00
parent 7c0eb86a80
commit 2bc0da0cd8
6 changed files with 558 additions and 43 deletions

View File

@@ -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));
}