Skip to content

Commit

Permalink
filterx: add support for isset() on attributes
Browse files Browse the repository at this point in the history
Signed-off-by: Balazs Scheidler <[email protected]>
  • Loading branch information
bazsi committed Jun 1, 2024
1 parent 587039a commit 173eb69
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/filterx/expr-getattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ _unset(FilterXExpr *s)
return result;
}

static gboolean
_isset(FilterXExpr *s)
{
FilterXGetAttr *self = (FilterXGetAttr *) s;
FilterXObject *variable = filterx_expr_eval_typed(self->operand);
if (!variable)
return FALSE;

gboolean result = filterx_object_is_key_set(variable, self->attr);

filterx_object_unref(variable);
return result;
}


static void
_free(FilterXExpr *s)
{
Expand All @@ -94,6 +109,7 @@ filterx_getattr_new(FilterXExpr *operand, const gchar *attr_name)
filterx_expr_init_instance(&self->super);
self->super.eval = _eval;
self->super.unset = _unset;
self->super.is_set = _isset;
self->super.free_fn = _free;
self->operand = operand;
self->attr = filterx_string_new(attr_name, -1);
Expand Down
1 change: 1 addition & 0 deletions tests/light/functional_tests/filterx/test_filterx.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,7 @@ def test_isset(config, syslog_ng):
isset(${values.int});
not isset($almafa);
isset($MSG["inner_key"]);
isset($MSG.inner_key);
not isset($MSG["almafa"]);
""",
)
Expand Down

0 comments on commit 173eb69

Please sign in to comment.