From 90d4ee087171e75d5313359ad6b6f1341e51ddc5 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Wed, 29 Aug 2018 16:23:27 +0200 Subject: JSON: Make match op mandatory, introduce 'in' operator This special operator is required for cases where missing operator does not lead to same results as equal operator, i.e. with bitmasks on RHS. Signed-off-by: Phil Sutter Signed-off-by: Pablo Neira Ayuso --- src/parser_json.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/parser_json.c') diff --git a/src/parser_json.c b/src/parser_json.c index 2f7e0a3e..6870434e 100644 --- a/src/parser_json.c +++ b/src/parser_json.c @@ -1363,24 +1363,24 @@ static struct stmt *json_parse_match_stmt(struct json_ctx *ctx, const char *opstr = NULL; enum ops op; - if (json_unpack_err(ctx, value, "{s:o, s:o}", + if (json_unpack_err(ctx, value, "{s:o, s:o, s:s}", "left", &jleft, - "right", &jright)) + "right", &jright, + "op", &opstr)) return NULL; - json_unpack(value, "{s:s}", "op", &opstr); - if (opstr) { - for (op = OP_INVALID; op < __OP_MAX; op++) { - if (expr_op_symbols[op] && - !strcmp(opstr, expr_op_symbols[op])) - break; - } - if (op == __OP_MAX) { + for (op = OP_INVALID; op < __OP_MAX; op++) { + if (expr_op_symbols[op] && + !strcmp(opstr, expr_op_symbols[op])) + break; + } + if (op == __OP_MAX) { + if (!strcmp(opstr, "in")) { + op = OP_IMPLICIT; + } else { json_error(ctx, "Unknown relational op '%s'.", opstr); return NULL; } - } else { - op = OP_IMPLICIT; } left = json_parse_expr(ctx, jleft); -- cgit v1.2.3