support for tz is now optional

This commit is contained in:
Jan-Piet Mens 2024-01-30 21:19:17 +01:00
parent 25cb0c3fa4
commit 5933b45715
7 changed files with 27 additions and 7 deletions

View File

@ -15,8 +15,7 @@ OTR_OBJS = json.o \
util.o \
storage.o \
fences.o \
listsort.o \
zonedetect.o
listsort.o
OTR_EXTRA_OBJS =
CFLAGS += -DGHASHPREC=$(GHASHPREC)
@ -77,6 +76,13 @@ ifeq ($(WITH_GREENWICH),yes)
CFLAGS += -DWITH_GREENWICH=1
endif
ifeq ($(WITH_TZ),yes)
CFLAGS += -DWITH_TZ
CFLAGS += -DTZDATADB=\"$(TZDATADB)\"
OTR_EXTRA_OBJS += zonedetect.o
OCAT_EXTRA_OBJS += zonedetect.o
endif
ifeq ($(JSON_INDENT),yes)
CFLAGS += -DJSON_INDENT="\" \""
else
@ -86,7 +92,6 @@ endif
CFLAGS += -DSTORAGEDEFAULT=\"$(STORAGEDEFAULT)\" -DDOCROOT=\"$(DOCROOT)\"
CFLAGS += -DCONFIGFILE=\"$(CONFIGFILE)\"
CFLAGS += -DGEOCODE_TIMEOUT=$(GEOCODE_TIMEOUT)
CFLAGS += -DTZDATADB=\"$(TZDATADB)\"
TARGETS += ot-recorder ocat
@ -101,8 +106,8 @@ ot-recorder: recorder.o $(OTR_OBJS) $(OTR_EXTRA_OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) -o ot-recorder recorder.o $(OTR_OBJS) $(OTR_EXTRA_OBJS) $(LIBS)
if test -r codesign.sh; then /bin/sh codesign.sh; fi
ocat: ocat.o $(OTR_OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) -o ocat ocat.o $(OTR_OBJS) $(LIBS)
ocat: ocat.o $(OTR_OBJS) $(OCAT_EXTRA_OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) -o ocat ocat.o $(OTR_OBJS) $(OCAT_EXTRA_OBJS) $(LIBS)
$(OTR_OBJS): config.mk Makefile

View File

@ -68,7 +68,9 @@ STORAGEDEFAULT = /var/spool/owntracks/recorder/store
# Where should the recorder find its document root (HTTP)?
DOCROOT = /var/spool/owntracks/recorder/htdocs
# Where will the recorder find the TZ data file?
# Should we support $TZ lookup in API data? If so, specify
# path to the database
WITH_TZ ?= yes
TZDATADB = /usr/share/owntracks/recorder/timezone16.bin

View File

@ -12,6 +12,7 @@ WITH_PING ?= yes
WITH_KILL ?= yes
WITH_ENCRYPT ?= yes
WITH_GREENWICH ?= yes
WITH_TZ ?= yes
STORAGEDEFAULT = /var/spool/owntracks/recorder/store
DOCROOT = /usr/share/owntracks/recorder/htdocs

View File

@ -13,6 +13,7 @@ WITH_PING ?= yes
WITH_KILL ?= yes
WITH_ENCRYPT ?= yes
WITH_GREENWICH ?= yes
WITH_TZ ?= yes
STORAGEDEFAULT = /var/spool/owntracks/recorder/store
DOCROOT = /usr/share/owntracks/recorder/htdocs

View File

@ -1986,7 +1986,9 @@ int main(int argc, char **argv)
#endif
olog(LOG_INFO, "Using storage at %s with precision %d", STORAGEDIR, geohash_prec());
#ifdef WITH_TZ
olog(LOG_INFO, "TZDATADB is at %s", TZDATADB);
#endif
while (run) {
#ifdef WITH_MQTT

View File

@ -37,7 +37,6 @@
#include "gcache.h"
#include "util.h"
#include "listsort.h"
#include "zonedetect.h"
char STORAGEDIR[BUFSIZ] = STORAGEDEFAULT;
@ -45,7 +44,11 @@ char STORAGEDIR[BUFSIZ] = STORAGEDEFAULT;
#define LARGEBUF (BUFSIZ * 2)
static struct gcache *gc = NULL;
#ifdef WITH_TZ
# include "zonedetect.h"
static ZoneDetect *zdb = NULL;
#endif
void storage_init(int revgeo)
{
@ -61,9 +64,11 @@ void storage_init(int revgeo)
}
}
#ifdef WITH_TZ
if (zdb == NULL) {
zdb = ZDOpenDatabase(TZDATADB);
}
#endif
}
void storage_gcache_dump(char *lmdbname)
@ -716,6 +721,7 @@ static JsonNode *line_to_location(char *line)
json_append_member(o, "isotst", json_mkstring(isotime(tst)));
json_append_member(o, "disptst", json_mkstring(disptime(tst)));
#ifdef WITH_TZ
if (zdb) {
char *tz_str = ZDHelperSimpleLookupString(zdb, lat, lon);
@ -726,6 +732,7 @@ static JsonNode *line_to_location(char *line)
ZDHelperSimpleLookupStringFree(tz_str);
}
}
#endif
return (o);

2
util.c
View File

@ -64,6 +64,7 @@ const char *disptime(time_t t) {
return(buf);
}
#ifdef WITH_TZ
const char *isolocal(long tst, char *tzname)
{
char old_tz[64] = "UTC", *p;
@ -83,6 +84,7 @@ const char *isolocal(long tst, char *tzname)
setenv("TZ", old_tz, 1);
return local;
}
#endif
char *slurp_file(char *filename, int fold_newlines)
{