From a2989e8c70eebf08178bc4189dfa43a3a03ad576 Mon Sep 17 00:00:00 2001 From: Jan-Piet Mens Date: Mon, 26 Oct 2015 19:00:21 +0100 Subject: [PATCH] allow extra.json closes #60 --- README.md | 2 +- storage.c | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a6b5ce1..0c18688 100644 --- a/README.md +++ b/README.md @@ -359,7 +359,7 @@ As mentioned earlier, data is stored in files, and these files are relative to ` * `cards/`, optional, contains user cards which are published when either you or one of your trackers on Hosted adds a new device. This card is then stored here and used with, e.g., `ocat --last` to show a user's name and optional avatar. * `config/`, optional, contains the JSON of a [device configuration](http://owntracks.org/booklet/features/remoteconfig/) (`.otrc`) which was requested remotely via a [dump command](http://owntracks.org/booklet/tech/json/#_typecmd). Note that this will contain sensitive data. You can use this `.otrc` file to restore the OwnTracks configuration on your device by copying to the device and opening it in OwnTracks. * `ghash/`, unless disabled, reverse Geo data is collected into an LMDB database located in this directory. This LMDB database also contains named databases which are used by your optional Lua hooks, as well as a `topic2tid` database which can be used for TID re-mapping. -* `last/` contains the last location published by devices. E.g. Jane's last publish from her iPhone would be in `last/jjolie/iphone/jjolie-iphone.json`. The JSON payload contained therein is enhanced with the fields `user`, `device`, `topic`, and `ghash`. +* `last/` contains the last location published by devices. E.g. Jane's last publish from her iPhone would be in `last/jjolie/iphone/jjolie-iphone.json`. The JSON payload contained therein is enhanced with the fields `user`, `device`, `topic`, and `ghash`. If a device's `last/` directory contains a file called `extra.json` (i.e. matching the example, this would be `last/jjolie/iphone/extra.json`), the content of this file is merged into the existing JSON for this user and returned by the API. Note, that you cannot overwrite existing values. So, an `extra.json` containing `{ "tst" : 11 }` will do nothing because the `tst` element we obtain from location data overrules, but adding `{ "beverage" : "water" }` will do what you want. * `monitor` a file which contains a timestamp and the last received topic (see Monitoring below). * `msg/` contains messages received by the Messaging system. * `photos/` optional; contains the binary photos from a _card_. diff --git a/storage.c b/storage.c index 08abfd0..4a81f1d 100644 --- a/storage.c +++ b/storage.c @@ -82,6 +82,7 @@ void storage_gcache_load(char *lmdbname) } #endif /* !LMDB */ + void get_geo(JsonNode *o, char *ghash) { #ifdef WITH_LMDB @@ -176,6 +177,11 @@ void append_device_details(JsonNode *userlist, char *user, char *device) get_geo(last, node->string_); } } + + /* Extra data */ + snprintf(path, BUFSIZ, "%s/last/%s/%s/extra.json", + STORAGEDIR, user, device); + json_copy_from_file(last, path); } /*