summaryrefslogtreecommitdiffstats
path: root/src/plugins/influxdb-writer.c
diff options
context:
space:
mode:
authorJohann CAHIER <johann.cahier@iot.bzh>2019-05-16 17:35:59 +0200
committerJohann CAHIER <johann.cahier@iot.bzh>2019-05-24 10:04:47 +0200
commit5dd410aab93c4ea5c3c04662585c072172ea5547 (patch)
tree3e8a46b7bf643bc918cda5a25872d5b43d4b632c /src/plugins/influxdb-writer.c
parent8c0851b6fdf7690ae25a6fbd83e0f2795a8cdf8b (diff)
Better memory management in chained list
key is now managed internally, using a copy. add_elt() / add_key() now provide a 'suffix' parameter. If suffix is given, it is appended to the key. If NULL, or empty string ("") is given, nothing is appended. NOTE : value is still owned by json object. Bug-AGL: SPEC-2416 Change-Id: I624a2dd211801c2d24b2c6739f2c7536a047ea32 Signed-off-by: Johann CAHIER <johann.cahier@iot.bzh>
Diffstat (limited to 'src/plugins/influxdb-writer.c')
-rw-r--r--src/plugins/influxdb-writer.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/plugins/influxdb-writer.c b/src/plugins/influxdb-writer.c
index 2815b19..a7ce8fc 100644
--- a/src/plugins/influxdb-writer.c
+++ b/src/plugins/influxdb-writer.c
@@ -136,7 +136,7 @@ CURL *make_curl_write_post(afb_api_t apiHandle, const char *url, json_object *me
curl_wrap_prepare_post_unescaped(url, NULL, "\n", (const char * const*)post_data) : NULL;
free(serie);
for(i = 0; i < lpd; i++)
- free(post_data[i]);
+ if (post_data[i]) free(post_data[i]);
free(post_data);
return curl;
@@ -155,6 +155,7 @@ CTLP_CAPI(write_to_influxdb, source, argsJ, eventJ)
const char *port = NULL;
const char *host = NULL;
CURL *curl_request;
+ int rc = -1;
json_object *req_args = afb_req_json(request),
*portJ = NULL,
@@ -163,15 +164,17 @@ CTLP_CAPI(write_to_influxdb, source, argsJ, eventJ)
if(wrap_json_unpack(req_args, "{s?s,s?o,so!}",
"host", &host,
"port", &portJ,
- "metric", &metric) || ! metric)
+ "metric", &metric) || ! metric) {
afb_req_fail(request, "Failed", "Error processing arguments. Miss metric\
JSON object or malformed");
- else
+ rc = -1;
+ } else {
port = json_object_is_type(portJ, json_type_null) ?
NULL : json_object_to_json_string(portJ);
+ curl_request = influxdb_write(source->api, host, port, metric);
+ curl_wrap_do(curl_request, influxdb_write_curl_cb, request);
+ rc = 0;
+ }
- curl_request = influxdb_write(source->api, host, port, metric);
- curl_wrap_do(curl_request, influxdb_write_curl_cb, request);
-
- return 0;
+ return rc;
}