From 92e1a0d7c3e11024213aebbd9e465d3d771ae402 Mon Sep 17 00:00:00 2001 From: Jan-Piet Mens Date: Tue, 20 Oct 2015 08:41:32 +0200 Subject: [PATCH] support waypoints dump for https://github.com/owntracks/ios/issues/346 --- README.md | 2 +- recorder.c | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 78f20a6..f7e7a9c 100644 --- a/README.md +++ b/README.md @@ -306,7 +306,7 @@ As mentioned earlier, data is stored in files, and these files are relative to ` * `msg/` contains messages received by the Messaging system. * `photos/` optional; contains the binary photos from a _card_. * `rec/` the recorder data proper. One subdirectory per user, one subdirectory therein per device. Data files are named `YYYY-MM.rec` (e.g. `2015-08.rec` for the data accumulated during the month of August 2015. -* `waypoints/` contains a directory per user and device. Therein are individual files named by a timestamp with the JSON payload of published (i.e. shared) waypoints. The file names are timestamps because the `tst` of a waypoint is its key. +* `waypoints/` contains a directory per user and device. Therein are individual files named by a timestamp with the JSON payload of published (i.e. shared) waypoints. The file names are timestamps because the `tst` of a waypoint is its key. If a user publishes all waypoints from a device (Publish Waypoints), the payload is stored in this directory as `dump.json`. You should definitely **not** modify or touch these files: they remain under the control of the _recorder_. You can of course, remove old `.rec` files if they consume too much space. diff --git a/recorder.c b/recorder.c index a710666..6c1809e 100644 --- a/recorder.c +++ b/recorder.c @@ -322,6 +322,34 @@ static void putrec(struct udata *ud, time_t now, UT_string *reltopic, UT_string } } +/* + * Payload contains JSON string with an array of waypoints. Dump + * these into a single file. + */ + +void waypoints_dump(struct udata *ud, UT_string *username, UT_string *device, char *payloadstring) +{ + static UT_string *ts = NULL; + + utstring_renew(ts); + + utstring_printf(ts, "%s/%s/%s/%s", + STORAGEDIR, + "waypoints", + UB(username), + UB(device)); + if (mkpath(UB(ts)) < 0) { + olog(LOG_ERR, "Cannot mkdir %s: %m", UB(ts)); + return; + } + + utstring_printf(ts, "/dump.json"); + if (ud->verbose) { + printf("Received waypoints dump, storing at %s\n", UB(ts)); + } + safewrite(UB(ts), payloadstring); +} + void on_message(struct mosquitto *mosq, void *userdata, const struct mosquitto_message *m) { JsonNode *json, *j, *geo = NULL; @@ -467,9 +495,11 @@ void on_message(struct mosquitto *mosq, void *userdata, const struct mosquitto_m case T_CONFIG: case T_LWT: case T_STEPS: - case T_WAYPOINTS: putrec(ud, now, reltopic, username, device, bindump(m->payload, m->payloadlen)); goto cleanup; + case T_WAYPOINTS: + waypoints_dump(ud, username, device, m->payload); + goto cleanup; case T_WAYPOINT: case T_TRANSITION: case T_LOCATION: