From edfbc0752d37e27354d0d9565b1697e6fcb4d47d Mon Sep 17 00:00:00 2001 From: jvoisin Date: Tue, 31 Oct 2017 18:08:09 +0100 Subject: Minor factorization of the keyword parsing code --- src/sp_config_keywords.c | 41 ++++++++++---------------- src/tests/broken_conf_mutually_exclusive.phpt | 2 +- src/tests/broken_conf_mutually_exclusive3.phpt | 2 +- src/tests/broken_conf_mutually_exclusive5.phpt | 2 +- 4 files changed, 19 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/sp_config_keywords.c b/src/sp_config_keywords.c index 416aaef..b1b22b5 100644 --- a/src/sp_config_keywords.c +++ b/src/sp_config_keywords.c @@ -182,36 +182,27 @@ int parse_disabled_functions(char *line) { return ret; } - if (df->value && df->value_r) { - sp_log_err("config", - "Invalid configuration line: 'sp.disabled_functions%s':" - "'.value' and '.regexp' are mutually exclusives on line %zu.", - line, sp_line_no); - return -1; - } else if (df->r_function && df->function) { - sp_log_err("config", - "Invalid configuration line: 'sp.disabled_functions%s': " - "'.r_function' and '.function' are mutually exclusive on line %zu.", - line, sp_line_no); - return -1; - } else if (df->r_filename && df->filename) { - sp_log_err("config", - "Invalid configuration line: 'sp.disabled_functions%s':" - "'.r_filename' and '.filename' are mutually exclusive on line %zu.", - line, sp_line_no); - return -1; - } else if (1 < ((df->r_param?1:0) + (df->param?1:0) + ((-1 != df->pos)?1:0))) { +#define MUTUALLY_EXCLUSIVE(X, Y, STR1, STR2) \ + if (X && Y) { \ + sp_log_err("config", \ + "Invalid configuration line: 'sp.disabled_functions%s': " \ + "'.%s' and '.%s' are mutually exclusive on line %zu.", \ + line, STR1, STR2, sp_line_no); \ + return 1;\ + } + + MUTUALLY_EXCLUSIVE(df->value, df->value_r, "value", "regexp"); + MUTUALLY_EXCLUSIVE(df->r_function, df->function, "r_function", "function"); + MUTUALLY_EXCLUSIVE(df->filename, df->r_filename, "r_filename", "filename"); + MUTUALLY_EXCLUSIVE(df->ret, df->r_ret, "r_ret", "ret"); +#undef MUTUALLY_EXCLUSIVE + + if (1 < ((df->r_param?1:0) + (df->param?1:0) + ((-1 != df->pos)?1:0))) { sp_log_err("config", "Invalid configuration line: 'sp.disabled_functions%s':" "'.r_param', '.param' and '.pos' are mutually exclusive on line %zu.", line, sp_line_no); return -1; - } else if (df->r_ret && df->ret) { - sp_log_err("config", - "Invalid configuration line: 'sp.disabled_functions%s':" - "'.r_ret' and '.ret' are mutually exclusive on line %zu.", - line, sp_line_no); - return -1; } else if ((df->r_ret || df->ret) && (df->r_param || df->param)) { sp_log_err("config", "Invalid configuration line: 'sp.disabled_functions%s':" diff --git a/src/tests/broken_conf_mutually_exclusive.phpt b/src/tests/broken_conf_mutually_exclusive.phpt index 7bfd313..5897770 100644 --- a/src/tests/broken_conf_mutually_exclusive.phpt +++ b/src/tests/broken_conf_mutually_exclusive.phpt @@ -6,4 +6,4 @@ Broken configuration sp.configuration_file={PWD}/config/broken_conf_mutually_exclusive.ini --FILE-- --EXPECT-- -[snuffleupagus][0.0.0.0][config][error] Invalid configuration line: 'sp.disabled_functions.function("system").param("id").value("42").value_r("^id$").drop();':'.value' and '.regexp' are mutually exclusives on line 1. \ No newline at end of file +[snuffleupagus][0.0.0.0][config][error] Invalid configuration line: 'sp.disabled_functions.function("system").param("id").value("42").value_r("^id$").drop();': '.value' and '.regexp' are mutually exclusive on line 1. diff --git a/src/tests/broken_conf_mutually_exclusive3.phpt b/src/tests/broken_conf_mutually_exclusive3.phpt index 3be561c..7b94318 100644 --- a/src/tests/broken_conf_mutually_exclusive3.phpt +++ b/src/tests/broken_conf_mutually_exclusive3.phpt @@ -6,4 +6,4 @@ Broken configuration sp.configuration_file={PWD}/config/broken_conf_mutually_exclusive3.ini --FILE-- --EXPECT-- -[snuffleupagus][0.0.0.0][config][error] Invalid configuration line: 'sp.disabled_functions.function("system").param("id").value("42").filename_r("^id$").filename("pouet.txt").drop();':'.r_filename' and '.filename' are mutually exclusive on line 1. \ No newline at end of file +[snuffleupagus][0.0.0.0][config][error] Invalid configuration line: 'sp.disabled_functions.function("system").param("id").value("42").filename_r("^id$").filename("pouet.txt").drop();': '.r_filename' and '.filename' are mutually exclusive on line 1. diff --git a/src/tests/broken_conf_mutually_exclusive5.phpt b/src/tests/broken_conf_mutually_exclusive5.phpt index 9ebc930..0a9e0fd 100644 --- a/src/tests/broken_conf_mutually_exclusive5.phpt +++ b/src/tests/broken_conf_mutually_exclusive5.phpt @@ -6,4 +6,4 @@ Broken configuration sp.configuration_file={PWD}/config/broken_conf_mutually_exclusive5.ini --FILE-- --EXPECT-- -[snuffleupagus][0.0.0.0][config][error] Invalid configuration line: 'sp.disabled_functions.function("system").ret("0").drop().ret_r("^0$");':'.r_ret' and '.ret' are mutually exclusive on line 1. \ No newline at end of file +[snuffleupagus][0.0.0.0][config][error] Invalid configuration line: 'sp.disabled_functions.function("system").ret("0").drop().ret_r("^0$");': '.r_ret' and '.ret' are mutually exclusive on line 1. -- cgit v1.3