diff options
| author | jvoisin | 2018-01-18 11:22:21 +0100 |
|---|---|---|
| committer | jvoisin | 2018-01-18 11:22:21 +0100 |
| commit | 6bf83ed292731490b09f4bc87fb746bef2520a8e (patch) | |
| tree | 2229c848620c43f207f58f42fe049de8d4cfdacb /src | |
| parent | 5b87206831cd4e290d50f9a1f09f4249c4964441 (diff) | |
Clean up a bit the glob code
Diffstat (limited to 'src')
| -rw-r--r-- | src/snuffleupagus.c | 36 |
1 files changed, 14 insertions, 22 deletions
diff --git a/src/snuffleupagus.c b/src/snuffleupagus.c index b1ca559..90ed7ec 100644 --- a/src/snuffleupagus.c +++ b/src/snuffleupagus.c | |||
| @@ -81,11 +81,11 @@ PHP_GINIT_FUNCTION(snuffleupagus) { | |||
| 81 | SP_INIT(snuffleupagus_globals->config.config_eval); | 81 | SP_INIT(snuffleupagus_globals->config.config_eval); |
| 82 | 82 | ||
| 83 | snuffleupagus_globals->config.config_disabled_constructs->construct_include = | 83 | snuffleupagus_globals->config.config_disabled_constructs->construct_include = |
| 84 | NULL; | 84 | NULL; |
| 85 | snuffleupagus_globals->config.config_disabled_constructs->construct_eval = | 85 | snuffleupagus_globals->config.config_disabled_constructs->construct_eval = |
| 86 | NULL; | 86 | NULL; |
| 87 | snuffleupagus_globals->config.config_disabled_functions->disabled_functions = | 87 | snuffleupagus_globals->config.config_disabled_functions->disabled_functions = |
| 88 | NULL; | 88 | NULL; |
| 89 | snuffleupagus_globals->config.config_disabled_functions_ret | 89 | snuffleupagus_globals->config.config_disabled_functions_ret |
| 90 | ->disabled_functions = NULL; | 90 | ->disabled_functions = NULL; |
| 91 | snuffleupagus_globals->config.config_cookie->cookies = NULL; | 91 | snuffleupagus_globals->config.config_cookie->cookies = NULL; |
| @@ -177,50 +177,42 @@ PHP_MINFO_FUNCTION(snuffleupagus) { | |||
| 177 | static PHP_INI_MH(OnUpdateConfiguration) { | 177 | static PHP_INI_MH(OnUpdateConfiguration) { |
| 178 | TSRMLS_FETCH(); | 178 | TSRMLS_FETCH(); |
| 179 | 179 | ||
| 180 | char *config_file = NULL; | ||
| 181 | |||
| 182 | if (!new_value || !new_value->len) { | 180 | if (!new_value || !new_value->len) { |
| 183 | return FAILURE; | 181 | return FAILURE; |
| 184 | } | 182 | } |
| 185 | 183 | ||
| 186 | config_file = strtok(new_value->val, ","); | ||
| 187 | |||
| 188 | glob_t globbuf; | 184 | glob_t globbuf; |
| 189 | 185 | char *config_file = strtok(new_value->val, ","); | |
| 190 | int ret = glob(config_file, GLOB_BRACE|GLOB_NOCHECK, NULL, &globbuf); | 186 | int ret = glob(config_file, GLOB_BRACE | GLOB_NOCHECK, NULL, &globbuf); |
| 191 | 187 | ||
| 192 | if (ret != 0) { | 188 | if (ret != 0) { |
| 193 | SNUFFLEUPAGUS_G(is_config_valid) = false; | 189 | SNUFFLEUPAGUS_G(is_config_valid) = false; |
| 194 | globfree(&globbuf); | 190 | globfree(&globbuf); |
| 195 | return FAILURE; | 191 | return FAILURE; |
| 196 | } | 192 | } |
| 197 | 193 | ||
| 198 | size_t i = 0; | 194 | for (size_t i = 0; globbuf.gl_pathv[i]; i++) { |
| 199 | while (globbuf.gl_pathv[i]) { | ||
| 200 | if (sp_parse_config(globbuf.gl_pathv[i]) != SUCCESS) { | 195 | if (sp_parse_config(globbuf.gl_pathv[i]) != SUCCESS) { |
| 201 | SNUFFLEUPAGUS_G(is_config_valid) = false; | 196 | SNUFFLEUPAGUS_G(is_config_valid) = false; |
| 202 | globfree(&globbuf); | 197 | globfree(&globbuf); |
| 203 | return FAILURE; | 198 | return FAILURE; |
| 204 | } | 199 | } |
| 205 | i++; | ||
| 206 | } | 200 | } |
| 207 | globfree(&globbuf); | 201 | globfree(&globbuf); |
| 208 | i = 0; | 202 | |
| 209 | |||
| 210 | while ((config_file = strtok(NULL, ","))) { | 203 | while ((config_file = strtok(NULL, ","))) { |
| 211 | ret = glob(config_file, GLOB_BRACE|GLOB_NOCHECK, NULL, &globbuf); | 204 | ret = glob(config_file, GLOB_BRACE | GLOB_NOCHECK, NULL, &globbuf); |
| 212 | if (ret != 0 ) { | 205 | if (ret != 0) { |
| 213 | SNUFFLEUPAGUS_G(is_config_valid) = false; | 206 | SNUFFLEUPAGUS_G(is_config_valid) = false; |
| 214 | globfree(&globbuf); | 207 | globfree(&globbuf); |
| 215 | return FAILURE; | 208 | return FAILURE; |
| 216 | } | 209 | } |
| 217 | while (globbuf.gl_pathv[i]) { | 210 | for (size_t i = 0; globbuf.gl_pathv[i]; i++) { |
| 218 | if (sp_parse_config(globbuf.gl_pathv[i]) != SUCCESS) { | 211 | if (sp_parse_config(globbuf.gl_pathv[i]) != SUCCESS) { |
| 219 | SNUFFLEUPAGUS_G(is_config_valid) = false; | 212 | SNUFFLEUPAGUS_G(is_config_valid) = false; |
| 220 | globfree(&globbuf); | 213 | globfree(&globbuf); |
| 221 | return FAILURE; | 214 | return FAILURE; |
| 222 | } | 215 | } |
| 223 | i++; | ||
| 224 | } | 216 | } |
| 225 | globfree(&globbuf); | 217 | globfree(&globbuf); |
| 226 | } | 218 | } |
