ttl.c revision e851ea826066ac5a5b01c2c23218faa0273a12e8
/*
* Copyright (C) 2004, 2005, 2007, 2011-2013 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 1999-2001 Internet Software Consortium.
*
* 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 ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC 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$ */
/*! \file */
#include <config.h>
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <isc/parseint.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];
unsigned int len;
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;
isc_uint32_t n;
char *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 {
while (*s != '\0' && isdigit((unsigned char)*s))
*np++ = *s++;
*np++ = '\0';
if (result != ISC_R_SUCCESS)
return (DNS_R_SYNTAX);
switch (*s) {
case 'w':
case 'W':
s++;
break;
case 'd':
case 'D':
s++;
break;
case 'h':
case 'H':
tmp += n * 3600;
s++;
break;
case 'm':
case 'M':
tmp += n * 60;
s++;
break;
case 's':
case 'S':
tmp += n;
s++;
break;
case '\0':
/* Plain number? */
if (tmp != 0)
return (DNS_R_SYNTAX);
tmp = n;
break;
default:
return (DNS_R_SYNTAX);
}
} while (*s != '\0');
return (ISC_R_SUCCESS);
}