diff options
Diffstat (limited to 'main')
| -rwxr-xr-x | main/php_streams.h | 18 | ||||
| -rwxr-xr-x | main/streams.c | 6 | ||||
| -rw-r--r-- | main/user_streams.c | 18 |
3 files changed, 25 insertions, 17 deletions
diff --git a/main/php_streams.h b/main/php_streams.h index 33fd4ee625..c8e05fd091 100755 --- a/main/php_streams.h +++ b/main/php_streams.h @@ -86,6 +86,7 @@ * retrieve using fgetwrapperdata(). */ typedef struct _php_stream php_stream; +typedef struct _php_stream_wrapper php_stream_wrapper; typedef struct _php_stream_ops { /* stdio like functions - these are mandatory! */ @@ -100,15 +101,16 @@ typedef struct _php_stream_ops { const char *label; /* label for this ops structure */ } php_stream_ops; -/* options uses the IGNORE_URL family of defines from fopen_wrappers.h */ -typedef php_stream *(*php_stream_factory_func_t)(char *filename, char *mode, int options, char **opened_path, void * wrappercontext STREAMS_DC TSRMLS_DC); -typedef void (*php_stream_wrapper_dtor_func_t)(php_stream *stream TSRMLS_DC); +typedef struct _php_stream_wrapper_ops { + php_stream *(*opener)(php_stream_wrapper *wrapper, char *filename, char *mode, + int options, char **opened_path STREAMS_DC TSRMLS_DC); + php_stream *(*closer)(php_stream_wrapper *wrapper, php_stream *stream TSRMLS_DC); +} php_stream_wrapper_ops; -typedef struct _php_stream_wrapper { - php_stream_factory_func_t create; - php_stream_wrapper_dtor_func_t destroy; - void * wrappercontext; -} php_stream_wrapper; +struct _php_stream_wrapper { + php_stream_wrapper_ops *wops; /* operations the wrapper can perform */ + void *abstract; /* context for the wrapper */ +}; struct _php_stream { php_stream_ops *ops; diff --git a/main/streams.c b/main/streams.c index a52d523ad5..8f366af0d5 100755 --- a/main/streams.c +++ b/main/streams.c @@ -126,8 +126,8 @@ PHPAPI int _php_stream_free(php_stream *stream, int close_options TSRMLS_DC) /* if (close_options & PHP_STREAM_FREE_RELEASE_STREAM) { - if (stream->wrapper && stream->wrapper->destroy) { - stream->wrapper->destroy(stream TSRMLS_CC); + if (stream->wrapper && stream->wrapper->wops->closer) { + stream->wrapper->wops->closer(stream->wrapper, stream TSRMLS_CC); stream->wrapper = NULL; } @@ -1038,7 +1038,7 @@ static php_stream *php_stream_open_url(char *path, char *mode, int options, char protocol = NULL; } if (wrapper) { - php_stream *stream = wrapper->create(path, mode, options, opened_path, wrapper->wrappercontext STREAMS_REL_CC TSRMLS_CC); + php_stream *stream = wrapper->wops->opener(wrapper, path, mode, options, opened_path STREAMS_REL_CC TSRMLS_CC); if (stream) stream->wrapper = wrapper; return stream; diff --git a/main/user_streams.c b/main/user_streams.c index ab90e1cd3b..53bb3863cc 100644 --- a/main/user_streams.c +++ b/main/user_streams.c @@ -29,7 +29,13 @@ struct php_user_stream_wrapper { php_stream_wrapper wrapper; }; -static php_stream *user_wrapper_factory(char *filename, char *mode, int options, char **opened_path, void * wrappercontext STREAMS_DC TSRMLS_DC); +static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, char *filename, char *mode, int options, char **opened_path STREAMS_DC TSRMLS_DC); + +static php_stream_wrapper_ops user_stream_wops = { + user_wrapper_opener, + NULL +}; + static void stream_wrapper_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) { @@ -107,9 +113,9 @@ function stream_open($path, $mode, $options, &$opened_path) * */ -static php_stream *user_wrapper_factory(char *filename, char *mode, int options, char **opened_path, void *wrappercontext STREAMS_DC TSRMLS_DC) +static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, char *filename, char *mode, int options, char **opened_path STREAMS_DC TSRMLS_DC) { - struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrappercontext; + 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]; @@ -206,14 +212,14 @@ PHP_FUNCTION(file_register_wrapper) uwrap = (struct php_user_stream_wrapper *)ecalloc(1, sizeof(*uwrap)); uwrap->protoname = estrndup(protocol, protocol_len); uwrap->classname = estrndup(classname, classname_len); - uwrap->wrapper.create = user_wrapper_factory; - uwrap->wrapper.wrappercontext = uwrap; + uwrap->wrapper.wops = &user_stream_wops; + uwrap->wrapper.abstract = uwrap; zend_str_tolower(uwrap->classname, classname_len); rsrc_id = ZEND_REGISTER_RESOURCE(NULL, uwrap, le_protocols); if (zend_hash_find(EG(class_table), uwrap->classname, classname_len + 1, (void**)&uwrap->ce) == SUCCESS) { -#ifdef ZEND_ENGINE_2 +#if ZEND_ENGINE_2 uwrap->ce = *(zend_class_entry**)uwrap->ce; #endif if (php_register_url_stream_wrapper(protocol, &uwrap->wrapper TSRMLS_CC) == SUCCESS) { |
