]> granicus.if.org Git - php/commitdiff
Extend Filter matching to check wildcards at multiple levels.
authorSara Golemon <pollita@php.net>
Tue, 28 Oct 2003 21:52:59 +0000 (21:52 +0000)
committerSara Golemon <pollita@php.net>
Tue, 28 Oct 2003 21:52:59 +0000 (21:52 +0000)
Ex:  foo.bar.baz.bomb
Searches:
     foo.bar.baz.bomb itself,
     foo.bar.baz.*,
     foo.bar.*, and
     foo.*

Also changed tempvar "char wildcard[128];" to an estrdup() to
deal with potential filternames longer than 127 bytes.

main/streams/filter.c

index c9dcee5abdcac9bd7b31924ed228a787f11f5b14..dd7c169dc62a000629e3eb5d275152944467a223 100644 (file)
@@ -217,8 +217,8 @@ PHPAPI void php_stream_bucket_unlink(php_stream_bucket *bucket TSRMLS_DC)
 
 
 /* We allow very simple pattern matching for filter factories:
- * if "charset.utf-8/sjis" is requested, we search first for an exact
- * match. If that fails, we try "charset.*".
+ * if "convert.charset.utf-8/sjis" is requested, we search first for an exact
+ * match. If that fails, we try "convert.charset.*", then "convert.*"
  * This means that we don't need to clog up the hashtable with a zillion
  * 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)
@@ -232,16 +232,23 @@ PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval
        
        if (SUCCESS == zend_hash_find(&stream_filters_hash, (char*)filtername, n, (void**)&factory)) {
                filter = factory->create_filter(filtername, filterparams, persistent TSRMLS_CC);
-       } else if ((period = strchr(filtername, '.'))) {
+       } else if ((period = strrchr(filtername, '.'))) {
                /* try a wildcard */
-               char wildname[128];
-
-               PHP_STRLCPY(wildname, filtername, sizeof(wildname) - 1, period-filtername + 1);
-               strcat(wildname, "*");
-               
-               if (SUCCESS == zend_hash_find(&stream_filters_hash, wildname, strlen(wildname), (void**)&factory)) {
-                       filter = factory->create_filter(filtername, filterparams, persistent TSRMLS_CC);
+               char *wildname;
+
+               wildname = estrdup(filtername);
+               period = wildname + (period - filtername);
+               while (period) {
+                       *period = '\0';
+                       strcat(wildname, ".*");
+                       if (SUCCESS == zend_hash_find(&stream_filters_hash, wildname, strlen(wildname), (void**)&factory)) {
+                               filter = factory->create_filter(filtername, filterparams, persistent TSRMLS_CC);
+                       }
+
+                       *period = '\0';
+                       period = strrchr(wildname, '.');
                }
+               efree(wildname);
        }
 
        if (filter == NULL) {