From 671f6f7538145b10c0a252940d27560b41297b86 Mon Sep 17 00:00:00 2001 From: Balazs Scheidler Date: Mon, 8 Apr 2024 15:02:31 +0200 Subject: [PATCH] filterx: implement isset/unset at FilterXGetSubscript Signed-off-by: Balazs Scheidler --- lib/filterx/expr-get-subscript.c | 47 ++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/lib/filterx/expr-get-subscript.c b/lib/filterx/expr-get-subscript.c index 269ef46dd88..3043cffad67 100644 --- a/lib/filterx/expr-get-subscript.c +++ b/lib/filterx/expr-get-subscript.c @@ -49,6 +49,51 @@ _eval(FilterXExpr *s) return result; } +static gboolean +_isset(FilterXExpr *s) +{ + FilterXGetSubscript *self = (FilterXGetSubscript *) s; + FilterXObject *variable = filterx_expr_eval_typed(self->operand); + if (!variable) + return FALSE; + + FilterXObject *key = filterx_expr_eval_typed(self->key); + if (!key) + { + filterx_object_unref(variable); + return FALSE; + } + + gboolean result = filterx_object_is_key_set(variable, key); + + filterx_object_unref(key); + filterx_object_unref(variable); + return result; +} + +static gboolean +_unset(FilterXExpr *s) +{ + FilterXGetSubscript *self = (FilterXGetSubscript *) s; + + FilterXObject *variable = filterx_expr_eval_typed(self->operand); + if (!variable) + return FALSE; + + FilterXObject *key = filterx_expr_eval_typed(self->key); + if (!key) + { + filterx_object_unref(variable); + return FALSE; + } + + gboolean result = filterx_object_unset_key(variable, key); + + filterx_object_unref(key); + filterx_object_unref(variable); + return result; +} + static void _free(FilterXExpr *s) { @@ -65,6 +110,8 @@ filterx_get_subscript_new(FilterXExpr *operand, FilterXExpr *key) filterx_expr_init_instance(&self->super); self->super.eval = _eval; + self->super.isset = _isset; + self->super.unset = _unset; self->super.free_fn = _free; self->operand = operand; self->key = key;