[syslog-ng] [PATCH 2/6] value-pairs: Change value_pairs_add_pair() to take a LogTemplate
Gergely Nagy
algernon at balabit.hu
Wed Sep 4 14:35:28 CEST 2013
Instead of taking a string and compiling the template ourselves, take a
LogTemplate instance instead.
Signed-off-by: Balazs Scheidler <bazsi at balabit.hu>
Signed-off-by: Gergely Nagy <algernon at balabit.hu>
---
lib/cfg-grammar.y | 12 ++++++++++--
lib/value-pairs.c | 27 +++++++++++++++++----------
lib/value-pairs.h | 7 ++++---
3 files changed, 31 insertions(+), 15 deletions(-)
diff --git a/lib/cfg-grammar.y b/lib/cfg-grammar.y
index dc21f05..41830f5 100644
--- a/lib/cfg-grammar.y
+++ b/lib/cfg-grammar.y
@@ -1101,8 +1101,16 @@ vp_options
;
vp_option
- : KW_PAIR '(' string ':' string ')' { value_pairs_add_pair(last_value_pairs, configuration, $3, $5); free($3); free($5); }
- | KW_PAIR '(' string string ')' { value_pairs_add_pair(last_value_pairs, configuration, $3, $4); free($3); free($4); }
+ : KW_PAIR '(' string ':' template_content ')'
+ {
+ value_pairs_add_pair(last_value_pairs, $3, $5);
+ free($3);
+ }
+ | KW_PAIR '(' string template_content ')'
+ {
+ value_pairs_add_pair(last_value_pairs, $3, $4);
+ free($3);
+ }
| KW_KEY '(' string KW_REKEY '('
{
last_vp_transset = value_pairs_transform_set_new($3);
diff --git a/lib/value-pairs.c b/lib/value-pairs.c
index ca76fd8..5fb3e8d 100644
--- a/lib/value-pairs.c
+++ b/lib/value-pairs.c
@@ -151,16 +151,15 @@ value_pairs_add_glob_pattern(ValuePairs *vp, const gchar *pattern,
vp->patterns[i] = p;
}
-void
-value_pairs_add_pair(ValuePairs *vp, GlobalConfig *cfg, const gchar *key, const gchar *value)
+gboolean
+value_pairs_add_pair(ValuePairs *vp, const gchar *key, LogTemplate *value)
{
VPPairConf *p = g_new(VPPairConf, 1);
p->name = g_strdup(key);
- p->template = log_template_new(cfg, NULL);
- log_template_compile(p->template, value, NULL);
-
+ p->template = log_template_ref(value);
g_ptr_array_add(vp->vpairs, p);
+ return TRUE;
}
static gchar *
@@ -739,6 +738,8 @@ vp_cmdline_parse_pair (const gchar *option_name, const gchar *value,
ValuePairs *vp = (ValuePairs *) args[1];
GlobalConfig *cfg = (GlobalConfig *) args[0];
gchar **kv;
+ gboolean res = FALSE;
+ LogTemplate *template;
vp_cmdline_parse_rekey_finish (data);
if (!g_strstr_len (value, strlen (value), "="))
@@ -749,13 +750,19 @@ vp_cmdline_parse_pair (const gchar *option_name, const gchar *value,
}
kv = g_strsplit(value, "=", 2);
- value_pairs_add_pair (vp, cfg, kv[0], kv[1]);
- g_free (kv[0]);
- g_free (kv[1]);
- g_free (kv);
+ template = log_template_new(cfg, NULL);
+ if (!log_template_compile(template, kv[1], error))
+ goto error;
- return TRUE;
+ value_pairs_add_pair(vp, kv[0], template);
+
+ res = TRUE;
+ error:
+ log_template_unref(template);
+ g_strfreev(kv);
+
+ return res;
}
static ValuePairsTransformSet *
diff --git a/lib/value-pairs.h b/lib/value-pairs.h
index a6c9f34..b060d54 100644
--- a/lib/value-pairs.h
+++ b/lib/value-pairs.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2011-2012 BalaBit IT Ltd, Budapest, Hungary
- * Copyright (c) 2011-2012 Gergely Nagy <algernon at balabit.hu>
+ * Copyright (c) 2011-2013 BalaBit IT Ltd, Budapest, Hungary
+ * Copyright (c) 2011-2013 Gergely Nagy <algernon at balabit.hu>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -27,6 +27,7 @@
#include "syslog-ng.h"
#include "nvtable.h"
+#include "template/templates.h"
typedef struct _ValuePairs ValuePairs;
typedef gboolean (*VPForeachFunc)(const gchar *name, const gchar *value, gpointer user_data);
@@ -41,7 +42,7 @@ typedef gboolean (*VPWalkCallbackFunc)(const gchar *name,
gboolean value_pairs_add_scope(ValuePairs *vp, const gchar *scope);
void value_pairs_add_glob_pattern(ValuePairs *vp, const gchar *pattern, gboolean include);
-void value_pairs_add_pair(ValuePairs *vp, GlobalConfig *cfg, const gchar *key, const gchar *value);
+gboolean value_pairs_add_pair(ValuePairs *vp, const gchar *key, LogTemplate *value);
void value_pairs_add_transforms(ValuePairs *vp, gpointer vpts);
--
1.7.10.4
More information about the syslog-ng
mailing list