]> granicus.if.org Git - php/commitdiff
Allow userspace filters to use wildcards
authorSara Golemon <pollita@php.net>
Wed, 29 Oct 2003 00:19:57 +0000 (00:19 +0000)
committerSara Golemon <pollita@php.net>
Wed, 29 Oct 2003 00:19:57 +0000 (00:19 +0000)
ext/standard/user_filters.c

index 891055bbd4e855249d51fee860fb825e50a1476f..64241d61470761613b29e9c9f9e5e39a69bf883f 100644 (file)
@@ -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 */