]> granicus.if.org Git - php/commitdiff
Phase 1 of wrapper OO cleanup.
authorWez Furlong <wez@php.net>
Sun, 24 Mar 2002 18:05:49 +0000 (18:05 +0000)
committerWez Furlong <wez@php.net>
Sun, 24 Mar 2002 18:05:49 +0000 (18:05 +0000)
# Collecting underpants

ext/standard/ftp_fopen_wrapper.c
ext/standard/http_fopen_wrapper.c
ext/standard/php_fopen_wrapper.c
ext/standard/php_fopen_wrappers.h
ext/zlib/php_zlib.h
ext/zlib/zlib.c
ext/zlib/zlib_fopen_wrapper.c
main/php_streams.h
main/streams.c
main/user_streams.c

index 6ef61b9e7bb46c4d7954c79f09aa0618a26f23a4..70bf9e68ae6f3b8c0fde4d6c1a6e5c2378eb2b5e 100644 (file)
@@ -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;
index 06508b4c5ac0ae6cced5042ff17f8b0be3527a6c..2f566bd1b3b5ee7b95a145117cd035517c106ea4 100644 (file)
@@ -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:
index 19aa15a2e41f1189da571227199e1a129b077708..842df5fceeec35b055091cdd1d21d30b6891b9f6 100644 (file)
@@ -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
 };
 
index 5178d74ce15ce2d77ff15909017c853c32f3a4d7..7c82937d05fb4140c6e25209ef0c552c229aa0f0 100644 (file)
@@ -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;
index 8907838f55e1206aade9a7ac8d1d894cb492be49..803727c7da7e50a9b88ecdcaad0a45687a49dab1 100644 (file)
@@ -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;
 
index 823603a2dbf3f3a7ee837045a40fd857a37aa4ed..24565602ea439281a85040bbb8c95111a8d837d1 100644 (file)
@@ -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;
        }
index 434719dae5a18f4115bda59d5162f556dbbcfd28..c6e60e363880873b41944ad137799e180636cbe7 100644 (file)
@@ -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
 };
 
index 33fd4ee6250e41f73c7524621af0634bb193eaca..c8e05fd091dfb74e4774ba23f7373379a37cfe1e 100755 (executable)
@@ -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;
index a52d523ad5d1e6db5e599ba81bf1b7910697d394..8f366af0d5d8795f87a86b2bbae7cc4d703ef283 100755 (executable)
@@ -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;
index ab90e1cd3b7b600d468504519a17482e75f5150a..53bb3863ccc36edea7d3b942b3d514d9eb3d4f02 100644 (file)
@@ -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) {