ttl.c revision 40f53fa8d9c6a4fc38c0014495e7a42b08f52481
/*
* Copyright (C) 1999, 2000 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: ttl.c,v 1.20 2000/08/01 01:23:03 tale Exp $ */
#include <config.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#define RETERR(x) do { \
isc_result_t _r = (x); \
if (_r != ISC_R_SUCCESS) \
return (_r); \
} while (0)
/*
* Helper for dns_ttl_totext().
*/
static isc_result_t
{
char tmp[60];
if (verbose)
t, s,
t == 1 ? "" : "s");
else
return (ISC_R_NOSPACE);
return (ISC_R_SUCCESS);
}
/*
* Derived from bind8 ns_format_ttl().
*/
x = 0;
if (weeks != 0) {
x++;
}
if (days != 0) {
x++;
}
if (hours != 0) {
x++;
}
if (mins != 0) {
x++;
}
if (secs != 0 ||
x++;
}
INSIST (x > 0);
/*
* If only a single unit letter is printed, print it
* in upper case. (Why? Because BIND 8 does that.
* Presumably it has a reason.)
*/
if (x == 1 && !verbose) {
/*
* The unit letter is the last character in the
* used region of the buffer.
*
* toupper() does not need its argument to be masked of cast
* here because region.base is type unsigned char *.
*/
}
return (ISC_R_SUCCESS);
}
}
if (result != ISC_R_SUCCESS)
return (result);
}
static isc_result_t
isc_uint32_t tmp = 0;
unsigned long n;
char *e, *s;
char buf[64];
/*
* Copy the buffer as it may not be NULL terminated.
* No legal counter / ttl is longer that 63 characters.
*/
return(DNS_R_SYNTAX);
s = buf;
do {
n = strtoul(s, &e, 10);
if (s == e)
return (DNS_R_SYNTAX);
switch (*e) {
case 'w':
case 'W':
s = e + 1;
break;
case 'd':
case 'D':
s = e + 1;
break;
case 'h':
case 'H':
tmp += n * 3600;
s = e + 1;
break;
case 'm':
case 'M':
tmp += n * 60;
s = e + 1;
break;
case 's':
case 'S':
tmp += n;
s = e + 1;
break;
case '\0':
/* Plain number? */
if (tmp != 0)
return (DNS_R_SYNTAX);
tmp = n;
s = e;
break;
default:
return (DNS_R_SYNTAX);
}
} while (*s != 0);
return (ISC_R_SUCCESS);
}