summaryrefslogtreecommitdiff
path: root/main/streams
diff options
context:
space:
mode:
Diffstat (limited to 'main/streams')
-rw-r--r--main/streams/cast.c53
-rw-r--r--main/streams/filter.c144
-rw-r--r--main/streams/glob_wrapper.c32
-rw-r--r--main/streams/memory.c150
-rw-r--r--main/streams/mmap.c14
-rw-r--r--main/streams/php_stream_context.h40
-rw-r--r--main/streams/php_stream_filter_api.h72
-rw-r--r--main/streams/php_stream_glob_wrapper.h16
-rw-r--r--main/streams/php_stream_mmap.h24
-rw-r--r--main/streams/php_stream_plain_wrapper.h36
-rw-r--r--main/streams/php_stream_transport.h74
-rw-r--r--main/streams/php_stream_userspace.h4
-rw-r--r--main/streams/php_streams_int.h10
-rw-r--r--main/streams/plain_wrapper.c314
-rw-r--r--main/streams/streams.c590
-rw-r--r--main/streams/transports.c149
-rw-r--r--main/streams/userspace.c936
-rw-r--r--main/streams/xp_socket.c231
18 files changed, 1410 insertions, 1479 deletions
diff --git a/main/streams/cast.c b/main/streams/cast.c
index e8956100cd..1bdcd91e34 100644
--- a/main/streams/cast.c
+++ b/main/streams/cast.c
@@ -1,8 +1,8 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2015 The PHP Group |
+ | Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -63,7 +63,6 @@ FILE *fopencookie(void *cookie, const char *mode, COOKIE_IO_FUNCTIONS_T *funcs)
static int stream_cookie_reader(void *cookie, char *buffer, int size)
{
int ret;
- TSRMLS_FETCH();
ret = php_stream_read((php_stream*)cookie, buffer, size);
return ret;
@@ -71,14 +70,12 @@ static int stream_cookie_reader(void *cookie, char *buffer, int size)
static int stream_cookie_writer(void *cookie, const char *buffer, int size)
{
- TSRMLS_FETCH();
return php_stream_write((php_stream *)cookie, (char *)buffer, size);
}
-static PHP_FPOS_T stream_cookie_seeker(void *cookie, off_t position, int whence)
+static PHP_FPOS_T stream_cookie_seeker(void *cookie, zend_off_t position, int whence)
{
- TSRMLS_FETCH();
return (PHP_FPOS_T)php_stream_seek((php_stream *)cookie, position, whence);
}
@@ -86,7 +83,6 @@ static PHP_FPOS_T stream_cookie_seeker(void *cookie, off_t position, int whence)
static int stream_cookie_closer(void *cookie)
{
php_stream *stream = (php_stream*)cookie;
- TSRMLS_FETCH();
/* prevent recursion */
stream->fclose_stdiocast = PHP_STREAM_FCLOSE_NONE;
@@ -96,7 +92,6 @@ static int stream_cookie_closer(void *cookie)
static ssize_t stream_cookie_reader(void *cookie, char *buffer, size_t size)
{
ssize_t ret;
- TSRMLS_FETCH();
ret = php_stream_read(((php_stream *)cookie), buffer, size);
return ret;
@@ -104,7 +99,6 @@ static ssize_t stream_cookie_reader(void *cookie, char *buffer, size_t size)
static ssize_t stream_cookie_writer(void *cookie, const char *buffer, size_t size)
{
- TSRMLS_FETCH();
return php_stream_write(((php_stream *)cookie), (char *)buffer, size);
}
@@ -112,9 +106,8 @@ static ssize_t stream_cookie_writer(void *cookie, const char *buffer, size_t siz
# ifdef COOKIE_SEEKER_USES_OFF64_T
static int stream_cookie_seeker(void *cookie, __off64_t *position, int whence)
{
- TSRMLS_FETCH();
- *position = php_stream_seek((php_stream *)cookie, (off_t)*position, whence);
+ *position = php_stream_seek((php_stream *)cookie, (zend_off_t)*position, whence);
if (*position == -1) {
return -1;
@@ -122,9 +115,8 @@ static int stream_cookie_seeker(void *cookie, __off64_t *position, int whence)
return 0;
}
# else
-static int stream_cookie_seeker(void *cookie, off_t position, int whence)
+static int stream_cookie_seeker(void *cookie, zend_off_t position, int whence)
{
- TSRMLS_FETCH();
return php_stream_seek((php_stream *)cookie, position, whence);
}
@@ -133,7 +125,6 @@ static int stream_cookie_seeker(void *cookie, off_t position, int whence)
static int stream_cookie_closer(void *cookie)
{
php_stream *stream = (php_stream*)cookie;
- TSRMLS_FETCH();
/* prevent recursion */
stream->fclose_stdiocast = PHP_STREAM_FCLOSE_NONE;
@@ -156,7 +147,7 @@ static COOKIE_IO_FUNCTIONS_T stream_cookie_functions =
* Result should have at least size 5, e.g. to write wbx+\0 */
void php_stream_mode_sanitize_fdopen_fopencookie(php_stream *stream, char *result)
{
- /* replace modes not supported by fdopen and fopencookie, but supported
+ /* replace modes not supported by fdopen and fopencookie, but supported
* by PHP's fread(), so that their calls won't fail */
const char *cur_mode = stream->mode;
int has_plus = 0,
@@ -174,7 +165,7 @@ void php_stream_mode_sanitize_fdopen_fopencookie(php_stream *stream, char *resul
/* x is allowed (at least by glibc & compat), but not as the 1st mode
* as in PHP and in any case is (at best) ignored by fdopen and fopencookie */
}
-
+
/* assume current mode has at most length 4 (e.g. wbn+) */
for (i = 1; i < 4 && cur_mode[i] != '\0'; i++) {
if (cur_mode[i] == 'b') {
@@ -197,7 +188,7 @@ void php_stream_mode_sanitize_fdopen_fopencookie(php_stream *stream, char *resul
/* }}} */
/* {{{ php_stream_cast */
-PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show_err TSRMLS_DC)
+PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show_err)
{
int flags = castas & PHP_STREAM_CAST_MASK;
castas &= ~PHP_STREAM_CAST_MASK;
@@ -206,9 +197,9 @@ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show
if (ret && castas != PHP_STREAM_AS_FD_FOR_SELECT) {
php_stream_flush(stream);
if (stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0) {
- off_t dummy;
+ zend_off_t dummy;
- stream->ops->seek(stream, stream->position, SEEK_SET, &dummy TSRMLS_CC);
+ stream->ops->seek(stream, stream->position, SEEK_SET, &dummy);
stream->readpos = stream->writepos = 0;
}
}
@@ -228,7 +219,7 @@ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show
if (php_stream_is(stream, PHP_STREAM_IS_STDIO) &&
stream->ops->cast &&
!php_stream_is_filtered(stream) &&
- stream->ops->cast(stream, castas, ret TSRMLS_CC) == SUCCESS
+ stream->ops->cast(stream, castas, ret) == SUCCESS
) {
goto exit_success;
}
@@ -246,7 +237,7 @@ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show
}
if (*ret != NULL) {
- off_t pos;
+ zend_off_t pos;
stream->fclose_stdiocast = PHP_STREAM_FCLOSE_FOPENCOOKIE;
@@ -254,7 +245,7 @@ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show
* the stdio layer to believe it's real location. */
pos = php_stream_tell(stream);
if (pos > 0) {
- fseek(*ret, pos, SEEK_SET);
+ zend_fseek(*ret, pos, SEEK_SET);
}
goto exit_success;
@@ -265,12 +256,12 @@ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show
b) no memory
-> lets bail
*/
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "fopencookie failed");
+ php_error_docref(NULL, E_ERROR, "fopencookie failed");
return FAILURE;
#endif
- if (!php_stream_is_filtered(stream) && stream->ops->cast && stream->ops->cast(stream, castas, NULL TSRMLS_CC) == SUCCESS) {
- if (FAILURE == stream->ops->cast(stream, castas, ret TSRMLS_CC)) {
+ if (!php_stream_is_filtered(stream) && stream->ops->cast && stream->ops->cast(stream, castas, NULL) == SUCCESS) {
+ if (FAILURE == stream->ops->cast(stream, castas, ret)) {
return FAILURE;
}
goto exit_success;
@@ -304,9 +295,9 @@ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show
}
if (php_stream_is_filtered(stream)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot cast a filtered stream on this system");
+ php_error_docref(NULL, E_WARNING, "cannot cast a filtered stream on this system");
return FAILURE;
- } else if (stream->ops->cast && stream->ops->cast(stream, castas, ret TSRMLS_CC) == SUCCESS) {
+ } else if (stream->ops->cast && stream->ops->cast(stream, castas, ret) == SUCCESS) {
goto exit_success;
}
@@ -319,7 +310,7 @@ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show
"select()able descriptor"
};
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot represent a stream of type %s as a %s", stream->ops->label, cast_names[castas]);
+ php_error_docref(NULL, E_WARNING, "cannot represent a stream of type %s as a %s", stream->ops->label, cast_names[castas]);
}
return FAILURE;
@@ -334,7 +325,7 @@ exit_success:
* will be accessing the stream. Emit a warning so that the end-user will
* know that they should try something else */
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%ld bytes of buffered data lost during stream conversion!", (long)(stream->writepos - stream->readpos));
+ php_error_docref(NULL, E_WARNING, ZEND_LONG_FMT " bytes of buffered data lost during stream conversion!", (zend_long)(stream->writepos - stream->readpos));
}
if (castas == PHP_STREAM_AS_STDIO && ret) {
@@ -351,7 +342,7 @@ exit_success:
/* }}} */
/* {{{ php_stream_open_wrapper_as_file */
-PHPAPI FILE * _php_stream_open_wrapper_as_file(char *path, char *mode, int options, char **opened_path STREAMS_DC TSRMLS_DC)
+PHPAPI FILE * _php_stream_open_wrapper_as_file(char *path, char *mode, int options, char **opened_path STREAMS_DC)
{
FILE *fp = NULL;
php_stream *stream = NULL;
@@ -374,7 +365,7 @@ PHPAPI FILE * _php_stream_open_wrapper_as_file(char *path, char *mode, int optio
/* }}} */
/* {{{ php_stream_make_seekable */
-PHPAPI int _php_stream_make_seekable(php_stream *origstream, php_stream **newstream, int flags STREAMS_DC TSRMLS_DC)
+PHPAPI int _php_stream_make_seekable(php_stream *origstream, php_stream **newstream, int flags STREAMS_DC)
{
if (newstream == NULL) {
return PHP_STREAM_FAILED;
diff --git a/main/streams/filter.c b/main/streams/filter.c
index fa29c0f6e2..67a6caa8d2 100644
--- a/main/streams/filter.c
+++ b/main/streams/filter.c
@@ -1,8 +1,8 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2015 The PHP Group |
+ | Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -38,39 +38,37 @@ PHPAPI HashTable *php_get_stream_filters_hash_global(void)
}
/* Normal hash selection/retrieval call */
-PHPAPI HashTable *_php_get_stream_filters_hash(TSRMLS_D)
+PHPAPI HashTable *_php_get_stream_filters_hash(void)
{
return (FG(stream_filters) ? FG(stream_filters) : &stream_filters_hash);
}
/* API for registering GLOBAL filters */
-PHPAPI int php_stream_filter_register_factory(const char *filterpattern, php_stream_filter_factory *factory TSRMLS_DC)
+PHPAPI int php_stream_filter_register_factory(const char *filterpattern, php_stream_filter_factory *factory)
{
- return zend_hash_add(&stream_filters_hash, (char*)filterpattern, strlen(filterpattern) + 1, factory, sizeof(*factory), NULL);
+ return zend_hash_str_add_ptr(&stream_filters_hash, filterpattern, strlen(filterpattern), factory) ? SUCCESS : FAILURE;
}
-PHPAPI int php_stream_filter_unregister_factory(const char *filterpattern TSRMLS_DC)
+PHPAPI int php_stream_filter_unregister_factory(const char *filterpattern)
{
- return zend_hash_del(&stream_filters_hash, (char*)filterpattern, strlen(filterpattern) + 1);
+ return zend_hash_str_del(&stream_filters_hash, filterpattern, strlen(filterpattern));
}
/* API for registering VOLATILE wrappers */
-PHPAPI int php_stream_filter_register_factory_volatile(const char *filterpattern, php_stream_filter_factory *factory TSRMLS_DC)
+PHPAPI int php_stream_filter_register_factory_volatile(const char *filterpattern, php_stream_filter_factory *factory)
{
if (!FG(stream_filters)) {
- php_stream_filter_factory tmpfactory;
-
ALLOC_HASHTABLE(FG(stream_filters));
zend_hash_init(FG(stream_filters), zend_hash_num_elements(&stream_filters_hash), NULL, NULL, 1);
- zend_hash_copy(FG(stream_filters), &stream_filters_hash, NULL, &tmpfactory, sizeof(php_stream_filter_factory));
+ zend_hash_copy(FG(stream_filters), &stream_filters_hash, NULL);
}
- return zend_hash_add(FG(stream_filters), (char*)filterpattern, strlen(filterpattern) + 1, factory, sizeof(*factory), NULL);
+ return zend_hash_str_add_ptr(FG(stream_filters), (char*)filterpattern, strlen(filterpattern), factory) ? SUCCESS : FAILURE;
}
/* Buckets */
-PHPAPI php_stream_bucket *php_stream_bucket_new(php_stream *stream, char *buf, size_t buflen, int own_buf, int buf_persistent TSRMLS_DC)
+PHPAPI php_stream_bucket *php_stream_bucket_new(php_stream *stream, char *buf, size_t buflen, int own_buf, int buf_persistent)
{
int is_persistent = php_stream_is_persistent(stream);
php_stream_bucket *bucket;
@@ -80,18 +78,18 @@ PHPAPI php_stream_bucket *php_stream_bucket_new(php_stream *stream, char *buf, s
if (bucket == NULL) {
return NULL;
}
-
+
bucket->next = bucket->prev = NULL;
if (is_persistent && !buf_persistent) {
/* all data in a persistent bucket must also be persistent */
bucket->buf = pemalloc(buflen, 1);
-
+
if (bucket->buf == NULL) {
pefree(bucket, 1);
return NULL;
}
-
+
memcpy(bucket->buf, buf, buflen);
bucket->buflen = buflen;
bucket->own_buf = 1;
@@ -114,12 +112,12 @@ PHPAPI php_stream_bucket *php_stream_bucket_new(php_stream *stream, char *buf, s
* In both cases, the original bucket is unlinked from its brigade.
* If a copy is made, the original bucket is delref'd.
* */
-PHPAPI php_stream_bucket *php_stream_bucket_make_writeable(php_stream_bucket *bucket TSRMLS_DC)
+PHPAPI php_stream_bucket *php_stream_bucket_make_writeable(php_stream_bucket *bucket)
{
php_stream_bucket *retval;
- php_stream_bucket_unlink(bucket TSRMLS_CC);
-
+ php_stream_bucket_unlink(bucket);
+
if (bucket->refcount == 1 && bucket->own_buf) {
return bucket;
}
@@ -133,12 +131,12 @@ PHPAPI php_stream_bucket *php_stream_bucket_make_writeable(php_stream_bucket *bu
retval->refcount = 1;
retval->own_buf = 1;
- php_stream_bucket_delref(bucket TSRMLS_CC);
-
+ php_stream_bucket_delref(bucket);
+
return retval;
}
-PHPAPI int php_stream_bucket_split(php_stream_bucket *in, php_stream_bucket **left, php_stream_bucket **right, size_t length TSRMLS_DC)
+PHPAPI int php_stream_bucket_split(php_stream_bucket *in, php_stream_bucket **left, php_stream_bucket **right, size_t length)
{
*left = (php_stream_bucket*)pecalloc(1, sizeof(php_stream_bucket), in->is_persistent);
*right = (php_stream_bucket*)pecalloc(1, sizeof(php_stream_bucket), in->is_persistent);
@@ -153,16 +151,16 @@ PHPAPI int php_stream_bucket_split(php_stream_bucket *in, php_stream_bucket **le
(*left)->refcount = 1;
(*left)->own_buf = 1;
(*left)->is_persistent = in->is_persistent;
-
+
(*right)->buflen = in->buflen - length;
(*right)->buf = pemalloc((*right)->buflen, in->is_persistent);
memcpy((*right)->buf, in->buf + length, (*right)->buflen);
(*right)->refcount = 1;
(*right)->own_buf = 1;
(*right)->is_persistent = in->is_persistent;
-
+
return SUCCESS;
-
+
exit_fail:
if (*right) {
if ((*right)->buf) {
@@ -179,7 +177,7 @@ exit_fail:
return FAILURE;
}
-PHPAPI void php_stream_bucket_delref(php_stream_bucket *bucket TSRMLS_DC)
+PHPAPI void php_stream_bucket_delref(php_stream_bucket *bucket)
{
if (--bucket->refcount == 0) {
if (bucket->own_buf) {
@@ -189,7 +187,7 @@ PHPAPI void php_stream_bucket_delref(php_stream_bucket *bucket TSRMLS_DC)
}
}
-PHPAPI void php_stream_bucket_prepend(php_stream_bucket_brigade *brigade, php_stream_bucket *bucket TSRMLS_DC)
+PHPAPI void php_stream_bucket_prepend(php_stream_bucket_brigade *brigade, php_stream_bucket *bucket)
{
bucket->next = brigade->head;
bucket->prev = NULL;
@@ -203,7 +201,7 @@ PHPAPI void php_stream_bucket_prepend(php_stream_bucket_brigade *brigade, php_st
bucket->brigade = brigade;
}
-PHPAPI void php_stream_bucket_append(php_stream_bucket_brigade *brigade, php_stream_bucket *bucket TSRMLS_DC)
+PHPAPI void php_stream_bucket_append(php_stream_bucket_brigade *brigade, php_stream_bucket *bucket)
{
if (brigade->tail == bucket) {
return;
@@ -221,7 +219,7 @@ PHPAPI void php_stream_bucket_append(php_stream_bucket_brigade *brigade, php_str
bucket->brigade = brigade;
}
-PHPAPI void php_stream_bucket_unlink(php_stream_bucket *bucket TSRMLS_DC)
+PHPAPI void php_stream_bucket_unlink(php_stream_bucket *bucket)
{
if (bucket->prev) {
bucket->prev->next = bucket->next;
@@ -236,7 +234,7 @@ PHPAPI void php_stream_bucket_unlink(php_stream_bucket *bucket TSRMLS_DC)
bucket->brigade = NULL;
bucket->next = bucket->prev = NULL;
}
-
+
@@ -249,7 +247,7 @@ PHPAPI void php_stream_bucket_unlink(php_stream_bucket *bucket TSRMLS_DC)
* match. If that fails, we try "convert.charset.*", then "convert.*"
* This means that we don't need to clog up the hashtable with a zillion
* charsets (for example) but still be able to provide them all as filters */
-PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval *filterparams, int persistent TSRMLS_DC)
+PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval *filterparams, int persistent)
{
HashTable *filter_hash = (FG(stream_filters) ? FG(stream_filters) : &stream_filters_hash);
php_stream_filter_factory *factory = NULL;
@@ -257,10 +255,10 @@ PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval
int n;
char *period;
- n = strlen(filtername);
-
- if (SUCCESS == zend_hash_find(filter_hash, (char*)filtername, n + 1, (void**)&factory)) {
- filter = factory->create_filter(filtername, filterparams, persistent TSRMLS_CC);
+ n = (int)strlen(filtername);
+
+ if (NULL != (factory = zend_hash_str_find_ptr(filter_hash, filtername, n))) {
+ filter = factory->create_filter(filtername, filterparams, persistent);
} else if ((period = strrchr(filtername, '.'))) {
/* try a wildcard */
char *wildname;
@@ -271,8 +269,8 @@ PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval
while (period && !filter) {
*period = '\0';
strncat(wildname, ".*", 2);
- if (SUCCESS == zend_hash_find(filter_hash, wildname, strlen(wildname) + 1, (void**)&factory)) {
- filter = factory->create_filter(filtername, filterparams, persistent TSRMLS_CC);
+ if (NULL != (factory = zend_hash_str_find_ptr(filter_hash, wildname, strlen(wildname)))) {
+ filter = factory->create_filter(filtername, filterparams, persistent);
}
*period = '\0';
@@ -284,15 +282,15 @@ PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval
if (filter == NULL) {
/* TODO: these need correct docrefs */
if (factory == NULL)
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to locate filter \"%s\"", filtername);
+ php_error_docref(NULL, E_WARNING, "unable to locate filter \"%s\"", filtername);
else
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to create or locate filter \"%s\"", filtername);
+ php_error_docref(NULL, E_WARNING, "unable to create or locate filter \"%s\"", filtername);
}
-
+
return filter;
}
-PHPAPI php_stream_filter *_php_stream_filter_alloc(php_stream_filter_ops *fops, void *abstract, int persistent STREAMS_DC TSRMLS_DC)
+PHPAPI php_stream_filter *_php_stream_filter_alloc(php_stream_filter_ops *fops, void *abstract, int persistent STREAMS_DC)
{
php_stream_filter *filter;
@@ -300,20 +298,20 @@ PHPAPI php_stream_filter *_php_stream_filter_alloc(php_stream_filter_ops *fops,
memset(filter, 0, sizeof(php_stream_filter));
filter->fops = fops;
- filter->abstract = abstract;
+ Z_PTR(filter->abstract) = abstract;
filter->is_persistent = persistent;
-
+
return filter;
}
-PHPAPI void php_stream_filter_free(php_stream_filter *filter TSRMLS_DC)
+PHPAPI void php_stream_filter_free(php_stream_filter *filter)
{
if (filter->fops->dtor)
- filter->fops->dtor(filter TSRMLS_CC);
+ filter->fops->dtor(filter);
pefree(filter, filter->is_persistent);
}
-PHPAPI int php_stream_filter_prepend_ex(php_stream_filter_chain *chain, php_stream_filter *filter TSRMLS_DC)
+PHPAPI int php_stream_filter_prepend_ex(php_stream_filter_chain *chain, php_stream_filter *filter)
{
filter->next = chain->head;
filter->prev = NULL;
@@ -329,12 +327,12 @@ PHPAPI int php_stream_filter_prepend_ex(php_stream_filter_chain *chain, php_stre
return SUCCESS;
}
-PHPAPI void _php_stream_filter_prepend(php_stream_filter_chain *chain, php_stream_filter *filter TSRMLS_DC)
+PHPAPI void _php_stream_filter_prepend(php_stream_filter_chain *chain, php_stream_filter *filter)
{
- php_stream_filter_prepend_ex(chain, filter TSRMLS_CC);
+ php_stream_filter_prepend_ex(chain, filter);
}
-PHPAPI int php_stream_filter_append_ex(php_stream_filter_chain *chain, php_stream_filter *filter TSRMLS_DC)
+PHPAPI int php_stream_filter_append_ex(php_stream_filter_chain *chain, php_stream_filter *filter)
{
php_stream *stream = chain->stream;
@@ -356,9 +354,9 @@ PHPAPI int php_stream_filter_append_ex(php_stream_filter_chain *chain, php_strea
php_stream_bucket *bucket;
size_t consumed = 0;
- bucket = php_stream_bucket_new(stream, (char*) stream->readbuf + stream->readpos, stream->writepos - stream->readpos, 0, 0 TSRMLS_CC);
- php_stream_bucket_append(brig_inp, bucket TSRMLS_CC);
- status = filter->fops->filter(stream, filter, brig_inp, brig_outp, &consumed, PSFS_FLAG_NORMAL TSRMLS_CC);
+ bucket = php_stream_bucket_new(stream, (char*) stream->readbuf + stream->readpos, stream->writepos - stream->readpos, 0, 0);
+ php_stream_bucket_append(brig_inp, bucket);
+ status = filter->fops->filter(stream, filter, brig_inp, brig_outp, &consumed, PSFS_FLAG_NORMAL);
if (stream->readpos + consumed > (uint)stream->writepos) {
/* No behaving filter should cause this. */
@@ -369,19 +367,19 @@ PHPAPI int php_stream_filter_append_ex(php_stream_filter_chain *chain, php_strea
case PSFS_ERR_FATAL:
while (brig_in.head) {
bucket = brig_in.head;
- php_stream_bucket_unlink(bucket TSRMLS_CC);
- php_stream_bucket_delref(bucket TSRMLS_CC);
+ php_stream_bucket_unlink(bucket);
+ php_stream_bucket_delref(bucket);
}
while (brig_out.head) {
bucket = brig_out.head;
- php_stream_bucket_unlink(bucket TSRMLS_CC);
- php_stream_bucket_delref(bucket TSRMLS_CC);
+ php_stream_bucket_unlink(bucket);
+ php_stream_bucket_delref(bucket);
}
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Filter failed to process pre-buffered data");
+ php_error_docref(NULL, E_WARNING, "Filter failed to process pre-buffered data");
return FAILURE;
case PSFS_FEED_ME:
/* We don't actually need data yet,
- leave this filter in a feed me state until data is needed.
+ leave this filter in a feed me state until data is needed.
Reset stream's internal read buffer since the filter is "holding" it. */
stream->readpos = 0;
stream->writepos = 0;
@@ -405,8 +403,8 @@ PHPAPI int php_stream_filter_append_ex(php_stream_filter_chain *chain, php_strea
memcpy(stream->readbuf + stream->writepos, bucket->buf, bucket->buflen);
stream->writepos += bucket->buflen;
- php_stream_bucket_unlink(bucket TSRMLS_CC);
- php_stream_bucket_delref(bucket TSRMLS_CC);
+ php_stream_bucket_unlink(bucket);
+ php_stream_bucket_delref(bucket);
}
break;
}
@@ -415,9 +413,9 @@ PHPAPI int php_stream_filter_append_ex(php_stream_filter_chain *chain, php_strea
return SUCCESS;
}
-PHPAPI void _php_stream_filter_append(php_stream_filter_chain *chain, php_stream_filter *filter TSRMLS_DC)
+PHPAPI void _php_stream_filter_append(php_stream_filter_chain *chain, php_stream_filter *filter)
{
- if (php_stream_filter_append_ex(chain, filter TSRMLS_CC) != SUCCESS) {
+ if (php_stream_filter_append_ex(chain, filter) != SUCCESS) {
if (chain->head == filter) {
chain->head = NULL;
chain->tail = NULL;
@@ -428,7 +426,7 @@ PHPAPI void _php_stream_filter_append(php_stream_filter_chain *chain, php_stream
}
}
-PHPAPI int _php_stream_filter_flush(php_stream_filter *filter, int finish TSRMLS_DC)
+PHPAPI int _php_stream_filter_flush(php_stream_filter *filter, int finish)
{
php_stream_bucket_brigade brig_a = { NULL, NULL }, brig_b = { NULL, NULL }, *inp = &brig_a, *outp = &brig_b, *brig_temp;
php_stream_bucket *bucket;
@@ -449,7 +447,7 @@ PHPAPI int _php_stream_filter_flush(php_stream_filter *filter, int finish TSRMLS
for(current = filter; current; current = current->next) {
php_stream_filter_status_t status;
- status = filter->fops->filter(stream, filter, inp, outp, NULL, flags TSRMLS_CC);
+ status = filter->fops->filter(stream, filter, inp, outp, NULL, flags);
if (status == PSFS_FEED_ME) {
/* We've flushed the data far enough */
return SUCCESS;
@@ -495,22 +493,22 @@ PHPAPI int _php_stream_filter_flush(php_stream_filter *filter, int finish TSRMLS
while ((bucket = inp->head)) {
memcpy(stream->readbuf + stream->writepos, bucket->buf, bucket->buflen);
stream->writepos += bucket->buflen;
- php_stream_bucket_unlink(bucket TSRMLS_CC);
- php_stream_bucket_delref(bucket TSRMLS_CC);
+ php_stream_bucket_unlink(bucket);
+ php_stream_bucket_delref(bucket);
}
} else if (chain == &(stream->writefilters)) {
/* Send flushed data to the stream */
while ((bucket = inp->head)) {
- stream->ops->write(stream, bucket->buf, bucket->buflen TSRMLS_CC);
- php_stream_bucket_unlink(bucket TSRMLS_CC);
- php_stream_bucket_delref(bucket TSRMLS_CC);
+ stream->ops->write(stream, bucket->buf, bucket->buflen);
+ php_stream_bucket_unlink(bucket);
+ php_stream_bucket_delref(bucket);
}
}
return SUCCESS;
}
-PHPAPI php_stream_filter *php_stream_filter_remove(php_stream_filter *filter, int call_dtor TSRMLS_DC)
+PHPAPI php_stream_filter *php_stream_filter_remove(php_stream_filter *filter, int call_dtor)
{
if (filter->prev) {
filter->prev->next = filter->next;
@@ -523,12 +521,12 @@ PHPAPI php_stream_filter *php_stream_filter_remove(php_stream_filter *filter, in
filter->chain->tail = filter->prev;
}
- if (filter->rsrc_id > 0) {
- zend_list_delete(filter->rsrc_id);
+ if (filter->res) {
+ zend_list_delete(filter->res);
}
if (call_dtor) {
- php_stream_filter_free(filter TSRMLS_CC);
+ php_stream_filter_free(filter);
return NULL;
}
return filter;
diff --git a/main/streams/glob_wrapper.c b/main/streams/glob_wrapper.c
index c4f9eb0781..f13db43ccb 100644
--- a/main/streams/glob_wrapper.c
+++ b/main/streams/glob_wrapper.c
@@ -1,8 +1,8 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2015 The PHP Group |
+ | Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -47,7 +47,7 @@ typedef struct {
size_t pattern_len;
} glob_s_t;
-PHPAPI char* _php_glob_stream_get_path(php_stream *stream, int copy, int *plen STREAMS_DC TSRMLS_DC) /* {{{ */
+PHPAPI char* _php_glob_stream_get_path(php_stream *stream, int copy, size_t *plen STREAMS_DC) /* {{{ */
{
glob_s_t *pglob = (glob_s_t *)stream->abstract;
@@ -69,10 +69,10 @@ PHPAPI char* _php_glob_stream_get_path(php_stream *stream, int copy, int *plen S
}
/* }}} */
-PHPAPI char* _php_glob_stream_get_pattern(php_stream *stream, int copy, int *plen STREAMS_DC TSRMLS_DC) /* {{{ */
+PHPAPI char* _php_glob_stream_get_pattern(php_stream *stream, int copy, size_t *plen STREAMS_DC) /* {{{ */
{
glob_s_t *pglob = (glob_s_t *)stream->abstract;
-
+
if (pglob && pglob->pattern) {
if (plen) {
*plen = pglob->pattern_len;
@@ -91,7 +91,7 @@ PHPAPI char* _php_glob_stream_get_pattern(php_stream *stream, int copy, int *ple
}
/* }}} */
-PHPAPI int _php_glob_stream_get_count(php_stream *stream, int *pflags STREAMS_DC TSRMLS_DC) /* {{{ */
+PHPAPI int _php_glob_stream_get_count(php_stream *stream, int *pflags STREAMS_DC) /* {{{ */
{
glob_s_t *pglob = (glob_s_t *)stream->abstract;
@@ -109,7 +109,7 @@ PHPAPI int _php_glob_stream_get_count(php_stream *stream, int *pflags STREAMS_DC
}
/* }}} */
-static void php_glob_stream_path_split(glob_s_t *pglob, const char *path, int get_path, const char **p_file TSRMLS_DC) /* {{{ */
+static void php_glob_stream_path_split(glob_s_t *pglob, const char *path, int get_path, const char **p_file) /* {{{ */
{
const char *pos, *gpath = path;
@@ -137,7 +137,7 @@ static void php_glob_stream_path_split(glob_s_t *pglob, const char *path, int ge
}
/* }}} */
-static size_t php_glob_stream_read(php_stream *stream, char *buf, size_t count TSRMLS_DC) /* {{{ */
+static size_t php_glob_stream_read(php_stream *stream, char *buf, size_t count) /* {{{ */
{
glob_s_t *pglob = (glob_s_t *)stream->abstract;
php_stream_dirent *ent = (php_stream_dirent*)buf;
@@ -146,7 +146,7 @@ static size_t php_glob_stream_read(php_stream *stream, char *buf, size_t count T
/* avoid problems if someone mis-uses the stream */
if (count == sizeof(php_stream_dirent) && pglob) {
if (pglob->index < (size_t)pglob->glob.gl_pathc) {
- php_glob_stream_path_split(pglob, pglob->glob.gl_pathv[pglob->index++], pglob->flags & GLOB_APPEND, &path TSRMLS_CC);
+ php_glob_stream_path_split(pglob, pglob->glob.gl_pathv[pglob->index++], pglob->flags & GLOB_APPEND, &path);
PHP_STRLCPY(ent->d_name, path, sizeof(ent->d_name), strlen(path));
return sizeof(php_stream_dirent);
}
@@ -161,7 +161,7 @@ static size_t php_glob_stream_read(php_stream *stream, char *buf, size_t count T
}
/* }}} */
-static int php_glob_stream_close(php_stream *stream, int close_handle TSRMLS_DC) /* {{{ */
+static int php_glob_stream_close(php_stream *stream, int close_handle) /* {{{ */
{
glob_s_t *pglob = (glob_s_t *)stream->abstract;
@@ -180,7 +180,7 @@ static int php_glob_stream_close(php_stream *stream, int close_handle TSRMLS_DC)
}
/* {{{ */
-static int php_glob_stream_rewind(php_stream *stream, off_t offset, int whence, off_t *newoffs TSRMLS_DC) /* {{{ */
+static int php_glob_stream_rewind(php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffs) /* {{{ */
{
glob_s_t *pglob = (glob_s_t *)stream->abstract;
@@ -207,13 +207,13 @@ php_stream_ops php_glob_stream_ops = {
/* {{{ php_glob_stream_opener */
static php_stream *php_glob_stream_opener(php_stream_wrapper *wrapper, const char *path, const char *mode,
- int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC)
+ int options, char **opened_path, php_stream_context *context STREAMS_DC)
{
glob_s_t *pglob;
int ret;
const char *tmp, *pos;
- if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(path TSRMLS_CC)) {
+ if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(path)) {
return NULL;
}
@@ -225,7 +225,7 @@ static php_stream *php_glob_stream_opener(php_stream_wrapper *wrapper, const cha
}
pglob = ecalloc(sizeof(*pglob), 1);
-
+
if (0 != (ret = glob(path, pglob->flags & GLOB_FLAGMASK, NULL, &pglob->glob))) {
#ifdef GLOB_NOMATCH
if (GLOB_NOMATCH != ret)
@@ -252,9 +252,9 @@ static php_stream *php_glob_stream_opener(php_stream_wrapper *wrapper, const cha
pglob->flags |= GLOB_APPEND;
if (pglob->glob.gl_pathc) {
- php_glob_stream_path_split(pglob, pglob->glob.gl_pathv[0], 1, &tmp TSRMLS_CC);
+ php_glob_stream_path_split(pglob, pglob->glob.gl_pathv[0], 1, &tmp);
} else {
- php_glob_stream_path_split(pglob, path, 1, &tmp TSRMLS_CC);
+ php_glob_stream_path_split(pglob, path, 1, &tmp);
}
return php_stream_alloc(&php_glob_stream_ops, pglob, 0, mode);
diff --git a/main/streams/memory.c b/main/streams/memory.c
index 1577ae5d60..6757f6ed41 100644
--- a/main/streams/memory.c
+++ b/main/streams/memory.c
@@ -1,8 +1,8 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2015 The PHP Group |
+ | Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -20,9 +20,9 @@
#define _GNU_SOURCE
#include "php.h"
+#include "ext/standard/base64.h"
PHPAPI int php_url_decode(char *str, int len);
-PHPAPI unsigned char *php_base64_decode(const unsigned char *str, int length, int *ret_length);
/* Memory streams use a dynamic memory buffer to emulate a stream.
* You can use php_stream_memory_open to create a readonly stream
@@ -46,7 +46,7 @@ typedef struct {
/* {{{ */
-static size_t php_stream_memory_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC)
+static size_t php_stream_memory_write(php_stream *stream, const char *buf, size_t count)
{
php_stream_memory_data *ms = (php_stream_memory_data*)stream->abstract;
assert(ms != NULL);
@@ -82,7 +82,7 @@ static size_t php_stream_memory_write(php_stream *stream, const char *buf, size_
/* {{{ */
-static size_t php_stream_memory_read(php_stream *stream, char *buf, size_t count TSRMLS_DC)
+static size_t php_stream_memory_read(php_stream *stream, char *buf, size_t count)
{
php_stream_memory_data *ms = (php_stream_memory_data*)stream->abstract;
assert(ms != NULL);
@@ -107,7 +107,7 @@ static size_t php_stream_memory_read(php_stream *stream, char *buf, size_t count
/* {{{ */
-static int php_stream_memory_close(php_stream *stream, int close_handle TSRMLS_DC)
+static int php_stream_memory_close(php_stream *stream, int close_handle)
{
php_stream_memory_data *ms = (php_stream_memory_data*)stream->abstract;
assert(ms != NULL);
@@ -122,7 +122,7 @@ static int php_stream_memory_close(php_stream *stream, int close_handle TSRMLS_D
/* {{{ */
-static int php_stream_memory_flush(php_stream *stream TSRMLS_DC)
+static int php_stream_memory_flush(php_stream *stream)
{
/* nothing to do here */
return 0;
@@ -131,7 +131,7 @@ static int php_stream_memory_flush(php_stream *stream TSRMLS_DC)
/* {{{ */
-static int php_stream_memory_seek(php_stream *stream, off_t offset, int whence, off_t *newoffs TSRMLS_DC)
+static int php_stream_memory_seek(php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffs)
{
php_stream_memory_data *ms = (php_stream_memory_data*)stream->abstract;
assert(ms != NULL);
@@ -195,13 +195,13 @@ static int php_stream_memory_seek(php_stream *stream, off_t offset, int whence,
/* }}} */
/* {{{ */
-static int php_stream_memory_cast(php_stream *stream, int castas, void **ret TSRMLS_DC)
+static int php_stream_memory_cast(php_stream *stream, int castas, void **ret)
{
return FAILURE;
}
/* }}} */
-static int php_stream_memory_stat(php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC) /* {{{ */
+static int php_stream_memory_stat(php_stream *stream, php_stream_statbuf *ssb) /* {{{ */
{
time_t timestamp = 0;
php_stream_memory_data *ms = (php_stream_memory_data*)stream->abstract;
@@ -209,7 +209,7 @@ static int php_stream_memory_stat(php_stream *stream, php_stream_statbuf *ssb TS
memset(ssb, 0, sizeof(php_stream_statbuf));
/* read-only across the board */
-
+
ssb->sb.st_mode = ms->mode & TEMP_STREAM_READONLY ? 0444 : 0666;
ssb->sb.st_size = ms->fsize;
@@ -244,11 +244,11 @@ static int php_stream_memory_stat(php_stream *stream, php_stream_statbuf *ssb TS
}
/* }}} */
-static int php_stream_memory_set_option(php_stream *stream, int option, int value, void *ptrparam TSRMLS_DC) /* {{{ */
+static int php_stream_memory_set_option(php_stream *stream, int option, int value, void *ptrparam) /* {{{ */
{
php_stream_memory_data *ms = (php_stream_memory_data*)stream->abstract;
size_t newsize;
-
+
switch(option) {
case PHP_STREAM_OPTION_TRUNCATE_API:
switch (value) {
@@ -277,7 +277,7 @@ static int php_stream_memory_set_option(php_stream *stream, int option, int valu
}
}
/* }}} */
-
+
PHPAPI php_stream_ops php_stream_memory_ops = {
php_stream_memory_write, php_stream_memory_read,
php_stream_memory_close, php_stream_memory_flush,
@@ -290,7 +290,7 @@ PHPAPI php_stream_ops php_stream_memory_ops = {
/* {{{ */
-PHPAPI php_stream *_php_stream_memory_create(int mode STREAMS_DC TSRMLS_DC)
+PHPAPI php_stream *_php_stream_memory_create(int mode STREAMS_DC)
{
php_stream_memory_data *self;
php_stream *stream;
@@ -301,7 +301,7 @@ PHPAPI php_stream *_php_stream_memory_create(int mode STREAMS_DC TSRMLS_DC)
self->fsize = 0;
self->smax = ~0u;
self->mode = mode;
-
+
stream = php_stream_alloc_rel(&php_stream_memory_ops, self, 0, mode & TEMP_STREAM_READONLY ? "rb" : "w+b");
stream->flags |= PHP_STREAM_FLAG_NO_BUFFER;
return stream;
@@ -310,14 +310,14 @@ PHPAPI php_stream *_php_stream_memory_create(int mode STREAMS_DC TSRMLS_DC)
/* {{{ */
-PHPAPI php_stream *_php_stream_memory_open(int mode, char *buf, size_t length STREAMS_DC TSRMLS_DC)
+PHPAPI php_stream *_php_stream_memory_open(int mode, char *buf, size_t length STREAMS_DC)
{
php_stream *stream;
php_stream_memory_data *ms;
if ((stream = php_stream_memory_create_rel(mode)) != NULL) {
ms = (php_stream_memory_data*)stream->abstract;
-
+
if (mode == TEMP_STREAM_READONLY || mode == TEMP_STREAM_TAKE_BUFFER) {
/* use the buffer directly */
ms->data = buf;
@@ -335,7 +335,7 @@ PHPAPI php_stream *_php_stream_memory_open(int mode, char *buf, size_t length ST
/* {{{ */
-PHPAPI char *_php_stream_memory_get_buffer(php_stream *stream, size_t *length STREAMS_DC TSRMLS_DC)
+PHPAPI char *_php_stream_memory_get_buffer(php_stream *stream, size_t *length STREAMS_DC)
{
php_stream_memory_data *ms = (php_stream_memory_data*)stream->abstract;
@@ -355,13 +355,13 @@ typedef struct {
php_stream *innerstream;
size_t smax;
int mode;
- zval* meta;
+ zval meta;
char* tmpdir;
} php_stream_temp_data;
/* {{{ */
-static size_t php_stream_temp_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC)
+static size_t php_stream_temp_write(php_stream *stream, const char *buf, size_t count)
{
php_stream_temp_data *ts = (php_stream_temp_data*)stream->abstract;
assert(ts != NULL);
@@ -387,7 +387,7 @@ static size_t php_stream_temp_write(php_stream *stream, const char *buf, size_t
/* {{{ */
-static size_t php_stream_temp_read(php_stream *stream, char *buf, size_t count TSRMLS_DC)
+static size_t php_stream_temp_read(php_stream *stream, char *buf, size_t count)
{
php_stream_temp_data *ts = (php_stream_temp_data*)stream->abstract;
size_t got;
@@ -397,18 +397,18 @@ static size_t php_stream_temp_read(php_stream *stream, char *buf, size_t count T
if (!ts->innerstream) {
return -1;
}
-
+
got = php_stream_read(ts->innerstream, buf, count);
-
+
stream->eof = ts->innerstream->eof;
-
+
return got;
}
/* }}} */
/* {{{ */
-static int php_stream_temp_close(php_stream *stream, int close_handle TSRMLS_DC)
+static int php_stream_temp_close(php_stream *stream, int close_handle)
{
php_stream_temp_data *ts = (php_stream_temp_data*)stream->abstract;
int ret;
@@ -420,10 +420,8 @@ static int php_stream_temp_close(php_stream *stream, int close_handle TSRMLS_DC)
} else {
ret = 0;
}
-
- if (ts->meta) {
- zval_ptr_dtor(&ts->meta);
- }
+
+ zval_ptr_dtor(&ts->meta);
if (ts->tmpdir) {
efree(ts->tmpdir);
@@ -437,7 +435,7 @@ static int php_stream_temp_close(php_stream *stream, int close_handle TSRMLS_DC)
/* {{{ */
-static int php_stream_temp_flush(php_stream *stream TSRMLS_DC)
+static int php_stream_temp_flush(php_stream *stream)
{
php_stream_temp_data *ts = (php_stream_temp_data*)stream->abstract;
assert(ts != NULL);
@@ -448,7 +446,7 @@ static int php_stream_temp_flush(php_stream *stream TSRMLS_DC)
/* {{{ */
-static int php_stream_temp_seek(php_stream *stream, off_t offset, int whence, off_t *newoffs TSRMLS_DC)
+static int php_stream_temp_seek(php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffs)
{
php_stream_temp_data *ts = (php_stream_temp_data*)stream->abstract;
int ret;
@@ -462,19 +460,19 @@ static int php_stream_temp_seek(php_stream *stream, off_t offset, int whence, of
ret = php_stream_seek(ts->innerstream, offset, whence);
*newoffs = php_stream_tell(ts->innerstream);
stream->eof = ts->innerstream->eof;
-
+
return ret;
}
/* }}} */
/* {{{ */
-static int php_stream_temp_cast(php_stream *stream, int castas, void **ret TSRMLS_DC)
+static int php_stream_temp_cast(php_stream *stream, int castas, void **ret)
{
php_stream_temp_data *ts = (php_stream_temp_data*)stream->abstract;
php_stream *file;
size_t memsize;
char *membuf;
- off_t pos;
+ zend_off_t pos;
assert(ts != NULL);
@@ -504,7 +502,7 @@ static int php_stream_temp_cast(php_stream *stream, int castas, void **ret TSRML
file = php_stream_fopen_tmpfile();
php_stream_write(file, membuf, memsize);
pos = php_stream_tell(ts->innerstream);
-
+
php_stream_free_enclosed(ts->innerstream, PHP_STREAM_FREE_CLOSE);
ts->innerstream = file;
php_stream_encloses(stream, ts->innerstream);
@@ -514,7 +512,7 @@ static int php_stream_temp_cast(php_stream *stream, int castas, void **ret TSRML
}
/* }}} */
-static int php_stream_temp_stat(php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC) /* {{{ */
+static int php_stream_temp_stat(php_stream *stream, php_stream_statbuf *ssb) /* {{{ */
{
php_stream_temp_data *ts = (php_stream_temp_data*)stream->abstract;
@@ -525,14 +523,14 @@ static int php_stream_temp_stat(php_stream *stream, php_stream_statbuf *ssb TSRM
}
/* }}} */
-static int php_stream_temp_set_option(php_stream *stream, int option, int value, void *ptrparam TSRMLS_DC) /* {{{ */
+static int php_stream_temp_set_option(php_stream *stream, int option, int value, void *ptrparam) /* {{{ */
{
php_stream_temp_data *ts = (php_stream_temp_data*)stream->abstract;
-
+
switch(option) {
case PHP_STREAM_OPTION_META_DATA_API:
- if (ts->meta) {
- zend_hash_copy(Z_ARRVAL_P((zval*)ptrparam), Z_ARRVAL_P(ts->meta), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval*));
+ if (Z_TYPE(ts->meta) != IS_UNDEF) {
+ zend_hash_copy(Z_ARRVAL_P((zval*)ptrparam), Z_ARRVAL(ts->meta), zval_add_ref);
}
return PHP_STREAM_OPTION_RETURN_OK;
default:
@@ -557,7 +555,7 @@ PHPAPI php_stream_ops php_stream_temp_ops = {
/* }}} */
/* {{{ _php_stream_temp_create_ex */
-PHPAPI php_stream *_php_stream_temp_create_ex(int mode, size_t max_memory_usage, const char *tmpdir STREAMS_DC TSRMLS_DC)
+PHPAPI php_stream *_php_stream_temp_create_ex(int mode, size_t max_memory_usage, const char *tmpdir STREAMS_DC)
{
php_stream_temp_data *self;
php_stream *stream;
@@ -565,6 +563,7 @@ PHPAPI php_stream *_php_stream_temp_create_ex(int mode, size_t max_memory_usage,
self = ecalloc(1, sizeof(*self));
self->smax = max_memory_usage;
self->mode = mode;
+ ZVAL_UNDEF(&self->meta);
if (tmpdir) {
self->tmpdir = estrdup(tmpdir);
}
@@ -578,24 +577,24 @@ PHPAPI php_stream *_php_stream_temp_create_ex(int mode, size_t max_memory_usage,
/* }}} */
/* {{{ _php_stream_temp_create */
-PHPAPI php_stream *_php_stream_temp_create(int mode, size_t max_memory_usage STREAMS_DC TSRMLS_DC)
+PHPAPI php_stream *_php_stream_temp_create(int mode, size_t max_memory_usage STREAMS_DC)
{
return php_stream_temp_create_ex(mode, max_memory_usage, NULL);
}
/* }}} */
/* {{{ _php_stream_temp_open */
-PHPAPI php_stream *_php_stream_temp_open(int mode, size_t max_memory_usage, char *buf, size_t length STREAMS_DC TSRMLS_DC)
+PHPAPI php_stream *_php_stream_temp_open(int mode, size_t max_memory_usage, char *buf, size_t length STREAMS_DC)
{
php_stream *stream;
php_stream_temp_data *ts;
- off_t newoffs;
+ zend_off_t newoffs;
if ((stream = php_stream_temp_create_rel(mode, max_memory_usage)) != NULL) {
if (length) {
assert(buf != NULL);
- php_stream_temp_write(stream, buf, length TSRMLS_CC);
- php_stream_temp_seek(stream, 0, SEEK_SET, &newoffs TSRMLS_CC);
+ php_stream_temp_write(stream, buf, length);
+ php_stream_temp_seek(stream, 0, SEEK_SET, &newoffs);
}
ts = (php_stream_temp_data*)stream->abstract;
assert(ts != NULL);
@@ -617,16 +616,18 @@ PHPAPI php_stream_ops php_stream_rfc2397_ops = {
static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, const char *path,
const char *mode, int options, char **opened_path,
- php_stream_context *context STREAMS_DC TSRMLS_DC) /* {{{ */
+ php_stream_context *context STREAMS_DC) /* {{{ */
{
php_stream *stream;
php_stream_temp_data *ts;
char *comma, *semi, *sep, *key;
size_t mlen, dlen, plen, vlen;
- off_t newoffs;
- zval *meta = NULL;
+ zend_off_t newoffs;
+ zval meta;
int base64 = 0, ilen;
+ zend_string *base64_comma = NULL;
+ ZVAL_NULL(&meta);
if (memcmp(path, "data:", 5)) {
return NULL;
}
@@ -640,7 +641,7 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, con
}
if ((comma = memchr(path, ',', dlen)) == NULL) {
- php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "rfc2397: no comma in URL");
+ php_stream_wrapper_log_error(wrapper, options, "rfc2397: no comma in URL");
return NULL;
}
@@ -650,25 +651,24 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, con
dlen -= mlen;
semi = memchr(path, ';', mlen);
sep = memchr(path, '/', mlen);
-
+
if (!semi && !sep) {
- php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "rfc2397: illegal media type");
+ php_stream_wrapper_log_error(wrapper, options, "rfc2397: illegal media type");
return NULL;
}
- MAKE_STD_ZVAL(meta);
- array_init(meta);
+ array_init(&meta);
if (!semi) { /* there is only a mime type */
- add_assoc_stringl(meta, "mediatype", (char *) path, mlen, 1);
+ add_assoc_stringl(&meta, "mediatype", (char *) path, mlen);
mlen = 0;
} else if (sep && sep < semi) { /* there is a mime type */
plen = semi - path;
- add_assoc_stringl(meta, "mediatype", (char *) path, plen, 1);
+ add_assoc_stringl(&meta, "mediatype", (char *) path, plen);
mlen -= plen;
path += plen;
} else if (semi != path || mlen != sizeof(";base64")-1 || memcmp(path, ";base64", sizeof(";base64")-1)) { /* must be error since parameters are only allowed after mediatype */
zval_ptr_dtor(&meta);
- php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "rfc2397: illegal media type");
+ php_stream_wrapper_log_error(wrapper, options, "rfc2397: illegal media type");
return NULL;
}
/* get parameters and potentially ';base64' */
@@ -681,7 +681,7 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, con
if (mlen != sizeof("base64")-1 || memcmp(path, "base64", sizeof("base64")-1)) {
/* must be error since parameters are only allowed after mediatype and we have no '=' sign */
zval_ptr_dtor(&meta);
- php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "rfc2397: illegal parameter");
+ php_stream_wrapper_log_error(wrapper, options, "rfc2397: illegal parameter");
return NULL;
}
base64 = 1;
@@ -693,7 +693,7 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, con
plen = sep - path;
vlen = (semi ? semi - sep : mlen - plen) - 1 /* '=' */;
key = estrndup(path, plen);
- add_assoc_stringl_ex(meta, key, plen + 1, sep + 1, vlen, 1);
+ add_assoc_stringl_ex(&meta, key, plen, sep + 1, vlen);
efree(key);
plen += vlen + 1;
mlen -= plen;
@@ -701,35 +701,37 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, con
}
if (mlen) {
zval_ptr_dtor(&meta);
- php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "rfc2397: illegal URL");
+ php_stream_wrapper_log_error(wrapper, options, "rfc2397: illegal URL");
return NULL;
}
} else {
- MAKE_STD_ZVAL(meta);
- array_init(meta);
+ array_init(&meta);
}
- add_assoc_bool(meta, "base64", base64);
+ add_assoc_bool(&meta, "base64", base64);
/* skip ',' */
comma++;
dlen--;
if (base64) {
- comma = (char*)php_base64_decode((const unsigned char *)comma, dlen, &ilen);
- if (!comma) {
+ base64_comma = php_base64_decode((const unsigned char *)comma, dlen);
+ if (!base64_comma) {
zval_ptr_dtor(&meta);
- php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "rfc2397: unable to decode");
+ php_stream_wrapper_log_error(wrapper, options, "rfc2397: unable to decode");
return NULL;
}
+ comma = base64_comma->val;
+ ilen = (int)base64_comma->len;
} else {
comma = estrndup(comma, dlen);
- ilen = dlen = php_url_decode(comma, dlen);
+ dlen = php_url_decode(comma, (int)dlen);
+ ilen = (int)dlen;
}
if ((stream = php_stream_temp_create_rel(0, ~0u)) != NULL) {
/* store data */
- php_stream_temp_write(stream, comma, ilen TSRMLS_CC);
- php_stream_temp_seek(stream, 0, SEEK_SET, &newoffs TSRMLS_CC);
+ php_stream_temp_write(stream, comma, ilen);
+ php_stream_temp_seek(stream, 0, SEEK_SET, &newoffs);
/* set special stream stuff (enforce exact mode) */
vlen = strlen(mode);
if (vlen >= sizeof(stream->mode)) {
@@ -741,9 +743,13 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, con
ts = (php_stream_temp_data*)stream->abstract;
assert(ts != NULL);
ts->mode = mode && mode[0] == 'r' && mode[1] != '+' ? TEMP_STREAM_READONLY : 0;
- ts->meta = meta;
+ ZVAL_COPY_VALUE(&ts->meta, &meta);
+ }
+ if (base64_comma) {
+ zend_string_free(base64_comma);
+ } else {
+ efree(comma);
}
- efree(comma);
return stream;
}
diff --git a/main/streams/mmap.c b/main/streams/mmap.c
index ee2b210f66..17e88554d8 100644
--- a/main/streams/mmap.c
+++ b/main/streams/mmap.c
@@ -1,8 +1,8 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2015 The PHP Group |
+ | Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -22,10 +22,10 @@
#include "php.h"
#include "php_streams_int.h"
-PHPAPI char *_php_stream_mmap_range(php_stream *stream, size_t offset, size_t length, php_stream_mmap_operation_t mode, size_t *mapped_len TSRMLS_DC)
+PHPAPI char *_php_stream_mmap_range(php_stream *stream, size_t offset, size_t length, php_stream_mmap_operation_t mode, size_t *mapped_len)
{
php_stream_mmap_range range;
-
+
range.offset = offset;
range.length = length;
range.mode = mode;
@@ -36,7 +36,7 @@ PHPAPI char *_php_stream_mmap_range(php_stream *stream, size_t offset, size_t le
if (length > 4 * 1024 * 1024) {
return NULL;
}
-
+
if (PHP_STREAM_OPTION_RETURN_OK == php_stream_set_option(stream, PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_MAP_RANGE, &range)) {
if (mapped_len) {
*mapped_len = range.length;
@@ -46,12 +46,12 @@ PHPAPI char *_php_stream_mmap_range(php_stream *stream, size_t offset, size_t le
return NULL;
}
-PHPAPI int _php_stream_mmap_unmap(php_stream *stream TSRMLS_DC)
+PHPAPI int _php_stream_mmap_unmap(php_stream *stream)
{
return php_stream_set_option(stream, PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_UNMAP, NULL) == PHP_STREAM_OPTION_RETURN_OK ? 1 : 0;
}
-PHPAPI int _php_stream_mmap_unmap_ex(php_stream *stream, off_t readden TSRMLS_DC)
+PHPAPI int _php_stream_mmap_unmap_ex(php_stream *stream, zend_off_t readden)
{
int ret = 1;
diff --git a/main/streams/php_stream_context.h b/main/streams/php_stream_context.h
index c31f1fa984..404e9bdbc3 100644
--- a/main/streams/php_stream_context.h
+++ b/main/streams/php_stream_context.h
@@ -1,8 +1,8 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2015 The PHP Group |
+ | Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -25,7 +25,7 @@ typedef void (*php_stream_notification_func)(php_stream_context *context,
int notifycode, int severity,
char *xmsg, int xcode,
size_t bytes_sofar, size_t bytes_max,
- void * ptr TSRMLS_DC);
+ void * ptr);
#define PHP_STREAM_NOTIFIER_PROGRESS 1
@@ -33,34 +33,34 @@ typedef void (*php_stream_notification_func)(php_stream_context *context,
If no context was passed, use the default context
The default context has not yet been created, do it now. */
#define php_stream_context_from_zval(zcontext, nocontext) ( \
- (zcontext) ? zend_fetch_resource(&(zcontext) TSRMLS_CC, -1, "Stream-Context", NULL, 1, php_le_stream_context(TSRMLS_C)) : \
+ (zcontext) ? zend_fetch_resource(zcontext, -1, "Stream-Context", NULL, 1, php_le_stream_context()) : \
(nocontext) ? NULL : \
FG(default_context) ? FG(default_context) : \
- (FG(default_context) = php_stream_context_alloc(TSRMLS_C)) )
+ (FG(default_context) = php_stream_context_alloc()) )
-#define php_stream_context_to_zval(context, zval) { ZVAL_RESOURCE(zval, (context)->rsrc_id); zend_list_addref((context)->rsrc_id); }
+#define php_stream_context_to_zval(context, zval) { ZVAL_RES(zval, (context)->res); GC_REFCOUNT((context)->res)++; }
typedef struct _php_stream_notifier php_stream_notifier;
struct _php_stream_notifier {
php_stream_notification_func func;
void (*dtor)(php_stream_notifier *notifier);
- void *ptr;
+ zval ptr;
int mask;
size_t progress, progress_max; /* position for progress notification */
};
struct _php_stream_context {
php_stream_notifier *notifier;
- zval *options; /* hash keyed by wrapper family or specific wrapper */
- int rsrc_id; /* used for auto-cleanup */
+ zval options; /* hash keyed by wrapper family or specific wrapper */
+ zend_resource *res; /* used for auto-cleanup */
};
BEGIN_EXTERN_C()
PHPAPI void php_stream_context_free(php_stream_context *context);
-PHPAPI php_stream_context *php_stream_context_alloc(TSRMLS_D);
-PHPAPI int php_stream_context_get_option(php_stream_context *context,
- const char *wrappername, const char *optionname, zval ***optionvalue);
+PHPAPI php_stream_context *php_stream_context_alloc(void);
+PHPAPI zval *php_stream_context_get_option(php_stream_context *context,
+ const char *wrappername, const char *optionname);
PHPAPI int php_stream_context_set_option(php_stream_context *context,
const char *wrappername, const char *optionname, zval *optionvalue);
@@ -86,17 +86,17 @@ END_EXTERN_C()
BEGIN_EXTERN_C()
PHPAPI void php_stream_notification_notify(php_stream_context *context, int notifycode, int severity,
- char *xmsg, int xcode, size_t bytes_sofar, size_t bytes_max, void * ptr TSRMLS_DC);
+ char *xmsg, int xcode, size_t bytes_sofar, size_t bytes_max, void * ptr);
PHPAPI php_stream_context *php_stream_context_set(php_stream *stream, php_stream_context *context);
END_EXTERN_C()
#define php_stream_notify_info(context, code, xmsg, xcode) do { if ((context) && (context)->notifier) { \
php_stream_notification_notify((context), (code), PHP_STREAM_NOTIFY_SEVERITY_INFO, \
- (xmsg), (xcode), 0, 0, NULL TSRMLS_CC); } } while (0)
-
+ (xmsg), (xcode), 0, 0, NULL); } } while (0)
+
#define php_stream_notify_progress(context, bsofar, bmax) do { if ((context) && (context)->notifier) { \
php_stream_notification_notify((context), PHP_STREAM_NOTIFY_PROGRESS, PHP_STREAM_NOTIFY_SEVERITY_INFO, \
- NULL, 0, (bsofar), (bmax), NULL TSRMLS_CC); } } while(0)
+ NULL, 0, (bsofar), (bmax), NULL); } } while(0)
#define php_stream_notify_progress_init(context, sofar, bmax) do { if ((context) && (context)->notifier) { \
(context)->notifier->progress = (sofar); \
@@ -111,12 +111,12 @@ END_EXTERN_C()
#define php_stream_notify_file_size(context, file_size, xmsg, xcode) do { if ((context) && (context)->notifier) { \
php_stream_notification_notify((context), PHP_STREAM_NOTIFY_FILE_SIZE_IS, PHP_STREAM_NOTIFY_SEVERITY_INFO, \
- (xmsg), (xcode), 0, (file_size), NULL TSRMLS_CC); } } while(0)
-
+ (xmsg), (xcode), 0, (file_size), NULL); } } while(0)
+
#define php_stream_notify_error(context, code, xmsg, xcode) do { if ((context) && (context)->notifier) {\
php_stream_notification_notify((context), (code), PHP_STREAM_NOTIFY_SEVERITY_ERR, \
- (xmsg), (xcode), 0, 0, NULL TSRMLS_CC); } } while(0)
-
+ (xmsg), (xcode), 0, 0, NULL); } } while(0)
+
/*
* Local variables:
diff --git a/main/streams/php_stream_filter_api.h b/main/streams/php_stream_filter_api.h
index 9e08b43cad..3c626fd59d 100644
--- a/main/streams/php_stream_filter_api.h
+++ b/main/streams/php_stream_filter_api.h
@@ -1,8 +1,8 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2015 The PHP Group |
+ | Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -26,7 +26,7 @@
* it is intentially a light-weight implementation.
*
* Each stream can have a chain of filters for reading and another for writing.
- *
+ *
* When data is written to the stream, it is placed into a bucket and placed at
* the start of the input brigade.
*
@@ -50,7 +50,7 @@ struct _php_stream_bucket {
/* if non-zero, buf should be pefreed when the bucket is destroyed */
int own_buf;
int is_persistent;
-
+
/* destroy this struct when refcount falls to zero */
int refcount;
};
@@ -67,14 +67,14 @@ typedef enum {
/* Buckets API. */
BEGIN_EXTERN_C()
-PHPAPI php_stream_bucket *php_stream_bucket_new(php_stream *stream, char *buf, size_t buflen, int own_buf, int buf_persistent TSRMLS_DC);
-PHPAPI int php_stream_bucket_split(php_stream_bucket *in, php_stream_bucket **left, php_stream_bucket **right, size_t length TSRMLS_DC);
-PHPAPI void php_stream_bucket_delref(php_stream_bucket *bucket TSRMLS_DC);
+PHPAPI php_stream_bucket *php_stream_bucket_new(php_stream *stream, char *buf, size_t buflen, int own_buf, int buf_persistent);
+PHPAPI int php_stream_bucket_split(php_stream_bucket *in, php_stream_bucket **left, php_stream_bucket **right, size_t length);
+PHPAPI void php_stream_bucket_delref(php_stream_bucket *bucket);
#define php_stream_bucket_addref(bucket) (bucket)->refcount++
-PHPAPI void php_stream_bucket_prepend(php_stream_bucket_brigade *brigade, php_stream_bucket *bucket TSRMLS_DC);
-PHPAPI void php_stream_bucket_append(php_stream_bucket_brigade *brigade, php_stream_bucket *bucket TSRMLS_DC);
-PHPAPI void php_stream_bucket_unlink(php_stream_bucket *bucket TSRMLS_DC);
-PHPAPI php_stream_bucket *php_stream_bucket_make_writeable(php_stream_bucket *bucket TSRMLS_DC);
+PHPAPI void php_stream_bucket_prepend(php_stream_bucket_brigade *brigade, php_stream_bucket *bucket);
+PHPAPI void php_stream_bucket_append(php_stream_bucket_brigade *brigade, php_stream_bucket *bucket);
+PHPAPI void php_stream_bucket_unlink(php_stream_bucket *bucket);
+PHPAPI php_stream_bucket *php_stream_bucket_make_writeable(php_stream_bucket *bucket);
END_EXTERN_C()
#define PSFS_FLAG_NORMAL 0 /* regular read/write */
@@ -90,12 +90,12 @@ typedef struct _php_stream_filter_ops {
php_stream_bucket_brigade *buckets_out,
size_t *bytes_consumed,
int flags
- TSRMLS_DC);
-
- void (*dtor)(php_stream_filter *thisfilter TSRMLS_DC);
-
+ );
+
+ void (*dtor)(php_stream_filter *thisfilter);
+
const char *label;
-
+
} php_stream_filter_ops;
typedef struct _php_stream_filter_chain {
@@ -107,7 +107,7 @@ typedef struct _php_stream_filter_chain {
struct _php_stream_filter {
php_stream_filter_ops *fops;
- void *abstract; /* for use by filter implementation */
+ zval abstract; /* for use by filter implementation */
php_stream_filter *next;
php_stream_filter *prev;
int is_persistent;
@@ -119,37 +119,37 @@ struct _php_stream_filter {
php_stream_bucket_brigade buffer;
/* filters are auto_registered when they're applied */
- int rsrc_id;
+ zend_resource *res;
};
/* stack filter onto a stream */
BEGIN_EXTERN_C()
-PHPAPI void _php_stream_filter_prepend(php_stream_filter_chain *chain, php_stream_filter *filter TSRMLS_DC);
-PHPAPI int php_stream_filter_prepend_ex(php_stream_filter_chain *chain, php_stream_filter *filter TSRMLS_DC);
-PHPAPI void _php_stream_filter_append(php_stream_filter_chain *chain, php_stream_filter *filter TSRMLS_DC);
-PHPAPI int php_stream_filter_append_ex(php_stream_filter_chain *chain, php_stream_filter *filter TSRMLS_DC);
-PHPAPI int _php_stream_filter_flush(php_stream_filter *filter, int finish TSRMLS_DC);
-PHPAPI php_stream_filter *php_stream_filter_remove(php_stream_filter *filter, int call_dtor TSRMLS_DC);
-PHPAPI void php_stream_filter_free(php_stream_filter *filter TSRMLS_DC);
-PHPAPI php_stream_filter *_php_stream_filter_alloc(php_stream_filter_ops *fops, void *abstract, int persistent STREAMS_DC TSRMLS_DC);
+PHPAPI void _php_stream_filter_prepend(php_stream_filter_chain *chain, php_stream_filter *filter);
+PHPAPI int php_stream_filter_prepend_ex(php_stream_filter_chain *chain, php_stream_filter *filter);
+PHPAPI void _php_stream_filter_append(php_stream_filter_chain *chain, php_stream_filter *filter);
+PHPAPI int php_stream_filter_append_ex(php_stream_filter_chain *chain, php_stream_filter *filter);
+PHPAPI int _php_stream_filter_flush(php_stream_filter *filter, int finish);
+PHPAPI php_stream_filter *php_stream_filter_remove(php_stream_filter *filter, int call_dtor);
+PHPAPI void php_stream_filter_free(php_stream_filter *filter);
+PHPAPI php_stream_filter *_php_stream_filter_alloc(php_stream_filter_ops *fops, void *abstract, int persistent STREAMS_DC);
END_EXTERN_C()
-#define php_stream_filter_alloc(fops, thisptr, persistent) _php_stream_filter_alloc((fops), (thisptr), (persistent) STREAMS_CC TSRMLS_CC)
-#define php_stream_filter_alloc_rel(fops, thisptr, persistent) _php_stream_filter_alloc((fops), (thisptr), (persistent) STREAMS_REL_CC TSRMLS_CC)
-#define php_stream_filter_prepend(chain, filter) _php_stream_filter_prepend((chain), (filter) TSRMLS_CC)
-#define php_stream_filter_append(chain, filter) _php_stream_filter_append((chain), (filter) TSRMLS_CC)
-#define php_stream_filter_flush(filter, finish) _php_stream_filter_flush((filter), (finish) TSRMLS_CC)
+#define php_stream_filter_alloc(fops, thisptr, persistent) _php_stream_filter_alloc((fops), (thisptr), (persistent) STREAMS_CC)
+#define php_stream_filter_alloc_rel(fops, thisptr, persistent) _php_stream_filter_alloc((fops), (thisptr), (persistent) STREAMS_REL_CC)
+#define php_stream_filter_prepend(chain, filter) _php_stream_filter_prepend((chain), (filter))
+#define php_stream_filter_append(chain, filter) _php_stream_filter_append((chain), (filter))
+#define php_stream_filter_flush(filter, finish) _php_stream_filter_flush((filter), (finish))
#define php_stream_is_filtered(stream) ((stream)->readfilters.head || (stream)->writefilters.head)
typedef struct _php_stream_filter_factory {
- php_stream_filter *(*create_filter)(const char *filtername, zval *filterparams, int persistent TSRMLS_DC);
+ php_stream_filter *(*create_filter)(const char *filtername, zval *filterparams, int persistent);
} php_stream_filter_factory;
BEGIN_EXTERN_C()
-PHPAPI int php_stream_filter_register_factory(const char *filterpattern, php_stream_filter_factory *factory TSRMLS_DC);
-PHPAPI int php_stream_filter_unregister_factory(const char *filterpattern TSRMLS_DC);
-PHPAPI int php_stream_filter_register_factory_volatile(const char *filterpattern, php_stream_filter_factory *factory TSRMLS_DC);
-PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval *filterparams, int persistent TSRMLS_DC);
+PHPAPI int php_stream_filter_register_factory(const char *filterpattern, php_stream_filter_factory *factory);
+PHPAPI int php_stream_filter_unregister_factory(const char *filterpattern);
+PHPAPI int php_stream_filter_register_factory_volatile(const char *filterpattern, php_stream_filter_factory *factory);
+PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval *filterparams, int persistent);
END_EXTERN_C()
/*
diff --git a/main/streams/php_stream_glob_wrapper.h b/main/streams/php_stream_glob_wrapper.h
index 691b3c4438..be93651fd1 100644
--- a/main/streams/php_stream_glob_wrapper.h
+++ b/main/streams/php_stream_glob_wrapper.h
@@ -1,8 +1,8 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2015 The PHP Group |
+ | Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -23,14 +23,14 @@ PHPAPI extern php_stream_ops php_glob_stream_ops;
BEGIN_EXTERN_C()
-PHPAPI char* _php_glob_stream_get_path(php_stream *stream, int copy, int *plen STREAMS_DC TSRMLS_DC);
-#define php_glob_stream_get_path(stream, copy, plen) _php_glob_stream_get_path((stream), (copy), (plen) STREAMS_CC TSRMLS_CC)
+PHPAPI char* _php_glob_stream_get_path(php_stream *stream, int copy, size_t *plen STREAMS_DC);
+#define php_glob_stream_get_path(stream, copy, plen) _php_glob_stream_get_path((stream), (copy), (plen) STREAMS_CC)
-PHPAPI char* _php_glob_stream_get_pattern(php_stream *stream, int copy, int *plen STREAMS_DC TSRMLS_DC);
-#define php_glob_stream_get_pattern(stream, copy, plen) _php_glob_stream_get_pattern((stream), (copy), (plen) STREAMS_CC TSRMLS_CC)
+PHPAPI char* _php_glob_stream_get_pattern(php_stream *stream, int copy, size_t *plen STREAMS_DC);
+#define php_glob_stream_get_pattern(stream, copy, plen) _php_glob_stream_get_pattern((stream), (copy), (plen) STREAMS_CC)
-PHPAPI int _php_glob_stream_get_count(php_stream *stream, int *pflags STREAMS_DC TSRMLS_DC);
-#define php_glob_stream_get_count(stream, pflags) _php_glob_stream_get_count((stream), (pflags) STREAMS_CC TSRMLS_CC)
+PHPAPI int _php_glob_stream_get_count(php_stream *stream, int *pflags STREAMS_DC);
+#define php_glob_stream_get_count(stream, pflags) _php_glob_stream_get_count((stream), (pflags) STREAMS_CC)
END_EXTERN_C()
diff --git a/main/streams/php_stream_mmap.h b/main/streams/php_stream_mmap.h
index e3ae0cb9f6..fa17325481 100644
--- a/main/streams/php_stream_mmap.h
+++ b/main/streams/php_stream_mmap.h
@@ -1,8 +1,8 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2015 The PHP Group |
+ | Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -37,7 +37,7 @@ typedef enum {
/* Unmap the last range that was mapped for the stream */
PHP_STREAM_MMAP_UNMAP
} php_stream_mmap_operation_t;
-
+
typedef enum {
PHP_STREAM_MAP_MODE_READONLY,
PHP_STREAM_MAP_MODE_READWRITE,
@@ -50,9 +50,9 @@ typedef struct {
* If length is 0, the whole file is mapped */
size_t offset;
size_t length;
-
+
php_stream_mmap_access_t mode;
-
+
/* returned mapped address */
char *mapped;
@@ -60,22 +60,22 @@ typedef struct {
#define PHP_STREAM_MMAP_ALL 0
-#define php_stream_mmap_supported(stream) (_php_stream_set_option((stream), PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_SUPPORTED, NULL TSRMLS_CC) == 0 ? 1 : 0)
+#define php_stream_mmap_supported(stream) (_php_stream_set_option((stream), PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_SUPPORTED, NULL) == 0 ? 1 : 0)
/* Returns 1 if the stream in its current state can be memory mapped,
* 0 otherwise */
#define php_stream_mmap_possible(stream) (!php_stream_is_filtered((stream)) && php_stream_mmap_supported((stream)))
BEGIN_EXTERN_C()
-PHPAPI char *_php_stream_mmap_range(php_stream *stream, size_t offset, size_t length, php_stream_mmap_operation_t mode, size_t *mapped_len TSRMLS_DC);
-#define php_stream_mmap_range(stream, offset, length, mode, mapped_len) _php_stream_mmap_range((stream), (offset), (length), (mode), (mapped_len) TSRMLS_CC)
+PHPAPI char *_php_stream_mmap_range(php_stream *stream, size_t offset, size_t length, php_stream_mmap_operation_t mode, size_t *mapped_len);
+#define php_stream_mmap_range(stream, offset, length, mode, mapped_len) _php_stream_mmap_range((stream), (offset), (length), (mode), (mapped_len))
/* un-maps the last mapped range */
-PHPAPI int _php_stream_mmap_unmap(php_stream *stream TSRMLS_DC);
-#define php_stream_mmap_unmap(stream) _php_stream_mmap_unmap((stream) TSRMLS_CC)
+PHPAPI int _php_stream_mmap_unmap(php_stream *stream);
+#define php_stream_mmap_unmap(stream) _php_stream_mmap_unmap((stream))
-PHPAPI int _php_stream_mmap_unmap_ex(php_stream *stream, off_t readden TSRMLS_DC);
-#define php_stream_mmap_unmap_ex(stream, readden) _php_stream_mmap_unmap_ex((stream), (readden) TSRMLS_CC)
+PHPAPI int _php_stream_mmap_unmap_ex(php_stream *stream, zend_off_t readden);
+#define php_stream_mmap_unmap_ex(stream, readden) _php_stream_mmap_unmap_ex((stream), (readden))
END_EXTERN_C()
/*
diff --git a/main/streams/php_stream_plain_wrapper.h b/main/streams/php_stream_plain_wrapper.h
index 040a1dca5d..d2bf50d189 100644
--- a/main/streams/php_stream_plain_wrapper.h
+++ b/main/streams/php_stream_plain_wrapper.h
@@ -1,8 +1,8 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2015 The PHP Group |
+ | Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -27,32 +27,32 @@ PHPAPI extern php_stream_wrapper php_plain_files_wrapper;
BEGIN_EXTERN_C()
/* like fopen, but returns a stream */
-PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, char **opened_path, int options STREAMS_DC TSRMLS_DC);
-#define php_stream_fopen(filename, mode, opened) _php_stream_fopen((filename), (mode), (opened), 0 STREAMS_CC TSRMLS_CC)
+PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, char **opened_path, int options STREAMS_DC);
+#define php_stream_fopen(filename, mode, opened) _php_stream_fopen((filename), (mode), (opened), 0 STREAMS_CC)
-PHPAPI php_stream *_php_stream_fopen_with_path(const char *filename, const char *mode, const char *path, char **opened_path, int options STREAMS_DC TSRMLS_DC);
-#define php_stream_fopen_with_path(filename, mode, path, opened) _php_stream_fopen_with_path((filename), (mode), (path), (opened), 0 STREAMS_CC TSRMLS_CC)
+PHPAPI php_stream *_php_stream_fopen_with_path(const char *filename, const char *mode, const char *path, char **opened_path, int options STREAMS_DC);
+#define php_stream_fopen_with_path(filename, mode, path, opened) _php_stream_fopen_with_path((filename), (mode), (path), (opened), 0 STREAMS_CC)
-PHPAPI php_stream *_php_stream_fopen_from_file(FILE *file, const char *mode STREAMS_DC TSRMLS_DC);
-#define php_stream_fopen_from_file(file, mode) _php_stream_fopen_from_file((file), (mode) STREAMS_CC TSRMLS_CC)
+PHPAPI php_stream *_php_stream_fopen_from_file(FILE *file, const char *mode STREAMS_DC);
+#define php_stream_fopen_from_file(file, mode) _php_stream_fopen_from_file((file), (mode) STREAMS_CC)
-PHPAPI php_stream *_php_stream_fopen_from_fd(int fd, const char *mode, const char *persistent_id STREAMS_DC TSRMLS_DC);
-#define php_stream_fopen_from_fd(fd, mode, persistent_id) _php_stream_fopen_from_fd((fd), (mode), (persistent_id) STREAMS_CC TSRMLS_CC)
+PHPAPI php_stream *_php_stream_fopen_from_fd(int fd, const char *mode, const char *persistent_id STREAMS_DC);
+#define php_stream_fopen_from_fd(fd, mode, persistent_id) _php_stream_fopen_from_fd((fd), (mode), (persistent_id) STREAMS_CC)
-PHPAPI php_stream *_php_stream_fopen_from_pipe(FILE *file, const char *mode STREAMS_DC TSRMLS_DC);
-#define php_stream_fopen_from_pipe(file, mode) _php_stream_fopen_from_pipe((file), (mode) STREAMS_CC TSRMLS_CC)
+PHPAPI php_stream *_php_stream_fopen_from_pipe(FILE *file, const char *mode STREAMS_DC);
+#define php_stream_fopen_from_pipe(file, mode) _php_stream_fopen_from_pipe((file), (mode) STREAMS_CC)
-PHPAPI php_stream *_php_stream_fopen_tmpfile(int dummy STREAMS_DC TSRMLS_DC);
-#define php_stream_fopen_tmpfile() _php_stream_fopen_tmpfile(0 STREAMS_CC TSRMLS_CC)
+PHPAPI php_stream *_php_stream_fopen_tmpfile(int dummy STREAMS_DC);
+#define php_stream_fopen_tmpfile() _php_stream_fopen_tmpfile(0 STREAMS_CC)
-PHPAPI php_stream *_php_stream_fopen_temporary_file(const char *dir, const char *pfx, char **opened_path STREAMS_DC TSRMLS_DC);
-#define php_stream_fopen_temporary_file(dir, pfx, opened_path) _php_stream_fopen_temporary_file((dir), (pfx), (opened_path) STREAMS_CC TSRMLS_CC)
+PHPAPI php_stream *_php_stream_fopen_temporary_file(const char *dir, const char *pfx, char **opened_path STREAMS_DC);
+#define php_stream_fopen_temporary_file(dir, pfx, opened_path) _php_stream_fopen_temporary_file((dir), (pfx), (opened_path) STREAMS_CC)
/* This is a utility API for extensions that are opening a stream, converting it
* to a FILE* and then closing it again. Be warned that fileno() on the result
* will most likely fail on systems with fopencookie. */
-PHPAPI FILE * _php_stream_open_wrapper_as_file(char * path, char * mode, int options, char **opened_path STREAMS_DC TSRMLS_DC);
-#define php_stream_open_wrapper_as_file(path, mode, options, opened_path) _php_stream_open_wrapper_as_file((path), (mode), (options), (opened_path) STREAMS_CC TSRMLS_CC)
+PHPAPI FILE * _php_stream_open_wrapper_as_file(char * path, char * mode, int options, char **opened_path STREAMS_DC);
+#define php_stream_open_wrapper_as_file(path, mode, options, opened_path) _php_stream_open_wrapper_as_file((path), (mode), (options), (opened_path) STREAMS_CC)
END_EXTERN_C()
diff --git a/main/streams/php_stream_transport.h b/main/streams/php_stream_transport.h
index 9147609822..7f587282f0 100644
--- a/main/streams/php_stream_transport.h
+++ b/main/streams/php_stream_transport.h
@@ -1,8 +1,8 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2015 The PHP Group |
+ | Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -30,12 +30,12 @@ typedef php_stream *(php_stream_transport_factory_func)(const char *proto, size_
const char *resourcename, size_t resourcenamelen,
const char *persistent_id, int options, int flags,
struct timeval *timeout,
- php_stream_context *context STREAMS_DC TSRMLS_DC);
+ php_stream_context *context STREAMS_DC);
typedef php_stream_transport_factory_func *php_stream_transport_factory;
BEGIN_EXTERN_C()
-PHPAPI int php_stream_xport_register(const char *protocol, php_stream_transport_factory factory TSRMLS_DC);
-PHPAPI int php_stream_xport_unregister(const char *protocol TSRMLS_DC);
+PHPAPI int php_stream_xport_register(const char *protocol, php_stream_transport_factory factory);
+PHPAPI int php_stream_xport_unregister(const char *protocol);
#define STREAM_XPORT_CLIENT 0
#define STREAM_XPORT_SERVER 1
@@ -50,48 +50,48 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, in
int flags, const char *persistent_id,
struct timeval *timeout,
php_stream_context *context,
- char **error_string,
+ zend_string **error_string,
int *error_code
- STREAMS_DC TSRMLS_DC);
+ STREAMS_DC);
#define php_stream_xport_create(name, namelen, options, flags, persistent_id, timeout, context, estr, ecode) \
- _php_stream_xport_create(name, namelen, options, flags, persistent_id, timeout, context, estr, ecode STREAMS_CC TSRMLS_CC)
+ _php_stream_xport_create(name, namelen, options, flags, persistent_id, timeout, context, estr, ecode STREAMS_CC)
/* Bind the stream to a local address */
PHPAPI int php_stream_xport_bind(php_stream *stream,
const char *name, size_t namelen,
- char **error_text
- TSRMLS_DC);
+ zend_string **error_text
+ );
/* Connect to a remote address */
PHPAPI int php_stream_xport_connect(php_stream *stream,
const char *name, size_t namelen,
int asynchronous,
struct timeval *timeout,
- char **error_text,
+ zend_string **error_text,
int *error_code
- TSRMLS_DC);
+ );
/* Prepare to listen */
PHPAPI int php_stream_xport_listen(php_stream *stream,
int backlog,
- char **error_text
- TSRMLS_DC);
+ zend_string **error_text
+ );
/* Get the next client and their address as a string, or the underlying address
* structure. You must efree either of these if you request them */
PHPAPI int php_stream_xport_accept(php_stream *stream, php_stream **client,
- char **textaddr, int *textaddrlen,
+ zend_string **textaddr,
void **addr, socklen_t *addrlen,
struct timeval *timeout,
- char **error_text
- TSRMLS_DC);
+ zend_string **error_text
+ );
/* Get the name of either the socket or it's peer */
PHPAPI int php_stream_xport_get_name(php_stream *stream, int want_peer,
- char **textaddr, int *textaddrlen,
+ zend_string **textaddr,
void **addr, socklen_t *addrlen
- TSRMLS_DC);
+ );
enum php_stream_xport_send_recv_flags {
STREAM_OOB = 1,
@@ -101,13 +101,13 @@ enum php_stream_xport_send_recv_flags {
/* Similar to recv() system call; read data from the stream, optionally
* peeking, optionally retrieving OOB data */
PHPAPI int php_stream_xport_recvfrom(php_stream *stream, char *buf, size_t buflen,
- long flags, void **addr, socklen_t *addrlen,
- char **textaddr, int *textaddrlen TSRMLS_DC);
+ int flags, void **addr, socklen_t *addrlen,
+ zend_string **textaddr);
/* Similar to send() system call; send data to the stream, optionally
* sending it as OOB data */
PHPAPI int php_stream_xport_sendto(php_stream *stream, const char *buf, size_t buflen,
- long flags, void *addr, socklen_t addrlen TSRMLS_DC);
+ int flags, void *addr, socklen_t addrlen);
typedef enum {
STREAM_SHUT_RD,
@@ -117,7 +117,7 @@ typedef enum {
/* Similar to shutdown() system call; shut down part of a full-duplex
* connection */
-PHPAPI int php_stream_xport_shutdown(php_stream *stream, stream_shutdown_t how TSRMLS_DC);
+PHPAPI int php_stream_xport_shutdown(php_stream *stream, stream_shutdown_t how);
END_EXTERN_C()
@@ -142,23 +142,21 @@ typedef struct _php_stream_xport_param {
struct {
char *name;
size_t namelen;
- int backlog;
struct timeval *timeout;
struct sockaddr *addr;
- socklen_t addrlen;
char *buf;
size_t buflen;
- long flags;
+ socklen_t addrlen;
+ int backlog;
+ int flags;
} inputs;
struct {
php_stream *client;
- int returncode;
struct sockaddr *addr;
socklen_t addrlen;
- char *textaddr;
- long textaddrlen;
-
- char *error_text;
+ zend_string *textaddr;
+ zend_string *error_text;
+ int returncode;
int error_code;
} outputs;
} php_stream_xport_param;
@@ -188,23 +186,23 @@ typedef enum {
/* These functions provide crypto support on the underlying transport */
BEGIN_EXTERN_C()
-PHPAPI int php_stream_xport_crypto_setup(php_stream *stream, php_stream_xport_crypt_method_t crypto_method, php_stream *session_stream TSRMLS_DC);
-PHPAPI int php_stream_xport_crypto_enable(php_stream *stream, int activate TSRMLS_DC);
+PHPAPI int php_stream_xport_crypto_setup(php_stream *stream, php_stream_xport_crypt_method_t crypto_method, php_stream *session_stream);
+PHPAPI int php_stream_xport_crypto_enable(php_stream *stream, int activate);
END_EXTERN_C()
typedef struct _php_stream_xport_crypto_param {
- enum {
- STREAM_XPORT_CRYPTO_OP_SETUP,
- STREAM_XPORT_CRYPTO_OP_ENABLE
- } op;
struct {
+ php_stream *session;
int activate;
php_stream_xport_crypt_method_t method;
- php_stream *session;
} inputs;
struct {
int returncode;
} outputs;
+ enum {
+ STREAM_XPORT_CRYPTO_OP_SETUP,
+ STREAM_XPORT_CRYPTO_OP_ENABLE
+ } op;
} php_stream_xport_crypto_param;
BEGIN_EXTERN_C()
diff --git a/main/streams/php_stream_userspace.h b/main/streams/php_stream_userspace.h
index 337b00512e..7a03690a8f 100644
--- a/main/streams/php_stream_userspace.h
+++ b/main/streams/php_stream_userspace.h
@@ -1,8 +1,8 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2015 The PHP Group |
+ | Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
diff --git a/main/streams/php_streams_int.h b/main/streams/php_streams_int.h
index cdecfccae1..d59f0287df 100644
--- a/main/streams/php_streams_int.h
+++ b/main/streams/php_streams_int.h
@@ -1,8 +1,8 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2015 The PHP Group |
+ | Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -49,7 +49,7 @@
#define CHUNK_SIZE 8192
#ifdef PHP_WIN32
-# ifdef EWOULDBLOCK
+# ifdef EWOULDBLOCK
# undef EWOULDBLOCK
# endif
# define EWOULDBLOCK WSAEWOULDBLOCK
@@ -66,6 +66,6 @@
* ones. result should be a char[5]. */
void php_stream_mode_sanitize_fdopen_fopencookie(php_stream *stream, char *result);
-void php_stream_tidy_wrapper_error_log(php_stream_wrapper *wrapper TSRMLS_DC);
-void php_stream_display_wrapper_errors(php_stream_wrapper *wrapper, const char *path, const char *caption TSRMLS_DC);
+void php_stream_tidy_wrapper_error_log(php_stream_wrapper *wrapper);
+void php_stream_display_wrapper_errors(php_stream_wrapper *wrapper, const char *path, const char *caption);
diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c
index cce0ac10e5..f52383dfbf 100644
--- a/main/streams/plain_wrapper.c
+++ b/main/streams/plain_wrapper.c
@@ -1,8 +1,8 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2015 The PHP Group |
+ | Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -44,14 +44,20 @@
# include "win32/time.h"
#endif
-#define php_stream_fopen_from_fd_int(fd, mode, persistent_id) _php_stream_fopen_from_fd_int((fd), (mode), (persistent_id) STREAMS_CC TSRMLS_CC)
-#define php_stream_fopen_from_fd_int_rel(fd, mode, persistent_id) _php_stream_fopen_from_fd_int((fd), (mode), (persistent_id) STREAMS_REL_CC TSRMLS_CC)
-#define php_stream_fopen_from_file_int(file, mode) _php_stream_fopen_from_file_int((file), (mode) STREAMS_CC TSRMLS_CC)
-#define php_stream_fopen_from_file_int_rel(file, mode) _php_stream_fopen_from_file_int((file), (mode) STREAMS_REL_CC TSRMLS_CC)
+#define php_stream_fopen_from_fd_int(fd, mode, persistent_id) _php_stream_fopen_from_fd_int((fd), (mode), (persistent_id) STREAMS_CC)
+#define php_stream_fopen_from_fd_int_rel(fd, mode, persistent_id) _php_stream_fopen_from_fd_int((fd), (mode), (persistent_id) STREAMS_REL_CC)
+#define php_stream_fopen_from_file_int(file, mode) _php_stream_fopen_from_file_int((file), (mode) STREAMS_CC)
+#define php_stream_fopen_from_file_int_rel(file, mode) _php_stream_fopen_from_file_int((file), (mode) STREAMS_REL_CC)
#if !defined(WINDOWS) && !defined(NETWARE)
-extern int php_get_uid_by_name(const char *name, uid_t *uid TSRMLS_DC);
-extern int php_get_gid_by_name(const char *name, gid_t *gid TSRMLS_DC);
+extern int php_get_uid_by_name(const char *name, uid_t *uid);
+extern int php_get_gid_by_name(const char *name, gid_t *gid);
+#endif
+
+#if defined(PHP_WIN32)
+# define PLAIN_WRAP_BUF_SIZE(st) (((st) > UINT_MAX) ? UINT_MAX : (unsigned int)(st))
+#else
+# define PLAIN_WRAP_BUF_SIZE(st) (st)
#endif
/* parse standard "fopen" modes into open() flags */
@@ -116,7 +122,7 @@ typedef struct {
unsigned is_pipe:1; /* don't try and seek */
unsigned cached_fstat:1; /* sb is valid */
unsigned _reserved:29;
-
+
int lock_flag; /* stores the lock state */
char *temp_file_name; /* if non-null, this is the path to a temporary file that
* is to be deleted when the stream is closed */
@@ -133,7 +139,7 @@ typedef struct {
HANDLE file_mapping;
#endif
- struct stat sb;
+ zend_stat_t sb;
} php_stdio_stream_data;
#define PHP_STDIOP_GET_FD(anfd, data) anfd = (data)->file ? fileno((data)->file) : (data)->fd
@@ -142,9 +148,9 @@ static int do_fstat(php_stdio_stream_data *d, int force)
if (!d->cached_fstat || force) {
int fd;
int r;
-
+
PHP_STDIOP_GET_FD(fd, d);
- r = fstat(fd, &d->sb);
+ r = zend_fstat(fd, &d->sb);
d->cached_fstat = r == 0;
return r;
@@ -152,10 +158,10 @@ static int do_fstat(php_stdio_stream_data *d, int force)
return 0;
}
-static php_stream *_php_stream_fopen_from_fd_int(int fd, const char *mode, const char *persistent_id STREAMS_DC TSRMLS_DC)
+static php_stream *_php_stream_fopen_from_fd_int(int fd, const char *mode, const char *persistent_id STREAMS_DC)
{
php_stdio_stream_data *self;
-
+
self = pemalloc_rel_orig(sizeof(*self), persistent_id);
memset(self, 0, sizeof(*self));
self->file = NULL;
@@ -164,14 +170,14 @@ static php_stream *_php_stream_fopen_from_fd_int(int fd, const char *mode, const
self->is_process_pipe = 0;
self->temp_file_name = NULL;
self->fd = fd;
-
+
return php_stream_alloc_rel(&php_stream_stdio_ops, self, persistent_id, mode);
}
-static php_stream *_php_stream_fopen_from_file_int(FILE *file, const char *mode STREAMS_DC TSRMLS_DC)
+static php_stream *_php_stream_fopen_from_file_int(FILE *file, const char *mode STREAMS_DC)
{
php_stdio_stream_data *self;
-
+
self = emalloc_rel_orig(sizeof(*self));
memset(self, 0, sizeof(*self));
self->file = file;
@@ -184,12 +190,12 @@ static php_stream *_php_stream_fopen_from_file_int(FILE *file, const char *mode
return php_stream_alloc_rel(&php_stream_stdio_ops, self, 0, mode);
}
-PHPAPI php_stream *_php_stream_fopen_temporary_file(const char *dir, const char *pfx, char **opened_path_ptr STREAMS_DC TSRMLS_DC)
+PHPAPI php_stream *_php_stream_fopen_temporary_file(const char *dir, const char *pfx, char **opened_path_ptr STREAMS_DC)
{
char *opened_path = NULL;
int fd;
- fd = php_open_temporary_fd(dir, pfx, &opened_path TSRMLS_CC);
+ fd = php_open_temporary_fd(dir, pfx, &opened_path);
if (fd != -1) {
php_stream *stream;
@@ -205,24 +211,24 @@ PHPAPI php_stream *_php_stream_fopen_temporary_file(const char *dir, const char
self->temp_file_name = opened_path;
self->lock_flag = LOCK_UN;
-
+
return stream;
}
close(fd);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to allocate stream");
+ php_error_docref(NULL, E_WARNING, "unable to allocate stream");
return NULL;
}
return NULL;
}
-PHPAPI php_stream *_php_stream_fopen_tmpfile(int dummy STREAMS_DC TSRMLS_DC)
+PHPAPI php_stream *_php_stream_fopen_tmpfile(int dummy STREAMS_DC)
{
return php_stream_fopen_temporary_file(NULL, "php", NULL);
}
-PHPAPI php_stream *_php_stream_fopen_from_fd(int fd, const char *mode, const char *persistent_id STREAMS_DC TSRMLS_DC)
+PHPAPI php_stream *_php_stream_fopen_from_fd(int fd, const char *mode, const char *persistent_id STREAMS_DC)
{
php_stream *stream = php_stream_fopen_from_fd_int_rel(fd, mode, persistent_id);
@@ -243,13 +249,13 @@ PHPAPI php_stream *_php_stream_fopen_from_fd(int fd, const char *mode, const cha
}
}
#endif
-
+
if (self->is_pipe) {
stream->flags |= PHP_STREAM_FLAG_NO_SEEK;
} else {
- stream->position = lseek(self->fd, 0, SEEK_CUR);
+ stream->position = zend_lseek(self->fd, 0, SEEK_CUR);
#ifdef ESPIPE
- if (stream->position == (off_t)-1 && errno == ESPIPE) {
+ if (stream->position == (zend_off_t)-1 && errno == ESPIPE) {
stream->position = 0;
stream->flags |= PHP_STREAM_FLAG_NO_SEEK;
self->is_pipe = 1;
@@ -261,7 +267,7 @@ PHPAPI php_stream *_php_stream_fopen_from_fd(int fd, const char *mode, const cha
return stream;
}
-PHPAPI php_stream *_php_stream_fopen_from_file(FILE *file, const char *mode STREAMS_DC TSRMLS_DC)
+PHPAPI php_stream *_php_stream_fopen_from_file(FILE *file, const char *mode STREAMS_DC)
{
php_stream *stream = php_stream_fopen_from_file_int_rel(file, mode);
@@ -282,18 +288,18 @@ PHPAPI php_stream *_php_stream_fopen_from_file(FILE *file, const char *mode STRE
}
}
#endif
-
+
if (self->is_pipe) {
stream->flags |= PHP_STREAM_FLAG_NO_SEEK;
} else {
- stream->position = ftell(file);
+ stream->position = zend_ftell(file);
}
}
return stream;
}
-PHPAPI php_stream *_php_stream_fopen_from_pipe(FILE *file, const char *mode STREAMS_DC TSRMLS_DC)
+PHPAPI php_stream *_php_stream_fopen_from_pipe(FILE *file, const char *mode STREAMS_DC)
{
php_stdio_stream_data *self;
php_stream *stream;
@@ -312,14 +318,18 @@ PHPAPI php_stream *_php_stream_fopen_from_pipe(FILE *file, const char *mode STRE
return stream;
}
-static size_t php_stdiop_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC)
+static size_t php_stdiop_write(php_stream *stream, const char *buf, size_t count)
{
php_stdio_stream_data *data = (php_stdio_stream_data*)stream->abstract;
assert(data != NULL);
if (data->fd >= 0) {
+#ifdef PHP_WIN32
+ int bytes_written = write(data->fd, buf, (unsigned int)count);
+#else
int bytes_written = write(data->fd, buf, count);
+#endif
if (bytes_written < 0) return 0;
return (size_t) bytes_written;
} else {
@@ -335,7 +345,7 @@ static size_t php_stdiop_write(php_stream *stream, const char *buf, size_t count
}
}
-static size_t php_stdiop_read(php_stream *stream, char *buf, size_t count TSRMLS_DC)
+static size_t php_stdiop_read(php_stream *stream, char *buf, size_t count)
{
php_stdio_stream_data *data = (php_stdio_stream_data*)stream->abstract;
size_t ret;
@@ -371,21 +381,21 @@ static size_t php_stdiop_read(php_stream *stream, char *buf, size_t count TSRMLS
}
}
#endif
- ret = read(data->fd, buf, count);
+ ret = read(data->fd, buf, PLAIN_WRAP_BUF_SIZE(count));
if (ret == (size_t)-1 && errno == EINTR) {
/* Read was interrupted, retry once,
If read still fails, giveup with feof==0
so script can retry if desired */
- ret = read(data->fd, buf, count);
+ ret = read(data->fd, buf, PLAIN_WRAP_BUF_SIZE(count));
}
-
+
stream->eof = (ret == 0 || (ret == (size_t)-1 && errno != EWOULDBLOCK && errno != EINTR && errno != EBADF));
-
+
} else {
#if HAVE_FLUSHIO
if (!data->is_pipe && data->last_op == 'w')
- fseek(data->file, 0, SEEK_CUR);
+ zend_fseek(data->file, 0, SEEK_CUR);
data->last_op = 'r';
#endif
@@ -396,7 +406,7 @@ static size_t php_stdiop_read(php_stream *stream, char *buf, size_t count TSRMLS
return ret;
}
-static int php_stdiop_close(php_stream *stream, int close_handle TSRMLS_DC)
+static int php_stdiop_close(php_stream *stream, int close_handle)
{
int ret;
php_stdio_stream_data *data = (php_stdio_stream_data*)stream->abstract;
@@ -418,7 +428,7 @@ static int php_stdiop_close(php_stream *stream, int close_handle TSRMLS_DC)
data->file_mapping = NULL;
}
#endif
-
+
if (close_handle) {
if (data->file) {
if (data->is_process_pipe) {
@@ -457,7 +467,7 @@ static int php_stdiop_close(php_stream *stream, int close_handle TSRMLS_DC)
return ret;
}
-static int php_stdiop_flush(php_stream *stream TSRMLS_DC)
+static int php_stdiop_flush(php_stream *stream)
{
php_stdio_stream_data *data = (php_stdio_stream_data*)stream->abstract;
@@ -474,7 +484,7 @@ static int php_stdiop_flush(php_stream *stream TSRMLS_DC)
return 0;
}
-static int php_stdiop_seek(php_stream *stream, off_t offset, int whence, off_t *newoffset TSRMLS_DC)
+static int php_stdiop_seek(php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffset)
{
php_stdio_stream_data *data = (php_stdio_stream_data*)stream->abstract;
int ret;
@@ -482,34 +492,34 @@ static int php_stdiop_seek(php_stream *stream, off_t offset, int whence, off_t *
assert(data != NULL);
if (data->is_pipe) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot seek on a pipe");
+ php_error_docref(NULL, E_WARNING, "cannot seek on a pipe");
return -1;
}
if (data->fd >= 0) {
- off_t result;
-
- result = lseek(data->fd, offset, whence);
- if (result == (off_t)-1)
+ zend_off_t result;
+
+ result = zend_lseek(data->fd, offset, whence);
+ if (result == (zend_off_t)-1)
return -1;
*newoffset = result;
return 0;
-
+
} else {
- ret = fseek(data->file, offset, whence);
- *newoffset = ftell(data->file);
+ ret = zend_fseek(data->file, offset, whence);
+ *newoffset = zend_ftell(data->file);
return ret;
}
}
-static int php_stdiop_cast(php_stream *stream, int castas, void **ret TSRMLS_DC)
+static int php_stdiop_cast(php_stream *stream, int castas, void **ret)
{
php_socket_t fd;
php_stdio_stream_data *data = (php_stdio_stream_data*) stream->abstract;
assert(data != NULL);
-
+
/* as soon as someone touches the stdio layer, buffering may ensue,
* so we need to stop using the fd directly in that case */
@@ -527,7 +537,7 @@ static int php_stdiop_cast(php_stream *stream, int castas, void **ret TSRMLS_DC)
return FAILURE;
}
}
-
+
*(FILE**)ret = data->file;
data->fd = SOCK_ERR;
}
@@ -561,7 +571,7 @@ static int php_stdiop_cast(php_stream *stream, int castas, void **ret TSRMLS_DC)
}
}
-static int php_stdiop_stat(php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC)
+static int php_stdiop_stat(php_stream *stream, php_stream_statbuf *ssb)
{
int ret;
php_stdio_stream_data *data = (php_stdio_stream_data*) stream->abstract;
@@ -573,7 +583,7 @@ static int php_stdiop_stat(php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC
return ret;
}
-static int php_stdiop_set_option(php_stream *stream, int option, int value, void *ptrparam TSRMLS_DC)
+static int php_stdiop_set_option(php_stream *stream, int option, int value, void *ptrparam)
{
php_stdio_stream_data *data = (php_stdio_stream_data*) stream->abstract;
size_t size;
@@ -583,9 +593,9 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void
int flags;
int oldval;
#endif
-
+
PHP_STDIOP_GET_FD(fd, data);
-
+
switch(option) {
case PHP_STREAM_OPTION_BLOCKING:
if (fd == -1)
@@ -597,20 +607,20 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void
flags &= ~O_NONBLOCK;
else
flags |= O_NONBLOCK;
-
+
if (-1 == fcntl(fd, F_SETFL, flags))
return -1;
return oldval;
#else
return -1; /* not yet implemented */
#endif
-
+
case PHP_STREAM_OPTION_WRITE_BUFFER:
if (data->file == NULL) {
return -1;
}
-
+
if (ptrparam)
size = *(size_t *)ptrparam;
else
@@ -619,10 +629,10 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void
switch(value) {
case PHP_STREAM_BUFFER_NONE:
return setvbuf(data->file, NULL, _IONBF, 0);
-
+
case PHP_STREAM_BUFFER_LINE:
return setvbuf(data->file, NULL, _IOLBF, size);
-
+
case PHP_STREAM_BUFFER_FULL:
return setvbuf(data->file, NULL, _IOFBF, size);
@@ -630,7 +640,7 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void
return -1;
}
break;
-
+
case PHP_STREAM_OPTION_LOCKING:
if (fd == -1) {
return -1;
@@ -653,7 +663,7 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void
{
php_stream_mmap_range *range = (php_stream_mmap_range*)ptrparam;
int prot, flags;
-
+
switch (value) {
case PHP_STREAM_MMAP_SUPPORTED:
return fd == -1 ? PHP_STREAM_OPTION_RETURN_ERR : PHP_STREAM_OPTION_RETURN_OK;
@@ -770,8 +780,8 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void
GetSystemInfo(&info);
gran = info.dwAllocationGranularity;
- loffs = (range->offset / gran) * gran;
- delta = range->offset - loffs;
+ loffs = ((DWORD)range->offset / gran) * gran;
+ delta = (DWORD)range->offset - loffs;
}
data->last_mapped_addr = MapViewOfFile(data->file_mapping, acc, 0, loffs, range->length + delta);
@@ -818,7 +828,7 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void
return ftruncate(fd, new_size) == 0 ? PHP_STREAM_OPTION_RETURN_OK : PHP_STREAM_OPTION_RETURN_ERR;
}
}
-
+
default:
return PHP_STREAM_OPTION_RETURN_NOTIMPL;
}
@@ -836,7 +846,7 @@ PHPAPI php_stream_ops php_stream_stdio_ops = {
/* }}} */
/* {{{ plain files opendir/readdir implementation */
-static size_t php_plain_files_dirstream_read(php_stream *stream, char *buf, size_t count TSRMLS_DC)
+static size_t php_plain_files_dirstream_read(php_stream *stream, char *buf, size_t count)
{
DIR *dir = (DIR*)stream->abstract;
/* avoid libc5 readdir problems */
@@ -855,12 +865,12 @@ static size_t php_plain_files_dirstream_read(php_stream *stream, char *buf, size
return 0;
}
-static int php_plain_files_dirstream_close(php_stream *stream, int close_handle TSRMLS_DC)
+static int php_plain_files_dirstream_close(php_stream *stream, int close_handle)
{
return closedir((DIR *)stream->abstract);
}
-static int php_plain_files_dirstream_rewind(php_stream *stream, off_t offset, int whence, off_t *newoffs TSRMLS_DC)
+static int php_plain_files_dirstream_rewind(php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffs)
{
rewinddir((DIR *)stream->abstract);
return 0;
@@ -877,26 +887,26 @@ static php_stream_ops php_plain_files_dirstream_ops = {
};
static php_stream *php_plain_files_dir_opener(php_stream_wrapper *wrapper, const char *path, const char *mode,
- int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC)
+ int options, char **opened_path, php_stream_context *context STREAMS_DC)
{
DIR *dir = NULL;
php_stream *stream = NULL;
#ifdef HAVE_GLOB
if (options & STREAM_USE_GLOB_DIR_OPEN) {
- return php_glob_stream_wrapper.wops->dir_opener(&php_glob_stream_wrapper, path, mode, options, opened_path, context STREAMS_REL_CC TSRMLS_CC);
+ return php_glob_stream_wrapper.wops->dir_opener(&php_glob_stream_wrapper, path, mode, options, opened_path, context STREAMS_REL_CC);
}
#endif
- if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(path TSRMLS_CC)) {
+ if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(path)) {
return NULL;
}
-
+
dir = VCWD_OPENDIR(path);
#ifdef PHP_WIN32
if (!dir) {
- php_win32_docref2_from_error(GetLastError(), path, path TSRMLS_CC);
+ php_win32_docref2_from_error(GetLastError(), path, path);
}
if (dir && dir->finished) {
@@ -909,13 +919,13 @@ static php_stream *php_plain_files_dir_opener(php_stream_wrapper *wrapper, const
if (stream == NULL)
closedir(dir);
}
-
+
return stream;
}
/* }}} */
/* {{{ php_stream_fopen */
-PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, char **opened_path, int options STREAMS_DC TSRMLS_DC)
+PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, char **opened_path, int options STREAMS_DC)
{
char *realpath = NULL;
int open_flags;
@@ -926,7 +936,7 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, cha
if (FAILURE == php_stream_parse_fopen_modes(mode, &open_flags)) {
if (options & REPORT_ERRORS) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "`%s' is not a valid mode for fopen", mode);
+ php_error_docref(NULL, E_WARNING, "`%s' is not a valid mode for fopen", mode);
}
return NULL;
}
@@ -934,14 +944,14 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, cha
if (options & STREAM_ASSUME_REALPATH) {
realpath = estrdup(filename);
} else {
- if ((realpath = expand_filepath(filename, NULL TSRMLS_CC)) == NULL) {
+ if ((realpath = expand_filepath(filename, NULL)) == NULL) {
return NULL;
}
}
if (persistent) {
spprintf(&persistent_id, 0, "streams_stdio_%d_%s", open_flags, realpath);
- switch (php_stream_from_persistent_id(persistent_id, &ret TSRMLS_CC)) {
+ switch (php_stream_from_persistent_id(persistent_id, &ret)) {
case PHP_STREAM_PERSISTENT_SUCCESS:
if (opened_path) {
*opened_path = realpath;
@@ -957,7 +967,7 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, cha
return ret;
}
}
-
+
fd = open(realpath, open_flags, 0666);
if (fd != -1) {
@@ -1015,22 +1025,22 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, cha
static php_stream *php_plain_files_stream_opener(php_stream_wrapper *wrapper, const char *path, const char *mode,
- int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC)
+ int options, char **opened_path, php_stream_context *context STREAMS_DC)
{
- if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(path TSRMLS_CC)) {
+ if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(path)) {
return NULL;
}
return php_stream_fopen_rel(path, mode, opened_path, options);
}
-static int php_plain_files_url_stater(php_stream_wrapper *wrapper, const char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC)
+static int php_plain_files_url_stater(php_stream_wrapper *wrapper, const char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context)
{
if (strncasecmp(url, "file://", sizeof("file://") - 1) == 0) {
url += sizeof("file://") - 1;
}
- if (php_check_open_basedir_ex(url, (flags & PHP_STREAM_URL_STAT_QUIET) ? 0 : 1 TSRMLS_CC)) {
+ if (php_check_open_basedir_ex(url, (flags & PHP_STREAM_URL_STAT_QUIET) ? 0 : 1)) {
return -1;
}
@@ -1050,7 +1060,7 @@ static int php_plain_files_url_stater(php_stream_wrapper *wrapper, const char *u
return VCWD_STAT(url, &ssb->sb);
}
-static int php_plain_files_unlink(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC)
+static int php_plain_files_unlink(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context)
{
int ret;
@@ -1058,25 +1068,25 @@ static int php_plain_files_unlink(php_stream_wrapper *wrapper, const char *url,
url += sizeof("file://") - 1;
}
- if (php_check_open_basedir(url TSRMLS_CC)) {
+ if (php_check_open_basedir(url)) {
return 0;
}
ret = VCWD_UNLINK(url);
if (ret == -1) {
if (options & REPORT_ERRORS) {
- php_error_docref1(NULL TSRMLS_CC, url, E_WARNING, "%s", strerror(errno));
+ php_error_docref1(NULL, url, E_WARNING, "%s", strerror(errno));
}
return 0;
}
/* Clear stat cache (and realpath cache) */
- php_clear_stat_cache(1, NULL, 0 TSRMLS_CC);
+ php_clear_stat_cache(1, NULL, 0);
return 1;
}
-static int php_plain_files_rename(php_stream_wrapper *wrapper, const char *url_from, const char *url_to, int options, php_stream_context *context TSRMLS_DC)
+static int php_plain_files_rename(php_stream_wrapper *wrapper, const char *url_from, const char *url_to, int options, php_stream_context *context)
{
int ret;
@@ -1085,12 +1095,12 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, const char *url_f
}
#ifdef PHP_WIN32
- if (!php_win32_check_trailing_space(url_from, strlen(url_from))) {
- php_win32_docref2_from_error(ERROR_INVALID_NAME, url_from, url_to TSRMLS_CC);
+ if (!php_win32_check_trailing_space(url_from, (int)strlen(url_from))) {
+ php_win32_docref2_from_error(ERROR_INVALID_NAME, url_from, url_to);
return 0;
}
- if (!php_win32_check_trailing_space(url_to, strlen(url_to))) {
- php_win32_docref2_from_error(ERROR_INVALID_NAME, url_from, url_to TSRMLS_CC);
+ if (!php_win32_check_trailing_space(url_to, (int)strlen(url_to))) {
+ php_win32_docref2_from_error(ERROR_INVALID_NAME, url_from, url_to);
return 0;
}
#endif
@@ -1103,7 +1113,7 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, const char *url_f
url_to += sizeof("file://") - 1;
}
- if (php_check_open_basedir(url_from TSRMLS_CC) || php_check_open_basedir(url_to TSRMLS_CC)) {
+ if (php_check_open_basedir(url_from) || php_check_open_basedir(url_to)) {
return 0;
}
@@ -1113,26 +1123,26 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, const char *url_f
#ifndef PHP_WIN32
# ifdef EXDEV
if (errno == EXDEV) {
- struct stat sb;
- if (php_copy_file(url_from, url_to TSRMLS_CC) == SUCCESS) {
+ zend_stat_t sb;
+ if (php_copy_file(url_from, url_to) == SUCCESS) {
if (VCWD_STAT(url_from, &sb) == 0) {
# if !defined(TSRM_WIN32) && !defined(NETWARE)
if (VCWD_CHMOD(url_to, sb.st_mode)) {
if (errno == EPERM) {
- php_error_docref2(NULL TSRMLS_CC, url_from, url_to, E_WARNING, "%s", strerror(errno));
+ php_error_docref2(NULL, url_from, url_to, E_WARNING, "%s", strerror(errno));
VCWD_UNLINK(url_from);
return 1;
}
- php_error_docref2(NULL TSRMLS_CC, url_from, url_to, E_WARNING, "%s", strerror(errno));
+ php_error_docref2(NULL, url_from, url_to, E_WARNING, "%s", strerror(errno));
return 0;
}
if (VCWD_CHOWN(url_to, sb.st_uid, sb.st_gid)) {
if (errno == EPERM) {
- php_error_docref2(NULL TSRMLS_CC, url_from, url_to, E_WARNING, "%s", strerror(errno));
+ php_error_docref2(NULL, url_from, url_to, E_WARNING, "%s", strerror(errno));
VCWD_UNLINK(url_from);
return 1;
}
- php_error_docref2(NULL TSRMLS_CC, url_from, url_to, E_WARNING, "%s", strerror(errno));
+ php_error_docref2(NULL, url_from, url_to, E_WARNING, "%s", strerror(errno));
return 0;
}
# endif
@@ -1140,27 +1150,27 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, const char *url_f
return 1;
}
}
- php_error_docref2(NULL TSRMLS_CC, url_from, url_to, E_WARNING, "%s", strerror(errno));
+ php_error_docref2(NULL, url_from, url_to, E_WARNING, "%s", strerror(errno));
return 0;
}
# endif
#endif
#ifdef PHP_WIN32
- php_win32_docref2_from_error(GetLastError(), url_from, url_to TSRMLS_CC);
+ php_win32_docref2_from_error(GetLastError(), url_from, url_to);
#else
- php_error_docref2(NULL TSRMLS_CC, url_from, url_to, E_WARNING, "%s", strerror(errno));
+ php_error_docref2(NULL, url_from, url_to, E_WARNING, "%s", strerror(errno));
#endif
return 0;
}
/* Clear stat cache (and realpath cache) */
- php_clear_stat_cache(1, NULL, 0 TSRMLS_CC);
+ php_clear_stat_cache(1, NULL, 0);
return 1;
}
-static int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, int mode, int options, php_stream_context *context TSRMLS_DC)
+static int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, int mode, int options, php_stream_context *context)
{
int ret, recursive = options & PHP_STREAM_MKDIR_RECURSIVE;
char *p;
@@ -1170,17 +1180,17 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, i
}
if (!recursive) {
- ret = php_mkdir(dir, mode TSRMLS_CC);
+ ret = php_mkdir(dir, mode);
} else {
/* we look for directory separator from the end of string, thus hopefuly reducing our work load */
char *e;
- struct stat sb;
- int dir_len = strlen(dir);
+ zend_stat_t sb;
+ int dir_len = (int)strlen(dir);
int offset = 0;
char buf[MAXPATHLEN];
- if (!expand_filepath_with_mode(dir, buf, NULL, 0, CWD_EXPAND TSRMLS_CC)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid path");
+ if (!expand_filepath_with_mode(dir, buf, NULL, 0, CWD_EXPAND )) {
+ php_error_docref(NULL, E_WARNING, "Invalid path");
return 0;
}
@@ -1191,7 +1201,7 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, i
}
if (p && dir_len == 1) {
- /* buf == "DEFAULT_SLASH" */
+ /* buf == "DEFAULT_SLASH" */
}
else {
/* find a top level directory we need to create */
@@ -1217,8 +1227,8 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, i
}
if (p == buf) {
- ret = php_mkdir(dir, mode TSRMLS_CC);
- } else if (!(ret = php_mkdir(buf, mode TSRMLS_CC))) {
+ ret = php_mkdir(dir, mode);
+ } else if (!(ret = php_mkdir(buf, mode))) {
if (!p) {
p = buf;
}
@@ -1229,7 +1239,7 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, i
if ((*(p+1) != '\0') &&
(ret = VCWD_MKDIR(buf, (mode_t)mode)) < 0) {
if (options & REPORT_ERRORS) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno));
+ php_error_docref(NULL, E_WARNING, "%s", strerror(errno));
}
break;
}
@@ -1246,35 +1256,35 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, i
}
}
-static int php_plain_files_rmdir(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC)
+static int php_plain_files_rmdir(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context)
{
if (strncasecmp(url, "file://", sizeof("file://") - 1) == 0) {
url += sizeof("file://") - 1;
}
- if (php_check_open_basedir(url TSRMLS_CC)) {
+ if (php_check_open_basedir(url)) {
return 0;
}
#if PHP_WIN32
if (!php_win32_check_trailing_space(url, (int)strlen(url))) {
- php_error_docref1(NULL TSRMLS_CC, url, E_WARNING, "%s", strerror(ENOENT));
+ php_error_docref1(NULL, url, E_WARNING, "%s", strerror(ENOENT));
return 0;
}
#endif
if (VCWD_RMDIR(url) < 0) {
- php_error_docref1(NULL TSRMLS_CC, url, E_WARNING, "%s", strerror(errno));
+ php_error_docref1(NULL, url, E_WARNING, "%s", strerror(errno));
return 0;
}
/* Clear stat cache (and realpath cache) */
- php_clear_stat_cache(1, NULL, 0 TSRMLS_CC);
+ php_clear_stat_cache(1, NULL, 0);
return 1;
}
-static int php_plain_files_metadata(php_stream_wrapper *wrapper, const char *url, int option, void *value, php_stream_context *context TSRMLS_DC)
+static int php_plain_files_metadata(php_stream_wrapper *wrapper, const char *url, int option, void *value, php_stream_context *context)
{
struct utimbuf *newtime;
#if !defined(WINDOWS) && !defined(NETWARE)
@@ -1284,12 +1294,12 @@ static int php_plain_files_metadata(php_stream_wrapper *wrapper, const char *url
mode_t mode;
int ret = 0;
#if PHP_WIN32
- int url_len = strlen(url);
+ int url_len = (int)strlen(url);
#endif
#if PHP_WIN32
if (!php_win32_check_trailing_space(url, url_len)) {
- php_error_docref1(NULL TSRMLS_CC, url, E_WARNING, "%s", strerror(ENOENT));
+ php_error_docref1(NULL, url, E_WARNING, "%s", strerror(ENOENT));
return 0;
}
#endif
@@ -1298,7 +1308,7 @@ static int php_plain_files_metadata(php_stream_wrapper *wrapper, const char *url
url += sizeof("file://") - 1;
}
- if (php_check_open_basedir(url TSRMLS_CC)) {
+ if (php_check_open_basedir(url)) {
return 0;
}
@@ -1308,7 +1318,7 @@ static int php_plain_files_metadata(php_stream_wrapper *wrapper, const char *url
if (VCWD_ACCESS(url, F_OK) != 0) {
FILE *file = VCWD_FOPEN(url, "w");
if (file == NULL) {
- php_error_docref1(NULL TSRMLS_CC, url, E_WARNING, "Unable to create file %s because %s", url, strerror(errno));
+ php_error_docref1(NULL, url, E_WARNING, "Unable to create file %s because %s", url, strerror(errno));
return 0;
}
fclose(file);
@@ -1320,8 +1330,8 @@ static int php_plain_files_metadata(php_stream_wrapper *wrapper, const char *url
case PHP_STREAM_META_OWNER_NAME:
case PHP_STREAM_META_OWNER:
if(option == PHP_STREAM_META_OWNER_NAME) {
- if(php_get_uid_by_name((char *)value, &uid TSRMLS_CC) != SUCCESS) {
- php_error_docref1(NULL TSRMLS_CC, url, E_WARNING, "Unable to find uid for %s", (char *)value);
+ if(php_get_uid_by_name((char *)value, &uid) != SUCCESS) {
+ php_error_docref1(NULL, url, E_WARNING, "Unable to find uid for %s", (char *)value);
return 0;
}
} else {
@@ -1332,8 +1342,8 @@ static int php_plain_files_metadata(php_stream_wrapper *wrapper, const char *url
case PHP_STREAM_META_GROUP:
case PHP_STREAM_META_GROUP_NAME:
if(option == PHP_STREAM_META_OWNER_NAME) {
- if(php_get_gid_by_name((char *)value, &gid TSRMLS_CC) != SUCCESS) {
- php_error_docref1(NULL TSRMLS_CC, url, E_WARNING, "Unable to find gid for %s", (char *)value);
+ if(php_get_gid_by_name((char *)value, &gid) != SUCCESS) {
+ php_error_docref1(NULL, url, E_WARNING, "Unable to find gid for %s", (char *)value);
return 0;
}
} else {
@@ -1343,18 +1353,18 @@ static int php_plain_files_metadata(php_stream_wrapper *wrapper, const char *url
break;
#endif
case PHP_STREAM_META_ACCESS:
- mode = (mode_t)*(long *)value;
+ mode = (mode_t)*(zend_long *)value;
ret = VCWD_CHMOD(url, mode);
break;
default:
- php_error_docref1(NULL TSRMLS_CC, url, E_WARNING, "Unknown option %d for stream_metadata", option);
+ php_error_docref1(NULL, url, E_WARNING, "Unknown option %d for stream_metadata", option);
return 0;
}
if (ret == -1) {
- php_error_docref1(NULL TSRMLS_CC, url, E_WARNING, "Operation failed: %s", strerror(errno));
+ php_error_docref1(NULL, url, E_WARNING, "Operation failed: %s", strerror(errno));
return 0;
}
- php_clear_stat_cache(0, NULL, 0 TSRMLS_CC);
+ php_clear_stat_cache(0, NULL, 0);
return 1;
}
@@ -1373,14 +1383,14 @@ static php_stream_wrapper_ops php_plain_files_wrapper_ops = {
php_plain_files_metadata
};
-php_stream_wrapper php_plain_files_wrapper = {
+PHPAPI php_stream_wrapper php_plain_files_wrapper = {
&php_plain_files_wrapper_ops,
NULL,
0
};
/* {{{ php_stream_fopen_with_path */
-PHPAPI php_stream *_php_stream_fopen_with_path(const char *filename, const char *mode, const char *path, char **opened_path, int options STREAMS_DC TSRMLS_DC)
+PHPAPI php_stream *_php_stream_fopen_with_path(const char *filename, const char *mode, const char *path, char **opened_path, int options STREAMS_DC)
{
/* code ripped off from fopen_wrappers.c */
char *pathbuf, *end;
@@ -1400,7 +1410,7 @@ PHPAPI php_stream *_php_stream_fopen_with_path(const char *filename, const char
return NULL;
}
- filename_length = strlen(filename);
+ filename_length = (int)strlen(filename);
/* Relative path open */
if (*filename == '.' && (IS_SLASH(filename[1]) || filename[1] == '.')) {
@@ -1414,7 +1424,7 @@ PHPAPI php_stream *_php_stream_fopen_with_path(const char *filename, const char
}
- if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(filename TSRMLS_CC)) {
+ if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(filename)) {
return NULL;
}
@@ -1426,31 +1436,31 @@ not_relative_path:
/* Absolute path open */
if (IS_ABSOLUTE_PATH(filename, filename_length)) {
- if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(filename TSRMLS_CC)) {
+ if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(filename)) {
return NULL;
}
return php_stream_fopen_rel(filename, mode, opened_path, options);
}
-
+
#ifdef PHP_WIN32
if (IS_SLASH(filename[0])) {
size_t cwd_len;
char *cwd;
- cwd = virtual_getcwd_ex(&cwd_len TSRMLS_CC);
+ cwd = virtual_getcwd_ex(&cwd_len);
/* getcwd() will return always return [DRIVE_LETTER]:/) on windows. */
*(cwd+3) = '\0';
-
+
if (snprintf(trypath, MAXPATHLEN, "%s%s", cwd, filename) >= MAXPATHLEN) {
- php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%s/%s path was truncated to %d", cwd, filename, MAXPATHLEN);
+ php_error_docref(NULL, E_NOTICE, "%s/%s path was truncated to %d", cwd, filename, MAXPATHLEN);
}
-
+
efree(cwd);
-
- if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(trypath TSRMLS_CC)) {
+
+ if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(trypath)) {
return NULL;
}
-
+
return php_stream_fopen_rel(trypath, mode, opened_path, options);
}
#endif
@@ -1463,10 +1473,10 @@ not_relative_path:
/* append the calling scripts' current working directory
* as a fall back case
*/
- if (zend_is_executing(TSRMLS_C)) {
- exec_fname = zend_get_executed_filename(TSRMLS_C);
- exec_fname_length = strlen(exec_fname);
- path_length = strlen(path);
+ if (zend_is_executing()) {
+ exec_fname = zend_get_executed_filename();
+ exec_fname_length = (int)strlen(exec_fname);
+ path_length = (int)strlen(path);
while ((--exec_fname_length >= 0) && !IS_SLASH(exec_fname[exec_fname_length]));
if ((exec_fname && exec_fname[0] == '[')
@@ -1496,13 +1506,13 @@ not_relative_path:
goto stream_skip;
}
if (snprintf(trypath, MAXPATHLEN, "%s/%s", ptr, filename) >= MAXPATHLEN) {
- php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%s/%s path was truncated to %d", ptr, filename, MAXPATHLEN);
+ php_error_docref(NULL, E_NOTICE, "%s/%s path was truncated to %d", ptr, filename, MAXPATHLEN);
}
- if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir_ex(trypath, 0 TSRMLS_CC)) {
+ if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir_ex(trypath, 0)) {
goto stream_skip;
}
-
+
stream = php_stream_fopen_rel(trypath, mode, opened_path, options);
if (stream) {
efree(pathbuf);
diff --git a/main/streams/streams.c b/main/streams/streams.c
index e2e9e4947f..e92c7449f7 100644
--- a/main/streams/streams.c
+++ b/main/streams/streams.c
@@ -1,8 +1,8 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2015 The PHP Group |
+ | Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -55,7 +55,7 @@ PHPAPI int php_file_le_stream_filter(void)
return le_stream_filter;
}
-PHPAPI HashTable *_php_stream_get_url_stream_wrappers_hash(TSRMLS_D)
+PHPAPI HashTable *_php_stream_get_url_stream_wrappers_hash(void)
{
return (FG(stream_wrappers) ? FG(stream_wrappers) : &url_stream_wrappers_hash);
}
@@ -65,19 +65,21 @@ PHPAPI HashTable *php_stream_get_url_stream_wrappers_hash_global(void)
return &url_stream_wrappers_hash;
}
-static int _php_stream_release_context(zend_rsrc_list_entry *le, void *pContext TSRMLS_DC)
+static int _php_stream_release_context(zval *zv, void *pContext)
{
+ zend_resource *le = Z_RES_P(zv);
if (le->ptr == pContext) {
- return --le->refcount == 0;
+ return --GC_REFCOUNT(le) == 0;
}
return 0;
}
-static int forget_persistent_resource_id_numbers(zend_rsrc_list_entry *rsrc TSRMLS_DC)
+static int forget_persistent_resource_id_numbers(zval *el)
{
php_stream *stream;
+ zend_resource *rsrc = Z_RES_P(el);
- if (Z_TYPE_P(rsrc) != le_pstream) {
+ if (rsrc->type != le_pstream) {
return 0;
}
@@ -87,13 +89,13 @@ static int forget_persistent_resource_id_numbers(zend_rsrc_list_entry *rsrc TSRM
fprintf(stderr, "forget_persistent: %s:%p\n", stream->ops->label, stream);
#endif
- stream->rsrc_id = FAILURE;
+ stream->res = NULL;
- if (stream->context) {
+ if (PHP_STREAM_CONTEXT(stream)) {
zend_hash_apply_with_argument(&EG(regular_list),
- (apply_func_arg_t) _php_stream_release_context,
- stream->context TSRMLS_CC);
- stream->context = NULL;
+ _php_stream_release_context,
+ PHP_STREAM_CONTEXT(stream));
+ stream->ctx = NULL;
}
return 0;
@@ -101,7 +103,7 @@ fprintf(stderr, "forget_persistent: %s:%p\n", stream->ops->label, stream);
PHP_RSHUTDOWN_FUNCTION(streams)
{
- zend_hash_apply(&EG(persistent_list), (apply_func_t)forget_persistent_resource_id_numbers TSRMLS_CC);
+ zend_hash_apply(&EG(persistent_list), forget_persistent_resource_id_numbers);
return SUCCESS;
}
@@ -114,38 +116,34 @@ PHPAPI php_stream *php_stream_encloses(php_stream *enclosing, php_stream *enclos
return orig;
}
-PHPAPI int php_stream_from_persistent_id(const char *persistent_id, php_stream **stream TSRMLS_DC)
+PHPAPI int php_stream_from_persistent_id(const char *persistent_id, php_stream **stream)
{
- zend_rsrc_list_entry *le;
+ zend_resource *le;
- if (zend_hash_find(&EG(persistent_list), (char*)persistent_id, strlen(persistent_id)+1, (void*) &le) == SUCCESS) {
- if (Z_TYPE_P(le) == le_pstream) {
+ if ((le = zend_hash_str_find_ptr(&EG(persistent_list), persistent_id, strlen(persistent_id))) != NULL) {
+ if (le->type == le_pstream) {
if (stream) {
HashPosition pos;
- zend_rsrc_list_entry *regentry;
- ulong index = -1; /* intentional */
+ zend_resource *regentry;
/* see if this persistent resource already has been loaded to the
* regular list; allowing the same resource in several entries in the
* regular list causes trouble (see bug #54623) */
zend_hash_internal_pointer_reset_ex(&EG(regular_list), &pos);
- while (zend_hash_get_current_data_ex(&EG(regular_list),
- (void **)&regentry, &pos) == SUCCESS) {
+ while ((regentry = zend_hash_get_current_data_ptr_ex(&EG(regular_list), &pos)) != NULL) {
if (regentry->ptr == le->ptr) {
- zend_hash_get_current_key_ex(&EG(regular_list), NULL, NULL,
- &index, 0, &pos);
break;
}
zend_hash_move_forward_ex(&EG(regular_list), &pos);
}
-
+
*stream = (php_stream*)le->ptr;
- if (index == -1) { /* not found in regular list */
- le->refcount++;
- (*stream)->rsrc_id = ZEND_REGISTER_RESOURCE(NULL, *stream, le_pstream);
+ if (!regentry) { /* not found in regular list */
+ GC_REFCOUNT(le)++;
+ (*stream)->res = ZEND_REGISTER_RESOURCE(NULL, *stream, le_pstream);
} else {
- regentry->refcount++;
- (*stream)->rsrc_id = index;
+ GC_REFCOUNT(regentry)++;
+ (*stream)->res = regentry;
}
}
return PHP_STREAM_PERSISTENT_SUCCESS;
@@ -157,32 +155,29 @@ PHPAPI int php_stream_from_persistent_id(const char *persistent_id, php_stream *
/* }}} */
-static zend_llist *php_get_wrapper_errors_list(php_stream_wrapper *wrapper TSRMLS_DC)
+static zend_llist *php_get_wrapper_errors_list(php_stream_wrapper *wrapper)
{
- zend_llist *list = NULL;
if (!FG(wrapper_errors)) {
return NULL;
} else {
- zend_hash_find(FG(wrapper_errors), (const char*)&wrapper,
- sizeof wrapper, (void**)&list);
- return list;
+ return (zend_llist*) zend_hash_str_find_ptr(FG(wrapper_errors), (const char*)&wrapper, sizeof(wrapper));
}
}
/* {{{ wrapper error reporting */
-void php_stream_display_wrapper_errors(php_stream_wrapper *wrapper, const char *path, const char *caption TSRMLS_DC)
+void php_stream_display_wrapper_errors(php_stream_wrapper *wrapper, const char *path, const char *caption)
{
char *tmp = estrdup(path);
char *msg;
int free_msg = 0;
if (wrapper) {
- zend_llist *err_list = php_get_wrapper_errors_list(wrapper TSRMLS_CC);
+ zend_llist *err_list = php_get_wrapper_errors_list(wrapper);
if (err_list) {
size_t l = 0;
int brlen;
int i;
- int count = zend_llist_count(err_list);
+ int count = (int)zend_llist_count(err_list);
const char *br;
const char **err_buf_p;
zend_llist_position pos;
@@ -227,17 +222,17 @@ void php_stream_display_wrapper_errors(php_stream_wrapper *wrapper, const char *
}
php_strip_url_passwd(tmp);
- php_error_docref1(NULL TSRMLS_CC, tmp, E_WARNING, "%s: %s", caption, msg);
+ php_error_docref1(NULL, tmp, E_WARNING, "%s: %s", caption, msg);
efree(tmp);
if (free_msg) {
efree(msg);
}
}
-void php_stream_tidy_wrapper_error_log(php_stream_wrapper *wrapper TSRMLS_DC)
+void php_stream_tidy_wrapper_error_log(php_stream_wrapper *wrapper)
{
if (wrapper && FG(wrapper_errors)) {
- zend_hash_del(FG(wrapper_errors), (const char*)&wrapper, sizeof wrapper);
+ zend_hash_str_del(FG(wrapper_errors), (const char*)&wrapper, sizeof(wrapper));
}
}
@@ -246,7 +241,13 @@ static void wrapper_error_dtor(void *error)
efree(*(char**)error);
}
-PHPAPI void php_stream_wrapper_log_error(php_stream_wrapper *wrapper, int options TSRMLS_DC, const char *fmt, ...)
+static void wrapper_list_dtor(zval *item) {
+ zend_llist *list = (zend_llist*)Z_PTR_P(item);
+ zend_llist_destroy(list);
+ efree(list);
+}
+
+PHPAPI void php_stream_wrapper_log_error(php_stream_wrapper *wrapper, int options, const char *fmt, ...)
{
va_list args;
char *buffer = NULL;
@@ -256,24 +257,22 @@ PHPAPI void php_stream_wrapper_log_error(php_stream_wrapper *wrapper, int option
va_end(args);
if (options & REPORT_ERRORS || wrapper == NULL) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", buffer);
+ php_error_docref(NULL, E_WARNING, "%s", buffer);
efree(buffer);
} else {
zend_llist *list = NULL;
if (!FG(wrapper_errors)) {
ALLOC_HASHTABLE(FG(wrapper_errors));
- zend_hash_init(FG(wrapper_errors), 8, NULL,
- (dtor_func_t)zend_llist_destroy, 0);
+ zend_hash_init(FG(wrapper_errors), 8, NULL, wrapper_list_dtor, 0);
} else {
- zend_hash_find(FG(wrapper_errors), (const char*)&wrapper,
- sizeof wrapper, (void**)&list);
+ list = zend_hash_str_find_ptr(FG(wrapper_errors), (const char*)&wrapper, sizeof(wrapper));
}
if (!list) {
zend_llist new_list;
- zend_llist_init(&new_list, sizeof buffer, wrapper_error_dtor, 0);
- zend_hash_update(FG(wrapper_errors), (const char*)&wrapper,
- sizeof wrapper, &new_list, sizeof new_list, (void**)&list);
+ zend_llist_init(&new_list, sizeof(buffer), wrapper_error_dtor, 0);
+ list = zend_hash_str_update_mem(FG(wrapper_errors), (const char*)&wrapper,
+ sizeof(wrapper), &new_list, sizeof(new_list));
}
/* append to linked list */
@@ -285,7 +284,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 TSRMLS_DC) /* {{{ */
+PHPAPI php_stream *_php_stream_alloc(php_stream_ops *ops, void *abstract, const char *persistent_id, const char *mode STREAMS_DC) /* {{{ */
{
php_stream *ret;
@@ -315,30 +314,26 @@ fprintf(stderr, "stream_alloc: %s:%p persistent=%s\n", ops->label, ret, persiste
}
if (persistent_id) {
- zend_rsrc_list_entry le;
-
- Z_TYPE(le) = le_pstream;
- le.ptr = ret;
- le.refcount = 0;
+ zval tmp;
- if (FAILURE == zend_hash_update(&EG(persistent_list), (char *)persistent_id,
- strlen(persistent_id) + 1,
- (void *)&le, sizeof(le), NULL)) {
+ ZVAL_NEW_PERSISTENT_RES(&tmp, -1, ret, le_pstream);
+ if (NULL == zend_hash_str_update(&EG(persistent_list), persistent_id,
+ strlen(persistent_id), &tmp)) {
pefree(ret, 1);
return NULL;
}
}
- ret->rsrc_id = ZEND_REGISTER_RESOURCE(NULL, ret, persistent_id ? le_pstream : le_stream);
+ ret->res = ZEND_REGISTER_RESOURCE(NULL, ret, persistent_id ? le_pstream : le_stream);
strlcpy(ret->mode, mode, sizeof(ret->mode));
ret->wrapper = NULL;
ret->wrapperthis = NULL;
- ret->wrapperdata = NULL;
+ ZVAL_UNDEF(&ret->wrapperdata);
ret->stdiocast = NULL;
ret->orig_path = NULL;
- ret->context = NULL;
+ ret->ctx = NULL;
ret->readbuf = NULL;
ret->enclosing_stream = NULL;
@@ -346,10 +341,10 @@ fprintf(stderr, "stream_alloc: %s:%p persistent=%s\n", ops->label, ret, persiste
}
/* }}} */
-PHPAPI int _php_stream_free_enclosed(php_stream *stream_enclosed, int close_options TSRMLS_DC) /* {{{ */
+PHPAPI int _php_stream_free_enclosed(php_stream *stream_enclosed, int close_options) /* {{{ */
{
return _php_stream_free(stream_enclosed,
- close_options | PHP_STREAM_FREE_IGNORE_ENCLOSING TSRMLS_CC);
+ close_options | PHP_STREAM_FREE_IGNORE_ENCLOSING);
}
/* }}} */
@@ -374,13 +369,14 @@ static const char *_php_stream_pretty_free_options(int close_options, char *out)
}
#endif
-static int _php_stream_free_persistent(zend_rsrc_list_entry *le, void *pStream TSRMLS_DC)
+static int _php_stream_free_persistent(zval *zv, void *pStream)
{
+ zend_resource *le = Z_RES_P(zv);
return le->ptr == pStream;
}
-PHPAPI int _php_stream_free(php_stream *stream, int close_options TSRMLS_DC) /* {{{ */
+PHPAPI int _php_stream_free(php_stream *stream, int close_options) /* {{{ */
{
int ret = 1;
int preserve_handle = close_options & PHP_STREAM_FREE_PRESERVE_HANDLE ? 1 : 0;
@@ -391,7 +387,7 @@ PHPAPI int _php_stream_free(php_stream *stream, int close_options TSRMLS_DC) /*
* already been freed (if it was created after the stream resource), so
* don't reference it */
if (EG(active)) {
- context = stream->context;
+ context = PHP_STREAM_CONTEXT(stream);
}
if (stream->flags & PHP_STREAM_FLAG_NO_CLOSE) {
@@ -404,7 +400,7 @@ PHPAPI int _php_stream_free(php_stream *stream, int close_options TSRMLS_DC) /*
fprintf(stderr, "stream_free: %s:%p[%s] in_free=%d opts=%s\n",
stream->ops->label, stream, stream->orig_path, stream->in_free, _php_stream_pretty_free_options(close_options, out));
}
-
+
#endif
if (stream->in_free) {
@@ -430,7 +426,7 @@ PHPAPI int _php_stream_free(php_stream *stream, int close_options TSRMLS_DC) /*
* enclosing stream can free this stream. We remove rsrc_dtor because
* we want the enclosing stream to be deleted from the resource list */
return _php_stream_free(enclosing_stream,
- (close_options | PHP_STREAM_FREE_CALL_DTOR) & ~PHP_STREAM_FREE_RSRC_DTOR TSRMLS_CC);
+ (close_options | PHP_STREAM_FREE_CALL_DTOR) & ~PHP_STREAM_FREE_RSRC_DTOR);
}
/* if we are releasing the stream only (and preserving the underlying handle),
@@ -458,16 +454,22 @@ fprintf(stderr, "stream_free: %s:%p[%s] preserve_handle=%d release_cast=%d remov
#endif
/* make sure everything is saved */
- _php_stream_flush(stream, 1 TSRMLS_CC);
+ _php_stream_flush(stream, 1);
/* If not called from the resource dtor, remove the stream from the resource list. */
- if ((close_options & PHP_STREAM_FREE_RSRC_DTOR) == 0) {
+ if ((close_options & PHP_STREAM_FREE_RSRC_DTOR) == 0 && stream->res) {
/* zend_list_delete actually only decreases the refcount; if we're
* releasing the stream, we want to actually delete the resource from
* the resource list, otherwise the resource will point to invalid memory.
* In any case, let's always completely delete it from the resource list,
* not only when PHP_STREAM_FREE_RELEASE_STREAM is set */
- while (zend_list_delete(stream->rsrc_id) == SUCCESS) {}
+//??? while (zend_list_delete(stream->res) == SUCCESS) {}
+//??? stream->res->gc.refcount = 0;
+ zend_list_close(stream->res);
+ if (!stream->__exposed) {
+ zend_list_delete(stream->res);
+ stream->res = NULL;
+ }
}
if (close_options & PHP_STREAM_FREE_CALL_DTOR) {
@@ -483,7 +485,7 @@ fprintf(stderr, "stream_free: %s:%p[%s] preserve_handle=%d release_cast=%d remov
return fclose(stream->stdiocast);
}
- ret = stream->ops->close(stream, preserve_handle ? 0 : 1 TSRMLS_CC);
+ ret = stream->ops->close(stream, preserve_handle ? 0 : 1);
stream->abstract = NULL;
/* tidy up any FILE* that might have been fdopened */
@@ -496,20 +498,20 @@ fprintf(stderr, "stream_free: %s:%p[%s] preserve_handle=%d release_cast=%d remov
if (close_options & PHP_STREAM_FREE_RELEASE_STREAM) {
while (stream->readfilters.head) {
- php_stream_filter_remove(stream->readfilters.head, 1 TSRMLS_CC);
+ php_stream_filter_remove(stream->readfilters.head, 1);
}
while (stream->writefilters.head) {
- php_stream_filter_remove(stream->writefilters.head, 1 TSRMLS_CC);
+ php_stream_filter_remove(stream->writefilters.head, 1);
}
if (stream->wrapper && stream->wrapper->wops && stream->wrapper->wops->stream_closer) {
- stream->wrapper->wops->stream_closer(stream->wrapper, stream TSRMLS_CC);
+ stream->wrapper->wops->stream_closer(stream->wrapper, stream);
stream->wrapper = NULL;
}
- if (stream->wrapperdata) {
+ if (Z_TYPE(stream->wrapperdata) != IS_UNDEF) {
zval_ptr_dtor(&stream->wrapperdata);
- stream->wrapperdata = NULL;
+ ZVAL_UNDEF(&stream->wrapperdata);
}
if (stream->readbuf) {
@@ -519,27 +521,29 @@ fprintf(stderr, "stream_free: %s:%p[%s] preserve_handle=%d release_cast=%d remov
if (stream->is_persistent && (close_options & PHP_STREAM_FREE_PERSISTENT)) {
/* we don't work with *stream but need its value for comparison */
- zend_hash_apply_with_argument(&EG(persistent_list), (apply_func_arg_t) _php_stream_free_persistent, stream TSRMLS_CC);
+ zend_hash_apply_with_argument(&EG(persistent_list), _php_stream_free_persistent, stream);
}
#if ZEND_DEBUG
if ((close_options & PHP_STREAM_FREE_RSRC_DTOR) && (stream->__exposed == 0) && (EG(error_reporting) & E_WARNING)) {
/* it leaked: Lets deliberately NOT pefree it so that the memory manager shows it
* as leaked; it will log a warning, but lets help it out and display what kind
* of stream it was. */
- char *leakinfo;
- spprintf(&leakinfo, 0, __FILE__ "(%d) : Stream of type '%s' %p (path:%s) was not closed\n", __LINE__, stream->ops->label, stream, stream->orig_path);
+ if (!CG(unclean_shutdown)) {
+ char *leakinfo;
+ spprintf(&leakinfo, 0, __FILE__ "(%d) : Stream of type '%s' %p (path:%s) was not closed\n", __LINE__, stream->ops->label, stream, stream->orig_path);
- if (stream->orig_path) {
- pefree(stream->orig_path, stream->is_persistent);
- stream->orig_path = NULL;
- }
+ if (stream->orig_path) {
+ pefree(stream->orig_path, stream->is_persistent);
+ stream->orig_path = NULL;
+ }
# if defined(PHP_WIN32)
- OutputDebugString(leakinfo);
+ OutputDebugString(leakinfo);
# else
- fprintf(stderr, "%s", leakinfo);
+ fprintf(stderr, "%s", leakinfo);
# endif
- efree(leakinfo);
+ efree(leakinfo);
+ }
} else {
if (stream->orig_path) {
pefree(stream->orig_path, stream->is_persistent);
@@ -559,7 +563,7 @@ fprintf(stderr, "stream_free: %s:%p[%s] preserve_handle=%d release_cast=%d remov
}
if (context) {
- zend_list_delete(context->rsrc_id);
+ zend_list_delete(context->res);
}
return ret;
@@ -568,7 +572,7 @@ fprintf(stderr, "stream_free: %s:%p[%s] preserve_handle=%d release_cast=%d remov
/* {{{ generic stream operations */
-static void php_stream_fill_read_buffer(php_stream *stream, size_t size TSRMLS_DC)
+static void php_stream_fill_read_buffer(php_stream *stream, size_t size)
{
/* allocate/fill the buffer */
@@ -593,12 +597,12 @@ static void php_stream_fill_read_buffer(php_stream *stream, size_t size TSRMLS_D
php_stream_filter *filter;
/* read a chunk into a bucket */
- justread = stream->ops->read(stream, chunk_buf, stream->chunk_size TSRMLS_CC);
+ justread = stream->ops->read(stream, chunk_buf, stream->chunk_size);
if (justread && justread != (size_t)-1) {
- bucket = php_stream_bucket_new(stream, chunk_buf, justread, 0, 0 TSRMLS_CC);
+ bucket = php_stream_bucket_new(stream, chunk_buf, justread, 0, 0);
/* after this call, bucket is owned by the brigade */
- php_stream_bucket_append(brig_inp, bucket TSRMLS_CC);
+ php_stream_bucket_append(brig_inp, bucket);
flags = PSFS_FLAG_NORMAL;
} else {
@@ -607,7 +611,7 @@ static void php_stream_fill_read_buffer(php_stream *stream, size_t size TSRMLS_D
/* wind the handle... */
for (filter = stream->readfilters.head; filter; filter = filter->next) {
- status = filter->fops->filter(stream, filter, brig_inp, brig_outp, NULL, flags TSRMLS_CC);
+ status = filter->fops->filter(stream, filter, brig_inp, brig_outp, NULL, flags);
if (status != PSFS_PASS_ON) {
break;
@@ -639,8 +643,8 @@ static void php_stream_fill_read_buffer(php_stream *stream, size_t size TSRMLS_D
memcpy(stream->readbuf + stream->writepos, bucket->buf, bucket->buflen);
stream->writepos += bucket->buflen;
- php_stream_bucket_unlink(bucket TSRMLS_CC);
- php_stream_bucket_delref(bucket TSRMLS_CC);
+ php_stream_bucket_unlink(bucket);
+ php_stream_bucket_delref(bucket);
}
break;
@@ -671,7 +675,7 @@ static void php_stream_fill_read_buffer(php_stream *stream, size_t size TSRMLS_D
} else {
/* is there enough data in the buffer ? */
- if (stream->writepos - stream->readpos < (off_t)size) {
+ if (stream->writepos - stream->readpos < (zend_off_t)size) {
size_t justread = 0;
/* reduce buffer memory consumption if possible, to avoid a realloc */
@@ -689,9 +693,9 @@ static void php_stream_fill_read_buffer(php_stream *stream, size_t size TSRMLS_D
stream->is_persistent);
}
- justread = stream->ops->read(stream, stream->readbuf + stream->writepos,
+ justread = stream->ops->read(stream, (char*)stream->readbuf + stream->writepos,
stream->readbuflen - stream->writepos
- TSRMLS_CC);
+ );
if (justread != (size_t)-1) {
stream->writepos += justread;
@@ -700,7 +704,7 @@ static void php_stream_fill_read_buffer(php_stream *stream, size_t size TSRMLS_D
}
}
-PHPAPI size_t _php_stream_read(php_stream *stream, char *buf, size_t size TSRMLS_DC)
+PHPAPI size_t _php_stream_read(php_stream *stream, char *buf, size_t size)
{
size_t toread = 0, didread = 0;
@@ -730,13 +734,13 @@ PHPAPI size_t _php_stream_read(php_stream *stream, char *buf, size_t size TSRMLS
}
if (!stream->readfilters.head && (stream->flags & PHP_STREAM_FLAG_NO_BUFFER || stream->chunk_size == 1)) {
- toread = stream->ops->read(stream, buf, size TSRMLS_CC);
+ toread = stream->ops->read(stream, buf, size);
if (toread == (size_t) -1) {
/* e.g. underlying read(2) returned -1 */
break;
}
} else {
- php_stream_fill_read_buffer(stream, size TSRMLS_CC);
+ php_stream_fill_read_buffer(stream, size);
toread = stream->writepos - stream->readpos;
if (toread > size) {
@@ -770,7 +774,7 @@ PHPAPI size_t _php_stream_read(php_stream *stream, char *buf, size_t size TSRMLS
return didread;
}
-PHPAPI int _php_stream_eof(php_stream *stream TSRMLS_DC)
+PHPAPI int _php_stream_eof(php_stream *stream)
{
/* if there is data in the buffer, it's not EOF */
if (stream->writepos - stream->readpos > 0) {
@@ -787,17 +791,17 @@ PHPAPI int _php_stream_eof(php_stream *stream TSRMLS_DC)
return stream->eof;
}
-PHPAPI int _php_stream_putc(php_stream *stream, int c TSRMLS_DC)
+PHPAPI int _php_stream_putc(php_stream *stream, int c)
{
unsigned char buf = c;
- if (php_stream_write(stream, &buf, 1) > 0) {
+ if (php_stream_write(stream, (char*)&buf, 1) > 0) {
return 1;
}
return EOF;
}
-PHPAPI int _php_stream_getc(php_stream *stream TSRMLS_DC)
+PHPAPI int _php_stream_getc(php_stream *stream)
{
char buf;
@@ -807,9 +811,9 @@ PHPAPI int _php_stream_getc(php_stream *stream TSRMLS_DC)
return EOF;
}
-PHPAPI int _php_stream_puts(php_stream *stream, const char *buf TSRMLS_DC)
+PHPAPI int _php_stream_puts(php_stream *stream, const char *buf)
{
- int len;
+ size_t len;
char newline[2] = "\n"; /* is this OK for Win? */
len = strlen(buf);
@@ -819,13 +823,13 @@ PHPAPI int _php_stream_puts(php_stream *stream, const char *buf TSRMLS_DC)
return 0;
}
-PHPAPI int _php_stream_stat(php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC)
+PHPAPI int _php_stream_stat(php_stream *stream, php_stream_statbuf *ssb)
{
memset(ssb, 0, sizeof(*ssb));
/* if the stream was wrapped, allow the wrapper to stat it */
if (stream->wrapper && stream->wrapper->wops->stream_stat != NULL) {
- return stream->wrapper->wops->stream_stat(stream->wrapper, stream, ssb TSRMLS_CC);
+ return stream->wrapper->wops->stream_stat(stream->wrapper, stream, ssb);
}
/* if the stream doesn't directly support stat-ing, return with failure.
@@ -836,21 +840,21 @@ PHPAPI int _php_stream_stat(php_stream *stream, php_stream_statbuf *ssb TSRMLS_D
return -1;
}
- return (stream->ops->stat)(stream, ssb TSRMLS_CC);
+ return (stream->ops->stat)(stream, ssb);
}
-PHPAPI const char *php_stream_locate_eol(php_stream *stream, const char *buf, size_t buf_len TSRMLS_DC)
+PHPAPI const char *php_stream_locate_eol(php_stream *stream, zend_string *buf)
{
size_t avail;
const char *cr, *lf, *eol = NULL;
const char *readptr;
if (!buf) {
- readptr = stream->readbuf + stream->readpos;
+ readptr = (char*)stream->readbuf + stream->readpos;
avail = stream->writepos - stream->readpos;
} else {
- readptr = buf;
- avail = buf_len;
+ readptr = buf->val;
+ avail = buf->len;
}
/* Look for EOL */
@@ -882,7 +886,7 @@ PHPAPI const char *php_stream_locate_eol(php_stream *stream, const char *buf, si
* appropriate length to hold the line, regardless of the line length, memory
* permitting */
PHPAPI char *_php_stream_get_line(php_stream *stream, char *buf, size_t maxlen,
- size_t *returned_len TSRMLS_DC)
+ size_t *returned_len)
{
size_t avail = 0;
size_t current_buf_size = 0;
@@ -918,8 +922,8 @@ PHPAPI char *_php_stream_get_line(php_stream *stream, char *buf, size_t maxlen,
const char *eol;
int done = 0;
- readptr = stream->readbuf + stream->readpos;
- eol = php_stream_locate_eol(stream, NULL, 0 TSRMLS_CC);
+ readptr = (char*)stream->readbuf + stream->readpos;
+ eol = php_stream_locate_eol(stream, NULL);
if (eol) {
cpysz = eol - readptr + 1;
@@ -972,7 +976,7 @@ PHPAPI char *_php_stream_get_line(php_stream *stream, char *buf, size_t maxlen,
}
}
- php_stream_fill_read_buffer(stream, toread TSRMLS_CC);
+ php_stream_fill_read_buffer(stream, toread);
if (stream->writepos - stream->readpos == 0) {
break;
@@ -1002,7 +1006,7 @@ static const char *_php_stream_search_delim(php_stream *stream,
size_t maxlen,
size_t skiplen,
const char *delim, /* non-empty! */
- size_t delim_len TSRMLS_DC)
+ size_t delim_len)
{
size_t seek_len;
@@ -1022,13 +1026,13 @@ static const char *_php_stream_search_delim(php_stream *stream,
}
}
-PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *returned_len, const char *delim, size_t delim_len TSRMLS_DC)
+PHPAPI zend_string *php_stream_get_record(php_stream *stream, size_t maxlen, const char *delim, size_t delim_len)
{
- char *ret_buf; /* returned buffer */
+ zend_string *ret_buf; /* returned buffer */
const char *found_delim = NULL;
size_t buffered_len,
tent_ret_len; /* tentative returned length */
- int has_delim = delim_len > 0;
+ int has_delim = delim_len > 0;
if (maxlen == 0) {
return NULL;
@@ -1036,7 +1040,7 @@ PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *re
if (has_delim) {
found_delim = _php_stream_search_delim(
- stream, maxlen, 0, delim, delim_len TSRMLS_CC);
+ stream, maxlen, 0, delim, delim_len);
}
buffered_len = STREAM_BUFFERED_AMOUNT(stream);
@@ -1047,7 +1051,7 @@ PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *re
to_read_now = MIN(maxlen - buffered_len, stream->chunk_size);
- php_stream_fill_read_buffer(stream, buffered_len + to_read_now TSRMLS_CC);
+ php_stream_fill_read_buffer(stream, buffered_len + to_read_now);
just_read = STREAM_BUFFERED_AMOUNT(stream) - buffered_len;
@@ -1062,14 +1066,14 @@ PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *re
* searched for the delimiter.
* The left part of the delimiter may still remain in the buffer,
* so subtract up to <delim_len - 1> from buffered_len, which is
- * the ammount of data we skip on this search as an optimization
+ * the amount of data we skip on this search as an optimization
*/
found_delim = _php_stream_search_delim(
stream, maxlen,
buffered_len >= (delim_len - 1)
? buffered_len - (delim_len - 1)
: 0,
- delim, delim_len TSRMLS_CC);
+ delim, delim_len);
if (found_delim) {
break;
}
@@ -1097,21 +1101,21 @@ PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *re
}
}
- ret_buf = emalloc(tent_ret_len + 1);
+ ret_buf = zend_string_alloc(tent_ret_len, 0);
/* php_stream_read will not call ops->read here because the necessary
* data is guaranteedly buffered */
- *returned_len = php_stream_read(stream, ret_buf, tent_ret_len);
+ ret_buf->len = php_stream_read(stream, ret_buf->val, tent_ret_len);
if (found_delim) {
stream->readpos += delim_len;
stream->position += delim_len;
}
- ret_buf[*returned_len] = '\0';
+ ret_buf->val[ret_buf->len] = '\0';
return ret_buf;
}
/* Writes a buffer directly to a stream, using multiple of the chunk size */
-static size_t _php_stream_write_buffer(php_stream *stream, const char *buf, size_t count TSRMLS_DC)
+static size_t _php_stream_write_buffer(php_stream *stream, const char *buf, size_t count)
{
size_t didwrite = 0, towrite, justwrote;
@@ -1121,7 +1125,7 @@ static size_t _php_stream_write_buffer(php_stream *stream, const char *buf, size
if (stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0 && stream->readpos != stream->writepos) {
stream->readpos = stream->writepos = 0;
- stream->ops->seek(stream, stream->position, SEEK_SET, &stream->position TSRMLS_CC);
+ stream->ops->seek(stream, stream->position, SEEK_SET, &stream->position);
}
@@ -1130,7 +1134,7 @@ static size_t _php_stream_write_buffer(php_stream *stream, const char *buf, size
if (towrite > stream->chunk_size)
towrite = stream->chunk_size;
- justwrote = stream->ops->write(stream, buf, towrite TSRMLS_CC);
+ justwrote = stream->ops->write(stream, buf, towrite);
/* convert justwrote to an integer, since normally it is unsigned */
if ((int)justwrote > 0) {
@@ -1156,7 +1160,7 @@ static size_t _php_stream_write_buffer(php_stream *stream, const char *buf, size
* This may trigger a real write to the stream.
* Returns the number of bytes consumed from buf by the first filter in the chain.
* */
-static size_t _php_stream_write_filtered(php_stream *stream, const char *buf, size_t count, int flags TSRMLS_DC)
+static size_t _php_stream_write_filtered(php_stream *stream, const char *buf, size_t count, int flags)
{
size_t consumed = 0;
php_stream_bucket *bucket;
@@ -1166,15 +1170,15 @@ static size_t _php_stream_write_filtered(php_stream *stream, const char *buf, si
php_stream_filter *filter;
if (buf) {
- bucket = php_stream_bucket_new(stream, (char *)buf, count, 0, 0 TSRMLS_CC);
- php_stream_bucket_append(&brig_in, bucket TSRMLS_CC);
+ bucket = php_stream_bucket_new(stream, (char *)buf, count, 0, 0);
+ php_stream_bucket_append(&brig_in, bucket);
}
for (filter = stream->writefilters.head; filter; filter = filter->next) {
/* for our return value, we are interested in the number of bytes consumed from
* the first filter in the chain */
status = filter->fops->filter(stream, filter, brig_inp, brig_outp,
- filter == stream->writefilters.head ? &consumed : NULL, flags TSRMLS_CC);
+ filter == stream->writefilters.head ? &consumed : NULL, flags);
if (status != PSFS_PASS_ON) {
break;
@@ -1194,14 +1198,14 @@ static size_t _php_stream_write_filtered(php_stream *stream, const char *buf, si
* underlying stream */
while (brig_inp->head) {
bucket = brig_inp->head;
- _php_stream_write_buffer(stream, bucket->buf, bucket->buflen TSRMLS_CC);
+ _php_stream_write_buffer(stream, bucket->buf, bucket->buflen);
/* Potential error situation - eg: no space on device. Perhaps we should keep this brigade
* hanging around and try to write it later.
* At the moment, we just drop it on the floor
* */
- php_stream_bucket_unlink(bucket TSRMLS_CC);
- php_stream_bucket_delref(bucket TSRMLS_CC);
+ php_stream_bucket_unlink(bucket);
+ php_stream_bucket_delref(bucket);
}
break;
case PSFS_FEED_ME:
@@ -1217,35 +1221,35 @@ static size_t _php_stream_write_filtered(php_stream *stream, const char *buf, si
return consumed;
}
-PHPAPI int _php_stream_flush(php_stream *stream, int closing TSRMLS_DC)
+PHPAPI int _php_stream_flush(php_stream *stream, int closing)
{
int ret = 0;
if (stream->writefilters.head) {
- _php_stream_write_filtered(stream, NULL, 0, closing ? PSFS_FLAG_FLUSH_CLOSE : PSFS_FLAG_FLUSH_INC TSRMLS_CC);
+ _php_stream_write_filtered(stream, NULL, 0, closing ? PSFS_FLAG_FLUSH_CLOSE : PSFS_FLAG_FLUSH_INC );
}
if (stream->ops->flush) {
- ret = stream->ops->flush(stream TSRMLS_CC);
+ ret = stream->ops->flush(stream);
}
return ret;
}
-PHPAPI size_t _php_stream_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC)
+PHPAPI size_t _php_stream_write(php_stream *stream, const char *buf, size_t count)
{
if (buf == NULL || count == 0 || stream->ops->write == NULL) {
return 0;
}
if (stream->writefilters.head) {
- return _php_stream_write_filtered(stream, buf, count, PSFS_FLAG_NORMAL TSRMLS_CC);
+ return _php_stream_write_filtered(stream, buf, count, PSFS_FLAG_NORMAL);
} else {
- return _php_stream_write_buffer(stream, buf, count TSRMLS_CC);
+ return _php_stream_write_buffer(stream, buf, count);
}
}
-PHPAPI size_t _php_stream_printf(php_stream *stream TSRMLS_DC, const char *fmt, ...)
+PHPAPI size_t _php_stream_printf(php_stream *stream, const char *fmt, ...)
{
size_t count;
char *buf;
@@ -1265,12 +1269,12 @@ PHPAPI size_t _php_stream_printf(php_stream *stream TSRMLS_DC, const char *fmt,
return count;
}
-PHPAPI off_t _php_stream_tell(php_stream *stream TSRMLS_DC)
+PHPAPI zend_off_t _php_stream_tell(php_stream *stream)
{
return stream->position;
}
-PHPAPI int _php_stream_seek(php_stream *stream, off_t offset, int whence TSRMLS_DC)
+PHPAPI int _php_stream_seek(php_stream *stream, zend_off_t offset, int whence)
{
if (stream->fclose_stdiocast == PHP_STREAM_FCLOSE_FOPENCOOKIE) {
/* flush to commit data written to the fopencookie FILE* */
@@ -1305,7 +1309,7 @@ PHPAPI int _php_stream_seek(php_stream *stream, off_t offset, int whence TSRMLS_
int ret;
if (stream->writefilters.head) {
- _php_stream_flush(stream, 0 TSRMLS_CC);
+ _php_stream_flush(stream, 0);
}
switch(whence) {
@@ -1314,7 +1318,7 @@ PHPAPI int _php_stream_seek(php_stream *stream, off_t offset, int whence TSRMLS_
whence = SEEK_SET;
break;
}
- ret = stream->ops->seek(stream, offset, whence, &stream->position TSRMLS_CC);
+ ret = stream->ops->seek(stream, offset, whence, &stream->position);
if (((stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0) || ret == 0) {
if (ret == 0) {
@@ -1344,23 +1348,24 @@ PHPAPI int _php_stream_seek(php_stream *stream, off_t offset, int whence TSRMLS_
return 0;
}
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "stream does not support seeking");
+ php_error_docref(NULL, E_WARNING, "stream does not support seeking");
return -1;
}
-PHPAPI int _php_stream_set_option(php_stream *stream, int option, int value, void *ptrparam TSRMLS_DC)
+PHPAPI int _php_stream_set_option(php_stream *stream, int option, int value, void *ptrparam)
{
int ret = PHP_STREAM_OPTION_RETURN_NOTIMPL;
if (stream->ops->set_option) {
- ret = stream->ops->set_option(stream, option, value, ptrparam TSRMLS_CC);
+ ret = stream->ops->set_option(stream, option, value, ptrparam);
}
if (ret == PHP_STREAM_OPTION_RETURN_NOTIMPL) {
switch(option) {
case PHP_STREAM_OPTION_SET_CHUNK_SIZE:
- ret = stream->chunk_size;
+ /* XXX chunk size itself is of size_t, that might be ok or not for a particular case*/
+ ret = stream->chunk_size > INT_MAX ? INT_MAX : (int)stream->chunk_size;
stream->chunk_size = value;
return ret;
@@ -1382,16 +1387,16 @@ PHPAPI int _php_stream_set_option(php_stream *stream, int option, int value, voi
return ret;
}
-PHPAPI int _php_stream_truncate_set_size(php_stream *stream, size_t newsize TSRMLS_DC)
+PHPAPI int _php_stream_truncate_set_size(php_stream *stream, size_t newsize)
{
return php_stream_set_option(stream, PHP_STREAM_OPTION_TRUNCATE_API, PHP_STREAM_TRUNCATE_SET_SIZE, &newsize);
}
-PHPAPI size_t _php_stream_passthru(php_stream * stream STREAMS_DC TSRMLS_DC)
+PHPAPI size_t _php_stream_passthru(php_stream * stream STREAMS_DC)
{
size_t bcount = 0;
char buf[8192];
- int b;
+ size_t b;
if (php_stream_mmap_possible(stream)) {
char *p;
@@ -1422,7 +1427,7 @@ PHPAPI size_t _php_stream_passthru(php_stream * stream STREAMS_DC TSRMLS_DC)
}
-PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen, int persistent STREAMS_DC TSRMLS_DC)
+PHPAPI zend_string *_php_stream_copy_to_mem(php_stream *src, size_t maxlen, int persistent STREAMS_DC)
{
size_t ret = 0;
char *ptr;
@@ -1430,9 +1435,10 @@ PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen
int step = CHUNK_SIZE;
int min_room = CHUNK_SIZE / 4;
php_stream_statbuf ssbuf;
+ zend_string *result;
if (maxlen == 0) {
- return 0;
+ return STR_EMPTY_ALLOC();
}
if (maxlen == PHP_STREAM_COPY_ALL) {
@@ -1440,7 +1446,8 @@ PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen
}
if (maxlen > 0) {
- ptr = *buf = pemalloc_rel_orig(maxlen + 1, persistent);
+ result = zend_string_alloc(maxlen, persistent);
+ ptr = result->val;
while ((len < maxlen) && !php_stream_eof(src)) {
ret = php_stream_read(src, ptr, maxlen - len);
if (!ret) {
@@ -1451,11 +1458,12 @@ PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen
}
if (len) {
*ptr = '\0';
+ result->len = len;
} else {
- pefree(*buf, persistent);
- *buf = NULL;
+ zend_string_free(result);
+ result = NULL;
}
- return len;
+ return result;
}
/* avoid many reallocs by allocating a good sized chunk to begin with, if
@@ -1470,30 +1478,32 @@ PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen
max_len = step;
}
- ptr = *buf = pemalloc_rel_orig(max_len, persistent);
+ result = zend_string_alloc(max_len, persistent);
+ ptr = result->val;
- while((ret = php_stream_read(src, ptr, max_len - len))) {
+ while ((ret = php_stream_read(src, ptr, max_len - len))) {
len += ret;
if (len + min_room >= max_len) {
- *buf = perealloc_rel_orig(*buf, max_len + step, persistent);
+ result = zend_string_realloc(result, max_len + step, persistent);
max_len += step;
- ptr = *buf + len;
+ ptr = result->val + len;
} else {
ptr += ret;
}
}
if (len) {
- *buf = perealloc_rel_orig(*buf, len + 1, persistent);
- (*buf)[len] = '\0';
+ result = zend_string_realloc(result, len, persistent);
+ result->val[len] = '\0';
} else {
- pefree(*buf, persistent);
- *buf = NULL;
+ zend_string_free(result);
+ result = NULL;
}
- return len;
+
+ return result;
}
/* Returns SUCCESS/FAILURE and sets *len to the number of bytes moved */
-PHPAPI int _php_stream_copy_to_stream_ex(php_stream *src, php_stream *dest, size_t maxlen, size_t *len STREAMS_DC TSRMLS_DC)
+PHPAPI int _php_stream_copy_to_stream_ex(php_stream *src, php_stream *dest, size_t maxlen, size_t *len STREAMS_DC)
{
char buf[CHUNK_SIZE];
size_t readchunk;
@@ -1600,10 +1610,10 @@ PHPAPI int _php_stream_copy_to_stream_ex(php_stream *src, php_stream *dest, size
* Returns 1 when source len is 0.
* Deprecated in favor of php_stream_copy_to_stream_ex() */
ZEND_ATTRIBUTE_DEPRECATED
-PHPAPI size_t _php_stream_copy_to_stream(php_stream *src, php_stream *dest, size_t maxlen STREAMS_DC TSRMLS_DC)
+PHPAPI size_t _php_stream_copy_to_stream(php_stream *src, php_stream *dest, size_t maxlen STREAMS_DC)
{
size_t len;
- int ret = _php_stream_copy_to_stream_ex(src, dest, maxlen, &len STREAMS_REL_CC TSRMLS_CC);
+ int ret = _php_stream_copy_to_stream_ex(src, dest, maxlen, &len STREAMS_REL_CC);
if (ret == SUCCESS && len == 0 && maxlen != 0) {
return 1;
}
@@ -1613,20 +1623,20 @@ PHPAPI size_t _php_stream_copy_to_stream(php_stream *src, php_stream *dest, size
/* {{{ wrapper init and registration */
-static void stream_resource_regular_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC)
+static void stream_resource_regular_dtor(zend_resource *rsrc)
{
php_stream *stream = (php_stream*)rsrc->ptr;
/* set the return value for pclose */
FG(pclose_ret) = php_stream_free(stream, PHP_STREAM_FREE_CLOSE | PHP_STREAM_FREE_RSRC_DTOR);
}
-static void stream_resource_persistent_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC)
+static void stream_resource_persistent_dtor(zend_resource *rsrc)
{
php_stream *stream = (php_stream*)rsrc->ptr;
FG(pclose_ret) = php_stream_free(stream, PHP_STREAM_FREE_CLOSE | PHP_STREAM_FREE_RSRC_DTOR);
}
-void php_shutdown_stream_hashes(TSRMLS_D)
+void php_shutdown_stream_hashes(void)
{
if (FG(stream_wrappers)) {
zend_hash_destroy(FG(stream_wrappers));
@@ -1639,7 +1649,7 @@ void php_shutdown_stream_hashes(TSRMLS_D)
efree(FG(stream_filters));
FG(stream_filters) = NULL;
}
-
+
if (FG(wrapper_errors)) {
zend_hash_destroy(FG(wrapper_errors));
efree(FG(wrapper_errors));
@@ -1647,7 +1657,7 @@ void php_shutdown_stream_hashes(TSRMLS_D)
}
}
-int php_init_stream_wrappers(int module_number TSRMLS_DC)
+int php_init_stream_wrappers(int module_number)
{
le_stream = zend_register_list_destructors_ex(stream_resource_regular_dtor, NULL, "stream", module_number);
le_pstream = zend_register_list_destructors_ex(NULL, stream_resource_persistent_dtor, "persistent stream", module_number);
@@ -1655,26 +1665,23 @@ int php_init_stream_wrappers(int module_number TSRMLS_DC)
/* Filters are cleaned up by the streams they're attached to */
le_stream_filter = zend_register_list_destructors_ex(NULL, NULL, "stream filter", module_number);
- return (
- zend_hash_init(&url_stream_wrappers_hash, 0, NULL, NULL, 1) == SUCCESS
- &&
- zend_hash_init(php_get_stream_filters_hash_global(), 0, NULL, NULL, 1) == SUCCESS
- &&
- zend_hash_init(php_stream_xport_get_hash(), 0, NULL, NULL, 1) == SUCCESS
- &&
- php_stream_xport_register("tcp", php_stream_generic_socket_factory TSRMLS_CC) == SUCCESS
+ zend_hash_init(&url_stream_wrappers_hash, 8, NULL, NULL, 1);
+ zend_hash_init(php_get_stream_filters_hash_global(), 8, NULL, NULL, 1);
+ zend_hash_init(php_stream_xport_get_hash(), 8, NULL, NULL, 1);
+
+ return (php_stream_xport_register("tcp", php_stream_generic_socket_factory) == SUCCESS
&&
- php_stream_xport_register("udp", php_stream_generic_socket_factory TSRMLS_CC) == SUCCESS
+ php_stream_xport_register("udp", php_stream_generic_socket_factory) == SUCCESS
#if defined(AF_UNIX) && !(defined(PHP_WIN32) || defined(__riscos__) || defined(NETWARE))
&&
- php_stream_xport_register("unix", php_stream_generic_socket_factory TSRMLS_CC) == SUCCESS
+ php_stream_xport_register("unix", php_stream_generic_socket_factory) == SUCCESS
&&
- php_stream_xport_register("udg", php_stream_generic_socket_factory TSRMLS_CC) == SUCCESS
+ php_stream_xport_register("udg", php_stream_generic_socket_factory) == SUCCESS
#endif
) ? SUCCESS : FAILURE;
}
-int php_shutdown_stream_wrappers(int module_number TSRMLS_DC)
+int php_shutdown_stream_wrappers(int module_number)
{
zend_hash_destroy(&url_stream_wrappers_hash);
zend_hash_destroy(php_get_stream_filters_hash_global());
@@ -1702,62 +1709,60 @@ 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 TSRMLS_DC)
+PHPAPI int php_register_url_stream_wrapper(const char *protocol, php_stream_wrapper *wrapper)
{
- unsigned int protocol_len = strlen(protocol);
+ unsigned int protocol_len = (unsigned int)strlen(protocol);
if (php_stream_wrapper_scheme_validate(protocol, protocol_len) == FAILURE) {
return FAILURE;
}
- return zend_hash_add(&url_stream_wrappers_hash, protocol, protocol_len + 1, &wrapper, sizeof(wrapper), NULL);
+ return zend_hash_str_add_ptr(&url_stream_wrappers_hash, protocol, protocol_len, wrapper) ? SUCCESS : FAILURE;
}
-PHPAPI int php_unregister_url_stream_wrapper(const char *protocol TSRMLS_DC)
+PHPAPI int php_unregister_url_stream_wrapper(const char *protocol)
{
- return zend_hash_del(&url_stream_wrappers_hash, protocol, strlen(protocol) + 1);
+ return zend_hash_str_del(&url_stream_wrappers_hash, protocol, strlen(protocol));
}
-static void clone_wrapper_hash(TSRMLS_D)
+static void clone_wrapper_hash(void)
{
- php_stream_wrapper *tmp;
-
ALLOC_HASHTABLE(FG(stream_wrappers));
zend_hash_init(FG(stream_wrappers), zend_hash_num_elements(&url_stream_wrappers_hash), NULL, NULL, 1);
- zend_hash_copy(FG(stream_wrappers), &url_stream_wrappers_hash, NULL, &tmp, sizeof(tmp));
+ 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 TSRMLS_DC)
+PHPAPI int php_register_url_stream_wrapper_volatile(const char *protocol, php_stream_wrapper *wrapper)
{
- unsigned int protocol_len = strlen(protocol);
+ unsigned int protocol_len = (unsigned int)strlen(protocol);
if (php_stream_wrapper_scheme_validate(protocol, protocol_len) == FAILURE) {
return FAILURE;
}
if (!FG(stream_wrappers)) {
- clone_wrapper_hash(TSRMLS_C);
+ clone_wrapper_hash();
}
- return zend_hash_add(FG(stream_wrappers), protocol, protocol_len + 1, &wrapper, sizeof(wrapper), NULL);
+ return zend_hash_str_add_ptr(FG(stream_wrappers), protocol, protocol_len, wrapper) ? SUCCESS : FAILURE;
}
-PHPAPI int php_unregister_url_stream_wrapper_volatile(const char *protocol TSRMLS_DC)
+PHPAPI int php_unregister_url_stream_wrapper_volatile(const char *protocol)
{
if (!FG(stream_wrappers)) {
- clone_wrapper_hash(TSRMLS_C);
+ clone_wrapper_hash();
}
- return zend_hash_del(FG(stream_wrappers), protocol, strlen(protocol) + 1);
+ return zend_hash_str_del(FG(stream_wrappers), protocol, strlen(protocol));
}
/* }}} */
/* {{{ php_stream_locate_url_wrapper */
-PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const char **path_for_open, int options TSRMLS_DC)
+PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const char **path_for_open, int options)
{
HashTable *wrapper_hash = (FG(stream_wrappers) ? FG(stream_wrappers) : &url_stream_wrappers_hash);
- php_stream_wrapper **wrapperpp = NULL;
+ php_stream_wrapper *wrapper = NULL;
const char *p, *protocol = NULL;
int n = 0;
@@ -1779,14 +1784,14 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const
/* BC with older php scripts and zlib wrapper */
protocol = "compress.zlib";
n = 13;
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Use of \"zlib:\" wrapper is deprecated; please use \"compress.zlib://\" instead");
+ php_error_docref(NULL, E_WARNING, "Use of \"zlib:\" wrapper is deprecated; please use \"compress.zlib://\" instead");
}
if (protocol) {
char *tmp = estrndup(protocol, n);
- if (FAILURE == zend_hash_find(wrapper_hash, (char*)tmp, n + 1, (void**)&wrapperpp)) {
+ if (NULL == (wrapper = zend_hash_str_find_ptr(wrapper_hash, (char*)tmp, n))) {
php_strtolower(tmp, n);
- if (FAILURE == zend_hash_find(wrapper_hash, (char*)tmp, n + 1, (void**)&wrapperpp)) {
+ if (NULL == (wrapper = zend_hash_str_find_ptr(wrapper_hash, (char*)tmp, n))) {
char wrapper_name[32];
if (n >= sizeof(wrapper_name)) {
@@ -1794,9 +1799,9 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const
}
PHP_STRLCPY(wrapper_name, protocol, sizeof(wrapper_name), n);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find the wrapper \"%s\" - did you forget to enable it when you configured PHP?", wrapper_name);
+ php_error_docref(NULL, E_WARNING, "Unable to find the wrapper \"%s\" - did you forget to enable it when you configured PHP?", wrapper_name);
- wrapperpp = NULL;
+ wrapper = NULL;
protocol = NULL;
}
}
@@ -1820,7 +1825,7 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const
if (localhost == 0 && path[n+3] != '\0' && path[n+3] != '/') {
#endif
if (options & REPORT_ERRORS) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "remote host file access not supported, %s", path);
+ php_error_docref(NULL, E_WARNING, "remote host file access not supported, %s", path);
}
return NULL;
}
@@ -1846,18 +1851,18 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const
if (FG(stream_wrappers)) {
/* The file:// wrapper may have been disabled/overridden */
- if (wrapperpp) {
+ if (wrapper) {
/* It was found so go ahead and provide it */
- return *wrapperpp;
+ return wrapper;
}
/* Check again, the original check might have not known the protocol name */
- if (zend_hash_find(wrapper_hash, "file", sizeof("file"), (void**)&wrapperpp) == SUCCESS) {
- return *wrapperpp;
+ if ((wrapper = zend_hash_str_find_ptr(wrapper_hash, "file", sizeof("file")-1)) != NULL) {
+ return wrapper;
}
if (options & REPORT_ERRORS) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "file:// wrapper is disabled in the server configuration");
+ php_error_docref(NULL, E_WARNING, "file:// wrapper is disabled in the server configuration");
}
return NULL;
}
@@ -1865,7 +1870,7 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const
return plain_files_wrapper;
}
- if (wrapperpp && (*wrapperpp)->is_url &&
+ if (wrapper && wrapper->is_url &&
(options & STREAM_DISABLE_URL_PROTECTION) == 0 &&
(!PG(allow_url_fopen) ||
(((options & STREAM_OPEN_FOR_INCLUDE) ||
@@ -1874,51 +1879,51 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const
/* protocol[n] probably isn't '\0' */
char *protocol_dup = estrndup(protocol, n);
if (!PG(allow_url_fopen)) {
- php_error_docref(NULL TSRMLS_CC, 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", protocol_dup);
} else {
- php_error_docref(NULL TSRMLS_CC, 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", protocol_dup);
}
efree(protocol_dup);
}
return NULL;
}
- return *wrapperpp;
+ return wrapper;
}
/* }}} */
/* {{{ _php_stream_mkdir
*/
-PHPAPI int _php_stream_mkdir(const char *path, int mode, int options, php_stream_context *context TSRMLS_DC)
+PHPAPI int _php_stream_mkdir(const char *path, int mode, int options, php_stream_context *context)
{
php_stream_wrapper *wrapper = NULL;
- wrapper = php_stream_locate_url_wrapper(path, NULL, 0 TSRMLS_CC);
+ wrapper = php_stream_locate_url_wrapper(path, NULL, 0);
if (!wrapper || !wrapper->wops || !wrapper->wops->stream_mkdir) {
return 0;
}
- return wrapper->wops->stream_mkdir(wrapper, path, mode, options, context TSRMLS_CC);
+ return wrapper->wops->stream_mkdir(wrapper, path, mode, options, context);
}
/* }}} */
/* {{{ _php_stream_rmdir
*/
-PHPAPI int _php_stream_rmdir(const char *path, int options, php_stream_context *context TSRMLS_DC)
+PHPAPI int _php_stream_rmdir(const char *path, int options, php_stream_context *context)
{
php_stream_wrapper *wrapper = NULL;
- wrapper = php_stream_locate_url_wrapper(path, NULL, 0 TSRMLS_CC);
+ wrapper = php_stream_locate_url_wrapper(path, NULL, 0);
if (!wrapper || !wrapper->wops || !wrapper->wops->stream_rmdir) {
return 0;
}
- return wrapper->wops->stream_rmdir(wrapper, path, options, context TSRMLS_CC);
+ return wrapper->wops->stream_rmdir(wrapper, path, options, context);
}
/* }}} */
/* {{{ _php_stream_stat_path */
-PHPAPI int _php_stream_stat_path(const char *path, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC)
+PHPAPI int _php_stream_stat_path(const char *path, int flags, php_stream_statbuf *ssb, php_stream_context *context)
{
php_stream_wrapper *wrapper = NULL;
const char *path_to_open = path;
@@ -1939,9 +1944,9 @@ PHPAPI int _php_stream_stat_path(const char *path, int flags, php_stream_statbuf
}
}
- wrapper = php_stream_locate_url_wrapper(path, &path_to_open, 0 TSRMLS_CC);
+ wrapper = php_stream_locate_url_wrapper(path, &path_to_open, 0);
if (wrapper && wrapper->wops->url_stat) {
- ret = wrapper->wops->url_stat(wrapper, path_to_open, flags, ssb, context TSRMLS_CC);
+ ret = wrapper->wops->url_stat(wrapper, path_to_open, flags, ssb, context);
if (ret == 0) {
if (!(flags & PHP_STREAM_URL_STAT_NOCACHE)) {
/* Drop into cache */
@@ -1968,7 +1973,7 @@ PHPAPI int _php_stream_stat_path(const char *path, int flags, php_stream_statbuf
/* {{{ php_stream_opendir */
PHPAPI php_stream *_php_stream_opendir(const char *path, int options,
- php_stream_context *context STREAMS_DC TSRMLS_DC)
+ php_stream_context *context STREAMS_DC)
{
php_stream *stream = NULL;
php_stream_wrapper *wrapper = NULL;
@@ -1980,31 +1985,31 @@ PHPAPI php_stream *_php_stream_opendir(const char *path, int options,
path_to_open = path;
- wrapper = php_stream_locate_url_wrapper(path, &path_to_open, options TSRMLS_CC);
+ wrapper = php_stream_locate_url_wrapper(path, &path_to_open, options);
if (wrapper && wrapper->wops->dir_opener) {
stream = wrapper->wops->dir_opener(wrapper,
path_to_open, "r", options ^ REPORT_ERRORS, NULL,
- context STREAMS_REL_CC TSRMLS_CC);
+ context STREAMS_REL_CC);
if (stream) {
stream->wrapper = wrapper;
stream->flags |= PHP_STREAM_FLAG_NO_BUFFER | PHP_STREAM_FLAG_IS_DIR;
}
} else if (wrapper) {
- php_stream_wrapper_log_error(wrapper, options ^ REPORT_ERRORS TSRMLS_CC, "not implemented");
+ php_stream_wrapper_log_error(wrapper, options ^ REPORT_ERRORS, "not implemented");
}
if (stream == NULL && (options & REPORT_ERRORS)) {
- php_stream_display_wrapper_errors(wrapper, path, "failed to open dir" TSRMLS_CC);
+ php_stream_display_wrapper_errors(wrapper, path, "failed to open dir");
}
- php_stream_tidy_wrapper_error_log(wrapper TSRMLS_CC);
+ php_stream_tidy_wrapper_error_log(wrapper);
return stream;
}
/* }}} */
/* {{{ _php_stream_readdir */
-PHPAPI php_stream_dirent *_php_stream_readdir(php_stream *dirstream, php_stream_dirent *ent TSRMLS_DC)
+PHPAPI php_stream_dirent *_php_stream_readdir(php_stream *dirstream, php_stream_dirent *ent)
{
if (sizeof(php_stream_dirent) == php_stream_read(dirstream, (char*)ent, sizeof(php_stream_dirent))) {
@@ -2017,7 +2022,7 @@ PHPAPI php_stream_dirent *_php_stream_readdir(php_stream *dirstream, php_stream_
/* {{{ php_stream_open_wrapper_ex */
PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mode, int options,
- char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC)
+ char **opened_path, php_stream_context *context STREAMS_DC)
{
php_stream *stream = NULL;
php_stream_wrapper *wrapper = NULL;
@@ -2031,12 +2036,12 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod
}
if (!path || !*path) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Filename cannot be empty");
+ php_error_docref(NULL, E_WARNING, "Filename cannot be empty");
return NULL;
}
if (options & USE_PATH) {
- resolved_path = zend_resolve_path(path, strlen(path) TSRMLS_CC);
+ resolved_path = zend_resolve_path(path, (int)strlen(path));
if (resolved_path) {
path = resolved_path;
/* we've found this file, don't re-check include_path or run realpath */
@@ -2047,9 +2052,9 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod
path_to_open = path;
- wrapper = php_stream_locate_url_wrapper(path, &path_to_open, options TSRMLS_CC);
+ wrapper = php_stream_locate_url_wrapper(path, &path_to_open, options);
if (options & STREAM_USE_URL && (!wrapper || !wrapper->is_url)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "This function may only be used against URLs");
+ php_error_docref(NULL, E_WARNING, "This function may only be used against URLs");
if (resolved_path) {
efree(resolved_path);
}
@@ -2058,18 +2063,18 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod
if (wrapper) {
if (!wrapper->wops->stream_opener) {
- php_stream_wrapper_log_error(wrapper, options ^ REPORT_ERRORS TSRMLS_CC,
+ php_stream_wrapper_log_error(wrapper, options ^ REPORT_ERRORS,
"wrapper does not support stream open");
} else {
stream = wrapper->wops->stream_opener(wrapper,
path_to_open, mode, options ^ REPORT_ERRORS,
- opened_path, context STREAMS_REL_CC TSRMLS_CC);
+ opened_path, context STREAMS_REL_CC);
}
/* if the caller asked for a persistent stream but the wrapper did not
* return one, force an error here */
if (stream && (options & STREAM_OPEN_PERSISTENT) && !stream->is_persistent) {
- php_stream_wrapper_log_error(wrapper, options ^ REPORT_ERRORS TSRMLS_CC,
+ php_stream_wrapper_log_error(wrapper, options ^ REPORT_ERRORS,
"wrapper does not support persistent streams");
php_stream_close(stream);
stream = NULL;
@@ -2122,7 +2127,7 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod
if (options & REPORT_ERRORS) {
char *tmp = estrdup(path);
php_strip_url_passwd(tmp);
- php_error_docref1(NULL TSRMLS_CC, tmp, E_WARNING, "could not make seekable - %s",
+ php_error_docref1(NULL, tmp, E_WARNING, "could not make seekable - %s",
tmp);
efree(tmp);
@@ -2132,22 +2137,22 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod
}
if (stream && stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0 && strchr(mode, 'a') && stream->position == 0) {
- off_t newpos = 0;
+ zend_off_t newpos = 0;
/* if opened for append, we need to revise our idea of the initial file position */
- if (0 == stream->ops->seek(stream, 0, SEEK_CUR, &newpos TSRMLS_CC)) {
+ if (0 == stream->ops->seek(stream, 0, SEEK_CUR, &newpos)) {
stream->position = newpos;
}
}
if (stream == NULL && (options & REPORT_ERRORS)) {
- php_stream_display_wrapper_errors(wrapper, path, "failed to open stream" TSRMLS_CC);
+ php_stream_display_wrapper_errors(wrapper, path, "failed to open stream");
if (opened_path && *opened_path) {
efree(*opened_path);
*opened_path = NULL;
}
}
- php_stream_tidy_wrapper_error_log(wrapper TSRMLS_CC);
+ php_stream_tidy_wrapper_error_log(wrapper);
#if ZEND_DEBUG
if (stream == NULL && copy_of_path != NULL) {
pefree(copy_of_path, persistent);
@@ -2163,33 +2168,33 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod
/* {{{ context API */
PHPAPI php_stream_context *php_stream_context_set(php_stream *stream, php_stream_context *context)
{
- php_stream_context *oldcontext = stream->context;
- TSRMLS_FETCH();
-
- stream->context = context;
+ php_stream_context *oldcontext = PHP_STREAM_CONTEXT(stream);
if (context) {
- zend_list_addref(context->rsrc_id);
+ stream->ctx = context->res;
+ GC_REFCOUNT(context->res)++;
+ } else {
+ stream->ctx = NULL;
}
if (oldcontext) {
- zend_list_delete(oldcontext->rsrc_id);
+ zend_list_delete(oldcontext->res);
}
return oldcontext;
}
PHPAPI void php_stream_notification_notify(php_stream_context *context, int notifycode, int severity,
- char *xmsg, int xcode, size_t bytes_sofar, size_t bytes_max, void * ptr TSRMLS_DC)
+ char *xmsg, int xcode, size_t bytes_sofar, size_t bytes_max, void * ptr)
{
if (context && context->notifier)
- context->notifier->func(context, notifycode, severity, xmsg, xcode, bytes_sofar, bytes_max, ptr TSRMLS_CC);
+ context->notifier->func(context, notifycode, severity, xmsg, xcode, bytes_sofar, bytes_max, ptr);
}
PHPAPI void php_stream_context_free(php_stream_context *context)
{
- if (context->options) {
+ if (Z_TYPE(context->options) != IS_UNDEF) {
zval_ptr_dtor(&context->options);
- context->options = NULL;
+ ZVAL_UNDEF(&context->options);
}
if (context->notifier) {
php_stream_notification_free(context->notifier);
@@ -2198,16 +2203,15 @@ PHPAPI void php_stream_context_free(php_stream_context *context)
efree(context);
}
-PHPAPI php_stream_context *php_stream_context_alloc(TSRMLS_D)
+PHPAPI php_stream_context *php_stream_context_alloc(void)
{
php_stream_context *context;
context = ecalloc(1, sizeof(php_stream_context));
context->notifier = NULL;
- MAKE_STD_ZVAL(context->options);
- array_init(context->options);
+ array_init(&context->options);
- context->rsrc_id = ZEND_REGISTER_RESOURCE(NULL, context, php_le_stream_context(TSRMLS_C));
+ context->res = ZEND_REGISTER_RESOURCE(NULL, context, php_le_stream_context());
return context;
}
@@ -2224,65 +2228,61 @@ PHPAPI void php_stream_notification_free(php_stream_notifier *notifier)
efree(notifier);
}
-PHPAPI int php_stream_context_get_option(php_stream_context *context,
- const char *wrappername, const char *optionname, zval ***optionvalue)
+PHPAPI zval *php_stream_context_get_option(php_stream_context *context,
+ const char *wrappername, const char *optionname)
{
- zval **wrapperhash;
+ zval *wrapperhash;
- if (FAILURE == zend_hash_find(Z_ARRVAL_P(context->options), (char*)wrappername, strlen(wrappername)+1, (void**)&wrapperhash)) {
- return FAILURE;
+ if (NULL == (wrapperhash = zend_hash_str_find(Z_ARRVAL(context->options), wrappername, strlen(wrappername)))) {
+ return NULL;
}
- return zend_hash_find(Z_ARRVAL_PP(wrapperhash), (char*)optionname, strlen(optionname)+1, (void**)optionvalue);
+ return zend_hash_str_find(Z_ARRVAL_P(wrapperhash), optionname, strlen(optionname));
}
PHPAPI int php_stream_context_set_option(php_stream_context *context,
const char *wrappername, const char *optionname, zval *optionvalue)
{
- zval **wrapperhash;
- zval *category, *copied_val;
+ zval *wrapperhash;
+ zval category, copied_val;
- ALLOC_INIT_ZVAL(copied_val);
- *copied_val = *optionvalue;
- zval_copy_ctor(copied_val);
- INIT_PZVAL(copied_val);
+ ZVAL_DUP(&copied_val, optionvalue);
- if (FAILURE == zend_hash_find(Z_ARRVAL_P(context->options), (char*)wrappername, strlen(wrappername)+1, (void**)&wrapperhash)) {
- MAKE_STD_ZVAL(category);
- array_init(category);
- if (FAILURE == zend_hash_update(Z_ARRVAL_P(context->options), (char*)wrappername, strlen(wrappername)+1, (void**)&category, sizeof(zval *), NULL)) {
+ if (NULL == (wrapperhash = zend_hash_str_find(Z_ARRVAL(context->options), wrappername, strlen(wrappername)))) {
+ array_init(&category);
+ if (NULL == zend_hash_str_update(Z_ARRVAL(context->options), (char*)wrappername, strlen(wrappername), &category)) {
return FAILURE;
}
wrapperhash = &category;
}
- return zend_hash_update(Z_ARRVAL_PP(wrapperhash), (char*)optionname, strlen(optionname)+1, (void**)&copied_val, sizeof(zval *), NULL);
+ return zend_hash_str_update(Z_ARRVAL_P(wrapperhash), optionname, strlen(optionname), &copied_val) ? SUCCESS : FAILURE;
}
/* }}} */
/* {{{ php_stream_dirent_alphasort
*/
-PHPAPI int php_stream_dirent_alphasort(const char **a, const char **b)
+PHPAPI int php_stream_dirent_alphasort(const zend_string **a, const zend_string **b)
{
- return strcoll(*a, *b);
+ return strcoll((*a)->val, (*b)->val);
}
/* }}} */
/* {{{ php_stream_dirent_alphasortr
*/
-PHPAPI int php_stream_dirent_alphasortr(const char **a, const char **b)
+PHPAPI int php_stream_dirent_alphasortr(const zend_string **a, const zend_string **b)
{
- return strcoll(*b, *a);
+ return strcoll((*b)->val, (*a)->val);
}
/* }}} */
/* {{{ php_stream_scandir
*/
-PHPAPI int _php_stream_scandir(const char *dirname, char **namelist[], int flags, php_stream_context *context,
- int (*compare) (const char **a, const char **b) TSRMLS_DC)
+PHPAPI int _php_stream_scandir(const char *dirname, zend_string **namelist[], int flags, php_stream_context *context,
+ int (*compare) (const zend_string **a, const zend_string **b))
{
php_stream *stream;
php_stream_dirent sdp;
- char **vector = NULL;
+ zend_string **vector = NULL;
unsigned int vector_size = 0;
unsigned int nfiles = 0;
@@ -2308,10 +2308,10 @@ PHPAPI int _php_stream_scandir(const char *dirname, char **namelist[], int flags
}
vector_size *= 2;
}
- vector = (char **) safe_erealloc(vector, vector_size, sizeof(char *), 0);
+ vector = (zend_string **) safe_erealloc(vector, vector_size, sizeof(char *), 0);
}
- vector[nfiles] = estrdup(sdp.d_name);
+ vector[nfiles] = zend_string_init(sdp.d_name, strlen(sdp.d_name), 0);
nfiles++;
if(vector_size < 10 || nfiles == 0) {
@@ -2326,7 +2326,7 @@ PHPAPI int _php_stream_scandir(const char *dirname, char **namelist[], int flags
*namelist = vector;
if (nfiles > 0 && compare) {
- qsort(*namelist, nfiles, sizeof(char *), (int(*)(const void *, const void *))compare);
+ qsort(*namelist, nfiles, sizeof(zend_string *), (int(*)(const void *, const void *))compare);
}
return nfiles;
}
diff --git a/main/streams/transports.c b/main/streams/transports.c
index c125f56a6a..4c3fc8b789 100644
--- a/main/streams/transports.c
+++ b/main/streams/transports.c
@@ -1,8 +1,8 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2015 The PHP Group |
+ | Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -29,50 +29,50 @@ PHPAPI HashTable *php_stream_xport_get_hash(void)
return &xport_hash;
}
-PHPAPI int php_stream_xport_register(const char *protocol, php_stream_transport_factory factory TSRMLS_DC)
+PHPAPI int php_stream_xport_register(const char *protocol, php_stream_transport_factory factory)
{
- return zend_hash_update(&xport_hash, protocol, strlen(protocol) + 1, &factory, sizeof(factory), NULL);
+ return zend_hash_str_update_ptr(&xport_hash, protocol, strlen(protocol), factory) ? SUCCESS : FAILURE;
}
-PHPAPI int php_stream_xport_unregister(const char *protocol TSRMLS_DC)
+PHPAPI int php_stream_xport_unregister(const char *protocol)
{
- return zend_hash_del(&xport_hash, protocol, strlen(protocol) + 1);
+ return zend_hash_str_del(&xport_hash, protocol, strlen(protocol));
}
#define ERR_REPORT(out_err, fmt, arg) \
- if (out_err) { spprintf(out_err, 0, fmt, arg); } \
- else { php_error_docref(NULL TSRMLS_CC, E_WARNING, fmt, arg); }
+ if (out_err) { *out_err = strpprintf(0, fmt, arg); } \
+ else { php_error_docref(NULL, E_WARNING, fmt, arg); }
#define ERR_RETURN(out_err, local_err, fmt) \
if (out_err) { *out_err = local_err; } \
- else { php_error_docref(NULL TSRMLS_CC, E_WARNING, fmt, local_err ? local_err : "Unspecified error"); \
- if (local_err) { efree(local_err); local_err = NULL; } \
+ else { php_error_docref(NULL, E_WARNING, fmt, local_err ? local_err->val : "Unspecified error"); \
+ if (local_err) { zend_string_release(local_err); local_err = NULL; } \
}
-
+
PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, int options,
int flags, const char *persistent_id,
struct timeval *timeout,
php_stream_context *context,
- char **error_string,
+ zend_string **error_string,
int *error_code
- STREAMS_DC TSRMLS_DC)
+ STREAMS_DC)
{
php_stream *stream = NULL;
- php_stream_transport_factory *factory = NULL;
+ php_stream_transport_factory factory = NULL;
const char *p, *protocol = NULL;
int n = 0, failed = 0;
- char *error_text = NULL;
+ zend_string *error_text = NULL;
struct timeval default_timeout = { 0, 0 };
-
+
default_timeout.tv_sec = FG(default_socket_timeout);
if (timeout == NULL) {
timeout = &default_timeout;
}
-
+
/* check for a cached persistent socket */
if (persistent_id) {
- switch(php_stream_from_persistent_id(persistent_id, &stream TSRMLS_CC)) {
+ switch(php_stream_from_persistent_id(persistent_id, &stream)) {
case PHP_STREAM_PERSISTENT_SUCCESS:
/* use a 0 second timeout when checking if the socket
* has already died */
@@ -107,13 +107,13 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, in
if (protocol) {
char *tmp = estrndup(protocol, n);
- if (FAILURE == zend_hash_find(&xport_hash, (char*)tmp, n + 1, (void**)&factory)) {
+ if (NULL == (factory = zend_hash_str_find_ptr(&xport_hash, tmp, n))) {
char wrapper_name[32];
if (n >= sizeof(wrapper_name))
n = sizeof(wrapper_name) - 1;
PHP_STRLCPY(wrapper_name, protocol, sizeof(wrapper_name), n);
-
+
ERR_REPORT(error_string, "Unable to find the socket transport \"%s\" - did you forget to enable it when you configured PHP?",
wrapper_name);
@@ -125,13 +125,13 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, in
if (factory == NULL) {
/* should never happen */
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not find a factory !?");
+ php_error_docref(NULL, E_WARNING, "Could not find a factory !?");
return NULL;
}
- stream = (*factory)(protocol, n,
+ stream = (factory)(protocol, n,
(char*)name, namelen, persistent_id, options, flags, timeout,
- context STREAMS_REL_CC TSRMLS_CC);
+ context STREAMS_REL_CC);
if (stream) {
php_stream_context_set(stream, context);
@@ -142,7 +142,7 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, in
if (flags & (STREAM_XPORT_CONNECT|STREAM_XPORT_CONNECT_ASYNC)) {
if (-1 == php_stream_xport_connect(stream, name, namelen,
flags & STREAM_XPORT_CONNECT_ASYNC ? 1 : 0,
- timeout, &error_text, error_code TSRMLS_CC)) {
+ timeout, &error_text, error_code)) {
ERR_RETURN(error_string, error_text, "connect() failed: %s");
@@ -153,24 +153,24 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, in
} else {
/* server */
if (flags & STREAM_XPORT_BIND) {
- if (0 != php_stream_xport_bind(stream, name, namelen, &error_text TSRMLS_CC)) {
+ if (0 != php_stream_xport_bind(stream, name, namelen, &error_text)) {
ERR_RETURN(error_string, error_text, "bind() failed: %s");
failed = 1;
} else if (flags & STREAM_XPORT_LISTEN) {
- zval **zbacklog = NULL;
+ zval *zbacklog = NULL;
int backlog = 32;
-
- if (stream->context && php_stream_context_get_option(stream->context, "socket", "backlog", &zbacklog) == SUCCESS) {
- zval *ztmp = *zbacklog;
-
- convert_to_long_ex(&ztmp);
+
+ if (PHP_STREAM_CONTEXT(stream) && (zbacklog = php_stream_context_get_option(PHP_STREAM_CONTEXT(stream), "socket", "backlog")) != NULL) {
+ zval *ztmp = zbacklog;
+
+ convert_to_long_ex(ztmp);
backlog = Z_LVAL_P(ztmp);
- if (ztmp != *zbacklog) {
- zval_ptr_dtor(&ztmp);
+ if (ztmp != zbacklog) {
+ zval_ptr_dtor(ztmp);
}
}
-
- if (0 != php_stream_xport_listen(stream, backlog, &error_text TSRMLS_CC)) {
+
+ if (0 != php_stream_xport_listen(stream, backlog, &error_text)) {
ERR_RETURN(error_string, error_text, "listen() failed: %s");
failed = 1;
}
@@ -195,12 +195,12 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, in
/* Bind the stream to a local address */
PHPAPI int php_stream_xport_bind(php_stream *stream,
const char *name, size_t namelen,
- char **error_text
- TSRMLS_DC)
+ zend_string **error_text
+ )
{
php_stream_xport_param param;
int ret;
-
+
memset(&param, 0, sizeof(param));
param.op = STREAM_XPORT_OP_BIND;
param.inputs.name = (char*)name;
@@ -225,13 +225,13 @@ PHPAPI int php_stream_xport_connect(php_stream *stream,
const char *name, size_t namelen,
int asynchronous,
struct timeval *timeout,
- char **error_text,
+ zend_string **error_text,
int *error_code
- TSRMLS_DC)
+ )
{
php_stream_xport_param param;
int ret;
-
+
memset(&param, 0, sizeof(param));
param.op = asynchronous ? STREAM_XPORT_OP_CONNECT_ASYNC: STREAM_XPORT_OP_CONNECT;
param.inputs.name = (char*)name;
@@ -239,7 +239,7 @@ PHPAPI int php_stream_xport_connect(php_stream *stream,
param.inputs.timeout = timeout;
param.want_errortext = error_text ? 1 : 0;
-
+
ret = php_stream_set_option(stream, PHP_STREAM_OPTION_XPORT_API, 0, &param);
if (ret == PHP_STREAM_OPTION_RETURN_OK) {
@@ -257,16 +257,16 @@ PHPAPI int php_stream_xport_connect(php_stream *stream,
}
/* Prepare to listen */
-PHPAPI int php_stream_xport_listen(php_stream *stream, int backlog, char **error_text TSRMLS_DC)
+PHPAPI int php_stream_xport_listen(php_stream *stream, int backlog, zend_string **error_text)
{
php_stream_xport_param param;
int ret;
-
+
memset(&param, 0, sizeof(param));
param.op = STREAM_XPORT_OP_LISTEN;
param.inputs.backlog = backlog;
param.want_errortext = error_text ? 1 : 0;
-
+
ret = php_stream_set_option(stream, PHP_STREAM_OPTION_XPORT_API, 0, &param);
if (ret == PHP_STREAM_OPTION_RETURN_OK) {
@@ -282,11 +282,11 @@ PHPAPI int php_stream_xport_listen(php_stream *stream, int backlog, char **error
/* Get the next client and their address (as a string) */
PHPAPI int php_stream_xport_accept(php_stream *stream, php_stream **client,
- char **textaddr, int *textaddrlen,
+ zend_string **textaddr,
void **addr, socklen_t *addrlen,
struct timeval *timeout,
- char **error_text
- TSRMLS_DC)
+ zend_string **error_text
+ )
{
php_stream_xport_param param;
int ret;
@@ -298,7 +298,7 @@ PHPAPI int php_stream_xport_accept(php_stream *stream, php_stream **client,
param.want_addr = addr ? 1 : 0;
param.want_textaddr = textaddr ? 1 : 0;
param.want_errortext = error_text ? 1 : 0;
-
+
ret = php_stream_set_option(stream, PHP_STREAM_OPTION_XPORT_API, 0, &param);
if (ret == PHP_STREAM_OPTION_RETURN_OK) {
@@ -309,7 +309,6 @@ PHPAPI int php_stream_xport_accept(php_stream *stream, php_stream **client,
}
if (textaddr) {
*textaddr = param.outputs.textaddr;
- *textaddrlen = param.outputs.textaddrlen;
}
if (error_text) {
*error_text = param.outputs.error_text;
@@ -321,9 +320,9 @@ PHPAPI int php_stream_xport_accept(php_stream *stream, php_stream **client,
}
PHPAPI int php_stream_xport_get_name(php_stream *stream, int want_peer,
- char **textaddr, int *textaddrlen,
+ zend_string **textaddr,
void **addr, socklen_t *addrlen
- TSRMLS_DC)
+ )
{
php_stream_xport_param param;
int ret;
@@ -333,7 +332,7 @@ PHPAPI int php_stream_xport_get_name(php_stream *stream, int want_peer,
param.op = want_peer ? STREAM_XPORT_OP_GET_PEER_NAME : STREAM_XPORT_OP_GET_NAME;
param.want_addr = addr ? 1 : 0;
param.want_textaddr = textaddr ? 1 : 0;
-
+
ret = php_stream_set_option(stream, PHP_STREAM_OPTION_XPORT_API, 0, &param);
if (ret == PHP_STREAM_OPTION_RETURN_OK) {
@@ -343,7 +342,6 @@ PHPAPI int php_stream_xport_get_name(php_stream *stream, int want_peer,
}
if (textaddr) {
*textaddr = param.outputs.textaddr;
- *textaddrlen = param.outputs.textaddrlen;
}
return param.outputs.returncode;
@@ -351,7 +349,7 @@ PHPAPI int php_stream_xport_get_name(php_stream *stream, int want_peer,
return ret;
}
-PHPAPI int php_stream_xport_crypto_setup(php_stream *stream, php_stream_xport_crypt_method_t crypto_method, php_stream *session_stream TSRMLS_DC)
+PHPAPI int php_stream_xport_crypto_setup(php_stream *stream, php_stream_xport_crypt_method_t crypto_method, php_stream *session_stream)
{
php_stream_xport_crypto_param param;
int ret;
@@ -360,19 +358,19 @@ PHPAPI int php_stream_xport_crypto_setup(php_stream *stream, php_stream_xport_cr
param.op = STREAM_XPORT_CRYPTO_OP_SETUP;
param.inputs.method = crypto_method;
param.inputs.session = session_stream;
-
+
ret = php_stream_set_option(stream, PHP_STREAM_OPTION_CRYPTO_API, 0, &param);
if (ret == PHP_STREAM_OPTION_RETURN_OK) {
return param.outputs.returncode;
}
- php_error_docref("streams.crypto" TSRMLS_CC, E_WARNING, "this stream does not support SSL/crypto");
-
+ php_error_docref("streams.crypto", E_WARNING, "this stream does not support SSL/crypto");
+
return ret;
}
-PHPAPI int php_stream_xport_crypto_enable(php_stream *stream, int activate TSRMLS_DC)
+PHPAPI int php_stream_xport_crypto_enable(php_stream *stream, int activate)
{
php_stream_xport_crypto_param param;
int ret;
@@ -380,23 +378,23 @@ PHPAPI int php_stream_xport_crypto_enable(php_stream *stream, int activate TSRML
memset(&param, 0, sizeof(param));
param.op = STREAM_XPORT_CRYPTO_OP_ENABLE;
param.inputs.activate = activate;
-
+
ret = php_stream_set_option(stream, PHP_STREAM_OPTION_CRYPTO_API, 0, &param);
if (ret == PHP_STREAM_OPTION_RETURN_OK) {
return param.outputs.returncode;
}
- php_error_docref("streams.crypto" TSRMLS_CC, E_WARNING, "this stream does not support SSL/crypto");
-
+ php_error_docref("streams.crypto", E_WARNING, "this stream does not support SSL/crypto");
+
return ret;
}
/* Similar to recv() system call; read data from the stream, optionally
* peeking, optionally retrieving OOB data */
PHPAPI int php_stream_xport_recvfrom(php_stream *stream, char *buf, size_t buflen,
- long flags, void **addr, socklen_t *addrlen, char **textaddr, int *textaddrlen
- TSRMLS_DC)
+ int flags, void **addr, socklen_t *addrlen, zend_string **textaddr
+ )
{
php_stream_xport_param param;
int ret = 0;
@@ -409,10 +407,10 @@ PHPAPI int php_stream_xport_recvfrom(php_stream *stream, char *buf, size_t bufle
}
if (stream->readfilters.head) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot peek or fetch OOB data from a filtered stream");
+ php_error_docref(NULL, E_WARNING, "cannot peek or fetch OOB data from a filtered stream");
return -1;
}
-
+
oob = (flags & STREAM_OOB) == STREAM_OOB;
if (!oob && addr == NULL) {
@@ -436,7 +434,7 @@ PHPAPI int php_stream_xport_recvfrom(php_stream *stream, char *buf, size_t bufle
#endif
/* otherwise, we are going to bypass the buffer */
-
+
memset(&param, 0, sizeof(param));
param.op = STREAM_XPORT_OP_RECV;
@@ -445,7 +443,7 @@ PHPAPI int php_stream_xport_recvfrom(php_stream *stream, char *buf, size_t bufle
param.inputs.buf = buf;
param.inputs.buflen = buflen;
param.inputs.flags = flags;
-
+
ret = php_stream_set_option(stream, PHP_STREAM_OPTION_XPORT_API, 0, &param);
if (ret == PHP_STREAM_OPTION_RETURN_OK) {
@@ -455,7 +453,6 @@ PHPAPI int php_stream_xport_recvfrom(php_stream *stream, char *buf, size_t bufle
}
if (textaddr) {
*textaddr = param.outputs.textaddr;
- *textaddrlen = param.outputs.textaddrlen;
}
return recvd_len + param.outputs.returncode;
}
@@ -465,7 +462,7 @@ PHPAPI int php_stream_xport_recvfrom(php_stream *stream, char *buf, size_t bufle
/* Similar to send() system call; send data to the stream, optionally
* sending it as OOB data */
PHPAPI int php_stream_xport_sendto(php_stream *stream, const char *buf, size_t buflen,
- long flags, void *addr, socklen_t addrlen TSRMLS_DC)
+ int flags, void *addr, socklen_t addrlen)
{
php_stream_xport_param param;
int ret = 0;
@@ -476,14 +473,14 @@ PHPAPI int php_stream_xport_sendto(php_stream *stream, const char *buf, size_t b
return php_stream_write(stream, buf, buflen);
}
#endif
-
+
oob = (flags & STREAM_OOB) == STREAM_OOB;
if ((oob || addr) && stream->writefilters.head) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot write OOB data, or data to a targeted address on a filtered stream");
+ php_error_docref(NULL, E_WARNING, "cannot write OOB data, or data to a targeted address on a filtered stream");
return -1;
}
-
+
memset(&param, 0, sizeof(param));
param.op = STREAM_XPORT_OP_SEND;
@@ -493,7 +490,7 @@ PHPAPI int php_stream_xport_sendto(php_stream *stream, const char *buf, size_t b
param.inputs.flags = flags;
param.inputs.addr = addr;
param.inputs.addrlen = addrlen;
-
+
ret = php_stream_set_option(stream, PHP_STREAM_OPTION_XPORT_API, 0, &param);
if (ret == PHP_STREAM_OPTION_RETURN_OK) {
@@ -504,7 +501,7 @@ PHPAPI int php_stream_xport_sendto(php_stream *stream, const char *buf, size_t b
/* Similar to shutdown() system call; shut down part of a full-duplex
* connection */
-PHPAPI int php_stream_xport_shutdown(php_stream *stream, stream_shutdown_t how TSRMLS_DC)
+PHPAPI int php_stream_xport_shutdown(php_stream *stream, stream_shutdown_t how)
{
php_stream_xport_param param;
int ret = 0;
@@ -513,7 +510,7 @@ PHPAPI int php_stream_xport_shutdown(php_stream *stream, stream_shutdown_t how T
param.op = STREAM_XPORT_OP_SHUTDOWN;
param.how = how;
-
+
ret = php_stream_set_option(stream, PHP_STREAM_OPTION_XPORT_API, 0, &param);
if (ret == PHP_STREAM_OPTION_RETURN_OK) {
diff --git a/main/streams/userspace.c b/main/streams/userspace.c
index 0152b889b0..de081cd734 100644
--- a/main/streams/userspace.c
+++ b/main/streams/userspace.c
@@ -1,8 +1,8 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2015 The PHP Group |
+ | Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -45,15 +45,15 @@ struct php_user_stream_wrapper {
php_stream_wrapper wrapper;
};
-static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char *filename, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC);
-static int user_wrapper_stat_url(php_stream_wrapper *wrapper, const char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC);
-static int user_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC);
-static int user_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from, const char *url_to, int options, php_stream_context *context TSRMLS_DC);
-static int user_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url, int mode, int options, php_stream_context *context TSRMLS_DC);
-static int user_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC);
-static int user_wrapper_metadata(php_stream_wrapper *wrapper, const char *url, int option, void *value, php_stream_context *context TSRMLS_DC);
+static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char *filename, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC);
+static int user_wrapper_stat_url(php_stream_wrapper *wrapper, const char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context);
+static int user_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context);
+static int user_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from, const char *url_to, int options, php_stream_context *context);
+static int user_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url, int mode, int options, php_stream_context *context);
+static int user_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context);
+static int user_wrapper_metadata(php_stream_wrapper *wrapper, const char *url, int option, void *value, php_stream_context *context);
static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char *filename, const char *mode,
- int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC);
+ int options, char **opened_path, php_stream_context *context STREAMS_DC);
static php_stream_wrapper_ops user_stream_wops = {
user_wrapper_opener,
@@ -70,7 +70,7 @@ static php_stream_wrapper_ops user_stream_wops = {
};
-static void stream_wrapper_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC)
+static void stream_wrapper_dtor(zend_resource *rsrc)
{
struct php_user_stream_wrapper * uwrap = (struct php_user_stream_wrapper*)rsrc->ptr;
@@ -120,7 +120,7 @@ PHP_MINIT_FUNCTION(user_streams)
struct _php_userstream_data {
struct php_user_stream_wrapper * wrapper;
- zval * object;
+ zval object;
};
typedef struct _php_userstream_data php_userstream_data_t;
@@ -281,18 +281,14 @@ typedef struct _php_userstream_data php_userstream_data_t;
}}} **/
-static zval *user_stream_create_object(struct php_user_stream_wrapper *uwrap, php_stream_context *context TSRMLS_DC)
+static void user_stream_create_object(struct php_user_stream_wrapper *uwrap, php_stream_context *context, zval *object)
{
- zval *object;
/* create an instance of our class */
- ALLOC_ZVAL(object);
object_init_ex(object, uwrap->ce);
- Z_SET_REFCOUNT_P(object, 1);
- Z_SET_ISREF_P(object);
if (context) {
- add_property_resource(object, "context", context->rsrc_id);
- zend_list_addref(context->rsrc_id);
+ add_property_resource(object, "context", context->res);
+ GC_REFCOUNT(context->res)++;
} else {
add_property_null(object, "context");
}
@@ -300,14 +296,14 @@ static zval *user_stream_create_object(struct php_user_stream_wrapper *uwrap, ph
if (uwrap->ce->constructor) {
zend_fcall_info fci;
zend_fcall_info_cache fcc;
- zval *retval_ptr;
+ zval retval;
fci.size = sizeof(fci);
fci.function_table = &uwrap->ce->function_table;
- fci.function_name = NULL;
+ ZVAL_UNDEF(&fci.function_name);
fci.symbol_table = NULL;
- fci.object_ptr = object;
- fci.retval_ptr_ptr = &retval_ptr;
+ fci.object = Z_OBJ_P(object);
+ fci.retval = &retval;
fci.param_count = 0;
fci.params = NULL;
fci.no_separation = 1;
@@ -316,36 +312,32 @@ static zval *user_stream_create_object(struct php_user_stream_wrapper *uwrap, ph
fcc.function_handler = uwrap->ce->constructor;
fcc.calling_scope = EG(scope);
fcc.called_scope = Z_OBJCE_P(object);
- fcc.object_ptr = object;
+ fcc.object = Z_OBJ_P(object);
- if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not execute %s::%s()", uwrap->ce->name, uwrap->ce->constructor->common.function_name);
+ if (zend_call_function(&fci, &fcc) == FAILURE) {
+ php_error_docref(NULL, E_WARNING, "Could not execute %s::%s()", uwrap->ce->name->val, uwrap->ce->constructor->common.function_name->val);
zval_dtor(object);
- FREE_ZVAL(object);
- return NULL;
+ ZVAL_UNDEF(object);
} else {
- if (retval_ptr) {
- zval_ptr_dtor(&retval_ptr);
- }
+ zval_ptr_dtor(&retval);
}
}
- return object;
}
static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char *filename, const char *mode,
- int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC)
+ int options, char **opened_path, php_stream_context *context STREAMS_DC)
{
struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract;
php_userstream_data_t *us;
- zval *zfilename, *zmode, *zopened, *zoptions, *zretval = NULL, *zfuncname;
- zval **args[4];
+ zval zretval, zfuncname;
+ zval args[4];
int call_result;
php_stream *stream = NULL;
zend_bool old_in_user_include;
/* Try to catch bad usage without preventing flexibility */
if (FG(user_stream_current_filename) != NULL && strcmp(filename, FG(user_stream_current_filename)) == 0) {
- php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "infinite recursion prevented");
+ php_stream_wrapper_log_error(wrapper, options, "infinite recursion prevented");
return NULL;
}
FG(user_stream_current_filename) = filename;
@@ -364,8 +356,8 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char *
us = emalloc(sizeof(*us));
us->wrapper = uwrap;
- us->object = user_stream_create_object(uwrap, context TSRMLS_CC);
- if(us->object == NULL) {
+ user_stream_create_object(uwrap, context, &us->object);
+ if (Z_TYPE(us->object) == IS_UNDEF) {
FG(user_stream_current_filename) = NULL;
PG(in_user_include) = old_in_user_include;
efree(us);
@@ -373,64 +365,48 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char *
}
/* call it's stream_open method - set up params first */
- MAKE_STD_ZVAL(zfilename);
- ZVAL_STRING(zfilename, filename, 1);
- args[0] = &zfilename;
-
- MAKE_STD_ZVAL(zmode);
- ZVAL_STRING(zmode, mode, 1);
- args[1] = &zmode;
-
- MAKE_STD_ZVAL(zoptions);
- ZVAL_LONG(zoptions, options);
- args[2] = &zoptions;
+ ZVAL_STRING(&args[0], filename);
+ ZVAL_STRING(&args[1], mode);
+ ZVAL_LONG(&args[2], options);
+ ZVAL_NEW_REF(&args[3], &EG(uninitialized_zval));
- MAKE_STD_ZVAL(zopened);
- Z_SET_REFCOUNT_P(zopened, 1);
- Z_SET_ISREF_P(zopened);
- ZVAL_NULL(zopened);
- args[3] = &zopened;
-
- MAKE_STD_ZVAL(zfuncname);
- ZVAL_STRING(zfuncname, USERSTREAM_OPEN, 1);
+ ZVAL_STRING(&zfuncname, USERSTREAM_OPEN);
call_result = call_user_function_ex(NULL,
- &us->object,
- zfuncname,
+ Z_ISUNDEF(us->object)? NULL : &us->object,
+ &zfuncname,
&zretval,
4, args,
- 0, NULL TSRMLS_CC);
+ 0, NULL );
- if (call_result == SUCCESS && zretval != NULL && zval_is_true(zretval)) {
+ if (call_result == SUCCESS && Z_TYPE(zretval) != IS_UNDEF && zval_is_true(&zretval)) {
/* the stream is now open! */
stream = php_stream_alloc_rel(&php_stream_userspace_ops, us, 0, mode);
/* if the opened path is set, copy it out */
- if (Z_TYPE_P(zopened) == IS_STRING && opened_path) {
- *opened_path = estrndup(Z_STRVAL_P(zopened), Z_STRLEN_P(zopened));
+ if (Z_ISREF(args[3]) && Z_TYPE_P(Z_REFVAL(args[3])) == IS_STRING && opened_path) {
+ *opened_path = estrndup(Z_STRVAL_P(Z_REFVAL(args[3])), Z_STRLEN_P(Z_REFVAL(args[3])));
}
/* set wrapper data to be a reference to our object */
- stream->wrapperdata = us->object;
- zval_add_ref(&stream->wrapperdata);
+ ZVAL_COPY(&stream->wrapperdata, &us->object);
} else {
- php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "\"%s::" USERSTREAM_OPEN "\" call failed",
+ php_stream_wrapper_log_error(wrapper, options, "\"%s::" USERSTREAM_OPEN "\" call failed",
us->wrapper->classname);
}
/* destroy everything else */
if (stream == NULL) {
zval_ptr_dtor(&us->object);
+ ZVAL_UNDEF(&us->object);
efree(us);
}
- if (zretval)
- zval_ptr_dtor(&zretval);
-
+ zval_ptr_dtor(&zretval);
zval_ptr_dtor(&zfuncname);
- zval_ptr_dtor(&zopened);
- zval_ptr_dtor(&zoptions);
- zval_ptr_dtor(&zmode);
- zval_ptr_dtor(&zfilename);
+ zval_ptr_dtor(&args[3]);
+ zval_ptr_dtor(&args[2]);
+ zval_ptr_dtor(&args[1]);
+ zval_ptr_dtor(&args[0]);
FG(user_stream_current_filename) = NULL;
@@ -439,18 +415,18 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char *
}
static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char *filename, const char *mode,
- int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC)
+ int options, char **opened_path, php_stream_context *context STREAMS_DC)
{
struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract;
php_userstream_data_t *us;
- zval *zfilename, *zoptions, *zretval = NULL, *zfuncname;
- zval **args[2];
+ zval zretval, zfuncname;
+ zval args[2];
int call_result;
php_stream *stream = NULL;
/* Try to catch bad usage without preventing flexibility */
if (FG(user_stream_current_filename) != NULL && strcmp(filename, FG(user_stream_current_filename)) == 0) {
- php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "infinite recursion prevented");
+ php_stream_wrapper_log_error(wrapper, options, "infinite recursion prevented");
return NULL;
}
FG(user_stream_current_filename) = filename;
@@ -458,55 +434,48 @@ static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char
us = emalloc(sizeof(*us));
us->wrapper = uwrap;
- us->object = user_stream_create_object(uwrap, context TSRMLS_CC);
- if(us->object == NULL) {
+ user_stream_create_object(uwrap, context, &us->object);
+ if (Z_TYPE(us->object) == IS_UNDEF) {
FG(user_stream_current_filename) = NULL;
efree(us);
return NULL;
}
/* call it's dir_open method - set up params first */
- MAKE_STD_ZVAL(zfilename);
- ZVAL_STRING(zfilename, filename, 1);
- args[0] = &zfilename;
+ ZVAL_STRING(&args[0], filename);
+ ZVAL_LONG(&args[1], options);
- MAKE_STD_ZVAL(zoptions);
- ZVAL_LONG(zoptions, options);
- args[1] = &zoptions;
-
- MAKE_STD_ZVAL(zfuncname);
- ZVAL_STRING(zfuncname, USERSTREAM_DIR_OPEN, 1);
+ ZVAL_STRING(&zfuncname, USERSTREAM_DIR_OPEN);
call_result = call_user_function_ex(NULL,
- &us->object,
- zfuncname,
+ Z_ISUNDEF(us->object)? NULL : &us->object,
+ &zfuncname,
&zretval,
2, args,
- 0, NULL TSRMLS_CC);
+ 0, NULL );
- if (call_result == SUCCESS && zretval != NULL && zval_is_true(zretval)) {
+ if (call_result == SUCCESS && Z_TYPE(zretval) != IS_UNDEF && zval_is_true(&zretval)) {
/* the stream is now open! */
stream = php_stream_alloc_rel(&php_stream_userspace_dir_ops, us, 0, mode);
/* set wrapper data to be a reference to our object */
- stream->wrapperdata = us->object;
- zval_add_ref(&stream->wrapperdata);
+ ZVAL_COPY(&stream->wrapperdata, &us->object);
} else {
- php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "\"%s::" USERSTREAM_DIR_OPEN "\" call failed",
+ php_stream_wrapper_log_error(wrapper, options, "\"%s::" USERSTREAM_DIR_OPEN "\" call failed",
us->wrapper->classname);
}
/* destroy everything else */
if (stream == NULL) {
zval_ptr_dtor(&us->object);
+ ZVAL_UNDEF(&us->object);
efree(us);
}
- if (zretval)
- zval_ptr_dtor(&zretval);
+ zval_ptr_dtor(&zretval);
zval_ptr_dtor(&zfuncname);
- zval_ptr_dtor(&zoptions);
- zval_ptr_dtor(&zfilename);
+ zval_ptr_dtor(&args[1]);
+ zval_ptr_dtor(&args[0]);
FG(user_stream_current_filename) = NULL;
@@ -518,43 +487,41 @@ static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char
Registers a custom URL protocol handler class */
PHP_FUNCTION(stream_wrapper_register)
{
- char *protocol, *classname;
- int protocol_len, classname_len;
+ zend_string *protocol, *classname;
struct php_user_stream_wrapper * uwrap;
- int rsrc_id;
- long flags = 0;
+ zend_resource *rsrc;
+ zend_long flags = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &protocol, &protocol_len, &classname, &classname_len, &flags) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS|l", &protocol, &classname, &flags) == FAILURE) {
RETURN_FALSE;
}
uwrap = (struct php_user_stream_wrapper *)ecalloc(1, sizeof(*uwrap));
- uwrap->protoname = estrndup(protocol, protocol_len);
- uwrap->classname = estrndup(classname, classname_len);
+ uwrap->protoname = estrndup(protocol->val, protocol->len);
+ uwrap->classname = estrndup(classname->val, classname->len);
uwrap->wrapper.wops = &user_stream_wops;
uwrap->wrapper.abstract = uwrap;
uwrap->wrapper.is_url = ((flags & PHP_STREAM_IS_URL) != 0);
- rsrc_id = ZEND_REGISTER_RESOURCE(NULL, uwrap, le_protocols);
+ rsrc = ZEND_REGISTER_RESOURCE(NULL, uwrap, le_protocols);
- if (zend_lookup_class(uwrap->classname, classname_len, (zend_class_entry***)&uwrap->ce TSRMLS_CC) == SUCCESS) {
- uwrap->ce = *(zend_class_entry**)uwrap->ce;
- if (php_register_url_stream_wrapper_volatile(protocol, &uwrap->wrapper TSRMLS_CC) == SUCCESS) {
+ if ((uwrap->ce = zend_lookup_class(classname)) != NULL) {
+ if (php_register_url_stream_wrapper_volatile(protocol->val, &uwrap->wrapper) == SUCCESS) {
RETURN_TRUE;
} else {
/* We failed. But why? */
- if (zend_hash_exists(php_stream_get_url_stream_wrappers_hash(), protocol, protocol_len + 1)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Protocol %s:// is already defined.", protocol);
+ if (zend_hash_exists(php_stream_get_url_stream_wrappers_hash(), protocol)) {
+ php_error_docref(NULL, E_WARNING, "Protocol %s:// is already defined.", protocol->val);
} else {
/* Hash doesn't exist so it must have been an invalid protocol scheme */
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid protocol scheme specified. Unable to register wrapper class %s to %s://", classname, protocol);
+ php_error_docref(NULL, E_WARNING, "Invalid protocol scheme specified. Unable to register wrapper class %s to %s://", classname->val, protocol->val);
}
}
} else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "class '%s' is undefined", classname);
+ php_error_docref(NULL, E_WARNING, "class '%s' is undefined", classname->val);
}
- zend_list_delete(rsrc_id);
+ zend_list_delete(rsrc);
RETURN_FALSE;
}
/* }}} */
@@ -564,15 +531,15 @@ PHP_FUNCTION(stream_wrapper_register)
PHP_FUNCTION(stream_wrapper_unregister)
{
char *protocol;
- int protocol_len;
+ size_t protocol_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &protocol, &protocol_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &protocol, &protocol_len) == FAILURE) {
RETURN_FALSE;
}
- if (php_unregister_url_stream_wrapper_volatile(protocol TSRMLS_CC) == FAILURE) {
+ if (php_unregister_url_stream_wrapper_volatile(protocol) == FAILURE) {
/* We failed */
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to unregister protocol %s://", protocol);
+ php_error_docref(NULL, E_WARNING, "Unable to unregister protocol %s://", protocol);
RETURN_FALSE;
}
@@ -584,34 +551,30 @@ PHP_FUNCTION(stream_wrapper_unregister)
Restore the original protocol handler, overriding if necessary */
PHP_FUNCTION(stream_wrapper_restore)
{
- char *protocol;
- int protocol_len;
- php_stream_wrapper **wrapperpp = NULL, *wrapper;
+ zend_string *protocol;
+ php_stream_wrapper *wrapper;
HashTable *global_wrapper_hash;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &protocol, &protocol_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &protocol) == FAILURE) {
RETURN_FALSE;
}
global_wrapper_hash = php_stream_get_url_stream_wrappers_hash_global();
if (php_stream_get_url_stream_wrappers_hash() == global_wrapper_hash) {
- php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%s:// was never changed, nothing to restore", protocol);
+ php_error_docref(NULL, E_NOTICE, "%s:// was never changed, nothing to restore", protocol->val);
RETURN_TRUE;
}
- if ((zend_hash_find(global_wrapper_hash, protocol, protocol_len + 1, (void**)&wrapperpp) == FAILURE) || !wrapperpp) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s:// never existed, nothing to restore", protocol);
+ if ((wrapper = zend_hash_find_ptr(global_wrapper_hash, protocol)) == NULL) {
+ php_error_docref(NULL, E_WARNING, "%s:// never existed, nothing to restore", protocol->val);
RETURN_FALSE;
}
- /* next line might delete the pointer that wrapperpp points at, so deref it now */
- wrapper = *wrapperpp;
-
/* A failure here could be okay given that the protocol might have been merely unregistered */
- php_unregister_url_stream_wrapper_volatile(protocol TSRMLS_CC);
+ php_unregister_url_stream_wrapper_volatile(protocol->val);
- if (php_register_url_stream_wrapper_volatile(protocol, wrapper TSRMLS_CC) == FAILURE) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to restore original %s:// wrapper", protocol);
+ if (php_register_url_stream_wrapper_volatile(protocol->val, wrapper) == FAILURE) {
+ php_error_docref(NULL, E_WARNING, "Unable to restore original %s:// wrapper", protocol->val);
RETURN_FALSE;
}
@@ -619,274 +582,257 @@ PHP_FUNCTION(stream_wrapper_restore)
}
/* }}} */
-static size_t php_userstreamop_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC)
+static size_t php_userstreamop_write(php_stream *stream, const char *buf, size_t count)
{
zval func_name;
- zval *retval = NULL;
+ zval retval;
int call_result;
php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract;
- zval **args[1];
- zval *zbufptr;
+ zval args[1];
size_t didwrite = 0;
assert(us != NULL);
- ZVAL_STRINGL(&func_name, USERSTREAM_WRITE, sizeof(USERSTREAM_WRITE)-1, 0);
+ ZVAL_STRINGL(&func_name, USERSTREAM_WRITE, sizeof(USERSTREAM_WRITE)-1);
- MAKE_STD_ZVAL(zbufptr);
- ZVAL_STRINGL(zbufptr, (char*)buf, count, 1);;
- args[0] = &zbufptr;
+ ZVAL_STRINGL(&args[0], (char*)buf, count);
call_result = call_user_function_ex(NULL,
- &us->object,
+ Z_ISUNDEF(us->object)? NULL : &us->object,
&func_name,
&retval,
1, args,
- 0, NULL TSRMLS_CC);
- zval_ptr_dtor(&zbufptr);
+ 0, NULL);
+ zval_ptr_dtor(&args[0]);
+ zval_ptr_dtor(&func_name);
didwrite = 0;
- if (call_result == SUCCESS && retval != NULL) {
- convert_to_long(retval);
- didwrite = Z_LVAL_P(retval);
+ if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) {
+ convert_to_long(&retval);
+ didwrite = Z_LVAL(retval);
} else if (call_result == FAILURE) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_WRITE " is not implemented!",
+ php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_WRITE " is not implemented!",
us->wrapper->classname);
}
/* don't allow strange buffer overruns due to bogus return */
if (didwrite > count) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_WRITE " wrote %ld bytes more data than requested (%ld written, %ld max)",
+ php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_WRITE " wrote " ZEND_LONG_FMT " bytes more data than requested (" ZEND_LONG_FMT " written, " ZEND_LONG_FMT " max)",
us->wrapper->classname,
- (long)(didwrite - count), (long)didwrite, (long)count);
+ (zend_long)(didwrite - count), (zend_long)didwrite, (zend_long)count);
didwrite = count;
}
- if (retval)
- zval_ptr_dtor(&retval);
+ zval_ptr_dtor(&retval);
return didwrite;
}
-static size_t php_userstreamop_read(php_stream *stream, char *buf, size_t count TSRMLS_DC)
+static size_t php_userstreamop_read(php_stream *stream, char *buf, size_t count)
{
zval func_name;
- zval *retval = NULL;
- zval **args[1];
+ zval retval;
+ zval args[1];
int call_result;
size_t didread = 0;
php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract;
- zval *zcount;
assert(us != NULL);
- ZVAL_STRINGL(&func_name, USERSTREAM_READ, sizeof(USERSTREAM_READ)-1, 0);
+ ZVAL_STRINGL(&func_name, USERSTREAM_READ, sizeof(USERSTREAM_READ)-1);
- MAKE_STD_ZVAL(zcount);
- ZVAL_LONG(zcount, count);
- args[0] = &zcount;
+ ZVAL_LONG(&args[0], count);
call_result = call_user_function_ex(NULL,
- &us->object,
+ Z_ISUNDEF(us->object)? NULL : &us->object,
&func_name,
&retval,
1, args,
- 0, NULL TSRMLS_CC);
+ 0, NULL);
- if (call_result == SUCCESS && retval != NULL) {
- convert_to_string(retval);
- didread = Z_STRLEN_P(retval);
+ if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) {
+ convert_to_string(&retval);
+ didread = Z_STRLEN(retval);
if (didread > count) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_READ " - read %ld bytes more data than requested (%ld read, %ld max) - excess data will be lost",
- us->wrapper->classname, (long)(didread - count), (long)didread, (long)count);
+ php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_READ " - read " ZEND_LONG_FMT " bytes more data than requested (" ZEND_LONG_FMT " read, " ZEND_LONG_FMT " max) - excess data will be lost",
+ us->wrapper->classname, (zend_long)(didread - count), (zend_long)didread, (zend_long)count);
didread = count;
}
if (didread > 0)
- memcpy(buf, Z_STRVAL_P(retval), didread);
+ memcpy(buf, Z_STRVAL(retval), didread);
} else if (call_result == FAILURE) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_READ " is not implemented!",
+ php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_READ " is not implemented!",
us->wrapper->classname);
}
- zval_ptr_dtor(&zcount);
+ zval_ptr_dtor(&args[0]);
- if (retval) {
- zval_ptr_dtor(&retval);
- retval = NULL;
- }
+ zval_ptr_dtor(&retval);
+ ZVAL_UNDEF(&retval);
+ zval_ptr_dtor(&func_name);
/* since the user stream has no way of setting the eof flag directly, we need to ask it if we hit eof */
- ZVAL_STRINGL(&func_name, USERSTREAM_EOF, sizeof(USERSTREAM_EOF)-1, 0);
+ ZVAL_STRINGL(&func_name, USERSTREAM_EOF, sizeof(USERSTREAM_EOF)-1);
call_result = call_user_function_ex(NULL,
- &us->object,
+ Z_ISUNDEF(us->object)? NULL : &us->object,
&func_name,
&retval,
- 0, NULL, 0, NULL TSRMLS_CC);
+ 0, NULL, 0, NULL);
- if (call_result == SUCCESS && retval != NULL && zval_is_true(retval)) {
+ if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF && zval_is_true(&retval)) {
stream->eof = 1;
} else if (call_result == FAILURE) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
+ php_error_docref(NULL, E_WARNING,
"%s::" USERSTREAM_EOF " is not implemented! Assuming EOF",
us->wrapper->classname);
stream->eof = 1;
}
- if (retval) {
- zval_ptr_dtor(&retval);
- retval = NULL;
- }
+ zval_ptr_dtor(&retval);
+ zval_ptr_dtor(&func_name);
return didread;
}
-static int php_userstreamop_close(php_stream *stream, int close_handle TSRMLS_DC)
+static int php_userstreamop_close(php_stream *stream, int close_handle)
{
zval func_name;
- zval *retval = NULL;
+ zval retval;
php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract;
assert(us != NULL);
- ZVAL_STRINGL(&func_name, USERSTREAM_CLOSE, sizeof(USERSTREAM_CLOSE)-1, 0);
+ ZVAL_STRINGL(&func_name, USERSTREAM_CLOSE, sizeof(USERSTREAM_CLOSE)-1);
call_user_function_ex(NULL,
- &us->object,
+ Z_ISUNDEF(us->object)? NULL : &us->object,
&func_name,
&retval,
- 0, NULL, 0, NULL TSRMLS_CC);
+ 0, NULL, 0, NULL);
- if (retval)
- zval_ptr_dtor(&retval);
+ zval_ptr_dtor(&retval);
+ zval_ptr_dtor(&func_name);
zval_ptr_dtor(&us->object);
+ ZVAL_UNDEF(&us->object);
efree(us);
return 0;
}
-static int php_userstreamop_flush(php_stream *stream TSRMLS_DC)
+static int php_userstreamop_flush(php_stream *stream)
{
zval func_name;
- zval *retval = NULL;
+ zval retval;
int call_result;
php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract;
assert(us != NULL);
- ZVAL_STRINGL(&func_name, USERSTREAM_FLUSH, sizeof(USERSTREAM_FLUSH)-1, 0);
+ ZVAL_STRINGL(&func_name, USERSTREAM_FLUSH, sizeof(USERSTREAM_FLUSH)-1);
call_result = call_user_function_ex(NULL,
- &us->object,
+ Z_ISUNDEF(us->object)? NULL : &us->object,
&func_name,
&retval,
- 0, NULL, 0, NULL TSRMLS_CC);
+ 0, NULL, 0, NULL);
- if (call_result == SUCCESS && retval != NULL && zval_is_true(retval))
+ if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF && zval_is_true(&retval))
call_result = 0;
else
call_result = -1;
- if (retval)
- zval_ptr_dtor(&retval);
+ zval_ptr_dtor(&retval);
+ zval_ptr_dtor(&func_name);
return call_result;
}
-static int php_userstreamop_seek(php_stream *stream, off_t offset, int whence, off_t *newoffs TSRMLS_DC)
+static int php_userstreamop_seek(php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffs)
{
zval func_name;
- zval *retval = NULL;
+ zval retval;
int call_result, ret;
php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract;
- zval **args[2];
- zval *zoffs, *zwhence;
+ zval args[2];
assert(us != NULL);
- ZVAL_STRINGL(&func_name, USERSTREAM_SEEK, sizeof(USERSTREAM_SEEK)-1, 0);
-
- MAKE_STD_ZVAL(zoffs);
- ZVAL_LONG(zoffs, offset);
- args[0] = &zoffs;
+ ZVAL_STRINGL(&func_name, USERSTREAM_SEEK, sizeof(USERSTREAM_SEEK)-1);
- MAKE_STD_ZVAL(zwhence);
- ZVAL_LONG(zwhence, whence);
- args[1] = &zwhence;
+ ZVAL_LONG(&args[0], offset);
+ ZVAL_LONG(&args[1], whence);
call_result = call_user_function_ex(NULL,
- &us->object,
+ Z_ISUNDEF(us->object)? NULL : &us->object,
&func_name,
&retval,
2, args,
- 0, NULL TSRMLS_CC);
+ 0, NULL);
- zval_ptr_dtor(&zoffs);
- zval_ptr_dtor(&zwhence);
+ zval_ptr_dtor(&args[0]);
+ zval_ptr_dtor(&args[1]);
+ zval_ptr_dtor(&func_name);
if (call_result == FAILURE) {
/* stream_seek is not implemented, so disable seeks for this stream */
stream->flags |= PHP_STREAM_FLAG_NO_SEEK;
/* there should be no retval to clean up */
- if (retval)
- zval_ptr_dtor(&retval);
+ zval_ptr_dtor(&retval);
return -1;
- } else if (call_result == SUCCESS && retval != NULL && zval_is_true(retval)) {
+ } else if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF && zval_is_true(&retval)) {
ret = 0;
} else {
ret = -1;
}
- if (retval) {
- zval_ptr_dtor(&retval);
- retval = NULL;
- }
+ zval_ptr_dtor(&retval);
+ ZVAL_UNDEF(&retval);
if (ret) {
return ret;
}
/* now determine where we are */
- ZVAL_STRINGL(&func_name, USERSTREAM_TELL, sizeof(USERSTREAM_TELL)-1, 0);
+ ZVAL_STRINGL(&func_name, USERSTREAM_TELL, sizeof(USERSTREAM_TELL)-1);
call_result = call_user_function_ex(NULL,
- &us->object,
+ Z_ISUNDEF(us->object)? NULL : &us->object,
&func_name,
&retval,
- 0, NULL, 0, NULL TSRMLS_CC);
+ 0, NULL, 0, NULL);
- if (call_result == SUCCESS && retval != NULL && Z_TYPE_P(retval) == IS_LONG) {
- *newoffs = Z_LVAL_P(retval);
+ if (call_result == SUCCESS && Z_TYPE(retval) == IS_LONG) {
+ *newoffs = Z_LVAL(retval);
ret = 0;
} else if (call_result == FAILURE) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_TELL " is not implemented!", us->wrapper->classname);
+ php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_TELL " is not implemented!", us->wrapper->classname);
ret = -1;
} else {
ret = -1;
}
- if (retval) {
- zval_ptr_dtor(&retval);
- }
+ zval_ptr_dtor(&retval);
+ zval_ptr_dtor(&func_name);
return ret;
}
/* parse the return value from one of the stat functions and store the
* relevant fields into the statbuf provided */
-static int statbuf_from_array(zval *array, php_stream_statbuf *ssb TSRMLS_DC)
+static int statbuf_from_array(zval *array, php_stream_statbuf *ssb)
{
- zval **elem;
+ zval *elem;
#define STAT_PROP_ENTRY_EX(name, name2) \
- if (SUCCESS == zend_hash_find(Z_ARRVAL_P(array), #name, sizeof(#name), (void**)&elem)) { \
+ if (NULL != (elem = zend_hash_str_find(Z_ARRVAL_P(array), #name, sizeof(#name)-1))) { \
SEPARATE_ZVAL(elem); \
- convert_to_long(*elem); \
- ssb->sb.st_##name2 = Z_LVAL_PP(elem); \
+ convert_to_long(elem); \
+ ssb->sb.st_##name2 = Z_LVAL_P(elem); \
}
#define STAT_PROP_ENTRY(name) STAT_PROP_ENTRY_EX(name,name)
@@ -923,114 +869,116 @@ static int statbuf_from_array(zval *array, php_stream_statbuf *ssb TSRMLS_DC)
return SUCCESS;
}
-static int php_userstreamop_stat(php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC)
+static int php_userstreamop_stat(php_stream *stream, php_stream_statbuf *ssb)
{
zval func_name;
- zval *retval = NULL;
+ zval retval;
int call_result;
php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract;
int ret = -1;
- ZVAL_STRINGL(&func_name, USERSTREAM_STAT, sizeof(USERSTREAM_STAT)-1, 0);
+ ZVAL_STRINGL(&func_name, USERSTREAM_STAT, sizeof(USERSTREAM_STAT)-1);
call_result = call_user_function_ex(NULL,
- &us->object,
+ Z_ISUNDEF(us->object)? NULL : &us->object,
&func_name,
&retval,
- 0, NULL, 0, NULL TSRMLS_CC);
+ 0, NULL, 0, NULL);
- if (call_result == SUCCESS && retval != NULL && Z_TYPE_P(retval) == IS_ARRAY) {
- if (SUCCESS == statbuf_from_array(retval, ssb TSRMLS_CC))
+ if (call_result == SUCCESS && Z_TYPE(retval) == IS_ARRAY) {
+ if (SUCCESS == statbuf_from_array(&retval, ssb))
ret = 0;
} else {
if (call_result == FAILURE) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_STAT " is not implemented!",
+ php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_STAT " is not implemented!",
us->wrapper->classname);
}
}
- if (retval)
- zval_ptr_dtor(&retval);
+ zval_ptr_dtor(&retval);
+ zval_ptr_dtor(&func_name);
return ret;
}
-static int php_userstreamop_set_option(php_stream *stream, int option, int value, void *ptrparam TSRMLS_DC) {
+static int php_userstreamop_set_option(php_stream *stream, int option, int value, void *ptrparam) {
zval func_name;
- zval *retval = NULL;
+ zval retval;
int call_result;
php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract;
int ret = PHP_STREAM_OPTION_RETURN_NOTIMPL;
- zval *zvalue = NULL;
- zval **args[3];
+ zval args[3];
switch (option) {
case PHP_STREAM_OPTION_CHECK_LIVENESS:
- ZVAL_STRINGL(&func_name, USERSTREAM_EOF, sizeof(USERSTREAM_EOF)-1, 0);
- call_result = call_user_function_ex(NULL, &us->object, &func_name, &retval, 0, NULL, 0, NULL TSRMLS_CC);
- if (call_result == SUCCESS && retval != NULL && Z_TYPE_P(retval) == IS_BOOL) {
- ret = zval_is_true(retval) ? PHP_STREAM_OPTION_RETURN_ERR : PHP_STREAM_OPTION_RETURN_OK;
+ ZVAL_STRINGL(&func_name, USERSTREAM_EOF, sizeof(USERSTREAM_EOF)-1);
+ call_result = call_user_function_ex(NULL, Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, 0, NULL, 0, NULL);
+ if (call_result == SUCCESS && (Z_TYPE(retval) == IS_FALSE || Z_TYPE(retval) == IS_TRUE)) {
+ ret = zval_is_true(&retval) ? PHP_STREAM_OPTION_RETURN_ERR : PHP_STREAM_OPTION_RETURN_OK;
} else {
ret = PHP_STREAM_OPTION_RETURN_ERR;
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
+ php_error_docref(NULL, E_WARNING,
"%s::" USERSTREAM_EOF " is not implemented! Assuming EOF",
us->wrapper->classname);
}
+ zval_ptr_dtor(&retval);
+ zval_ptr_dtor(&func_name);
break;
case PHP_STREAM_OPTION_LOCKING:
- MAKE_STD_ZVAL(zvalue);
- ZVAL_LONG(zvalue, 0);
+ ZVAL_LONG(&args[0], 0);
if (value & LOCK_NB) {
- Z_LVAL_P(zvalue) |= PHP_LOCK_NB;
+ Z_LVAL_P(&args[0]) |= PHP_LOCK_NB;
}
switch(value & ~LOCK_NB) {
case LOCK_SH:
- Z_LVAL_P(zvalue) |= PHP_LOCK_SH;
+ Z_LVAL_P(&args[0]) |= PHP_LOCK_SH;
break;
case LOCK_EX:
- Z_LVAL_P(zvalue) |= PHP_LOCK_EX;
+ Z_LVAL_P(&args[0]) |= PHP_LOCK_EX;
break;
case LOCK_UN:
- Z_LVAL_P(zvalue) |= PHP_LOCK_UN;
+ Z_LVAL_P(&args[0]) |= PHP_LOCK_UN;
break;
}
- args[0] = &zvalue;
-
/* TODO wouldblock */
- ZVAL_STRINGL(&func_name, USERSTREAM_LOCK, sizeof(USERSTREAM_LOCK)-1, 0);
+ ZVAL_STRINGL(&func_name, USERSTREAM_LOCK, sizeof(USERSTREAM_LOCK)-1);
call_result = call_user_function_ex(NULL,
- &us->object,
- &func_name,
- &retval,
- 1, args, 0, NULL TSRMLS_CC);
+ Z_ISUNDEF(us->object)? NULL : &us->object,
+ &func_name,
+ &retval,
+ 1, args, 0, NULL);
- if (call_result == SUCCESS && retval != NULL && Z_TYPE_P(retval) == IS_BOOL) {
- ret = !Z_LVAL_P(retval);
+ if (call_result == SUCCESS && (Z_TYPE(retval) == IS_FALSE || Z_TYPE(retval) == IS_TRUE)) {
+ ret = (Z_TYPE(retval) == IS_FALSE);
} else if (call_result == FAILURE) {
if (value == 0) {
/* lock support test (TODO: more check) */
ret = PHP_STREAM_OPTION_RETURN_OK;
} else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_LOCK " is not implemented!",
+ php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_LOCK " is not implemented!",
us->wrapper->classname);
ret = PHP_STREAM_OPTION_RETURN_ERR;
}
}
+ zval_ptr_dtor(&retval);
+ zval_ptr_dtor(&func_name);
+ zval_ptr_dtor(&args[0]);
break;
case PHP_STREAM_OPTION_TRUNCATE_API:
- ZVAL_STRINGL(&func_name, USERSTREAM_TRUNCATE, sizeof(USERSTREAM_TRUNCATE)-1, 0);
+ ZVAL_STRINGL(&func_name, USERSTREAM_TRUNCATE, sizeof(USERSTREAM_TRUNCATE)-1);
switch (value) {
case PHP_STREAM_TRUNCATE_SUPPORTED:
- if (zend_is_callable_ex(&func_name, us->object, IS_CALLABLE_CHECK_SILENT,
- NULL, NULL, NULL, NULL TSRMLS_CC))
+ if (zend_is_callable_ex(&func_name,
+ Z_ISUNDEF(us->object)? NULL : Z_OBJ(us->object),
+ IS_CALLABLE_CHECK_SILENT, NULL, NULL, NULL))
ret = PHP_STREAM_OPTION_RETURN_OK;
else
ret = PHP_STREAM_OPTION_RETURN_ERR;
@@ -1039,479 +987,413 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value
case PHP_STREAM_TRUNCATE_SET_SIZE: {
ptrdiff_t new_size = *(ptrdiff_t*) ptrparam;
if (new_size >= 0 && new_size <= (ptrdiff_t)LONG_MAX) {
- MAKE_STD_ZVAL(zvalue);
- ZVAL_LONG(zvalue, (long)new_size);
- args[0] = &zvalue;
+ ZVAL_LONG(&args[0], (zend_long)new_size);
call_result = call_user_function_ex(NULL,
- &us->object,
- &func_name,
- &retval,
- 1, args, 0, NULL TSRMLS_CC);
- if (call_result == SUCCESS && retval != NULL) {
- if (Z_TYPE_P(retval) == IS_BOOL) {
- ret = Z_LVAL_P(retval) ? PHP_STREAM_OPTION_RETURN_OK :
- PHP_STREAM_OPTION_RETURN_ERR;
+ Z_ISUNDEF(us->object)? NULL : &us->object,
+ &func_name,
+ &retval,
+ 1, args, 0, NULL);
+ if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) {
+ if (Z_TYPE(retval) == IS_FALSE || Z_TYPE(retval) == IS_TRUE) {
+ ret = (Z_TYPE(retval) == IS_TRUE) ? PHP_STREAM_OPTION_RETURN_OK :
+ PHP_STREAM_OPTION_RETURN_ERR;
} else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
+ php_error_docref(NULL, E_WARNING,
"%s::" USERSTREAM_TRUNCATE " did not return a boolean!",
us->wrapper->classname);
}
} else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
+ php_error_docref(NULL, E_WARNING,
"%s::" USERSTREAM_TRUNCATE " is not implemented!",
us->wrapper->classname);
}
+ zval_ptr_dtor(&retval);
+ zval_ptr_dtor(&args[0]);
} else { /* bad new size */
ret = PHP_STREAM_OPTION_RETURN_ERR;
}
break;
}
}
+ zval_ptr_dtor(&func_name);
break;
case PHP_STREAM_OPTION_READ_BUFFER:
case PHP_STREAM_OPTION_WRITE_BUFFER:
case PHP_STREAM_OPTION_READ_TIMEOUT:
case PHP_STREAM_OPTION_BLOCKING: {
- zval *zoption = NULL;
- zval *zptrparam = NULL;
-
- ZVAL_STRINGL(&func_name, USERSTREAM_SET_OPTION, sizeof(USERSTREAM_SET_OPTION)-1, 0);
-
- ALLOC_INIT_ZVAL(zoption);
- ZVAL_LONG(zoption, option);
- ALLOC_INIT_ZVAL(zvalue);
- ALLOC_INIT_ZVAL(zptrparam);
+ ZVAL_STRINGL(&func_name, USERSTREAM_SET_OPTION, sizeof(USERSTREAM_SET_OPTION)-1);
- args[0] = &zoption;
- args[1] = &zvalue;
- args[2] = &zptrparam;
+ ZVAL_LONG(&args[0], option);
+ ZVAL_NULL(&args[1]);
+ ZVAL_NULL(&args[2]);
switch(option) {
case PHP_STREAM_OPTION_READ_BUFFER:
case PHP_STREAM_OPTION_WRITE_BUFFER:
- ZVAL_LONG(zvalue, value);
+ ZVAL_LONG(&args[1], value);
if (ptrparam) {
- ZVAL_LONG(zptrparam, *(long *)ptrparam);
+ ZVAL_LONG(&args[2], *(long *)ptrparam);
} else {
- ZVAL_LONG(zptrparam, BUFSIZ);
+ ZVAL_LONG(&args[2], BUFSIZ);
}
break;
case PHP_STREAM_OPTION_READ_TIMEOUT: {
struct timeval tv = *(struct timeval*)ptrparam;
- ZVAL_LONG(zvalue, tv.tv_sec);
- ZVAL_LONG(zptrparam, tv.tv_usec);
+ ZVAL_LONG(&args[1], tv.tv_sec);
+ ZVAL_LONG(&args[2], tv.tv_usec);
break;
}
case PHP_STREAM_OPTION_BLOCKING:
- ZVAL_LONG(zvalue, value);
+ ZVAL_LONG(&args[1], value);
break;
default:
break;
}
call_result = call_user_function_ex(NULL,
- &us->object,
+ Z_ISUNDEF(us->object)? NULL : &us->object,
&func_name,
&retval,
- 3, args, 0, NULL TSRMLS_CC);
+ 3, args, 0, NULL);
if (call_result == FAILURE) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_SET_OPTION " is not implemented!",
+ php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_SET_OPTION " is not implemented!",
us->wrapper->classname);
ret = PHP_STREAM_OPTION_RETURN_ERR;
- } else if (retval && zend_is_true(retval)) {
+ } else if (Z_TYPE(retval) != IS_UNDEF && zend_is_true(&retval)) {
ret = PHP_STREAM_OPTION_RETURN_OK;
} else {
ret = PHP_STREAM_OPTION_RETURN_ERR;
}
- if (zoption) {
- zval_ptr_dtor(&zoption);
- }
- if (zptrparam) {
- zval_ptr_dtor(&zptrparam);
- }
+ zval_ptr_dtor(&retval);
+ zval_ptr_dtor(&args[2]);
+ zval_ptr_dtor(&args[1]);
+ zval_ptr_dtor(&args[0]);
+ zval_ptr_dtor(&func_name);
break;
}
}
- /* clean up */
- if (retval) {
- zval_ptr_dtor(&retval);
- }
-
-
- if (zvalue) {
- zval_ptr_dtor(&zvalue);
- }
-
return ret;
}
-static int user_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC)
+static int user_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context)
{
struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract;
- zval *zfilename, *zfuncname, *zretval;
- zval **args[1];
+ zval zfuncname, zretval;
+ zval args[1];
int call_result;
- zval *object;
+ zval object;
int ret = 0;
/* create an instance of our class */
- object = user_stream_create_object(uwrap, context TSRMLS_CC);
- if(object == NULL) {
+ user_stream_create_object(uwrap, context, &object);
+ if (Z_TYPE(object) == IS_UNDEF) {
return ret;
}
/* call the unlink method */
- MAKE_STD_ZVAL(zfilename);
- ZVAL_STRING(zfilename, url, 1);
- args[0] = &zfilename;
+ ZVAL_STRING(&args[0], url);
- MAKE_STD_ZVAL(zfuncname);
- ZVAL_STRING(zfuncname, USERSTREAM_UNLINK, 1);
+ ZVAL_STRING(&zfuncname, USERSTREAM_UNLINK);
call_result = call_user_function_ex(NULL,
&object,
- zfuncname,
+ &zfuncname,
&zretval,
1, args,
- 0, NULL TSRMLS_CC);
+ 0, NULL );
- if (call_result == SUCCESS && zretval && Z_TYPE_P(zretval) == IS_BOOL) {
- ret = Z_LVAL_P(zretval);
+ if (call_result == SUCCESS && (Z_TYPE(zretval) == IS_FALSE || Z_TYPE(zretval) == IS_TRUE)) {
+ ret = (Z_TYPE(zretval) == IS_TRUE);
} else if (call_result == FAILURE) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_UNLINK " is not implemented!", uwrap->classname);
+ php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_UNLINK " is not implemented!", uwrap->classname);
}
/* clean up */
zval_ptr_dtor(&object);
- if (zretval)
- zval_ptr_dtor(&zretval);
-
+ zval_ptr_dtor(&zretval);
zval_ptr_dtor(&zfuncname);
- zval_ptr_dtor(&zfilename);
+
+ zval_ptr_dtor(&args[0]);
return ret;
}
static int user_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from, const char *url_to,
- int options, php_stream_context *context TSRMLS_DC)
+ int options, php_stream_context *context)
{
struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract;
- zval *zold_name, *znew_name, *zfuncname, *zretval;
- zval **args[2];
+ zval zfuncname, zretval;
+ zval args[2];
int call_result;
- zval *object;
+ zval object;
int ret = 0;
/* create an instance of our class */
- object = user_stream_create_object(uwrap, context TSRMLS_CC);
- if(object == NULL) {
+ user_stream_create_object(uwrap, context, &object);
+ if (Z_TYPE(object) == IS_UNDEF) {
return ret;
}
/* call the rename method */
- MAKE_STD_ZVAL(zold_name);
- ZVAL_STRING(zold_name, url_from, 1);
- args[0] = &zold_name;
+ ZVAL_STRING(&args[0], url_from);
+ ZVAL_STRING(&args[1], url_to);
- MAKE_STD_ZVAL(znew_name);
- ZVAL_STRING(znew_name, url_to, 1);
- args[1] = &znew_name;
-
- MAKE_STD_ZVAL(zfuncname);
- ZVAL_STRING(zfuncname, USERSTREAM_RENAME, 1);
+ ZVAL_STRING(&zfuncname, USERSTREAM_RENAME);
call_result = call_user_function_ex(NULL,
&object,
- zfuncname,
+ &zfuncname,
&zretval,
2, args,
- 0, NULL TSRMLS_CC);
+ 0, NULL );
- if (call_result == SUCCESS && zretval && Z_TYPE_P(zretval) == IS_BOOL) {
- ret = Z_LVAL_P(zretval);
+ if (call_result == SUCCESS && (Z_TYPE(zretval) == IS_FALSE || Z_TYPE(zretval) == IS_TRUE)) {
+ ret = (Z_TYPE(zretval) == IS_TRUE);
} else if (call_result == FAILURE) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_RENAME " is not implemented!", uwrap->classname);
+ php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_RENAME " is not implemented!", uwrap->classname);
}
/* clean up */
zval_ptr_dtor(&object);
- if (zretval)
- zval_ptr_dtor(&zretval);
+ zval_ptr_dtor(&zretval);
zval_ptr_dtor(&zfuncname);
- zval_ptr_dtor(&zold_name);
- zval_ptr_dtor(&znew_name);
+ zval_ptr_dtor(&args[1]);
+ zval_ptr_dtor(&args[0]);
return ret;
}
static int user_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url, int mode,
- int options, php_stream_context *context TSRMLS_DC)
+ int options, php_stream_context *context)
{
struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract;
- zval *zfilename, *zmode, *zoptions, *zfuncname, *zretval;
- zval **args[3];
+ zval zfuncname, zretval;
+ zval args[3];
int call_result;
- zval *object;
+ zval object;
int ret = 0;
/* create an instance of our class */
- object = user_stream_create_object(uwrap, context TSRMLS_CC);
- if(object == NULL) {
+ user_stream_create_object(uwrap, context, &object);
+ if (Z_TYPE(object) == IS_UNDEF) {
return ret;
}
/* call the mkdir method */
- MAKE_STD_ZVAL(zfilename);
- ZVAL_STRING(zfilename, url, 1);
- args[0] = &zfilename;
-
- MAKE_STD_ZVAL(zmode);
- ZVAL_LONG(zmode, mode);
- args[1] = &zmode;
-
- MAKE_STD_ZVAL(zoptions);
- ZVAL_LONG(zoptions, options);
- args[2] = &zoptions;
+ ZVAL_STRING(&args[0], url);
+ ZVAL_LONG(&args[1], mode);
+ ZVAL_LONG(&args[2], options);
- MAKE_STD_ZVAL(zfuncname);
- ZVAL_STRING(zfuncname, USERSTREAM_MKDIR, 1);
+ ZVAL_STRING(&zfuncname, USERSTREAM_MKDIR);
call_result = call_user_function_ex(NULL,
&object,
- zfuncname,
+ &zfuncname,
&zretval,
3, args,
- 0, NULL TSRMLS_CC);
+ 0, NULL );
- if (call_result == SUCCESS && zretval && Z_TYPE_P(zretval) == IS_BOOL) {
- ret = Z_LVAL_P(zretval);
+ if (call_result == SUCCESS && (Z_TYPE(zretval) == IS_FALSE || Z_TYPE(zretval) == IS_TRUE)) {
+ ret = (Z_TYPE(zretval) == IS_TRUE);
} else if (call_result == FAILURE) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_MKDIR " is not implemented!", uwrap->classname);
+ php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_MKDIR " is not implemented!", uwrap->classname);
}
/* clean up */
zval_ptr_dtor(&object);
- if (zretval) {
- zval_ptr_dtor(&zretval);
- }
+ zval_ptr_dtor(&zretval);
zval_ptr_dtor(&zfuncname);
- zval_ptr_dtor(&zfilename);
- zval_ptr_dtor(&zmode);
- zval_ptr_dtor(&zoptions);
+ zval_ptr_dtor(&args[2]);
+ zval_ptr_dtor(&args[1]);
+ zval_ptr_dtor(&args[0]);
return ret;
}
static int user_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url,
- int options, php_stream_context *context TSRMLS_DC)
+ int options, php_stream_context *context)
{
struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract;
- zval *zfilename, *zoptions, *zfuncname, *zretval;
- zval **args[3];
+ zval zfuncname, zretval;
+ zval args[2];
int call_result;
- zval *object;
+ zval object;
int ret = 0;
/* create an instance of our class */
- object = user_stream_create_object(uwrap, context TSRMLS_CC);
- if(object == NULL) {
+ user_stream_create_object(uwrap, context, &object);
+ if (Z_TYPE(object) == IS_UNDEF) {
return ret;
}
/* call the rmdir method */
- MAKE_STD_ZVAL(zfilename);
- ZVAL_STRING(zfilename, url, 1);
- args[0] = &zfilename;
-
- MAKE_STD_ZVAL(zoptions);
- ZVAL_LONG(zoptions, options);
- args[1] = &zoptions;
+ ZVAL_STRING(&args[0], url);
+ ZVAL_LONG(&args[1], options);
- MAKE_STD_ZVAL(zfuncname);
- ZVAL_STRING(zfuncname, USERSTREAM_RMDIR, 1);
+ ZVAL_STRING(&zfuncname, USERSTREAM_RMDIR);
call_result = call_user_function_ex(NULL,
&object,
- zfuncname,
+ &zfuncname,
&zretval,
2, args,
- 0, NULL TSRMLS_CC);
+ 0, NULL );
- if (call_result == SUCCESS && zretval && Z_TYPE_P(zretval) == IS_BOOL) {
- ret = Z_LVAL_P(zretval);
+ if (call_result == SUCCESS && (Z_TYPE(zretval) == IS_FALSE || Z_TYPE(zretval) == IS_TRUE)) {
+ ret = (Z_TYPE(zretval) == IS_TRUE);
} else if (call_result == FAILURE) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_RMDIR " is not implemented!", uwrap->classname);
+ php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_RMDIR " is not implemented!", uwrap->classname);
}
/* clean up */
zval_ptr_dtor(&object);
- if (zretval) {
- zval_ptr_dtor(&zretval);
- }
+ zval_ptr_dtor(&zretval);
zval_ptr_dtor(&zfuncname);
- zval_ptr_dtor(&zfilename);
- zval_ptr_dtor(&zoptions);
+ zval_ptr_dtor(&args[1]);
+ zval_ptr_dtor(&args[0]);
return ret;
}
static int user_wrapper_metadata(php_stream_wrapper *wrapper, const char *url, int option,
- void *value, php_stream_context *context TSRMLS_DC)
+ void *value, php_stream_context *context)
{
struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract;
- zval *zfilename, *zoption, *zvalue, *zfuncname, *zretval;
- zval **args[3];
+ zval zfuncname, zretval;
+ zval args[3];
int call_result;
- zval *object;
+ zval object;
int ret = 0;
- MAKE_STD_ZVAL(zvalue);
switch(option) {
case PHP_STREAM_META_TOUCH:
- array_init(zvalue);
+ array_init(&args[2]);
if(value) {
struct utimbuf *newtime = (struct utimbuf *)value;
- add_index_long(zvalue, 0, newtime->modtime);
- add_index_long(zvalue, 1, newtime->actime);
+ add_index_long(&args[2], 0, newtime->modtime);
+ add_index_long(&args[2], 1, newtime->actime);
}
break;
case PHP_STREAM_META_GROUP:
case PHP_STREAM_META_OWNER:
case PHP_STREAM_META_ACCESS:
- ZVAL_LONG(zvalue, *(long *)value);
+ ZVAL_LONG(&args[2], *(long *)value);
break;
case PHP_STREAM_META_GROUP_NAME:
case PHP_STREAM_META_OWNER_NAME:
- ZVAL_STRING(zvalue, value, 1);
+ ZVAL_STRING(&args[2], value);
break;
default:
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown option %d for " USERSTREAM_METADATA, option);
- zval_ptr_dtor(&zvalue);
+ php_error_docref(NULL, E_WARNING, "Unknown option %d for " USERSTREAM_METADATA, option);
+ zval_ptr_dtor(&args[2]);
return ret;
}
/* create an instance of our class */
- object = user_stream_create_object(uwrap, context TSRMLS_CC);
- if(object == NULL) {
- zval_ptr_dtor(&zvalue);
+ user_stream_create_object(uwrap, context, &object);
+ if (Z_TYPE(object) == IS_UNDEF) {
+ zval_ptr_dtor(&args[2]);
return ret;
}
/* call the mkdir method */
- MAKE_STD_ZVAL(zfilename);
- ZVAL_STRING(zfilename, url, 1);
- args[0] = &zfilename;
-
- MAKE_STD_ZVAL(zoption);
- ZVAL_LONG(zoption, option);
- args[1] = &zoption;
+ ZVAL_STRING(&args[0], url);
+ ZVAL_LONG(&args[1], option);
- args[2] = &zvalue;
-
- MAKE_STD_ZVAL(zfuncname);
- ZVAL_STRING(zfuncname, USERSTREAM_METADATA, 1);
+ ZVAL_STRING(&zfuncname, USERSTREAM_METADATA);
call_result = call_user_function_ex(NULL,
&object,
- zfuncname,
+ &zfuncname,
&zretval,
3, args,
- 0, NULL TSRMLS_CC);
+ 0, NULL );
- if (call_result == SUCCESS && zretval && Z_TYPE_P(zretval) == IS_BOOL) {
- ret = Z_LVAL_P(zretval);
+ if (call_result == SUCCESS && (Z_TYPE(zretval) == IS_FALSE || Z_TYPE(zretval) == IS_TRUE)) {
+ ret = Z_TYPE(zretval) == IS_TRUE;
} else if (call_result == FAILURE) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_METADATA " is not implemented!", uwrap->classname);
+ php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_METADATA " is not implemented!", uwrap->classname);
}
/* clean up */
zval_ptr_dtor(&object);
- if (zretval) {
- zval_ptr_dtor(&zretval);
- }
+ zval_ptr_dtor(&zretval);
zval_ptr_dtor(&zfuncname);
- zval_ptr_dtor(&zfilename);
- zval_ptr_dtor(&zoption);
- zval_ptr_dtor(&zvalue);
+ zval_ptr_dtor(&args[0]);
+ zval_ptr_dtor(&args[1]);
+ zval_ptr_dtor(&args[2]);
return ret;
}
static int user_wrapper_stat_url(php_stream_wrapper *wrapper, const char *url, int flags,
- php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC)
+ php_stream_statbuf *ssb, php_stream_context *context)
{
struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract;
- zval *zfilename, *zfuncname, *zretval, *zflags;
- zval **args[2];
+ zval zfuncname, zretval;
+ zval args[2];
int call_result;
- zval *object;
+ zval object;
int ret = -1;
/* create an instance of our class */
- object = user_stream_create_object(uwrap, context TSRMLS_CC);
- if(object == NULL) {
+ user_stream_create_object(uwrap, context, &object);
+ if (Z_TYPE(object) == IS_UNDEF) {
return ret;
}
/* call it's stat_url method - set up params first */
- MAKE_STD_ZVAL(zfilename);
- ZVAL_STRING(zfilename, url, 1);
- args[0] = &zfilename;
-
- MAKE_STD_ZVAL(zflags);
- ZVAL_LONG(zflags, flags);
- args[1] = &zflags;
+ ZVAL_STRING(&args[0], url);
+ ZVAL_LONG(&args[1], flags);
- MAKE_STD_ZVAL(zfuncname);
- ZVAL_STRING(zfuncname, USERSTREAM_STATURL, 1);
+ ZVAL_STRING(&zfuncname, USERSTREAM_STATURL);
call_result = call_user_function_ex(NULL,
&object,
- zfuncname,
+ &zfuncname,
&zretval,
2, args,
- 0, NULL TSRMLS_CC);
+ 0, NULL );
- if (call_result == SUCCESS && zretval != NULL && Z_TYPE_P(zretval) == IS_ARRAY) {
+ if (call_result == SUCCESS && Z_TYPE(zretval) == IS_ARRAY) {
/* We got the info we needed */
- if (SUCCESS == statbuf_from_array(zretval, ssb TSRMLS_CC))
+ if (SUCCESS == statbuf_from_array(&zretval, ssb))
ret = 0;
} else {
if (call_result == FAILURE) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_STATURL " is not implemented!",
+ php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_STATURL " is not implemented!",
uwrap->classname);
}
}
/* clean up */
zval_ptr_dtor(&object);
- if (zretval)
- zval_ptr_dtor(&zretval);
+ zval_ptr_dtor(&zretval);
zval_ptr_dtor(&zfuncname);
- zval_ptr_dtor(&zfilename);
- zval_ptr_dtor(&zflags);
+ zval_ptr_dtor(&args[1]);
+ zval_ptr_dtor(&args[0]);
return ret;
}
-static size_t php_userstreamop_readdir(php_stream *stream, char *buf, size_t count TSRMLS_DC)
+static size_t php_userstreamop_readdir(php_stream *stream, char *buf, size_t count)
{
zval func_name;
- zval *retval = NULL;
+ zval retval;
int call_result;
size_t didread = 0;
php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract;
@@ -1521,125 +1403,122 @@ static size_t php_userstreamop_readdir(php_stream *stream, char *buf, size_t cou
if (count != sizeof(php_stream_dirent))
return 0;
- ZVAL_STRINGL(&func_name, USERSTREAM_DIR_READ, sizeof(USERSTREAM_DIR_READ)-1, 0);
+ ZVAL_STRINGL(&func_name, USERSTREAM_DIR_READ, sizeof(USERSTREAM_DIR_READ)-1);
call_result = call_user_function_ex(NULL,
- &us->object,
+ Z_ISUNDEF(us->object)? NULL : &us->object,
&func_name,
&retval,
0, NULL,
- 0, NULL TSRMLS_CC);
+ 0, NULL);
- if (call_result == SUCCESS && retval != NULL && Z_TYPE_P(retval) != IS_BOOL) {
- convert_to_string(retval);
- PHP_STRLCPY(ent->d_name, Z_STRVAL_P(retval), sizeof(ent->d_name), Z_STRLEN_P(retval));
+ if (call_result == SUCCESS && Z_TYPE(retval) != IS_FALSE && Z_TYPE(retval) != IS_TRUE) {
+ convert_to_string(&retval);
+ PHP_STRLCPY(ent->d_name, Z_STRVAL(retval), sizeof(ent->d_name), Z_STRLEN(retval));
didread = sizeof(php_stream_dirent);
} else if (call_result == FAILURE) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_DIR_READ " is not implemented!",
+ php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_DIR_READ " is not implemented!",
us->wrapper->classname);
}
- if (retval)
- zval_ptr_dtor(&retval);
+ zval_ptr_dtor(&retval);
+ zval_ptr_dtor(&func_name);
return didread;
}
-static int php_userstreamop_closedir(php_stream *stream, int close_handle TSRMLS_DC)
+static int php_userstreamop_closedir(php_stream *stream, int close_handle)
{
zval func_name;
- zval *retval = NULL;
+ zval retval;
php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract;
assert(us != NULL);
- ZVAL_STRINGL(&func_name, USERSTREAM_DIR_CLOSE, sizeof(USERSTREAM_DIR_CLOSE)-1, 0);
+ ZVAL_STRINGL(&func_name, USERSTREAM_DIR_CLOSE, sizeof(USERSTREAM_DIR_CLOSE)-1);
call_user_function_ex(NULL,
- &us->object,
+ Z_ISUNDEF(us->object)? NULL : &us->object,
&func_name,
&retval,
- 0, NULL, 0, NULL TSRMLS_CC);
-
- if (retval)
- zval_ptr_dtor(&retval);
+ 0, NULL, 0, NULL);
+ zval_ptr_dtor(&retval);
+ zval_ptr_dtor(&func_name);
zval_ptr_dtor(&us->object);
+ ZVAL_UNDEF(&us->object);
efree(us);
return 0;
}
-static int php_userstreamop_rewinddir(php_stream *stream, off_t offset, int whence, off_t *newoffs TSRMLS_DC)
+static int php_userstreamop_rewinddir(php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffs)
{
zval func_name;
- zval *retval = NULL;
+ zval retval;
php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract;
- ZVAL_STRINGL(&func_name, USERSTREAM_DIR_REWIND, sizeof(USERSTREAM_DIR_REWIND)-1, 0);
+ ZVAL_STRINGL(&func_name, USERSTREAM_DIR_REWIND, sizeof(USERSTREAM_DIR_REWIND)-1);
call_user_function_ex(NULL,
- &us->object,
+ Z_ISUNDEF(us->object)? NULL : &us->object,
&func_name,
&retval,
- 0, NULL, 0, NULL TSRMLS_CC);
+ 0, NULL, 0, NULL);
- if (retval)
- zval_ptr_dtor(&retval);
+ zval_ptr_dtor(&retval);
+ zval_ptr_dtor(&func_name);
return 0;
}
-static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr TSRMLS_DC)
+static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr)
{
php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract;
zval func_name;
- zval *retval = NULL;
- zval *zcastas = NULL;
- zval **args[1];
+ zval retval;
+ zval args[1];
php_stream * intstream = NULL;
int call_result;
int ret = FAILURE;
- ZVAL_STRINGL(&func_name, USERSTREAM_CAST, sizeof(USERSTREAM_CAST)-1, 0);
+ ZVAL_STRINGL(&func_name, USERSTREAM_CAST, sizeof(USERSTREAM_CAST)-1);
- ALLOC_INIT_ZVAL(zcastas);
switch(castas) {
case PHP_STREAM_AS_FD_FOR_SELECT:
- ZVAL_LONG(zcastas, PHP_STREAM_AS_FD_FOR_SELECT);
+ ZVAL_LONG(&args[0], PHP_STREAM_AS_FD_FOR_SELECT);
break;
default:
- ZVAL_LONG(zcastas, PHP_STREAM_AS_STDIO);
+ ZVAL_LONG(&args[0], PHP_STREAM_AS_STDIO);
break;
}
- args[0] = &zcastas;
call_result = call_user_function_ex(NULL,
- &us->object,
+ Z_ISUNDEF(us->object)? NULL : &us->object,
&func_name,
&retval,
- 1, args, 0, NULL TSRMLS_CC);
+ 1, args, 0, NULL);
do {
if (call_result == FAILURE) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_CAST " is not implemented!",
+ php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_CAST " is not implemented!",
us->wrapper->classname);
break;
}
- if (retval == NULL || !zend_is_true(retval)) {
+ if (Z_ISUNDEF(retval) || !zend_is_true(&retval)) {
break;
}
php_stream_from_zval_no_verify(intstream, &retval);
if (!intstream) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_CAST " must return a stream resource",
+ php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_CAST " must return a stream resource",
us->wrapper->classname);
break;
}
if (intstream == stream) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_CAST " must not return itself",
+ php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_CAST " must not return itself",
us->wrapper->classname);
intstream = NULL;
break;
@@ -1647,12 +1526,9 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr T
ret = php_stream_cast(intstream, castas, retptr, 1);
} while (0);
- if (retval) {
- zval_ptr_dtor(&retval);
- }
- if (zcastas) {
- zval_ptr_dtor(&zcastas);
- }
+ zval_ptr_dtor(&retval);
+ zval_ptr_dtor(&func_name);
+ zval_ptr_dtor(&args[0]);
return ret;
}
diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c
index ee06f26bf2..3c293eb40a 100644
--- a/main/streams/xp_socket.c
+++ b/main/streams/xp_socket.c
@@ -1,8 +1,8 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2015 The PHP Group |
+ | Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -39,6 +39,13 @@
# define MSG_PEEK 0
#endif
+#ifdef PHP_WIN32
+/* send/recv family on windows expects int */
+# define XP_SOCK_BUF_SIZE(sz) (((sz) > INT_MAX) ? INT_MAX : (int)(sz))
+#else
+# define XP_SOCK_BUF_SIZE(sz) (sz)
+#endif
+
php_stream_ops php_stream_generic_socket_ops;
PHPAPI php_stream_ops php_stream_socket_ops;
php_stream_ops php_stream_udp_socket_ops;
@@ -48,16 +55,16 @@ php_stream_ops php_stream_unixdg_socket_ops;
#endif
-static int php_tcp_sockop_set_option(php_stream *stream, int option, int value, void *ptrparam TSRMLS_DC);
+static int php_tcp_sockop_set_option(php_stream *stream, int option, int value, void *ptrparam);
/* {{{ Generic socket stream operations */
-static size_t php_sockop_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC)
+static size_t php_sockop_write(php_stream *stream, const char *buf, size_t count)
{
php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract;
int didwrite;
struct timeval *ptimeout;
- if (sock->socket == -1) {
+ if (!sock || sock->socket == -1) {
return 0;
}
@@ -67,7 +74,7 @@ static size_t php_sockop_write(php_stream *stream, const char *buf, size_t count
ptimeout = &sock->timeout;
retry:
- didwrite = send(sock->socket, buf, count, (sock->is_blocked && ptimeout) ? MSG_DONTWAIT : 0);
+ didwrite = send(sock->socket, buf, XP_SOCK_BUF_SIZE(count), (sock->is_blocked && ptimeout) ? MSG_DONTWAIT : 0);
if (didwrite <= 0) {
long err = php_socket_errno();
@@ -95,13 +102,13 @@ retry:
} while (err == EINTR);
}
estr = php_socket_strerror(err, NULL, 0);
- php_error_docref(NULL TSRMLS_CC, E_NOTICE, "send of %ld bytes failed with errno=%ld %s",
- (long)count, err, estr);
+ php_error_docref(NULL, E_NOTICE, "send of " ZEND_LONG_FMT " bytes failed with errno=%ld %s",
+ (zend_long)count, err, estr);
efree(estr);
}
if (didwrite > 0) {
- php_stream_notify_progress_increment(stream->context, didwrite, 0);
+ php_stream_notify_progress_increment(PHP_STREAM_CONTEXT(stream), didwrite, 0);
}
if (didwrite < 0) {
@@ -111,15 +118,15 @@ retry:
return didwrite;
}
-static void php_sock_stream_wait_for_data(php_stream *stream, php_netstream_data_t *sock TSRMLS_DC)
+static void php_sock_stream_wait_for_data(php_stream *stream, php_netstream_data_t *sock)
{
int retval;
struct timeval *ptimeout;
- if (sock->socket == -1) {
+ if (!sock || sock->socket == -1) {
return;
}
-
+
sock->timeout_event = 0;
if (sock->timeout.tv_sec == -1)
@@ -141,27 +148,27 @@ static void php_sock_stream_wait_for_data(php_stream *stream, php_netstream_data
}
}
-static size_t php_sockop_read(php_stream *stream, char *buf, size_t count TSRMLS_DC)
+static size_t php_sockop_read(php_stream *stream, char *buf, size_t count)
{
php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract;
- int nr_bytes = 0;
+ ssize_t nr_bytes = 0;
- if (sock->socket == -1) {
+ if (!sock || sock->socket == -1) {
return 0;
}
if (sock->is_blocked) {
- php_sock_stream_wait_for_data(stream, sock TSRMLS_CC);
+ php_sock_stream_wait_for_data(stream, sock);
if (sock->timeout_event)
return 0;
}
- nr_bytes = recv(sock->socket, buf, count, (sock->is_blocked && sock->timeout.tv_sec != -1) ? MSG_DONTWAIT : 0);
+ nr_bytes = recv(sock->socket, buf, XP_SOCK_BUF_SIZE(count), (sock->is_blocked && sock->timeout.tv_sec != -1) ? MSG_DONTWAIT : 0);
stream->eof = (nr_bytes == 0 || (nr_bytes == -1 && php_socket_errno() != EWOULDBLOCK));
if (nr_bytes > 0) {
- php_stream_notify_progress_increment(stream->context, nr_bytes, 0);
+ php_stream_notify_progress_increment(PHP_STREAM_CONTEXT(stream), nr_bytes, 0);
}
if (nr_bytes < 0) {
@@ -172,13 +179,17 @@ static size_t php_sockop_read(php_stream *stream, char *buf, size_t count TSRMLS
}
-static int php_sockop_close(php_stream *stream, int close_handle TSRMLS_DC)
+static int php_sockop_close(php_stream *stream, int close_handle)
{
php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract;
#ifdef PHP_WIN32
int n;
#endif
+ if (!sock) {
+ return 0;
+ }
+
if (close_handle) {
#ifdef PHP_WIN32
@@ -207,11 +218,11 @@ static int php_sockop_close(php_stream *stream, int close_handle TSRMLS_DC)
}
pefree(sock, php_stream_is_persistent(stream));
-
+
return 0;
}
-static int php_sockop_flush(php_stream *stream TSRMLS_DC)
+static int php_sockop_flush(php_stream *stream)
{
#if 0
php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract;
@@ -220,32 +231,38 @@ static int php_sockop_flush(php_stream *stream TSRMLS_DC)
return 0;
}
-static int php_sockop_stat(php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC)
+static int php_sockop_stat(php_stream *stream, php_stream_statbuf *ssb)
{
- php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract;
#if ZEND_WIN32
return 0;
#else
- return fstat(sock->socket, &ssb->sb);
+ php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract;
+
+ return zend_fstat(sock->socket, &ssb->sb);
#endif
}
static inline int sock_sendto(php_netstream_data_t *sock, const char *buf, size_t buflen, int flags,
struct sockaddr *addr, socklen_t addrlen
- TSRMLS_DC)
+ )
{
int ret;
if (addr) {
- ret = sendto(sock->socket, buf, buflen, flags, addr, addrlen);
+ ret = sendto(sock->socket, buf, XP_SOCK_BUF_SIZE(buflen), flags, addr, XP_SOCK_BUF_SIZE(addrlen));
+
return (ret == SOCK_CONN_ERR) ? -1 : ret;
}
+#ifdef PHP_WIN32
+ return ((ret = send(sock->socket, buf, buflen > INT_MAX ? INT_MAX : (int)buflen, flags)) == SOCK_CONN_ERR) ? -1 : ret;
+#else
return ((ret = send(sock->socket, buf, buflen, flags)) == SOCK_CONN_ERR) ? -1 : ret;
+#endif
}
static inline int sock_recvfrom(php_netstream_data_t *sock, char *buf, size_t buflen, int flags,
- char **textaddr, long *textaddrlen,
+ zend_string **textaddr,
struct sockaddr **addr, socklen_t *addrlen
- TSRMLS_DC)
+ )
{
php_sockaddr_storage sa;
socklen_t sl = sizeof(sa);
@@ -253,24 +270,28 @@ static inline int sock_recvfrom(php_netstream_data_t *sock, char *buf, size_t bu
int want_addr = textaddr || addr;
if (want_addr) {
- ret = recvfrom(sock->socket, buf, buflen, flags, (struct sockaddr*)&sa, &sl);
+ ret = recvfrom(sock->socket, buf, XP_SOCK_BUF_SIZE(buflen), flags, (struct sockaddr*)&sa, &sl);
ret = (ret == SOCK_CONN_ERR) ? -1 : ret;
php_network_populate_name_from_sockaddr((struct sockaddr*)&sa, sl,
- textaddr, textaddrlen, addr, addrlen TSRMLS_CC);
+ textaddr, addr, addrlen);
} else {
- ret = recv(sock->socket, buf, buflen, flags);
+ ret = recv(sock->socket, buf, XP_SOCK_BUF_SIZE(buflen), flags);
ret = (ret == SOCK_CONN_ERR) ? -1 : ret;
}
return ret;
}
-static int php_sockop_set_option(php_stream *stream, int option, int value, void *ptrparam TSRMLS_DC)
+static int php_sockop_set_option(php_stream *stream, int option, int value, void *ptrparam)
{
int oldmode, flags;
php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract;
php_stream_xport_param *xparam;
-
+
+ if (!sock) {
+ return PHP_STREAM_OPTION_RETURN_NOTIMPL;
+ }
+
switch(option) {
case PHP_STREAM_OPTION_CHECK_LIVENESS:
{
@@ -299,10 +320,10 @@ static int php_sockop_set_option(php_stream *stream, int option, int value, void
}
return alive ? PHP_STREAM_OPTION_RETURN_OK : PHP_STREAM_OPTION_RETURN_ERR;
}
-
+
case PHP_STREAM_OPTION_BLOCKING:
oldmode = sock->is_blocked;
- if (SUCCESS == php_set_sock_blocking(sock->socket, value TSRMLS_CC)) {
+ if (SUCCESS == php_set_sock_blocking(sock->socket, value)) {
sock->is_blocked = value;
return oldmode;
}
@@ -318,7 +339,7 @@ static int php_sockop_set_option(php_stream *stream, int option, int value, void
add_assoc_bool((zval *)ptrparam, "blocked", sock->is_blocked);
add_assoc_bool((zval *)ptrparam, "eof", stream->eof);
return PHP_STREAM_OPTION_RETURN_OK;
-
+
case PHP_STREAM_OPTION_XPORT_API:
xparam = (php_stream_xport_param *)ptrparam;
@@ -330,19 +351,17 @@ static int php_sockop_set_option(php_stream *stream, int option, int value, void
case STREAM_XPORT_OP_GET_NAME:
xparam->outputs.returncode = php_network_get_sock_name(sock->socket,
xparam->want_textaddr ? &xparam->outputs.textaddr : NULL,
- xparam->want_textaddr ? &xparam->outputs.textaddrlen : NULL,
xparam->want_addr ? &xparam->outputs.addr : NULL,
xparam->want_addr ? &xparam->outputs.addrlen : NULL
- TSRMLS_CC);
+ );
return PHP_STREAM_OPTION_RETURN_OK;
case STREAM_XPORT_OP_GET_PEER_NAME:
xparam->outputs.returncode = php_network_get_peer_name(sock->socket,
xparam->want_textaddr ? &xparam->outputs.textaddr : NULL,
- xparam->want_textaddr ? &xparam->outputs.textaddrlen : NULL,
xparam->want_addr ? &xparam->outputs.addr : NULL,
xparam->want_addr ? &xparam->outputs.addrlen : NULL
- TSRMLS_CC);
+ );
return PHP_STREAM_OPTION_RETURN_OK;
case STREAM_XPORT_OP_SEND:
@@ -354,10 +373,10 @@ static int php_sockop_set_option(php_stream *stream, int option, int value, void
xparam->inputs.buf, xparam->inputs.buflen,
flags,
xparam->inputs.addr,
- xparam->inputs.addrlen TSRMLS_CC);
+ xparam->inputs.addrlen);
if (xparam->outputs.returncode == -1) {
char *err = php_socket_strerror(php_socket_errno(), NULL, 0);
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
+ php_error_docref(NULL, E_WARNING,
"%s\n", err);
efree(err);
}
@@ -375,10 +394,9 @@ static int php_sockop_set_option(php_stream *stream, int option, int value, void
xparam->inputs.buf, xparam->inputs.buflen,
flags,
xparam->want_textaddr ? &xparam->outputs.textaddr : NULL,
- xparam->want_textaddr ? &xparam->outputs.textaddrlen : NULL,
xparam->want_addr ? &xparam->outputs.addr : NULL,
xparam->want_addr ? &xparam->outputs.addrlen : NULL
- TSRMLS_CC);
+ );
return PHP_STREAM_OPTION_RETURN_OK;
@@ -399,7 +417,7 @@ static int php_sockop_set_option(php_stream *stream, int option, int value, void
return PHP_STREAM_OPTION_RETURN_OK;
}
#endif
-
+
default:
return PHP_STREAM_OPTION_RETURN_NOTIMPL;
}
@@ -409,10 +427,14 @@ static int php_sockop_set_option(php_stream *stream, int option, int value, void
}
}
-static int php_sockop_cast(php_stream *stream, int castas, void **ret TSRMLS_DC)
+static int php_sockop_cast(php_stream *stream, int castas, void **ret)
{
php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract;
+ if (!sock) {
+ return FAILURE;
+ }
+
switch(castas) {
case PHP_STREAM_AS_STDIO:
if (ret) {
@@ -496,7 +518,7 @@ php_stream_ops php_stream_unixdg_socket_ops = {
/* network socket operations */
#ifdef AF_UNIX
-static inline int parse_unix_address(php_stream_xport_param *xparam, struct sockaddr_un *unix_addr TSRMLS_DC)
+static inline int parse_unix_address(php_stream_xport_param *xparam, struct sockaddr_un *unix_addr)
{
memset(unix_addr, 0, sizeof(*unix_addr));
unix_addr->sun_family = AF_UNIX;
@@ -510,7 +532,7 @@ static inline int parse_unix_address(php_stream_xport_param *xparam, struct sock
* BUT, to get into this branch of code, the name is too long,
* so we don't care. */
xparam->inputs.namelen = sizeof(unix_addr->sun_path) - 1;
- php_error_docref(NULL TSRMLS_CC, E_NOTICE,
+ php_error_docref(NULL, E_NOTICE,
"socket path exceeded the maximum allowed length of %lu bytes "
"and was truncated", (unsigned long)sizeof(unix_addr->sun_path));
}
@@ -521,7 +543,7 @@ static inline int parse_unix_address(php_stream_xport_param *xparam, struct sock
}
#endif
-static inline char *parse_ip_address_ex(const char *str, size_t str_len, int *portno, int get_err, char **err TSRMLS_DC)
+static inline char *parse_ip_address_ex(const char *str, size_t str_len, int *portno, int get_err, zend_string **err)
{
char *colon;
char *host = NULL;
@@ -534,7 +556,7 @@ static inline char *parse_ip_address_ex(const char *str, size_t str_len, int *po
p = memchr(str + 1, ']', str_len - 2);
if (!p || *(p + 1) != ':') {
if (get_err) {
- spprintf(err, 0, "Failed to parse IPv6 address \"%s\"", str);
+ *err = strpprintf(0, "Failed to parse IPv6 address \"%s\"", str);
}
return NULL;
}
@@ -552,7 +574,7 @@ static inline char *parse_ip_address_ex(const char *str, size_t str_len, int *po
host = estrndup(str, colon - str);
} else {
if (get_err) {
- spprintf(err, 0, "Failed to parse address \"%s\"", str);
+ *err = strpprintf(0, "Failed to parse address \"%s\"", str);
}
return NULL;
}
@@ -560,16 +582,18 @@ static inline char *parse_ip_address_ex(const char *str, size_t str_len, int *po
return host;
}
-static inline char *parse_ip_address(php_stream_xport_param *xparam, int *portno TSRMLS_DC)
+static inline char *parse_ip_address(php_stream_xport_param *xparam, int *portno)
{
- return parse_ip_address_ex(xparam->inputs.name, xparam->inputs.namelen, portno, xparam->want_errortext, &xparam->outputs.error_text TSRMLS_CC);
+ return parse_ip_address_ex(xparam->inputs.name, xparam->inputs.namelen, portno, xparam->want_errortext, &xparam->outputs.error_text);
}
static inline int php_tcp_sockop_bind(php_stream *stream, php_netstream_data_t *sock,
- php_stream_xport_param *xparam TSRMLS_DC)
+ php_stream_xport_param *xparam)
{
char *host = NULL;
int portno, err;
+ long sockopts = STREAM_SOCKOP_NONE;
+ zval *tmpzval = NULL;
#ifdef AF_UNIX
if (stream->ops == &php_stream_unix_socket_ops || stream->ops == &php_stream_unixdg_socket_ops) {
@@ -579,32 +603,52 @@ static inline int php_tcp_sockop_bind(php_stream *stream, php_netstream_data_t *
if (sock->socket == SOCK_ERR) {
if (xparam->want_errortext) {
- spprintf(&xparam->outputs.error_text, 0, "Failed to create unix%s socket %s",
+ xparam->outputs.error_text = strpprintf(0, "Failed to create unix%s socket %s",
stream->ops == &php_stream_unix_socket_ops ? "" : "datagram",
strerror(errno));
}
return -1;
}
- parse_unix_address(xparam, &unix_addr TSRMLS_CC);
+ parse_unix_address(xparam, &unix_addr);
return bind(sock->socket, (const struct sockaddr *)&unix_addr,
(socklen_t) XtOffsetOf(struct sockaddr_un, sun_path) + xparam->inputs.namelen);
}
#endif
- host = parse_ip_address(xparam, &portno TSRMLS_CC);
+ host = parse_ip_address(xparam, &portno);
if (host == NULL) {
return -1;
}
+#ifdef SO_REUSEPORT
+ if (PHP_STREAM_CONTEXT(stream)
+ && (tmpzval = php_stream_context_get_option(PHP_STREAM_CONTEXT(stream), "socket", "so_reuseport")) != NULL
+ && zend_is_true(tmpzval)
+ ) {
+ sockopts |= STREAM_SOCKOP_SO_REUSEPORT;
+ }
+#endif
+
+#ifdef SO_BROADCAST
+ if (stream->ops == &php_stream_udp_socket_ops /* SO_BROADCAST is only applicable for UDP */
+ && PHP_STREAM_CONTEXT(stream)
+ && (tmpzval = php_stream_context_get_option(PHP_STREAM_CONTEXT(stream), "socket", "so_broadcast")) != NULL
+ && zend_is_true(tmpzval)
+ ) {
+ sockopts |= STREAM_SOCKOP_SO_BROADCAST;
+ }
+#endif
+
sock->socket = php_network_bind_socket_to_local_addr(host, portno,
stream->ops == &php_stream_udp_socket_ops ? SOCK_DGRAM : SOCK_STREAM,
+ sockopts,
xparam->want_errortext ? &xparam->outputs.error_text : NULL,
&err
- TSRMLS_CC);
-
+ );
+
if (host) {
efree(host);
}
@@ -613,13 +657,14 @@ static inline int php_tcp_sockop_bind(php_stream *stream, php_netstream_data_t *
}
static inline int php_tcp_sockop_connect(php_stream *stream, php_netstream_data_t *sock,
- php_stream_xport_param *xparam TSRMLS_DC)
+ php_stream_xport_param *xparam)
{
char *host = NULL, *bindto = NULL;
int portno, bindport = 0;
int err = 0;
int ret;
- zval **tmpzval = NULL;
+ zval *tmpzval = NULL;
+ long sockopts = STREAM_SOCKOP_NONE;
#ifdef AF_UNIX
if (stream->ops == &php_stream_unix_socket_ops || stream->ops == &php_stream_unixdg_socket_ops) {
@@ -629,12 +674,12 @@ static inline int php_tcp_sockop_connect(php_stream *stream, php_netstream_data_
if (sock->socket == SOCK_ERR) {
if (xparam->want_errortext) {
- spprintf(&xparam->outputs.error_text, 0, "Failed to create unix socket");
+ xparam->outputs.error_text = strpprintf(0, "Failed to create unix socket");
}
return -1;
}
- parse_unix_address(xparam, &unix_addr TSRMLS_CC);
+ parse_unix_address(xparam, &unix_addr);
ret = php_network_connect_socket(sock->socket,
(const struct sockaddr *)&unix_addr, (socklen_t) XtOffsetOf(struct sockaddr_un, sun_path) + xparam->inputs.namelen,
@@ -648,27 +693,37 @@ static inline int php_tcp_sockop_connect(php_stream *stream, php_netstream_data_
}
#endif
- host = parse_ip_address(xparam, &portno TSRMLS_CC);
+ host = parse_ip_address(xparam, &portno);
if (host == NULL) {
return -1;
}
- if (stream->context && php_stream_context_get_option(stream->context, "socket", "bindto", &tmpzval) == SUCCESS) {
- if (Z_TYPE_PP(tmpzval) != IS_STRING) {
+ if (PHP_STREAM_CONTEXT(stream) && (tmpzval = php_stream_context_get_option(PHP_STREAM_CONTEXT(stream), "socket", "bindto")) != NULL) {
+ if (Z_TYPE_P(tmpzval) != IS_STRING) {
if (xparam->want_errortext) {
- spprintf(&xparam->outputs.error_text, 0, "local_addr context option is not a string.");
+ xparam->outputs.error_text = strpprintf(0, "local_addr context option is not a string.");
}
efree(host);
return -1;
}
- bindto = parse_ip_address_ex(Z_STRVAL_PP(tmpzval), Z_STRLEN_PP(tmpzval), &bindport, xparam->want_errortext, &xparam->outputs.error_text TSRMLS_CC);
+ bindto = parse_ip_address_ex(Z_STRVAL_P(tmpzval), Z_STRLEN_P(tmpzval), &bindport, xparam->want_errortext, &xparam->outputs.error_text);
}
+#ifdef SO_BROADCAST
+ if (stream->ops == &php_stream_udp_socket_ops /* SO_BROADCAST is only applicable for UDP */
+ && PHP_STREAM_CONTEXT(stream)
+ && (tmpzval = php_stream_context_get_option(PHP_STREAM_CONTEXT(stream), "socket", "so_broadcast")) != NULL
+ && zend_is_true(tmpzval)
+ ) {
+ sockopts |= STREAM_SOCKOP_SO_BROADCAST;
+ }
+#endif
+
/* Note: the test here for php_stream_udp_socket_ops is important, because we
* want the default to be TCP sockets so that the openssl extension can
* re-use this code. */
-
+
sock->socket = php_network_connect_socket_to_host(host, portno,
stream->ops == &php_stream_udp_socket_ops ? SOCK_DGRAM : SOCK_STREAM,
xparam->op == STREAM_XPORT_OP_CONNECT_ASYNC,
@@ -676,9 +731,10 @@ static inline int php_tcp_sockop_connect(php_stream *stream, php_netstream_data_
xparam->want_errortext ? &xparam->outputs.error_text : NULL,
&err,
bindto,
- bindport
- TSRMLS_CC);
-
+ bindport,
+ sockopts
+ );
+
ret = sock->socket == -1 ? -1 : 0;
xparam->outputs.error_code = err;
@@ -697,12 +753,12 @@ out:
/* indicates pending connection */
return 1;
}
-
+
return ret;
}
static inline int php_tcp_sockop_accept(php_stream *stream, php_netstream_data_t *sock,
- php_stream_xport_param *xparam STREAMS_DC TSRMLS_DC)
+ php_stream_xport_param *xparam STREAMS_DC)
{
int clisock;
@@ -710,13 +766,12 @@ static inline int php_tcp_sockop_accept(php_stream *stream, php_netstream_data_t
clisock = php_network_accept_incoming(sock->socket,
xparam->want_textaddr ? &xparam->outputs.textaddr : NULL,
- xparam->want_textaddr ? &xparam->outputs.textaddrlen : NULL,
xparam->want_addr ? &xparam->outputs.addr : NULL,
xparam->want_addr ? &xparam->outputs.addrlen : NULL,
xparam->inputs.timeout,
xparam->want_errortext ? &xparam->outputs.error_text : NULL,
&xparam->outputs.error_code
- TSRMLS_CC);
+ );
if (clisock >= 0) {
php_netstream_data_t *clisockdata;
@@ -732,18 +787,18 @@ static inline int php_tcp_sockop_accept(php_stream *stream, php_netstream_data_t
xparam->outputs.client = php_stream_alloc_rel(stream->ops, clisockdata, NULL, "r+");
if (xparam->outputs.client) {
- xparam->outputs.client->context = stream->context;
- if (stream->context) {
- zend_list_addref(stream->context->rsrc_id);
+ xparam->outputs.client->ctx = stream->ctx;
+ if (stream->ctx) {
+ GC_REFCOUNT(stream->ctx)++;
}
}
}
}
-
+
return xparam->outputs.client == NULL ? -1 : 0;
}
-static int php_tcp_sockop_set_option(php_stream *stream, int option, int value, void *ptrparam TSRMLS_DC)
+static int php_tcp_sockop_set_option(php_stream *stream, int option, int value, void *ptrparam)
{
php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract;
php_stream_xport_param *xparam;
@@ -755,23 +810,23 @@ static int php_tcp_sockop_set_option(php_stream *stream, int option, int value,
switch(xparam->op) {
case STREAM_XPORT_OP_CONNECT:
case STREAM_XPORT_OP_CONNECT_ASYNC:
- xparam->outputs.returncode = php_tcp_sockop_connect(stream, sock, xparam TSRMLS_CC);
+ xparam->outputs.returncode = php_tcp_sockop_connect(stream, sock, xparam);
return PHP_STREAM_OPTION_RETURN_OK;
case STREAM_XPORT_OP_BIND:
- xparam->outputs.returncode = php_tcp_sockop_bind(stream, sock, xparam TSRMLS_CC);
+ xparam->outputs.returncode = php_tcp_sockop_bind(stream, sock, xparam);
return PHP_STREAM_OPTION_RETURN_OK;
case STREAM_XPORT_OP_ACCEPT:
- xparam->outputs.returncode = php_tcp_sockop_accept(stream, sock, xparam STREAMS_CC TSRMLS_CC);
+ xparam->outputs.returncode = php_tcp_sockop_accept(stream, sock, xparam STREAMS_CC);
return PHP_STREAM_OPTION_RETURN_OK;
default:
/* fall through */
;
}
}
- return php_sockop_set_option(stream, option, value, ptrparam TSRMLS_CC);
+ return php_sockop_set_option(stream, option, value, ptrparam);
}
@@ -779,7 +834,7 @@ PHPAPI php_stream *php_stream_generic_socket_factory(const char *proto, size_t p
const char *resourcename, size_t resourcenamelen,
const char *persistent_id, int options, int flags,
struct timeval *timeout,
- php_stream_context *context STREAMS_DC TSRMLS_DC)
+ php_stream_context *context STREAMS_DC)
{
php_stream *stream = NULL;
php_netstream_data_t *sock;
@@ -802,7 +857,7 @@ PHPAPI php_stream *php_stream_generic_socket_factory(const char *proto, size_t p
/* should never happen */
return NULL;
}
-
+
sock = pemalloc(sizeof(php_netstream_data_t), persistent_id ? 1 : 0);
memset(sock, 0, sizeof(php_netstream_data_t));
@@ -813,7 +868,7 @@ PHPAPI php_stream *php_stream_generic_socket_factory(const char *proto, size_t p
/* we don't know the socket until we have determined if we are binding or
* connecting */
sock->socket = -1;
-
+
stream = php_stream_alloc_rel(ops, sock, persistent_id, "r+");
if (stream == NULL) {