From d4df7fd73d8b9630095ee0ff2444ab11d8e218b1 Mon Sep 17 00:00:00 2001 From: Jan-Piet Mens Date: Tue, 25 Aug 2015 16:44:14 +0200 Subject: [PATCH] RECORDER: [NEW]: keep track of original username/device name in LAST --- ot-recorder.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/ot-recorder.c b/ot-recorder.c index 14020b2..b20123d 100644 --- a/ot-recorder.c +++ b/ot-recorder.c @@ -531,6 +531,7 @@ void on_message(struct mosquitto *mosq, void *userdata, const struct mosquitto_m * Add a few bits to the JSON, and record it on a per-user/device basis. json_append_member(json, "ghash", json_mkstring(utstring_body(ghash))); */ + if ((jsonstring = json_stringify(json, NULL)) != NULL) { @@ -542,22 +543,32 @@ void on_message(struct mosquitto *mosq, void *userdata, const struct mosquitto_m #endif if (ud->usefiles) { + char *js; + if ((fp = pathn("a", "rec", username, device, "rec")) != NULL) { fprintf(fp, RECFORMAT, isotime(now), "*", jsonstring); fclose(fp); } - /* Now safewrite the last location */ - utstring_printf(ts, "%s/last/%s/%s", - STORAGEDIR, utstring_body(username), utstring_body(device)); - if (mkpath(utstring_body(ts)) < 0) { - perror(utstring_body(ts)); - } - utstring_printf(ts, "/%s-%s.json", - utstring_body(username), utstring_body(device)); - safewrite(utstring_body(ts), jsonstring); + /* Keep track of original username & device name in LAST. */ + json_append_member(json, "username", json_mkstring(utstring_body(username))); + json_append_member(json, "device", json_mkstring(utstring_body(device))); + + if ((js = json_stringify(json, NULL)) != NULL) { + /* Now safewrite the last location */ + utstring_printf(ts, "%s/last/%s/%s", + STORAGEDIR, utstring_body(username), utstring_body(device)); + if (mkpath(utstring_body(ts)) < 0) { + perror(utstring_body(ts)); + } + utstring_printf(ts, "/%s-%s.json", + utstring_body(username), utstring_body(device)); + + safewrite(utstring_body(ts), js); + free(js); + } } free(jsonstring); }