diff --git a/Makefile.am b/Makefile.am index 137aff091a..d95895a98c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -41,6 +41,7 @@ EXTRA_DIST = $(filter-out ${NODIST_BUILT_SOURCES},${BUILT_SOURCES}) VERSION.txt cmake/syslog-ng.pc.cmake \ cmake/syslog-ng-native-connector.pc.cmake \ syslog-ng-ctl/CMakeLists.txt \ + syslog-ng-fx/CMakeLists.txt \ requirements.txt \ dev-requirements.txt \ optional-dev-requirements.txt \ @@ -260,6 +261,7 @@ include docker/Makefile.am include modules/Makefile.am include syslog-ng/Makefile.am include syslog-ng-ctl/Makefile.am +include syslog-ng-fx/Makefile.am include scripts/Makefile.am include tests/Makefile.am include doc/Makefile.am diff --git a/lib/cfg-parser.c b/lib/cfg-parser.c index 3656964704..9d10f7a3bb 100644 --- a/lib/cfg-parser.c +++ b/lib/cfg-parser.c @@ -30,8 +30,6 @@ #include #include "str-utils.h" -extern int main_debug; - /* defined in the parser */ int main_parse(CfgLexer *lexer, gpointer *dummy, gpointer arg); diff --git a/lib/syslog-ng.h b/lib/syslog-ng.h index 6928c3a382..de02bf892a 100644 --- a/lib/syslog-ng.h +++ b/lib/syslog-ng.h @@ -58,5 +58,6 @@ typedef struct _StatsClusterLabel StatsClusterLabel; /* configuration being parsed, used by the bison generated code, NULL whenever parsing is finished. */ extern GlobalConfig *configuration; +extern int cfg_parser_debug; #endif diff --git a/syslog-ng-fx/CMakeLists.txt b/syslog-ng-fx/CMakeLists.txt new file mode 100644 index 0000000000..a057587442 --- /dev/null +++ b/syslog-ng-fx/CMakeLists.txt @@ -0,0 +1,12 @@ +set(SYSLOG_NG_FX_SOURCES + syslog-ng-fx.c +) + +add_executable(syslog-ng-fx ${SYSLOG_NG_FX_SOURCES}) +target_link_libraries(syslog-ng-fx PRIVATE + syslog-ng + secret-storage + GLib::GLib + ${RESOLV_LIBS}) +target_include_directories(syslog-ng-fx PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) +install(TARGETS syslog-ng-fx RUNTIME DESTINATION sbin) diff --git a/syslog-ng-fx/Makefile.am b/syslog-ng-fx/Makefile.am new file mode 100644 index 0000000000..bd1fc11ced --- /dev/null +++ b/syslog-ng-fx/Makefile.am @@ -0,0 +1,17 @@ + + +bin_PROGRAMS += syslog-ng-fx/syslog-ng-fx + +syslog_ng_fx_syslog_ng_fx_SOURCES = \ + syslog-ng-fx/syslog-ng-fx.c + +syslog_ng_fx_syslog_ng_fx_LDADD = \ + $(MODULE_DEPS_LIBS) \ + $(TOOL_DEPS_LIBS) \ + $(top_builddir)/lib/secret-storage/libsecret-storage.la + +syslog_ng_fx_syslog_ng_fx_CPPFLAGS = \ + $(AM_CPPFLAGS) \ + -I$(top_srcdir)/syslog-ng-fx + +EXTRA_syslog_ng_fx_syslog_ng_fx_DEPENDENCIES = lib/libsyslog-ng.la lib/secret-storage/libsecret-storage.la diff --git a/syslog-ng-fx/syslog-ng-fx.c b/syslog-ng-fx/syslog-ng-fx.c new file mode 100644 index 0000000000..448f793534 --- /dev/null +++ b/syslog-ng-fx/syslog-ng-fx.c @@ -0,0 +1,65 @@ +#include "filterx/filterx-parser.h" +#include "resolved-configurable-paths.h" +#include "cfg.h" +#include "apphook.h" + +static gboolean display_version = FALSE; +static gboolean display_module_registry = FALSE; + +static GOptionEntry syslogng_fx_options[] = +{ + { "version", 'V', 0, G_OPTION_ARG_NONE, &display_version, "Display version number (" SYSLOG_NG_PACKAGE_NAME " " SYSLOG_NG_COMBINED_VERSION ")", NULL }, + { "module-path", 0, 0, G_OPTION_ARG_STRING, &resolved_configurable_paths.initial_module_path, "Set the list of colon separated directories to search for modules, default=" SYSLOG_NG_MODULE_PATH, "" }, + { "module-registry", 0, 0, G_OPTION_ARG_NONE, &display_module_registry, "Display module information", NULL }, +#ifdef YYDEBUG + { "yydebug", 'y', 0, G_OPTION_ARG_NONE, &cfg_parser_debug, "Enable configuration parser debugging", NULL }, +#endif + { NULL }, +}; + + + +int +main(int argc, char *argv[]) +{ + GOptionContext *ctx; + GError *error = NULL; + const gchar *text = "{ foo = 'bar'; }"; + gint res = 1; + + + ctx = g_option_context_new("syslog-ng-fx"); + g_option_context_add_main_entries(ctx, syslogng_fx_options, NULL); + if (!g_option_context_parse(ctx, &argc, &argv, &error)) + { + fprintf(stderr, "Error parsing command line arguments: %s\n", error ? error->message : "Invalid arguments"); + g_error_free(error); + g_option_context_free(ctx); + return 1; + } + g_option_context_free(ctx); + fprintf(stderr, "huhha\n"); + + + app_startup(); + configuration = cfg_new_snippet(); + CfgLexer *lexer = cfg_lexer_new_buffer(configuration, text, strlen(text)); + + configuration->lexer = lexer; + cfg_set_global_paths(configuration); + + gpointer result; + if (!cfg_parser_parse(&filterx_parser, lexer, &result, NULL)) + { + fprintf(stderr, "Error parsing filterx expression\n"); + goto exit; + } + + res = 0; + filterx_expr_unref(result); +exit: + cfg_free(configuration); + configuration = NULL; + app_shutdown(); + return res; +} diff --git a/syslog-ng/main.c b/syslog-ng/main.c index f0f8d2425f..0b53ad0f80 100644 --- a/syslog-ng/main.c +++ b/syslog-ng/main.c @@ -64,10 +64,6 @@ static gboolean dummy = FALSE; static MainLoopOptions main_loop_options; -#ifdef YYDEBUG -extern int cfg_parser_debug; -#endif - static GOptionEntry syslogng_options[] = { { "version", 'V', 0, G_OPTION_ARG_NONE, &display_version, "Display version number (" SYSLOG_NG_PACKAGE_NAME " " SYSLOG_NG_COMBINED_VERSION ")", NULL },