From 838a303d38b973b5be5bce7724cca99bc82afdd8 Mon Sep 17 00:00:00 2001 From: Jan-Piet Mens Date: Sat, 5 Mar 2016 18:27:55 +0100 Subject: [PATCH] allow negative _geoprec --- README.md | 2 +- recorder.c | 26 ++++++++++++++------------ storage.c | 2 +- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 0d2bc51..800adc3 100644 --- a/README.md +++ b/README.md @@ -1093,5 +1093,5 @@ It actually is possible to gateway location publishes arriving via HTTP into MQT ### Override reverse-geo precision -If a payload is received with an element called `_geoprec` it contains an ovveride for the Recorder's configured reverse-geo precision. So, for example, if Recorder is running with precision 7, say, and the received payload contains `"_geoprec" : 2` the 2 will be used for this particular publish. This is not used in the OwnTracks apps, but it can be used with payloads you generate otherwise. +If a payload is received with an element called `_geoprec` it contains an overide for the Recorder's configured reverse-geo precision. So, for example, if Recorder is running with precision 7, say, and the received payload contains `"_geoprec" : 2` the 2 will be used for this particular publish. This is not used in the OwnTracks apps, but it can be used with payloads you generate otherwise. If `_geoprec` is negative, new reverse geo lookups will not be performed, but cached entries of `abs(_geoprec)` will be used. diff --git a/recorder.c b/recorder.c index 196fe90..997a829 100644 --- a/recorder.c +++ b/recorder.c @@ -849,7 +849,7 @@ void handle_message(void *userdata, char *topic, char *payload, size_t payloadle utstring_renew(ghash); utstring_renew(addr); utstring_renew(cc); - p = geohash_encode(lat, lon, geoprec); + p = geohash_encode(lat, lon, abs(geoprec)); if (p != NULL) { utstring_printf(ghash, "%s", p); free(p); @@ -870,19 +870,21 @@ void handle_message(void *userdata, char *topic, char *payload, size_t payloadle utstring_printf(addr, "%s", j->string_); } } else { - if ((geo = revgeo(ud, lat, lon, addr, cc)) != NULL) { - gcache_json_put(ud->gc, UB(ghash), geo); - } else { - /* We didn't obtain reverse Geo, maybe because of over - * quota; make a note of the missing geohash */ + if (geoprec > 0) { + if ((geo = revgeo(ud, lat, lon, addr, cc)) != NULL) { + gcache_json_put(ud->gc, UB(ghash), geo); + } else { + /* We didn't obtain reverse Geo, maybe because of over + * quota; make a note of the missing geohash */ - char gfile[BUFSIZ]; - FILE *fp; + char gfile[BUFSIZ]; + FILE *fp; - snprintf(gfile, BUFSIZ, "%s/ghash/missing", STORAGEDIR); - if ((fp = fopen(gfile, "a")) != NULL) { - fprintf(fp, "%s %lf %lf\n", UB(ghash), lat, lon); - fclose(fp); + snprintf(gfile, BUFSIZ, "%s/ghash/missing", STORAGEDIR); + if ((fp = fopen(gfile, "a")) != NULL) { + fprintf(fp, "%s %lf %lf\n", UB(ghash), lat, lon); + fclose(fp); + } } } } diff --git a/storage.c b/storage.c index db52242..d56d8b1 100644 --- a/storage.c +++ b/storage.c @@ -675,7 +675,7 @@ static JsonNode *line_to_location(char *line) geoprec = j->number_; } - if ((ghash = geohash_encode(lat, lon, geoprec)) != NULL) { + if ((ghash = geohash_encode(lat, lon, abs(geoprec))) != NULL) { json_append_member(o, "ghash", json_mkstring(ghash)); get_geo(o, ghash); free(ghash);