diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/sp_config.c | 2 | ||||
| -rw-r--r-- | src/sp_config_scanner.h | 2 | ||||
| -rw-r--r-- | src/sp_config_scanner.re | 32 | ||||
| -rw-r--r-- | src/sp_ini.c | 2 | ||||
| -rw-r--r-- | src/sp_utils.h | 5 |
5 files changed, 24 insertions, 19 deletions
diff --git a/src/sp_config.c b/src/sp_config.c index 2d2631a..de58c2a 100644 --- a/src/sp_config.c +++ b/src/sp_config.c | |||
| @@ -90,7 +90,7 @@ zend_result sp_process_rule(sp_parsed_keyword *parsed_rule, const sp_config_keyw | |||
| 90 | 90 | ||
| 91 | if (!found_kw) { | 91 | if (!found_kw) { |
| 92 | zend_string *kwname = zend_string_init(kw->kw, kw->kwlen, 0); | 92 | zend_string *kwname = zend_string_init(kw->kw, kw->kwlen, 0); |
| 93 | sp_log_err("config", "Unexpected keyword '%s' on line %d", ZSTR_VAL(kwname), kw->lineno); | 93 | sp_log_err("config", "Unexpected keyword '%s' on line %zu", ZSTR_VAL(kwname), kw->lineno); |
| 94 | zend_string_release_ex(kwname, 0); | 94 | zend_string_release_ex(kwname, 0); |
| 95 | return FAILURE; | 95 | return FAILURE; |
| 96 | } | 96 | } |
diff --git a/src/sp_config_scanner.h b/src/sp_config_scanner.h index 560ea6e..dda3dc2 100644 --- a/src/sp_config_scanner.h +++ b/src/sp_config_scanner.h | |||
| @@ -15,7 +15,7 @@ typedef struct { | |||
| 15 | const char *arg; // optional argument / can be not null terminated | 15 | const char *arg; // optional argument / can be not null terminated |
| 16 | size_t arglen; | 16 | size_t arglen; |
| 17 | sp_argtype argtype; | 17 | sp_argtype argtype; |
| 18 | long lineno; | 18 | size_t lineno; |
| 19 | } sp_parsed_keyword; | 19 | } sp_parsed_keyword; |
| 20 | 20 | ||
| 21 | zend_result sp_config_scan(const char *data, zend_result (*process_rule)(sp_parsed_keyword*)); | 21 | zend_result sp_config_scan(const char *data, zend_result (*process_rule)(sp_parsed_keyword*)); |
diff --git a/src/sp_config_scanner.re b/src/sp_config_scanner.re index 8f0b24e..f9a6ce9 100644 --- a/src/sp_config_scanner.re +++ b/src/sp_config_scanner.re | |||
| @@ -90,11 +90,11 @@ static void str_dtor(zval *zv) { | |||
| 90 | 90 | ||
| 91 | // sy_ functions and macros are helpers for the shunting yard algorithm | 91 | // sy_ functions and macros are helpers for the shunting yard algorithm |
| 92 | #define sy_res_push(val) \ | 92 | #define sy_res_push(val) \ |
| 93 | if (cond_res_i >= MAX_CONDITIONS) { cs_log_error("condition too complex on line %d", lineno); goto out; } \ | 93 | if (cond_res_i >= MAX_CONDITIONS) { cs_log_error("condition too complex on line %zu", lineno); goto out; } \ |
| 94 | cond_res[cond_res_i++] = val; | 94 | cond_res[cond_res_i++] = val; |
| 95 | #define sy_res_pop() cond_res[--cond_res_i] | 95 | #define sy_res_pop() cond_res[--cond_res_i] |
| 96 | #define sy_op_push(op) \ | 96 | #define sy_op_push(op) \ |
| 97 | if (cond_op_i >= MAX_CONDITIONS) { cs_log_error("condition too complex on line %d", lineno); goto out; } \ | 97 | if (cond_op_i >= MAX_CONDITIONS) { cs_log_error("condition too complex on line %zu", lineno); goto out; } \ |
| 98 | cond_op[cond_op_i++] = op; | 98 | cond_op[cond_op_i++] = op; |
| 99 | #define sy_op_pop() cond_op[--cond_op_i] | 99 | #define sy_op_pop() cond_op[--cond_op_i] |
| 100 | #define sy_op_peek() cond_op[cond_op_i-1] | 100 | #define sy_op_peek() cond_op[cond_op_i-1] |
| @@ -138,7 +138,7 @@ static int sy_apply_op(const char op, const int a, const int b) { | |||
| 138 | #define SY_APPLY_OP_FROM_STACK() \ | 138 | #define SY_APPLY_OP_FROM_STACK() \ |
| 139 | char op = sy_op_pop(); \ | 139 | char op = sy_op_pop(); \ |
| 140 | int unary = (op == '!'); \ | 140 | int unary = (op == '!'); \ |
| 141 | if (cond_res_i < (2 - unary)) { cs_log_error("not enough input on line %d", lineno); goto out; } \ | 141 | if (cond_res_i < (2 - unary)) { cs_log_error("not enough input on line %zu", lineno); goto out; } \ |
| 142 | int a = sy_res_pop(); \ | 142 | int a = sy_res_pop(); \ |
| 143 | int b = unary ? 0 : sy_res_pop(); \ | 143 | int b = unary ? 0 : sy_res_pop(); \ |
| 144 | int res = sy_apply_op(op, a, b); \ | 144 | int res = sy_apply_op(op, a, b); \ |
| @@ -169,7 +169,7 @@ zend_result sp_config_scan(const char *data, zend_result (*process_rule)(sp_pars | |||
| 169 | int cond_op_i = 0; | 169 | int cond_op_i = 0; |
| 170 | 170 | ||
| 171 | int cond = yycinit; | 171 | int cond = yycinit; |
| 172 | long lineno = 1; | 172 | size_t lineno = 1; |
| 173 | 173 | ||
| 174 | /*!stags:re2c format = 'const char *@@;\n'; */ | 174 | /*!stags:re2c format = 'const char *@@;\n'; */ |
| 175 | /*!re2c | 175 | /*!re2c |
| @@ -189,7 +189,7 @@ zend_result sp_config_scan(const char *data, zend_result (*process_rule)(sp_pars | |||
| 189 | keyword = [a-zA-Z][a-zA-Z0-9_]*; | 189 | keyword = [a-zA-Z][a-zA-Z0-9_]*; |
| 190 | string = ["] ("\\"["] | [^"\r\n\x00])* ["]; | 190 | string = ["] ("\\"["] | [^"\r\n\x00])* ["]; |
| 191 | 191 | ||
| 192 | <init> * { cs_log_error("parser error on line %d", lineno); goto out; } | 192 | <init> * { cs_log_error("parser error on line %zu", lineno); goto out; } |
| 193 | <init> whitespace+ { goto yyc_init; } | 193 | <init> whitespace+ { goto yyc_init; } |
| 194 | <init> [;#] [^\r\n\x00]* { goto yyc_init; } | 194 | <init> [;#] [^\r\n\x00]* { goto yyc_init; } |
| 195 | <init> newline { lineno++; goto yyc_init; } | 195 | <init> newline { lineno++; goto yyc_init; } |
| @@ -212,19 +212,19 @@ zend_result sp_config_scan(const char *data, zend_result (*process_rule)(sp_pars | |||
| 212 | <init> ( "@log" | "@info" ) whitespace+ @t1 string @t2 ";" { | 212 | <init> ( "@log" | "@info" ) whitespace+ @t1 string @t2 ";" { |
| 213 | if (!cond_res[0]) { goto yyc_init; } | 213 | if (!cond_res[0]) { goto yyc_init; } |
| 214 | TMPSTR(tmpstr, t2, t1); | 214 | TMPSTR(tmpstr, t2, t1); |
| 215 | cs_log_info("[line %d]: %s", lineno, tmpstr); | 215 | cs_log_info("[line %zu]: %s", lineno, tmpstr); |
| 216 | goto yyc_init; | 216 | goto yyc_init; |
| 217 | } | 217 | } |
| 218 | <init> ( "@warn" | "@warning" ) whitespace+ @t1 string @t2 ";" { | 218 | <init> ( "@warn" | "@warning" ) whitespace+ @t1 string @t2 ";" { |
| 219 | if (!cond_res[0]) { goto yyc_init; } | 219 | if (!cond_res[0]) { goto yyc_init; } |
| 220 | TMPSTR(tmpstr, t2, t1); | 220 | TMPSTR(tmpstr, t2, t1); |
| 221 | cs_log_warning("[line %d]: %s", lineno, tmpstr); | 221 | cs_log_warning("[line %zu]: %s", lineno, tmpstr); |
| 222 | goto yyc_init; | 222 | goto yyc_init; |
| 223 | } | 223 | } |
| 224 | <init> ( "@err" | "@error" ) whitespace+ @t1 string @t2 ";" { | 224 | <init> ( "@err" | "@error" ) whitespace+ @t1 string @t2 ";" { |
| 225 | if (!cond_res[0]) { goto yyc_init; } | 225 | if (!cond_res[0]) { goto yyc_init; } |
| 226 | TMPSTR(tmpstr, t2, t1); | 226 | TMPSTR(tmpstr, t2, t1); |
| 227 | cs_log_error("[line %d]: %s", lineno, tmpstr); | 227 | cs_log_error("[line %zu]: %s", lineno, tmpstr); |
| 228 | goto out; | 228 | goto out; |
| 229 | } | 229 | } |
| 230 | 230 | ||
| @@ -236,7 +236,7 @@ zend_result sp_config_scan(const char *data, zend_result (*process_rule)(sp_pars | |||
| 236 | int is_loaded = (zend_hash_str_find_ptr(&module_registry, t3+1, t4-t3-2) != NULL); | 236 | int is_loaded = (zend_hash_str_find_ptr(&module_registry, t3+1, t4-t3-2) != NULL); |
| 237 | sy_res_push(is_loaded); | 237 | sy_res_push(is_loaded); |
| 238 | } else { | 238 | } else { |
| 239 | cs_log_error("unknown function in condition on line %d", lineno); | 239 | cs_log_error("unknown function in condition on line %zu", lineno); |
| 240 | goto out; | 240 | goto out; |
| 241 | } | 241 | } |
| 242 | goto yyc_cond_op; | 242 | goto yyc_cond_op; |
| @@ -244,7 +244,7 @@ zend_result sp_config_scan(const char *data, zend_result (*process_rule)(sp_pars | |||
| 244 | <cond> @t1 keyword @t2 { | 244 | <cond> @t1 keyword @t2 { |
| 245 | zend_string *tmp = zend_hash_str_find_ptr(&vars, t1, t2-t1); | 245 | zend_string *tmp = zend_hash_str_find_ptr(&vars, t1, t2-t1); |
| 246 | if (!tmp) { | 246 | if (!tmp) { |
| 247 | cs_log_error("unknown variable in condition on line %d", lineno); | 247 | cs_log_error("unknown variable in condition on line %zu", lineno); |
| 248 | goto out; | 248 | goto out; |
| 249 | } | 249 | } |
| 250 | sy_res_push(atoi(ZSTR_VAL(tmp))); | 250 | sy_res_push(atoi(ZSTR_VAL(tmp))); |
| @@ -280,27 +280,27 @@ zend_result sp_config_scan(const char *data, zend_result (*process_rule)(sp_pars | |||
| 280 | SY_APPLY_OP_FROM_STACK(); | 280 | SY_APPLY_OP_FROM_STACK(); |
| 281 | } | 281 | } |
| 282 | if (cond_op_i == 0 || sy_op_peek() != '(') { | 282 | if (cond_op_i == 0 || sy_op_peek() != '(') { |
| 283 | cs_log_error("unbalanced parenthesis on line %d", lineno); goto out; | 283 | cs_log_error("unbalanced parenthesis on line %zu", lineno); goto out; |
| 284 | } | 284 | } |
| 285 | cond_op_i--; | 285 | cond_op_i--; |
| 286 | goto yyc_cond_op; | 286 | goto yyc_cond_op; |
| 287 | } | 287 | } |
| 288 | <cond_op> ";" { | 288 | <cond_op> ";" { |
| 289 | while (cond_op_i) { | 289 | while (cond_op_i) { |
| 290 | if (sy_op_peek() == '(') { cs_log_error("unbalanced parenthesis on line %d", lineno); goto out; } | 290 | if (sy_op_peek() == '(') { cs_log_error("unbalanced parenthesis on line %zu", lineno); goto out; } |
| 291 | SY_APPLY_OP_FROM_STACK(); | 291 | SY_APPLY_OP_FROM_STACK(); |
| 292 | } | 292 | } |
| 293 | if (cond_res_i > 1) { cs_log_error("invalid condition on line %d", lineno); goto out; } | 293 | if (cond_res_i > 1) { cs_log_error("invalid condition on line %zu", lineno); goto out; } |
| 294 | goto yyc_init; | 294 | goto yyc_init; |
| 295 | } | 295 | } |
| 296 | <cond, cond_op> * { cs_log_error("syntax error in condition on line %d", lineno); goto out; } | 296 | <cond, cond_op> * { cs_log_error("syntax error in condition on line %zu", lineno); goto out; } |
| 297 | 297 | ||
| 298 | <rule> whitespace+ { goto yyc_rule; } | 298 | <rule> whitespace+ { goto yyc_rule; } |
| 299 | <rule> newline / ( newline | whitespace )* "." { lineno++; goto yyc_rule; } | 299 | <rule> newline / ( newline | whitespace )* "." { lineno++; goto yyc_rule; } |
| 300 | <rule> "." @t1 keyword @t2 ( "(" @t3 ( string? | keyword ) @t4 ")" )? { | 300 | <rule> "." @t1 keyword @t2 ( "(" @t3 ( string? | keyword ) @t4 ")" )? { |
| 301 | if (!cond_res[0]) { goto yyc_rule; } | 301 | if (!cond_res[0]) { goto yyc_rule; } |
| 302 | if (kw_i == MAX_KEYWORDS) { | 302 | if (kw_i == MAX_KEYWORDS) { |
| 303 | cs_log_error("too many keywords in rule (more than %d) on line %d", MAX_KEYWORDS, lineno); | 303 | cs_log_error("too many keywords in rule (more than %d) on line %zu", MAX_KEYWORDS, lineno); |
| 304 | goto out; | 304 | goto out; |
| 305 | } | 305 | } |
| 306 | sp_parsed_keyword kw = { | 306 | sp_parsed_keyword kw = { |
| @@ -321,7 +321,7 @@ zend_result sp_config_scan(const char *data, zend_result (*process_rule)(sp_pars | |||
| 321 | } else { | 321 | } else { |
| 322 | zend_string *tmp = zend_hash_str_find_ptr(&vars, t3, t4-t3); | 322 | zend_string *tmp = zend_hash_str_find_ptr(&vars, t3, t4-t3); |
| 323 | if (!tmp) { | 323 | if (!tmp) { |
| 324 | cs_log_error("unknown variable on line %d", lineno); | 324 | cs_log_error("unknown variable on line %zu", lineno); |
| 325 | goto out; | 325 | goto out; |
| 326 | } | 326 | } |
| 327 | kw.arg = ZSTR_VAL(tmp); | 327 | kw.arg = ZSTR_VAL(tmp); |
diff --git a/src/sp_ini.c b/src/sp_ini.c index 8860a92..cfbc615 100644 --- a/src/sp_ini.c +++ b/src/sp_ini.c | |||
| @@ -97,7 +97,7 @@ static bool /* success */ sp_ini_check(zend_string *const restrict varname, zend | |||
| 97 | if (entry->msg) { | 97 | if (entry->msg) { |
| 98 | sp_log_ini_check_violation("%s", ZSTR_VAL(entry->msg)); | 98 | sp_log_ini_check_violation("%s", ZSTR_VAL(entry->msg)); |
| 99 | } else { | 99 | } else { |
| 100 | sp_log_ini_check_violation("INI value %lld for `%s` out of range", lvalue, ZSTR_VAL(entry->key)); | 100 | sp_log_ini_check_violation("INI value " ZEND_LONG_FMT " for `%s` out of range", lvalue, ZSTR_VAL(entry->key)); |
| 101 | } | 101 | } |
| 102 | return simulation; | 102 | return simulation; |
| 103 | } | 103 | } |
diff --git a/src/sp_utils.h b/src/sp_utils.h index 36caa52..1146db3 100644 --- a/src/sp_utils.h +++ b/src/sp_utils.h | |||
| @@ -71,6 +71,11 @@ extern int sp_debug_stderr; | |||
| 71 | #define GET_SUFFIX(x) (x == 1) ? "st" : ((x == 2) ? "nd" : "th") | 71 | #define GET_SUFFIX(x) (x == 1) ? "st" : ((x == 2) ? "nd" : "th") |
| 72 | 72 | ||
| 73 | const char *get_ipaddr(void); | 73 | const char *get_ipaddr(void); |
| 74 | #if defined __has_attribute | ||
| 75 | # if __has_attribute (__format__) | ||
| 76 | __attribute__((__format__(printf, 4, 5))) | ||
| 77 | # endif | ||
| 78 | #endif | ||
| 74 | void sp_log_msgf(char const* const restrict feature, int level, int type, char const* const restrict fmt, ...); | 79 | void sp_log_msgf(char const* const restrict feature, int level, int type, char const* const restrict fmt, ...); |
| 75 | int compute_hash(char const* const restrict filename, char *restrict file_hash); | 80 | int compute_hash(char const* const restrict filename, char *restrict file_hash); |
| 76 | const zend_string *sp_zval_to_zend_string(const zval *); | 81 | const zend_string *sp_zval_to_zend_string(const zval *); |
