+ st = (apache_t *) malloc (sizeof (*st));
+ if (st == NULL)
+ {
+ ERROR ("apache plugin: malloc failed.");
+ return (-1);
+ }
+
+ memset (st, 0, sizeof (*st));
+
+ status = config_set_string (&st->name, ci);
+ if (status != 0)
+ {
+ sfree (st);
+ return (status);
+ }
+
+ for (i = 0; i < ci->children_num; i++)
+ {
+ oconfig_item_t *child = ci->children + i;
+
+ if (strcasecmp ("URL", child->key) == 0)
+ status = config_set_string (&st->url, child);
+ else if (strcasecmp ("Host", child->key) == 0)
+ status = config_set_string (&st->host, child);
+ else if (strcasecmp ("User", child->key) == 0)
+ status = config_set_string (&st->user, child);
+ else if (strcasecmp ("Password", child->key) == 0)
+ status = config_set_string (&st->pass, child);
+ else if (strcasecmp ("VerifyPeer", child->key) == 0)
+ status = config_set_string (&st->verify_peer, child);
+ else if (strcasecmp ("VerifyHost", child->key) == 0)
+ status = config_set_string (&st->verify_host, child);
+ else if (strcasecmp ("CACert", child->key) == 0)
+ status = config_set_string (&st->cacert, child);
+ else
+ {
+ WARNING ("apache plugin: Option `%s' not allowed here.", child->key);
+ status = -1;
+ }
+
+ if (status != 0)
+ break;
+ }
+
+ if (status == 0)
+ {
+ apache_t **temp;
+ temp = (apache_t **) realloc (apache, sizeof (*apache) * (apache_num + 1));
+ if (temp == NULL)
+ {
+ ERROR ("apache plugin: realloc failed");
+ status = -1;
+ }
+ else
+ {
+ apache = temp;
+ apache[apache_num] = st;
+ apache_num++;
+ }
+ }
+
+ if (status != 0)
+ {
+ apache_free(st);
+ return (-1);
+ }
+
+ return (0);
+} /* int config_add */
+
+static int config (oconfig_item_t *ci)
+{
+ int status = 0;
+ int i;
+ oconfig_item_t *lci = NULL; /* legacy config */
+
+ for (i = 0; i < ci->children_num; i++)
+ {
+ oconfig_item_t *child = ci->children + i;
+
+ if (strcasecmp ("Instance", child->key) == 0 && child->children_num > 0)
+ config_add (child);
+ else
+ {
+ /* legacy mode - convert to <Instance ...> config */
+ if (lci == NULL)
+ {
+ lci = malloc (sizeof(*lci));
+ if (lci == NULL)
+ {
+ ERROR ("apache plugin: malloc failed.");
+ return (-1);
+ }
+ memset (lci, '\0', sizeof (*lci));
+ }
+ if (strcasecmp ("Instance", child->key) == 0)
+ {
+ lci->key = child->key;
+ lci->values = child->values;
+ lci->values_num = child->values_num;
+ lci->parent = child->parent;
+ }
+ else
+ {
+ lci->children_num++;
+ lci->children =
+ realloc (lci->children,
+ lci->children_num * sizeof (*child));
+ if (lci->children == NULL)
+ {
+ ERROR ("apache plugin: realloc failed.");
+ return (-1);
+ }
+ memcpy (&lci->children[lci->children_num-1], child, sizeof (*child));
+ }
+ }
+ } /* for (ci->children) */
+
+ if (lci)
+ {
+ // create a <Instance ""> entry
+ lci->key = "Instance";
+ lci->values_num = 1;
+ lci->values = (oconfig_value_t *) malloc (lci->values_num * sizeof (oconfig_value_t));
+ lci->values[0].type = OCONFIG_TYPE_STRING;
+ lci->values[0].value.string = "";
+
+ status = config_add (lci);
+ sfree (lci->children);
+ sfree (lci);
+ }
+
+ return status;
+} /* int config */
+
+
+// initialize curl for each host
+static int init_host (apache_t *st) /* {{{ */