php_http_message_body_addref(body);
return body;
}
-
+
body = ecalloc(1, sizeof(php_http_message_body_t));
body->refcount = 1;
if (stream) {
body->res = stream->res;
- ++GC_REFCOUNT(body->res);
+ GC_ADDREF(body->res);
} else {
body->res = php_stream_temp_create(TEMP_STREAM_DEFAULT, 0xffff)->res;
}
zval *val;
php_http_arrkey_t key;
- if (!ZEND_HASH_GET_APPLY_COUNT(fields)) {
- ZEND_HASH_INC_APPLY_COUNT(fields);
+ if (!HT_IS_RECURSIVE(fields)) {
+ HT_PROTECT_RECURSION(fields);
ZEND_HASH_FOREACH_KEY_VAL_IND(fields, key.h, key.key, val)
{
char *str = format_key(&key, name);
if (Z_TYPE_P(val) != IS_ARRAY && Z_TYPE_P(val) != IS_OBJECT) {
if (SUCCESS != add_recursive_field_value(body, str, val)) {
efree(str);
- ZEND_HASH_DEC_APPLY_COUNT(fields);
+ HT_UNPROTECT_RECURSION(fields);
return FAILURE;
}
} else if (SUCCESS != add_recursive_fields(body, str, HASH_OF(val))) {
efree(str);
- ZEND_HASH_DEC_APPLY_COUNT(fields);
+ HT_UNPROTECT_RECURSION(fields);
return FAILURE;
}
efree(str);
}
ZEND_HASH_FOREACH_END();
- ZEND_HASH_DEC_APPLY_COUNT(fields);
+ HT_UNPROTECT_RECURSION(fields);
}
return SUCCESS;
zval *val;
php_http_arrkey_t key;
- if (!ZEND_HASH_GET_APPLY_COUNT(files)) {
- ZEND_HASH_INC_APPLY_COUNT(files);
+ if (!HT_IS_RECURSIVE(files)) {
+ HT_PROTECT_RECURSION(files);
ZEND_HASH_FOREACH_KEY_VAL_IND(files, key.h, key.key, val)
{
if (Z_TYPE_P(val) == IS_ARRAY || Z_TYPE_P(val) == IS_OBJECT) {
if (SUCCESS != add_recursive_files(body, str, HASH_OF(val))) {
efree(str);
- ZEND_HASH_DEC_APPLY_COUNT(files);
+ HT_UNPROTECT_RECURSION(files);
return FAILURE;
}
efree(str);
}
}
ZEND_HASH_FOREACH_END();
- ZEND_HASH_DEC_APPLY_COUNT(files);
+ HT_UNPROTECT_RECURSION(files);
}
return SUCCESS;
} else {
# define HASH_OF(p) ((HashTable*)(Z_TYPE_P(p)==IS_ARRAY ? Z_ARRVAL_P(p) : ((Z_TYPE_P(p)==IS_OBJECT ? Z_OBJ_HT_P(p)->get_properties((p)) : NULL))))
#endif
+#ifndef GC_SET_REFCOUNT
+# define GC_SET_REFCOUNT(gc, rc) GC_REFCOUNT(gc) = rc
+#endif
+#ifndef GC_ADDREF
+# define GC_ADDREF(gc) ++GC_REFCOUNT(gc)
+#endif
+#ifndef GC_DELREF
+# define GC_DELREF(gc) --GC_REFCOUNT(gc)
+#endif
+
+#ifdef ZEND_HASH_GET_APPLY_COUNT
+# define HT_IS_RECURSIVE(ht) (ZEND_HASH_GET_APPLY_COUNT(ht) > 0)
+#else
+# define HT_IS_RECURSIVE(ht) GC_IS_RECURSIVE(ht)
+#endif
+#ifdef ZEND_HASH_INC_APPLY_COUNT
+# define HT_PROTECT_RECURSION(ht) ZEND_HASH_INC_APPLY_COUNT(ht)
+#else
+# define HT_PROTECT_RECURSION(ht) GC_PROTECT_RECURSION(ht)
+#endif
+#ifdef ZEND_HASH_DEC_APPLY_COUNT
+# define HT_UNPROTECT_RECURSION ZEND_HASH_DEC_APPLY_COUNT(ht)
+#else
+# define HT_UNPROTECT_RECURSION(ht) GC_UNPROTECT_RECURSION(ht)
+#endif
+
static inline void *PHP_HTTP_OBJ(zend_object *zo, zval *zv)
{
if (!zo) {
str->len = l;
str->h = 0;
- GC_REFCOUNT(str) = 1;
+ GC_SET_REFCOUNT(str, 1);
GC_TYPE_INFO(str) = IS_STRING;
return str;
static inline char *localhostname(void)
{
char hostname[1024] = {0};
-
+
#if PHP_WIN32
if (SUCCESS == gethostname(hostname, lenof(hostname))) {
return estrdup(hostname);
if (!(flags & PHP_HTTP_URL_STRIP_PASS)) {
url_copy(pass);
}
-
+
url_copy(host);
-
+
if (!(flags & PHP_HTTP_URL_STRIP_PORT)) {
url(buf)->port = url_isset(new_url, port) ? new_url->port : ((old_url) ? old_url->port : 0);
}
if ((flags & PHP_HTTP_URL_JOIN_PATH) && url_isset(old_url, path) && url_isset(new_url, path) && *new_url->path != '/') {
size_t old_path_len = strlen(old_url->path), new_path_len = strlen(new_url->path);
char *path = ecalloc(1, old_path_len + new_path_len + 1 + 1);
-
+
strcat(path, old_url->path);
if (path[old_path_len - 1] != '/') {
php_dirname(path, old_path_len);
strcat(path, "/");
}
strcat(path, new_url->path);
-
+
url(buf)->path = &buf.data[buf.used];
if (path[0] != '/') {
url_append(&buf, php_http_buffer_append(&buf, "/", 1));
if (!(flags & PHP_HTTP_URL_STRIP_QUERY)) {
if ((flags & PHP_HTTP_URL_JOIN_QUERY) && url_isset(new_url, query) && url_isset(old_url, query)) {
zval qarr, qstr;
-
+
array_init(&qarr);
-
+
ZVAL_STRING(&qstr, old_url->query);
php_http_querystring_update(&qarr, &qstr, NULL);
zval_ptr_dtor(&qstr);
ZVAL_STRING(&qstr, new_url->query);
php_http_querystring_update(&qarr, &qstr, NULL);
zval_ptr_dtor(&qstr);
-
+
ZVAL_NULL(&qstr);
php_http_querystring_update(&qarr, NULL, &qstr);
if (!(flags & PHP_HTTP_URL_STRIP_FRAGMENT)) {
url_copy(fragment);
}
-
+
/* done with copy & combine & strip */
if (flags & PHP_HTTP_URL_FROM_ENV) {
&& url(buf)->path
&& url(buf)->path[0] && url(buf)->path[1]) {
char *ptr, *end = url(buf)->path + strlen(url(buf)->path) + 1;
-
+
for (ptr = strchr(url(buf)->path, '/'); ptr; ptr = strchr(ptr, '/')) {
switch (ptr[1]) {
case '/':
memmove(&ptr[1], &ptr[2], end - &ptr[2]);
break;
-
+
case '.':
switch (ptr[2]) {
case '\0':
url(buf)->port = 0;
}
}
-
+
return url(buf);
}
state->maxlen = maxlen;
if (!parse_scheme(state)) {
- php_error_docref(NULL, E_WARNING, "Failed to parse URL scheme: '%s'", state->ptr);
+ if (!(flags & PHP_HTTP_URL_SILENT_ERRORS)) {
+ php_error_docref(NULL, E_WARNING, "Failed to parse URL scheme: '%s'", state->ptr);
+ }
efree(state);
return NULL;
}
}
if (!parse_query(state)) {
- php_error_docref(NULL, E_WARNING, "Failed to parse URL query: '%s'", state->ptr);
+ if (!(flags & PHP_HTTP_URL_SILENT_ERRORS)) {
+ php_error_docref(NULL, E_WARNING, "Failed to parse URL query: '%s'", state->ptr);
+ }
efree(state);
return NULL;
}
if (!parse_fragment(state)) {
- php_error_docref(NULL, E_WARNING, "Failed to parse URL fragment: '%s'", state->ptr);
+ if (!(flags & PHP_HTTP_URL_SILENT_ERRORS)) {
+ php_error_docref(NULL, E_WARNING, "Failed to parse URL fragment: '%s'", state->ptr);
+ }
efree(state);
return NULL;
}
flags |= PHP_HTTP_URL_FROM_ENV;
}
- if (flags & PHP_HTTP_URL_SILENT_ERRORS) {
- zend_replace_error_handling(EH_SUPPRESS, NULL, &zeh);
- } else if (flags & PHP_HTTP_URL_IGNORE_ERRORS) {
+ if (flags & (PHP_HTTP_URL_SILENT_ERRORS|PHP_HTTP_URL_IGNORE_ERRORS)) {
zend_replace_error_handling(EH_NORMAL, NULL, &zeh);
} else {
zend_replace_error_handling(EH_THROW, php_http_get_exception_bad_url_class_entry(), &zeh);
php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "z!|l", &new_url, &flags), invalid_arg, return);
- if (flags & PHP_HTTP_URL_SILENT_ERRORS) {
- zend_replace_error_handling(EH_SUPPRESS, NULL, &zeh);
- } else if (flags & PHP_HTTP_URL_IGNORE_ERRORS) {
+ if (flags & (PHP_HTTP_URL_SILENT_ERRORS|PHP_HTTP_URL_IGNORE_ERRORS)) {
zend_replace_error_handling(EH_NORMAL, NULL, &zeh);
} else {
zend_replace_error_handling(EH_THROW, php_http_get_exception_bad_url_class_entry(), &zeh);