+ vl.values = &value;
+ vl.values_len = 1;
+
+ value_str = column_values[r->legacy_position];
+ if (0 != parse_value (value_str, &vl.values[0], r_area->ds->ds[0].type))
+ {
+ ERROR ("db query utils: udb_legacy_result_handle_result: "
+ "Parsing `%s' as %s failed.", value_str,
+ DS_TYPE_TO_STRING (r_area->ds->ds[0].type));
+ errno = EINVAL;
+ return (-1);
+ }
+
+ if (q_area->interval > 0)
+ vl.interval = q_area->interval;
+
+ sstrncpy (vl.host, q_area->host, sizeof (vl.host));
+ sstrncpy (vl.plugin, q_area->plugin, sizeof (vl.plugin));
+ sstrncpy (vl.plugin_instance, q_area->db_name, sizeof (vl.type_instance));
+ sstrncpy (vl.type, r->type, sizeof (vl.type));
+
+ if (r->instance_prefix != NULL)
+ sstrncpy (vl.type_instance, r->instance_prefix,
+ sizeof (vl.type_instance));
+
+ plugin_dispatch_values (&vl);
+
+ return (0);
+} /* }}} int udb_legacy_result_handle_result */
+
+static int udb_legacy_result_prepare_result (const udb_result_t const *r, /* {{{ */
+ udb_result_preparation_area_t *prep_area,
+ char **column_names, size_t column_num)
+{
+ if (r == NULL)
+ return (-EINVAL);
+
+ assert (r->legacy_mode == 1);
+
+ /* Make sure previous preparations are cleaned up. */
+ udb_legacy_result_finish_result (r, prep_area);
+
+ if (r->legacy_position >= column_num)
+ {
+ ERROR ("db query utils: The legacy configuration specified (at least) "
+ "%zu `Column's, but the query returned only %zu columns!",
+ r->legacy_position + 1, column_num);
+ return (-ENOENT);
+ }
+
+ /* Read `ds' and check number of values {{{ */
+ prep_area->ds = plugin_get_ds (r->type);
+ if (prep_area->ds == NULL)
+ {
+ ERROR ("db query utils: udb_result_prepare_result: Type `%s' is not "
+ "known by the daemon. See types.db(5) for details.",
+ r->type);
+ return (-1);
+ }
+
+ if (prep_area->ds->ds_num != 1)
+ {
+ ERROR ("db query utils: udb_result_prepare_result: The type `%s' "
+ "requires exactly %i values, but the legacy configuration "
+ "requires exactly one!",
+ r->type,
+ prep_area->ds->ds_num);
+ return (-1);
+ }
+ /* }}} */
+
+ return (0);
+} /* }}} int udb_legacy_result_prepare_result */
+
+static int udb_legacy_result_create (const char *query_name, /* {{{ */
+ udb_result_t **r_head, oconfig_item_t *ci, size_t position)
+{
+ udb_result_t *r;
+
+ if ((ci->values_num < 1) || (ci->values_num > 2)
+ || (ci->values[0].type != OCONFIG_TYPE_STRING)
+ || ((ci->values_num == 2)
+ && (ci->values[1].type != OCONFIG_TYPE_STRING)))
+ {
+ WARNING ("db query utils: The `Column' block needs either one or two "
+ "string arguments.");
+ return (-1);
+ }
+
+ r = (udb_result_t *) malloc (sizeof (*r));
+ if (r == NULL)
+ {
+ ERROR ("db query utils: malloc failed.");
+ return (-1);
+ }
+ memset (r, 0, sizeof (*r));
+
+ r->legacy_mode = 1;
+ r->legacy_position = position;
+
+ r->type = strdup (ci->values[0].value.string);
+ if (r->type == NULL)
+ {
+ ERROR ("db query utils: strdup failed.");
+ free (r);
+ return (-1);
+ }
+
+ r->instance_prefix = NULL;
+ if (ci->values_num == 2)
+ {
+ r->instance_prefix = strdup (ci->values[1].value.string);
+ if (r->instance_prefix == NULL)
+ {
+ ERROR ("db query utils: strdup failed.");
+ free (r->type);
+ free (r);
+ return (-1);
+ }
+ }
+
+ /* If all went well, add this result to the list of results. */
+ if (*r_head == NULL)