summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorInternet Software Consortium, Inc <@isc.org>2014-02-11 09:01:28 -0700
committerInternet Software Consortium, Inc <@isc.org>2014-02-11 09:01:28 -0700
commit8b0dafdc16eff31ee5f4acc8544b45b2ae287a7d (patch)
tree1802897ca34cc0d67741aed71af55cf5ef36b145 /lib
parent8af21b710f34092dcd08abdc13e7971553b616d2 (diff)
downloadbind9-8b0dafdc16eff31ee5f4acc8544b45b2ae287a7d.tar.gz
9.9.5rc2
Diffstat (limited to 'lib')
-rw-r--r--lib/dns/api2
-rw-r--r--lib/dns/dispatch.c17
-rw-r--r--lib/dns/include/dns/Makefile.in7
-rw-r--r--lib/dns/rdata/generic/rrsig_46.c32
-rw-r--r--lib/export/isc/Makefile.in4
-rw-r--r--lib/irs/api4
-rw-r--r--lib/irs/include/irs/Makefile.in4
-rw-r--r--lib/irs/include/irs/resconf.h14
-rw-r--r--lib/irs/resconf.c81
-rw-r--r--lib/isc/Makefile.in7
-rw-r--r--lib/isc/api4
-rw-r--r--lib/isc/include/isc/Makefile.in14
-rw-r--r--lib/isc/include/isc/tm.h46
-rw-r--r--lib/isc/tm.c (renamed from lib/isc/win32/strptime.c)133
-rw-r--r--lib/isc/unix/time.c30
-rw-r--r--lib/isc/win32/libisc.def.in2
-rw-r--r--lib/isc/win32/libisc.dsp.in8
-rw-r--r--lib/isc/win32/libisc.mak.in24
-rw-r--r--lib/isc/win32/libisc.vcxproj.filters.in8
-rw-r--r--lib/isc/win32/libisc.vcxproj.in4
-rw-r--r--lib/isc/win32/time.c31
21 files changed, 310 insertions, 166 deletions
diff --git a/lib/dns/api b/lib/dns/api
index 1bf8d3fa..cc5437d0 100644
--- a/lib/dns/api
+++ b/lib/dns/api
@@ -5,5 +5,5 @@
# 9.9: 90-109
# 9.9-sub: 130-139
LIBINTERFACE = 102
-LIBREVISION = 1
+LIBREVISION = 2
LIBAGE = 2
diff --git a/lib/dns/dispatch.c b/lib/dns/dispatch.c
index 77010414..7af8e644 100644
--- a/lib/dns/dispatch.c
+++ b/lib/dns/dispatch.c
@@ -778,6 +778,7 @@ port_search(dns_dispatch_t *disp, in_port_t port) {
static dispportentry_t *
new_portentry(dns_dispatch_t *disp, in_port_t port) {
dispportentry_t *portentry;
+ dns_qid_t *qid;
REQUIRE(disp->port_table != NULL);
@@ -786,10 +787,13 @@ new_portentry(dns_dispatch_t *disp, in_port_t port) {
return (portentry);
portentry->port = port;
- portentry->refs = 0;
+ portentry->refs = 1;
ISC_LINK_INIT(portentry, link);
+ qid = DNS_QID(disp);
+ LOCK(&qid->lock);
ISC_LIST_APPEND(disp->port_table[port % DNS_DISPATCH_PORTTABLESIZE],
portentry, link);
+ UNLOCK(&qid->lock);
return (portentry);
}
@@ -800,7 +804,6 @@ new_portentry(dns_dispatch_t *disp, in_port_t port) {
static void
deref_portentry(dns_dispatch_t *disp, dispportentry_t **portentryp) {
dispportentry_t *portentry = *portentryp;
- isc_boolean_t unlink = ISC_FALSE;
dns_qid_t *qid;
REQUIRE(disp->port_table != NULL);
@@ -809,15 +812,14 @@ deref_portentry(dns_dispatch_t *disp, dispportentry_t **portentryp) {
qid = DNS_QID(disp);
LOCK(&qid->lock);
portentry->refs--;
- unlink = ISC_TF(portentry->refs == 0);
- UNLOCK(&qid->lock);
- if (unlink) {
+ if (portentry->refs == 0) {
ISC_LIST_UNLINK(disp->port_table[portentry->port %
DNS_DISPATCH_PORTTABLESIZE],
portentry, link);
isc_mempool_put(disp->portpool, portentry);
}
+ UNLOCK(&qid->lock);
*portentryp = NULL;
}
@@ -939,8 +941,11 @@ get_dispsocket(dns_dispatch_t *disp, isc_sockaddr_t *dest,
result = ISC_R_NOMEMORY;
break;
}
+ } else {
+ LOCK(&qid->lock);
+ portentry->refs++;
+ UNLOCK(&qid->lock);
}
- portentry->refs++;
break;
} else if (result == ISC_R_NOPERM) {
char buf[ISC_SOCKADDR_FORMATSIZE];
diff --git a/lib/dns/include/dns/Makefile.in b/lib/dns/include/dns/Makefile.in
index 1a69f2c8..6ff682f7 100644
--- a/lib/dns/include/dns/Makefile.in
+++ b/lib/dns/include/dns/Makefile.in
@@ -1,4 +1,4 @@
-# Copyright (C) 2004, 2007-2009, 2011, 2012 Internet Systems Consortium, Inc. ("ISC")
+# Copyright (C) 2004, 2007-2009, 2011, 2012, 2014 Internet Systems Consortium, Inc. ("ISC")
# Copyright (C) 1998-2003 Internet Software Consortium.
#
# Permission to use, copy, modify, and/or distribute this software for any
@@ -22,7 +22,8 @@ top_srcdir = @top_srcdir@
@BIND9_VERSION@
HEADERS = acl.h adb.h byaddr.h cache.h callbacks.h cert.h compress.h \
- clientinfo.h db.h dbiterator.h dbtable.h diff.h dispatch.h \
+ client.h clientinfo.h compress.h \
+ db.h dbiterator.h dbtable.h diff.h dispatch.h \
dlz.h dnssec.h ds.h events.h fixedname.h iptable.h journal.h \
keyflags.h keytable.h keyvalues.h lib.h log.h \
master.h masterdump.h message.h name.h ncache.h nsec.h \
@@ -30,7 +31,7 @@ HEADERS = acl.h adb.h byaddr.h cache.h callbacks.h cert.h compress.h \
rdata.h rdataclass.h rdatalist.h rdataset.h rdatasetiter.h \
rdataslab.h rdatatype.h request.h resolver.h result.h \
rootns.h rpz.h sdb.h sdlz.h secalg.h secproto.h soa.h ssu.h \
- tcpmsg.h time.h tkey.h tsig.h ttl.h types.h \
+ tcpmsg.h time.h tkey.h tsec.h tsig.h ttl.h types.h \
validator.h version.h view.h xfrin.h zone.h zonekey.h zt.h
GENHEADERS = enumclass.h enumtype.h rdatastruct.h
diff --git a/lib/dns/rdata/generic/rrsig_46.c b/lib/dns/rdata/generic/rrsig_46.c
index 58a327c0..5dd5a31a 100644
--- a/lib/dns/rdata/generic/rrsig_46.c
+++ b/lib/dns/rdata/generic/rrsig_46.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2004, 2005, 2007, 2009, 2011, 2012 Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (C) 2004, 2005, 2007, 2009, 2011, 2012, 2014 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 2003 Internet Software Consortium.
*
* Permission to use, copy, modify, and/or distribute this software for any
@@ -90,7 +90,20 @@ fromtext_rrsig(ARGS_FROMTEXT) {
*/
RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
ISC_FALSE));
- RETTOK(dns_time32_fromtext(DNS_AS_STR(token), &time_expire));
+ if (strlen(DNS_AS_STR(token)) <= 10U &&
+ *DNS_AS_STR(token) != '-' && *DNS_AS_STR(token) != '+') {
+ char *end;
+ unsigned long u;
+ isc_uint64_t u64;
+
+ u64 = u = strtoul(DNS_AS_STR(token), &end, 10);
+ if (u == ULONG_MAX || *end != 0)
+ RETTOK(DNS_R_SYNTAX);
+ if (u64 > 0xffffffffUL)
+ RETTOK(ISC_R_RANGE);
+ time_expire = u;
+ } else
+ RETTOK(dns_time32_fromtext(DNS_AS_STR(token), &time_expire));
RETERR(uint32_tobuffer(time_expire, target));
/*
@@ -98,7 +111,20 @@ fromtext_rrsig(ARGS_FROMTEXT) {
*/
RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
ISC_FALSE));
- RETTOK(dns_time32_fromtext(DNS_AS_STR(token), &time_signed));
+ if (strlen(DNS_AS_STR(token)) <= 10U &&
+ *DNS_AS_STR(token) != '-' && *DNS_AS_STR(token) != '+') {
+ char *end;
+ unsigned long u;
+ isc_uint64_t u64;
+
+ u64 = u = strtoul(DNS_AS_STR(token), &end, 10);
+ if (u == ULONG_MAX || *end != 0)
+ RETTOK(DNS_R_SYNTAX);
+ if (u64 > 0xffffffffUL)
+ RETTOK(ISC_R_RANGE);
+ time_signed = u;
+ } else
+ RETTOK(dns_time32_fromtext(DNS_AS_STR(token), &time_signed));
RETERR(uint32_tobuffer(time_signed, target));
/*
diff --git a/lib/export/isc/Makefile.in b/lib/export/isc/Makefile.in
index 46df39df..a92f66f3 100644
--- a/lib/export/isc/Makefile.in
+++ b/lib/export/isc/Makefile.in
@@ -1,4 +1,4 @@
-# Copyright (C) 2009, 2010, 2012, 2013 Internet Systems Consortium, Inc. ("ISC")
+# Copyright (C) 2009, 2010, 2012-2014 Internet Systems Consortium, Inc. ("ISC")
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
@@ -73,6 +73,7 @@ OBJS = @ISC_EXTRA_OBJS@ \
rwlock.@O@ safe.@O@ serial.@O@ sha1.@O@ sha2.@O@ \
sockaddr.@O@ stats.@O@ string.@O@ \
symtab.@O@ \
+ tm.@O@ \
version.@O@ \
${APIOBJS} ${ISCDRIVEROBJS} \
${UNIXOBJS} ${NLSOBJS} ${THREADOBJS}
@@ -96,6 +97,7 @@ SRCS = @ISC_EXTRA_SRCS@ \
random.c refcount.c region.c regex.c result.c rwlock.c \
safe.c serial.c sha1.c sha2.c sockaddr.c \
stats.c string.c symtab.c \
+ tm.c \
version.c \
${APISRCS} ${ISCDRIVERSRCS}
diff --git a/lib/irs/api b/lib/irs/api
index 343e4aaf..3f5a2a3b 100644
--- a/lib/irs/api
+++ b/lib/irs/api
@@ -4,6 +4,6 @@
# 9.8: 80-89, 120-129
# 9.9: 90-109
# 9.9-sub: 130-139
-LIBINTERFACE = 90
-LIBREVISION = 2
+LIBINTERFACE = 91
+LIBREVISION = 0
LIBAGE = 0
diff --git a/lib/irs/include/irs/Makefile.in b/lib/irs/include/irs/Makefile.in
index 63e7fd6b..eca98eb1 100644
--- a/lib/irs/include/irs/Makefile.in
+++ b/lib/irs/include/irs/Makefile.in
@@ -1,4 +1,4 @@
-# Copyright (C) 2009, 2012 Internet Systems Consortium, Inc. ("ISC")
+# Copyright (C) 2009, 2012, 2014 Internet Systems Consortium, Inc. ("ISC")
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
@@ -39,6 +39,8 @@ install:: installdirs
done
${INSTALL_DATA} netdb.h ${DESTDIR}${includedir}/irs
${INSTALL_DATA} platform.h ${DESTDIR}${includedir}/irs
+ ${INSTALL_DATA} resconf.h ${DESTDIR}${includedir}/irs
+ ${INSTALL_DATA} types.h ${DESTDIR}${includedir}/irs
distclean::
rm -f netdb.h platform.h
diff --git a/lib/irs/include/irs/resconf.h b/lib/irs/include/irs/resconf.h
index 78c87d51..dec110ad 100644
--- a/lib/irs/include/irs/resconf.h
+++ b/lib/irs/include/irs/resconf.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (C) 2009, 2014 Internet Systems Consortium, Inc. ("ISC")
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -46,7 +46,12 @@ isc_result_t
irs_resconf_load(isc_mem_t *mctx, const char *filename, irs_resconf_t **confp);
/*%<
* Load the resolver configuration file 'filename' in the "resolv.conf" format,
- * and create a new irs_resconf_t object from the configuration.
+ * and create a new irs_resconf_t object from the configuration. If the file
+ * is not found ISC_R_FILENOTFOUND is returned with the structure initialized
+ * as if file contained only:
+ *
+ * nameserver ::1
+ * nameserver 127.0.0.1
*
* Notes:
*
@@ -55,6 +60,11 @@ irs_resconf_load(isc_mem_t *mctx, const char *filename, irs_resconf_t **confp);
* In addition, 'sortlist' is not actually effective; it's parsed, but
* the application cannot use the configuration.
*
+ * Returns:
+ * \li ISC_R_SUCCESS on success
+ * \li ISC_R_FILENOTFOUND if the file was not found. *confp will be valid.
+ * \li other on error.
+ *
* Requires:
*
*\li 'mctx' is a valid memory context.
diff --git a/lib/irs/resconf.c b/lib/irs/resconf.c
index 15a46baf..cb240079 100644
--- a/lib/irs/resconf.c
+++ b/lib/irs/resconf.c
@@ -483,7 +483,7 @@ irs_resconf_load(isc_mem_t *mctx, const char *filename, irs_resconf_t **confp)
{
FILE *fp = NULL;
char word[256];
- isc_result_t rval, ret;
+ isc_result_t rval, ret = ISC_R_SUCCESS;
irs_resconf_t *conf;
int i, stopchar;
@@ -507,45 +507,49 @@ irs_resconf_load(isc_mem_t *mctx, const char *filename, irs_resconf_t **confp)
conf->search[i] = NULL;
errno = 0;
- if ((fp = fopen(filename, "r")) == NULL) {
- isc_mem_put(mctx, conf, sizeof(*conf));
- return (ISC_R_INVALIDFILE);
- }
-
- ret = ISC_R_SUCCESS;
- do {
- stopchar = getword(fp, word, sizeof(word));
- if (stopchar == EOF) {
- rval = ISC_R_SUCCESS;
- POST(rval);
- break;
- }
-
- if (strlen(word) == 0U)
- rval = ISC_R_SUCCESS;
- else if (strcmp(word, "nameserver") == 0)
- rval = resconf_parsenameserver(conf, fp);
- else if (strcmp(word, "domain") == 0)
- rval = resconf_parsedomain(conf, fp);
- else if (strcmp(word, "search") == 0)
- rval = resconf_parsesearch(conf, fp);
- else if (strcmp(word, "sortlist") == 0)
- rval = resconf_parsesortlist(conf, fp);
- else if (strcmp(word, "options") == 0)
- rval = resconf_parseoption(conf, fp);
- else {
- /* unrecognised word. Ignore entire line */
- rval = ISC_R_SUCCESS;
- stopchar = eatline(fp);
+ if ((fp = fopen(filename, "r")) != NULL) {
+ do {
+ stopchar = getword(fp, word, sizeof(word));
if (stopchar == EOF) {
+ rval = ISC_R_SUCCESS;
+ POST(rval);
break;
}
- }
- if (ret == ISC_R_SUCCESS && rval != ISC_R_SUCCESS)
- ret = rval;
- } while (1);
- fclose(fp);
+ if (strlen(word) == 0U)
+ rval = ISC_R_SUCCESS;
+ else if (strcmp(word, "nameserver") == 0)
+ rval = resconf_parsenameserver(conf, fp);
+ else if (strcmp(word, "domain") == 0)
+ rval = resconf_parsedomain(conf, fp);
+ else if (strcmp(word, "search") == 0)
+ rval = resconf_parsesearch(conf, fp);
+ else if (strcmp(word, "sortlist") == 0)
+ rval = resconf_parsesortlist(conf, fp);
+ else if (strcmp(word, "options") == 0)
+ rval = resconf_parseoption(conf, fp);
+ else {
+ /* unrecognised word. Ignore entire line */
+ rval = ISC_R_SUCCESS;
+ stopchar = eatline(fp);
+ if (stopchar == EOF) {
+ break;
+ }
+ }
+ if (ret == ISC_R_SUCCESS && rval != ISC_R_SUCCESS)
+ ret = rval;
+ } while (1);
+
+ fclose(fp);
+ } else {
+ switch (errno) {
+ case ENOENT:
+ break;
+ default:
+ isc_mem_put(mctx, conf, sizeof(*conf));
+ return (ISC_R_INVALIDFILE);
+ }
+ }
/* If we don't find a nameserver fall back to localhost */
if (conf->numns == 0) {
@@ -575,8 +579,11 @@ irs_resconf_load(isc_mem_t *mctx, const char *filename, irs_resconf_t **confp)
if (ret != ISC_R_SUCCESS)
irs_resconf_destroy(&conf);
- else
+ else {
+ if (fp == NULL)
+ ret = ISC_R_FILENOTFOUND;
*confp = conf;
+ }
return (ret);
}
diff --git a/lib/isc/Makefile.in b/lib/isc/Makefile.in
index e8c28214..709771f7 100644
--- a/lib/isc/Makefile.in
+++ b/lib/isc/Makefile.in
@@ -1,4 +1,4 @@
-# Copyright (C) 2004-2013 Internet Systems Consortium, Inc. ("ISC")
+# Copyright (C) 2004-2014 Internet Systems Consortium, Inc. ("ISC")
# Copyright (C) 1998-2003 Internet Software Consortium.
#
# Permission to use, copy, modify, and/or distribute this software for any
@@ -64,7 +64,8 @@ OBJS = @ISC_EXTRA_OBJS@ \
rwlock.@O@ \
safe.@O@ serial.@O@ sha1.@O@ sha2.@O@ sockaddr.@O@ stats.@O@ \
string.@O@ strtoul.@O@ symtab.@O@ task.@O@ taskpool.@O@ \
- timer.@O@ version.@O@ ${UNIXOBJS} ${NLSOBJS} ${THREADOBJS}
+ tm.@O@ timer.@O@ version.@O@ \
+ ${UNIXOBJS} ${NLSOBJS} ${THREADOBJS}
SYMTBLOBJS = backtrace-emptytbl.@O@
# Alphabetically
@@ -80,7 +81,7 @@ SRCS = @ISC_EXTRA_SRCS@ \
ratelimiter.c refcount.c region.c regex.c result.c rwlock.c \
safe.c serial.c sha1.c sha2.c sockaddr.c stats.c string.c \
strtoul.c symtab.c symtbl-empty.c task.c taskpool.c timer.c \
- version.c
+ tm.c version.c
LIBS = @LIBS@
diff --git a/lib/isc/api b/lib/isc/api
index 07c646d6..a1fe77ff 100644
--- a/lib/isc/api
+++ b/lib/isc/api
@@ -4,6 +4,6 @@
# 9.8: 80-89, 120-129
# 9.9: 90-109
# 9.9-sub: 130-139
-LIBINTERFACE = 99
+LIBINTERFACE = 100
LIBREVISION = 0
-LIBAGE = 4
+LIBAGE = 5
diff --git a/lib/isc/include/isc/Makefile.in b/lib/isc/include/isc/Makefile.in
index 3b2b0369..54524bed 100644
--- a/lib/isc/include/isc/Makefile.in
+++ b/lib/isc/include/isc/Makefile.in
@@ -1,4 +1,4 @@
-# Copyright (C) 2004-2009, 2012, 2013 Internet Systems Consortium, Inc. ("ISC")
+# Copyright (C) 2004-2009, 2012-2014 Internet Systems Consortium, Inc. ("ISC")
# Copyright (C) 1998-2001, 2003 Internet Software Consortium.
#
# Permission to use, copy, modify, and/or distribute this software for any
@@ -29,18 +29,16 @@ top_srcdir = @top_srcdir@
HEADERS = app.h assertions.h base64.h bind9.h bitstring.h boolean.h \
buffer.h bufferlist.h commandline.h entropy.h error.h event.h \
eventclass.h file.h formatcheck.h fsaccess.h \
- hash.h heap.h hex.h hmacmd5.h hmacsha.h \
- httpd.h \
- interfaceiter.h @ISC_IPV6_H@ iterated_hash.h lang.h lex.h \
- lfsr.h lib.h list.h log.h \
+ hash.h heap.h hex.h hmacmd5.h hmacsha.h httpd.h \
+ interfaceiter.h @ISC_IPV6_H@ iterated_hash.h \
+ lang.h lex.h lfsr.h lib.h list.h log.h \
magic.h md5.h mem.h msgcat.h msgs.h mutexblock.h \
namespace.h netaddr.h ondestroy.h os.h parseint.h \
print.h quota.h radix.h random.h ratelimiter.h \
refcount.h regex.h region.h resource.h \
result.h resultclass.h rwlock.h safe.h serial.h sha1.h sha2.h \
- sockaddr.h socket.h stdio.h stdlib.h string.h \
- symtab.h \
- task.h taskpool.h timer.h types.h util.h version.h \
+ sockaddr.h socket.h stdio.h stdlib.h string.h symtab.h \
+ task.h taskpool.h timer.h tm.h types.h util.h version.h \
xml.h
SUBDIRS =
diff --git a/lib/isc/include/isc/tm.h b/lib/isc/include/isc/tm.h
new file mode 100644
index 00000000..44b81480
--- /dev/null
+++ b/lib/isc/include/isc/tm.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
+ *
+ * Permission to use, copy, modify, and/or 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 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.
+ */
+
+#ifndef ISC_TM_H
+#define ISC_TM_H 1
+
+/*! \file isc/tm.h
+ * Provides portable conversion routines for struct tm.
+ */
+#include <time.h>
+
+#include <isc/lang.h>
+#include <isc/types.h>
+
+
+ISC_LANG_BEGINDECLS
+
+time_t
+isc_tm_timegm(struct tm *tm);
+/*
+ * Convert a tm structure to time_t, using UTC rather than the local
+ * time zone.
+ */
+
+char *
+isc_tm_strptime(const char *buf, const char *fmt, struct tm *tm);
+/*
+ * Parse a formatted date string into struct tm.
+ */
+
+ISC_LANG_ENDDECLS
+
+#endif /* ISC_TIMER_H */
diff --git a/lib/isc/win32/strptime.c b/lib/isc/tm.c
index 10dcec1e..713ce0e5 100644
--- a/lib/isc/win32/strptime.c
+++ b/lib/isc/tm.c
@@ -1,3 +1,19 @@
+/*
+ * Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
+ *
+ * Permission to use, copy, modify, and/or 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 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.
+ */
+
/*-
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -33,10 +49,23 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#include <config.h>
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
+#include <ctype.h>
+
+#include <isc/tm.h>
+#include <isc/util.h>
+
+/*
+ * Portable conversion routines for struct tm, replacing
+ * timegm() and strptime(), which are not available on all
+ * platforms and don't always behave the same way when they
+ * are.
+ */
/*
* We do not implement alternate representations. However, we always
@@ -50,8 +79,6 @@
#define TM_YEAR_BASE 1900
#endif
-static int conv_num(const char **, int *, int, int);
-
static const char *day[7] = {
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday"
@@ -71,9 +98,58 @@ static const char *am_pm[2] = {
"AM", "PM"
};
-static char *
-strptime(const char *buf, const char *fmt, struct tm *tm) {
- char c;
+static int
+conv_num(const char **buf, int *dest, int llim, int ulim) {
+ int result = 0;
+
+ /* The limit also determines the number of valid digits. */
+ int rulim = ulim;
+
+ if (**buf < '0' || **buf > '9')
+ return (0);
+
+ do {
+ result *= 10;
+ result += *(*buf)++ - '0';
+ rulim /= 10;
+ } while ((result * 10 <= ulim) &&
+ rulim && **buf >= '0' && **buf <= '9');
+
+ if (result < llim || result > ulim)
+ return (0);
+
+ *dest = result;
+ return (1);
+}
+
+time_t
+isc_tm_timegm(struct tm *tm) {
+ time_t ret;
+ int i, yday = 0, leapday;
+ int mdays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30 };
+
+ leapday = ((((tm->tm_year + 1900 ) % 4) == 0 &&
+ ((tm->tm_year + 1900 ) % 100) != 0) ||
+ ((tm->tm_year + 1900 ) % 400) == 0) ? 1 : 0;
+ mdays[1] += leapday;
+
+ yday = tm->tm_mday - 1;
+ for (i = 1; i <= tm->tm_mon; i++)
+ yday += mdays[i - 1];
+ ret = tm->tm_sec +
+ (60 * tm->tm_min) +
+ (3600 * tm->tm_hour) +
+ (86400 * (yday +
+ ((tm->tm_year - 70) * 365) +
+ ((tm->tm_year - 69) / 4) -
+ ((tm->tm_year - 1) / 100) +
+ ((tm->tm_year + 299) / 400)));
+ return (ret);
+}
+
+char *
+isc_tm_strptime(const char *buf, const char *fmt, struct tm *tm) {
+ char c, *ret;
const char *bp;
size_t len = 0;
int alt_format, i, split_year = 0;
@@ -85,8 +161,8 @@ strptime(const char *buf, const char *fmt, struct tm *tm) {
alt_format = 0;
/* Eat up white-space. */
- if (isspace(c)) {
- while (isspace(*bp))
+ if (isspace((unsigned char) c)) {
+ while (isspace((unsigned char) *bp))
bp++;
fmt++;
@@ -123,43 +199,43 @@ literal:
*/
case 'c': /* Date and time, using the locale's format. */
LEGAL_ALT(ALT_E);
- if (!(bp = strptime(bp, "%x %X", tm)))
+ if (!(bp = isc_tm_strptime(bp, "%x %X", tm)))
return (0);
break;
case 'D': /* The date as "%m/%d/%y". */
LEGAL_ALT(0);
- if (!(bp = strptime(bp, "%m/%d/%y", tm)))
+ if (!(bp = isc_tm_strptime(bp, "%m/%d/%y", tm)))
return (0);
break;
case 'R': /* The time as "%H:%M". */
LEGAL_ALT(0);
- if (!(bp = strptime(bp, "%H:%M", tm)))
+ if (!(bp = isc_tm_strptime(bp, "%H:%M", tm)))
return (0);
break;
case 'r': /* The time in 12-hour clock representation. */
LEGAL_ALT(0);
- if (!(bp = strptime(bp, "%I:%M:%S %p", tm)))
+ if (!(bp = isc_tm_strptime(bp, "%I:%M:%S %p", tm)))
return (0);
break;
case 'T': /* The time as "%H:%M:%S". */
LEGAL_ALT(0);
- if (!(bp = strptime(bp, "%H:%M:%S", tm)))
+ if (!(bp = isc_tm_strptime(bp, "%H:%M:%S", tm)))
return (0);
break;
case 'X': /* The time, using the locale's format. */
LEGAL_ALT(ALT_E);
- if (!(bp = strptime(bp, "%H:%M:%S", tm)))
+ if (!(bp = isc_tm_strptime(bp, "%H:%M:%S", tm)))
return (0);
break;
case 'x': /* The date, using the locale's format. */
LEGAL_ALT(ALT_E);
- if (!(bp = strptime(bp, "%m/%d/%y", tm)))
+ if (!(bp = isc_tm_strptime(bp, "%m/%d/%y", tm)))
return (0);
break;
@@ -351,7 +427,7 @@ literal:
case 'n': /* Any kind of white-space. */
case 't':
LEGAL_ALT(0);
- while (isspace(*bp))
+ while (isspace((unsigned char) *bp))
bp++;
break;
@@ -364,29 +440,6 @@ literal:
}
/* LINTED functional specification */
- return ((char *)bp);
-}
-
-static int
-conv_num(const char **buf, int *dest, int llim, int ulim) {
- int result = 0;
-
- /* The limit also determines the number of valid digits. */
- int rulim = ulim;
-
- if (**buf < '0' || **buf > '9')
- return (0);
-
- do {
- result *= 10;
- result += *(*buf)++ - '0';
- rulim /= 10;
- } while ((result * 10 <= ulim) &&
- rulim && **buf >= '0' && **buf <= '9');
-
- if (result < llim || result > ulim)
- return (0);
-
- *dest = result;
- return (1);
+ DE_CONST(bp, ret);
+ return (ret);
}
diff --git a/lib/isc/unix/time.c b/lib/isc/unix/time.c
index 9039b06a..890b9192 100644
--- a/lib/isc/unix/time.c
+++ b/lib/isc/unix/time.c
@@ -34,6 +34,7 @@
#include <isc/strerror.h>
#include <isc/string.h>
#include <isc/time.h>
+#include <isc/tm.h>
#include <isc/util.h>
#define NS_PER_S 1000000000 /*%< Nanoseconds per second. */
@@ -408,31 +409,6 @@ isc_time_formathttptimestamp(const isc_time_t *t, char *buf, unsigned int len) {
INSIST(flen < len);
}
-static time_t
-timetfromtm(struct tm *tm) {
- time_t ret;
- int i, yday = 0, leapday;
- int mdays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30 };
-
- leapday = ((((tm->tm_year + 1900 ) % 4) == 0 &&
- ((tm->tm_year + 1900 ) % 100) != 0) ||
- ((tm->tm_year + 1900 ) % 400) == 0) ? 1 : 0;
- mdays[1] += leapday;
-
- yday = tm->tm_mday - 1;
- for (i = 1; i <= tm->tm_mon; i++)
- yday += mdays[i - 1];
- ret = tm->tm_sec +
- (60 * tm->tm_min) +
- (3600 * tm->tm_hour) +
- (86400 * (yday +
- ((tm->tm_year - 70) * 365) +
- ((tm->tm_year - 69) / 4) -
- ((tm->tm_year - 1) / 100) +
- ((tm->tm_year + 299) / 400)));
- return (ret);
-}
-
isc_result_t
isc_time_parsehttptimestamp(char *buf, isc_time_t *t) {
struct tm t_tm;
@@ -441,10 +417,10 @@ isc_time_parsehttptimestamp(char *buf, isc_time_t *t) {
REQUIRE(buf != NULL);
REQUIRE(t != NULL);
- p = strptime(buf, "%a, %d %b %Y %H:%M:%S", &t_tm);
+ p = isc_tm_strptime(buf, "%a, %d %b %Y %H:%M:%S", &t_tm);
if (p == NULL)
return (ISC_R_UNEXPECTED);
- when = timetfromtm(&t_tm);
+ when = isc_tm_timegm(&t_tm);
if (when == -1)
return (ISC_R_UNEXPECTED);
isc_time_set(t, when, 0);
diff --git a/lib/isc/win32/libisc.def.in b/lib/isc/win32/libisc.def.in
index f03fd879..94363250 100644
--- a/lib/isc/win32/libisc.def.in
+++ b/lib/isc/win32/libisc.def.in
@@ -588,6 +588,8 @@ isc_time_seconds
isc_time_set
isc_time_settoepoch
isc_time_subtract
+isc_tm_timegm
+isc_tm_strptime
isc_win32os_majorversion
isc_win32os_minorversion
isc_win32os_servicepackmajor
diff --git a/lib/isc/win32/libisc.dsp.in b/lib/isc/win32/libisc.dsp.in
index a68dd9e3..2c06974a 100644
--- a/lib/isc/win32/libisc.dsp.in
+++ b/lib/isc/win32/libisc.dsp.in
@@ -561,6 +561,10 @@ SOURCE=..\include\isc\timer.h
# End Source File
# Begin Source File
+SOURCE=..\include\isc\tm.h
+# End Source File
+# Begin Source File
+
SOURCE=.\include\isc\win32os.h
# End Source File
# Begin Source File
@@ -805,6 +809,10 @@ SOURCE=..\timer.c
# End Source File
# Begin Source File
+SOURCE=..\tm.c
+# End Source File
+# Begin Source File
+
SOURCE=.\win32os.c
# End Source File
# End Group
diff --git a/lib/isc/win32/libisc.mak.in b/lib/isc/win32/libisc.mak.in
index f1c754a0..5cca6d96 100644
--- a/lib/isc/win32/libisc.mak.in
+++ b/lib/isc/win32/libisc.mak.in
@@ -192,6 +192,7 @@ CLEAN :
-@erase "$(INTDIR)\thread.obj"
-@erase "$(INTDIR)\time.obj"
-@erase "$(INTDIR)\timer.obj"
+ -@erase "$(INTDIR)\tm.obj"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(INTDIR)\version.obj"
-@erase "$(INTDIR)\win32os.obj"
@@ -289,6 +290,7 @@ LINK32_OBJS= \
"$(INTDIR)\task.obj" \
"$(INTDIR)\taskpool.obj" \
"$(INTDIR)\timer.obj" \
+ "$(INTDIR)\tm.obj" \
"$(INTDIR)\parseint.obj" \
"$(INTDIR)\pool.obj" \
"$(INTDIR)\portset.obj" \
@@ -469,6 +471,8 @@ CLEAN :
-@erase "$(INTDIR)\time.sbr"
-@erase "$(INTDIR)\timer.obj"
-@erase "$(INTDIR)\timer.sbr"
+ -@erase "$(INTDIR)\tm.obj"
+ -@erase "$(INTDIR)\tm.sbr"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(INTDIR)\vc60.pdb"
-@erase "$(INTDIR)\version.obj"
@@ -567,6 +571,7 @@ BSC32_SBRS= \
"$(INTDIR)\task.sbr" \
"$(INTDIR)\taskpool.sbr" \
"$(INTDIR)\timer.sbr" \
+ "$(INTDIR)\tm.sbr" \
"$(INTDIR)\parseint.sbr" \
"$(INTDIR)\pool.sbr" \
"$(INTDIR)\portset.sbr" \
@@ -658,6 +663,7 @@ LINK32_OBJS= \
"$(INTDIR)\task.obj" \
"$(INTDIR)\taskpool.obj" \
"$(INTDIR)\timer.obj" \
+ "$(INTDIR)\tm.obj" \
"$(INTDIR)\parseint.obj" \
"$(INTDIR)\pool.obj" \
"$(INTDIR)\portset.obj" \
@@ -2105,6 +2111,24 @@ SOURCE=..\timer.c
!ENDIF
+SOURCE=..\tm.c
+
+!IF "$(CFG)" == "libisc - @PLATFORM@ Release"
+
+
+"$(INTDIR)\tm.obj" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+!ELSEIF "$(CFG)" == "libisc - @PLATFORM@ Debug"
+
+
+"$(INTDIR)\tm.obj" "$(INTDIR)\tm.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+!ENDIF
+
!ENDIF
diff --git a/lib/isc/win32/libisc.vcxproj.filters.in b/lib/isc/win32/libisc.vcxproj.filters.in
index ea3c2e30..e7b3c793 100644
--- a/lib/isc/win32/libisc.vcxproj.filters.in
+++ b/lib/isc/win32/libisc.vcxproj.filters.in
@@ -248,6 +248,9 @@
<ClInclude Include="..\include\isc\timer.h">
<Filter>Library Header Files</Filter>
</ClInclude>
+ <ClInclude Include="..\include\isc\tm.h">
+ <Filter>Library Header Files</Filter>
+ </ClInclude>
<ClInclude Include="..\include\isc\types.h">
<Filter>Library Header Files</Filter>
</ClInclude>
@@ -593,5 +596,8 @@
<ClCompile Include="..\timer.c">
<Filter>Library Source Files</Filter>
</ClCompile>
+ <ClCompile Include="..\tm.c">
+ <Filter>Library Source Files</Filter>
+ </ClCompile>
</ItemGroup>
-</Project> \ No newline at end of file
+</Project>
diff --git a/lib/isc/win32/libisc.vcxproj.in b/lib/isc/win32/libisc.vcxproj.in
index 4e459cec..7a915240 100644
--- a/lib/isc/win32/libisc.vcxproj.in
+++ b/lib/isc/win32/libisc.vcxproj.in
@@ -312,6 +312,7 @@ copy /Y @VCREDIST_PATH@ ..\Build\Release\
<ClInclude Include="..\include\isc\task.h" />
<ClInclude Include="..\include\isc\taskpool.h" />
<ClInclude Include="..\include\isc\timer.h" />
+ <ClInclude Include="..\include\isc\tm.h" />
<ClInclude Include="..\include\isc\types.h" />
<ClInclude Include="..\include\isc\util.h" />
<ClInclude Include="..\include\isc\version.h" />
@@ -405,6 +406,7 @@ copy /Y @VCREDIST_PATH@ ..\Build\Release\
<ClCompile Include="..\task.c" />
<ClCompile Include="..\taskpool.c" />
<ClCompile Include="..\timer.c" />
+ <ClCompile Include="..\tm.c" />
<ClCompile Include="app.c" />
<ClCompile Include="condition.c" />
<ClCompile Include="dir.c" />
@@ -434,4 +436,4 @@ copy /Y @VCREDIST_PATH@ ..\Build\Release\
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
-</Project> \ No newline at end of file
+</Project>
diff --git a/lib/isc/win32/time.c b/lib/isc/win32/time.c
index 6c38e25a..d6993f93 100644
--- a/lib/isc/win32/time.c
+++ b/lib/isc/win32/time.c
@@ -30,6 +30,7 @@
#include <isc/assertions.h>
#include <isc/time.h>
+#include <isc/tm.h>
#include <isc/util.h>
/*
@@ -318,32 +319,6 @@ isc_time_formathttptimestamp(const isc_time_t *t, char *buf, unsigned int len) {
}
}
-static time_t
-timetfromtm(struct tm *tm) {
- time_t ret;
- int i, yday = 0, leapday;
- int mdays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30 };
-
- leapday = ((((tm->tm_year + 1900 ) % 4) == 0 &&
- ((tm->tm_year + 1900 ) % 100) != 0) ||
- ((tm->tm_year + 1900 ) % 400) == 0) ? 1 : 0;
- mdays[1] += leapday;
-
- yday = tm->tm_mday - 1;
- for (i = 1; i <= tm->tm_mon; i++)
- yday += mdays[i - 1];
- ret = tm->tm_sec +
- (60 * tm->tm_min) +
- (3600 * tm->tm_hour) +
- (86400 * (yday +
- ((tm->tm_year - 70) * 365) +
- ((tm->tm_year - 69) / 4) -
- ((tm->tm_year - 1) / 100) +
- ((tm->tm_year + 299) / 400)));
- return (ret);
-}
-
-#include "strptime.c"
isc_result_t
isc_time_parsehttptimestamp(char *buf, isc_time_t *t) {
struct tm t_tm;
@@ -352,10 +327,10 @@ isc_time_parsehttptimestamp(char *buf, isc_time_t *t) {
REQUIRE(buf != NULL);
REQUIRE(t != NULL);
- p = strptime(buf, "%a, %d %b %Y %H:%M:%S", &t_tm);
+ p = isc_tm_strptime(buf, "%a, %d %b %Y %H:%M:%S", &t_tm);
if (p == NULL)
return (ISC_R_UNEXPECTED);
- when = timetfromtm(&t_tm);
+ when = isc_tm_timegm(&t_tm);
if (when == -1)
return (ISC_R_UNEXPECTED);
isc_time_set(t, when, 0);