From 62c48bf9a85e0294b7b32cea438e904e1cd50669 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Thu, 28 Dec 2017 15:14:02 +0100 Subject: Show in the phpinfo() is the config is valid This should close #39 --- src/php_snuffleupagus.h | 1 + src/snuffleupagus.c | 6 ++++++ src/tests/broken_conf_shown_in_phpinfo.phpt | 22 ++++++++++++++++++++++ src/tests/example_configuration.phpt | 12 ++++++++++-- 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 src/tests/broken_conf_shown_in_phpinfo.phpt (limited to 'src') 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; ZEND_BEGIN_MODULE_GLOBALS(snuffleupagus) sp_config config; +bool is_config_valid; HashTable *disabled_functions_hook; HashTable *sp_internal_functions_hook; 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) { php_info_print_table_start(); php_info_print_table_row(2, "snuffleupagus support", "enabled"); php_info_print_table_row(2, "Version", PHP_SNUFFLEUPAGUS_VERSION); + php_info_print_table_row(2, "Valid config", + (SNUFFLEUPAGUS_G(is_config_valid) == true)?"yes":"no"); php_info_print_table_end(); DISPLAY_INI_ENTRIES(); } @@ -167,14 +169,18 @@ static PHP_INI_MH(OnUpdateConfiguration) { config_file = strtok(new_value->val, ","); if (sp_parse_config(config_file) != SUCCESS) { + SNUFFLEUPAGUS_G(is_config_valid) = false; return FAILURE; } while ((config_file = strtok(NULL, ","))) { if (sp_parse_config(config_file) != SUCCESS) { + SNUFFLEUPAGUS_G(is_config_valid) = false; return FAILURE; } } + SNUFFLEUPAGUS_G(is_config_valid) = true; + if (SNUFFLEUPAGUS_G(config).config_random->enable) { hook_rand(); } 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 @@ +--TEST-- +Broken configuration +--SKIPIF-- + +--INI-- +sp.configuration_file={PWD}/config/broken_config_regexp.ini +--FILE-- + no') !== FALSE) { + echo "win"; +} else { + echo "lose"; +} +?> +--EXPECT-- +[snuffleupagus][0.0.0.0][config][error] Failed to compile '*.': nothing to repeat on line 1. +[snuffleupagus][0.0.0.0][config][error] '.filename_r()' is expecting a valid regexp, and not '"*."' on line 1. +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 sp.configuration_file={PWD}/../../config/examples.ini --FILE-- yes') !== FALSE) { + echo "win"; +} else { + echo "lose"; +} ?> --EXPECTF-- -0 +win -- cgit v1.3