diff options
| author | Sebastien Blot | 2018-01-18 11:07:06 +0100 |
|---|---|---|
| committer | Sebastien Blot | 2018-01-18 11:08:08 +0100 |
| commit | a09a48c605a36e052446f47b4e0eb98f9b8398a2 (patch) | |
| tree | 580befadb5d0c999058da8c5643bea543909c5d6 | |
| parent | 8b69ee4f557bb1314d98afb09ab133d036f30483 (diff) | |
Add globbing support for configuration file path (closes #125)
| -rw-r--r-- | src/snuffleupagus.c | 34 | ||||
| -rw-r--r-- | src/tests/glob_config.phpt | 23 |
2 files changed, 53 insertions, 4 deletions
diff --git a/src/snuffleupagus.c b/src/snuffleupagus.c index 78a8659..32a4198 100644 --- a/src/snuffleupagus.c +++ b/src/snuffleupagus.c | |||
| @@ -1,3 +1,5 @@ | |||
| 1 | #include <glob.h> | ||
| 2 | |||
| 1 | #ifdef HAVE_CONFIG_H | 3 | #ifdef HAVE_CONFIG_H |
| 2 | #include "config.h" | 4 | #include "config.h" |
| 3 | #endif | 5 | #endif |
| @@ -182,15 +184,39 @@ static PHP_INI_MH(OnUpdateConfiguration) { | |||
| 182 | } | 184 | } |
| 183 | 185 | ||
| 184 | config_file = strtok(new_value->val, ","); | 186 | config_file = strtok(new_value->val, ","); |
| 185 | if (sp_parse_config(config_file) != SUCCESS) { | 187 | |
| 186 | SNUFFLEUPAGUS_G(is_config_valid) = false; | 188 | glob_t globbuf; |
| 189 | |||
| 190 | int ret = glob(config_file, GLOB_BRACE|GLOB_NOCHECK, NULL, &globbuf); | ||
| 191 | |||
| 192 | if (ret != 0) { | ||
| 187 | return FAILURE; | 193 | return FAILURE; |
| 188 | } | 194 | } |
| 189 | while ((config_file = strtok(NULL, ","))) { | 195 | |
| 190 | if (sp_parse_config(config_file) != SUCCESS) { | 196 | size_t i = 0; |
| 197 | while (globbuf.gl_pathv[i]) { | ||
| 198 | if (sp_parse_config(globbuf.gl_pathv[i]) != SUCCESS) { | ||
| 191 | SNUFFLEUPAGUS_G(is_config_valid) = false; | 199 | SNUFFLEUPAGUS_G(is_config_valid) = false; |
| 192 | return FAILURE; | 200 | return FAILURE; |
| 193 | } | 201 | } |
| 202 | i++; | ||
| 203 | } | ||
| 204 | globfree(&globbuf); | ||
| 205 | i = 0; | ||
| 206 | |||
| 207 | while ((config_file = strtok(NULL, ","))) { | ||
| 208 | ret = glob(config_file, GLOB_BRACE|GLOB_NOCHECK, NULL, &globbuf); | ||
| 209 | if (ret != 0 ) { | ||
| 210 | return FAILURE; | ||
| 211 | } | ||
| 212 | while (globbuf.gl_pathv[i]) { | ||
| 213 | if (sp_parse_config(globbuf.gl_pathv[i]) != SUCCESS) { | ||
| 214 | SNUFFLEUPAGUS_G(is_config_valid) = false; | ||
| 215 | return FAILURE; | ||
| 216 | } | ||
| 217 | i++; | ||
| 218 | } | ||
| 219 | globfree(&globbuf); | ||
| 194 | } | 220 | } |
| 195 | 221 | ||
| 196 | SNUFFLEUPAGUS_G(is_config_valid) = true; | 222 | SNUFFLEUPAGUS_G(is_config_valid) = true; |
diff --git a/src/tests/glob_config.phpt b/src/tests/glob_config.phpt new file mode 100644 index 0000000..929664f --- /dev/null +++ b/src/tests/glob_config.phpt | |||
| @@ -0,0 +1,23 @@ | |||
| 1 | --TEST-- | ||
| 2 | Multiple configuration files | ||
| 3 | --SKIPIF-- | ||
| 4 | <?php if (!extension_loaded("snuffleupagus")) die "skip"; ?> | ||
| 5 | --INI-- | ||
| 6 | sp.configuration_file={PWD}/config/config_multi*.ini | ||
| 7 | --FILE-- | ||
| 8 | <?php | ||
| 9 | function foo() { | ||
| 10 | echo "1\n"; | ||
| 11 | } | ||
| 12 | function bla() { | ||
| 13 | echo "2\n"; | ||
| 14 | } | ||
| 15 | foo(); | ||
| 16 | bla(); | ||
| 17 | ?> | ||
| 18 | --EXPECTF-- | ||
| 19 | [snuffleupagus][0.0.0.0][disabled_function][simulation] The call to the function 'foo' in %s/src/tests/glob_config.php:%d has been disabled. | ||
| 20 | 1 | ||
| 21 | [snuffleupagus][0.0.0.0][disabled_function][simulation] The call to the function 'bla' in %s/src/tests/glob_config.php:%d has been disabled. | ||
| 22 | 2 | ||
| 23 | |||
