curl_easy_setopt (cb->curl, CURLOPT_NOSIGNAL, 1L);
curl_easy_setopt (cb->curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
- cb->headers = NULL;
cb->headers = curl_slist_append (cb->headers, "Accept: */*");
if (cb->format == WH_FORMAT_JSON)
cb->headers = curl_slist_append (cb->headers, "Content-Type: application/json");
if (cb->pass != NULL)
credentials_size += strlen (cb->pass);
- cb->credentials = (char *) malloc (credentials_size);
+ cb->credentials = malloc (credentials_size);
if (cb->credentials == NULL)
{
ERROR ("curl plugin: malloc failed.");
return (0);
} /* }}} int config_set_format */
+static int wh_config_append_string (const char *name, struct curl_slist **dest, /* {{{ */
+ oconfig_item_t *ci)
+{
+ struct curl_slist *temp = NULL;
+ if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
+ {
+ WARNING ("write_http plugin: `%s' needs exactly one string argument.", name);
+ return (-1);
+ }
+
+ temp = curl_slist_append(*dest, ci->values[0].value.string);
+ if (temp == NULL)
+ return (-1);
+
+ *dest = temp;
+
+ return (0);
+} /* }}} int wh_config_append_string */
+
static int wh_config_node (oconfig_item_t *ci) /* {{{ */
{
wh_callback_t *cb;
int status = 0;
int i;
- cb = malloc (sizeof (*cb));
+ cb = calloc (1, sizeof (*cb));
if (cb == NULL)
{
- ERROR ("write_http plugin: malloc failed.");
+ ERROR ("write_http plugin: calloc failed.");
return (-1);
}
- memset (cb, 0, sizeof (*cb));
cb->verify_peer = 1;
cb->verify_host = 1;
cb->format = WH_FORMAT_COMMAND;
status = cf_util_get_int (child, &cb->timeout);
else if (strcasecmp ("LogHttpError", child->key) == 0)
status = cf_util_get_boolean (child, &cb->log_http_error);
+ else if (strcasecmp ("Header", child->key) == 0)
+ status = wh_config_append_string ("Header", &cb->headers, child);
else
{
ERROR ("write_http plugin: Invalid configuration "