From: Sara Golemon Date: Tue, 28 Oct 2003 21:52:59 +0000 (+0000) Subject: Extend Filter matching to check wildcards at multiple levels. X-Git-Tag: RELEASE_2_0_0RC1~30 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c9b49af9902095638cdbcea9eaa7bf623df15f37;p=php Extend Filter matching to check wildcards at multiple levels. 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. --- diff --git a/main/streams/filter.c b/main/streams/filter.c index c9dcee5abd..dd7c169dc6 100644 --- a/main/streams/filter.c +++ b/main/streams/filter.c @@ -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) {