From: Wez Furlong Date: Sun, 24 Mar 2002 18:05:49 +0000 (+0000) Subject: Phase 1 of wrapper OO cleanup. X-Git-Tag: php-4.3.0dev-ZendEngine2-Preview1~1058 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5ee65bd8f5e6b3b205bc3eb08e019f2a15c07a35;p=php Phase 1 of wrapper OO cleanup. # Collecting underpants --- diff --git a/ext/standard/ftp_fopen_wrapper.c b/ext/standard/ftp_fopen_wrapper.c index 6ef61b9e7b..70bf9e68ae 100644 --- a/ext/standard/ftp_fopen_wrapper.c +++ b/ext/standard/ftp_fopen_wrapper.c @@ -77,16 +77,20 @@ static int php_get_ftp_result(php_stream *stream TSRMLS_DC) return strtol(tmp_line, NULL, 10); } -php_stream_wrapper php_stream_ftp_wrapper = { +static php_stream_wrapper_ops ftp_stream_wops = { php_stream_url_wrap_ftp, - NULL, + NULL +}; + +php_stream_wrapper php_stream_ftp_wrapper = { + &ftp_stream_wops, NULL }; /* {{{ php_fopen_url_wrap_ftp */ -php_stream * php_stream_url_wrap_ftp(char *path, char *mode, int options, char **opened_path, void *wrappercontext STREAMS_DC TSRMLS_DC) +php_stream * php_stream_url_wrap_ftp(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path STREAMS_DC TSRMLS_DC) { php_stream *stream=NULL; php_url *resource=NULL; diff --git a/ext/standard/http_fopen_wrapper.c b/ext/standard/http_fopen_wrapper.c index 06508b4c5a..2f566bd1b3 100644 --- a/ext/standard/http_fopen_wrapper.c +++ b/ext/standard/http_fopen_wrapper.c @@ -71,7 +71,7 @@ #define HTTP_HEADER_BLOCK_SIZE 1024 -php_stream *php_stream_url_wrap_http(char *path, char *mode, int options, char **opened_path, void *wrappercontext STREAMS_DC TSRMLS_DC) +php_stream *php_stream_url_wrap_http(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path STREAMS_DC TSRMLS_DC) { php_stream *stream = NULL; php_url *resource = NULL; @@ -268,7 +268,7 @@ php_stream *php_stream_url_wrap_http(char *path, char *mode, int options, char * else { strlcpy(new_path, location, sizeof(new_path)); } - stream = php_stream_url_wrap_http(new_path, mode, options, opened_path, NULL STREAMS_CC TSRMLS_CC); + stream = php_stream_url_wrap_http(NULL, new_path, mode, options, opened_path STREAMS_CC TSRMLS_CC); if (stream->wrapperdata) { entryp = &entry; MAKE_STD_ZVAL(entry); @@ -309,12 +309,15 @@ out: return stream; } -php_stream_wrapper php_stream_http_wrapper = { +static php_stream_wrapper_ops http_stream_wops = { php_stream_url_wrap_http, - NULL, NULL }; +php_stream_wrapper php_stream_http_wrapper = { + &http_stream_wops, + NULL +}; /* * Local variables: diff --git a/ext/standard/php_fopen_wrapper.c b/ext/standard/php_fopen_wrapper.c index 19aa15a2e4..842df5fcee 100644 --- a/ext/standard/php_fopen_wrapper.c +++ b/ext/standard/php_fopen_wrapper.c @@ -30,7 +30,7 @@ #include "php_standard.h" #include "php_fopen_wrappers.h" -php_stream * php_stream_url_wrap_php(char * path, char * mode, int options, char ** opened_path, void *wrappercontext STREAMS_DC TSRMLS_DC) +php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path STREAMS_DC TSRMLS_DC) { FILE * fp = NULL; php_stream * stream = NULL; @@ -55,9 +55,13 @@ php_stream * php_stream_url_wrap_php(char * path, char * mode, int options, char return stream; } -php_stream_wrapper php_stream_php_wrapper = { +static php_stream_wrapper_ops php_stdio_wops = { php_stream_url_wrap_php, - NULL, + NULL +}; + +php_stream_wrapper php_stream_php_wrapper = { + &php_stdio_wops, NULL }; diff --git a/ext/standard/php_fopen_wrappers.h b/ext/standard/php_fopen_wrappers.h index 5178d74ce1..7c82937d05 100644 --- a/ext/standard/php_fopen_wrappers.h +++ b/ext/standard/php_fopen_wrappers.h @@ -23,8 +23,8 @@ #ifndef PHP_FOPEN_WRAPPERS_H #define PHP_FOPEN_WRAPPERS_H -php_stream *php_stream_url_wrap_http(char *path, char *mode, int options, char **opened_path, void *wrappercontext STREAMS_DC TSRMLS_DC); -php_stream *php_stream_url_wrap_ftp(char *path, char *mode, int options, char **opened_path, void *wrappercontext STREAMS_DC TSRMLS_DC); +php_stream *php_stream_url_wrap_http(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path STREAMS_DC TSRMLS_DC); +php_stream *php_stream_url_wrap_ftp(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path STREAMS_DC TSRMLS_DC); php_stream_wrapper php_stream_http_wrapper; php_stream_wrapper php_stream_ftp_wrapper; php_stream_wrapper php_stream_php_wrapper; diff --git a/ext/zlib/php_zlib.h b/ext/zlib/php_zlib.h index 8907838f55..803727c7da 100644 --- a/ext/zlib/php_zlib.h +++ b/ext/zlib/php_zlib.h @@ -53,7 +53,7 @@ PHP_FUNCTION(ob_gzhandler); int php_enable_output_compression(int buffer_size TSRMLS_DC); -php_stream *php_stream_gzopen(char *path, char *mode, int options, char **opened_path, void *wrappercontext STREAMS_DC TSRMLS_DC); +php_stream *php_stream_gzopen(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path STREAMS_DC TSRMLS_DC); extern php_stream_ops php_stream_gzio_ops; extern php_stream_wrapper php_stream_gzip_wrapper; diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index 823603a2db..24565602ea 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -273,7 +273,7 @@ PHP_FUNCTION(gzfile) convert_to_string_ex(filename); /* using a stream here is a bit more efficient (resource wise) than php_gzopen_wrapper */ - stream = php_stream_gzopen(Z_STRVAL_PP(filename), "rb", use_include_path|ENFORCE_SAFE_MODE|REPORT_ERRORS, NULL, NULL STREAMS_CC TSRMLS_CC); + stream = php_stream_gzopen(NULL, Z_STRVAL_PP(filename), "rb", use_include_path|ENFORCE_SAFE_MODE|REPORT_ERRORS, NULL STREAMS_CC TSRMLS_CC); if (stream == NULL) { php_error(E_WARNING,"gzFile(\"%s\") - %s",Z_STRVAL_PP(filename),strerror(errno)); RETURN_FALSE; @@ -329,7 +329,7 @@ PHP_FUNCTION(gzopen) convert_to_string_ex(arg2); p = estrndup(Z_STRVAL_PP(arg2),Z_STRLEN_PP(arg2)); - stream = php_stream_gzopen(Z_STRVAL_PP(arg1), p, use_include_path|ENFORCE_SAFE_MODE, NULL, NULL STREAMS_CC TSRMLS_CC); + stream = php_stream_gzopen(NULL, Z_STRVAL_PP(arg1), p, use_include_path|ENFORCE_SAFE_MODE, NULL STREAMS_CC TSRMLS_CC); if (!stream) { RETURN_FALSE; } @@ -370,7 +370,7 @@ PHP_FUNCTION(readgzfile) } convert_to_string_ex(arg1); - stream = php_stream_gzopen(Z_STRVAL_PP(arg1), "rb", use_include_path|ENFORCE_SAFE_MODE, NULL, NULL STREAMS_CC TSRMLS_CC); + stream = php_stream_gzopen(NULL, Z_STRVAL_PP(arg1), "rb", use_include_path|ENFORCE_SAFE_MODE, NULL STREAMS_CC TSRMLS_CC); if (!stream) { RETURN_FALSE; } diff --git a/ext/zlib/zlib_fopen_wrapper.c b/ext/zlib/zlib_fopen_wrapper.c index 434719dae5..c6e60e3638 100644 --- a/ext/zlib/zlib_fopen_wrapper.c +++ b/ext/zlib/zlib_fopen_wrapper.c @@ -92,7 +92,7 @@ php_stream_ops php_stream_gzio_ops = { NULL, "ZLIB" }; -php_stream *php_stream_gzopen(char *path, char *mode, int options, char **opened_path, void *wrappercontext STREAMS_DC TSRMLS_DC) +php_stream *php_stream_gzopen(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path STREAMS_DC TSRMLS_DC) { struct php_gz_stream_data_t *self; php_stream *stream = NULL; @@ -126,9 +126,13 @@ php_stream *php_stream_gzopen(char *path, char *mode, int options, char **opened return NULL; } -php_stream_wrapper php_stream_gzip_wrapper = { +static php_stream_wrapper_ops gzip_stream_wops = { php_stream_gzopen, - NULL, + NULL +}; + +php_stream_wrapper php_stream_gzip_wrapper = { + &gzip_stream_wops, NULL }; 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) {