diff options
| author | Thibault "bui" Koechlin | 2017-10-19 18:05:37 +0200 |
|---|---|---|
| committer | GitHub | 2017-10-19 18:05:37 +0200 |
| commit | 8d3a23b2cc4cc433706706db5ba5fbfb24e06b7c (patch) | |
| tree | 69b4cecad32571120b9cd6edbdc2f0525805fa9d /src/sp_config_keywords.c | |
| parent | e8d255e5cef8949256d3290b2d8fd22de9428a83 (diff) | |
| parent | 066b79abe9943821240ccc3a458e8ba45b9ee9e8 (diff) | |
Merge pull request #33 from nbs-system/4-match-on-arg-pos
Implement match on arguments position
Diffstat (limited to 'src/sp_config_keywords.c')
| -rw-r--r-- | src/sp_config_keywords.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/sp_config_keywords.c b/src/sp_config_keywords.c index 29f1bfc..097d08b 100644 --- a/src/sp_config_keywords.c +++ b/src/sp_config_keywords.c | |||
| @@ -144,7 +144,9 @@ int parse_cookie_encryption(char *line) { | |||
| 144 | int parse_disabled_functions(char *line) { | 144 | int parse_disabled_functions(char *line) { |
| 145 | int ret = 0; | 145 | int ret = 0; |
| 146 | bool enable = true, disable = false; | 146 | bool enable = true, disable = false; |
| 147 | char *pos = NULL; | ||
| 147 | sp_disabled_function *df = pecalloc(sizeof(*df), 1, 1); | 148 | sp_disabled_function *df = pecalloc(sizeof(*df), 1, 1); |
| 149 | df->pos = -1; | ||
| 148 | 150 | ||
| 149 | sp_config_functions sp_config_funcs_disabled_functions[] = { | 151 | sp_config_functions sp_config_funcs_disabled_functions[] = { |
| 150 | {parse_empty, SP_TOKEN_ENABLE, &(enable)}, | 152 | {parse_empty, SP_TOKEN_ENABLE, &(enable)}, |
| @@ -169,6 +171,7 @@ int parse_disabled_functions(char *line) { | |||
| 169 | {parse_regexp, SP_TOKEN_RET_REGEXP, &(df->r_ret)}, | 171 | {parse_regexp, SP_TOKEN_RET_REGEXP, &(df->r_ret)}, |
| 170 | {parse_php_type, SP_TOKEN_RET_TYPE, &(df->ret_type)}, | 172 | {parse_php_type, SP_TOKEN_RET_TYPE, &(df->ret_type)}, |
| 171 | {parse_str, SP_TOKEN_LOCAL_VAR, &(df->var)}, | 173 | {parse_str, SP_TOKEN_LOCAL_VAR, &(df->var)}, |
| 174 | {parse_str, SP_TOKEN_VALUE_ARG_POS, &(pos)}, | ||
| 172 | {0}}; | 175 | {0}}; |
| 173 | 176 | ||
| 174 | ret = parse_keywords(sp_config_funcs_disabled_functions, line); | 177 | ret = parse_keywords(sp_config_funcs_disabled_functions, line); |
| @@ -201,10 +204,10 @@ int parse_disabled_functions(char *line) { | |||
| 201 | "'.r_filename' and '.filename' are mutually exclusive on line %zu.", | 204 | "'.r_filename' and '.filename' are mutually exclusive on line %zu.", |
| 202 | line, sp_line_no); | 205 | line, sp_line_no); |
| 203 | return -1; | 206 | return -1; |
| 204 | } else if (df->r_param && df->param) { | 207 | } else if (1 < ((df->r_param?1:0) + (df->param?1:0) + ((-1 != df->pos)?1:0))) { |
| 205 | sp_log_err("config", | 208 | sp_log_err("config", |
| 206 | "Invalid configuration line: 'sp.disabled_functions%s':" | 209 | "Invalid configuration line: 'sp.disabled_functions%s':" |
| 207 | "'.r_param' and '.param' are mutually exclusive on line %zu.", | 210 | "'.r_param', '.param' and '.pos' are mutually exclusive on line %zu.", |
| 208 | line, sp_line_no); | 211 | line, sp_line_no); |
| 209 | return -1; | 212 | return -1; |
| 210 | } else if (df->r_ret && df->ret) { | 213 | } else if (df->r_ret && df->ret) { |
| @@ -233,6 +236,22 @@ int parse_disabled_functions(char *line) { | |||
| 233 | return -1; | 236 | return -1; |
| 234 | } | 237 | } |
| 235 | 238 | ||
| 239 | if (pos) { | ||
| 240 | errno = 0; | ||
| 241 | char *endptr; | ||
| 242 | df->pos = strtol(pos, &endptr, 10); | ||
| 243 | if (errno != 0 || endptr == pos) { | ||
| 244 | sp_log_err("config", "Failed to parse arg '%s' of `pos` on line %zu.", | ||
| 245 | pos, sp_line_no); | ||
| 246 | return -1; | ||
| 247 | } | ||
| 248 | |||
| 249 | // We'll never have a function with more than 128 params | ||
| 250 | if (df->pos > 128) { | ||
| 251 | df->pos = 128; | ||
| 252 | } | ||
| 253 | } | ||
| 254 | |||
| 236 | if (df->function) { | 255 | if (df->function) { |
| 237 | df->functions_list = parse_functions_list(df->function); | 256 | df->functions_list = parse_functions_list(df->function); |
| 238 | } | 257 | } |
