--- /dev/null
+CREDITS
+=======
+Michael Wallner, <mike@php.net>
+Sara Golemon, <pollita@php.net> php_url_encode_hash(), http_build_query()
+Daniel Stenberg, <daniel@haxx.se>, et al. http_parse_date()
#include "php_http.h"
#include "php_http_api.h"
#include "php_http_curl_api.h"
+#include "php_http_std_defs.h"
#ifdef ZEND_ENGINE_2
# include "ext/standard/php_http.h"
#ifdef ZEND_ENGINE_2
# include "ext/standard/php_http.h"
-#else
- #include "http_build_query.c"
#endif
#include "php_http.h"
#include "php_http_api.h"
+#include "php_http_std_defs.h"
ZEND_DECLARE_MODULE_GLOBALS(http)
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 *) */
if (php_stream_seek(s, begin, SEEK_SET)) {
return FAILURE;
}
- buf = (char *) ecalloc(1, HTTP_BUF_SIZE);
+ buf = (char *) ecalloc(1, HTTP_SENDBUF_SIZE);
/* read into buf and write out */
- while ((len -= HTTP_BUF_SIZE) >= 0) {
- if (!(read = php_stream_read(s, buf, HTTP_BUF_SIZE))) {
+ while ((len -= HTTP_SENDBUF_SIZE) >= 0) {
+ if (!(read = php_stream_read(s, buf, HTTP_SENDBUF_SIZE))) {
efree(buf);
return FAILURE;
}
/* read & write left over */
if (len) {
- if (read = php_stream_read(s, buf, HTTP_BUF_SIZE + 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;
}
/* }}} */
-/* {{{ inline char *http_etag(void *, size_t, http_send_mode) */
-PHP_HTTP_API inline char *_http_etag(const void *data_ptr, const size_t data_len,
+/* {{{ char *http_etag(void *, size_t, http_send_mode) */
+PHP_HTTP_API char *_http_etag(const void *data_ptr, const size_t data_len,
const http_send_mode data_mode TSRMLS_DC)
{
char ssb_buf[128] = {0};
}
/* }}} */
-/* {{{ inline http_lmod(void *, http_send_mode) */
-PHP_HTTP_API inline time_t _http_lmod(const void *data_ptr, const http_send_mode data_mode TSRMLS_DC)
+/* {{{ time_t http_lmod(void *, http_send_mode) */
+PHP_HTTP_API time_t _http_lmod(const void *data_ptr, const http_send_mode data_mode TSRMLS_DC)
{
switch (data_mode)
{
}
/* }}} */
-/* {{{inline int http_is_range_request(void) */
-PHP_HTTP_API inline int _http_is_range_request(TSRMLS_D)
+/* {{{ int http_is_range_request(void) */
+PHP_HTTP_API int _http_is_range_request(TSRMLS_D)
{
return zend_hash_exists(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]),
"HTTP_RANGE", sizeof("HTTP_RANGE"));
}
/* }}} */
-/* {{{ inline STATUS http_send_status(int) */
-PHP_HTTP_API inline STATUS _http_send_status(const int status TSRMLS_DC)
+/* {{{ STATUS http_send_status(int) */
+PHP_HTTP_API STATUS _http_send_status(const int status TSRMLS_DC)
{
int s = status;
return sapi_header_op(SAPI_HEADER_SET_STATUS, (void *) s TSRMLS_CC);
}
/* }}} */
-/* {{{ inline STATUS http_send_header(char *) */
-PHP_HTTP_API inline STATUS _http_send_header(const char *header TSRMLS_DC)
+/* {{{ STATUS http_send_header(char *) */
+PHP_HTTP_API STATUS _http_send_header(const char *header TSRMLS_DC)
{
return http_send_status_header(0, header);
}
/* }}} */
-/* {{{ inline STATUS http_send_status_header(int, char *) */
-PHP_HTTP_API inline STATUS _http_send_status_header(const int status, const char *header TSRMLS_DC)
+/* {{{ STATUS http_send_status_header(int, char *) */
+PHP_HTTP_API STATUS _http_send_status_header(const int status, const char *header TSRMLS_DC)
{
sapi_header_line h = {(char *) header, strlen(header), status};
return sapi_header_op(SAPI_HEADER_REPLACE, &h TSRMLS_CC);
}
/* }}} */
-/* {{{ inline zval *http_get_server_var(char *) */
-PHP_HTTP_API inline zval *_http_get_server_var(const char *key TSRMLS_DC)
+/* {{{ zval *http_get_server_var(char *) */
+PHP_HTTP_API zval *_http_get_server_var(const char *key TSRMLS_DC)
{
zval **var;
if (SUCCESS == zend_hash_find(
}
/* walk through the supported array */
- for ( zend_hash_internal_pointer_reset(Z_ARRVAL_P(supported));
- SUCCESS == zend_hash_get_current_data(
- Z_ARRVAL_P(supported), (void **) &zsupp);
- zend_hash_move_forward(Z_ARRVAL_P(supported))) {
+ FOREACH_VAL(supported, zsupp) {
if (!strcasecmp(Z_STRVAL_PP(zsupp), Z_STRVAL_PP(zentry))) {
add_assoc_double(zentries, Z_STRVAL_PP(zsupp), qual);
break;
/* {{{ void http_get_request_headers(zval *) */
PHP_HTTP_API void _http_get_request_headers(zval *array TSRMLS_DC)
{
- char *key;
+ char *key = NULL;
+ long idx = 0;
- for ( zend_hash_internal_pointer_reset(HTTP_SERVER_VARS);
- zend_hash_get_current_key(HTTP_SERVER_VARS, &key, NULL, 0) != HASH_KEY_NON_EXISTANT;
- zend_hash_move_forward(HTTP_SERVER_VARS)) {
- if (!strncmp(key, "HTTP_", 5)) {
+ FOREACH_HASH_KEY(HTTP_SERVER_VARS, key, idx) {
+ if (key && !strncmp(key, "HTTP_", 5)) {
zval **header;
zend_hash_get_current_data(HTTP_SERVER_VARS, (void **) &header);
add_assoc_stringl(array, pretty_key(key + 5, strlen(key) - 5, 1, 1), Z_STRVAL_PP(header), Z_STRLEN_PP(header), 1);
}
/* }}} */
+/* {{{ STATUS http_urlencode_hash_ex(HashTable *, int, char **, size_t *) */
+PHP_HTTP_API STATUS _http_urlencode_hash_ex(HashTable *hash, int override_argsep,
+ char *pre_encoded_data, size_t pre_encoded_len,
+ char **encoded_data, size_t *encoded_len TSRMLS_DC)
+{
+ smart_str qstr = {0};
+
+ if (override_argsep) {
+ HTTP_URL_ARGSEP_OVERRIDE;
+ }
+
+ if (pre_encoded_len && pre_encoded_data) {
+ smart_str_appendl(&qstr, pre_encoded_data, pre_encoded_len);
+ }
+
+ if (SUCCESS != php_url_encode_hash_ex(hash, &qstr, NULL, 0, NULL, 0, NULL, 0, NULL TSRMLS_CC)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't encode query data");
+ if (qstr.c) {
+ efree(qstr.c);
+ }
+ if (override_argsep) {
+ HTTP_URL_ARGSEP_RESTORE;
+ }
+ return FAILURE;
+ }
+
+ if (override_argsep) {
+ HTTP_URL_ARGSEP_RESTORE;
+ }
+
+ smart_str_0(&qstr);
+
+ *encoded_data = qstr.c;
+ if (encoded_len) {
+ *encoded_len = qstr.len;
+ }
+
+ return SUCCESS;
+}
+/* }}} */
+
/* {{{ STATUS http_auth_header(char *, char*) */
PHP_HTTP_API STATUS _http_auth_header(const char *type, const char *realm TSRMLS_DC)
{
}
/* }}} */
+#ifndef ZEND_ENGINE_2
+/* {{{ php_url_encode_hash
+ Author: Sarah Golemon <pollita@php.net> */
+PHP_HTTP_API int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
+ const char *num_prefix, int num_prefix_len,
+ const char *key_prefix, int key_prefix_len,
+ const char *key_suffix, int key_suffix_len,
+ zval *type TSRMLS_DC)
+{
+ char *arg_sep = NULL, *key = NULL, *ekey, *newprefix, *p;
+ int arg_sep_len, key_len, ekey_len, key_type, newprefix_len;
+ ulong idx;
+ zval **zdata = NULL, *copyzval;
+
+ if (!ht) {
+ return FAILURE;
+ }
+
+ if (ht->nApplyCount > 0) {
+ /* Prevent recursion */
+ return SUCCESS;
+ }
+
+ arg_sep = INI_STR("arg_separator.output");
+ if (!arg_sep || !strlen(arg_sep)) {
+ arg_sep = HTTP_URL_ARGSEP_DEFAULT;
+ }
+ arg_sep_len = strlen(arg_sep);
+
+ for (zend_hash_internal_pointer_reset(ht);
+ (key_type = zend_hash_get_current_key_ex(ht, &key, &key_len, &idx, 0, NULL)) != HASH_KEY_NON_EXISTANT;
+ zend_hash_move_forward(ht)
+ ) {
+ if (key_type == HASH_KEY_IS_STRING && key_len && key[key_len-1] == '\0') {
+ /* We don't want that trailing NULL */
+ key_len -= 1;
+ }
+
+#ifdef ZEND_ENGINE_2
+ /* handling for private & protected object properties */
+ if (key && *key == '\0' && type != NULL) {
+ char *tmp;
+
+ zend_object *zobj = zend_objects_get_address(type TSRMLS_CC);
+ if (zend_check_property_access(zobj, key TSRMLS_CC) != SUCCESS) {
+ /* private or protected property access outside of the class */
+ continue;
+ }
+ zend_unmangle_property_name(key, &tmp, &key);
+ key_len = strlen(key);
+ }
+#endif
+
+ if (zend_hash_get_current_data_ex(ht, (void **)&zdata, NULL) == FAILURE || !zdata || !(*zdata)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error traversing form data array.");
+ return FAILURE;
+ }
+ if (Z_TYPE_PP(zdata) == IS_ARRAY || Z_TYPE_PP(zdata) == IS_OBJECT) {
+ if (key_type == HASH_KEY_IS_STRING) {
+ ekey = php_url_encode(key, key_len, &ekey_len);
+ newprefix_len = key_suffix_len + ekey_len + key_prefix_len + 1;
+ newprefix = emalloc(newprefix_len + 1);
+ p = newprefix;
+
+ if (key_prefix) {
+ memcpy(p, key_prefix, key_prefix_len);
+ p += key_prefix_len;
+ }
+
+ memcpy(p, ekey, ekey_len);
+ p += ekey_len;
+ efree(ekey);
+
+ if (key_suffix) {
+ memcpy(p, key_suffix, key_suffix_len);
+ p += key_suffix_len;
+ }
+
+ *(p++) = '[';
+ *p = '\0';
+ } else {
+ /* Is an integer key */
+ ekey_len = spprintf(&ekey, 12, "%ld", idx);
+ newprefix_len = key_prefix_len + num_prefix_len + ekey_len + key_suffix_len + 1;
+ newprefix = emalloc(newprefix_len + 1);
+ p = newprefix;
+
+ if (key_prefix) {
+ memcpy(p, key_prefix, key_prefix_len);
+ p += key_prefix_len;
+ }
+
+ memcpy(p, num_prefix, num_prefix_len);
+ p += num_prefix_len;
+
+ memcpy(p, ekey, ekey_len);
+ p += ekey_len;
+ efree(ekey);
+
+ if (key_suffix) {
+ memcpy(p, key_suffix, key_suffix_len);
+ p += key_suffix_len;
+ }
+ *(p++) = '[';
+ *p = '\0';
+ }
+ ht->nApplyCount++;
+ php_url_encode_hash_ex(HASH_OF(*zdata), formstr, NULL, 0, newprefix, newprefix_len, "]", 1, (Z_TYPE_PP(zdata) == IS_OBJECT ? *zdata : NULL) TSRMLS_CC);
+ ht->nApplyCount--;
+ efree(newprefix);
+ } else if (Z_TYPE_PP(zdata) == IS_NULL || Z_TYPE_PP(zdata) == IS_RESOURCE) {
+ /* Skip these types */
+ continue;
+ } else {
+ if (formstr->len) {
+ smart_str_appendl(formstr, arg_sep, arg_sep_len);
+ }
+ /* Simple key=value */
+ smart_str_appendl(formstr, key_prefix, key_prefix_len);
+ if (key_type == HASH_KEY_IS_STRING) {
+ ekey = php_url_encode(key, key_len, &ekey_len);
+ smart_str_appendl(formstr, ekey, ekey_len);
+ efree(ekey);
+ } else {
+ /* Numeric key */
+ if (num_prefix) {
+ smart_str_appendl(formstr, num_prefix, num_prefix_len);
+ }
+ ekey_len = spprintf(&ekey, 12, "%ld", idx);
+ smart_str_appendl(formstr, ekey, ekey_len);
+ efree(ekey);
+ }
+ smart_str_appendl(formstr, key_suffix, key_suffix_len);
+ smart_str_appendl(formstr, "=", 1);
+ switch (Z_TYPE_PP(zdata)) {
+ case IS_STRING:
+ ekey = php_url_encode(Z_STRVAL_PP(zdata), Z_STRLEN_PP(zdata), &ekey_len);
+ break;
+ case IS_LONG:
+ case IS_BOOL:
+ ekey_len = spprintf(&ekey, 12, "%ld", Z_LVAL_PP(zdata));
+ break;
+ case IS_DOUBLE:
+ ekey_len = spprintf(&ekey, 48, "%.*G", (int) EG(precision), Z_DVAL_PP(zdata));
+ break;
+ default:
+ /* fall back on convert to string */
+ MAKE_STD_ZVAL(copyzval);
+ *copyzval = **zdata;
+ zval_copy_ctor(copyzval);
+ convert_to_string_ex(©zval);
+ ekey = php_url_encode(Z_STRVAL_P(copyzval), Z_STRLEN_P(copyzval), &ekey_len);
+ zval_ptr_dtor(©zval);
+ }
+ smart_str_appendl(formstr, ekey, ekey_len);
+ efree(ekey);
+ }
+ }
+
+ return SUCCESS;
+}
+/* }}} */
+#endif /* !ZEND_ENDGINE_2 */
+
/* }}} public API */
/*
+++ /dev/null
-/*
- +----------------------------------------------------------------------+
- | PHP Version 5 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
- +----------------------------------------------------------------------+
- | 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 the following url: |
- | 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. |
- +----------------------------------------------------------------------+
- | Authors: Sara Golemon <pollita@php.net> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#include "php_http.h"
-#include "php_http_api.h"
-#include "php_ini.h"
-#include "ext/standard/url.h"
-
-#define URL_DEFAULT_ARG_SEP "&"
-
-/* {{{ php_url_encode_hash */
-PHP_HTTP_API int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
- const char *num_prefix, int num_prefix_len,
- const char *key_prefix, int key_prefix_len,
- const char *key_suffix, int key_suffix_len,
- zval *type TSRMLS_DC)
-{
- char *arg_sep = NULL, *key = NULL, *ekey, *newprefix, *p;
- int arg_sep_len, key_len, ekey_len, key_type, newprefix_len;
- ulong idx;
- zval **zdata = NULL, *copyzval;
-
- if (!ht) {
- return FAILURE;
- }
-
- if (ht->nApplyCount > 0) {
- /* Prevent recursion */
- return SUCCESS;
- }
-
- arg_sep = INI_STR("arg_separator.output");
- if (!arg_sep || !strlen(arg_sep)) {
- arg_sep = URL_DEFAULT_ARG_SEP;
- }
- arg_sep_len = strlen(arg_sep);
-
- for (zend_hash_internal_pointer_reset(ht);
- (key_type = zend_hash_get_current_key_ex(ht, &key, &key_len, &idx, 0, NULL)) != HASH_KEY_NON_EXISTANT;
- zend_hash_move_forward(ht)
- ) {
- if (key_type == HASH_KEY_IS_STRING && key_len && key[key_len-1] == '\0') {
- /* We don't want that trailing NULL */
- key_len -= 1;
- }
-
-#ifdef ZEND_ENGINE_2
- /* handling for private & protected object properties */
- if (key && *key == '\0' && type != NULL) {
- char *tmp;
-
- zend_object *zobj = zend_objects_get_address(type TSRMLS_CC);
- if (zend_check_property_access(zobj, key TSRMLS_CC) != SUCCESS) {
- /* private or protected property access outside of the class */
- continue;
- }
- zend_unmangle_property_name(key, &tmp, &key);
- key_len = strlen(key);
- }
-#endif
-
- if (zend_hash_get_current_data_ex(ht, (void **)&zdata, NULL) == FAILURE || !zdata || !(*zdata)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error traversing form data array.");
- return FAILURE;
- }
- if (Z_TYPE_PP(zdata) == IS_ARRAY || Z_TYPE_PP(zdata) == IS_OBJECT) {
- if (key_type == HASH_KEY_IS_STRING) {
- ekey = php_url_encode(key, key_len, &ekey_len);
- newprefix_len = key_suffix_len + ekey_len + key_prefix_len + 1;
- newprefix = emalloc(newprefix_len + 1);
- p = newprefix;
-
- if (key_prefix) {
- memcpy(p, key_prefix, key_prefix_len);
- p += key_prefix_len;
- }
-
- memcpy(p, ekey, ekey_len);
- p += ekey_len;
- efree(ekey);
-
- if (key_suffix) {
- memcpy(p, key_suffix, key_suffix_len);
- p += key_suffix_len;
- }
-
- *(p++) = '[';
- *p = '\0';
- } else {
- /* Is an integer key */
- ekey_len = spprintf(&ekey, 12, "%ld", idx);
- newprefix_len = key_prefix_len + num_prefix_len + ekey_len + key_suffix_len + 1;
- newprefix = emalloc(newprefix_len + 1);
- p = newprefix;
-
- if (key_prefix) {
- memcpy(p, key_prefix, key_prefix_len);
- p += key_prefix_len;
- }
-
- memcpy(p, num_prefix, num_prefix_len);
- p += num_prefix_len;
-
- memcpy(p, ekey, ekey_len);
- p += ekey_len;
- efree(ekey);
-
- if (key_suffix) {
- memcpy(p, key_suffix, key_suffix_len);
- p += key_suffix_len;
- }
- *(p++) = '[';
- *p = '\0';
- }
- ht->nApplyCount++;
- php_url_encode_hash_ex(HASH_OF(*zdata), formstr, NULL, 0, newprefix, newprefix_len, "]", 1, (Z_TYPE_PP(zdata) == IS_OBJECT ? *zdata : NULL) TSRMLS_CC);
- ht->nApplyCount--;
- efree(newprefix);
- } else if (Z_TYPE_PP(zdata) == IS_NULL || Z_TYPE_PP(zdata) == IS_RESOURCE) {
- /* Skip these types */
- continue;
- } else {
- if (formstr->len) {
- smart_str_appendl(formstr, arg_sep, arg_sep_len);
- }
- /* Simple key=value */
- smart_str_appendl(formstr, key_prefix, key_prefix_len);
- if (key_type == HASH_KEY_IS_STRING) {
- ekey = php_url_encode(key, key_len, &ekey_len);
- smart_str_appendl(formstr, ekey, ekey_len);
- efree(ekey);
- } else {
- /* Numeric key */
- if (num_prefix) {
- smart_str_appendl(formstr, num_prefix, num_prefix_len);
- }
- ekey_len = spprintf(&ekey, 12, "%ld", idx);
- smart_str_appendl(formstr, ekey, ekey_len);
- efree(ekey);
- }
- smart_str_appendl(formstr, key_suffix, key_suffix_len);
- smart_str_appendl(formstr, "=", 1);
- switch (Z_TYPE_PP(zdata)) {
- case IS_STRING:
- ekey = php_url_encode(Z_STRVAL_PP(zdata), Z_STRLEN_PP(zdata), &ekey_len);
- break;
- case IS_LONG:
- case IS_BOOL:
- ekey_len = spprintf(&ekey, 12, "%ld", Z_LVAL_PP(zdata));
- break;
- case IS_DOUBLE:
- ekey_len = spprintf(&ekey, 48, "%.*G", (int) EG(precision), Z_DVAL_PP(zdata));
- break;
- default:
- /* fall back on convert to string */
- MAKE_STD_ZVAL(copyzval);
- *copyzval = **zdata;
- zval_copy_ctor(copyzval);
- convert_to_string_ex(©zval);
- ekey = php_url_encode(Z_STRVAL_P(copyzval), Z_STRLEN_P(copyzval), &ekey_len);
- zval_ptr_dtor(©zval);
- }
- smart_str_appendl(formstr, ekey, ekey_len);
- efree(ekey);
- }
- }
-
- return SUCCESS;
-}
-/* }}} */
-
-/* {{{ proto string http_build_query(mixed formdata [, string prefix])
- Generates a form-encoded query string from an associative array or object. */
-PHP_FUNCTION(http_build_query)
-{
- zval *formdata;
- char *prefix = NULL;
- int prefix_len = 0;
- smart_str formstr = {0};
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|s", &formdata, &prefix, &prefix_len) != SUCCESS) {
- RETURN_FALSE;
- }
-
- if (Z_TYPE_P(formdata) != IS_ARRAY && Z_TYPE_P(formdata) != IS_OBJECT) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Parameter 1 expected to be Array or Object. Incorrect value given.");
- RETURN_FALSE;
- }
-
- if (php_url_encode_hash_ex(HASH_OF(formdata), &formstr, prefix, prefix_len, NULL, 0, NULL, 0, (Z_TYPE_P(formdata) == IS_OBJECT ? formdata : NULL) TSRMLS_CC) == FAILURE) {
- if (formstr.c) {
- efree(formstr.c);
- }
- RETURN_FALSE;
- }
-
- if (!formstr.c) {
- RETURN_NULL();
- }
-
- smart_str_0(&formstr);
-
- RETURN_STRINGL(formstr.c, formstr.len, 0);
-}
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 fdm=marker
- * vim<600: sw=4 ts=4
- */
-
#include "php_http.h"
#include "php_http_api.h"
#include "php_http_curl_api.h"
+#include "php_http_std_defs.h"
#include "ext/standard/php_smart_str.h"
#include "php_http.h"
#include "php_http_api.h"
#include "php_http_curl_api.h"
+#include "php_http_std_defs.h"
ZEND_DECLARE_MODULE_GLOBALS(http)
PHP_FUNCTION(http_redirect)
{
int url_len;
+ size_t query_len = 0;
zend_bool session = 0, permanent = 0;
zval *params = NULL;
- smart_str qstr = {0};
- char *url, *URI, LOC[HTTP_URI_MAXLEN + 9], RED[HTTP_URI_MAXLEN * 2 + 34];
+ char *query, *url, *URI,
+ LOC[HTTP_URI_MAXLEN + sizeof("Location: ")],
+ RED[HTTP_URI_MAXLEN * 2 + sizeof("Redirecting to <a href=\"%s?%s\">%s?%s</a>.\n")];
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sa!/bb", &url, &url_len, ¶ms, &session, &permanent) != SUCCESS) {
RETURN_FALSE;
/* treat params array with http_build_query() */
if (params) {
- if (php_url_encode_hash_ex(Z_ARRVAL_P(params), &qstr, NULL,0,NULL,0,NULL,0,NULL TSRMLS_CC) != SUCCESS) {
- if (qstr.c) {
- efree(qstr.c);
- }
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not encode query parameters");
+ if (SUCCESS != http_urlencode_hash_ex(Z_ARRVAL_P(params), 0, NULL, 0, &query, &query_len)) {
RETURN_FALSE;
}
- smart_str_0(&qstr);
}
URI = http_absolute_uri(url, NULL);
- if (qstr.c) {
- snprintf(LOC, HTTP_URI_MAXLEN + strlen("Location: "), "Location: %s?%s", URI, qstr.c);
- sprintf(RED, "Redirecting to <a href=\"%s?%s\">%s?%s</a>.\n", URI, qstr.c, URI, qstr.c);
- efree(qstr.c);
+ if (query_len) {
+ snprintf(LOC, HTTP_URI_MAXLEN + sizeof("Location: "), "Location: %s?%s", URI, query);
+ sprintf(RED, "Redirecting to <a href=\"%s?%s\">%s?%s</a>.\n", URI, query, URI, query);
+ efree(query);
} else {
- snprintf(LOC, HTTP_URI_MAXLEN + strlen("Location: "), "Location: %s", URI);
+ snprintf(LOC, HTTP_URI_MAXLEN + sizeof("Location: "), "Location: %s", URI);
sprintf(RED, "Redirecting to <a href=\"%s\">%s</a>.\n", URI, URI);
}
efree(URI);
}
/* }}}*/
+/* {{{ Sara Golemons http_build_query() */
+#ifndef ZEND_ENGINE_2
+
+/* {{{ proto string http_build_query(mixed formdata [, string prefix])
+ Generates a form-encoded query string from an associative array or object. */
+PHP_FUNCTION(http_build_query)
+{
+ zval *formdata;
+ char *prefix = NULL;
+ int prefix_len = 0;
+ smart_str formstr = {0};
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|s", &formdata, &prefix, &prefix_len) != SUCCESS) {
+ RETURN_FALSE;
+ }
+
+ if (Z_TYPE_P(formdata) != IS_ARRAY && Z_TYPE_P(formdata) != IS_OBJECT) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Parameter 1 expected to be Array or Object. Incorrect value given.");
+ RETURN_FALSE;
+ }
+
+ if (php_url_encode_hash_ex(HASH_OF(formdata), &formstr, prefix, prefix_len, NULL, 0, NULL, 0, (Z_TYPE_P(formdata) == IS_OBJECT ? formdata : NULL) TSRMLS_CC) == FAILURE) {
+ if (formstr.c) {
+ efree(formstr.c);
+ }
+ RETURN_FALSE;
+ }
+
+ if (!formstr.c) {
+ RETURN_NULL();
+ }
+
+ smart_str_0(&formstr);
+
+ RETURN_STRINGL(formstr.c, formstr.len, 0);
+}
+/* }}} */
+#endif /* !ZEND_ENGINE_2 */
+/* }}} */
/*
* Local variables:
#include "php_http.h"
#include "php_http_api.h"
#include "php_http_curl_api.h"
+#include "php_http_std_defs.h"
+
#include "ext/standard/php_smart_str.h"
#ifdef ZEND_ENGINE_2
*/
PHP_METHOD(HTTPi_Request, setOptions)
{
+ char *key = NULL;
+ long idx = 0;
zval *opts, *old_opts, **opt;
getObject(httpi_request_object, obj);
old_opts = GET_PROP(obj, options);
- /* headers and cookies need extra attention -- thus cannot use zend_hash_merge() or php_array_merge() directly */
- for ( zend_hash_internal_pointer_reset(Z_ARRVAL_P(opts));
- zend_hash_get_current_data(Z_ARRVAL_P(opts), (void **) &opt) == SUCCESS;
- zend_hash_move_forward(Z_ARRVAL_P(opts))) {
- char *key;
- long idx;
- if (HASH_KEY_IS_STRING == zend_hash_get_current_key(Z_ARRVAL_P(opts), &key, &idx, 0)) {
+ /* headers and cookies need extra attention -- thus cannot use array_merge() directly */
+ FOREACH_KEYVAL(opts, key, idx, opt) {
+ if (key) {
if (!strcmp(key, "headers")) {
zval **headers;
if (SUCCESS == zend_hash_find(Z_ARRVAL_P(old_opts), "headers", sizeof("headers"), (void **) &headers)) {
}
zval_add_ref(opt);
add_assoc_zval(old_opts, key, *opt);
+
+ /* reset */
+ key = NULL;
}
}
+
RETURN_TRUE;
}
/* }}} */
PHP_METHOD(HTTPi_Request, setQueryData)
{
zval *qdata;
+ char *query_data = NULL;
getObject(httpi_request_object, obj);
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &qdata)) {
}
if ((Z_TYPE_P(qdata) == IS_ARRAY) || (Z_TYPE_P(qdata) == IS_OBJECT)) {
- smart_str qstr = {0};
- HTTP_URL_ARGSEP_OVERRIDE;
- if (SUCCESS != php_url_encode_hash_ex(HASH_OF(qdata), &qstr, NULL, 0, NULL, 0, NULL, 0, NULL TSRMLS_CC)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't encode query data");
- if (qstr.c) {
- efree(qstr.c);
- }
- HTTP_URL_ARGSEP_RESTORE;
+ if (SUCCESS != http_urlencode_hash(HASH_OF(qdata), &query_data)) {
RETURN_FALSE;
}
- HTTP_URL_ARGSEP_RESTORE;
- smart_str_0(&qstr);
- UPD_PROP(obj, string, queryData, qstr.c);
- efree(qstr.c);
+ UPD_PROP(obj, string, queryData, query_data);
+ efree(query_data);
RETURN_TRUE;
}
PHP_METHOD(HTTPi_Request, addQueryData)
{
zval *qdata, *old_qdata;
- smart_str qstr = {0};
- char *separator;
+ char *query_data = NULL;
getObject(httpi_request_object, obj);
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &qdata)) {
}
old_qdata = GET_PROP(obj, queryData);
- if (Z_STRLEN_P(old_qdata)) {
- smart_str_appendl(&qstr, Z_STRVAL_P(old_qdata), Z_STRLEN_P(old_qdata));
- }
-
- HTTP_URL_ARGSEP_OVERRIDE;
- if (SUCCESS != php_url_encode_hash_ex(HASH_OF(qdata), &qstr, NULL, 0, NULL, 0, NULL, 0, NULL TSRMLS_CC)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't encode query data");
- if (qstr.c) {
- efree(qstr.c);
- }
- HTTP_URL_ARGSEP_RESTORE;
+
+ if (SUCCESS != http_urlencode_hash_ex(HASH_OF(qdata), 1, Z_STRVAL_P(old_qdata), Z_STRLEN_P(old_qdata), &query_data, NULL)) {
RETURN_FALSE;
}
- HTTP_URL_ARGSEP_RESTORE;
- smart_str_0(&qstr);
-
- UPD_PROP(obj, string, queryData, qstr.c);
- efree(qstr.c);
+ UPD_PROP(obj, string, queryData, query_data);
+ efree(query_data);
+
RETURN_TRUE;
}
/* }}} */
case HTTP_POST:
{
- zval *post_files, *post_data, **data;
+ zval *post_files, *post_data;
post_files = GET_PROP(obj, postFiles);
post_data = GET_PROP(obj, postData);
/*
* multipart post
*/
+ char *key = NULL;
+ long idx;
+ zval **data;
struct curl_httppost *http_post_data[2] = {NULL, NULL};
/* normal data */
- for ( zend_hash_internal_pointer_reset(Z_ARRVAL_P(post_data));
- zend_hash_get_current_data(Z_ARRVAL_P(post_data), (void **) &data) == SUCCESS;
- zend_hash_move_forward(Z_ARRVAL_P(post_data))) {
-
- char *key;
- long idx;
-
- if (HASH_KEY_IS_STRING == zend_hash_get_current_key(Z_ARRVAL_P(post_data), &key, &idx, 0)) {
+ FOREACH_KEYVAL(post_data, key, idx, data) {
+ if (key) {
convert_to_string_ex(data);
curl_formadd(&http_post_data[0], &http_post_data[1],
CURLFORM_COPYNAME, key,
CURLFORM_CONTENTSLENGTH, Z_STRLEN_PP(data),
CURLFORM_END
);
+
+ /* reset */
+ key = NULL;
}
}
-
+
/* file data */
- for ( zend_hash_internal_pointer_reset(Z_ARRVAL_P(post_files));
- zend_hash_get_current_data(Z_ARRVAL_P(post_files), (void **) &data) == SUCCESS;
- zend_hash_move_forward(Z_ARRVAL_P(post_files))) {
-
+ FOREACH_VAL(post_files, data) {
zval **file, **type, **name;
- if (
- SUCCESS == zend_hash_find(Z_ARRVAL_PP(data), "name", sizeof("name"), (void **) &name) &&
- SUCCESS == zend_hash_find(Z_ARRVAL_PP(data), "type", sizeof("type"), (void **) &type) &&
- SUCCESS == zend_hash_find(Z_ARRVAL_PP(data), "file", sizeof("file"), (void **) &file)
- ) {
+ if ( SUCCESS == zend_hash_find(Z_ARRVAL_PP(data), "name", sizeof("name"), (void **) &name) &&
+ SUCCESS == zend_hash_find(Z_ARRVAL_PP(data), "type", sizeof("type"), (void **) &type) &&
+ SUCCESS == zend_hash_find(Z_ARRVAL_PP(data), "file", sizeof("file"), (void **) &file)) {
curl_formadd(&http_post_data[0], &http_post_data[1],
CURLFORM_COPYNAME, Z_STRVAL_PP(name),
<filelist>
<dir name="/">
+ <file role="doc">CREDITS</file>
<file role="doc">EXPERIMENTAL</file>
<file role="doc">docs/functions.html</file>
<file role="src">php_http.h</file>
<file role="src">php_http_api.h</file>
<file role="src">php_http_curl_api.h</file>
+ <file role="src">php_http_std_defs.h</file>
<file role="src">http.c</file>
<file role="src">http_functions.c</file>
<file role="src">http_api.c</file>
<file role="src">http_curl_api.c</file>
- <file role="src">http_build_query.c</file>
- <file role="src">php_http_build_query.h</file>
</dir>
</filelist>
</package>
# define HTTP_G(v) (http_globals.v)
#endif
-#ifndef ZEND_ENGINE_2
-# include "php_http_build_query.h"
-#else
+#ifdef ZEND_ENGINE_2
typedef struct {
zend_object zo;
#endif
PHP_FUNCTION(http_auth_basic);
PHP_FUNCTION(http_auth_basic_cb);
-
+#ifndef ZEND_ENGINE_2
+PHP_FUNCTION(http_build_query);
+#endif
PHP_FUNCTION(ob_httpetaghandler);
PHP_MINIT_FUNCTION(http);
# define PHP_HTTP_API
#endif
-#ifndef ZEND_ENGINE_2
-# include "php_http_build_query.h"
-#endif
-
-#define RETURN_SUCCESS(v) RETURN_BOOL(SUCCESS == (v))
-#define HASH_ORNULL(z) ((z) ? Z_ARRVAL_P(z) : NULL)
-#define NO_ARGS if (ZEND_NUM_ARGS()) WRONG_PARAM_COUNT
-
-#define array_copy(src, dst) zend_hash_copy(Z_ARRVAL_P(dst), Z_ARRVAL_P(src), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *))
-#define array_merge(src, dst) zend_hash_merge(Z_ARRVAL_P(dst), Z_ARRVAL_P(src), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *), 1)
-
-#ifdef ZEND_ENGINE_2
-
-# define HTTP_REGISTER_CLASS_EX(classname, name, parent, flags) \
- { \
- zend_class_entry ce; \
- INIT_CLASS_ENTRY(ce, #classname, name## _class_methods); \
- ce.create_object = name## _new_object; \
- name## _ce = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \
- name## _ce->ce_flags |= flags; \
- memcpy(& name## _object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); \
- name## _object_handlers.clone_obj = NULL; \
- name## _declare_default_properties(name## _ce); \
- }
-
-# define HTTP_REGISTER_CLASS(classname, name, parent, flags) \
- { \
- zend_class_entry ce; \
- INIT_CLASS_ENTRY(ce, #classname, name## _class_methods); \
- ce.create_object = NULL; \
- name## _ce = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \
- name## _ce->ce_flags |= flags; \
- }
-
-# define getObject(t, o) t * o = ((t *) zend_object_store_get_object(getThis() TSRMLS_CC))
-# define OBJ_PROP(o) o->zo.properties
-# define DCL_PROP(a, t, n, v) zend_declare_property_ ##t(ce, (#n), sizeof(#n), (v), (ZEND_ACC_ ##a) TSRMLS_CC)
-# define DCL_PROP_Z(a, n, v) zend_declare_property(ce, (#n), sizeof(#n), (v), (ZEND_ACC_ ##a) TSRMLS_CC)
-# define DCL_PROP_N(a, n) zend_declare_property_null(ce, (#n), sizeof(#n), (ZEND_ACC_ ##a) TSRMLS_CC)
-# define UPD_PROP(o, t, n, v) zend_update_property_ ##t(o->zo.ce, getThis(), (#n), sizeof(#n), (v) TSRMLS_CC)
-# define SET_PROP(o, n, z) zend_update_property(o->zo.ce, getThis(), (#n), sizeof(#n), (z) TSRMLS_CC)
-# define GET_PROP(o, n) zend_read_property(o->zo.ce, getThis(), (#n), sizeof(#n), 0 TSRMLS_CC)
-
-# define INIT_PARR(o, n) \
- { \
- zval *__tmp; \
- MAKE_STD_ZVAL(__tmp); \
- array_init(__tmp); \
- SET_PROP(o, n, __tmp); \
- }
-
-# define FREE_PARR(o, p) \
- { \
- zval *__tmp = NULL; \
- if (__tmp = GET_PROP(o, p)) { \
- zval_dtor(__tmp); \
- FREE_ZVAL(__tmp); \
- __tmp = NULL; \
- } \
- }
-
-#endif /* ZEND_ENGINE_2 */
-
/* make functions that return SUCCESS|FAILURE more obvious */
typedef int STATUS;
} http_send_mode;
/* }}} */
-/* CR LF */
-#define HTTP_CRLF "\r\n"
-
-/* default cache control */
-#define HTTP_DEFAULT_CACHECONTROL "private, must-revalidate, max-age=0"
-
-/* max URI length */
-#define HTTP_URI_MAXLEN 2048
-
-/* buffer size */
-#define HTTP_BUF_SIZE 2097152
-
-/* server vars shorthand */
-#define HTTP_SERVER_VARS Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER])
-
-
-/* {{{ HTTP_GSC(var, name, ret) */
-#define HTTP_GSC(var, name, ret) HTTP_GSP(var, name, return ret)
-/* }}} */
-
-/* {{{ HTTP_GSP(var, name, ret) */
-#define HTTP_GSP(var, name, ret) \
- if (!(var = http_get_server_var(name))) { \
- ret; \
- } \
- if (!Z_STRLEN_P(var)) { \
- ret; \
- }
-/* }}} */
-
char *pretty_key(char *key, int key_len, int uctitle, int xhyphen);
/* {{{ public API */
#define http_chunked_decode(e, el, d, dl) _http_chunked_decode((e), (el), (d), (dl) TSRMLS_CC)
PHP_HTTP_API STATUS _http_chunked_decode(const char *encoded, const size_t encoded_len, char **decoded, size_t *decoded_len TSRMLS_DC);
+#define http_urlencode_hash(h, q) _http_urlencode_hash_ex((h), 1, NULL, 0, (q), NULL TSRMLS_CC)
+#define http_urlencode_hash_ex(h, o, p, pl, q, ql) _http_urlencode_hash_ex((h), (o), (p), (pl), (q), (ql) TSRMLS_CC)
+PHP_HTTP_API STATUS _http_urlencode_hash_ex(HashTable *hash, int override_argsep, char *pre_encoded_data, size_t pre_encoded_len, char **encoded_data, size_t *encoded_len TSRMLS_DC);
+
#define http_split_response(r, h, b) _http_split_response_ex(Z_STRVAL_P(r), Z_STRLEN_P(r), (h), (b) TSRMLS_CC)
#define http_split_response_ex(r, l, h, b) _http_split_response_ex((r), (l), (h), (b) TSRMLS_CC)
PHP_HTTP_API STATUS _http_split_response_ex(char *response, size_t repsonse_len, zval *zheaders, zval *zbody TSRMLS_DC);
#define http_auth_header(t, r) _http_auth_header((t), (r) TSRMLS_CC)
PHP_HTTP_API STATUS _http_auth_header(const char *type, const char *realm TSRMLS_DC);
+#ifndef ZEND_ENGINE_2
+#define php_url_encode_hash(ht, formstr) php_url_encode_hash_ex((ht), (formstr), NULL, 0, NULL, 0, NULL, 0, NULL TSRMLS_CC)
+PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
+ const char *num_prefix, int num_prefix_len,
+ const char *key_prefix, int key_prefix_len,
+ const char *key_suffix, int key_suffix_len,
+ zval *type TSRMLS_DC);
+#endif
+
/* }}} */
#endif
+++ /dev/null
-/*
- +----------------------------------------------------------------------+
- | PHP Version 5 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
- +----------------------------------------------------------------------+
- | 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 the following url: |
- | 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. |
- +----------------------------------------------------------------------+
- | Authors: Sara Golemon <pollita@php.net> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef PHP_HTTP_H
-#define PHP_HTTP_H
-
-#include "php.h"
-#include "ext/standard/php_smart_str.h"
-
-PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
- const char *num_prefix, int num_prefix_len,
- const char *key_prefix, int key_prefix_len,
- const char *key_suffix, int key_suffix_len,
- zval *type TSRMLS_DC);
-#define php_url_encode_hash(ht, formstr) php_url_encode_hash_ex((ht), (formstr), NULL, 0, NULL, 0, NULL, 0, NULL TSRMLS_CC)
-
-PHP_FUNCTION(http_build_query);
-
-#endif
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 fdm=marker
- * vim<600: sw=4 ts=4
- */
#define PHP_HTTP_CURL_API_H
#include <curl/curl.h>
-#include "zend_ini.h"
-
-/* override arg_separator.output to "&" for data used in outgoing requests */
-#define HTTP_URL_ARGSEP_OVERRIDE zend_alter_ini_entry("arg_separator.output", sizeof("arg_separator.output") - 1, "&", 1, ZEND_INI_ALL, ZEND_INI_STAGE_RUNTIME)
-#define HTTP_URL_ARGSEP_RESTORE zend_restore_ini_entry("arg_separator.output", sizeof("arg_separator.output") - 1, ZEND_INI_STAGE_RUNTIME)
-
-/* CURL buffer size */
-#define HTTP_CURLBUF_SIZE 16384
#define http_get(u, o, i, d, l) _http_get_ex(NULL, (u), (o), (i), (d), (l) TSRMLS_CC)
#define http_get_ex(c, u, o, i, d, l) _http_get_ex((c), (u), (o), (i), (d), (l) TSRMLS_CC)
--- /dev/null
+/*
+ +----------------------------------------------------------------------+
+ | 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> |
+ +----------------------------------------------------------------------+
+*/
+
+/* $Id$ */
+
+#ifndef PHP_HTTP_STD_DEFS_H
+#define PHP_HTTP_STD_DEFS_H
+
+#define RETURN_SUCCESS(v) RETURN_BOOL(SUCCESS == (v))
+#define HASH_ORNULL(z) ((z) ? Z_ARRVAL_P(z) : NULL)
+#define NO_ARGS if (ZEND_NUM_ARGS()) WRONG_PARAM_COUNT
+
+/* CR LF */
+#define HTTP_CRLF "\r\n"
+
+/* default cache control */
+#define HTTP_DEFAULT_CACHECONTROL "private, must-revalidate, max-age=0"
+
+/* max URI length */
+#define HTTP_URI_MAXLEN 2048
+
+/* send buffer size */
+#define HTTP_SENDBUF_SIZE 2097152
+
+/* CURL buffer size */
+#define HTTP_CURLBUF_SIZE 16384
+
+/* server vars shorthand */
+#define HTTP_SERVER_VARS Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER])
+
+
+/* {{{ HTTP_GSC(var, name, ret) */
+#define HTTP_GSC(var, name, ret) HTTP_GSP(var, name, return ret)
+/* }}} */
+
+/* {{{ HTTP_GSP(var, name, ret) */
+#define HTTP_GSP(var, name, ret) \
+ if (!(var = http_get_server_var(name))) { \
+ ret; \
+ } \
+ if (!Z_STRLEN_P(var)) { \
+ ret; \
+ }
+/* }}} */
+
+/* override arg_separator.output to "&" for data used in outgoing requests */
+#include "zend_ini.h"
+#define HTTP_URL_ARGSEP_DEFAULT "&"
+#define HTTP_URL_ARGSEP_OVERRIDE zend_alter_ini_entry("arg_separator.output", sizeof("arg_separator.output") - 1, HTTP_URL_ARGSEP_DEFAULT, sizeof(HTTP_URL_ARGSEP_DEFAULT) - 1, ZEND_INI_ALL, ZEND_INI_STAGE_RUNTIME)
+#define HTTP_URL_ARGSEP_RESTORE zend_restore_ini_entry("arg_separator.output", sizeof("arg_separator.output") - 1, ZEND_INI_STAGE_RUNTIME)
+
+/* {{{ arrays */
+#define FOREACH_VAL(array, val) FOREACH_HASH_VAL(Z_ARRVAL_P(array), val)
+#define FOREACH_HASH_VAL(hash, val) \
+ for ( zend_hash_internal_pointer_reset(hash); \
+ zend_hash_get_current_data(hash, (void **) &val) == SUCCESS; \
+ zend_hash_move_forward(hash))
+
+#define FOREACH_KEY(array, strkey, numkey) FOREACH_HASH_KEY(Z_ARRVAL_P(array), strkey, numkey)
+#define FOREACH_HASH_KEY(hash, strkey, numkey) \
+ for ( zend_hash_internal_pointer_reset(hash); \
+ zend_hash_get_current_key(hash, &strkey, &numkey, 0) != HASH_KEY_NON_EXISTANT; \
+ zend_hash_move_forward(hash)) \
+
+#define FOREACH_KEYVAL(array, strkey, numkey, val) FOREACH_HASH_KEYVAL(Z_ARRVAL_P(array), strkey, numkey, val)
+#define FOREACH_HASH_KEYVAL(hash, strkey, numkey, val) \
+ for ( zend_hash_internal_pointer_reset(hash); \
+ zend_hash_get_current_key(hash, &strkey, &numkey, 0) != HASH_KEY_NON_EXISTANT && \
+ zend_hash_get_current_data(hash, (void **) &val) == SUCCESS; \
+ zend_hash_move_forward(hash)) \
+
+#define array_copy(src, dst) zend_hash_copy(Z_ARRVAL_P(dst), Z_ARRVAL_P(src), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *))
+#define array_merge(src, dst) zend_hash_merge(Z_ARRVAL_P(dst), Z_ARRVAL_P(src), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *), 1)
+/* }}} */
+
+/* {{{ objects & properties */
+#ifdef ZEND_ENGINE_2
+
+# define HTTP_REGISTER_CLASS_EX(classname, name, parent, flags) \
+ { \
+ zend_class_entry ce; \
+ INIT_CLASS_ENTRY(ce, #classname, name## _class_methods); \
+ ce.create_object = name## _new_object; \
+ name## _ce = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \
+ name## _ce->ce_flags |= flags; \
+ memcpy(& name## _object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); \
+ name## _object_handlers.clone_obj = NULL; \
+ name## _declare_default_properties(name## _ce); \
+ }
+
+# define HTTP_REGISTER_CLASS(classname, name, parent, flags) \
+ { \
+ zend_class_entry ce; \
+ INIT_CLASS_ENTRY(ce, #classname, name## _class_methods); \
+ ce.create_object = NULL; \
+ name## _ce = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \
+ name## _ce->ce_flags |= flags; \
+ }
+
+# define getObject(t, o) t * o = ((t *) zend_object_store_get_object(getThis() TSRMLS_CC))
+# define OBJ_PROP(o) o->zo.properties
+# define DCL_PROP(a, t, n, v) zend_declare_property_ ##t(ce, (#n), sizeof(#n), (v), (ZEND_ACC_ ##a) TSRMLS_CC)
+# define DCL_PROP_Z(a, n, v) zend_declare_property(ce, (#n), sizeof(#n), (v), (ZEND_ACC_ ##a) TSRMLS_CC)
+# define DCL_PROP_N(a, n) zend_declare_property_null(ce, (#n), sizeof(#n), (ZEND_ACC_ ##a) TSRMLS_CC)
+# define UPD_PROP(o, t, n, v) zend_update_property_ ##t(o->zo.ce, getThis(), (#n), sizeof(#n), (v) TSRMLS_CC)
+# define SET_PROP(o, n, z) zend_update_property(o->zo.ce, getThis(), (#n), sizeof(#n), (z) TSRMLS_CC)
+# define GET_PROP(o, n) zend_read_property(o->zo.ce, getThis(), (#n), sizeof(#n), 0 TSRMLS_CC)
+
+# define INIT_PARR(o, n) \
+ { \
+ zval *__tmp; \
+ MAKE_STD_ZVAL(__tmp); \
+ array_init(__tmp); \
+ SET_PROP(o, n, __tmp); \
+ }
+
+# define FREE_PARR(o, p) \
+ { \
+ zval *__tmp = NULL; \
+ if (__tmp = GET_PROP(o, p)) { \
+ zval_dtor(__tmp); \
+ FREE_ZVAL(__tmp); \
+ __tmp = NULL; \
+ } \
+ }
+
+#endif /* ZEND_ENGINE_2 */
+/* }}} */
+
+
+#endif /* PHP_HTTP_STD_DEFS_H */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: noet sw=4 ts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4
+ */
\ No newline at end of file