ttl.c revision cd750f6e7449678173e8cfe080ae0bf3dcb424cf
6fb9b25791778f69002eb72be6235e20d98ec452Tinderbox User * Copyright (C) 2004, 2005, 2007, 2011-2014 Internet Systems Consortium, Inc. ("ISC")
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrews * Copyright (C) 1999-2001 Internet Software Consortium.
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Permission to use, copy, modify, and/or distribute this software for any
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * purpose with or without fee is hereby granted, provided that the above
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrews * copyright notice and this permission notice appear in all copies.
28a8f5b0de57d269cf2845c69cb6abe18cbd3b3aMark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
8a07de2f032b0137d89ae8af14faa1a915aaf9faAutomatic Updater * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrews * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
3759f10fc543747668b1ca4b4671f35b0dea8445Francis Dupont * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
3759f10fc543747668b1ca4b4671f35b0dea8445Francis Dupont * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrews * PERFORMANCE OF THIS SOFTWARE.
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrews#define RETERR(x) do { \
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrewsstatic isc_result_t bind_ttl(isc_textregion_t *source, isc_uint32_t *ttl);
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrews * Helper for dns_ttl_totext().
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrewsttlfmt(unsigned int t, const char *s, isc_boolean_t verbose,
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrews unsigned int len;
8a07de2f032b0137d89ae8af14faa1a915aaf9faAutomatic Updater len = snprintf(tmp, sizeof(tmp), "%s%u %s%s",
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrews len = snprintf(tmp, sizeof(tmp), "%u%c", t, s[0]);
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrews * Derived from bind8 ns_format_ttl().
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrewsdns_ttl_totext(isc_uint32_t src, isc_boolean_t verbose, isc_buffer_t *target) {
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrews return (dns_ttl_totext2(src, verbose, ISC_TRUE, target));
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrewsdns_ttl_totext2(isc_uint32_t src, isc_boolean_t verbose,
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrews RETERR(ttlfmt(weeks, "week", verbose, ISC_TF(x > 0), target));
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrews RETERR(ttlfmt(days, "day", verbose, ISC_TF(x > 0), target));
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrews RETERR(ttlfmt(hours, "hour", verbose, ISC_TF(x > 0), target));
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrews RETERR(ttlfmt(mins, "minute", verbose, ISC_TF(x > 0), target));
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrews (weeks == 0 && days == 0 && hours == 0 && mins == 0)) {
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrews RETERR(ttlfmt(secs, "second", verbose, ISC_TF(x > 0), target));
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrews * If only a single unit letter is printed, print it
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrews * in upper case. (Why? Because BIND 8 does that.
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrews * Presumably it has a reason.)
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrews * The unit letter is the last character in the
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrews * used region of the buffer.
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrews * toupper() does not need its argument to be masked of cast
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrews * here because region.base is type unsigned char *.
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrewsdns_counter_fromtext(isc_textregion_t *source, isc_uint32_t *ttl) {
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrewsdns_ttl_fromtext(isc_textregion_t *source, isc_uint32_t *ttl) {
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrews if (result != ISC_R_SUCCESS && result != ISC_R_RANGE)
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrewsbind_ttl(isc_textregion_t *source, isc_uint32_t *ttl) {
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrews * Copy the buffer as it may not be NULL terminated.
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrews * No legal counter / ttl is longer that 63 characters.
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrews while (*s != '\0' && isdigit((unsigned char)*s))
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrews switch (*s) {
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrews /* Plain number? */
d1bcaec0d6c3a2f6afe004c1a087314015cb77c0Mark Andrews } while (*s != '\0');