/*
- +----------------------------------------------------------------------+
- | PECL :: http |
- +----------------------------------------------------------------------+
- | This source file is subject to version 3.0 of the PHP license, that |
- | is bundled with this package in the file LICENSE, and is available |
- | through the world-wide-web at http://www.php.net/license/3_0.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Copyright (c) 2004-2005 Michael Wallner <mike@php.net> |
- +----------------------------------------------------------------------+
+ +--------------------------------------------------------------------+
+ | PECL :: http |
+ +--------------------------------------------------------------------+
+ | Redistribution and use in source and binary forms, with or without |
+ | modification, are permitted provided that the conditions mentioned |
+ | in the accompanying LICENSE file are met. |
+ +--------------------------------------------------------------------+
+ | Copyright (c) 2004-2006, Michael Wallner <mike@php.net> |
+ +--------------------------------------------------------------------+
*/
/* $Id$ */
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-#include "php.h"
-
#include "php_http.h"
-#include "php_http_std_defs.h"
-#include <ctype.h>
+#include "php_http_api.h"
+#include "php_http_date_api.h"
-static int check_day(char *day, size_t len);
-static int check_month(char *month);
-static int check_tzone(char *tzone);
+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);
+static inline time_t parse_date(const char *month);
/* {{{ day/month names */
static const char *days[] = {
/* {{{ Day/Month/TZ checks for http_parse_date()
Originally by libcurl, Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al. */
-static int check_day(char *day, size_t len)
+static inline int check_day(const char *day, size_t len)
{
int i;
const char * const *check = (len > 3) ? &weekdays[0] : &wkdays[0];
return -1;
}
-static int check_month(char *month)
+static inline int check_month(const char *month)
{
int i;
const char * const *check = &months[0];
/* return the time zone offset between GMT and the input one, in number
of seconds or -1 if the timezone wasn't found/legal */
-static int check_tzone(char *tzone)
+static inline int check_tzone(const char *tzone)
{
unsigned i;
const struct time_zone *check = time_zones;
{
struct tm *gmtime, tmbuf;
- if (gmtime = php_gmtime_r(&t, &tmbuf)) {
+ if ((gmtime = php_gmtime_r(&t, &tmbuf))) {
char *date = ecalloc(1, 31);
snprintf(date, 30,
"%s, %02d %s %04d %02d:%02d:%02d GMT",
}
/* }}} */
-/* {{{ time_t http_parse_date(char *)
+/* {{{ time_t http_parse_date(char *) */
+PHP_HTTP_API time_t _http_parse_date(const char *date TSRMLS_DC)
+{
+ time_t t = -1;
+
+#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) {
+ http_error_ex(HE_NOTICE, HTTP_E_RUNTIME, "Could not parse date: %s", date);
+ }
+
+ return t;
+}
+/* }}} */
+
+/* time_t parse_date(char *)
Originally by libcurl, Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al. */
-PHP_HTTP_API time_t _http_parse_date(const char *date)
+static inline time_t parse_date(const char *date)
{
time_t t = 0;
int tz_offset = -1, year = -1, month = -1, monthday = -1, weekday = -1,