From b87908a5c854d42bf3cf6e7255b455062b61bc8c Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Mon, 26 Aug 2013 12:08:47 +0200 Subject: [PATCH] value-pairs: Allow comma-separated scopes in the command-line parser Allow comma-separated scopes in the command-line parser, in $(format-json) and anything else that may be using the same framework. We do this by splitting the value by commas first, and iterating through the list. Fixes: BugZilla#248 Reported-by: Fabien Wernli Signed-off-by: Gergely Nagy --- lib/value-pairs.c | 17 +++++++++++++---- modules/json/tests/test_json.c | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/value-pairs.c b/lib/value-pairs.c index ee22b737..eefdf810 100644 --- a/lib/value-pairs.c +++ b/lib/value-pairs.c @@ -667,15 +667,24 @@ vp_cmdline_parse_scope(const gchar *option_name, const gchar *value, { gpointer *args = (gpointer *) data; ValuePairs *vp = (ValuePairs *) args[1]; + gchar **scopes; + gint i; vp_cmdline_parse_rekey_finish (data); - if (!value_pairs_add_scope (vp, value)) + scopes = g_strsplit (value, ",", -1); + for (i = 0; scopes[i] != NULL; i++) { - g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, - "Error parsing value-pairs: unknown scope %s", value); - return FALSE; + if (!value_pairs_add_scope (vp, scopes[i])) + { + g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, + "Error parsing value-pairs: unknown scope %s", scopes[i]); + g_strfreev (scopes); + return FALSE; + } } + g_strfreev (scopes); + return TRUE; } diff --git a/modules/json/tests/test_json.c b/modules/json/tests/test_json.c index 8087c3e7..3ab31dbf 100644 --- a/modules/json/tests/test_json.c +++ b/modules/json/tests/test_json.c @@ -14,6 +14,7 @@ test_format_json(void) assert_template_format("$(format-json kernel.SUBSYSTEM=pci kernel.DEVICE.type=pci kernel.DEVICE.name=0000:02:00.0 MSGID=801 MESSAGE=test)", "{\"kernel\":{\"SUBSYSTEM\":\"pci\",\"DEVICE\":{\"type\":\"pci\",\"name\":\"0000:02:00.0\"}},\"MSGID\":\"801\",\"MESSAGE\":\"test\"}"); assert_template_format("$(format-json .foo=bar)", "{\"_foo\":\"bar\"}"); + assert_template_format("$(format-json --scope rfc3164,rfc3164)", "{\"PROGRAM\":\"syslog-ng\",\"PRIORITY\":\"err\",\"PID\":\"23323\",\"MESSAGE\":\"árvíztűrőtükörfúrógép\",\"HOST\":\"bzorp\",\"FACILITY\":\"local3\",\"DATE\":\"Feb 11 18:58:35\"}"); } void