+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));
+ }
+
+ 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->values);
+ sfree (lci->children);
+ sfree (lci);
+ }
+
+ return status;
+} /* int config */
+
+/* initialize curl for each host */
+static int init_host (apache_t *st) /* {{{ */
+{
+ static char credentials[1024];
+
+ assert (st->url != NULL);
+ /* (Assured by `config_add') */
+
+ if (st->curl != NULL)
+ {
+ curl_easy_cleanup (st->curl);
+ st->curl = NULL;
+ }
+
+ if ((st->curl = curl_easy_init ()) == NULL)
+ {
+ ERROR ("apache plugin: init_host: `curl_easy_init' failed.");
+ return (-1);
+ }
+
+ curl_easy_setopt (st->curl, CURLOPT_WRITEFUNCTION, apache_curl_callback);
+ curl_easy_setopt (st->curl, CURLOPT_WRITEDATA, st);
+
+ /* not set as yet if the user specified string doesn't match apache or
+ * lighttpd, then ignore it. Headers will be parsed to find out the
+ * server type */
+ st->server_type = -1;
+
+ if (st->server != NULL)
+ {
+ if (strcasecmp(st->server, "apache") == 0)
+ st->server_type = APACHE;
+ else if (strcasecmp(st->server, "lighttpd") == 0)
+ st->server_type = LIGHTTPD;
+ else
+ WARNING ("apache plugin: Unknown `Server' setting: %s",
+ st->server);
+ }
+
+ /* if not found register a header callback to determine the server_type */
+ if (st->server_type == -1)
+ {
+ curl_easy_setopt (st->curl, CURLOPT_HEADERFUNCTION, apache_header_callback);
+ curl_easy_setopt (st->curl, CURLOPT_WRITEHEADER, st);
+ }
+
+ curl_easy_setopt (st->curl, CURLOPT_USERAGENT, PACKAGE_NAME"/"PACKAGE_VERSION);
+ curl_easy_setopt (st->curl, CURLOPT_ERRORBUFFER, st->apache_curl_error);
+
+ if (st->user != NULL)