-#include "php_http.h"
-#include "php_http_api.h"
-#include "php_http_std_defs.h"
-
-ZEND_DECLARE_MODULE_GLOBALS(http)
-
-/* {{{ day/month names */
-static const char *days[] = {
- "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
-};
-static const char *wkdays[] = {
- "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"
-};
-static const char *weekdays[] = {
- "Monday", "Tuesday", "Wednesday",
- "Thursday", "Friday", "Saturday", "Sunday"
-};
-static const char *months[] = {
- "Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"
-};
-enum assume_next {
- DATE_MDAY,
- DATE_YEAR,
- DATE_TIME
-};
-static const struct time_zone {
- const char *name;
- const int offset;
-} time_zones[] = {
- {"GMT", 0}, /* Greenwich Mean */
- {"UTC", 0}, /* Universal (Coordinated) */
- {"WET", 0}, /* Western European */
- {"BST", 0}, /* British Summer */
- {"WAT", 60}, /* West Africa */
- {"AST", 240}, /* Atlantic Standard */
- {"ADT", 240}, /* Atlantic Daylight */
- {"EST", 300}, /* Eastern Standard */
- {"EDT", 300}, /* Eastern Daylight */
- {"CST", 360}, /* Central Standard */
- {"CDT", 360}, /* Central Daylight */
- {"MST", 420}, /* Mountain Standard */
- {"MDT", 420}, /* Mountain Daylight */
- {"PST", 480}, /* Pacific Standard */
- {"PDT", 480}, /* Pacific Daylight */
- {"YST", 540}, /* Yukon Standard */
- {"YDT", 540}, /* Yukon Daylight */
- {"HST", 600}, /* Hawaii Standard */
- {"HDT", 600}, /* Hawaii Daylight */
- {"CAT", 600}, /* Central Alaska */
- {"AHST", 600}, /* Alaska-Hawaii Standard */
- {"NT", 660}, /* Nome */
- {"IDLW", 720}, /* International Date Line West */
- {"CET", -60}, /* Central European */
- {"MET", -60}, /* Middle European */
- {"MEWT", -60}, /* Middle European Winter */
- {"MEST", -120}, /* Middle European Summer */
- {"CEST", -120}, /* Central European Summer */
- {"MESZ", -60}, /* Middle European Summer */
- {"FWT", -60}, /* French Winter */
- {"FST", -60}, /* French Summer */
- {"EET", -120}, /* Eastern Europe, USSR Zone 1 */
- {"WAST", -420}, /* West Australian Standard */
- {"WADT", -420}, /* West Australian Daylight */
- {"CCT", -480}, /* China Coast, USSR Zone 7 */
- {"JST", -540}, /* Japan Standard, USSR Zone 8 */
- {"EAST", -600}, /* Eastern Australian Standard */
- {"EADT", -600}, /* Eastern Australian Daylight */
- {"GST", -600}, /* Guam Standard, USSR Zone 9 */
- {"NZT", -720}, /* New Zealand */
- {"NZST", -720}, /* New Zealand Standard */
- {"NZDT", -720}, /* New Zealand Daylight */
- {"IDLE", -720}, /* International Date Line East */
-};
-/* }}} */
-
-/* {{{ internals */
-
-static int http_sort_q(const void *a, const void *b TSRMLS_DC);
-#define http_send_chunk(d, b, e, m) _http_send_chunk((d), (b), (e), (m) TSRMLS_CC)
-static STATUS _http_send_chunk(const void *data, const size_t begin, const size_t end, const http_send_mode mode TSRMLS_DC);
-
-static int check_day(char *day, size_t len);
-static int check_month(char *month);
-static int check_tzone(char *tzone);
-
-static int http_ob_stack_get(php_ob_buffer *, php_ob_buffer **);
-
-/* {{{ static int http_sort_q(const void *, const void *) */
-static int http_sort_q(const void *a, const void *b TSRMLS_DC)
-{
- Bucket *f, *s;
- zval result, *first, *second;
-
- f = *((Bucket **) a);
- s = *((Bucket **) b);
-
- first = *((zval **) f->pData);
- second= *((zval **) s->pData);
-
- if (numeric_compare_function(&result, first, second TSRMLS_CC) != SUCCESS) {
- return 0;
- }
- return (Z_LVAL(result) > 0 ? -1 : (Z_LVAL(result) < 0 ? 1 : 0));
-}
-/* }}} */
-
-/* {{{ static STATUS http_send_chunk(const void *, size_t, size_t,
- http_send_mode) */
-static STATUS _http_send_chunk(const void *data, const size_t begin,
- const size_t end, const http_send_mode mode TSRMLS_DC)
-{
- long len = end - begin;
-
- switch (mode)
- {
- case SEND_RSRC:
- {
- char *buf;
- size_t read = 0;
- php_stream *s = (php_stream *) data;
-
- if (php_stream_seek(s, begin, SEEK_SET)) {
- return FAILURE;
- }
-
- buf = (char *) ecalloc(1, HTTP_SENDBUF_SIZE);
- /* read into buf and write out */
- while ((len -= HTTP_SENDBUF_SIZE) >= 0) {
- if (!(read = php_stream_read(s, buf, HTTP_SENDBUF_SIZE))) {
- efree(buf);
- return FAILURE;
- }
- if (read - php_body_write(buf, read TSRMLS_CC)) {
- efree(buf);
- return FAILURE;
- }
- /* ob_flush() && flush() */
- php_end_ob_buffer(1, 1 TSRMLS_CC);
- sapi_flush(TSRMLS_C);
- }
-
- /* read & write left over */
- if (len) {
- if (read = php_stream_read(s, buf, HTTP_SENDBUF_SIZE + len)) {
- if (read - php_body_write(buf, read TSRMLS_CC)) {
- efree(buf);
- return FAILURE;
- }
- } else {
- efree(buf);
- return FAILURE;
- }
- /* ob_flush() & flush() */
- php_end_ob_buffer(1, 1 TSRMLS_CC);
- sapi_flush(TSRMLS_C);
- }
- efree(buf);
- return SUCCESS;
- }
-
- case SEND_DATA:
- {
- char *s = (char *) data + begin;
-
- while ((len -= HTTP_SENDBUF_SIZE) >= 0) {
- if (HTTP_SENDBUF_SIZE - php_body_write(s, HTTP_SENDBUF_SIZE TSRMLS_CC)) {
- return FAILURE;
- }
- s += HTTP_SENDBUF_SIZE;
- /* ob_flush() & flush() */
- php_end_ob_buffer(1, 1 TSRMLS_CC);
- sapi_flush(TSRMLS_C);
- }
-
- /* write left over */
- if (len) {
- if (HTTP_SENDBUF_SIZE + len - php_body_write(s, HTTP_SENDBUF_SIZE + len TSRMLS_CC)) {
- return FAILURE;
- }
- /* ob_flush() & flush() */
- php_end_ob_buffer(1, 1 TSRMLS_CC);
- sapi_flush(TSRMLS_C);
- }
- return SUCCESS;
- }
-
- default:
- return FAILURE;
- break;
- }
-}
-/* }}} */
-
-/* {{{ 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)