ttl.c revision 0c27b3fe77ac1d5094ba3521e8142d9e7973133f
/*
* Copyright (C) 1999-2001, 2004, 2005, 2007, 2011-2014, 2016 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/* $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.)
*/
/*
* 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);
}
}
return (result);
}
static isc_result_t
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':
s++;
break;
case 'm':
case 'M':
s++;
break;
case 's':
case 'S':
tmp += (isc_uint64_t) n;
s++;
break;
case '\0':
/* Plain number? */
return (DNS_R_SYNTAX);
tmp = n;
break;
default:
return (DNS_R_SYNTAX);
}
} while (*s != '\0');
if (tmp > 0xffffffffULL)
return (ISC_R_RANGE);
return (ISC_R_SUCCESS);
}