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

macros: extract type information from MESSAGE, PROGRAM and HOST #162

Merged
merged 2 commits into from
Jun 21, 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
16 changes: 9 additions & 7 deletions lib/template/macros.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*
* Copyright (c) 2002-2014 Balabit
* Copyright (c) 1998-2014 Balázs Scheidler
* Copyright (c) 2024 Axoflow
* Copyright (c) 2024 Attila Szakacs <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -233,12 +235,12 @@ static struct timespec app_uptime;
static GHashTable *macro_hash;

static void
_result_append_value(GString *result, const LogMessage *lm, NVHandle handle)
_result_append_value(GString *result, const LogMessage *lm, NVHandle handle, LogMessageValueType *type)
{
const gchar *str;
gssize len = 0;

str = log_msg_get_value(lm, handle, &len);
str = log_msg_get_value_with_type(lm, handle, &len, type);
g_string_append_len(result, str, len);
}

Expand Down Expand Up @@ -530,7 +532,7 @@ log_macro_expand(gint id, LogTemplateEvalOptions *options, const LogMessage *msg
const gchar *p1, *p2;
int remaining, length;
gssize host_len;
const gchar *host = log_msg_get_value(msg, LM_V_HOST, &host_len);
const gchar *host = log_msg_get_value_with_type(msg, LM_V_HOST, &host_len, &t);

p1 = memchr(host, '@', host_len);

Expand All @@ -547,7 +549,7 @@ log_macro_expand(gint id, LogTemplateEvalOptions *options, const LogMessage *msg
}
else
{
_result_append_value(result, msg, LM_V_HOST);
_result_append_value(result, msg, LM_V_HOST, &t);
}
break;
}
Expand All @@ -561,14 +563,14 @@ log_macro_expand(gint id, LogTemplateEvalOptions *options, const LogMessage *msg
gssize len;
const gchar *p;

p = log_msg_get_value(msg, LM_V_LEGACY_MSGHDR, &len);
p = log_msg_get_value_with_type(msg, LM_V_LEGACY_MSGHDR, &len, &t);
if (len > 0)
g_string_append_len(result, p, len);
else
{
/* message, complete with program name and pid */
len = result->len;
_result_append_value(result, msg, LM_V_PROGRAM);
_result_append_value(result, msg, LM_V_PROGRAM, &t);
if (len != result->len)
{
const gchar *pid = log_msg_get_value(msg, LM_V_PID, &len);
Expand All @@ -585,7 +587,7 @@ log_macro_expand(gint id, LogTemplateEvalOptions *options, const LogMessage *msg
}
case M_MESSAGE:
{
_result_append_value(result, msg, LM_V_MESSAGE);
_result_append_value(result, msg, LM_V_MESSAGE, &t);
break;
}
case M_SOURCE_IP:
Expand Down
3 changes: 3 additions & 0 deletions news/bugfix-162.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
macros: Fixed a bug which always set certain macros to string type

The affected macros are `$PROGRAM`, `$HOST` and `$MESSAGE`.
Loading