support waypoints dump

for https://github.com/owntracks/ios/issues/346
This commit is contained in:
Jan-Piet Mens
2015-10-20 08:41:32 +02:00
parent a11ddb1392
commit 92e1a0d7c3
2 changed files with 32 additions and 2 deletions

View File

@@ -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.

View File

@@ -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: