than embedding a copy. Discussed upstream but was not desired.
History:
+r10 : make timezone case insensitive
r9: fix another compile error without --with-system-tzdata configured (Michael Heimpold)
r8: fix compile error without --with-system-tzdata configured
r7: improve check for valid timezone id to exclude directories
--- a/ext/date/lib/parse_tz.c
+++ b/ext/date/lib/parse_tz.c
-@@ -24,6 +24,16 @@
+@@ -20,6 +20,16 @@
#include "timelib.h"
#include <stdio.h>
#ifdef HAVE_LOCALE_H
-@@ -35,7 +45,12 @@
+@@ -31,7 +41,12 @@
#else
#include <strings.h>
#endif
#if (defined(__APPLE__) || defined(__APPLE_CC__)) && (defined(__BIG_ENDIAN__) || defined(__LITTLE_ENDIAN__))
# if defined(__LITTLE_ENDIAN__)
-@@ -55,9 +70,14 @@
+@@ -51,9 +66,14 @@
static void read_preamble(const unsigned char **tzf, timelib_tzinfo *tz)
{
/* read BC flag */
tz->bc = (**tzf == '\1');
*tzf += 1;
-@@ -260,7 +280,397 @@ void timelib_dump_tzinfo(timelib_tzinfo
+@@ -256,7 +276,405 @@
}
}
+#endif
+
+/* System timezone database pointer. */
-+static const timelib_tzdb *timezonedb_system = NULL;
++static const timelib_tzdb *timezonedb_system;
+
+/* Hash table entry for the cache of the zone.tab mapping table. */
+struct location_info {
+ * prevent too many collisions. */
+#define LOCINFO_HASH_SIZE (1021)
+
++/* Compute a case insensitive hash of str */
+static uint32_t tz_hash(const char *str)
+{
+ const unsigned char *p = (const unsigned char *)str;
+ uint32_t hash = 5381;
+ int c;
+
-+ while ((c = *p++) != '\0') {
++ while ((c = tolower(*p++)) != '\0') {
+ hash = (hash << 5) ^ hash ^ c;
+ }
+
+ return NULL;
+ }
+
++ if (system_location_table) {
++ const struct location_info *li;
++ if ((li = find_zone_info(system_location_table, timezone)) != NULL) {
++ /* Use the stored name to avoid case issue */
++ timezone = li->name;
++ }
++ }
+ snprintf(fname, sizeof fname, ZONEINFO_PREFIX "/%s", timezone);
+
+ fd = open(fname, O_RDONLY);
{
int left = 0, right = tzdb->index_size - 1;
#ifdef HAVE_SETLOCALE
-@@ -299,36 +709,128 @@ static int seek_to_tz_position(const uns
+@@ -295,36 +713,135 @@
return 0;
}
+ struct stat st;
+
+ if (timezone[0] == '\0' || strstr(timezone, "..") != NULL) {
-+ return 0;
++ return 0;
++ }
++
++ if (system_location_table) {
++ if (find_zone_info(system_location_table, timezone) != NULL) {
++ /* found in cache */
++ return 1;
++ }
+ }
+
+ snprintf(fname, sizeof fname, ZONEINFO_PREFIX "/%s", timezone);