From 70f4a0c9ecfd8bd5ce5a424a3004dec607d0ea67 Mon Sep 17 00:00:00 2001 From: Sara Golemon Date: Wed, 29 Oct 2003 00:19:57 +0000 Subject: [PATCH] Allow userspace filters to use wildcards --- ext/standard/user_filters.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/ext/standard/user_filters.c b/ext/standard/user_filters.c index 891055bbd4..64241d6147 100644 --- a/ext/standard/user_filters.c +++ b/ext/standard/user_filters.c @@ -246,9 +246,36 @@ static php_stream_filter *user_filter_factory_create(const char *filtername, /* determine the classname/class entry */ if (FAILURE == zend_hash_find(BG(user_filter_map), (char*)filtername, strlen(filtername), (void**)&fdat)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, - "Err, filter \"%s\" is not in the user-filter map, but somehow the user-filter-factory was invoked for it!?", filtername); - return NULL; + char *period; + + /* Userspace Filters using ambiguous wildcards could cause problems. + i.e.: myfilter.foo.bar will always call into myfilter.foo.* + never seeing myfilter.* + TODO: Allow failed userfilter creations to continue + scanning through the list */ + if ((period = strrchr(filtername, '.'))) { + char *wildcard; + + /* Search for wildcard matches instead */ + wildcard = estrdup(filtername); + period = wildcard + (period - filtername); + while (period) { + *period = '\0'; + strcat(wildcard, ".*"); + if (SUCCESS == zend_hash_find(BG(user_filter_map), wildcard, strlen(wildcard), (void**)&fdat)) { + period = NULL; + } else { + *period = '\0'; + period = strrchr(wildcard, '.'); + } + } + efree(wildcard); + } + if (fdat == NULL) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, + "Err, filter \"%s\" is not in the user-filter map, but somehow the user-filter-factory was invoked for it!?", filtername); + return NULL; + } } /* bind the classname to the actual class */ -- 2.50.1