-static int cdbi_config_add_string (char ***ret_array, /* {{{ */
- size_t *ret_array_len, oconfig_item_t *ci)
-{
- char **array;
- size_t array_len;
- int i;
-
- if (ci->values_num < 1)
- {
- WARNING ("dbi plugin: The `%s' config option "
- "needs at least one argument.", ci->key);
- return (-1);
- }
-
- for (i = 0; i < ci->values_num; i++)
- {
- if (ci->values[i].type != OCONFIG_TYPE_STRING)
- {
- WARNING ("dbi plugin: Argument %i to the `%s' option "
- "is not a string.", i + 1, ci->key);
- return (-1);
- }
- }
-
- array_len = *ret_array_len;
- array = (char **) realloc (*ret_array,
- sizeof (char *) * (array_len + ci->values_num));
- if (array == NULL)
- {
- ERROR ("dbi plugin: realloc failed.");
- return (-1);
- }
- *ret_array = array;
-
- for (i = 0; i < ci->values_num; i++)
- {
- array[array_len] = strdup (ci->values[i].value.string);
- if (array[array_len] == NULL)
- {
- ERROR ("dbi plugin: strdup failed.");
- *ret_array_len = array_len;
- return (-1);
- }
- array_len++;
- }
-
- *ret_array_len = array_len;
- return (0);
-} /* }}} int cdbi_config_add_string */
-
-static int cdbi_config_add_query (oconfig_item_t *ci) /* {{{ */
-{
- cdbi_query_t *q;
- int status;
- int i;
-
- if ((ci->values_num != 1)
- || (ci->values[0].type != OCONFIG_TYPE_STRING))
- {
- WARNING ("dbi plugin: The `Query' block "
- "needs exactly one string argument.");
- return (-1);
- }
-
- q = (cdbi_query_t *) malloc (sizeof (*q));
- if (q == NULL)
- {
- ERROR ("dbi plugin: malloc failed.");
- return (-1);
- }
- memset (q, 0, sizeof (*q));
-
- status = cdbi_config_set_string (&q->name, ci);
- if (status != 0)
- {
- sfree (q);
- return (status);
- }
-
- /* Fill the `cdbi_query_t' structure.. */
- for (i = 0; i < ci->children_num; i++)
- {
- oconfig_item_t *child = ci->children + i;
-
- if (strcasecmp ("Statement", child->key) == 0)
- status = cdbi_config_set_string (&q->statement, child);
- else if (strcasecmp ("Type", child->key) == 0)
- status = cdbi_config_set_string (&q->type, child);
- else if (strcasecmp ("InstancesFrom", child->key) == 0)
- status = cdbi_config_add_string (&q->instances, &q->instances_num, child);
- else if (strcasecmp ("ValuesFrom", child->key) == 0)
- status = cdbi_config_add_string (&q->values, &q->values_num, child);
- else
- {
- WARNING ("dbi plugin: Option `%s' not allowed here.", child->key);
- status = -1;
- }
-
- if (status != 0)
- break;
- }
-
- /* Check that all necessary options have been given. */
- while (status == 0)
- {
- if (q->statement == NULL)
- {
- WARNING ("dbi plugin: `Statement' not given for query `%s'", q->name);
- status = -1;
- }
- if (q->type == NULL)
- {
- WARNING ("dbi plugin: `Type' not given for query `%s'", q->name);
- status = -1;
- }
- if (q->instances == NULL)
- {
- WARNING ("dbi plugin: `InstancesFrom' not given for query `%s'", q->name);
- status = -1;
- }
- if (q->values == NULL)
- {
- WARNING ("dbi plugin: `ValuesFrom' not given for query `%s'", q->name);
- status = -1;
- }
-
- break;
- } /* while (status == 0) */
-
- /* If all went well, add this query to the list of queries within the
- * database structure. */
- if (status == 0)
- {
- cdbi_query_t **temp;
-
- temp = (cdbi_query_t **) realloc (queries,
- sizeof (*queries) * (queries_num + 1));
- if (temp == NULL)
- {
- ERROR ("dbi plugin: realloc failed");
- status = -1;
- }
- else
- {
- queries = temp;
- queries[queries_num] = q;
- queries_num++;
- }
- }
-
- if (status != 0)
- {
- cdbi_query_free (q);
- return (-1);
- }
-
- return (0);
-} /* }}} int cdbi_config_add_query */
-