else
ds->max = NAN;
return 0;
-} /* static data_source_t *hv2data_source (HV *) */
+} /* static int hv2data_source (HV *, data_source_t *) */
static int av2value (pTHX_ char *name, AV *array, value_t *value, int len)
{
return len;
} /* static int av2value (char *, AV *, value_t *, int) */
+/*
+ * value list:
+ * {
+ * values => [ @values ],
+ * time => $time,
+ * host => $host,
+ * plugin => $plugin,
+ * plugin_instance => $pinstance,
+ * type_instance => $tinstance,
+ * }
+ */
+static int hv2value_list (pTHX_ HV *hash, value_list_t *vl)
+{
+ SV **tmp;
+
+ if ((NULL == hash) || (NULL == vl))
+ return -1;
+
+ if (NULL == (tmp = hv_fetch (hash, "type", 4, 0))) {
+ log_err ("hv2value_list: No type given.");
+ return -1;
+ }
+
+ sstrncpy (vl->type, SvPV_nolen (*tmp), sizeof (vl->type));
+
+ if ((NULL == (tmp = hv_fetch (hash, "values", 6, 0)))
+ || (! (SvROK (*tmp) && (SVt_PVAV == SvTYPE (SvRV (*tmp)))))) {
+ log_err ("hv2value_list: No valid values given.");
+ return -1;
+ }
+
+ {
+ AV *array = (AV *)SvRV (*tmp);
+ int len = av_len (array) + 1;
+
+ if (len <= 0)
+ return -1;
+
+ vl->values = (value_t *)smalloc (len * sizeof (value_t));
+ vl->values_len = av2value (aTHX_ vl->type, (AV *)SvRV (*tmp),
+ vl->values, len);
+
+ if (-1 == vl->values_len) {
+ sfree (vl->values);
+ return -1;
+ }
+ }
+
+ if (NULL != (tmp = hv_fetch (hash, "time", 4, 0))) {
+ vl->time = (time_t)SvIV (*tmp);
+ }
+
+ if (NULL != (tmp = hv_fetch (hash, "host", 4, 0))) {
+ sstrncpy (vl->host, SvPV_nolen (*tmp), sizeof (vl->host));
+ }
+ else {
+ sstrncpy (vl->host, hostname_g, sizeof (vl->host));
+ }
+
+ if (NULL != (tmp = hv_fetch (hash, "plugin", 6, 0)))
+ sstrncpy (vl->plugin, SvPV_nolen (*tmp), sizeof (vl->plugin));
+
+ if (NULL != (tmp = hv_fetch (hash, "plugin_instance", 15, 0)))
+ sstrncpy (vl->plugin_instance, SvPV_nolen (*tmp),
+ sizeof (vl->plugin_instance));
+
+ if (NULL != (tmp = hv_fetch (hash, "type_instance", 13, 0)))
+ sstrncpy (vl->type_instance, SvPV_nolen (*tmp),
+ sizeof (vl->type_instance));
+ return 0;
+} /* static int hv2value_list (pTHX_ HV *, value_list_t *) */
+
static int data_set2av (pTHX_ data_set_t *ds, AV *array)
{
int i = 0;
/*
* Submit the values to the write functions.
- *
- * value list:
- * {
- * values => [ @values ],
- * time => $time,
- * host => $host,
- * plugin => $plugin,
- * plugin_instance => $pinstance,
- * type_instance => $tinstance,
- * }
*/
static int pplugin_dispatch_values (pTHX_ HV *values)
{
- value_list_t list = VALUE_LIST_INIT;
- value_t *val = NULL;
-
- SV **tmp = NULL;
+ value_list_t vl = VALUE_LIST_INIT;
int ret = 0;
if (NULL == values)
return -1;
- if (NULL == (tmp = hv_fetch (values, "type", 4, 0))) {
- log_err ("pplugin_dispatch_values: No type given.");
- return -1;
- }
-
- sstrncpy (list.type, SvPV_nolen (*tmp), sizeof (list.type));
-
- if ((NULL == (tmp = hv_fetch (values, "values", 6, 0)))
- || (! (SvROK (*tmp) && (SVt_PVAV == SvTYPE (SvRV (*tmp)))))) {
- log_err ("pplugin_dispatch_values: No valid values given.");
+ if (0 != hv2value_list (aTHX_ values, &vl))
return -1;
- }
-
- {
- AV *array = (AV *)SvRV (*tmp);
- int len = av_len (array) + 1;
-
- if (len <= 0)
- return -1;
-
- val = (value_t *)smalloc (len * sizeof (value_t));
-
- list.values_len = av2value (aTHX_ list.type, (AV *)SvRV (*tmp),
- val, len);
- list.values = val;
-
- if (-1 == list.values_len) {
- sfree (val);
- return -1;
- }
- }
-
- if (NULL != (tmp = hv_fetch (values, "time", 4, 0))) {
- list.time = (time_t)SvIV (*tmp);
- }
-
- if (NULL != (tmp = hv_fetch (values, "host", 4, 0))) {
- sstrncpy (list.host, SvPV_nolen (*tmp), sizeof (list.host));
- }
- else {
- sstrncpy (list.host, hostname_g, sizeof (list.host));
- }
-
- if (NULL != (tmp = hv_fetch (values, "plugin", 6, 0)))
- sstrncpy (list.plugin, SvPV_nolen (*tmp), sizeof (list.plugin));
-
- if (NULL != (tmp = hv_fetch (values, "plugin_instance", 15, 0)))
- sstrncpy (list.plugin_instance, SvPV_nolen (*tmp),
- sizeof (list.plugin_instance));
-
- if (NULL != (tmp = hv_fetch (values, "type_instance", 13, 0)))
- sstrncpy (list.type_instance, SvPV_nolen (*tmp),
- sizeof (list.type_instance));
- ret = plugin_dispatch_values (&list);
+ ret = plugin_dispatch_values (&vl);
- sfree (val);
+ sfree (vl.values);
return ret;
} /* static int pplugin_dispatch_values (char *, HV *) */