From 4eef10810d007368b82a24921c422ecc5de7bb28 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Mon, 9 Feb 2009 19:20:13 +0100 Subject: [PATCH] perl plugin: Don't do any type conversion in pplugin_dispatch_notification(). The conversion of the hash value to a notification_t object has been moved into its own separate function. --- src/perl.c | 99 +++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 56 insertions(+), 43 deletions(-) diff --git a/src/perl.c b/src/perl.c index c0326943..2d4cc867 100644 --- a/src/perl.c +++ b/src/perl.c @@ -403,6 +403,60 @@ static int av2data_set (pTHX_ AV *array, char *name, data_set_t *ds) return 0; } /* static int av2data_set (pTHX_ AV *, data_set_t *) */ +/* + * notification: + * { + * severity => $severity, + * time => $time, + * message => $msg, + * host => $host, + * plugin => $plugin, + * type => $type, + * plugin_instance => $instance, + * type_instance => $type_instance + * } + */ +static int hv2notification (pTHX_ HV *hash, notification_t *n) +{ + SV **tmp = NULL; + + if ((NULL == hash) || (NULL == n)) + return -1; + + if (NULL != (tmp = hv_fetch (hash, "severity", 8, 0))) + n->severity = SvIV (*tmp); + else + n->severity = NOTIF_FAILURE; + + if (NULL != (tmp = hv_fetch (hash, "time", 4, 0))) + n->time = (time_t)SvIV (*tmp); + else + n->time = time (NULL); + + if (NULL != (tmp = hv_fetch (hash, "message", 7, 0))) + sstrncpy (n->message, SvPV_nolen (*tmp), sizeof (n->message)); + + if (NULL != (tmp = hv_fetch (hash, "host", 4, 0))) + sstrncpy (n->host, SvPV_nolen (*tmp), sizeof (n->host)); + else + sstrncpy (n->host, hostname_g, sizeof (n->host)); + + if (NULL != (tmp = hv_fetch (hash, "plugin", 6, 0))) + sstrncpy (n->plugin, SvPV_nolen (*tmp), sizeof (n->plugin)); + + if (NULL != (tmp = hv_fetch (hash, "plugin_instance", 15, 0))) + sstrncpy (n->plugin_instance, SvPV_nolen (*tmp), + sizeof (n->plugin_instance)); + + if (NULL != (tmp = hv_fetch (hash, "type", 4, 0))) + sstrncpy (n->type, SvPV_nolen (*tmp), sizeof (n->type)); + + if (NULL != (tmp = hv_fetch (hash, "type_instance", 13, 0))) + sstrncpy (n->type_instance, SvPV_nolen (*tmp), + sizeof (n->type_instance)); + return 0; +} /* static int hv2notification (pTHX_ HV *, notification_t *) */ + static int data_set2av (pTHX_ data_set_t *ds, AV *array) { int i = 0; @@ -684,60 +738,19 @@ static int pplugin_dispatch_values (pTHX_ HV *values) /* * Dispatch a notification. - * - * notification: - * { - * severity => $severity, - * time => $time, - * message => $msg, - * host => $host, - * plugin => $plugin, - * type => $type, - * plugin_instance => $instance, - * type_instance => $type_instance - * } */ static int pplugin_dispatch_notification (pTHX_ HV *notif) { notification_t n; - SV **tmp = NULL; - if (NULL == notif) return -1; memset (&n, 0, sizeof (n)); - if (NULL != (tmp = hv_fetch (notif, "severity", 8, 0))) - n.severity = SvIV (*tmp); - else - n.severity = NOTIF_FAILURE; - - if (NULL != (tmp = hv_fetch (notif, "time", 4, 0))) - n.time = (time_t)SvIV (*tmp); - else - n.time = time (NULL); - - if (NULL != (tmp = hv_fetch (notif, "message", 7, 0))) - sstrncpy (n.message, SvPV_nolen (*tmp), sizeof (n.message)); - - if (NULL != (tmp = hv_fetch (notif, "host", 4, 0))) - sstrncpy (n.host, SvPV_nolen (*tmp), sizeof (n.host)); - else - sstrncpy (n.host, hostname_g, sizeof (n.host)); - - if (NULL != (tmp = hv_fetch (notif, "plugin", 6, 0))) - sstrncpy (n.plugin, SvPV_nolen (*tmp), sizeof (n.plugin)); - - if (NULL != (tmp = hv_fetch (notif, "plugin_instance", 15, 0))) - sstrncpy (n.plugin_instance, SvPV_nolen (*tmp), - sizeof (n.plugin_instance)); - - if (NULL != (tmp = hv_fetch (notif, "type", 4, 0))) - sstrncpy (n.type, SvPV_nolen (*tmp), sizeof (n.type)); + if (0 != hv2notification (aTHX_ notif, &n)) + return -1; - if (NULL != (tmp = hv_fetch (notif, "type_instance", 13, 0))) - sstrncpy (n.type_instance, SvPV_nolen (*tmp), sizeof (n.type_instance)); return plugin_dispatch_notification (&n); } /* static int pplugin_dispatch_notification (HV *) */ -- 2.11.0