Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filterx: rework of unset_empties #275

Merged
merged 6 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/filterx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ set(FILTERX_HEADERS
filterx/expr-plus.h
filterx/expr-null-coalesce.h
filterx/expr-plus-generator.h
filterx/func-flags.h
PARENT_SCOPE
)

Expand Down
3 changes: 2 additions & 1 deletion lib/filterx/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ filterxinclude_HEADERS = \
lib/filterx/func-sdata.h \
lib/filterx/filterx-private.h \
lib/filterx/expr-null-coalesce.h \
lib/filterx/expr-plus-generator.h
lib/filterx/expr-plus-generator.h \
lib/filterx/func-flags.h


filterx_sources = \
Expand Down
31 changes: 29 additions & 2 deletions lib/filterx/expr-literal-generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,16 +289,43 @@ filterx_literal_inner_list_generator_new(FilterXExpr *root_literal_generator, GL
return &self->super;
}

gboolean
_filterx_expr_is_inner_dict_generator(FilterXExpr *s)
{
return s && (s->eval == _inner_dict_generator_eval);
}

gboolean
_filterx_expr_is_inner_list_generator(FilterXExpr *s)
{
return s && (s->eval == _inner_list_generator_eval);
}

gboolean
filterx_expr_is_literal_dict_generator(FilterXExpr *s)
{
FilterXExprGenerator *generator = (FilterXExprGenerator *) s;
return filterx_expr_is_generator(s) && generator->create_container == filterx_generator_create_dict_container;
return (filterx_expr_is_generator(s) && generator->create_container == filterx_generator_create_dict_container)
|| _filterx_expr_is_inner_dict_generator(s);
}

gboolean
filterx_expr_is_literal_list_generator(FilterXExpr *s)
{
FilterXExprGenerator *generator = (FilterXExprGenerator *) s;
return filterx_expr_is_generator(s) && generator->create_container == filterx_generator_create_list_container;
return (filterx_expr_is_generator(s) && generator->create_container == filterx_generator_create_list_container)
|| _filterx_expr_is_inner_list_generator(s);
}

gboolean
filterx_expr_is_literal_generator(FilterXExpr *s)
{
return filterx_expr_is_literal_list_generator(s) || filterx_expr_is_literal_dict_generator(s);
}

guint
filterx_expr_literal_generator_len(FilterXExpr *s)
MrAnno marked this conversation as resolved.
Show resolved Hide resolved
{
FilterXExprLiteralGenerator *self = (FilterXExprLiteralGenerator *) s;
return g_list_length(self->elements);
}
3 changes: 3 additions & 0 deletions lib/filterx/expr-literal-generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@ FilterXExpr *filterx_literal_inner_list_generator_new(FilterXExpr *root_literal_
gboolean filterx_expr_is_literal_dict_generator(FilterXExpr *s);
gboolean filterx_expr_is_literal_list_generator(FilterXExpr *s);

guint filterx_expr_literal_generator_len(FilterXExpr *s);
gboolean filterx_expr_is_literal_generator(FilterXExpr *s);

#endif
76 changes: 76 additions & 0 deletions lib/filterx/func-flags.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (c) 2023 Axoflow
* Copyright (c) 2024 shifter
*
* 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 FUNC_FLAGS_H
#define FUNC_FLAGS_H

#include "syslog-ng.h"

#define MAX_ENUMS 64

#define STATIC_ASSERT(COND) G_STATIC_ASSERT(COND)

#define DEFINE_FUNC_FLAGS(ENUM_NAME, ...) \
typedef enum { __VA_ARGS__, ENUM_NAME##_MAX} ENUM_NAME; \
STATIC_ASSERT(ENUM_NAME##_MAX <= MAX_ENUMS) \

#define FUNC_FLAGS_ITER(ENUM_NAME, CODE) for (guint64 enum_elt = 0; enum_elt < ENUM_NAME##_MAX; enum_elt++) { CODE; };

#define FLAG_VAL(ID) (1 << ID)

#define ALL_FLAG_SET(ENUM_NAME) (FLAG_VAL(ENUM_NAME##_MAX) - 1)

static inline void
set_flag(guint64 *flags, guint64 flag, gboolean val)
{
if (val)
{
*flags |= FLAG_VAL(flag);
}
else
{
*flags &= ~FLAG_VAL(flag);
}
}

static inline gboolean
check_flag(guint64 flags, guint64 flag)
{
return (flags & FLAG_VAL(flag)) != 0;
}

static inline void
reset_flags(guint64 *flags, guint64 val)
{
*flags = val;
}

static inline gboolean
toggle_flag(guint64 *flags, guint64 flag)
{
*flags ^= FLAG_VAL(flag);
return (*flags & FLAG_VAL(flag)) != 0;
}

#endif
Loading
Loading