diff options
| author | jvoisin | 2017-12-28 15:14:02 +0100 |
|---|---|---|
| committer | jvoisin | 2017-12-28 15:14:02 +0100 |
| commit | 62c48bf9a85e0294b7b32cea438e904e1cd50669 (patch) | |
| tree | 7c7e88debd8b6873fe444c6ed43a674827cc8c04 | |
| parent | b21139d922268251a19dd16f98248551863fe3e5 (diff) | |
Show in the phpinfo() is the config is valid
This should close #39
| -rw-r--r-- | src/php_snuffleupagus.h | 1 | ||||
| -rw-r--r-- | src/snuffleupagus.c | 6 | ||||
| -rw-r--r-- | src/tests/broken_conf_shown_in_phpinfo.phpt | 22 | ||||
| -rw-r--r-- | src/tests/example_configuration.phpt | 12 |
4 files changed, 39 insertions, 2 deletions
diff --git a/src/php_snuffleupagus.h b/src/php_snuffleupagus.h index cf50a10..d7c3e27 100644 --- a/src/php_snuffleupagus.h +++ b/src/php_snuffleupagus.h | |||
| @@ -59,6 +59,7 @@ extern zend_module_entry snuffleupagus_module_entry; | |||
| 59 | 59 | ||
| 60 | ZEND_BEGIN_MODULE_GLOBALS(snuffleupagus) | 60 | ZEND_BEGIN_MODULE_GLOBALS(snuffleupagus) |
| 61 | sp_config config; | 61 | sp_config config; |
| 62 | bool is_config_valid; | ||
| 62 | HashTable *disabled_functions_hook; | 63 | HashTable *disabled_functions_hook; |
| 63 | HashTable *sp_internal_functions_hook; | 64 | HashTable *sp_internal_functions_hook; |
| 64 | ZEND_END_MODULE_GLOBALS(snuffleupagus) | 65 | ZEND_END_MODULE_GLOBALS(snuffleupagus) |
diff --git a/src/snuffleupagus.c b/src/snuffleupagus.c index afbd725..b823a87 100644 --- a/src/snuffleupagus.c +++ b/src/snuffleupagus.c | |||
| @@ -152,6 +152,8 @@ PHP_MINFO_FUNCTION(snuffleupagus) { | |||
| 152 | php_info_print_table_start(); | 152 | php_info_print_table_start(); |
| 153 | php_info_print_table_row(2, "snuffleupagus support", "enabled"); | 153 | php_info_print_table_row(2, "snuffleupagus support", "enabled"); |
| 154 | php_info_print_table_row(2, "Version", PHP_SNUFFLEUPAGUS_VERSION); | 154 | php_info_print_table_row(2, "Version", PHP_SNUFFLEUPAGUS_VERSION); |
| 155 | php_info_print_table_row(2, "Valid config", | ||
| 156 | (SNUFFLEUPAGUS_G(is_config_valid) == true)?"yes":"no"); | ||
| 155 | php_info_print_table_end(); | 157 | php_info_print_table_end(); |
| 156 | DISPLAY_INI_ENTRIES(); | 158 | DISPLAY_INI_ENTRIES(); |
| 157 | } | 159 | } |
| @@ -167,14 +169,18 @@ static PHP_INI_MH(OnUpdateConfiguration) { | |||
| 167 | 169 | ||
| 168 | config_file = strtok(new_value->val, ","); | 170 | config_file = strtok(new_value->val, ","); |
| 169 | if (sp_parse_config(config_file) != SUCCESS) { | 171 | if (sp_parse_config(config_file) != SUCCESS) { |
| 172 | SNUFFLEUPAGUS_G(is_config_valid) = false; | ||
| 170 | return FAILURE; | 173 | return FAILURE; |
| 171 | } | 174 | } |
| 172 | while ((config_file = strtok(NULL, ","))) { | 175 | while ((config_file = strtok(NULL, ","))) { |
| 173 | if (sp_parse_config(config_file) != SUCCESS) { | 176 | if (sp_parse_config(config_file) != SUCCESS) { |
| 177 | SNUFFLEUPAGUS_G(is_config_valid) = false; | ||
| 174 | return FAILURE; | 178 | return FAILURE; |
| 175 | } | 179 | } |
| 176 | } | 180 | } |
| 177 | 181 | ||
| 182 | SNUFFLEUPAGUS_G(is_config_valid) = true; | ||
| 183 | |||
| 178 | if (SNUFFLEUPAGUS_G(config).config_random->enable) { | 184 | if (SNUFFLEUPAGUS_G(config).config_random->enable) { |
| 179 | hook_rand(); | 185 | hook_rand(); |
| 180 | } | 186 | } |
diff --git a/src/tests/broken_conf_shown_in_phpinfo.phpt b/src/tests/broken_conf_shown_in_phpinfo.phpt new file mode 100644 index 0000000..61e9512 --- /dev/null +++ b/src/tests/broken_conf_shown_in_phpinfo.phpt | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | --TEST-- | ||
| 2 | Broken configuration | ||
| 3 | --SKIPIF-- | ||
| 4 | <?php if (!extension_loaded("snuffleupagus")) print "skip"; ?> | ||
| 5 | --INI-- | ||
| 6 | sp.configuration_file={PWD}/config/broken_config_regexp.ini | ||
| 7 | --FILE-- | ||
| 8 | <?php | ||
| 9 | ob_start(); | ||
| 10 | phpinfo(); | ||
| 11 | $info = ob_get_clean(); | ||
| 12 | ob_get_clean(); | ||
| 13 | if (strstr($info, 'Valid config => no') !== FALSE) { | ||
| 14 | echo "win"; | ||
| 15 | } else { | ||
| 16 | echo "lose"; | ||
| 17 | } | ||
| 18 | ?> | ||
| 19 | --EXPECT-- | ||
| 20 | [snuffleupagus][0.0.0.0][config][error] Failed to compile '*.': nothing to repeat on line 1. | ||
| 21 | [snuffleupagus][0.0.0.0][config][error] '.filename_r()' is expecting a valid regexp, and not '"*."' on line 1. | ||
| 22 | win | ||
diff --git a/src/tests/example_configuration.phpt b/src/tests/example_configuration.phpt index b7fec48..74bdb49 100644 --- a/src/tests/example_configuration.phpt +++ b/src/tests/example_configuration.phpt | |||
| @@ -6,7 +6,15 @@ Shipped configuration | |||
| 6 | sp.configuration_file={PWD}/../../config/examples.ini | 6 | sp.configuration_file={PWD}/../../config/examples.ini |
| 7 | --FILE-- | 7 | --FILE-- |
| 8 | <?php | 8 | <?php |
| 9 | echo 0; | 9 | ob_start(); |
| 10 | phpinfo(); | ||
| 11 | $info = ob_get_clean(); | ||
| 12 | ob_get_clean(); | ||
| 13 | if (strstr($info, 'Valid config => yes') !== FALSE) { | ||
| 14 | echo "win"; | ||
| 15 | } else { | ||
| 16 | echo "lose"; | ||
| 17 | } | ||
| 10 | ?> | 18 | ?> |
| 11 | --EXPECTF-- | 19 | --EXPECTF-- |
| 12 | 0 | 20 | win |
