X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http_date_api.c;h=6d6e58c30f9f4a4ef912b15d8fbf30fcb92bde50;hp=02f619c27a18d7713188d3c06bb013d525a70c0b;hb=01300e3808fec53def73a410233f68f36f292097;hpb=d8523b1334eaf61f71233401fe401925230fe1e5 diff --git a/http_date_api.c b/http_date_api.c index 02f619c..6d6e58c 100644 --- a/http_date_api.c +++ b/http_date_api.c @@ -6,22 +6,17 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2005, Michael Wallner | + | Copyright (c) 2004-2007, Michael Wallner | +--------------------------------------------------------------------+ */ /* $Id$ */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include "php_http.h" + #include "php_http_api.h" #include "php_http_date_api.h" -ZEND_EXTERN_MODULE_GLOBALS(http); - static inline int check_day(const char *day, size_t len); static inline int check_month(const char *month); static inline int check_tzone(const char *tzone); @@ -146,46 +141,28 @@ static inline int check_tzone(const char *tzone) /* {{{ char *http_date(time_t) */ PHP_HTTP_API char *_http_date(time_t t TSRMLS_DC) { + char *date = NULL; struct tm *gmtime, tmbuf; if ((gmtime = php_gmtime_r(&t, &tmbuf))) { - char *date = ecalloc(1, 31); - snprintf(date, 30, + spprintf(&date, 0, "%s, %02d %s %04d %02d:%02d:%02d GMT", days[gmtime->tm_wday], gmtime->tm_mday, months[gmtime->tm_mon], gmtime->tm_year + 1900, gmtime->tm_hour, gmtime->tm_min, gmtime->tm_sec ); - return date; } - return NULL; + return date; } /* }}} */ /* {{{ time_t http_parse_date(char *) */ -PHP_HTTP_API time_t _http_parse_date(const char *date TSRMLS_DC) +PHP_HTTP_API time_t _http_parse_date_ex(const char *date, zend_bool silent TSRMLS_DC) { - time_t t = -1; - -#ifdef PHP_WIN32 - /* fix odd offsets with Win32 */ - char tzput[64] = "TZ="; - const char *tzget = NULL; + time_t t = parse_date(date); - if ((tzget = getenv("TZ"))) { - strlcat(tzput, tzget, 63); - } - putenv("TZ=GMT"); -#endif - - t = parse_date(date); - -#ifdef PHP_WIN32 - putenv(tzput); -#endif - - if (-1 == t) { + if (-1 == t && !silent) { http_error_ex(HE_NOTICE, HTTP_E_RUNTIME, "Could not parse date: %s", date); } @@ -209,11 +186,11 @@ static inline time_t parse_date(const char *date) while (*date && (part < 6)) { int found = 0; - while (*date && !isalnum(*date)) { + while (*date && !HTTP_IS_CTYPE(alnum, *date)) { date++; } - if (isalpha(*date)) { + if (HTTP_IS_CTYPE(alpha, *date)) { /* a name coming up */ char buf[32] = ""; size_t len; @@ -247,7 +224,7 @@ static inline time_t parse_date(const char *date) } date += len; } - else if (isdigit(*date)) { + else if (HTTP_IS_CTYPE(digit, *date)) { /* a digit */ int val; char *end; @@ -344,11 +321,13 @@ static inline time_t parse_date(const char *date) long delta; time_t t2; - if(!(gmt = php_gmtime_r(&t, &keeptime2))) { + if((gmt = php_gmtime_r(&t, &keeptime2))) { + tm = *gmt; /* MSVC quirks */ + } else { return -1; /* illegal date/time */ } - t2 = mktime(gmt); + t2 = mktime(&tm); /* Add the time zone diff (between the given timezone and GMT) and the diff between the local time zone and GMT. */