pollita Tue Oct 28 16:53:00 2003 EDT Modified files: /php-src/main/streams filter.c Log: 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. Index: php-src/main/streams/filter.c diff -u php-src/main/streams/filter.c:1.6 php-src/main/streams/filter.c:1.7 --- php-src/main/streams/filter.c:1.6 Tue Jun 10 16:03:42 2003 +++ php-src/main/streams/filter.c Tue Oct 28 16:52:59 2003 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: filter.c,v 1.6 2003/06/10 20:03:42 imajes Exp $ */ +/* $Id: filter.c,v 1.7 2003/10/28 21:52:59 pollita Exp $ */ #include "php.h" #include "php_globals.h" @@ -217,8 +217,8 @@ /* 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 @@ 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]; + char *wildname; - 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); + 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) {
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php