X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fwrite_http.c;h=8dd37c45ad189e2dfbf4265410d37a5b96382bb6;hb=db35efb33e81d0a013e09a8a6ffa362ad5962f7c;hp=c817749f0b0bd93cec839176972d63ceb8a7e490;hpb=09c12e0e1e0ef340a7074146684650ed54cba64d;p=collectd.git diff --git a/src/write_http.c b/src/write_http.c index c817749f..8dd37c45 100644 --- a/src/write_http.c +++ b/src/write_http.c @@ -156,7 +156,6 @@ static int wh_callback_init (wh_callback_t *cb) /* {{{ */ 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"); @@ -241,7 +240,7 @@ static int wh_flush_nolock (cdtime_t timeout, wh_callback_t *cb) /* {{{ */ if (cb->format == WH_FORMAT_COMMAND) { - if (cb->send_buffer_fill <= 0) + if (cb->send_buffer_fill == 0) { cb->send_buffer_init_time = cdtime (); return (0); @@ -540,6 +539,25 @@ static int config_set_format (wh_callback_t *cb, /* {{{ */ 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; @@ -642,6 +660,8 @@ static int wh_config_node (oconfig_item_t *ci) /* {{{ */ 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 "