[PATCH (3.4) 1/2] value-pairs: Update value_pairs_new_from_cmdline() to 3.4.
A while ago the template functions were changed so that their argv[0] became the template function's name. What this means for value-pairs() is that we no longer need to play dirty tricks with its argv[] to please g_option_context_parse(), which expected the zero-index argument to be a program name. Signed-off-by: Gergely Nagy <algernon@balabit.hu> --- lib/value-pairs.c | 10 +--------- 1 files changed, 1 insertions(+), 9 deletions(-) diff --git a/lib/value-pairs.c b/lib/value-pairs.c index 10f3e57..c4e2542 100644 --- a/lib/value-pairs.c +++ b/lib/value-pairs.c @@ -430,7 +430,7 @@ vp_cmdline_parse_pair (const gchar *option_name, const gchar *value, ValuePairs * value_pairs_new_from_cmdline (GlobalConfig *cfg, - gint cargc, gchar **cargv, + gint argc, gchar **argv, GError **error) { ValuePairs *vp; @@ -448,8 +448,6 @@ value_pairs_new_from_cmdline (GlobalConfig *cfg, NULL, NULL }, { NULL } }; - gchar **argv; - gint argc = cargc + 1; gint i; GOptionGroup *og; gpointer user_data_args[2]; @@ -458,12 +456,6 @@ value_pairs_new_from_cmdline (GlobalConfig *cfg, user_data_args[0] = cfg; user_data_args[1] = vp; - argv = g_new (gchar *, argc + 1); - for (i = 0; i < argc; i++) - argv[i + 1] = cargv[i]; - argv[0] = "value-pairs"; - argv[argc] = NULL; - ctx = g_option_context_new ("value-pairs"); og = g_option_group_new (NULL, NULL, NULL, user_data_args, NULL); g_option_group_add_entries (og, vp_options); -- 1.7.2.5
The non-simple template functions had an API change, this patch brings tfjson up to date with those: Since the state is now kept by core, TFJsonState was introduced, to hold our additional state. Furthermore tf_json_prepare() was updated to use the supplied state, instead of trying to keep our own. A new function, tf_json_free_state() was also introduced, to free the additional state that tf_json_prepare() allocated. And as a final step, tf_json_eval() was removed, and tf_json_call() was updated to use the state kept by the core. Signed-off-by: Gergely Nagy <algernon@balabit.hu> --- modules/tfjson/tfjson.c | 42 +++++++++++++++++++++++------------------- 1 files changed, 23 insertions(+), 19 deletions(-) diff --git a/modules/tfjson/tfjson.c b/modules/tfjson/tfjson.c index 39a6cdb..59c9f54 100644 --- a/modules/tfjson/tfjson.c +++ b/modules/tfjson/tfjson.c @@ -35,21 +35,23 @@ #include <json-glib/json-glib.h> #endif +typedef struct _TFJsonState +{ + TFSimpleFuncState super; + ValuePairs *vp; +} TFJsonState; + static gboolean -tf_json_prepare(LogTemplateFunction *self, LogTemplate *parent, +tf_json_prepare(LogTemplateFunction *self, gpointer s, LogTemplate *parent, gint argc, gchar *argv[], - gpointer *state, GDestroyNotify *state_destroy, GError **error) { - ValuePairs *vp; + TFJsonState *state = (TFJsonState *)s; - vp = value_pairs_new_from_cmdline (parent->cfg, argc, argv, error); - if (!vp) + state->vp = value_pairs_new_from_cmdline (parent->cfg, argc, argv, error); + if (!state->vp) return FALSE; - *state = vp; - *state_destroy = (GDestroyNotify) value_pairs_free; - return TRUE; } @@ -119,26 +121,28 @@ tf_json_append(GString *result, ValuePairs *vp, LogMessage *msg) #endif static void -tf_json_call(LogTemplateFunction *self, gpointer state, GPtrArray *arg_bufs, - LogMessage **messages, gint num_messages, LogTemplateOptions *opts, - gint tz, gint seq_num, const gchar *context_id, GString *result) +tf_json_call(LogTemplateFunction *self, gpointer s, + const LogTemplateInvokeArgs *args, GString *result) { + TFJsonState *state = (TFJsonState *)s; gint i; - ValuePairs *vp = (ValuePairs *)state; - for (i = 0; i < num_messages; i++) - tf_json_append(result, vp, messages[i]); + for (i = 0; i < args->num_messages; i++) + tf_json_append(result, state->vp, args->messages[i]); } static void -tf_json_eval (LogTemplateFunction *self, gpointer state, GPtrArray *arg_bufs, - LogMessage **messages, gint num_messages, LogTemplateOptions *opts, - gint tz, gint seq_num, const gchar *context_id) +tf_json_free_state(gpointer s) { - return; + TFJsonState *state = (TFJsonState *)s; + + if (state->vp) + value_pairs_free(state->vp); + tf_simple_func_free_state(&state->super); } -TEMPLATE_FUNCTION(tf_json, tf_json_prepare, tf_json_eval, tf_json_call, NULL); +TEMPLATE_FUNCTION(TFJsonState, tf_json, tf_json_prepare, NULL, tf_json_call, + tf_json_free_state, NULL); static Plugin builtin_tmpl_func_plugins[] = { -- 1.7.2.5
Hi, Both applied, thanks Gergely. On Sun, 2011-06-05 at 16:37 +0200, Gergely Nagy wrote:
The non-simple template functions had an API change, this patch brings tfjson up to date with those:
-- Bazsi
participants (2)
-
Balazs Scheidler
-
Gergely Nagy