[syslog-ng] [PATCH (3.4)] value-pairs: Do not require --rekey in the command-line parser.
Gergely Nagy
algernon at balabit.hu
Fri Feb 3 11:20:17 CET 2012
The --rekey in the commandline parser is not needed, the various
transformation functions can work just fine without it, and do the
setup themselves, if so need be.
This patch gets rid of --rekey.
Signed-off-by: Gergely Nagy <algernon at balabit.hu>
---
lib/value-pairs.c | 44 ++++++++++++++++++++++++++------------------
1 files changed, 26 insertions(+), 18 deletions(-)
diff --git a/lib/value-pairs.c b/lib/value-pairs.c
index 6ecd810..59380f5 100644
--- a/lib/value-pairs.c
+++ b/lib/value-pairs.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2011 BalaBit IT Ltd, Budapest, Hungary
- * Copyright (c) 2011 Gergely Nagy <algernon at balabit.hu>
+ * Copyright (c) 2011-2012 BalaBit IT Ltd, Budapest, Hungary
+ * Copyright (c) 2011-2012 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
@@ -506,33 +506,39 @@ vp_cmdline_parse_pair (const gchar *option_name, const gchar *value,
return TRUE;
}
-static gboolean
-vp_cmdline_parse_rekey (const gchar *option_name, const gchar *value,
- gpointer data, GError **error)
+static ValuePairsTransformSet *
+vp_cmdline_rekey_verify (gchar *key, ValuePairsTransformSet *vpts,
+ gpointer data)
{
- gpointer *args = (gpointer *) data;
- ValuePairsTransformSet *vpts = (ValuePairsTransformSet *) args[2];
- gchar *key = (gchar *) args[3];
+ gpointer *args = (gpointer *)data;
- vpts = value_pairs_transform_set_new (key);
- vp_cmdline_parse_rekey_finish (data);
-
- args[2] = vpts;
- return TRUE;
+ if (!vpts)
+ {
+ if (!key)
+ return NULL;
+ vpts = value_pairs_transform_set_new (key);
+ vp_cmdline_parse_rekey_finish (data);
+ args[2] = vpts;
+ return vpts;
+ }
+ return vpts;
}
+
static gboolean
vp_cmdline_parse_rekey_replace (const gchar *option_name, const gchar *value,
gpointer data, GError **error)
{
gpointer *args = (gpointer *) data;
ValuePairsTransformSet *vpts = (ValuePairsTransformSet *) args[2];
+ gchar *key = (gchar *) args[3];
gchar **kv;
+ vpts = vp_cmdline_rekey_verify (key, vpts, data);
if (!vpts)
{
g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
- "Error parsing value-pairs: --replace used without --rekey");
+ "Error parsing value-pairs: --replace used without --key");
return FALSE;
}
@@ -560,11 +566,13 @@ vp_cmdline_parse_rekey_add_prefix (const gchar *option_name, const gchar *value,
{
gpointer *args = (gpointer *) data;
ValuePairsTransformSet *vpts = (ValuePairsTransformSet *) args[2];
+ gchar *key = (gchar *) args[3];
+ vpts = vp_cmdline_rekey_verify (key, vpts, data);
if (!vpts)
{
g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
- "Error parsing value-pairs: --add-prefix used without --rekey");
+ "Error parsing value-pairs: --add-prefix used without --key");
return FALSE;
}
@@ -579,11 +587,13 @@ vp_cmdline_parse_rekey_shift (const gchar *option_name, const gchar *value,
{
gpointer *args = (gpointer *) data;
ValuePairsTransformSet *vpts = (ValuePairsTransformSet *) args[2];
+ gchar *key = (gchar *) args[3];
+ vpts = vp_cmdline_rekey_verify (key, vpts, data);
if (!vpts)
{
g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
- "Error parsing value-pairs: --shift used without --rekey");
+ "Error parsing value-pairs: --shift used without --key");
return FALSE;
}
@@ -609,8 +619,6 @@ value_pairs_new_from_cmdline (GlobalConfig *cfg,
NULL, NULL },
{ "pair", 'p', 0, G_OPTION_ARG_CALLBACK, vp_cmdline_parse_pair,
NULL, NULL },
- { "rekey", 'r', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
- vp_cmdline_parse_rekey, NULL, NULL },
{ "shift", 'S', 0, G_OPTION_ARG_CALLBACK, vp_cmdline_parse_rekey_shift,
NULL, NULL },
{ "add-prefix", 'A', 0, G_OPTION_ARG_CALLBACK, vp_cmdline_parse_rekey_add_prefix,
--
1.7.8.3
More information about the syslog-ng
mailing list