]>
Commit | Line | Data |
---|---|---|
c0240cb1 | 1 | Add support for use of the system timezone database, rather |
2 | than embedding a copy. Discussed upstream but was not desired. | |
3 | ||
4 | History: | |
a659fa18 ER |
5 | r12: adapt for upstream changes for new zic |
6 | r11: use canonical names to avoid more case sensitivity issues | |
7 | round lat/long from zone.tab towards zero per builtin db | |
8 | r10: make timezone case insensitive | |
361fb152 ER |
9 | r9: fix another compile error without --with-system-tzdata configured (Michael Heimpold) |
10 | r8: fix compile error without --with-system-tzdata configured | |
c0240cb1 | 11 | r7: improve check for valid timezone id to exclude directories |
a659fa18 | 12 | r6: fix fd leak in r5, fix country code/BC flag use in |
c0240cb1 | 13 | timezone_identifiers_list() using system db, |
14 | fix use of PECL timezonedb to override system db, | |
15 | r5: reverts addition of "System/Localtime" fake tzname. | |
16 | updated for 5.3.0, parses zone.tab to pick up mapping between | |
17 | timezone name, country code and long/lat coords | |
18 | r4: added "System/Localtime" tzname which uses /etc/localtime | |
19 | r3: fix a crash if /usr/share/zoneinfo doesn't exist (Raphael Geissert) | |
20 | r2: add filesystem trawl to set up name alias index | |
21 | r1: initial revision | |
22 | ||
a659fa18 ER |
23 | diff -up php-5.6.9RC1/ext/date/lib/parse_tz.c.systzdata php-5.6.9RC1/ext/date/lib/parse_tz.c |
24 | --- php-5.6.9RC1/ext/date/lib/parse_tz.c.systzdata 2015-04-30 00:00:18.000000000 +0200 | |
25 | +++ php-5.6.9RC1/ext/date/lib/parse_tz.c 2015-04-30 06:36:47.019617321 +0200 | |
7588b36c | 26 | @@ -20,6 +20,16 @@ |
c0240cb1 | 27 | |
28 | #include "timelib.h" | |
29 | ||
30 | +#ifdef HAVE_SYSTEM_TZDATA | |
31 | +#include <sys/mman.h> | |
32 | +#include <sys/stat.h> | |
33 | +#include <limits.h> | |
34 | +#include <fcntl.h> | |
35 | +#include <unistd.h> | |
36 | + | |
37 | +#include "php_scandir.h" | |
38 | +#endif | |
39 | + | |
40 | #include <stdio.h> | |
41 | ||
42 | #ifdef HAVE_LOCALE_H | |
7588b36c | 43 | @@ -31,7 +41,12 @@ |
c0240cb1 | 44 | #else |
45 | #include <strings.h> | |
46 | #endif | |
47 | + | |
48 | +#ifndef HAVE_SYSTEM_TZDATA | |
49 | #include "timezonedb.h" | |
50 | +#endif | |
51 | + | |
52 | +#include <ctype.h> | |
53 | ||
54 | #if (defined(__APPLE__) || defined(__APPLE_CC__)) && (defined(__BIG_ENDIAN__) || defined(__LITTLE_ENDIAN__)) | |
55 | # if defined(__LITTLE_ENDIAN__) | |
a659fa18 | 56 | @@ -53,6 +68,10 @@ static int read_preamble(const unsigned |
c0240cb1 | 57 | { |
a659fa18 ER |
58 | uint32_t version; |
59 | ||
60 | + if (memcmp(*tzf, "TZif", 4) == 0) { | |
61 | + *tzf += 20; | |
62 | + return 0; | |
63 | + } | |
64 | /* read ID */ | |
65 | version = (*tzf)[3] - '0'; | |
66 | *tzf += 4; | |
67 | @@ -296,7 +315,418 @@ void timelib_dump_tzinfo(timelib_tzinfo | |
c0240cb1 | 68 | } |
69 | } | |
70 | ||
71 | -static int seek_to_tz_position(const unsigned char **tzf, char *timezone, const timelib_tzdb *tzdb) | |
72 | +#ifdef HAVE_SYSTEM_TZDATA | |
73 | + | |
74 | +#ifdef HAVE_SYSTEM_TZDATA_PREFIX | |
75 | +#define ZONEINFO_PREFIX HAVE_SYSTEM_TZDATA_PREFIX | |
76 | +#else | |
77 | +#define ZONEINFO_PREFIX "/usr/share/zoneinfo" | |
78 | +#endif | |
79 | + | |
80 | +/* System timezone database pointer. */ | |
7588b36c | 81 | +static const timelib_tzdb *timezonedb_system; |
c0240cb1 | 82 | + |
83 | +/* Hash table entry for the cache of the zone.tab mapping table. */ | |
84 | +struct location_info { | |
85 | + char code[2]; | |
86 | + double latitude, longitude; | |
87 | + char name[64]; | |
88 | + char *comment; | |
89 | + struct location_info *next; | |
90 | +}; | |
91 | + | |
92 | +/* Cache of zone.tab. */ | |
93 | +static struct location_info **system_location_table; | |
94 | + | |
95 | +/* Size of the zone.tab hash table; a random-ish prime big enough to | |
96 | + * prevent too many collisions. */ | |
97 | +#define LOCINFO_HASH_SIZE (1021) | |
98 | + | |
7588b36c | 99 | +/* Compute a case insensitive hash of str */ |
c0240cb1 | 100 | +static uint32_t tz_hash(const char *str) |
101 | +{ | |
102 | + const unsigned char *p = (const unsigned char *)str; | |
103 | + uint32_t hash = 5381; | |
104 | + int c; | |
105 | + | |
7588b36c | 106 | + while ((c = tolower(*p++)) != '\0') { |
c0240cb1 | 107 | + hash = (hash << 5) ^ hash ^ c; |
108 | + } | |
109 | + | |
110 | + return hash % LOCINFO_HASH_SIZE; | |
111 | +} | |
112 | + | |
113 | +/* Parse an ISO-6709 date as used in zone.tab. Returns end of the | |
114 | + * parsed string on success, or NULL on parse error. On success, | |
115 | + * writes the parsed number to *result. */ | |
116 | +static char *parse_iso6709(char *p, double *result) | |
117 | +{ | |
118 | + double v, sign; | |
119 | + char *pend; | |
120 | + size_t len; | |
121 | + | |
122 | + if (*p == '+') | |
123 | + sign = 1.0; | |
124 | + else if (*p == '-') | |
125 | + sign = -1.0; | |
126 | + else | |
127 | + return NULL; | |
128 | + | |
129 | + p++; | |
130 | + for (pend = p; *pend >= '0' && *pend <= '9'; pend++) | |
131 | + ;; | |
132 | + | |
133 | + /* Annoying encoding used by zone.tab has no decimal point, so use | |
134 | + * the length to determine the format: | |
135 | + * | |
136 | + * 4 = DDMM | |
137 | + * 5 = DDDMM | |
138 | + * 6 = DDMMSS | |
139 | + * 7 = DDDMMSS | |
140 | + */ | |
141 | + len = pend - p; | |
142 | + if (len < 4 || len > 7) { | |
143 | + return NULL; | |
144 | + } | |
145 | + | |
146 | + /* p => [D]DD */ | |
147 | + v = (p[0] - '0') * 10.0 + (p[1] - '0'); | |
148 | + p += 2; | |
149 | + if (len == 5 || len == 7) | |
150 | + v = v * 10.0 + (*p++ - '0'); | |
151 | + /* p => MM[SS] */ | |
152 | + v += (10.0 * (p[0] - '0') | |
153 | + + p[1] - '0') / 60.0; | |
154 | + p += 2; | |
155 | + /* p => [SS] */ | |
156 | + if (len > 5) { | |
157 | + v += (10.0 * (p[0] - '0') | |
158 | + + p[1] - '0') / 3600.0; | |
159 | + p += 2; | |
160 | + } | |
161 | + | |
162 | + /* Round to five decimal place, not because it's a good idea, | |
163 | + * but, because the builtin data uses rounded data, so, match | |
164 | + * that. */ | |
a659fa18 | 165 | + *result = trunc(v * sign * 100000.0) / 100000.0; |
c0240cb1 | 166 | + |
167 | + return p; | |
168 | +} | |
169 | + | |
170 | +/* This function parses the zone.tab file to build up the mapping of | |
171 | + * timezone to country code and geographic location, and returns a | |
172 | + * hash table. The hash table is indexed by the function: | |
173 | + * | |
174 | + * tz_hash(timezone-name) | |
175 | + */ | |
176 | +static struct location_info **create_location_table(void) | |
177 | +{ | |
178 | + struct location_info **li, *i; | |
179 | + char zone_tab[PATH_MAX]; | |
180 | + char line[512]; | |
181 | + FILE *fp; | |
182 | + | |
183 | + strncpy(zone_tab, ZONEINFO_PREFIX "/zone.tab", sizeof zone_tab); | |
184 | + | |
185 | + fp = fopen(zone_tab, "r"); | |
186 | + if (!fp) { | |
187 | + return NULL; | |
188 | + } | |
189 | + | |
190 | + li = calloc(LOCINFO_HASH_SIZE, sizeof *li); | |
191 | + | |
192 | + while (fgets(line, sizeof line, fp)) { | |
193 | + char *p = line, *code, *name, *comment; | |
194 | + uint32_t hash; | |
195 | + double latitude, longitude; | |
196 | + | |
197 | + while (isspace(*p)) | |
198 | + p++; | |
199 | + | |
200 | + if (*p == '#' || *p == '\0' || *p == '\n') | |
201 | + continue; | |
202 | + | |
203 | + if (!isalpha(p[0]) || !isalpha(p[1]) || p[2] != '\t') | |
204 | + continue; | |
205 | + | |
206 | + /* code => AA */ | |
207 | + code = p; | |
208 | + p[2] = 0; | |
209 | + p += 3; | |
210 | + | |
211 | + /* coords => [+-][D]DDMM[SS][+-][D]DDMM[SS] */ | |
212 | + p = parse_iso6709(p, &latitude); | |
213 | + if (!p) { | |
214 | + continue; | |
215 | + } | |
216 | + p = parse_iso6709(p, &longitude); | |
217 | + if (!p) { | |
218 | + continue; | |
219 | + } | |
220 | + | |
221 | + if (!p || *p != '\t') { | |
222 | + continue; | |
223 | + } | |
224 | + | |
225 | + /* name = string */ | |
226 | + name = ++p; | |
227 | + while (*p != '\t' && *p && *p != '\n') | |
228 | + p++; | |
229 | + | |
230 | + *p++ = '\0'; | |
231 | + | |
232 | + /* comment = string */ | |
233 | + comment = p; | |
234 | + while (*p != '\t' && *p && *p != '\n') | |
235 | + p++; | |
236 | + | |
237 | + if (*p == '\n' || *p == '\t') | |
238 | + *p = '\0'; | |
239 | + | |
240 | + hash = tz_hash(name); | |
241 | + i = malloc(sizeof *i); | |
242 | + memcpy(i->code, code, 2); | |
243 | + strncpy(i->name, name, sizeof i->name); | |
244 | + i->comment = strdup(comment); | |
245 | + i->longitude = longitude; | |
246 | + i->latitude = latitude; | |
247 | + i->next = li[hash]; | |
248 | + li[hash] = i; | |
249 | + /* printf("%s [%u, %f, %f]\n", name, hash, latitude, longitude); */ | |
250 | + } | |
251 | + | |
252 | + fclose(fp); | |
253 | + | |
254 | + return li; | |
255 | +} | |
256 | + | |
257 | +/* Return location info from hash table, using given timezone name. | |
258 | + * Returns NULL if the name could not be found. */ | |
259 | +const struct location_info *find_zone_info(struct location_info **li, | |
260 | + const char *name) | |
261 | +{ | |
262 | + uint32_t hash = tz_hash(name); | |
263 | + const struct location_info *l; | |
264 | + | |
265 | + if (!li) { | |
266 | + return NULL; | |
267 | + } | |
268 | + | |
269 | + for (l = li[hash]; l; l = l->next) { | |
270 | + if (strcasecmp(l->name, name) == 0) | |
271 | + return l; | |
272 | + } | |
273 | + | |
274 | + return NULL; | |
275 | +} | |
276 | + | |
277 | +/* Filter out some non-tzdata files and the posix/right databases, if | |
278 | + * present. */ | |
279 | +static int index_filter(const struct dirent *ent) | |
280 | +{ | |
281 | + return strcmp(ent->d_name, ".") != 0 | |
282 | + && strcmp(ent->d_name, "..") != 0 | |
283 | + && strcmp(ent->d_name, "posix") != 0 | |
284 | + && strcmp(ent->d_name, "posixrules") != 0 | |
285 | + && strcmp(ent->d_name, "right") != 0 | |
286 | + && strstr(ent->d_name, ".tab") == NULL; | |
287 | +} | |
288 | + | |
289 | +static int sysdbcmp(const void *first, const void *second) | |
290 | +{ | |
291 | + const timelib_tzdb_index_entry *alpha = first, *beta = second; | |
292 | + | |
a659fa18 | 293 | + return strcasecmp(alpha->id, beta->id); |
c0240cb1 | 294 | +} |
295 | + | |
296 | + | |
297 | +/* Create the zone identifier index by trawling the filesystem. */ | |
298 | +static void create_zone_index(timelib_tzdb *db) | |
299 | +{ | |
300 | + size_t dirstack_size, dirstack_top; | |
301 | + size_t index_size, index_next; | |
302 | + timelib_tzdb_index_entry *db_index; | |
303 | + char **dirstack; | |
304 | + | |
305 | + /* LIFO stack to hold directory entries to scan; each slot is a | |
306 | + * directory name relative to the zoneinfo prefix. */ | |
307 | + dirstack_size = 32; | |
308 | + dirstack = malloc(dirstack_size * sizeof *dirstack); | |
309 | + dirstack_top = 1; | |
310 | + dirstack[0] = strdup(""); | |
311 | + | |
312 | + /* Index array. */ | |
313 | + index_size = 64; | |
314 | + db_index = malloc(index_size * sizeof *db_index); | |
315 | + index_next = 0; | |
316 | + | |
317 | + do { | |
318 | + struct dirent **ents; | |
319 | + char name[PATH_MAX], *top; | |
320 | + int count; | |
321 | + | |
322 | + /* Pop the top stack entry, and iterate through its contents. */ | |
323 | + top = dirstack[--dirstack_top]; | |
324 | + snprintf(name, sizeof name, ZONEINFO_PREFIX "/%s", top); | |
325 | + | |
326 | + count = php_scandir(name, &ents, index_filter, php_alphasort); | |
327 | + | |
328 | + while (count > 0) { | |
329 | + struct stat st; | |
330 | + const char *leaf = ents[count - 1]->d_name; | |
331 | + | |
332 | + snprintf(name, sizeof name, ZONEINFO_PREFIX "/%s/%s", | |
333 | + top, leaf); | |
334 | + | |
335 | + if (strlen(name) && stat(name, &st) == 0) { | |
336 | + /* Name, relative to the zoneinfo prefix. */ | |
337 | + const char *root = top; | |
338 | + | |
339 | + if (root[0] == '/') root++; | |
340 | + | |
341 | + snprintf(name, sizeof name, "%s%s%s", root, | |
342 | + *root ? "/": "", leaf); | |
343 | + | |
344 | + if (S_ISDIR(st.st_mode)) { | |
345 | + if (dirstack_top == dirstack_size) { | |
346 | + dirstack_size *= 2; | |
347 | + dirstack = realloc(dirstack, | |
348 | + dirstack_size * sizeof *dirstack); | |
349 | + } | |
350 | + dirstack[dirstack_top++] = strdup(name); | |
351 | + } | |
352 | + else { | |
353 | + if (index_next == index_size) { | |
354 | + index_size *= 2; | |
355 | + db_index = realloc(db_index, | |
356 | + index_size * sizeof *db_index); | |
357 | + } | |
358 | + | |
359 | + db_index[index_next++].id = strdup(name); | |
360 | + } | |
361 | + } | |
362 | + | |
363 | + free(ents[--count]); | |
364 | + } | |
365 | + | |
366 | + if (count != -1) free(ents); | |
367 | + free(top); | |
368 | + } while (dirstack_top); | |
369 | + | |
370 | + qsort(db_index, index_next, sizeof *db_index, sysdbcmp); | |
371 | + | |
372 | + db->index = db_index; | |
373 | + db->index_size = index_next; | |
374 | + | |
375 | + free(dirstack); | |
376 | +} | |
377 | + | |
378 | +#define FAKE_HEADER "1234\0??\1??" | |
379 | +#define FAKE_UTC_POS (7 - 4) | |
380 | + | |
381 | +/* Create a fake data segment for database 'sysdb'. */ | |
382 | +static void fake_data_segment(timelib_tzdb *sysdb, | |
383 | + struct location_info **info) | |
384 | +{ | |
385 | + size_t n; | |
386 | + char *data, *p; | |
387 | + | |
388 | + data = malloc(3 * sysdb->index_size + 7); | |
389 | + | |
390 | + p = mempcpy(data, FAKE_HEADER, sizeof(FAKE_HEADER) - 1); | |
391 | + | |
392 | + for (n = 0; n < sysdb->index_size; n++) { | |
393 | + const struct location_info *li; | |
394 | + timelib_tzdb_index_entry *ent; | |
395 | + | |
396 | + ent = (timelib_tzdb_index_entry *)&sysdb->index[n]; | |
397 | + | |
398 | + /* Lookup the timezone name in the hash table. */ | |
399 | + if (strcmp(ent->id, "UTC") == 0) { | |
400 | + ent->pos = FAKE_UTC_POS; | |
401 | + continue; | |
402 | + } | |
403 | + | |
404 | + li = find_zone_info(info, ent->id); | |
405 | + if (li) { | |
406 | + /* If found, append the BC byte and the | |
407 | + * country code; set the position for this | |
408 | + * section of timezone data. */ | |
409 | + ent->pos = (p - data) - 4; | |
410 | + *p++ = '\1'; | |
411 | + *p++ = li->code[0]; | |
412 | + *p++ = li->code[1]; | |
413 | + } | |
414 | + else { | |
415 | + /* If not found, the timezone data can | |
416 | + * point at the header. */ | |
417 | + ent->pos = 0; | |
418 | + } | |
419 | + } | |
420 | + | |
421 | + sysdb->data = (unsigned char *)data; | |
422 | +} | |
423 | + | |
424 | +/* Returns true if the passed-in stat structure describes a | |
425 | + * probably-valid timezone file. */ | |
426 | +static int is_valid_tzfile(const struct stat *st) | |
427 | +{ | |
428 | + return S_ISREG(st->st_mode) && st->st_size > 20; | |
429 | +} | |
430 | + | |
a659fa18 ER |
431 | +/* To allow timezone names to be used case-insensitively, find the |
432 | + * canonical name for this timezone, if possible. */ | |
433 | +static const char *canonical_tzname(const char *timezone) | |
434 | +{ | |
435 | + if (timezonedb_system) { | |
436 | + timelib_tzdb_index_entry *ent, lookup; | |
437 | + | |
438 | + lookup.id = (char *)timezone; | |
439 | + | |
440 | + ent = bsearch(&lookup, timezonedb_system->index, | |
441 | + timezonedb_system->index_size, sizeof lookup, | |
442 | + sysdbcmp); | |
443 | + if (ent) { | |
444 | + return ent->id; | |
445 | + } | |
446 | + } | |
447 | + | |
448 | + return timezone; | |
449 | +} | |
450 | + | |
c0240cb1 | 451 | +/* Return the mmap()ed tzfile if found, else NULL. On success, the |
452 | + * length of the mapped data is placed in *length. */ | |
453 | +static char *map_tzfile(const char *timezone, size_t *length) | |
454 | +{ | |
455 | + char fname[PATH_MAX]; | |
456 | + struct stat st; | |
457 | + char *p; | |
458 | + int fd; | |
459 | + | |
460 | + if (timezone[0] == '\0' || strstr(timezone, "..") != NULL) { | |
461 | + return NULL; | |
462 | + } | |
463 | + | |
a659fa18 | 464 | + snprintf(fname, sizeof fname, ZONEINFO_PREFIX "/%s", canonical_tzname(timezone)); |
c0240cb1 | 465 | + |
466 | + fd = open(fname, O_RDONLY); | |
467 | + if (fd == -1) { | |
468 | + return NULL; | |
469 | + } else if (fstat(fd, &st) != 0 || !is_valid_tzfile(&st)) { | |
470 | + close(fd); | |
471 | + return NULL; | |
472 | + } | |
473 | + | |
474 | + *length = st.st_size; | |
475 | + p = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0); | |
476 | + close(fd); | |
477 | + | |
478 | + return p != MAP_FAILED ? p : NULL; | |
479 | +} | |
480 | + | |
481 | +#endif | |
482 | + | |
483 | +static int inmem_seek_to_tz_position(const unsigned char **tzf, char *timezone, const timelib_tzdb *tzdb) | |
484 | { | |
485 | int left = 0, right = tzdb->index_size - 1; | |
486 | #ifdef HAVE_SETLOCALE | |
a659fa18 | 487 | @@ -335,21 +765,87 @@ static int seek_to_tz_position(const uns |
c0240cb1 | 488 | return 0; |
489 | } | |
490 | ||
a659fa18 | 491 | +static int seek_to_tz_position(const unsigned char **tzf, char *timezone, |
c0240cb1 | 492 | + char **map, size_t *maplen, |
493 | + const timelib_tzdb *tzdb) | |
494 | +{ | |
361fb152 | 495 | +#ifdef HAVE_SYSTEM_TZDATA |
c0240cb1 | 496 | + if (tzdb == timezonedb_system) { |
497 | + char *orig; | |
498 | + | |
499 | + orig = map_tzfile(timezone, maplen); | |
500 | + if (orig == NULL) { | |
501 | + return 0; | |
502 | + } | |
a659fa18 | 503 | + |
c0240cb1 | 504 | + (*tzf) = (unsigned char *)orig ; |
505 | + *map = orig; | |
a659fa18 | 506 | + return 1; |
c0240cb1 | 507 | + } |
a659fa18 | 508 | + else |
361fb152 | 509 | +#endif |
a659fa18 | 510 | + { |
c0240cb1 | 511 | + return inmem_seek_to_tz_position(tzf, timezone, tzdb); |
512 | + } | |
513 | +} | |
514 | + | |
515 | const timelib_tzdb *timelib_builtin_db(void) | |
516 | { | |
517 | +#ifdef HAVE_SYSTEM_TZDATA | |
518 | + if (timezonedb_system == NULL) { | |
519 | + timelib_tzdb *tmp = malloc(sizeof *tmp); | |
520 | + | |
521 | + tmp->version = "0.system"; | |
522 | + tmp->data = NULL; | |
523 | + create_zone_index(tmp); | |
524 | + system_location_table = create_location_table(); | |
a659fa18 | 525 | + fake_data_segment(tmp, system_location_table); |
c0240cb1 | 526 | + timezonedb_system = tmp; |
527 | + } | |
528 | + | |
c0240cb1 | 529 | + return timezonedb_system; |
530 | +#else | |
531 | return &timezonedb_builtin; | |
532 | +#endif | |
533 | } | |
534 | ||
535 | const timelib_tzdb_index_entry *timelib_timezone_builtin_identifiers_list(int *count) | |
536 | { | |
537 | +#ifdef HAVE_SYSTEM_TZDATA | |
538 | + *count = timezonedb_system->index_size; | |
539 | + return timezonedb_system->index; | |
540 | +#else | |
541 | *count = sizeof(timezonedb_idx_builtin) / sizeof(*timezonedb_idx_builtin); | |
542 | return timezonedb_idx_builtin; | |
543 | +#endif | |
544 | } | |
545 | ||
546 | int timelib_timezone_id_is_valid(char *timezone, const timelib_tzdb *tzdb) | |
547 | { | |
548 | const unsigned char *tzf; | |
549 | - return (seek_to_tz_position(&tzf, timezone, tzdb)); | |
550 | + | |
551 | +#ifdef HAVE_SYSTEM_TZDATA | |
a659fa18 ER |
552 | + if (tzdb == timezonedb_system) { |
553 | + char fname[PATH_MAX]; | |
554 | + struct stat st; | |
555 | + | |
556 | + if (timezone[0] == '\0' || strstr(timezone, "..") != NULL) { | |
557 | + return 0; | |
558 | + } | |
c0240cb1 | 559 | + |
a659fa18 ER |
560 | + if (system_location_table) { |
561 | + if (find_zone_info(system_location_table, timezone) != NULL) { | |
562 | + /* found in cache */ | |
563 | + return 1; | |
564 | + } | |
565 | + } | |
566 | + | |
567 | + snprintf(fname, sizeof fname, ZONEINFO_PREFIX "/%s", canonical_tzname(timezone)); | |
568 | + | |
569 | + return stat(fname, &st) == 0 && is_valid_tzfile(&st); | |
570 | + } | |
571 | +#endif | |
c0240cb1 | 572 | + return (inmem_seek_to_tz_position(&tzf, timezone, tzdb)); |
573 | } | |
574 | ||
a659fa18 ER |
575 | static void skip_64bit_preamble(const unsigned char **tzf, timelib_tzinfo *tz) |
576 | @@ -374,24 +870,54 @@ static void read_64bit_header(const unsi | |
c0240cb1 | 577 | timelib_tzinfo *timelib_parse_tzfile(char *timezone, const timelib_tzdb *tzdb) |
578 | { | |
579 | const unsigned char *tzf; | |
580 | + char *memmap = NULL; | |
581 | + size_t maplen; | |
582 | timelib_tzinfo *tmp; | |
a659fa18 | 583 | int version; |
c0240cb1 | 584 | |
585 | - if (seek_to_tz_position(&tzf, timezone, tzdb)) { | |
586 | + if (seek_to_tz_position(&tzf, timezone, &memmap, &maplen, tzdb)) { | |
587 | tmp = timelib_tzinfo_ctor(timezone); | |
588 | ||
a659fa18 | 589 | version = read_preamble(&tzf, tmp); |
c0240cb1 | 590 | read_header(&tzf, tmp); |
591 | read_transistions(&tzf, tmp); | |
592 | read_types(&tzf, tmp); | |
a659fa18 ER |
593 | - if (version == 2) { |
594 | - skip_64bit_preamble(&tzf, tmp); | |
595 | - read_64bit_header(&tzf, tmp); | |
596 | - skip_64bit_transistions(&tzf, tmp); | |
597 | - skip_64bit_types(&tzf, tmp); | |
598 | - skip_posix_string(&tzf, tmp); | |
599 | - } | |
c0240cb1 | 600 | - read_location(&tzf, tmp); |
601 | + | |
602 | +#ifdef HAVE_SYSTEM_TZDATA | |
603 | + if (memmap) { | |
604 | + const struct location_info *li; | |
605 | + | |
606 | + /* TZif-style - grok the location info from the system database, | |
607 | + * if possible. */ | |
608 | + | |
609 | + if ((li = find_zone_info(system_location_table, timezone)) != NULL) { | |
610 | + tmp->location.comments = strdup(li->comment); | |
611 | + strncpy(tmp->location.country_code, li->code, 2); | |
612 | + tmp->location.longitude = li->longitude; | |
613 | + tmp->location.latitude = li->latitude; | |
614 | + tmp->bc = 1; | |
615 | + } | |
616 | + else { | |
617 | + strcpy(tmp->location.country_code, "??"); | |
618 | + tmp->bc = 0; | |
619 | + tmp->location.comments = strdup(""); | |
620 | + } | |
621 | + | |
622 | + /* Now done with the mmap segment - discard it. */ | |
623 | + munmap(memmap, maplen); | |
361fb152 | 624 | + } else |
c0240cb1 | 625 | +#endif |
361fb152 | 626 | + { |
a659fa18 ER |
627 | + if (version == 2) { |
628 | + skip_64bit_preamble(&tzf, tmp); | |
629 | + read_64bit_header(&tzf, tmp); | |
630 | + skip_64bit_transistions(&tzf, tmp); | |
631 | + skip_64bit_types(&tzf, tmp); | |
632 | + skip_posix_string(&tzf, tmp); | |
633 | + } | |
c0240cb1 | 634 | + /* PHP-style - use the embedded info. */ |
635 | + read_location(&tzf, tmp); | |
a659fa18 | 636 | + } |
c0240cb1 | 637 | } else { |
638 | tmp = NULL; | |
639 | } | |
a659fa18 ER |
640 | diff -up php-5.6.9RC1/ext/date/lib/timelib.m4.systzdata php-5.6.9RC1/ext/date/lib/timelib.m4 |
641 | --- php-5.6.9RC1/ext/date/lib/timelib.m4.systzdata 2015-04-30 00:00:18.000000000 +0200 | |
642 | +++ php-5.6.9RC1/ext/date/lib/timelib.m4 2015-04-30 06:32:08.549500385 +0200 | |
c0240cb1 | 643 | @@ -78,3 +78,17 @@ stdlib.h |
644 | ||
645 | dnl Check for strtoll, atoll | |
646 | AC_CHECK_FUNCS(strtoll atoll strftime) | |
647 | + | |
648 | +PHP_ARG_WITH(system-tzdata, for use of system timezone data, | |
649 | +[ --with-system-tzdata[=DIR] to specify use of system timezone data], | |
650 | +no, no) | |
651 | + | |
652 | +if test "$PHP_SYSTEM_TZDATA" != "no"; then | |
653 | + AC_DEFINE(HAVE_SYSTEM_TZDATA, 1, [Define if system timezone data is used]) | |
654 | + | |
655 | + if test "$PHP_SYSTEM_TZDATA" != "yes"; then | |
656 | + AC_DEFINE_UNQUOTED(HAVE_SYSTEM_TZDATA_PREFIX, "$PHP_SYSTEM_TZDATA", | |
657 | + [Define for location of system timezone data]) | |
658 | + fi | |
659 | +fi | |
660 | + |