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

WIP: Filterx repl #279

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions lib/cfg-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
#include <stdlib.h>
#include "str-utils.h"

extern int main_debug;

/* defined in the parser */
int main_parse(CfgLexer *lexer, gpointer *dummy, gpointer arg);

Expand Down
1 change: 1 addition & 0 deletions lib/syslog-ng.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 12 additions & 0 deletions syslog-ng-fx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
17 changes: 17 additions & 0 deletions syslog-ng-fx/Makefile.am
Original file line number Diff line number Diff line change
@@ -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
65 changes: 65 additions & 0 deletions syslog-ng-fx/syslog-ng-fx.c
Original file line number Diff line number Diff line change
@@ -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, "<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;
}
4 changes: 0 additions & 4 deletions syslog-ng/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
Loading