pollita Fri Sep 10 16:45:36 2004 EDT Modified files: /php-src NEWS /php-src/ext/standard basic_functions.c streamsfuncs.h /php-src/main php_streams.h /php-src/main/streams streams.c userspace.c Log: Add stream_wrapper_unregister() Disables a wrapper (user-defined or built-in) for the life of the request. Add stream_wrapper_restore() Restores the wrapper originally defined at the time the request started to the protocol name mentioned.
http://cvs.php.net/diff.php/php-src/NEWS?r1=1.1807&r2=1.1808&ty=u Index: php-src/NEWS diff -u php-src/NEWS:1.1807 php-src/NEWS:1.1808 --- php-src/NEWS:1.1807 Tue Sep 7 15:27:11 2004 +++ php-src/NEWS Fri Sep 10 16:45:26 2004 @@ -14,6 +14,8 @@ . array_intersect_ukey() (Christiano Duarte) . stream_context_get_default() (Wez) . stream_socket_enable_crypto() (Wez) + . stream_wrapper_unregister() (Sara) + . stream_wrapper_restore() (Sara) . DomDocumentFragment->appendXML() (Christian) . SimpleXMLElement->registerXPathNamespace() (Christian) . mysqli->client_info property (Georg) http://cvs.php.net/diff.php/php-src/ext/standard/basic_functions.c?r1=1.685&r2=1.686&ty=u Index: php-src/ext/standard/basic_functions.c diff -u php-src/ext/standard/basic_functions.c:1.685 php-src/ext/standard/basic_functions.c:1.686 --- php-src/ext/standard/basic_functions.c:1.685 Thu Aug 19 11:14:04 2004 +++ php-src/ext/standard/basic_functions.c Fri Sep 10 16:45:33 2004 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: basic_functions.c,v 1.685 2004/08/19 15:14:04 tony2001 Exp $ */ +/* $Id: basic_functions.c,v 1.686 2004/09/10 20:45:33 pollita Exp $ */ #include "php.h" #include "php_streams.h" @@ -623,6 +623,8 @@ PHP_FE(stream_get_line, NULL) PHP_FE(stream_wrapper_register, NULL) PHP_FALIAS(stream_register_wrapper, stream_wrapper_register, NULL) + PHP_FE(stream_wrapper_unregister, NULL) + PHP_FE(stream_wrapper_restore, NULL) PHP_FE(stream_get_wrappers, NULL) PHP_FE(stream_get_transports, NULL) PHP_FE(get_headers, NULL) http://cvs.php.net/diff.php/php-src/ext/standard/streamsfuncs.h?r1=1.9&r2=1.10&ty=u Index: php-src/ext/standard/streamsfuncs.h diff -u php-src/ext/standard/streamsfuncs.h:1.9 php-src/ext/standard/streamsfuncs.h:1.10 --- php-src/ext/standard/streamsfuncs.h:1.9 Thu Jul 22 08:12:28 2004 +++ php-src/ext/standard/streamsfuncs.h Fri Sep 10 16:45:35 2004 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: streamsfuncs.h,v 1.9 2004/07/22 12:12:28 wez Exp $ */ +/* $Id: streamsfuncs.h,v 1.10 2004/09/10 20:45:35 pollita Exp $ */ /* Flags for stream_socket_client */ #define PHP_STREAM_CLIENT_PERSISTENT 1 @@ -43,6 +43,8 @@ PHP_FUNCTION(stream_get_line); PHP_FUNCTION(stream_get_meta_data); PHP_FUNCTION(stream_wrapper_register); +PHP_FUNCTION(stream_wrapper_unregister); +PHP_FUNCTION(stream_wrapper_restore); PHP_FUNCTION(stream_context_create); PHP_FUNCTION(stream_context_set_params); PHP_FUNCTION(stream_context_set_option); http://cvs.php.net/diff.php/php-src/main/php_streams.h?r1=1.95&r2=1.96&ty=u Index: php-src/main/php_streams.h diff -u php-src/main/php_streams.h:1.95 php-src/main/php_streams.h:1.96 --- php-src/main/php_streams.h:1.95 Mon Jun 21 17:08:05 2004 +++ php-src/main/php_streams.h Fri Sep 10 16:45:35 2004 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_streams.h,v 1.95 2004/06/21 21:08:05 pollita Exp $ */ +/* $Id: php_streams.h,v 1.96 2004/09/10 20:45:35 pollita Exp $ */ #ifndef PHP_STREAMS_H #define PHP_STREAMS_H @@ -510,6 +510,7 @@ PHPAPI int php_register_url_stream_wrapper(char *protocol, php_stream_wrapper *wrapper TSRMLS_DC); PHPAPI int php_unregister_url_stream_wrapper(char *protocol TSRMLS_DC); PHPAPI int php_register_url_stream_wrapper_volatile(char *protocol, php_stream_wrapper *wrapper TSRMLS_DC); +PHPAPI int php_unregister_url_stream_wrapper_volatile(char *protocol TSRMLS_DC); PHPAPI php_stream *_php_stream_open_wrapper_ex(char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC); PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char **path_for_open, int options TSRMLS_DC); PHPAPI char *php_stream_locate_eol(php_stream *stream, char *buf, size_t buf_len TSRMLS_DC); @@ -541,6 +542,7 @@ /* 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_stream_get_url_stream_wrappers_hash_global(void); 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(); http://cvs.php.net/diff.php/php-src/main/streams/streams.c?r1=1.63&r2=1.64&ty=u Index: php-src/main/streams/streams.c diff -u php-src/main/streams/streams.c:1.63 php-src/main/streams/streams.c:1.64 --- php-src/main/streams/streams.c:1.63 Wed Sep 8 14:42:15 2004 +++ php-src/main/streams/streams.c Fri Sep 10 16:45:35 2004 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: streams.c,v 1.63 2004/09/08 18:42:15 pollita Exp $ */ +/* $Id: streams.c,v 1.64 2004/09/10 20:45:35 pollita Exp $ */ #define _GNU_SOURCE #include "php.h" @@ -54,6 +54,11 @@ return (FG(stream_wrappers) ? FG(stream_wrappers) : &url_stream_wrappers_hash); } +PHPAPI HashTable *php_stream_get_url_stream_wrappers_hash_global(void) +{ + return &url_stream_wrappers_hash; +} + static int _php_stream_release_context(list_entry *le, void *pContext TSRMLS_DC) { if (le->ptr == pContext) { @@ -1417,6 +1422,18 @@ return zend_hash_add(FG(stream_wrappers), protocol, strlen(protocol), wrapper, sizeof(*wrapper), NULL); } +PHPAPI int php_unregister_url_stream_wrapper_volatile(char *protocol TSRMLS_DC) +{ + if (!FG(stream_wrappers)) { + php_stream_wrapper tmpwrapper; + + FG(stream_wrappers) = emalloc(sizeof(HashTable)); + zend_hash_init(FG(stream_wrappers), 0, NULL, NULL, 1); + zend_hash_copy(FG(stream_wrappers), &url_stream_wrappers_hash, NULL, &tmpwrapper, sizeof(php_stream_wrapper)); + } + + return zend_hash_del(FG(stream_wrappers), protocol, strlen(protocol)); +} /* }}} */ /* {{{ php_stream_locate_url_wrapper */ http://cvs.php.net/diff.php/php-src/main/streams/userspace.c?r1=1.26&r2=1.27&ty=u Index: php-src/main/streams/userspace.c diff -u php-src/main/streams/userspace.c:1.26 php-src/main/streams/userspace.c:1.27 --- php-src/main/streams/userspace.c:1.26 Mon Jun 21 14:58:55 2004 +++ php-src/main/streams/userspace.c Fri Sep 10 16:45:35 2004 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: userspace.c,v 1.26 2004/06/21 18:58:55 pollita Exp $ */ +/* $Id: userspace.c,v 1.27 2004/09/10 20:45:35 pollita Exp $ */ #include "php.h" #include "php_globals.h" @@ -437,6 +437,62 @@ } /* }}} */ +/* {{{ bool stream_wrapper_unregister(string protocol) + Unregister a wrapper for the life of the current request. */ +PHP_FUNCTION(stream_wrapper_unregister) +{ + char *protocol; + int protocol_len; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &protocol, &protocol_len) == FAILURE) { + RETURN_FALSE; + } + + if (php_unregister_url_stream_wrapper_volatile(protocol TSRMLS_CC) == FAILURE) { + /* We failed */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to unregister protocol %s://", protocol); + RETURN_FALSE; + } + + RETURN_TRUE; +} +/* }}} */ + +/* {{{ bool stream_wrapper_restore(string protocol) + Restore the original protocol handler, overriding if necessary */ +PHP_FUNCTION(stream_wrapper_restore) +{ + char *protocol; + int protocol_len; + php_stream_wrapper *wrapper = NULL; + HashTable *global_wrapper_hash; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &protocol, &protocol_len) == FAILURE) { + RETURN_FALSE; + } + + global_wrapper_hash = php_stream_get_url_stream_wrappers_hash_global(); + if (php_stream_get_url_stream_wrappers_hash() == global_wrapper_hash) { + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%s:// was never changed, nothing to restore", protocol); + RETURN_TRUE; + } + + if ((zend_hash_find(global_wrapper_hash, protocol, protocol_len, (void**)&wrapper) == FAILURE) || !wrapper) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s:// never existed, nothing to restore", protocol); + RETURN_FALSE; + } + + /* A failure here could be okay given that the protocol might have been merely unregistered */ + php_unregister_url_stream_wrapper_volatile(protocol TSRMLS_CC); + + 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; +} +/* }}} */ static size_t php_userstreamop_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC) {
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php