]>
Commit | Line | Data |
---|---|---|
0545caaa | 1 | /* |
5b74111a | 2 | * Copyright (C) 1996-2018 The Squid Software Foundation and contributors |
0545caaa AJ |
3 | * |
4 | * Squid software is distributed under GPLv2+ license and includes | |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
7 | */ | |
8 | ||
f7f3304a | 9 | #include "squid.h" |
2d72d4fd | 10 | #include "util.h" |
59ef7bfc | 11 | |
59ef7bfc | 12 | #if HAVE_STRING_H |
13 | #include <string.h> | |
14 | #endif | |
15 | #if HAVE_CTYPE_H | |
16 | #include <ctype.h> | |
17 | #endif | |
59ef7bfc | 18 | #if HAVE_TIME_H |
19 | #include <time.h> | |
20 | #endif | |
59ef7bfc | 21 | |
59ef7bfc | 22 | #define ASCII_DIGIT(c) ((c)-48) |
23 | ||
24 | time_t | |
25 | parse_iso3307_time(const char *buf) | |
26 | { | |
26ac0430 | 27 | /* buf is an ISO 3307 style time: YYYYMMDDHHMMSS or YYYYMMDDHHMMSS.xxx */ |
59ef7bfc | 28 | struct tm tms; |
29 | time_t t; | |
30 | while (*buf == ' ' || *buf == '\t') | |
26ac0430 | 31 | buf++; |
59ef7bfc | 32 | if ((int) strlen(buf) < 14) |
26ac0430 | 33 | return 0; |
59ef7bfc | 34 | memset(&tms, '\0', sizeof(struct tm)); |
b9bbc34c | 35 | tms.tm_year = (ASCII_DIGIT(buf[0]) * 1000) + (ASCII_DIGIT(buf[1]) * 100) + |
26ac0430 | 36 | (ASCII_DIGIT(buf[2]) * 10) + ASCII_DIGIT(buf[3]) - 1900; |
59ef7bfc | 37 | tms.tm_mon = (ASCII_DIGIT(buf[4]) * 10) + ASCII_DIGIT(buf[5]) - 1; |
38 | tms.tm_mday = (ASCII_DIGIT(buf[6]) * 10) + ASCII_DIGIT(buf[7]); | |
39 | tms.tm_hour = (ASCII_DIGIT(buf[8]) * 10) + ASCII_DIGIT(buf[9]); | |
40 | tms.tm_min = (ASCII_DIGIT(buf[10]) * 10) + ASCII_DIGIT(buf[11]); | |
41 | tms.tm_sec = (ASCII_DIGIT(buf[12]) * 10) + ASCII_DIGIT(buf[13]); | |
42 | #if HAVE_TIMEGM | |
43 | t = timegm(&tms); | |
44 | #elif HAVE_MKTIME | |
45 | t = mktime(&tms); | |
46 | #else | |
47 | t = (time_t) 0; | |
48 | #endif | |
49 | return t; | |
50 | } | |
f53969cc | 51 |