Skip to content

Commit

Permalink
filterx: add expr-isset and expr-unset
Browse files Browse the repository at this point in the history
Signed-off-by: Attila Szakacs <[email protected]>
  • Loading branch information
alltilla authored and bazsi committed Apr 9, 2024
1 parent d7d8077 commit 13a7a7e
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/filterx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ set(FILTERX_HEADERS
filterx/object-list-interface.h
filterx/object-dict-interface.h
filterx/expr-condition.h
filterx/expr-isset.h
filterx/expr-unset.h
filterx/filterx-globals-tests.h
PARENT_SCOPE
)
Expand Down Expand Up @@ -69,6 +71,8 @@ set(FILTERX_SOURCES
filterx/object-list-interface.c
filterx/object-dict-interface.c
filterx/expr-condition.c
filterx/expr-isset.c
filterx/expr-unset.c
PARENT_SCOPE
)

Expand Down
4 changes: 4 additions & 0 deletions lib/filterx/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ filterxinclude_HEADERS = \
lib/filterx/filterx-pipe.h \
lib/filterx/expr-function.h \
lib/filterx/expr-condition.h \
lib/filterx/expr-isset.h \
lib/filterx/expr-unset.h \
lib/filterx/filterx-globals-tests.h


Expand Down Expand Up @@ -70,6 +72,8 @@ filterx_sources = \
lib/filterx/filterx-pipe.c \
lib/filterx/expr-function.c \
lib/filterx/expr-condition.c \
lib/filterx/expr-isset.c \
lib/filterx/expr-unset.c \
lib/filterx/filterx-grammar.y

BUILT_SOURCES += \
Expand Down
42 changes: 42 additions & 0 deletions lib/filterx/expr-isset.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2024 Attila Szakacs
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As an additional exemption you are allowed to compile & link against the
* OpenSSL libraries as published by the OpenSSL project. See the file
* COPYING for details.
*
*/

#include "filterx/expr-isset.h"
#include "filterx/object-primitive.h"

FilterXObject *
_eval(FilterXExpr *s)
{
FilterXUnaryOp *self = (FilterXUnaryOp *) s;

return filterx_boolean_new(filterx_expr_isset(self->operand));
}

FilterXExpr *
filterx_isset_new(FilterXExpr *expr)
{
FilterXUnaryOp *self = g_new0(FilterXUnaryOp, 1);
filterx_unary_op_init_instance(self, expr);
self->super.eval = _eval;
return &self->super;
}
30 changes: 30 additions & 0 deletions lib/filterx/expr-isset.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2024 Attila Szakacs
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As an additional exemption you are allowed to compile & link against the
* OpenSSL libraries as published by the OpenSSL project. See the file
* COPYING for details.
*
*/
#ifndef FILTERX_IS_KEY_SET_H_INCLUDED
#define FILTERX_IS_KEY_SET_H_INCLUDED

#include "filterx/filterx-expr.h"

FilterXExpr *filterx_isset_new(FilterXExpr *expr);

#endif
44 changes: 44 additions & 0 deletions lib/filterx/expr-unset.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2024 Attila Szakacs
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As an additional exemption you are allowed to compile & link against the
* OpenSSL libraries as published by the OpenSSL project. See the file
* COPYING for details.
*
*/

#include "filterx/expr-unset.h"
#include "filterx/object-primitive.h"

FilterXObject *
_eval(FilterXExpr *s)
{
FilterXUnaryOp *self = (FilterXUnaryOp *) s;

if (!filterx_expr_unset(self->operand))
return NULL;
return filterx_boolean_new(TRUE);
}

FilterXExpr *
filterx_unset_new(FilterXExpr *expr)
{
FilterXUnaryOp *self = g_new0(FilterXUnaryOp, 1);
filterx_unary_op_init_instance(self, expr);
self->super.eval = _eval;
return &self->super;
}
30 changes: 30 additions & 0 deletions lib/filterx/expr-unset.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2024 Attila Szakacs
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As an additional exemption you are allowed to compile & link against the
* OpenSSL libraries as published by the OpenSSL project. See the file
* COPYING for details.
*
*/
#ifndef FILTERX_UNSET_KEY_H_INCLUDED
#define FILTERX_UNSET_KEY_H_INCLUDED

#include "filterx/filterx-expr.h"

FilterXExpr *filterx_unset_new(FilterXExpr *expr);

#endif

0 comments on commit 13a7a7e

Please sign in to comment.