php_info_print_table_colspan_header(2, "Request Methods");
{
unsigned i;
+ HashPosition pos;
zval **custom_method;
phpstr *known_request_methods = phpstr_new();
phpstr *custom_request_methods = phpstr_new();
phpstr_appendl(known_request_methods, http_request_method_name(i));
phpstr_appends(known_request_methods, ", ");
}
- FOREACH_HASH_VAL(&HTTP_G(request).methods.custom, custom_method) {
+ FOREACH_HASH_VAL(pos, &HTTP_G(request).methods.custom, custom_method) {
phpstr_append(custom_request_methods, Z_STRVAL_PP(custom_method), Z_STRLEN_PP(custom_method));
phpstr_appends(custom_request_methods, ", ");
}
} \
\
if (rs_array) { \
+ HashPosition pos; \
zval **value; \
\
- FOREACH_VAL(supported, value) { \
+ FOREACH_VAL(pos, supported, value) { \
convert_to_string_ex(value); \
add_assoc_double(rs_array, Z_STRVAL_PP(value), 1.0); \
} \
char *_http_negotiate_language_func(const char *test, double *quality, HashTable *supported TSRMLS_DC)
{
zval **value;
+ HashPosition pos;
const char *dash_test;
- FOREACH_HASH_VAL(supported, value) {
+ FOREACH_HASH_VAL(pos, supported, value) {
#if HTTP_DBG_NEG
fprintf(stderr, "strcasecmp('%s', '%s')\n", Z_STRVAL_PP(value), test);
#endif
/* no distinct match found, so try primaries */
if (dash_test = strchr(test, '-')) {
- FOREACH_HASH_VAL(supported, value) {
+ FOREACH_HASH_VAL(pos, supported, value) {
int len = dash_test - test;
#if HTTP_DBG_NEG
fprintf(stderr, "strncascmp('%s', '%s', %d)\n", Z_STRVAL_PP(value), test, len);
char *_http_negotiate_default_func(const char *test, double *quality, HashTable *supported TSRMLS_DC)
{
zval **value;
+ HashPosition pos;
- FOREACH_HASH_VAL(supported, value) {
+ FOREACH_HASH_VAL(pos, supported, value) {
#if HTTP_DBG_NEG
fprintf(stderr, "strcasecmp('%s', '%s')\n", Z_STRVAL_PP(value), test);
#endif
if (zend_hash_num_elements(Z_ARRVAL(ex_arr)) > 0) {
int i = 0;
+ HashPosition pos;
zval **entry, array;
INIT_PZVAL(&array);
array_init(&array);
- FOREACH_HASH_VAL(Z_ARRVAL(ex_arr), entry) {
+ FOREACH_HASH_VAL(pos, Z_ARRVAL(ex_arr), entry) {
double quality;
char *selected, *identifier;
const char *separator;
char *key = NULL;
ulong idx = 0;
zval array, **hsv;
+ HashPosition pos;
Z_ARRVAL(array) = headers;
if (SUCCESS == zend_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"), (void **) &hsv)) {
- FOREACH_KEY(*hsv, key, idx) {
+ FOREACH_KEY(pos, *hsv, key, idx) {
if (key && !strncmp(key, "HTTP_", 5)) {
zval **header;
key = pretty_key(key, strlen(key), 1, 1);
}
- zend_hash_get_current_data(Z_ARRVAL_PP(hsv), (void **) &header);
+ zend_hash_get_current_data_ex(Z_ARRVAL_PP(hsv), (void **) &header, &pos);
add_assoc_stringl(&array, key, Z_STRVAL_PP(header), Z_STRLEN_PP(header), 1);
key = NULL;
}
ulong idx;
zend_bool result = 0;
HashTable headers;
+ HashPosition pos;
name = pretty_key(estrdup(header), strlen(header), 1, 1);
zend_hash_init(&headers, 0, NULL, ZVAL_PTR_DTOR, 0);
http_get_request_headers_ex(&headers, 1);
- FOREACH_HASH_KEY(&headers, key, idx) {
+ FOREACH_HASH_KEY(pos, &headers, key, idx) {
if (key && (!strcmp(key, name))) {
zval **data;
- if (SUCCESS == zend_hash_get_current_data(&headers, (void **) &data)) {
+ if (SUCCESS == zend_hash_get_current_data_ex(&headers, (void **) &data, &pos)) {
result = (match_case ? strcmp(Z_STRVAL_PP(data), value) : strcasecmp(Z_STRVAL_PP(data), value)) ? 0 : 1;
}
break;
char *key, *data;
ulong idx;
zval **header;
+ HashPosition pos1;
phpstr_init_ex(&str, 4096, 0);
break;
}
- FOREACH_HASH_KEYVAL(&msg->hdrs, key, idx, header) {
+ FOREACH_HASH_KEYVAL(pos1, &msg->hdrs, key, idx, header) {
if (key) {
zval **single_header;
break;
case IS_ARRAY:
- FOREACH_VAL(*header, single_header) {
+ {
+ HashPosition pos2;
+ FOREACH_VAL(pos2, *header, single_header) {
phpstr_appendf(&str, "%s: %s" HTTP_CRLF, key, Z_STRVAL_PP(single_header));
}
+ }
break;
}
char *key;
ulong idx;
zval **val;
+ HashPosition pos1;
- FOREACH_HASH_KEYVAL(&message->hdrs, key, idx, val) {
+ FOREACH_HASH_KEYVAL(pos1, &message->hdrs, key, idx, val) {
if (key) {
if (Z_TYPE_PP(val) == IS_ARRAY) {
zend_bool first = 1;
zval **data;
+ HashPosition pos2;
- FOREACH_VAL(*val, data) {
+ FOREACH_VAL(pos2, *val, data) {
http_send_header_ex(key, strlen(key), Z_STRVAL_PP(data), Z_STRLEN_PP(data), first, NULL);
first = 0;
}
char *key = NULL;
ulong idx;
zval **data;
+ HashPosition pos;
struct curl_httppost *http_post_data[2] = {NULL, NULL};
/* normal data */
- FOREACH_HASH_KEYVAL(fields, key, idx, data) {
+ FOREACH_HASH_KEYVAL(pos, fields, key, idx, data) {
CURLcode err;
if (key) {
+ zval *orig = *data;
+
convert_to_string_ex(data);
err = curl_formadd(&http_post_data[0], &http_post_data[1],
CURLFORM_COPYNAME, key,
CURLFORM_CONTENTSLENGTH, (long) Z_STRLEN_PP(data),
CURLFORM_END
);
+
+ if (orig != *data) {
+ zval_ptr_dtor(data);
+ }
+
if (CURLE_OK != err) {
http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Could not encode post fields: %s", curl_easy_strerror(err));
curl_formfree(http_post_data[0]);
}
/* file data */
- FOREACH_HASH_VAL(files, data) {
+ FOREACH_HASH_VAL(pos, 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 (Z_TYPE_PP(data) != IS_ARRAY) {
+ http_error(HE_NOTICE, HTTP_E_INVALID_PARAM, "Unrecognized type of post file array entry");
+ } else 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)) {
http_error(HE_NOTICE, HTTP_E_INVALID_PARAM, "Post file array entry misses either 'name', 'type' or 'file' entry");
} else {
CURLcode err = curl_formadd(&http_post_data[0], &http_post_data[1],
if (zoption = http_curl_getopt(options, "headers", IS_ARRAY)) {
char *header_key;
ulong header_idx;
+ HashPosition pos;
struct curl_slist *headers = NULL;
- FOREACH_KEY(zoption, header_key, header_idx) {
+ FOREACH_KEY(pos, zoption, header_key, header_idx) {
if (header_key) {
zval **header_val;
- if (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(zoption), (void **) &header_val)) {
+ if (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_P(zoption), (void **) &header_val, &pos)) {
char header[1024] = {0};
snprintf(header, 1023, "%s: %s", header_key, Z_STRVAL_PP(header_val));
headers = curl_slist_append(headers, http_request_data_copy(COPY_STRING, header));
if (zoption = http_curl_getopt(options, "cookies", IS_ARRAY)) {
char *cookie_key = NULL;
ulong cookie_idx = 0;
+ HashPosition pos;
phpstr *qstr = phpstr_new();
- FOREACH_KEY(zoption, cookie_key, cookie_idx) {
+ FOREACH_KEY(pos, zoption, cookie_key, cookie_idx) {
if (cookie_key) {
zval **cookie_val;
- if (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(zoption), (void **) &cookie_val)) {
+ if (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_P(zoption), (void **) &cookie_val, &pos)) {
phpstr_appendf(qstr, "%s=%s; ", cookie_key, Z_STRVAL_PP(cookie_val));
}
ulong idx;
char *key = NULL;
zval **param;
+ HashPosition pos;
- FOREACH_KEYVAL(zoption, key, idx, param) {
+ FOREACH_KEYVAL(pos, zoption, key, idx, param) {
if (key) {
HTTP_CURL_OPT_SSL_STRING(CERT);
#if LIBCURL_VERSION_NUM >= 0x070903
zval **data;
char *key;
ulong idx;
+ HashPosition pos;
- FOREACH_HASH_KEYVAL(&HTTP_G(request).methods.custom, key, idx, data) {
+ FOREACH_HASH_KEYVAL(pos, &HTTP_G(request).methods.custom, key, idx, data) {
if (!strcmp(name, Z_STRVAL_PP(data))) {
return idx + HTTP_MAX_REQUEST_METHOD;
}
{
char *key = NULL;
ulong idx = 0;
+ HashPosition pos;
zval *opts = NULL, *old_opts, **opt;
getObject(http_request_object, obj);
}
/* some options need extra attention -- thus cannot use array_merge() directly */
- FOREACH_KEYVAL(opts, key, idx, opt) {
+ FOREACH_KEYVAL(pos, opts, key, idx, opt) {
if (key) {
if (!strcmp(key, "headers")) {
zval **headers;
ulong idx = 0;
char *key = NULL;
zval **header = NULL;
+ HashPosition pos1;
- convert_to_array_ex(headers);
- FOREACH_HASH_KEYVAL(Z_ARRVAL_PP(headers), key, idx, header) {
+ convert_to_array(*headers);
+ FOREACH_HASH_KEYVAL(pos1, Z_ARRVAL_PP(headers), key, idx, header) {
if (key && !strcasecmp(key, "Set-Cookie")) {
/* several cookies? */
if (Z_TYPE_PP(header) == IS_ARRAY) {
zval **cookie;
+ HashPosition pos2;
- FOREACH_HASH_VAL(Z_ARRVAL_PP(header), cookie) {
+ FOREACH_HASH_VAL(pos2, Z_ARRVAL_PP(header), cookie) {
zval *cookie_hash;
MAKE_STD_ZVAL(cookie_hash);
array_init(cookie_hash);
zend_bool replace = 1;
char *name;
int name_len = 0;
- zval *value = NULL;
+ zval *value = NULL, *orig = NULL;
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz/!|b", &name, &name_len, &value, &replace)) {
RETURN_FALSE;
/* send multiple header if replace is false and value is an array */
if (!replace && Z_TYPE_P(value) == IS_ARRAY) {
zval **data;
+ HashPosition pos;
- FOREACH_VAL(value, data) {
+ FOREACH_VAL(pos, value, data) {
+ zval *orig = *data;
+
convert_to_string_ex(data);
if (SUCCESS != http_send_header_ex(name, name_len, Z_STRVAL_PP(data), Z_STRLEN_PP(data), 0, NULL)) {
+ if (orig != *data) {
+ zval_ptr_dtor(data);
+ }
RETURN_FALSE;
}
+ if (orig != *data) {
+ zval_ptr_dtor(data);
+ }
}
RETURN_TRUE;
}
/* send standard header */
- if (Z_TYPE_P(value) != IS_STRING) {
- convert_to_string_ex(&value);
+ orig = value;
+ convert_to_string_ex(&value);
+ RETVAL_SUCCESS(http_send_header_ex(name, name_len, Z_STRVAL_P(value), Z_STRLEN_P(value), replace, NULL));
+ if (orig != value) {
+ zval_ptr_dtor(&value);
}
- RETURN_SUCCESS(http_send_header_ex(name, name_len, Z_STRVAL_P(value), Z_STRLEN_P(value), replace, NULL));
}
/* }}} */
}
} else {
/* multi range */
+ HashPosition pos;
zval **range, **begin, **end;
const char *content_type = HTTP_G(send).content_type;
char boundary_str[32], range_header_str[256];
content_type = "application/x-octetstream";
}
- FOREACH_HASH_VAL(&ranges, range) {
+ FOREACH_HASH_VAL(pos, &ranges, range) {
if ( SUCCESS == zend_hash_index_find(Z_ARRVAL_PP(range), 0, (void **) &begin) &&
SUCCESS == zend_hash_index_find(Z_ARRVAL_PP(range), 1, (void **) &end)) {
char preface_str[512];
uint len = 0;
ulong idx = 0;
zval **data = NULL;
+ HashPosition pos;
if (!ht || !str) {
http_error(HE_WARNING, HTTP_E_INVALID_PARAM, "Invalid parameters");
return SUCCESS;
}
- FOREACH_HASH_KEYLENVAL(ht, key, len, idx, data) {
+ FOREACH_HASH_KEYLENVAL(pos, ht, key, len, idx, data) {
char *encoded_key;
int encoded_len;
phpstr new_prefix;
ZEND_BEGIN_MODULE_GLOBALS(http)
-#ifdef ZEND_ENGINE_2
- zend_bool only_exceptions;
-#endif
struct _http_globals_etag {
long mode;
void *ctx;
#endif /* HTTP_HAVE_CURL */
} request;
+#ifdef ZEND_ENGINE_2
+ zend_bool only_exceptions;
+#endif
+
ZEND_END_MODULE_GLOBALS(http)
#ifdef ZTS
STD_PHP_INI_ENTRY_EX(entry, default, scope, updater, global, zend_http_globals, http_globals, displayer)
/* {{{ 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 FOREACH_KEYLENVAL(array, strkey, keylen, numkey, val) FOREACH_HASH_KEYVAL(Z_ARRVAL_P(array), strkey, keylen, numkey, val)
-#define FOREACH_HASH_KEYLENVAL(hash, strkey, keylen, numkey, val) \
- for ( zend_hash_internal_pointer_reset(hash); \
- zend_hash_get_current_key_ex(hash, &strkey, &keylen, &numkey, 0, NULL) != HASH_KEY_NON_EXISTANT && \
- zend_hash_get_current_data(hash, (void **) &val) == SUCCESS; \
- zend_hash_move_forward(hash))
+#define FOREACH_VAL(pos, array, val) FOREACH_HASH_VAL(pos, Z_ARRVAL_P(array), val)
+#define FOREACH_HASH_VAL(pos, hash, val) \
+ for ( zend_hash_internal_pointer_reset_ex(hash, &pos); \
+ zend_hash_get_current_data_ex(hash, (void **) &val, &pos) == SUCCESS; \
+ zend_hash_move_forward_ex(hash, &pos))
+
+#define FOREACH_KEY(pos, array, strkey, numkey) FOREACH_HASH_KEY(pos, Z_ARRVAL_P(array), strkey, numkey)
+#define FOREACH_HASH_KEY(pos, hash, strkey, numkey) \
+ for ( zend_hash_internal_pointer_reset_ex(hash, &pos); \
+ zend_hash_get_current_key_ex(hash, &strkey, NULL, &numkey, 0, &pos) != HASH_KEY_NON_EXISTANT; \
+ zend_hash_move_forward_ex(hash, &pos)) \
+
+#define FOREACH_KEYVAL(pos, array, strkey, numkey, val) FOREACH_HASH_KEYVAL(pos, Z_ARRVAL_P(array), strkey, numkey, val)
+#define FOREACH_HASH_KEYVAL(pos, hash, strkey, numkey, val) \
+ for ( zend_hash_internal_pointer_reset_ex(hash, &pos); \
+ zend_hash_get_current_key_ex(hash, &strkey, NULL, &numkey, 0, &pos) != HASH_KEY_NON_EXISTANT && \
+ zend_hash_get_current_data_ex(hash, (void **) &val, &pos) == SUCCESS; \
+ zend_hash_move_forward_ex(hash, &pos))
+
+#define FOREACH_KEYLENVAL(pos, array, strkey, keylen, numkey, val) FOREACH_HASH_KEYVAL(pos, Z_ARRVAL_P(array), strkey, keylen, numkey, val)
+#define FOREACH_HASH_KEYLENVAL(pos, hash, strkey, keylen, numkey, val) \
+ for ( zend_hash_internal_pointer_reset_ex(hash, &pos); \
+ zend_hash_get_current_key_ex(hash, &strkey, &keylen, &numkey, 0, &pos) != HASH_KEY_NON_EXISTANT && \
+ zend_hash_get_current_data_ex(hash, (void **) &val, &pos) == SUCCESS; \
+ zend_hash_move_forward_ex(hash, &pos))
#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)
uint klen; \
char *key = NULL; \
zval **data; \
+ HashPosition pos; \
\
- for ( zend_hash_internal_pointer_reset(Z_ARRVAL_P(src)); \
- zend_hash_get_current_key_ex(Z_ARRVAL_P(src), &key, &klen, &idx, 0, NULL) != HASH_KEY_NON_EXISTANT && \
- zend_hash_get_current_data(Z_ARRVAL_P(src), (void **) &data) == SUCCESS; \
- zend_hash_move_forward(Z_ARRVAL_P(src))) \
+ for ( zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(src), &pos); \
+ zend_hash_get_current_key_ex(Z_ARRVAL_P(src), &key, &klen, &idx, 0, &pos) != HASH_KEY_NON_EXISTANT && \
+ zend_hash_get_current_data_ex(Z_ARRVAL_P(src), (void **) &data, &pos) == SUCCESS; \
+ zend_hash_move_forward_ex(Z_ARRVAL_P(src), &pos)) \
{ \
if (key) { \
zval **tmp; \