summaryrefslogtreecommitdiff
path: root/main/streams/streams.c
diff options
context:
space:
mode:
Diffstat (limited to 'main/streams/streams.c')
-rw-r--r--main/streams/streams.c63
1 files changed, 30 insertions, 33 deletions
diff --git a/main/streams/streams.c b/main/streams/streams.c
index 19d08c7978..4df6c60e0b 100644
--- a/main/streams/streams.c
+++ b/main/streams/streams.c
@@ -121,12 +121,12 @@ PHPAPI int php_stream_from_persistent_id(const char *persistent_id, php_stream *
*stream = (php_stream*)le->ptr;
ZEND_HASH_FOREACH_PTR(&EG(regular_list), regentry) {
if (regentry->ptr == le->ptr) {
- GC_REFCOUNT(regentry)++;
+ GC_ADDREF(regentry);
(*stream)->res = regentry;
return PHP_STREAM_PERSISTENT_SUCCESS;
}
} ZEND_HASH_FOREACH_END();
- GC_REFCOUNT(le)++;
+ GC_ADDREF(le);
(*stream)->res = zend_register_resource(*stream, le_pstream);
}
return PHP_STREAM_PERSISTENT_SUCCESS;
@@ -230,7 +230,7 @@ static void wrapper_list_dtor(zval *item) {
efree(list);
}
-PHPAPI void php_stream_wrapper_log_error(php_stream_wrapper *wrapper, int options, const char *fmt, ...)
+PHPAPI void php_stream_wrapper_log_error(const php_stream_wrapper *wrapper, int options, const char *fmt, ...)
{
va_list args;
char *buffer = NULL;
@@ -267,7 +267,7 @@ PHPAPI void php_stream_wrapper_log_error(php_stream_wrapper *wrapper, int option
/* }}} */
/* allocate a new stream for a particular ops */
-PHPAPI php_stream *_php_stream_alloc(php_stream_ops *ops, void *abstract, const char *persistent_id, const char *mode STREAMS_DC) /* {{{ */
+PHPAPI php_stream *_php_stream_alloc(const php_stream_ops *ops, void *abstract, const char *persistent_id, const char *mode STREAMS_DC) /* {{{ */
{
php_stream *ret;
@@ -297,12 +297,7 @@ fprintf(stderr, "stream_alloc: %s:%p persistent=%s\n", ops->label, ret, persiste
}
if (persistent_id) {
- zval tmp;
-
- ZVAL_NEW_PERSISTENT_RES(&tmp, -1, ret, le_pstream);
-
- if (NULL == zend_hash_str_update(&EG(persistent_list), persistent_id,
- strlen(persistent_id), &tmp)) {
+ if (NULL == zend_register_persistent_resource(persistent_id, strlen(persistent_id), ret, le_pstream)) {
pefree(ret, 1);
return NULL;
}
@@ -1670,15 +1665,20 @@ static inline int php_stream_wrapper_scheme_validate(const char *protocol, unsig
}
/* API for registering GLOBAL wrappers */
-PHPAPI int php_register_url_stream_wrapper(const char *protocol, php_stream_wrapper *wrapper)
+PHPAPI int php_register_url_stream_wrapper(const char *protocol, const php_stream_wrapper *wrapper)
{
unsigned int protocol_len = (unsigned int)strlen(protocol);
+ int ret;
+ zend_string *str;
if (php_stream_wrapper_scheme_validate(protocol, protocol_len) == FAILURE) {
return FAILURE;
}
- return zend_hash_add_ptr(&url_stream_wrappers_hash, zend_string_init_interned(protocol, protocol_len, 1), wrapper) ? SUCCESS : FAILURE;
+ str = zend_string_init_interned(protocol, protocol_len, 1);
+ ret = zend_hash_add_ptr(&url_stream_wrappers_hash, str, (void*)wrapper) ? SUCCESS : FAILURE;
+ zend_string_release(str);
+ return ret;
}
PHPAPI int php_unregister_url_stream_wrapper(const char *protocol)
@@ -1689,16 +1689,14 @@ PHPAPI int php_unregister_url_stream_wrapper(const char *protocol)
static void clone_wrapper_hash(void)
{
ALLOC_HASHTABLE(FG(stream_wrappers));
- zend_hash_init(FG(stream_wrappers), zend_hash_num_elements(&url_stream_wrappers_hash), NULL, NULL, 1);
+ zend_hash_init(FG(stream_wrappers), zend_hash_num_elements(&url_stream_wrappers_hash), NULL, NULL, 0);
zend_hash_copy(FG(stream_wrappers), &url_stream_wrappers_hash, NULL);
}
/* API for registering VOLATILE wrappers */
-PHPAPI int php_register_url_stream_wrapper_volatile(const char *protocol, php_stream_wrapper *wrapper)
+PHPAPI int php_register_url_stream_wrapper_volatile(zend_string *protocol, php_stream_wrapper *wrapper)
{
- unsigned int protocol_len = (unsigned int)strlen(protocol);
-
- if (php_stream_wrapper_scheme_validate(protocol, protocol_len) == FAILURE) {
+ if (php_stream_wrapper_scheme_validate(ZSTR_VAL(protocol), ZSTR_LEN(protocol)) == FAILURE) {
return FAILURE;
}
@@ -1706,16 +1704,16 @@ PHPAPI int php_register_url_stream_wrapper_volatile(const char *protocol, php_st
clone_wrapper_hash();
}
- return zend_hash_str_add_ptr(FG(stream_wrappers), protocol, protocol_len, wrapper) ? SUCCESS : FAILURE;
+ return zend_hash_add_ptr(FG(stream_wrappers), protocol, wrapper) ? SUCCESS : FAILURE;
}
-PHPAPI int php_unregister_url_stream_wrapper_volatile(const char *protocol)
+PHPAPI int php_unregister_url_stream_wrapper_volatile(zend_string *protocol)
{
if (!FG(stream_wrappers)) {
clone_wrapper_hash();
}
- return zend_hash_str_del(FG(stream_wrappers), protocol, strlen(protocol));
+ return zend_hash_del(FG(stream_wrappers), protocol);
}
/* }}} */
@@ -1732,7 +1730,7 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const
}
if (options & IGNORE_URL) {
- return (options & STREAM_LOCATE_WRAPPERS_ONLY) ? NULL : &php_plain_files_wrapper;
+ return (php_stream_wrapper*)((options & STREAM_LOCATE_WRAPPERS_ONLY) ? NULL : &php_plain_files_wrapper);
}
for (p = path; isalnum((int)*p) || *p == '+' || *p == '-' || *p == '.'; p++) {
@@ -1744,10 +1742,11 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const
}
if (protocol) {
- char *tmp = estrndup(protocol, n);
- if (NULL == (wrapper = zend_hash_str_find_ptr(wrapper_hash, (char*)tmp, n))) {
+ if (NULL == (wrapper = zend_hash_str_find_ptr(wrapper_hash, protocol, n))) {
+ char *tmp = estrndup(protocol, n);
+
php_strtolower(tmp, n);
- if (NULL == (wrapper = zend_hash_str_find_ptr(wrapper_hash, (char*)tmp, n))) {
+ if (NULL == (wrapper = zend_hash_str_find_ptr(wrapper_hash, tmp, n))) {
char wrapper_name[32];
if (n >= sizeof(wrapper_name)) {
@@ -1760,13 +1759,13 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const
wrapper = NULL;
protocol = NULL;
}
+ efree(tmp);
}
- efree(tmp);
}
/* TODO: curl based streams probably support file:// properly */
if (!protocol || !strncasecmp(protocol, "file", n)) {
/* fall back on regular file access */
- php_stream_wrapper *plain_files_wrapper = &php_plain_files_wrapper;
+ php_stream_wrapper *plain_files_wrapper = (php_stream_wrapper*)&php_plain_files_wrapper;
if (protocol) {
int localhost = 0;
@@ -1815,7 +1814,7 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const
}
/* Check again, the original check might have not known the protocol name */
- if ((wrapper = zend_hash_str_find_ptr(wrapper_hash, "file", sizeof("file")-1)) != NULL) {
+ if ((wrapper = zend_hash_find_ex_ptr(wrapper_hash, ZSTR_KNOWN(ZEND_STR_FILE), 1)) != NULL) {
return wrapper;
}
@@ -1835,13 +1834,11 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const
PG(in_user_include)) && !PG(allow_url_include)))) {
if (options & REPORT_ERRORS) {
/* protocol[n] probably isn't '\0' */
- char *protocol_dup = estrndup(protocol, n);
if (!PG(allow_url_fopen)) {
- php_error_docref(NULL, E_WARNING, "%s:// wrapper is disabled in the server configuration by allow_url_fopen=0", protocol_dup);
+ php_error_docref(NULL, E_WARNING, "%.*s:// wrapper is disabled in the server configuration by allow_url_fopen=0", (int)n, protocol);
} else {
- php_error_docref(NULL, E_WARNING, "%s:// wrapper is disabled in the server configuration by allow_url_include=0", protocol_dup);
+ php_error_docref(NULL, E_WARNING, "%.*s:// wrapper is disabled in the server configuration by allow_url_include=0", (int)n, protocol);
}
- efree(protocol_dup);
}
return NULL;
}
@@ -1999,7 +1996,7 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod
}
if (options & USE_PATH) {
- resolved_path = zend_resolve_path(path, (int)strlen(path));
+ resolved_path = zend_resolve_path(path, strlen(path));
if (resolved_path) {
path = ZSTR_VAL(resolved_path);
/* we've found this file, don't re-check include_path or run realpath */
@@ -2130,7 +2127,7 @@ PHPAPI php_stream_context *php_stream_context_set(php_stream *stream, php_stream
if (context) {
stream->ctx = context->res;
- GC_REFCOUNT(context->res)++;
+ GC_ADDREF(context->res);
} else {
stream->ctx = NULL;
}