Skip to content

Commit

Permalink
Merge pull request #162 from alltilla/fix-macro-expansion-type
Browse files Browse the repository at this point in the history
macros: extract type information from MESSAGE, PROGRAM and HOST
  • Loading branch information
bazsi authored Jun 21, 2024
2 parents dfef041 + 5b6178e commit 0ef7af9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
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`.

0 comments on commit 0ef7af9

Please sign in to comment.