+static int config_add_writer (oconfig_item_t *ci,
+ c_psql_writer_t *src_writers, size_t src_writers_num,
+ c_psql_writer_t ***dst_writers, size_t *dst_writers_num)
+{
+ char *name;
+
+ size_t i;
+
+ if ((ci == NULL) || (dst_writers == NULL) || (dst_writers_num == NULL))
+ return -1;
+
+ if ((ci->values_num != 1)
+ || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
+ log_err ("`Writer' expects a single string argument.");
+ return 1;
+ }
+
+ name = ci->values[0].value.string;
+
+ for (i = 0; i < src_writers_num; ++i) {
+ c_psql_writer_t **tmp;
+
+ if (strcasecmp (name, src_writers[i].name) != 0)
+ continue;
+
+ tmp = (c_psql_writer_t **)realloc (*dst_writers,
+ sizeof (**dst_writers) * (*dst_writers_num + 1));
+ if (tmp == NULL) {
+ log_err ("Out of memory.");
+ return -1;
+ }
+
+ tmp[*dst_writers_num] = src_writers + i;
+
+ *dst_writers = tmp;
+ ++(*dst_writers_num);
+ break;
+ }
+
+ if (i >= src_writers_num) {
+ log_err ("No such writer: `%s'", name);
+ return -1;
+ }
+
+ return 0;
+} /* config_add_writer */
+
+static int c_psql_config_writer (oconfig_item_t *ci)
+{
+ c_psql_writer_t *writer;
+ c_psql_writer_t *tmp;
+
+ int status = 0;
+ int i;
+
+ if ((ci->values_num != 1)
+ || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
+ log_err ("<Writer> expects a single string argument.");
+ return 1;
+ }
+
+ tmp = (c_psql_writer_t *)realloc (writers,
+ sizeof (*writers) * (writers_num + 1));
+ if (tmp == NULL) {
+ log_err ("Out of memory.");
+ return -1;
+ }
+
+ writers = tmp;
+ writer = writers + writers_num;
+ ++writers_num;
+
+ writer->name = sstrdup (ci->values[0].value.string);
+ writer->statement = NULL;
+ writer->store_rates = 1;
+
+ for (i = 0; i < ci->children_num; ++i) {
+ oconfig_item_t *c = ci->children + i;
+
+ if (strcasecmp ("Statement", c->key) == 0)
+ status = cf_util_get_string (c, &writer->statement);
+ else if (strcasecmp ("StoreRates", c->key) == 0)
+ status = cf_util_get_boolean (c, &writer->store_rates);
+ else
+ log_warn ("Ignoring unknown config key \"%s\".", c->key);
+ }
+
+ if (status != 0) {
+ sfree (writer->statement);
+ sfree (writer->name);
+ sfree (writer);
+ return status;
+ }
+
+ return 0;
+} /* c_psql_config_writer */
+