[syslog-ng] [PATCH (3.5) 3/3] afamqp: Catch template syntax errors at config time
Gergely Nagy
algernon at balabit.hu
Mon Jun 10 17:58:35 CEST 2013
Teach the AMQP destination to catch template syntax errors at config
time, by adding an output error variable and a return value to
afamqp_dd_set_routing_key() and afamqp_dd_set_body(), and checking the
return value of log_template_compile(), and propagating error messages
upwards.
Signed-off-by: Gergely Nagy <algernon at balabit.hu>
---
modules/afamqp/afamqp-grammar.ym | 22 ++++++++++++++++++----
modules/afamqp/afamqp.c | 14 +++++++-------
modules/afamqp/afamqp.h | 8 ++++----
3 files changed, 29 insertions(+), 15 deletions(-)
diff --git a/modules/afamqp/afamqp-grammar.ym b/modules/afamqp/afamqp-grammar.ym
index a336d5d..0adf6bb 100644
--- a/modules/afamqp/afamqp-grammar.ym
+++ b/modules/afamqp/afamqp-grammar.ym
@@ -1,7 +1,7 @@
/*
* Copyright (c) 2012 Nagy, Attila <bra at fsn.hu>
- * Copyright (c) 2012 BalaBit IT Ltd, Budapest, Hungary
- * Copyright (c) 2012 Gergely Nagy <algernon at balabit.hu>
+ * Copyright (c) 2012-2013 BalaBit IT Ltd, Budapest, Hungary
+ * Copyright (c) 2012-2013 Gergely Nagy <algernon at balabit.hu>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
@@ -80,8 +80,22 @@ afamqp_option
| KW_EXCHANGE '(' string ')' { afamqp_dd_set_exchange(last_driver, $3); free($3); }
| KW_EXCHANGE_DECLARE '(' yesno ')' { afamqp_dd_set_exchange_declare(last_driver, $3); }
| KW_EXCHANGE_TYPE '(' string ')' { afamqp_dd_set_exchange_type(last_driver, $3); free($3); }
- | KW_ROUTING_KEY '(' string ')' { afamqp_dd_set_routing_key(last_driver, $3); free($3); }
- | KW_BODY '(' string ')' { afamqp_dd_set_body(last_driver, $3); free($3); }
+ | KW_ROUTING_KEY '(' string ')'
+ {
+ GError *error;
+
+ CHECK_ERROR(afamqp_dd_set_routing_key(last_driver, $3, &error), @3,
+ "Error compiling template; %s", error->message);
+ free($3);
+ }
+ | KW_BODY '(' string ')'
+ {
+ GError *error;
+
+ CHECK_ERROR(afamqp_dd_set_body(last_driver, $3, &error), @3,
+ "Error compiling template; %s", error->message);
+ free($3);
+ }
| KW_PERSISTENT '(' yesno ')' { afamqp_dd_set_persistent(last_driver, $3); }
| KW_USERNAME '(' string ')' { afamqp_dd_set_user(last_driver, $3); free($3); }
| KW_PASSWORD '(' string ')' { afamqp_dd_set_password(last_driver, $3); free($3); }
diff --git a/modules/afamqp/afamqp.c b/modules/afamqp/afamqp.c
index 9a6c07d..315335c 100644
--- a/modules/afamqp/afamqp.c
+++ b/modules/afamqp/afamqp.c
@@ -156,22 +156,22 @@ afamqp_dd_set_exchange_type(LogDriver *d, const gchar *exchange_type)
self->exchange_type = g_strdup(exchange_type);
}
-void
-afamqp_dd_set_routing_key(LogDriver *d, const gchar *routing_key)
+gboolean
+afamqp_dd_set_routing_key(LogDriver *d, const gchar *routing_key, GError **error)
{
AMQPDestDriver *self = (AMQPDestDriver *) d;
- log_template_compile(self->routing_key_template, routing_key, NULL);
+ return log_template_compile(self->routing_key_template, routing_key, error);
}
-void
-afamqp_dd_set_body(LogDriver *d, const gchar *body)
+gboolean
+afamqp_dd_set_body(LogDriver *d, const gchar *body, GError **error)
{
AMQPDestDriver *self = (AMQPDestDriver *) d;
if (!self->body_template)
self->body_template = log_template_new(configuration, NULL);
- log_template_compile(self->body_template, body, NULL);
+ return log_template_compile(self->body_template, body, error);
}
void
@@ -698,7 +698,7 @@ afamqp_dd_new(void)
afamqp_dd_set_port((LogDriver *) self, 5672);
afamqp_dd_set_exchange((LogDriver *) self, "syslog");
afamqp_dd_set_exchange_type((LogDriver *) self, "fanout");
- afamqp_dd_set_routing_key((LogDriver *) self, "");
+ afamqp_dd_set_routing_key((LogDriver *) self, "", NULL);
afamqp_dd_set_persistent((LogDriver *) self, TRUE);
afamqp_dd_set_exchange_declare((LogDriver *) self, FALSE);
diff --git a/modules/afamqp/afamqp.h b/modules/afamqp/afamqp.h
index 1247a25..5876231 100644
--- a/modules/afamqp/afamqp.h
+++ b/modules/afamqp/afamqp.h
@@ -1,7 +1,7 @@
/*
* Copyright (c) 2012 Nagy, Attila <bra at fsn.hu>
- * Copyright (c) 2012 BalaBit IT Ltd, Budapest, Hungary
- * Copyright (c) 2012 Gergely Nagy <algernon at balabit.hu>
+ * Copyright (c) 2012-2013 BalaBit IT Ltd, Budapest, Hungary
+ * Copyright (c) 2012-2013 Gergely Nagy <algernon at balabit.hu>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
@@ -36,8 +36,8 @@ void afamqp_dd_set_exchange(LogDriver *d, const gchar *database);
void afamqp_dd_set_exchange_declare(LogDriver *d, gboolean declare);
void afamqp_dd_set_exchange_type(LogDriver *d, const gchar *exchange_type);
void afamqp_dd_set_vhost(LogDriver *d, const gchar *vhost);
-void afamqp_dd_set_routing_key(LogDriver *d, const gchar *routing_key);
-void afamqp_dd_set_body(LogDriver *d, const gchar *body);
+gboolean afamqp_dd_set_routing_key(LogDriver *d, const gchar *routing_key, GError **error);
+gboolean afamqp_dd_set_body(LogDriver *d, const gchar *body, GError **error);
void afamqp_dd_set_persistent(LogDriver *d, gboolean persistent);
void afamqp_dd_set_user(LogDriver *d, const gchar *user);
void afamqp_dd_set_password(LogDriver *d, const gchar *password);
--
1.7.10.4
More information about the syslog-ng
mailing list