diff options
author | Ondřej Surý <ondrej@sury.org> | 2011-10-21 11:11:28 +0200 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2011-10-21 11:11:28 +0200 |
commit | cabdec2be579c07e03c43361f30cea5ccf8e0abb (patch) | |
tree | 58cddb33ca2f1304ecf027c8bcd5bace439db54b /main/streams | |
parent | fe956d3fa6d11dd971c27768ee1799642c8abe01 (diff) | |
download | php-cabdec2be579c07e03c43361f30cea5ccf8e0abb.tar.gz |
Imported Upstream version 5.4.0~beta2upstream/5.4.0_beta2
Diffstat (limited to 'main/streams')
-rw-r--r-- | main/streams/cast.c | 16 | ||||
-rwxr-xr-x | main/streams/glob_wrapper.c | 4 | ||||
-rw-r--r-- | main/streams/memory.c | 20 | ||||
-rw-r--r-- | main/streams/mmap.c | 2 | ||||
-rw-r--r-- | main/streams/php_stream_context.h | 6 | ||||
-rwxr-xr-x | main/streams/php_stream_glob_wrapper.h | 2 | ||||
-rw-r--r-- | main/streams/php_stream_mmap.h | 2 | ||||
-rw-r--r-- | main/streams/php_stream_plain_wrapper.h | 2 | ||||
-rw-r--r-- | main/streams/php_stream_transport.h | 2 | ||||
-rw-r--r-- | main/streams/php_stream_userspace.h | 2 | ||||
-rw-r--r-- | main/streams/php_streams_int.h | 2 | ||||
-rw-r--r-- | main/streams/plain_wrapper.c | 263 | ||||
-rwxr-xr-x | main/streams/streams.c | 100 | ||||
-rw-r--r-- | main/streams/transports.c | 2 | ||||
-rw-r--r-- | main/streams/userspace.c | 343 | ||||
-rw-r--r-- | main/streams/xp_socket.c | 6 |
16 files changed, 504 insertions, 270 deletions
diff --git a/main/streams/cast.c b/main/streams/cast.c index 1dcfba00c..45c5a12b0 100644 --- a/main/streams/cast.c +++ b/main/streams/cast.c @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: cast.c 307611 2011-01-20 06:32:59Z pajoye $ */ +/* $Id: cast.c 316121 2011-09-04 22:36:33Z cataphract $ */ #define _GNU_SOURCE #include "php.h" @@ -271,15 +271,15 @@ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show newstream = php_stream_fopen_tmpfile(); if (newstream) { - int retval = php_stream_copy_to_stream_ex(stream, newstream, PHP_STREAM_COPY_ALL, NULL); + int retcopy = php_stream_copy_to_stream_ex(stream, newstream, PHP_STREAM_COPY_ALL, NULL); - if (ret != SUCCESS) { + if (retcopy != SUCCESS) { php_stream_close(newstream); } else { - int retcode = php_stream_cast(newstream, castas | flags, (void **)ret, show_err); + int retcast = php_stream_cast(newstream, castas | flags, (void **)ret, show_err); - if (retcode == SUCCESS) { - rewind(*(FILE**)retval); + if (retcast == SUCCESS) { + rewind(*(FILE**)ret); } /* do some specialized cleanup */ @@ -287,7 +287,9 @@ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show php_stream_free(stream, PHP_STREAM_FREE_CLOSE_CASTED); } - return retcode; + /* TODO: we probably should be setting .stdiocast and .fclose_stdiocast or + * we may be leaking the FILE*. Needs investigation, though. */ + return retcast; } } } diff --git a/main/streams/glob_wrapper.c b/main/streams/glob_wrapper.c index 67bceb2ca..a5fb3d15d 100755 --- a/main/streams/glob_wrapper.c +++ b/main/streams/glob_wrapper.c @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: glob_wrapper.c 306939 2011-01-01 02:19:59Z felipe $ */ +/* $Id: glob_wrapper.c 306938 2011-01-01 02:17:06Z felipe $ */ #include "php.h" #include "php_streams_int.h" @@ -145,7 +145,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 < pglob->glob.gl_pathc) { + 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_STRLCPY(ent->d_name, path, sizeof(ent->d_name), strlen(path)); return sizeof(php_stream_dirent); diff --git a/main/streams/memory.c b/main/streams/memory.c index aa338da2e..8918c9021 100644 --- a/main/streams/memory.c +++ b/main/streams/memory.c @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: memory.c 306939 2011-01-01 02:19:59Z felipe $ */ +/* $Id: memory.c 306938 2011-01-01 02:17:06Z felipe $ */ #define _GNU_SOURCE #include "php.h" @@ -42,7 +42,6 @@ typedef struct { size_t fsize; size_t smax; int mode; - php_stream **owner_ptr; } php_stream_memory_data; @@ -112,9 +111,6 @@ static int php_stream_memory_close(php_stream *stream, int close_handle TSRMLS_D if (ms->data && close_handle && ms->mode != TEMP_STREAM_READONLY) { efree(ms->data); } - if (ms->owner_ptr) { - *ms->owner_ptr = NULL; - } efree(ms); return 0; } @@ -301,7 +297,6 @@ PHPAPI php_stream *_php_stream_memory_create(int mode STREAMS_DC TSRMLS_DC) self->fsize = 0; self->smax = ~0u; self->mode = mode; - self->owner_ptr = NULL; 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; @@ -376,8 +371,9 @@ static size_t php_stream_temp_write(php_stream *stream, const char *buf, size_t if (memsize + count >= ts->smax) { php_stream *file = php_stream_fopen_tmpfile(); php_stream_write(file, membuf, memsize); - php_stream_close(ts->innerstream); + php_stream_free_enclosed(ts->innerstream, PHP_STREAM_FREE_CLOSE); ts->innerstream = file; + php_stream_encloses(stream, ts->innerstream); } } return php_stream_write(ts->innerstream, buf, count); @@ -415,7 +411,7 @@ static int php_stream_temp_close(php_stream *stream, int close_handle TSRMLS_DC) assert(ts != NULL); if (ts->innerstream) { - ret = php_stream_free(ts->innerstream, PHP_STREAM_FREE_CLOSE | (close_handle ? 0 : PHP_STREAM_FREE_PRESERVE_HANDLE)); + ret = php_stream_free_enclosed(ts->innerstream, PHP_STREAM_FREE_CLOSE | (close_handle ? 0 : PHP_STREAM_FREE_PRESERVE_HANDLE)); } else { ret = 0; } @@ -499,9 +495,10 @@ 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_close(ts->innerstream); + + php_stream_free_enclosed(ts->innerstream, PHP_STREAM_FREE_CLOSE); ts->innerstream = file; + php_stream_encloses(stream, ts->innerstream); php_stream_seek(ts->innerstream, pos, SEEK_SET); return php_stream_cast(ts->innerstream, castas, ret, 1); @@ -563,8 +560,7 @@ PHPAPI php_stream *_php_stream_temp_create(int mode, size_t max_memory_usage STR stream = php_stream_alloc_rel(&php_stream_temp_ops, self, 0, mode & TEMP_STREAM_READONLY ? "rb" : "w+b"); stream->flags |= PHP_STREAM_FLAG_NO_BUFFER; self->innerstream = php_stream_memory_create_rel(mode); - php_stream_auto_cleanup(self->innerstream); /* do not warn if innerstream is GC'ed before stream */ - ((php_stream_memory_data*)self->innerstream->abstract)->owner_ptr = &self->innerstream; + php_stream_encloses(stream, self->innerstream); return stream; } diff --git a/main/streams/mmap.c b/main/streams/mmap.c index de8a3d2eb..1d221e292 100644 --- a/main/streams/mmap.c +++ b/main/streams/mmap.c @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: mmap.c 306939 2011-01-01 02:19:59Z felipe $ */ +/* $Id: mmap.c 306938 2011-01-01 02:17:06Z felipe $ */ /* Memory Mapping interface for streams */ #include "php.h" diff --git a/main/streams/php_stream_context.h b/main/streams/php_stream_context.h index 10f5a7906..cbfb517ff 100644 --- a/main/streams/php_stream_context.h +++ b/main/streams/php_stream_context.h @@ -33,10 +33,10 @@ 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()) : \ + (zcontext) ? zend_fetch_resource(&(zcontext) TSRMLS_CC, -1, "Stream-Context", NULL, 1, php_le_stream_context(TSRMLS_C)) : \ (nocontext) ? NULL : \ FG(default_context) ? FG(default_context) : \ - (FG(default_context) = php_stream_context_alloc()) ) + (FG(default_context) = php_stream_context_alloc(TSRMLS_C)) ) #define php_stream_context_to_zval(context, zval) { ZVAL_RESOURCE(zval, (context)->rsrc_id); zend_list_addref((context)->rsrc_id); } @@ -59,7 +59,7 @@ struct _php_stream_context { BEGIN_EXTERN_C() PHPAPI void php_stream_context_free(php_stream_context *context); -PHPAPI php_stream_context *php_stream_context_alloc(void); +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 int php_stream_context_set_option(php_stream_context *context, diff --git a/main/streams/php_stream_glob_wrapper.h b/main/streams/php_stream_glob_wrapper.h index f55245bb0..3ccf2f57d 100755 --- a/main/streams/php_stream_glob_wrapper.h +++ b/main/streams/php_stream_glob_wrapper.h @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_stream_glob_wrapper.h 306939 2011-01-01 02:19:59Z felipe $ */ +/* $Id: php_stream_glob_wrapper.h 306938 2011-01-01 02:17:06Z felipe $ */ PHPAPI extern php_stream_wrapper php_glob_stream_wrapper; PHPAPI extern php_stream_ops php_glob_stream_ops; diff --git a/main/streams/php_stream_mmap.h b/main/streams/php_stream_mmap.h index 242b43e05..5c5d514c5 100644 --- a/main/streams/php_stream_mmap.h +++ b/main/streams/php_stream_mmap.h @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_stream_mmap.h 306939 2011-01-01 02:19:59Z felipe $ */ +/* $Id: php_stream_mmap.h 306938 2011-01-01 02:17:06Z felipe $ */ /* Memory Mapping interface for streams. * The intention is to provide a uniform interface over the most common diff --git a/main/streams/php_stream_plain_wrapper.h b/main/streams/php_stream_plain_wrapper.h index 2d64fec19..9b513e3c3 100644 --- a/main/streams/php_stream_plain_wrapper.h +++ b/main/streams/php_stream_plain_wrapper.h @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_stream_plain_wrapper.h 306939 2011-01-01 02:19:59Z felipe $ */ +/* $Id: php_stream_plain_wrapper.h 306938 2011-01-01 02:17:06Z felipe $ */ /* definitions for the plain files wrapper */ diff --git a/main/streams/php_stream_transport.h b/main/streams/php_stream_transport.h index e14ac1023..a17245c7b 100644 --- a/main/streams/php_stream_transport.h +++ b/main/streams/php_stream_transport.h @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_stream_transport.h 306939 2011-01-01 02:19:59Z felipe $ */ +/* $Id: php_stream_transport.h 306938 2011-01-01 02:17:06Z felipe $ */ #ifdef PHP_WIN32 #include "config.w32.h" #include <Ws2tcpip.h> diff --git a/main/streams/php_stream_userspace.h b/main/streams/php_stream_userspace.h index 08a66e50e..f36c61c38 100644 --- a/main/streams/php_stream_userspace.h +++ b/main/streams/php_stream_userspace.h @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_stream_userspace.h 306939 2011-01-01 02:19:59Z felipe $ */ +/* $Id: php_stream_userspace.h 306938 2011-01-01 02:17:06Z felipe $ */ /* for user-space streams */ diff --git a/main/streams/php_streams_int.h b/main/streams/php_streams_int.h index 168614ea1..dda614011 100644 --- a/main/streams/php_streams_int.h +++ b/main/streams/php_streams_int.h @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_streams_int.h 306939 2011-01-01 02:19:59Z felipe $ */ +/* $Id: php_streams_int.h 306938 2011-01-01 02:17:06Z felipe $ */ #if ZEND_DEBUG diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index 01fb7111c..8f134b2df 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: plain_wrapper.c 308011 2011-02-04 10:47:41Z aharvey $ */ +/* $Id: plain_wrapper.c 316627 2011-09-13 13:29:35Z dmitry $ */ #include "php.h" #include "php_globals.h" @@ -48,6 +48,11 @@ #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) +#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); +#endif + /* parse standard "fopen" modes into open() flags */ PHPAPI int php_stream_parse_fopen_modes(const char *mode, int *open_flags) { @@ -108,7 +113,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 */ @@ -134,7 +139,7 @@ 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); d->cached_fstat = r == 0; @@ -147,7 +152,7 @@ static int do_fstat(php_stdio_stream_data *d, int force) static php_stream *_php_stream_fopen_from_fd_int(int fd, const char *mode, const char *persistent_id STREAMS_DC TSRMLS_DC) { php_stdio_stream_data *self; - + self = pemalloc_rel_orig(sizeof(*self), persistent_id); memset(self, 0, sizeof(*self)); self->file = NULL; @@ -156,14 +161,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) { php_stdio_stream_data *self; - + self = emalloc_rel_orig(sizeof(*self)); memset(self, 0, sizeof(*self)); self->file = file; @@ -208,7 +213,7 @@ PHPAPI php_stream *_php_stream_fopen_tmpfile(int dummy STREAMS_DC TSRMLS_DC) self->temp_file_name = opened_path; self->lock_flag = LOCK_UN; - + return stream; } close(fd); @@ -241,7 +246,7 @@ 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 { @@ -280,7 +285,7 @@ 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 { @@ -349,9 +354,9 @@ static size_t php_stdiop_read(php_stream *stream, char *buf, size_t count TSRMLS so script can retry if desired */ ret = read(data->fd, buf, 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') @@ -388,7 +393,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) { @@ -458,14 +463,14 @@ static int php_stdiop_seek(php_stream *stream, off_t offset, int whence, off_t * if (data->fd >= 0) { off_t result; - + result = lseek(data->fd, offset, whence); if (result == (off_t)-1) return -1; *newoffset = result; return 0; - + } else { ret = fseek(data->file, offset, whence); *newoffset = ftell(data->file); @@ -479,7 +484,7 @@ static int php_stdiop_cast(php_stream *stream, int castas, void **ret TSRMLS_DC) 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 */ @@ -497,7 +502,7 @@ static int php_stdiop_cast(php_stream *stream, int castas, void **ret TSRMLS_DC) return FAILURE; } } - + *(FILE**)ret = data->file; data->fd = -1; } @@ -553,9 +558,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) @@ -567,20 +572,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 @@ -588,22 +593,19 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void switch(value) { case PHP_STREAM_BUFFER_NONE: - stream->flags |= PHP_STREAM_FLAG_NO_BUFFER; return setvbuf(data->file, NULL, _IONBF, 0); - + case PHP_STREAM_BUFFER_LINE: - stream->flags ^= PHP_STREAM_FLAG_NO_BUFFER; return setvbuf(data->file, NULL, _IOLBF, size); - + case PHP_STREAM_BUFFER_FULL: - stream->flags ^= PHP_STREAM_FLAG_NO_BUFFER; return setvbuf(data->file, NULL, _IOFBF, size); default: return -1; } break; - + case PHP_STREAM_OPTION_LOCKING: if (fd == -1) { return -1; @@ -626,7 +628,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; @@ -791,7 +793,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; } @@ -864,11 +866,7 @@ static php_stream *php_plain_files_dir_opener(php_stream_wrapper *wrapper, char if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(path TSRMLS_CC)) { return NULL; } - - if (PG(safe_mode) &&(!php_checkuid(path, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { - return NULL; - } - + dir = VCWD_OPENDIR(path); #ifdef PHP_WIN32 @@ -886,7 +884,7 @@ static php_stream *php_plain_files_dir_opener(php_stream_wrapper *wrapper, char if (stream == NULL) closedir(dir); } - + return stream; } /* }}} */ @@ -934,7 +932,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) { @@ -998,13 +996,6 @@ static php_stream *php_plain_files_stream_opener(php_stream_wrapper *wrapper, ch return NULL; } - if ((php_check_safe_mode_include_dir(path TSRMLS_CC)) == 0) { - return php_stream_fopen_rel(path, mode, opened_path, options); - } - - if ((options & ENFORCE_SAFE_MODE) && PG(safe_mode) && (!php_checkuid(path, mode, CHECKUID_CHECK_MODE_PARAM))) - return NULL; - return php_stream_fopen_rel(path, mode, opened_path, options); } @@ -1015,10 +1006,6 @@ static int php_plain_files_url_stater(php_stream_wrapper *wrapper, char *url, in url += sizeof("file://") - 1; } - if (PG(safe_mode) &&(!php_checkuid_ex(url, NULL, CHECKUID_CHECK_FILE_AND_DIR, (flags & PHP_STREAM_URL_STAT_QUIET) ? CHECKUID_NO_ERRORS : 0))) { - return -1; - } - if (php_check_open_basedir_ex(url, (flags & PHP_STREAM_URL_STAT_QUIET) ? 0 : 1 TSRMLS_CC)) { return -1; } @@ -1048,14 +1035,8 @@ static int php_plain_files_unlink(php_stream_wrapper *wrapper, char *url, int op url = p + 3; } - if (options & ENFORCE_SAFE_MODE) { - if (PG(safe_mode) && !php_checkuid(url, NULL, CHECKUID_CHECK_FILE_AND_DIR)) { - return 0; - } - - if (php_check_open_basedir(url TSRMLS_CC)) { - return 0; - } + if (php_check_open_basedir(url TSRMLS_CC)) { + return 0; } ret = VCWD_UNLINK(url); @@ -1100,11 +1081,6 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, char *url_from, c url_to = p + 3; } - if (PG(safe_mode) && (!php_checkuid(url_from, NULL, CHECKUID_CHECK_FILE_AND_DIR) || - !php_checkuid(url_to, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { - return 0; - } - if (php_check_open_basedir(url_from TSRMLS_CC) || php_check_open_basedir(url_to TSRMLS_CC)) { return 0; } @@ -1175,31 +1151,25 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, char *dir, int mod ret = php_mkdir(dir, mode TSRMLS_CC); } else { /* we look for directory separator from the end of string, thus hopefuly reducing our work load */ - char *e, *buf; + char *e; struct stat sb; int dir_len = strlen(dir); int offset = 0; + char buf[MAXPATHLEN]; - buf = estrndup(dir, dir_len); - -#ifdef PHP_WIN32 - e = buf; - while (*e) { - if (*e == '/') { - *e = DEFAULT_SLASH; - } - e++; + if (!expand_filepath_with_mode(dir, buf, NULL, 0, CWD_EXPAND TSRMLS_CC)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid path"); + return 0; } -#else - e = buf + dir_len; -#endif + + e = buf + strlen(buf); if ((p = memchr(buf, DEFAULT_SLASH, dir_len))) { offset = p - buf + 1; } if (p && dir_len == 1) { - /* buf == "DEFAULT_SLASH" */ + /* buf == "DEFAULT_SLASH" */ } else { /* find a top level directory we need to create */ @@ -1244,7 +1214,6 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, char *dir, int mod } } } - efree(buf); } if (ret < 0) { /* Failure */ @@ -1260,10 +1229,6 @@ static int php_plain_files_rmdir(php_stream_wrapper *wrapper, char *url, int opt #if PHP_WIN32 int url_len = strlen(url); #endif - if (PG(safe_mode) &&(!php_checkuid(url, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { - return 0; - } - if (php_check_open_basedir(url TSRMLS_CC)) { return 0; } @@ -1286,6 +1251,92 @@ static int php_plain_files_rmdir(php_stream_wrapper *wrapper, char *url, int opt return 1; } +static int php_plain_files_metadata(php_stream_wrapper *wrapper, char *url, int option, void *value, php_stream_context *context TSRMLS_DC) +{ + struct utimbuf *newtime; + char *p; +#if !defined(WINDOWS) && !defined(NETWARE) + uid_t uid; + gid_t gid; +#endif + mode_t mode; + int ret = 0; +#if PHP_WIN32 + int url_len = 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)); + return 0; + } +#endif + + if ((p = strstr(url, "://")) != NULL) { + url = p + 3; + } + + if (php_check_open_basedir(url TSRMLS_CC)) { + return 0; + } + + switch(option) { + case PHP_STREAM_META_TOUCH: + newtime = (struct utimbuf *)value; + 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)); + return 0; + } + fclose(file); + } + + ret = VCWD_UTIME(url, newtime); + break; +#if !defined(WINDOWS) && !defined(NETWARE) + 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); + return 0; + } + } else { + uid = (uid_t)*(long *)value; + } + ret = VCWD_CHOWN(url, uid, -1); + break; + 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); + return 0; + } + } else { + gid = (gid_t)*(long *)value; + } + ret = VCWD_CHOWN(url, -1, gid); + break; +#endif + case PHP_STREAM_META_ACCESS: + mode = (mode_t)*(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); + return 0; + } + if (ret == -1) { + php_error_docref1(NULL TSRMLS_CC, url, E_WARNING, "Operation failed: %s", strerror(errno)); + return 0; + } + php_clear_stat_cache(0, NULL, 0 TSRMLS_CC); + return 1; +} + + static php_stream_wrapper_ops php_plain_files_wrapper_ops = { php_plain_files_stream_opener, NULL, @@ -1296,7 +1347,8 @@ static php_stream_wrapper_ops php_plain_files_wrapper_ops = { php_plain_files_unlink, php_plain_files_rename, php_plain_files_mkdir, - php_plain_files_rmdir + php_plain_files_rmdir, + php_plain_files_metadata }; php_stream_wrapper php_plain_files_wrapper = { @@ -1310,7 +1362,7 @@ PHPAPI php_stream *_php_stream_fopen_with_path(char *filename, char *mode, char { /* code ripped off from fopen_wrappers.c */ char *pathbuf, *ptr, *end; - char *exec_fname; + const char *exec_fname; char trypath[MAXPATHLEN]; php_stream *stream; int path_length; @@ -1343,17 +1395,9 @@ PHPAPI php_stream *_php_stream_fopen_with_path(char *filename, char *mode, char return NULL; } - if (PG(safe_mode) && (!php_checkuid(filename, mode, CHECKUID_CHECK_MODE_PARAM))) { - return NULL; - } return php_stream_fopen_rel(filename, mode, opened_path, options); } - /* - * files in safe_mode_include_dir (or subdir) are excluded from - * safe mode GID/UID checks - */ - not_relative_path: /* Absolute path open */ @@ -1363,16 +1407,9 @@ not_relative_path: return NULL; } - if ((php_check_safe_mode_include_dir(filename TSRMLS_CC)) == 0) - /* filename is in safe_mode_include_dir (or subdir) */ - return php_stream_fopen_rel(filename, mode, opened_path, options); - - if (PG(safe_mode) && (!php_checkuid(filename, mode, CHECKUID_CHECK_MODE_PARAM))) - return NULL; - return php_stream_fopen_rel(filename, mode, opened_path, options); } - + #ifdef PHP_WIN32 if (IS_SLASH(filename[0])) { size_t cwd_len; @@ -1380,31 +1417,22 @@ not_relative_path: cwd = virtual_getcwd_ex(&cwd_len TSRMLS_CC); /* 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); } - + free(cwd); - + if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(trypath TSRMLS_CC)) { return NULL; } - if ((php_check_safe_mode_include_dir(trypath TSRMLS_CC)) == 0) { - return php_stream_fopen_rel(trypath, mode, opened_path, options); - } - if (PG(safe_mode) && (!php_checkuid(trypath, mode, CHECKUID_CHECK_MODE_PARAM))) { - return NULL; - } - + return php_stream_fopen_rel(trypath, mode, opened_path, options); } #endif if (!path || (path && !*path)) { - if (PG(safe_mode) && (!php_checkuid(filename, mode, CHECKUID_CHECK_MODE_PARAM))) { - return NULL; - } return php_stream_fopen_rel(filename, mode, opened_path, options); } @@ -1451,24 +1479,9 @@ not_relative_path: if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir_ex(trypath, 0 TSRMLS_CC)) { goto stream_skip; } - - if (PG(safe_mode)) { - struct stat sb; - if (VCWD_STAT(trypath, &sb) == 0) { - /* file exists ... check permission */ - if ((php_check_safe_mode_include_dir(trypath TSRMLS_CC) == 0) || - php_checkuid_ex(trypath, mode, CHECKUID_CHECK_MODE_PARAM, CHECKUID_NO_ERRORS)) { - /* UID ok, or trypath is in safe_mode_include_dir */ - stream = php_stream_fopen_rel(trypath, mode, opened_path, options); - goto stream_done; - } - } - goto stream_skip; - } stream = php_stream_fopen_rel(trypath, mode, opened_path, options); if (stream) { -stream_done: efree(pathbuf); return stream; } diff --git a/main/streams/streams.c b/main/streams/streams.c index be2745cb8..8e6a237bb 100755 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: streams.c 312937 2011-07-05 16:09:06Z cataphract $ */ +/* $Id: streams.c 316121 2011-09-04 22:36:33Z cataphract $ */ #define _GNU_SOURCE #include "php.h" @@ -105,6 +105,15 @@ PHP_RSHUTDOWN_FUNCTION(streams) return SUCCESS; } +PHPAPI php_stream *php_stream_encloses(php_stream *enclosing, php_stream *enclosed) +{ + php_stream *orig = enclosed->enclosing_stream; + + php_stream_auto_cleanup(enclosed); + enclosed->enclosing_stream = enclosing; + return orig; +} + PHPAPI int php_stream_from_persistent_id(const char *persistent_id, php_stream **stream TSRMLS_DC) { zend_rsrc_list_entry *le; @@ -305,19 +314,56 @@ fprintf(stderr, "stream_alloc: %s:%p persistent=%s\n", ops->label, ret, persiste ret->rsrc_id = 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; + ret->stdiocast = NULL; + ret->orig_path = NULL; + ret->context = NULL; + ret->readbuf = NULL; + ret->enclosing_stream = NULL; + return ret; } /* }}} */ +PHPAPI int _php_stream_free_enclosed(php_stream *stream_enclosed, int close_options TSRMLS_DC) /* {{{ */ +{ + return _php_stream_free(stream_enclosed, + close_options | PHP_STREAM_FREE_IGNORE_ENCLOSING TSRMLS_CC); +} +/* }}} */ + +#if STREAM_DEBUG +static const char *_php_stream_pretty_free_options(int close_options, char *out) +{ + if (close_options & PHP_STREAM_FREE_CALL_DTOR) + strcat(out, "CALL_DTOR, "); + if (close_options & PHP_STREAM_FREE_RELEASE_STREAM) + strcat(out, "RELEASE_STREAM, "); + if (close_options & PHP_STREAM_FREE_PRESERVE_HANDLE) + strcat(out, "PREVERSE_HANDLE, "); + if (close_options & PHP_STREAM_FREE_RSRC_DTOR) + strcat(out, "RSRC_DTOR, "); + if (close_options & PHP_STREAM_FREE_PERSISTENT) + strcat(out, "PERSISTENT, "); + if (close_options & PHP_STREAM_FREE_IGNORE_ENCLOSING) + strcat(out, "IGNORE_ENCLOSING, "); + if (out[0] != '\0') + out[strlen(out) - 2] = '\0'; + return out; +} +#endif + static int _php_stream_free_persistent(zend_rsrc_list_entry *le, void *pStream TSRMLS_DC) { return le->ptr == pStream; } + PHPAPI int _php_stream_free(php_stream *stream, int close_options TSRMLS_DC) /* {{{ */ { int ret = 1; - int remove_rsrc = 1; int preserve_handle = close_options & PHP_STREAM_FREE_PRESERVE_HANDLE ? 1 : 0; int release_cast = 1; php_stream_context *context = stream->context; @@ -327,16 +373,40 @@ PHPAPI int _php_stream_free(php_stream *stream, int close_options TSRMLS_DC) /* } #if STREAM_DEBUG -fprintf(stderr, "stream_free: %s:%p[%s] in_free=%d opts=%08x\n", stream->ops->label, stream, stream->orig_path, stream->in_free, close_options); + { + char out[200] = ""; + 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 - /* recursion protection */ if (stream->in_free) { - return 1; + /* hopefully called recursively from the enclosing stream; the pointer was NULLed below */ + if ((stream->in_free == 1) && (close_options & PHP_STREAM_FREE_IGNORE_ENCLOSING) && (stream->enclosing_stream == NULL)) { + close_options |= PHP_STREAM_FREE_RSRC_DTOR; /* restore flag */ + } else { + return 1; /* recursion protection */ + } } stream->in_free++; + /* force correct order on enclosing/enclosed stream destruction (only from resource + * destructor as in when reverse destroying the resource list) */ + if ((close_options & PHP_STREAM_FREE_RSRC_DTOR) && + !(close_options & PHP_STREAM_FREE_IGNORE_ENCLOSING) && + (close_options & (PHP_STREAM_FREE_CALL_DTOR | PHP_STREAM_FREE_RELEASE_STREAM)) && /* always? */ + (stream->enclosing_stream != NULL)) { + php_stream *enclosing_stream = stream->enclosing_stream; + stream->enclosing_stream = NULL; + /* we force PHP_STREAM_CALL_DTOR because that's from where the + * 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); + } + /* if we are releasing the stream only (and preserving the underlying handle), * we need to do things a little differently. * We are only ever called like this when the stream is cast to a FILE* @@ -357,14 +427,15 @@ fprintf(stderr, "stream_free: %s:%p[%s] in_free=%d opts=%08x\n", stream->ops->la #if STREAM_DEBUG fprintf(stderr, "stream_free: %s:%p[%s] preserve_handle=%d release_cast=%d remove_rsrc=%d\n", - stream->ops->label, stream, stream->orig_path, preserve_handle, release_cast, remove_rsrc); + stream->ops->label, stream, stream->orig_path, preserve_handle, release_cast, + (close_options & PHP_STREAM_FREE_RSRC_DTOR) == 0); #endif /* make sure everything is saved */ _php_stream_flush(stream, 1 TSRMLS_CC); /* If not called from the resource dtor, remove the stream from the resource list. */ - if ((close_options & PHP_STREAM_FREE_RSRC_DTOR) == 0 && remove_rsrc) { + if ((close_options & PHP_STREAM_FREE_RSRC_DTOR) == 0) { /* 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. @@ -1346,7 +1417,7 @@ PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen } /* Returns SUCCESS/FAILURE and sets *len to the number of bytes moved */ -PHPAPI size_t _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 TSRMLS_DC) { char buf[CHUNK_SIZE]; size_t readchunk; @@ -1741,7 +1812,7 @@ PHPAPI int _php_stream_mkdir(char *path, int mode, int options, php_stream_conte { php_stream_wrapper *wrapper = NULL; - wrapper = php_stream_locate_url_wrapper(path, NULL, ENFORCE_SAFE_MODE TSRMLS_CC); + wrapper = php_stream_locate_url_wrapper(path, NULL, 0 TSRMLS_CC); if (!wrapper || !wrapper->wops || !wrapper->wops->stream_mkdir) { return 0; } @@ -1756,7 +1827,7 @@ PHPAPI int _php_stream_rmdir(char *path, int options, php_stream_context *contex { php_stream_wrapper *wrapper = NULL; - wrapper = php_stream_locate_url_wrapper(path, NULL, ENFORCE_SAFE_MODE TSRMLS_CC); + wrapper = php_stream_locate_url_wrapper(path, NULL, 0 TSRMLS_CC); if (!wrapper || !wrapper->wops || !wrapper->wops->stream_rmdir) { return 0; } @@ -1785,7 +1856,7 @@ PHPAPI int _php_stream_stat_path(char *path, int flags, php_stream_statbuf *ssb, } } - wrapper = php_stream_locate_url_wrapper(path, &path_to_open, ENFORCE_SAFE_MODE TSRMLS_CC); + wrapper = php_stream_locate_url_wrapper(path, &path_to_open, 0 TSRMLS_CC); if (wrapper && wrapper->wops->url_stat) { ret = wrapper->wops->url_stat(wrapper, path_to_open, flags, ssb, context TSRMLS_CC); if (ret == 0) { @@ -1870,7 +1941,6 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(char *path, char *mode, int optio char *resolved_path = NULL; char *copy_of_path = NULL; - if (opened_path) { *opened_path = NULL; } @@ -2047,7 +2117,7 @@ PHPAPI void php_stream_context_free(php_stream_context *context) efree(context); } -PHPAPI php_stream_context *php_stream_context_alloc(void) +PHPAPI php_stream_context *php_stream_context_alloc(TSRMLS_D) { php_stream_context *context; @@ -2056,7 +2126,7 @@ PHPAPI php_stream_context *php_stream_context_alloc(void) MAKE_STD_ZVAL(context->options); array_init(context->options); - context->rsrc_id = ZEND_REGISTER_RESOURCE(NULL, context, php_le_stream_context()); + context->rsrc_id = ZEND_REGISTER_RESOURCE(NULL, context, php_le_stream_context(TSRMLS_C)); return context; } @@ -2199,7 +2269,7 @@ PHPAPI int _php_stream_scandir(char *dirname, char **namelist[], int flags, php_ return FAILURE; } - stream = php_stream_opendir(dirname, ENFORCE_SAFE_MODE | REPORT_ERRORS, context); + stream = php_stream_opendir(dirname, REPORT_ERRORS, context); if (!stream) { return FAILURE; } diff --git a/main/streams/transports.c b/main/streams/transports.c index 3c75bde80..fe5ce6cfc 100644 --- a/main/streams/transports.c +++ b/main/streams/transports.c @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: transports.c 306939 2011-01-01 02:19:59Z felipe $ */ +/* $Id: transports.c 306938 2011-01-01 02:17:06Z felipe $ */ #include "php.h" #include "php_streams_int.h" diff --git a/main/streams/userspace.c b/main/streams/userspace.c index 98371ea64..6bdc99efc 100644 --- a/main/streams/userspace.c +++ b/main/streams/userspace.c @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: userspace.c 307934 2011-02-01 22:55:17Z cataphract $ */ +/* $Id: userspace.c 311422 2011-05-25 21:03:55Z stas $ */ #include "php.h" #include "php_globals.h" @@ -26,6 +26,15 @@ #ifdef HAVE_SYS_FILE_H #include <sys/file.h> #endif +#include <stddef.h> + +#if HAVE_UTIME +# ifdef PHP_WIN32 +# include <sys/utime.h> +# else +# include <utime.h> +# endif +#endif static int le_protocols; @@ -42,6 +51,7 @@ static int user_wrapper_unlink(php_stream_wrapper *wrapper, char *url, int optio static int user_wrapper_rename(php_stream_wrapper *wrapper, char *url_from, char *url_to, int options, php_stream_context *context TSRMLS_DC); static int user_wrapper_mkdir(php_stream_wrapper *wrapper, char *url, int mode, int options, php_stream_context *context TSRMLS_DC); static int user_wrapper_rmdir(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC); +static int user_wrapper_metadata(php_stream_wrapper *wrapper, char *url, int option, void *value, php_stream_context *context TSRMLS_DC); static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, char *filename, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC); @@ -55,7 +65,8 @@ static php_stream_wrapper_ops user_stream_wops = { user_wrapper_unlink, user_wrapper_rename, user_wrapper_mkdir, - user_wrapper_rmdir + user_wrapper_rmdir, + user_wrapper_metadata }; @@ -77,7 +88,6 @@ PHP_MINIT_FUNCTION(user_streams) REGISTER_LONG_CONSTANT("STREAM_USE_PATH", USE_PATH, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_IGNORE_URL", IGNORE_URL, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_ENFORCE_SAFE_MODE", ENFORCE_SAFE_MODE, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_REPORT_ERRORS", REPORT_ERRORS, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_MUST_SEEK", STREAM_MUST_SEEK, CONST_CS|CONST_PERSISTENT); @@ -99,6 +109,12 @@ PHP_MINIT_FUNCTION(user_streams) REGISTER_LONG_CONSTANT("STREAM_CAST_AS_STREAM", PHP_STREAM_AS_STDIO, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_CAST_FOR_SELECT", PHP_STREAM_AS_FD_FOR_SELECT, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("STREAM_META_TOUCH", PHP_STREAM_META_TOUCH, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("STREAM_META_OWNER", PHP_STREAM_META_OWNER, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("STREAM_META_OWNER_NAME", PHP_STREAM_META_OWNER_NAME, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("STREAM_META_GROUP", PHP_STREAM_META_GROUP, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("STREAM_META_GROUP_NAME", PHP_STREAM_META_GROUP_NAME, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("STREAM_META_ACCESS", PHP_STREAM_META_ACCESS, CONST_CS|CONST_PERSISTENT); return SUCCESS; } @@ -130,35 +146,37 @@ typedef struct _php_userstream_data php_userstream_data_t; #define USERSTREAM_LOCK "stream_lock" #define USERSTREAM_CAST "stream_cast" #define USERSTREAM_SET_OPTION "stream_set_option" +#define USERSTREAM_TRUNCATE "stream_truncate" +#define USERSTREAM_METADATA "stream_metadata" /* {{{ class should have methods like these: - + function stream_open($path, $mode, $options, &$opened_path) { return true/false; } - + function stream_read($count) { return false on error; else return string; } - + function stream_write($data) { return false on error; else return count written; } - + function stream_close() { } - + function stream_flush() { return true/false; } - + function stream_seek($offset, $whence) { return true/false; @@ -255,7 +273,12 @@ typedef struct _php_userstream_data php_userstream_data_t; { return true / false; } - + + function stream_truncate($new_size) + { + return true / false; + } + }}} **/ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, char *filename, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) @@ -263,7 +286,7 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, char *filena 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 **args[4]; int call_result; php_stream *stream = NULL; zend_bool old_in_user_include; @@ -274,32 +297,32 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, char *filena return NULL; } FG(user_stream_current_filename) = filename; - + /* if the user stream was registered as local and we are in include context, we add allow_url_include restrictions to allow_url_fopen ones */ /* we need only is_url == 0 here since if is_url == 1 and remote wrappers were restricted we wouldn't get here */ old_in_user_include = PG(in_user_include); - if(uwrap->wrapper.is_url == 0 && + if(uwrap->wrapper.is_url == 0 && (options & STREAM_OPEN_FOR_INCLUDE) && !PG(allow_url_include)) { PG(in_user_include) = 1; } us = emalloc(sizeof(*us)); - us->wrapper = uwrap; + us->wrapper = uwrap; /* create an instance of our class */ ALLOC_ZVAL(us->object); object_init_ex(us->object, uwrap->ce); Z_SET_REFCOUNT_P(us->object, 1); Z_SET_ISREF_P(us->object); - + if (uwrap->ce->constructor) { zend_fcall_info fci; zend_fcall_info_cache fcc; zval *retval_ptr; - + fci.size = sizeof(fci); fci.function_table = &uwrap->ce->function_table; fci.function_name = NULL; @@ -309,7 +332,7 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, char *filena fci.param_count = 0; fci.params = NULL; fci.no_separation = 1; - + fcc.initialized = 1; fcc.function_handler = uwrap->ce->constructor; fcc.calling_scope = EG(scope); @@ -337,7 +360,7 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, char *filena } else { add_property_null(us->object, "context"); } - + /* call it's stream_open method - set up params first */ MAKE_STD_ZVAL(zfilename); ZVAL_STRING(zfilename, filename, 1); @@ -359,14 +382,14 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, char *filena MAKE_STD_ZVAL(zfuncname); ZVAL_STRING(zfuncname, USERSTREAM_OPEN, 1); - + call_result = call_user_function_ex(NULL, &us->object, zfuncname, &zretval, 4, args, 0, NULL TSRMLS_CC); - + if (call_result == SUCCESS && zretval != NULL && zval_is_true(zretval)) { /* the stream is now open! */ stream = php_stream_alloc_rel(&php_stream_userspace_ops, us, 0, mode); @@ -383,7 +406,7 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, char *filena php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "\"%s::" USERSTREAM_OPEN "\" call failed", us->wrapper->classname); } - + /* destroy everything else */ if (stream == NULL) { zval_ptr_dtor(&us->object); @@ -391,7 +414,7 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, char *filena } if (zretval) zval_ptr_dtor(&zretval); - + zval_ptr_dtor(&zfuncname); zval_ptr_dtor(&zopened); zval_ptr_dtor(&zoptions); @@ -399,7 +422,7 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, char *filena zval_ptr_dtor(&zfilename); FG(user_stream_current_filename) = NULL; - + PG(in_user_include) = old_in_user_include; return stream; } @@ -410,7 +433,7 @@ static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, char *filen 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 **args[2]; int call_result; php_stream *stream = NULL; @@ -420,9 +443,9 @@ static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, char *filen return NULL; } FG(user_stream_current_filename) = filename; - + us = emalloc(sizeof(*us)); - us->wrapper = uwrap; + us->wrapper = uwrap; /* create an instance of our class */ ALLOC_ZVAL(us->object); @@ -436,7 +459,7 @@ static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, char *filen } else { add_property_null(us->object, "context"); } - + /* call it's dir_open method - set up params first */ MAKE_STD_ZVAL(zfilename); ZVAL_STRING(zfilename, filename, 1); @@ -448,14 +471,14 @@ static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, char *filen MAKE_STD_ZVAL(zfuncname); ZVAL_STRING(zfuncname, USERSTREAM_DIR_OPEN, 1); - + call_result = call_user_function_ex(NULL, &us->object, zfuncname, &zretval, 2, args, 0, NULL TSRMLS_CC); - + if (call_result == SUCCESS && zretval != NULL && zval_is_true(zretval)) { /* the stream is now open! */ stream = php_stream_alloc_rel(&php_stream_userspace_dir_ops, us, 0, mode); @@ -467,7 +490,7 @@ static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, char *filen php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "\"%s::" USERSTREAM_DIR_OPEN "\" call failed", us->wrapper->classname); } - + /* destroy everything else */ if (stream == NULL) { zval_ptr_dtor(&us->object); @@ -475,13 +498,13 @@ static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, char *filen } if (zretval) zval_ptr_dtor(&zretval); - + zval_ptr_dtor(&zfuncname); zval_ptr_dtor(&zoptions); zval_ptr_dtor(&zfilename); FG(user_stream_current_filename) = NULL; - + return stream; } @@ -495,11 +518,11 @@ PHP_FUNCTION(stream_wrapper_register) struct php_user_stream_wrapper * uwrap; int rsrc_id; long flags = 0; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &protocol, &protocol_len, &classname, &classname_len, &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); @@ -585,7 +608,7 @@ PHP_FUNCTION(stream_wrapper_restore) 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); RETURN_FALSE; - } + } RETURN_TRUE; } @@ -633,10 +656,10 @@ static size_t php_userstreamop_write(php_stream *stream, const char *buf, size_t (long)(didwrite - count), (long)didwrite, (long)count); didwrite = count; } - + if (retval) zval_ptr_dtor(&retval); - + return didwrite; } @@ -721,9 +744,9 @@ static int php_userstreamop_close(php_stream *stream, int close_handle TSRMLS_DC 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); - + call_user_function_ex(NULL, &us->object, &func_name, @@ -732,11 +755,11 @@ static int php_userstreamop_close(php_stream *stream, int close_handle TSRMLS_DC if (retval) zval_ptr_dtor(&retval); - + zval_ptr_dtor(&us->object); efree(us); - + return 0; } @@ -750,7 +773,7 @@ static int php_userstreamop_flush(php_stream *stream TSRMLS_DC) assert(us != NULL); ZVAL_STRINGL(&func_name, USERSTREAM_FLUSH, sizeof(USERSTREAM_FLUSH)-1, 0); - + call_result = call_user_function_ex(NULL, &us->object, &func_name, @@ -761,10 +784,10 @@ static int php_userstreamop_flush(php_stream *stream TSRMLS_DC) call_result = 0; else call_result = -1; - + if (retval) zval_ptr_dtor(&retval); - + return call_result; } @@ -803,10 +826,10 @@ static int php_userstreamop_seek(php_stream *stream, off_t offset, int whence, o /* 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) + + if (retval) zval_ptr_dtor(&retval); - + return -1; } else if (call_result == SUCCESS && retval != NULL && zval_is_true(retval)) { ret = 0; @@ -889,8 +912,8 @@ static int statbuf_from_array(zval *array, php_stream_statbuf *ssb TSRMLS_DC) STAT_PROP_ENTRY(blocks); #endif -#undef STAT_PROP_ENTRY -#undef STAT_PROP_ENTRY_EX +#undef STAT_PROP_ENTRY +#undef STAT_PROP_ENTRY_EX return SUCCESS; } @@ -920,9 +943,9 @@ static int php_userstreamop_stat(php_stream *stream, php_stream_statbuf *ssb TSR } } - if (retval) + if (retval) zval_ptr_dtor(&retval); - + return ret; } @@ -932,7 +955,7 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value zval *retval = NULL; int call_result; php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; - int ret = -1; + int ret = PHP_STREAM_OPTION_RETURN_NOTIMPL; zval *zvalue = NULL; zval **args[3]; @@ -970,37 +993,83 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value } args[0] = &zvalue; - + /* TODO wouldblock */ ZVAL_STRINGL(&func_name, USERSTREAM_LOCK, sizeof(USERSTREAM_LOCK)-1, 0); - + call_result = call_user_function_ex(NULL, &us->object, &func_name, &retval, 1, args, 0, NULL TSRMLS_CC); - + if (call_result == SUCCESS && retval != NULL && Z_TYPE_P(retval) == IS_BOOL) { ret = !Z_LVAL_P(retval); } else if (call_result == FAILURE) { - if (value == 0) { + if (value == 0) { /* lock support test (TODO: more check) */ - ret = 0; + 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 TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_LOCK " is not implemented!", us->wrapper->classname); + ret = PHP_STREAM_OPTION_RETURN_ERR; } } break; - + + case PHP_STREAM_OPTION_TRUNCATE_API: + ZVAL_STRINGL(&func_name, USERSTREAM_TRUNCATE, sizeof(USERSTREAM_TRUNCATE)-1, 0); + + 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)) + ret = PHP_STREAM_OPTION_RETURN_OK; + else + ret = PHP_STREAM_OPTION_RETURN_ERR; + break; + + 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; + 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; + } else { + php_error_docref(NULL TSRMLS_CC, E_WARNING, + "%s::" USERSTREAM_TRUNCATE " did not return a boolean!", + us->wrapper->classname); + } + } else { + php_error_docref(NULL TSRMLS_CC, E_WARNING, + "%s::" USERSTREAM_TRUNCATE " is not implemented!", + us->wrapper->classname); + } + } else { /* bad new size */ + ret = PHP_STREAM_OPTION_RETURN_ERR; + } + break; + } + } + 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); @@ -1041,17 +1110,16 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value &func_name, &retval, 3, args, 0, NULL TSRMLS_CC); - - do { - if (call_result == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_SET_OPTION " is not implemented!", - us->wrapper->classname); - break; - } - if (retval && zend_is_true(retval)) { - ret = PHP_STREAM_OPTION_RETURN_OK; - } - } while (0); + + if (call_result == FAILURE) { + php_error_docref(NULL TSRMLS_CC, 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)) { + ret = PHP_STREAM_OPTION_RETURN_OK; + } else { + ret = PHP_STREAM_OPTION_RETURN_ERR; + } if (zoption) { zval_ptr_dtor(&zoption); @@ -1068,7 +1136,7 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value if (retval) { zval_ptr_dtor(&retval); } - + if (zvalue) { zval_ptr_dtor(&zvalue); @@ -1107,7 +1175,7 @@ static int user_wrapper_unlink(php_stream_wrapper *wrapper, char *url, int optio MAKE_STD_ZVAL(zfuncname); ZVAL_STRING(zfuncname, USERSTREAM_UNLINK, 1); - + call_result = call_user_function_ex(NULL, &object, zfuncname, @@ -1125,7 +1193,7 @@ static int user_wrapper_unlink(php_stream_wrapper *wrapper, char *url, int optio zval_ptr_dtor(&object); if (zretval) zval_ptr_dtor(&zretval); - + zval_ptr_dtor(&zfuncname); zval_ptr_dtor(&zfilename); @@ -1165,7 +1233,7 @@ static int user_wrapper_rename(php_stream_wrapper *wrapper, char *url_from, char MAKE_STD_ZVAL(zfuncname); ZVAL_STRING(zfuncname, USERSTREAM_RENAME, 1); - + call_result = call_user_function_ex(NULL, &object, zfuncname, @@ -1183,7 +1251,7 @@ static int user_wrapper_rename(php_stream_wrapper *wrapper, char *url_from, char zval_ptr_dtor(&object); if (zretval) zval_ptr_dtor(&zretval); - + zval_ptr_dtor(&zfuncname); zval_ptr_dtor(&zold_name); zval_ptr_dtor(&znew_name); @@ -1228,7 +1296,7 @@ static int user_wrapper_mkdir(php_stream_wrapper *wrapper, char *url, int mode, MAKE_STD_ZVAL(zfuncname); ZVAL_STRING(zfuncname, USERSTREAM_MKDIR, 1); - + call_result = call_user_function_ex(NULL, &object, zfuncname, @@ -1247,7 +1315,7 @@ static int user_wrapper_mkdir(php_stream_wrapper *wrapper, char *url, int mode, if (zretval) { zval_ptr_dtor(&zretval); } - + zval_ptr_dtor(&zfuncname); zval_ptr_dtor(&zfilename); zval_ptr_dtor(&zmode); @@ -1289,7 +1357,7 @@ static int user_wrapper_rmdir(php_stream_wrapper *wrapper, char *url, int option MAKE_STD_ZVAL(zfuncname); ZVAL_STRING(zfuncname, USERSTREAM_RMDIR, 1); - + call_result = call_user_function_ex(NULL, &object, zfuncname, @@ -1308,7 +1376,7 @@ static int user_wrapper_rmdir(php_stream_wrapper *wrapper, char *url, int option if (zretval) { zval_ptr_dtor(&zretval); } - + zval_ptr_dtor(&zfuncname); zval_ptr_dtor(&zfilename); zval_ptr_dtor(&zoptions); @@ -1316,11 +1384,100 @@ static int user_wrapper_rmdir(php_stream_wrapper *wrapper, char *url, int option return ret; } +static int user_wrapper_metadata(php_stream_wrapper *wrapper, char *url, int option, void *value, php_stream_context *context TSRMLS_DC) +{ + struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; + zval *zfilename, *zoption, *zvalue, *zfuncname, *zretval; + zval **args[3]; + int call_result; + zval *object; + int ret = 0; + + MAKE_STD_ZVAL(zvalue); + switch(option) { + case PHP_STREAM_META_TOUCH: + array_init(zvalue); + if(value) { + struct utimbuf *newtime = (struct utimbuf *)value; + add_index_long(zvalue, 0, newtime->modtime); + add_index_long(zvalue, 1, newtime->actime); + } + break; + case PHP_STREAM_META_GROUP: + case PHP_STREAM_META_OWNER: + case PHP_STREAM_META_ACCESS: + ZVAL_LONG(zvalue, *(long *)value); + break; + case PHP_STREAM_META_GROUP_NAME: + case PHP_STREAM_META_OWNER_NAME: + ZVAL_STRING(zvalue, value, 1); + break; + default: + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown option %d for " USERSTREAM_METADATA, option); + zval_ptr_dtor(&zvalue); + return ret; + } + + /* 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); + } else { + add_property_null(object, "context"); + } + + /* 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; + + args[2] = &zvalue; + + MAKE_STD_ZVAL(zfuncname); + ZVAL_STRING(zfuncname, USERSTREAM_METADATA, 1); + + call_result = call_user_function_ex(NULL, + &object, + zfuncname, + &zretval, + 3, args, + 0, NULL TSRMLS_CC); + + if (call_result == SUCCESS && zretval && Z_TYPE_P(zretval) == IS_BOOL) { + ret = Z_LVAL_P(zretval); + } else if (call_result == FAILURE) { + php_error_docref(NULL TSRMLS_CC, 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(&zfuncname); + zval_ptr_dtor(&zfilename); + zval_ptr_dtor(&zoption); + zval_ptr_dtor(&zvalue); + + return ret; +} + + static int user_wrapper_stat_url(php_stream_wrapper *wrapper, char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC) { struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; zval *zfilename, *zfuncname, *zretval, *zflags; - zval **args[2]; + zval **args[2]; int call_result; zval *object; int ret = -1; @@ -1349,14 +1506,14 @@ static int user_wrapper_stat_url(php_stream_wrapper *wrapper, char *url, int fla MAKE_STD_ZVAL(zfuncname); ZVAL_STRING(zfuncname, USERSTREAM_STATURL, 1); - + call_result = call_user_function_ex(NULL, &object, zfuncname, &zretval, 2, args, 0, NULL TSRMLS_CC); - + if (call_result == SUCCESS && zretval != NULL && Z_TYPE_P(zretval) == IS_ARRAY) { /* We got the info we needed */ if (SUCCESS == statbuf_from_array(zretval, ssb TSRMLS_CC)) @@ -1367,16 +1524,16 @@ static int user_wrapper_stat_url(php_stream_wrapper *wrapper, char *url, int fla uwrap->classname); } } - + /* clean up */ zval_ptr_dtor(&object); if (zretval) zval_ptr_dtor(&zretval); - + zval_ptr_dtor(&zfuncname); zval_ptr_dtor(&zfilename); zval_ptr_dtor(&zflags); - + return ret; } @@ -1426,9 +1583,9 @@ static int php_userstreamop_closedir(php_stream *stream, int close_handle TSRMLS 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); - + call_user_function_ex(NULL, &us->object, &func_name, @@ -1437,11 +1594,11 @@ static int php_userstreamop_closedir(php_stream *stream, int close_handle TSRMLS if (retval) zval_ptr_dtor(&retval); - + zval_ptr_dtor(&us->object); efree(us); - + return 0; } @@ -1452,7 +1609,7 @@ static int php_userstreamop_rewinddir(php_stream *stream, off_t offset, int when php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; ZVAL_STRINGL(&func_name, USERSTREAM_DIR_REWIND, sizeof(USERSTREAM_DIR_REWIND)-1, 0); - + call_user_function_ex(NULL, &us->object, &func_name, @@ -1461,7 +1618,7 @@ static int php_userstreamop_rewinddir(php_stream *stream, off_t offset, int when if (retval) zval_ptr_dtor(&retval); - + return 0; } @@ -1536,7 +1693,7 @@ php_stream_ops php_stream_userspace_ops = { "user-space", php_userstreamop_seek, php_userstreamop_cast, - php_userstreamop_stat, + php_userstreamop_stat, php_userstreamop_set_option, }; diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c index 9d0859d5a..05c29d226 100644 --- a/main/streams/xp_socket.c +++ b/main/streams/xp_socket.c @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: xp_socket.c 306939 2011-01-01 02:19:59Z felipe $ */ +/* $Id: xp_socket.c 308477 2011-02-19 01:28:37Z cataphract $ */ #include "php.h" #include "ext/standard/file.h" @@ -400,10 +400,6 @@ static int php_sockop_set_option(php_stream *stream, int option, int value, void } #endif - case PHP_STREAM_OPTION_WRITE_BUFFER: - php_stream_set_chunk_size(stream, (ptrparam ? *(size_t *)ptrparam : PHP_SOCK_CHUNK_SIZE)); - return PHP_STREAM_OPTION_RETURN_OK; - default: return PHP_STREAM_OPTION_RETURN_NOTIMPL; } |