summaryrefslogtreecommitdiffstats
path: root/src/plugins/influxdb.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.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.c')
-rw-r--r--src/plugins/influxdb.c30
1 files changed, 7 insertions, 23 deletions
diff --git a/src/plugins/influxdb.c b/src/plugins/influxdb.c
index 2cfd551..b8f85d2 100644
--- a/src/plugins/influxdb.c
+++ b/src/plugins/influxdb.c
@@ -117,28 +117,12 @@ int create_database(afb_req_t request)
void unpack_values(void* l, json_object* valuesJ, const char* key)
{
- struct list** oneList = (struct list**)l;
-
- /* Append a suffix to be able to differentiate tags and fields at reading
- time */
- char* suffixed_key = calloc(1, strlen(key) + 3);
- strcpy(suffixed_key, key);
- // strcat(suffixed_key, "_f");
-
- add_elt(oneList, suffixed_key, valuesJ);
+ add_elt((struct list**)l, key, "", valuesJ);
}
void unpack_metadata(void* l, json_object* valuesJ, const char* key)
{
- struct list** oneList = (struct list**)l;
-
- /* Append a suffix to be able to differentiate tags and fields at reading
- time */
- char* suffixed_key = calloc(1, strlen(key) + 3);
- strcpy(suffixed_key, key);
- // strcat(suffixed_key, "_t");
-
- add_elt(oneList, suffixed_key, valuesJ);
+ add_elt((struct list**)l, key, "", valuesJ);
}
void unpacking_from_api(void* s, json_object* valueJ, const char* key)
@@ -156,13 +140,13 @@ void unpacking_from_api(void* s, json_object* valueJ, const char* key)
else if (strcasecmp("value", key) == 0 || strcasecmp("values", key) == 0)
wrap_json_object_for_all(valueJ, unpack_values, (void*)&serie->serie_columns.fields);
/* Treat all key looking for tag and field object. Those ones could be find
- with the last 2 character. '_t' for tag and '_f' that are the keys that
- could be indefinite. Cf influxdb documentation:
- https://docs.influxdata.com/influxdb/v1.5/write_protocols/line_protocol_reference/ */
+ with the last 2 character. '_t' for tag and '_f' that are the keys that
+ could be indefinite. Cf influxdb documentation:
+ https://docs.influxdata.com/influxdb/v1.5/write_protocols/line_protocol_reference/ */
else if (strncasecmp(&key[key_length - 2], "_t", 2) == 0)
- add_elt(&serie->serie_columns.tags, key, valueJ);
+ add_elt(&serie->serie_columns.tags, key, "", valueJ);
else if (strncasecmp(&key[key_length - 2], "_f", 2) == 0)
- add_elt(&serie->serie_columns.fields, key, valueJ);
+ add_elt(&serie->serie_columns.fields, key, "", valueJ);
}
int unpack_metric_from_api(json_object* m, struct series_t* serie)