From dda13615393204c17f9b8941cfe4473a919e2d9d Mon Sep 17 00:00:00 2001 From: Balazs Scheidler Date: Sat, 11 May 2024 06:22:03 +0200 Subject: [PATCH 1/8] appmodel: add support for filterx expressions Signed-off-by: Balazs Scheidler --- modules/appmodel/app-parser-generator.c | 31 +++++++++++++++---- modules/appmodel/application.c | 8 +++++ modules/appmodel/application.h | 2 ++ modules/appmodel/appmodel-grammar.ym | 1 + .../tests/test_app_parser_generator.c | 4 +-- 5 files changed, 38 insertions(+), 8 deletions(-) diff --git a/modules/appmodel/app-parser-generator.c b/modules/appmodel/app-parser-generator.c index 26821d0c21..7dc64a7fed 100644 --- a/modules/appmodel/app-parser-generator.c +++ b/modules/appmodel/app-parser-generator.c @@ -98,18 +98,36 @@ _generate_parser(AppParserGenerator *self, const gchar *parser_expr) " };\n", parser_expr); } +static void +_generate_filterx(AppParserGenerator *self, const gchar *filterx_expr) +{ + if (filterx_expr) + g_string_append_printf(self->block, + " filterx {\n" + " %s\n" + " };\n", filterx_expr); +} + static void _generate_action(AppParserGenerator *self, Application *app) { - if (!self->allow_overlaps) - { - g_string_append_printf(self->block, + if (self->allow_overlaps) + return; + + if (app->filterx_expr) + g_string_append_printf(self->block, + " filterx {\n" + " meta.app_name = '%s';\n" + " };\n", + app->super.name); + + else + g_string_append_printf(self->block, " rewrite {\n" " set-tag('.app.%s');\n" " set('%s' value('.app.name'));\n" " };\n", app->super.name, app->super.name); - } } static void @@ -147,6 +165,7 @@ _generate_application(Application *app, gpointer user_data) _generate_filter(self, app->filter_expr); _generate_parser(self, app->parser_expr); + _generate_filterx(self, app->filterx_expr); _generate_action(self, app); g_string_append_printf(self->block, " #End Application %s\n", app->super.name); @@ -175,7 +194,7 @@ _generate_framing(AppParserGenerator *self, GlobalConfig *cfg) g_string_append(self->block, " channel {\n"); g_string_append(self->block, - " filter { tags('.app.doesnotexist'); };\n" + " filterx { false; };\n" " };\n"); } else @@ -190,7 +209,7 @@ _generate_framing(AppParserGenerator *self, GlobalConfig *cfg) static void _generate_empty_frame(AppParserGenerator *self) { - g_string_append(self->block, "channel { filter { tags('.app.doesnotexist'); }; };"); + g_string_append(self->block, "channel { filterx { false; }; };"); } void diff --git a/modules/appmodel/application.c b/modules/appmodel/application.c index 11b32ea20d..672ba4d8c9 100644 --- a/modules/appmodel/application.c +++ b/modules/appmodel/application.c @@ -37,12 +37,20 @@ application_set_parser(Application *self, const gchar *parser_expr) self->parser_expr = g_strdup(parser_expr); } +void +application_set_filterx(Application *self, const gchar *filterx_expr) +{ + g_free(self->filterx_expr); + self->filterx_expr = g_strdup(filterx_expr); +} + static void application_free(AppModelObject *s) { Application *self = (Application *) s; g_free(self->filter_expr); g_free(self->parser_expr); + g_free(self->filterx_expr); } Application * diff --git a/modules/appmodel/application.h b/modules/appmodel/application.h index c8dda0cf5a..944f6c63a0 100644 --- a/modules/appmodel/application.h +++ b/modules/appmodel/application.h @@ -33,10 +33,12 @@ typedef struct _Application AppModelObject super; gchar *filter_expr; gchar *parser_expr; + gchar *filterx_expr; } Application; void application_set_filter(Application *self, const gchar *filter_expr); void application_set_parser(Application *self, const gchar *parser_expr); +void application_set_filterx(Application *self, const gchar *parser_expr); Application *application_new(const gchar *name, const gchar *topic); diff --git a/modules/appmodel/appmodel-grammar.ym b/modules/appmodel/appmodel-grammar.ym index 90eb1ca045..928c29aee5 100644 --- a/modules/appmodel/appmodel-grammar.ym +++ b/modules/appmodel/appmodel-grammar.ym @@ -84,6 +84,7 @@ application_options application_option : KW_FILTER _block_content_context_push LL_BLOCK _block_content_context_pop { application_set_filter($0, $3); free($3); } | KW_PARSER _block_content_context_push LL_BLOCK _block_content_context_pop { application_set_parser($0, $3); free($3); } + | KW_FILTERX _block_content_context_push LL_BLOCK _block_content_context_pop { application_set_filterx($0, $3); free($3); } ; /* INCLUDE_RULES */ diff --git a/modules/appmodel/tests/test_app_parser_generator.c b/modules/appmodel/tests/test_app_parser_generator.c index 1fb7e81c60..b08e0eb881 100644 --- a/modules/appmodel/tests/test_app_parser_generator.c +++ b/modules/appmodel/tests/test_app_parser_generator.c @@ -201,7 +201,7 @@ Test(app_parser_generator, app_parser_with_no_apps_registered_generates_empty_fr { _app_parser_generate("port514"); _assert_parser_framing_is_present(); - _assert_snippet_is_present("tags('.app.doesnotexist')"); + _assert_snippet_is_present("filterx { false; }"); _assert_config_is_valid("port514", NULL); } @@ -223,7 +223,7 @@ Test(app_parser_generator, app_parser_is_disabled_if_auto_parse_is_set_to_no) _register_sample_application("bar", "port514"); _app_parser_generate_with_args("port514", _build_cfg_args("auto-parse", "no", NULL)); - _assert_snippet_is_present("tags('.app.doesnotexist')"); + _assert_snippet_is_present("filterx { false; }"); _app_parser_generate_with_args("port514", _build_cfg_args("auto-parse", "yes", NULL)); _assert_parser_framing_is_present(); From 70af8f764d8ed6bbf6c12e990c4ea2d3b48e0477 Mon Sep 17 00:00:00 2001 From: Balazs Scheidler Date: Wed, 25 Oct 2023 09:57:21 +0200 Subject: [PATCH 2/8] appmodel: add Transformation objects Signed-off-by: Balazs Scheidler --- modules/appmodel/Makefile.am | 2 + modules/appmodel/transformation.c | 92 +++++++++++++++++++++++++++++++ modules/appmodel/transformation.h | 59 ++++++++++++++++++++ 3 files changed, 153 insertions(+) create mode 100644 modules/appmodel/transformation.c create mode 100644 modules/appmodel/transformation.h diff --git a/modules/appmodel/Makefile.am b/modules/appmodel/Makefile.am index f87ac90a78..ab3003fe45 100644 --- a/modules/appmodel/Makefile.am +++ b/modules/appmodel/Makefile.am @@ -16,6 +16,8 @@ modules_appmodel_libappmodel_la_SOURCES = \ modules/appmodel/app-parser-generator.h \ modules/appmodel/application.c \ modules/appmodel/application.h \ + modules/appmodel/transformation.c \ + modules/appmodel/transformation.h \ modules/appmodel/appmodel-grammar.y modules_appmodel_libappmodel_la_CPPFLAGS = \ diff --git a/modules/appmodel/transformation.c b/modules/appmodel/transformation.c new file mode 100644 index 0000000000..2f6cc0c5cd --- /dev/null +++ b/modules/appmodel/transformation.c @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2023 Balázs Scheidler + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; 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 "transformation.h" + +/* TransformationStep: a named filterx expression */ + +TransformationStep * +transformation_step_new(const gchar *name, const gchar *expr) +{ + TransformationStep *self = g_new0(TransformationStep, 1); + self->name = g_strdup(name); + self->expr = g_strdup(expr); + return self; +} + +void +transformation_step_free(TransformationStep *self) +{ + g_free(self->name); + g_free(self->expr); +} + +/* TransformationBlock: named list of steps */ + +void +transformation_block_add_step(TransformationBlock *self, const gchar *name, const gchar *expr) +{ + self->steps = g_list_append(self->steps, transformation_step_new(name, expr)); +} + +TransformationBlock * +transformation_block_new(const gchar *name) +{ + TransformationBlock *self = g_new0(TransformationBlock, 1); + self->name = g_strdup(name); + return self; +} + +void +transformation_block_free(TransformationBlock *self) +{ + g_free(self->name); + g_list_free_full(self->steps, (GDestroyNotify) transformation_step_free); + g_free(self); +} + +/* Transformation */ +/* list of blocks */ + +void +transformation_add_block(Transformation *self, TransformationBlock *block) +{ + self->blocks = g_list_append(self->blocks, block); +} + +static void +transformation_free(AppModelObject *s) +{ + Transformation *self = (Transformation *) s; + + g_list_free_full(self->blocks, (GDestroyNotify) transformation_block_free); +} + +Transformation * +transformation_new(const gchar *app, const gchar *flavour) +{ + Transformation *self = g_new0(Transformation, 1); + + appmodel_object_init_instance(&self->super, TRANSFORMATION_TYPE_NAME, app, flavour); + self->super.free_fn = transformation_free; + return self; +} diff --git a/modules/appmodel/transformation.h b/modules/appmodel/transformation.h new file mode 100644 index 0000000000..07aa31cbda --- /dev/null +++ b/modules/appmodel/transformation.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2023 Balázs Scheidler + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; 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 APPMODEL_TRANSFORMATION_H_INCLUDED +#define APPMODEL_TRANSFORMATION_H_INCLUDED + +#include "appmodel-context.h" + +#define TRANSFORMATION_TYPE_NAME "transformation" + +typedef struct _TransformationStep +{ + gchar *name; + gchar *expr; +} TransformationStep; + +TransformationStep *transformation_step_new(const gchar *name, const gchar *expr); +void transformation_step_free(TransformationStep *self); + + +typedef struct _TransformationBlock +{ + gchar *name; + GList *steps; +} TransformationBlock; + +void transformation_block_add_step(TransformationBlock *self, const gchar *name, const gchar *step); +TransformationBlock *transformation_block_new(const gchar *name); +void transformation_block_free(TransformationBlock *self); + +typedef struct _Transformation +{ + AppModelObject super; + GList *blocks; +} Transformation; + +void transformation_add_block(Transformation *self, TransformationBlock *block); +Transformation *transformation_new(const gchar *app, const gchar *name); + +#endif From 40bd184a44c421f3bdb151a11a6ae01cd8567885 Mon Sep 17 00:00:00 2001 From: Balazs Scheidler Date: Sun, 22 Oct 2023 19:46:16 +0200 Subject: [PATCH 3/8] appmodel: add support for parsing Transformations Signed-off-by: Balazs Scheidler --- modules/appmodel/appmodel-grammar.ym | 49 ++++++++++++++++++++++++++++ modules/appmodel/appmodel-parser.c | 5 ++- modules/appmodel/appmodel-plugin.c | 5 +++ modules/appmodel/appmodel.c | 15 +++++++++ modules/appmodel/appmodel.h | 4 +++ 5 files changed, 77 insertions(+), 1 deletion(-) diff --git a/modules/appmodel/appmodel-grammar.ym b/modules/appmodel/appmodel-grammar.ym index 928c29aee5..d368c9c33c 100644 --- a/modules/appmodel/appmodel-grammar.ym +++ b/modules/appmodel/appmodel-grammar.ym @@ -48,8 +48,12 @@ /* INCLUDE_DECLS */ %token KW_APPLICATION +%token KW_TRANSFORMATION +%token KW_TRANSFORM +%token KW_STEP %type application_definition +%type transformation_definition %% @@ -60,6 +64,12 @@ start *instance = $2; YYACCEPT; } + | LL_CONTEXT_ROOT transformation_definition + { + appmodel_register_transformation(configuration, $2); + *instance = $2; + YYACCEPT; + } ; @@ -87,6 +97,45 @@ application_option | KW_FILTERX _block_content_context_push LL_BLOCK _block_content_context_pop { application_set_filterx($0, $3); free($3); } ; + +transformation_definition + : KW_TRANSFORMATION string '[' string ']' + { + $$ = transformation_new($2, $4); + }[transformation] + '{' { $$ = $transformation; } transformation_options '}' + { + $$ = $transformation; + free($2); + free($4); + } + ; + +transformation_options + : transformation_option semicolons { $$ = $0; } transformation_options + | + ; + +/* $0 is Transformation */ +transformation_option + : KW_TRANSFORM '[' string ']' '{' { $$ = transformation_block_new($3); } transformation_steps '}' + { free($3); transformation_add_block($0, $6); } + ; + +/* $0 is TransformationBlock */ +transformation_steps + : transformation_step semicolons { $$ = $0; } transformation_steps + | + ; + +/* $0 is TransformationBlock */ +transformation_step + : KW_STEP '[' string ']' _block_content_context_push LL_BLOCK _block_content_context_pop + { + transformation_block_add_step($0, $3, $6); free($3); free($6); + } + ; + /* INCLUDE_RULES */ %% diff --git a/modules/appmodel/appmodel-parser.c b/modules/appmodel/appmodel-parser.c index c72c14edbc..29310fc6b8 100644 --- a/modules/appmodel/appmodel-parser.c +++ b/modules/appmodel/appmodel-parser.c @@ -31,7 +31,10 @@ int appmodel_parse(CfgLexer *lexer, gpointer *instance, gpointer arg); static CfgLexerKeyword appmodel_keywords[] = { - { "application", KW_APPLICATION }, + { "application", KW_APPLICATION }, + { "transformation", KW_TRANSFORMATION }, + { "transform", KW_TRANSFORM }, + { "step", KW_STEP }, { NULL } }; diff --git a/modules/appmodel/appmodel-plugin.c b/modules/appmodel/appmodel-plugin.c index 7bd8692261..03ed0d2f59 100644 --- a/modules/appmodel/appmodel-plugin.c +++ b/modules/appmodel/appmodel-plugin.c @@ -43,6 +43,11 @@ static Plugin appmodel_plugins[] = .name = "application", .parser = &appmodel_parser, }, + { + .type = LL_CONTEXT_ROOT, + .name = "transformation", + .parser = &appmodel_parser, + }, { .type = LL_CONTEXT_PARSER | LL_CONTEXT_FLAG_GENERATOR, .name = "app-parser", diff --git a/modules/appmodel/appmodel.c b/modules/appmodel/appmodel.c index e94aea1368..4118143d4f 100644 --- a/modules/appmodel/appmodel.c +++ b/modules/appmodel/appmodel.c @@ -53,3 +53,18 @@ appmodel_iter_applications(GlobalConfig *cfg, void (*foreach)(Application *app, AppModelContext *appmodel = appmodel_get_context(cfg); appmodel_context_iter_objects(appmodel, APPLICATION_TYPE_NAME, (AppModelContextIterFunc) foreach, user_data); } + +void +appmodel_register_transformation(GlobalConfig *cfg, Transformation *transformation) +{ + AppModelContext *ac = appmodel_get_context(cfg); + + appmodel_context_register_object(ac, &transformation->super); +} + +void +appmodel_iter_transformations(GlobalConfig *cfg, void (*foreach)(Transformation *transformation, gpointer user_data), gpointer user_data) +{ + AppModelContext *appmodel = appmodel_get_context(cfg); + appmodel_context_iter_objects(appmodel, TRANSFORMATION_TYPE_NAME, (AppModelContextIterFunc) foreach, user_data); +} diff --git a/modules/appmodel/appmodel.h b/modules/appmodel/appmodel.h index 34b0f3dd7e..2b8aca7a43 100644 --- a/modules/appmodel/appmodel.h +++ b/modules/appmodel/appmodel.h @@ -25,6 +25,7 @@ #include "module-config.h" #include "application.h" +#include "transformation.h" AppModelContext *appmodel_get_context(GlobalConfig *cfg); void appmodel_register_application(GlobalConfig *cfg, Application *application); @@ -32,4 +33,7 @@ void appmodel_iter_applications(GlobalConfig *cfg, void (*foreach)(Application *app, gpointer user_data), gpointer user_data); +void appmodel_register_transformation(GlobalConfig *cfg, Transformation *transformation); +void appmodel_iter_transformations(GlobalConfig *cfg, void (*foreach)(Transformation *transformation, gpointer user_data), gpointer user_data); + #endif From 3e29428040ec106488c2b3fb26e30198b836bed3 Mon Sep 17 00:00:00 2001 From: Balazs Scheidler Date: Wed, 25 Oct 2023 09:57:40 +0200 Subject: [PATCH 4/8] appmodel: add app-transform() parser Signed-off-by: Balazs Scheidler --- modules/appmodel/CMakeLists.txt | 1 + modules/appmodel/Makefile.am | 2 + modules/appmodel/app-parser-generator.h | 4 +- modules/appmodel/app-transform-generator.c | 121 +++++++++++++++++++++ modules/appmodel/app-transform-generator.h | 32 ++++++ modules/appmodel/appmodel-plugin.c | 13 +++ 6 files changed, 171 insertions(+), 2 deletions(-) create mode 100644 modules/appmodel/app-transform-generator.c create mode 100644 modules/appmodel/app-transform-generator.h diff --git a/modules/appmodel/CMakeLists.txt b/modules/appmodel/CMakeLists.txt index 2bb5efe5d1..9365a9fc51 100644 --- a/modules/appmodel/CMakeLists.txt +++ b/modules/appmodel/CMakeLists.txt @@ -11,6 +11,7 @@ set (APPMODEL_SOURCES appmodel-context.c app-object-generator.c app-parser-generator.c + app-transform-generator.c application.c ) diff --git a/modules/appmodel/Makefile.am b/modules/appmodel/Makefile.am index ab3003fe45..5405ef2bb9 100644 --- a/modules/appmodel/Makefile.am +++ b/modules/appmodel/Makefile.am @@ -14,6 +14,8 @@ modules_appmodel_libappmodel_la_SOURCES = \ modules/appmodel/app-object-generator.h \ modules/appmodel/app-parser-generator.c \ modules/appmodel/app-parser-generator.h \ + modules/appmodel/app-transform-generator.c \ + modules/appmodel/app-transform-generator.h \ modules/appmodel/application.c \ modules/appmodel/application.h \ modules/appmodel/transformation.c \ diff --git a/modules/appmodel/app-parser-generator.h b/modules/appmodel/app-parser-generator.h index ea45d5e468..d3b78157be 100644 --- a/modules/appmodel/app-parser-generator.h +++ b/modules/appmodel/app-parser-generator.h @@ -22,8 +22,8 @@ * */ -#ifndef APPMODEL_APPPARSER_GENERATOR_H_INCLUDED -#define APPMODEL_APPPARSER_GENERATOR_H_INCLUDED +#ifndef APPMODEL_APP_PARSER_GENERATOR_H_INCLUDED +#define APPMODEL_APP_PARSER_GENERATOR_H_INCLUDED #include "plugin.h" diff --git a/modules/appmodel/app-transform-generator.c b/modules/appmodel/app-transform-generator.c new file mode 100644 index 0000000000..c3e829df7d --- /dev/null +++ b/modules/appmodel/app-transform-generator.c @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2024 Balazs Scheidler + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; 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 "app-object-generator.h" +#include "appmodel.h" + +/* app-transform() */ + +typedef struct _AppTransformGenerator +{ + AppObjectGenerator super; + const gchar *flavour; + GString *block; +} AppTransformGenerator; + +static gboolean +_parse_transforms_arg(AppTransformGenerator *self, CfgArgs *args, const gchar *reference) +{ + self->flavour = cfg_args_get(args, "flavour"); + if (!self->flavour) + self->flavour = "default"; + return TRUE; +} + +static gboolean +app_transform_generator_parse_arguments(AppObjectGenerator *s, CfgArgs *args, const gchar *reference) +{ + AppTransformGenerator *self = (AppTransformGenerator *) s; + g_assert(args != NULL); + + if (!_parse_transforms_arg(self, args, reference)) + return FALSE; + + if (!app_object_generator_parse_arguments_method(&self->super, args, reference)) + return FALSE; + + return TRUE; +} + +static void +_generate_steps(AppTransformGenerator *self, GList *steps) +{ + for (GList *l = steps; l; l = l->next) + { + TransformationStep *step = l->data; + g_string_append_printf(self->block, " # step: %s", step->name); + g_string_append_printf(self->block, " %s\n", step->expr); + } +} + +static void +_generate_app_transform(Transformation *transformation, gpointer user_data) +{ + AppTransformGenerator *self = (AppTransformGenerator *) user_data; + + if (strcmp(transformation->super.instance, self->flavour) != 0) + return; + + if (!app_object_generator_is_application_included(&self->super, transformation->super.name)) + return; + + if (app_object_generator_is_application_excluded(&self->super, transformation->super.name)) + return; + + g_string_append_printf(self->block, "\n#Start Application %s\n", transformation->super.name); + g_string_append_printf(self->block, " if (meta.app_name == '%s') {\n", transformation->super.name); + for (GList *l = transformation->blocks; l; l = l->next) + { + TransformationBlock *block = l->data; + + _generate_steps(self, block->steps); + } + g_string_append(self->block, " };\n"); + g_string_append_printf(self->block, "\n#End Application %s\n", transformation->super.name); +} + + +static void +app_transform_generate_config(AppObjectGenerator *s, GlobalConfig *cfg, GString *result) +{ + AppTransformGenerator *self = (AppTransformGenerator *) s; + + self->block = result; + g_string_append_printf(result, "## app-transform(flavour(%s))\n" + "channel {\n" + " filterx {\n", self->flavour); + appmodel_iter_transformations(cfg, _generate_app_transform, self); + g_string_append(result, " };\n" + "}"); + self->block = NULL; +} + +CfgBlockGenerator * +app_transform_generator_new(gint context, const gchar *name) +{ + AppTransformGenerator *self = g_new0(AppTransformGenerator, 1); + + app_object_generator_init_instance(&self->super, context, name); + self->super.parse_arguments = app_transform_generator_parse_arguments; + self->super.generate_config = app_transform_generate_config; + return &self->super.super; +} diff --git a/modules/appmodel/app-transform-generator.h b/modules/appmodel/app-transform-generator.h new file mode 100644 index 0000000000..61db093465 --- /dev/null +++ b/modules/appmodel/app-transform-generator.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2017 Balabit + * Copyright (c) 2017 Balazs Scheidler + * + * 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 APPMODEL_APP_TRANSFORM_GENERATOR_H_INCLUDED +#define APPMODEL_APP_TRANSFORM_GENERATOR_H_INCLUDED + +#include "plugin.h" + +CfgBlockGenerator *app_transform_generator_new(gint context, const gchar *name); + +#endif diff --git a/modules/appmodel/appmodel-plugin.c b/modules/appmodel/appmodel-plugin.c index 03ed0d2f59..30ba1cbb47 100644 --- a/modules/appmodel/appmodel-plugin.c +++ b/modules/appmodel/appmodel-plugin.c @@ -24,6 +24,7 @@ #include "cfg-parser.h" #include "appmodel-parser.h" #include "app-parser-generator.h" +#include "app-transform-generator.h" #include "block-ref-parser.h" #include "plugin.h" #include "plugin-types.h" @@ -36,6 +37,12 @@ app_parser_construct(Plugin *p) return app_parser_generator_new(p->type, p->name); } +static gpointer +app_transform_construct(Plugin *p) +{ + return app_transform_generator_new(p->type, p->name); +} + static Plugin appmodel_plugins[] = { { @@ -53,6 +60,12 @@ static Plugin appmodel_plugins[] = .name = "app-parser", .construct = app_parser_construct, .parser = &block_ref_parser + }, + { + .type = LL_CONTEXT_PARSER | LL_CONTEXT_FLAG_GENERATOR, + .name = "app-transform", + .construct = app_transform_construct, + .parser = &block_ref_parser } }; From 1f6e5bada53bc09c4d9169d68780fcc981bbf1a3 Mon Sep 17 00:00:00 2001 From: Balazs Scheidler Date: Wed, 22 May 2024 12:23:07 +0200 Subject: [PATCH 5/8] appmodel: convert app-parser-generator to the GPL license This was filed incorrectly when implemented back in 2017. LGPL allows us to convert LGPL to GPL (Terms, Section 3), please see the details below. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. Signed-off-by: Balazs Scheidler --- modules/appmodel/app-parser-generator.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/appmodel/app-parser-generator.c b/modules/appmodel/app-parser-generator.c index 7dc64a7fed..5b86e95dcd 100644 --- a/modules/appmodel/app-parser-generator.c +++ b/modules/appmodel/app-parser-generator.c @@ -1,19 +1,19 @@ /* * Copyright (c) 2017 Balabit * Copyright (c) 2017 Balazs Scheidler + * Copyright (c) 2024 Balazs Scheidler * - * 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 program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation, or (at your option) any later version. * - * This library is distributed in the hope that it will be useful, + * This program 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. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU 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 + * You should have received a copy of the GNU General Public License + * along with this program; 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 From 71e3e155791a13c87b808d4db7ef8d2df106af10 Mon Sep 17 00:00:00 2001 From: Attila Szakacs Date: Tue, 21 May 2024 13:26:21 +0200 Subject: [PATCH 6/8] appmodel: fix license of new files Signed-off-by: Attila Szakacs --- modules/appmodel/app-transform-generator.h | 20 +++++++++----------- tests/copyright/policy | 2 ++ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/appmodel/app-transform-generator.h b/modules/appmodel/app-transform-generator.h index 61db093465..404ec2dfc9 100644 --- a/modules/appmodel/app-transform-generator.h +++ b/modules/appmodel/app-transform-generator.h @@ -1,19 +1,17 @@ /* - * Copyright (c) 2017 Balabit - * Copyright (c) 2017 Balazs Scheidler + * Copyright (c) 2024 Balazs Scheidler * - * 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 program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation, or (at your option) any later version. * - * This library is distributed in the hope that it will be useful, + * This program 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. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU 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 + * You should have received a copy of the GNU General Public License + * along with this program; 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 diff --git a/tests/copyright/policy b/tests/copyright/policy index 7322fef8df..cf7424a871 100644 --- a/tests/copyright/policy +++ b/tests/copyright/policy @@ -272,6 +272,8 @@ modules/kvformat/filterx-func-parse-kv\.[ch] modules/kvformat/filterx-func-format-kv\.[ch] modules/kvformat/tests/test_filterx_func_parse_kv.c modules/kvformat/tests/test_filterx_func_format_kv.c +modules/appmodel/app-transform-generator\.[ch]$ +modules/appmodel/transformation\.[ch]$ docker/python-modules/webhook/scl/webhook.conf docker/python-modules/webhook/source.py packaging/package-indexer/remote_storage_synchronizer/s3_bucket_synchronizer.py From 97135f22a85b05871c672da6e84c92a3e23eb5a2 Mon Sep 17 00:00:00 2001 From: Attila Szakacs Date: Tue, 21 May 2024 13:22:49 +0200 Subject: [PATCH 7/8] appmodel: add missing source to CMakeLists Signed-off-by: Attila Szakacs --- modules/appmodel/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/appmodel/CMakeLists.txt b/modules/appmodel/CMakeLists.txt index 9365a9fc51..fee01a875c 100644 --- a/modules/appmodel/CMakeLists.txt +++ b/modules/appmodel/CMakeLists.txt @@ -13,6 +13,7 @@ set (APPMODEL_SOURCES app-parser-generator.c app-transform-generator.c application.c + transformation.c ) add_module( From ebccc0d95f87bc2f9062ca55c5b071a6e6c4af35 Mon Sep 17 00:00:00 2001 From: Attila Szakacs Date: Wed, 22 May 2024 14:23:57 +0200 Subject: [PATCH 8/8] appmodel: style format fix Signed-off-by: Attila Szakacs --- modules/appmodel/app-parser-generator.c | 18 +++++++++--------- modules/appmodel/app-transform-generator.c | 6 +++--- modules/appmodel/appmodel.c | 3 ++- modules/appmodel/appmodel.h | 3 ++- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/modules/appmodel/app-parser-generator.c b/modules/appmodel/app-parser-generator.c index 5b86e95dcd..0fd1958cf6 100644 --- a/modules/appmodel/app-parser-generator.c +++ b/modules/appmodel/app-parser-generator.c @@ -116,18 +116,18 @@ _generate_action(AppParserGenerator *self, Application *app) if (app->filterx_expr) g_string_append_printf(self->block, - " filterx {\n" - " meta.app_name = '%s';\n" - " };\n", - app->super.name); + " filterx {\n" + " meta.app_name = '%s';\n" + " };\n", + app->super.name); else g_string_append_printf(self->block, - " rewrite {\n" - " set-tag('.app.%s');\n" - " set('%s' value('.app.name'));\n" - " };\n", - app->super.name, app->super.name); + " rewrite {\n" + " set-tag('.app.%s');\n" + " set('%s' value('.app.name'));\n" + " };\n", + app->super.name, app->super.name); } static void diff --git a/modules/appmodel/app-transform-generator.c b/modules/appmodel/app-transform-generator.c index c3e829df7d..7c04a2cb61 100644 --- a/modules/appmodel/app-transform-generator.c +++ b/modules/appmodel/app-transform-generator.c @@ -101,11 +101,11 @@ app_transform_generate_config(AppObjectGenerator *s, GlobalConfig *cfg, GString self->block = result; g_string_append_printf(result, "## app-transform(flavour(%s))\n" - "channel {\n" - " filterx {\n", self->flavour); + "channel {\n" + " filterx {\n", self->flavour); appmodel_iter_transformations(cfg, _generate_app_transform, self); g_string_append(result, " };\n" - "}"); + "}"); self->block = NULL; } diff --git a/modules/appmodel/appmodel.c b/modules/appmodel/appmodel.c index 4118143d4f..dab106ac52 100644 --- a/modules/appmodel/appmodel.c +++ b/modules/appmodel/appmodel.c @@ -63,7 +63,8 @@ appmodel_register_transformation(GlobalConfig *cfg, Transformation *transformati } void -appmodel_iter_transformations(GlobalConfig *cfg, void (*foreach)(Transformation *transformation, gpointer user_data), gpointer user_data) +appmodel_iter_transformations(GlobalConfig *cfg, void (*foreach)(Transformation *transformation, gpointer user_data), + gpointer user_data) { AppModelContext *appmodel = appmodel_get_context(cfg); appmodel_context_iter_objects(appmodel, TRANSFORMATION_TYPE_NAME, (AppModelContextIterFunc) foreach, user_data); diff --git a/modules/appmodel/appmodel.h b/modules/appmodel/appmodel.h index 2b8aca7a43..f017f63bba 100644 --- a/modules/appmodel/appmodel.h +++ b/modules/appmodel/appmodel.h @@ -34,6 +34,7 @@ void appmodel_iter_applications(GlobalConfig *cfg, gpointer user_data); void appmodel_register_transformation(GlobalConfig *cfg, Transformation *transformation); -void appmodel_iter_transformations(GlobalConfig *cfg, void (*foreach)(Transformation *transformation, gpointer user_data), gpointer user_data); +void appmodel_iter_transformations(GlobalConfig *cfg, void (*foreach)(Transformation *transformation, + gpointer user_data), gpointer user_data); #endif