cvs: php-src /ext/standard basic_functions.c file.h user_filters.c /main php_streams.h /main/streams filter.c php_stream_filter_api.h streams.c

From: Date: Mon, 21 Jun 2004 21:08:05 +0000
Subject: cvs: php-src /ext/standard basic_functions.c file.h user_filters.c /main php_streams.h /main/streams filter.c php_stream_filter_api.h streams.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-27665@lists.php.net to get a copy of this message
pollita Mon Jun 21 17:08:05 2004 EDT Modified files: /php-src/ext/standard basic_functions.c file.h user_filters.c /php-src/main php_streams.h /php-src/main/streams filter.c php_stream_filter_api.h streams.c Log: BugFix#28868 (Part Two): This fixes thread unsafety in the userspace filters which relates to the fix just applied for userspace wrappers.

http://cvs.php.net/diff.php/php-src/ext/standard/basic_functions.c?r1=1.671&r2=1.672&ty=u Index: php-src/ext/standard/basic_functions.c diff -u php-src/ext/standard/basic_functions.c:1.671 php-src/ext/standard/basic_functions.c:1.672 --- php-src/ext/standard/basic_functions.c:1.671 Mon Jun 21 14:58:54 2004 +++ php-src/ext/standard/basic_functions.c Mon Jun 21 17:08:05 2004 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: basic_functions.c,v 1.671 2004/06/21 18:58:54 pollita Exp $ */ +/* $Id: basic_functions.c,v 1.672 2004/06/21 21:08:05 pollita Exp $ */ #include "php.h" #include "php_streams.h" @@ -1163,6 +1163,9 @@ /* Default to global wrappers only */ FG(stream_wrappers) = NULL; + /* Default to global filters only */ + FG(stream_filters) = NULL; + return SUCCESS; } @@ -1186,6 +1189,18 @@ } STR_FREE(BG(locale_string)); + if (FG(stream_wrappers)) { + zend_hash_destroy(FG(stream_wrappers)); + efree(FG(stream_wrappers)); + FG(stream_wrappers) = NULL; + } + + if (FG(stream_filters)) { + zend_hash_destroy(FG(stream_filters)); + efree(FG(stream_filters)); + FG(stream_filters) = NULL; + } + PHP_RSHUTDOWN(filestat)(SHUTDOWN_FUNC_ARGS_PASSTHRU); #ifdef HAVE_SYSLOG_H PHP_RSHUTDOWN(syslog)(SHUTDOWN_FUNC_ARGS_PASSTHRU); @@ -1198,12 +1213,6 @@ zend_llist_destroy(BG(user_tick_functions)); efree(BG(user_tick_functions)); BG(user_tick_functions) = NULL; - } - - if (FG(stream_wrappers)) { - zend_hash_destroy(FG(stream_wrappers)); - efree(FG(stream_wrappers)); - FG(stream_wrappers) = NULL; } PHP_RSHUTDOWN(user_filters)(SHUTDOWN_FUNC_ARGS_PASSTHRU); http://cvs.php.net/diff.php/php-src/ext/standard/file.h?r1=1.89&r2=1.90&ty=u Index: php-src/ext/standard/file.h diff -u php-src/ext/standard/file.h:1.89 php-src/ext/standard/file.h:1.90 --- php-src/ext/standard/file.h:1.89 Mon Jun 21 14:58:54 2004 +++ php-src/ext/standard/file.h Mon Jun 21 17:08:05 2004 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: file.h,v 1.89 2004/06/21 18:58:54 pollita Exp $ */ +/* $Id: file.h,v 1.90 2004/06/21 21:08:05 pollita Exp $ */ /* Synced with php 3.0 revision 1.30 1999-06-16 [ssb] */ @@ -114,6 +114,7 @@ char *user_stream_current_filename; /* for simple recursion protection */ php_stream_context *default_context; HashTable *stream_wrappers; /* per-request copy of url_stream_wrappers_hash */ + HashTable *stream_filters; /* per-request copy of stream_filters_hash */ } php_file_globals; #ifdef ZTS http://cvs.php.net/diff.php/php-src/ext/standard/user_filters.c?r1=1.27&r2=1.28&ty=u Index: php-src/ext/standard/user_filters.c diff -u php-src/ext/standard/user_filters.c:1.27 php-src/ext/standard/user_filters.c:1.28 --- php-src/ext/standard/user_filters.c:1.27 Thu May 6 10:29:32 2004 +++ php-src/ext/standard/user_filters.c Mon Jun 21 17:08:05 2004 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: user_filters.c,v 1.27 2004/05/06 14:29:32 pollita Exp $ */ +/* $Id: user_filters.c,v 1.28 2004/06/21 21:08:05 pollita Exp $ */ #include "php.h" #include "php_globals.h" @@ -528,7 +528,7 @@ if (zend_hash_add(BG(user_filter_map), filtername, filtername_len, (void*)fdat, sizeof(*fdat) + classname_len, NULL) == SUCCESS && - php_stream_filter_register_factory(filtername, &user_filter_factory TSRMLS_CC) == SUCCESS) { + php_stream_filter_register_factory_volatile(filtername, &user_filter_factory TSRMLS_CC) == SUCCESS) { RETVAL_TRUE; } http://cvs.php.net/diff.php/php-src/main/php_streams.h?r1=1.94&r2=1.95&ty=u Index: php-src/main/php_streams.h diff -u php-src/main/php_streams.h:1.94 php-src/main/php_streams.h:1.95 --- php-src/main/php_streams.h:1.94 Mon Jun 21 14:58:55 2004 +++ php-src/main/php_streams.h Mon Jun 21 17:08:05 2004 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_streams.h,v 1.94 2004/06/21 18:58:55 pollita Exp $ */ +/* $Id: php_streams.h,v 1.95 2004/06/21 21:08:05 pollita Exp $ */ #ifndef PHP_STREAMS_H #define PHP_STREAMS_H @@ -541,7 +541,9 @@ /* Give other modules access to the url_stream_wrappers_hash and stream_filters_hash */ PHPAPI HashTable *_php_stream_get_url_stream_wrappers_hash(TSRMLS_D); #define php_stream_get_url_stream_wrappers_hash() _php_stream_get_url_stream_wrappers_hash(TSRMLS_C) -PHPAPI HashTable *php_get_stream_filters_hash(); +PHPAPI HashTable *_php_get_stream_filters_hash(TSRMLS_D); +#define php_get_stream_filters_hash() _php_get_stream_filters_hash(TSRMLS_C) +PHPAPI HashTable *php_get_stream_filters_hash_global(); END_EXTERN_C() #endif http://cvs.php.net/diff.php/php-src/main/streams/filter.c?r1=1.12&r2=1.13&ty=u Index: php-src/main/streams/filter.c diff -u php-src/main/streams/filter.c:1.12 php-src/main/streams/filter.c:1.13 --- php-src/main/streams/filter.c:1.12 Wed May 26 17:19:21 2004 +++ php-src/main/streams/filter.c Mon Jun 21 17:08:05 2004 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: filter.c,v 1.12 2004/05/26 21:19:21 wez Exp $ */ +/* $Id: filter.c,v 1.13 2004/06/21 21:08:05 pollita Exp $ */ #include "php.h" #include "php_globals.h" @@ -28,13 +28,22 @@ #include "php_streams_int.h" +/* Global filter hash, copied to FG(stream_filters) on registration of volatile filter */ static HashTable stream_filters_hash; -PHPAPI HashTable *php_get_stream_filters_hash() +/* Should only be used during core initialization */ +PHPAPI HashTable *php_get_stream_filters_hash_global() { return &stream_filters_hash; } +/* Normal hash selection/retrieval call */ +PHPAPI HashTable *_php_get_stream_filters_hash(TSRMLS_D) +{ + 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) { return zend_hash_add(&stream_filters_hash, (char*)filterpattern, strlen(filterpattern), factory, sizeof(*factory), NULL); @@ -45,6 +54,20 @@ return zend_hash_del(&stream_filters_hash, (char*)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) +{ + if (!FG(stream_filters)) { + php_stream_filter_factory tmpfactory; + + FG(stream_filters) = emalloc(sizeof(HashTable)); + zend_hash_init(FG(stream_filters), 0, NULL, NULL, 1); + zend_hash_copy(FG(stream_filters), &stream_filters_hash, NULL, &tmpfactory, sizeof(php_stream_filter_factory)); + } + + return zend_hash_add(FG(stream_filters), (char*)filterpattern, strlen(filterpattern), factory, sizeof(*factory), NULL); +} + /* 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) @@ -223,6 +246,7 @@ * 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) { + HashTable *filter_hash = (FG(stream_filters) ? FG(stream_filters) : &stream_filters_hash); php_stream_filter_factory *factory; php_stream_filter *filter = NULL; int n; @@ -230,7 +254,7 @@ n = strlen(filtername); - if (SUCCESS == zend_hash_find(&stream_filters_hash, (char*)filtername, n, (void**)&factory)) { + if (SUCCESS == zend_hash_find(filter_hash, (char*)filtername, n, (void**)&factory)) { filter = factory->create_filter(filtername, filterparams, persistent TSRMLS_CC); } else if ((period = strrchr(filtername, '.'))) { /* try a wildcard */ @@ -241,7 +265,7 @@ while (period && !filter) { *period = '\0'; strcat(wildname, ".*"); - if (SUCCESS == zend_hash_find(&stream_filters_hash, wildname, strlen(wildname), (void**)&factory)) { + if (SUCCESS == zend_hash_find(filter_hash, wildname, strlen(wildname), (void**)&factory)) { filter = factory->create_filter(filtername, filterparams, persistent TSRMLS_CC); } http://cvs.php.net/diff.php/php-src/main/streams/php_stream_filter_api.h?r1=1.9&r2=1.10&ty=u Index: php-src/main/streams/php_stream_filter_api.h diff -u php-src/main/streams/php_stream_filter_api.h:1.9 php-src/main/streams/php_stream_filter_api.h:1.10 --- php-src/main/streams/php_stream_filter_api.h:1.9 Wed May 26 17:19:21 2004 +++ php-src/main/streams/php_stream_filter_api.h Mon Jun 21 17:08:05 2004 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_stream_filter_api.h,v 1.9 2004/05/26 21:19:21 wez Exp $ */ +/* $Id: php_stream_filter_api.h,v 1.10 2004/06/21 21:08:05 pollita Exp $ */ /* The filter API works on the principle of "Bucket-Brigades". This is * partially inspired by the Apache 2 method of doing things, although @@ -141,6 +141,7 @@ 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); END_EXTERN_C() http://cvs.php.net/diff.php/php-src/main/streams/streams.c?r1=1.56&r2=1.57&ty=u Index: php-src/main/streams/streams.c diff -u php-src/main/streams/streams.c:1.56 php-src/main/streams/streams.c:1.57 --- php-src/main/streams/streams.c:1.56 Mon Jun 21 14:58:55 2004 +++ php-src/main/streams/streams.c Mon Jun 21 17:08:05 2004 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: streams.c,v 1.56 2004/06/21 18:58:55 pollita Exp $ */ +/* $Id: streams.c,v 1.57 2004/06/21 21:08:05 pollita Exp $ */ #define _GNU_SOURCE #include "php.h" @@ -1351,7 +1351,7 @@ return ( zend_hash_init(&url_stream_wrappers_hash, 0, NULL, NULL, 1) == SUCCESS && - zend_hash_init(php_get_stream_filters_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 &&
« previous php.cvs (#27665) next »