aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.vscode/settings.json3
-rw-r--r--src/plugins/influxdb-writer.c4
-rw-r--r--src/plugins/influxdb.h75
3 files changed, 68 insertions, 14 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json
index c3366cb..8337700 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -21,7 +21,8 @@
"type_traits": "c",
"influxdb.h": "c",
"tsdb.h": "c",
- "ctl-plugin.h": "c"
+ "ctl-plugin.h": "c",
+ "escape.h": "c"
},
"C_Cpp.intelliSenseEngineFallback": "Disabled",
"C_Cpp.errorSquiggles": "Disabled",
diff --git a/src/plugins/influxdb-writer.c b/src/plugins/influxdb-writer.c
index aaa8991..be02e34 100644
--- a/src/plugins/influxdb-writer.c
+++ b/src/plugins/influxdb-writer.c
@@ -56,7 +56,7 @@ static size_t format_write_args(char *query, struct series_t *serie)
struct list *tags = serie->serie_columns.tags;
struct list *fields = serie->serie_columns.fields;
- strncat(query, serie->name, strlen(serie->name));
+ concatenate(query, serie->name, NULL);
if(tags) {
while(tags != NULL) {
concatenate(query, tags->key, ",");
@@ -132,6 +132,8 @@ CURL *make_curl_write_post(AFB_ApiT apiHandle, const char *url, json_object *met
}
}
+ AFB_ApiDebug(apiHandle, "influx curl: url=%s data=%s", url, (const char*) *post_data);
+
/* Check that we just do not broke the for loop before trying preparing CURL
request object */
curl = i == lpd ?
diff --git a/src/plugins/influxdb.h b/src/plugins/influxdb.h
index 0f06dda..88ea2bc 100644
--- a/src/plugins/influxdb.h
+++ b/src/plugins/influxdb.h
@@ -21,32 +21,83 @@
#define _GNU_SOURCE
#include <string.h>
+#include "../utils/list.h"
#include "ctl-plugin.h"
-#include "wrap-json.h"
#include "tsdb.h"
-#include "../utils/list.h"
+#include "wrap-json.h"
struct serie_columns_t {
- struct list *tags;
- struct list *fields;
+ struct list* tags;
+ struct list* fields;
};
struct series_t {
- const char *name;
- struct serie_columns_t serie_columns;
- uint64_t timestamp;
+ const char* name;
+ struct serie_columns_t serie_columns;
+ uint64_t timestamp;
};
int create_database(AFB_ReqT request);
-int unpack_metric_from_api(json_object *m, struct series_t *serie);
+int unpack_metric_from_api(json_object* m, struct series_t* serie);
+
+static inline int should_escape(char c)
+{
+ switch (c) {
+ case ',':
+ case '=':
+ case ' ':
+ case '"':
+ return 1;
+ break;
+ }
+ return 0;
+}
+
+static inline char* escape_chr(const char* src)
+{
+ int j, i = 0;
+ size_t len, src_len;
+ char* res;
+
+ len = src_len = strlen(src);
+ while (i < src_len) {
+ if (should_escape(src[i++]))
+ len++;
+ }
+
+ if (len == src_len) {
+ res = strdup(src);
+ } else {
+ res = malloc(len + 1);
+ if (res) {
+ i = j = 0;
+ while (i < src_len) {
+ if (should_escape(src[i]))
+ res[j++] = '\\';
+ res[j++] = src[i++];
+ }
+ }
+ res[j] = '\0';
+ }
+ return res;
+}
-static inline void concatenate(char* dest, const char* source, const char *sep)
+static inline void concatenate(char* dest, const char* source, const char* sep)
{
- strncat(dest, sep, strlen(sep));
- strncat(dest, source, strlen(source));
+ char* esc_source;
+
+ if (sep)
+ strncat(dest, sep, strlen(sep));
+
+ esc_source = escape_chr(source);
+
+ strncat(dest, esc_source, strlen(esc_source));
+
+ if (esc_source)
+ free(esc_source);
}
-size_t make_url(char *url, size_t l_url, const char *host, const char *port, const char *endpoint);
+size_t make_url(char* url, size_t l_url, const char* host, const char* port, const char* endpoint);
#endif