-static int o_config_set_string (char **ret_string, /* {{{ */
- oconfig_item_t *ci)
-{
- char *string;
-
- if ((ci->values_num != 1)
- || (ci->values[0].type != OCONFIG_TYPE_STRING))
- {
- WARNING ("oracle plugin: The `%s' config option "
- "needs exactly one string argument.", ci->key);
- return (-1);
- }
-
- string = strdup (ci->values[0].value.string);
- if (string == NULL)
- {
- ERROR ("oracle plugin: strdup failed.");
- return (-1);
- }
-
- if (*ret_string != NULL)
- free (*ret_string);
- *ret_string = string;
-
- return (0);
-} /* }}} int o_config_set_string */
-
-static int o_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 ("oracle 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 ("oracle 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 ("oracle 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 ("oracle plugin: strdup failed.");
- *ret_array_len = array_len;
- return (-1);
- }
- array_len++;
- }
-
- *ret_array_len = array_len;
- return (0);
-} /* }}} int o_config_add_string */
-
-static int o_config_add_query (oconfig_item_t *ci) /* {{{ */
-{
- o_query_t *q;
- int status;
- int i;
-
- if ((ci->values_num != 1)
- || (ci->values[0].type != OCONFIG_TYPE_STRING))
- {
- WARNING ("oracle plugin: The `Query' block "
- "needs exactly one string argument.");
- return (-1);
- }
-
- q = (o_query_t *) malloc (sizeof (*q));
- if (q == NULL)
- {
- ERROR ("oracle plugin: malloc failed.");
- return (-1);
- }
- memset (q, 0, sizeof (*q));
-
- status = o_config_set_string (&q->name, ci);
- if (status != 0)
- {
- sfree (q);
- return (status);
- }
-
- /* Fill the `o_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 = o_config_set_string (&q->statement, child);
- else if (strcasecmp ("Type", child->key) == 0)
- status = o_config_set_string (&q->type, child);
- else if (strcasecmp ("InstancesFrom", child->key) == 0)
- status = o_config_add_string (&q->instances, &q->instances_num, child);
- else if (strcasecmp ("ValuesFrom", child->key) == 0)
- status = o_config_add_string (&q->values, &q->values_num, child);
- else
- {
- WARNING ("oracle 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 ("oracle plugin: `Statement' not given for query `%s'", q->name);
- status = -1;
- }
- if (q->type == NULL)
- {
- WARNING ("oracle plugin: `Type' not given for query `%s'", q->name);
- status = -1;
- }
- if (q->instances == NULL)
- {
- WARNING ("oracle plugin: `InstancesFrom' not given for query `%s'", q->name);
- status = -1;
- }
- if (q->values == NULL)
- {
- WARNING ("oracle 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)
- {
- o_query_t **temp;
-
- temp = (o_query_t **) realloc (queries,
- sizeof (*queries) * (queries_num + 1));
- if (temp == NULL)
- {
- ERROR ("oracle plugin: realloc failed");
- status = -1;
- }
- else
- {
- queries = temp;
- queries[queries_num] = q;
- queries_num++;
- }
- }
-
- if (status != 0)
- {
- o_query_free (q);
- return (-1);
- }
-
- return (0);
-} /* }}} int o_config_add_query */
-
-static int o_config_add_database_query (o_database_t *db, /* {{{ */
- oconfig_item_t *ci)
-{
- o_query_t *q;
- o_query_t **temp;
- size_t i;
-
- if ((ci->values_num != 1)
- || (ci->values[0].type != OCONFIG_TYPE_STRING))
- {
- WARNING ("oracle plugin: The `Query' config option "
- "needs exactly one string argument.");
- return (-1);
- }
-
- q = NULL;
- for (i = 0; i < queries_num; i++)
- {
- if (strcasecmp (queries[i]->name, ci->values[0].value.string) == 0)
- {
- q = queries[i];
- break;
- }
- }
-
- if (q == NULL)
- {
- WARNING ("oracle plugin: Database `%s': Unknown query `%s'. "
- "Please make sure that the <Query \"%s\"> block comes before "
- "the <Database \"%s\"> block.",
- db->name, ci->values[0].value.string,
- ci->values[0].value.string, db->name);
- return (-1);
- }
-
- temp = (o_query_t **) realloc (db->queries,
- sizeof (*db->queries) * (db->queries_num + 1));
- if (temp == NULL)
- {
- ERROR ("oracle plugin: realloc failed");
- return (-1);
- }
- else
- {
- db->queries = temp;
- db->queries[db->queries_num] = q;
- db->queries_num++;
- }
-
- return (0);
-} /* }}} int o_config_add_database_query */
-