/* Default to global wrappers only */
FG(stream_wrappers) = NULL;
+ /* Default to global filters only */
+ FG(stream_filters) = NULL;
+
return SUCCESS;
}
}
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);
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);
return SUCCESS;
#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);
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)
* 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;
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 */
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);
}