+ 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)
+ {
+ int status;
+
+ status = ssnprintf (credentials, sizeof (credentials), "%s:%s",
+ st->user, (st->pass == NULL) ? "" : st->pass);
+ if ((status < 0) || ((size_t) status >= sizeof (credentials)))
+ {
+ ERROR ("apache plugin: init_host: Returning an error "
+ "because the credentials have been "
+ "truncated.");
+ curl_easy_cleanup (st->curl);
+ st->curl = NULL;
+ return (-1);
+ }
+
+ curl_easy_setopt (st->curl, CURLOPT_USERPWD, credentials);
+ }
+
+ curl_easy_setopt (st->curl, CURLOPT_URL, st->url);
+ curl_easy_setopt (st->curl, CURLOPT_FOLLOWLOCATION, 1);
+
+ if (st->verify_peer != 0)
+ {
+ curl_easy_setopt (st->curl, CURLOPT_SSL_VERIFYPEER, 1);
+ }
+ else
+ {
+ curl_easy_setopt (st->curl, CURLOPT_SSL_VERIFYPEER, 0);
+ }
+
+ if (st->verify_host != 0)
+ {
+ curl_easy_setopt (st->curl, CURLOPT_SSL_VERIFYHOST, 2);
+ }
+ else
+ {
+ curl_easy_setopt (st->curl, CURLOPT_SSL_VERIFYHOST, 0);
+ }
+
+ if (st->cacert != NULL)
+ {
+ curl_easy_setopt (st->curl, CURLOPT_CAINFO, st->cacert);
+ }
+
+ return (0);
+} /* }}} int init_host */
+
+static void submit_value (const char *type, const char *type_instance,
+ value_t value, apache_t *st)
+{
+ value_list_t vl = VALUE_LIST_INIT;
+
+ vl.values = &value;
+ vl.values_len = 1;
+
+ sstrncpy (vl.host, (st->host != NULL) ? st->host : hostname_g,
+ sizeof (vl.host));
+
+ sstrncpy (vl.plugin, "apache", sizeof (vl.plugin));
+ if (st->name != NULL)
+ sstrncpy (vl.plugin_instance, st->name,
+ sizeof (vl.plugin_instance));