X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http_date_api.c;h=78a5da1938da7935a83acf587c4b6ccfe1ecaffd;hp=10f3463a437c8efd2ab5cee7636f8c22ba2815f9;hb=ad5f896b03adaa073134a00108a9cdf00720673a;hpb=c40902a33546532405c17c6216c347874f8cb8ff diff --git a/http_date_api.c b/http_date_api.c index 10f3463..78a5da1 100644 --- a/http_date_api.c +++ b/http_date_api.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2006, Michael Wallner | + | Copyright (c) 2004-2010, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -141,46 +141,29 @@ static inline int check_tzone(const char *tzone) /* {{{ char *http_date(time_t) */ PHP_HTTP_API char *_http_date(time_t t TSRMLS_DC) { - struct tm *gmtime, tmbuf; + char *date = NULL; + struct tm *gmtime = NULL, tmbuf; + memset(&tmbuf, 0, sizeof(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; + time_t t = parse_date(date); -#ifdef PHP_WIN32 - /* fix odd offsets with Win32 */ - char tzput[64] = "TZ="; - const char *tzget = NULL; - - 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); } @@ -339,11 +322,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. */