diff --git a/Makefile b/Makefile index e5a0be4..09a3ca2 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,11 @@ OTR_EXTRA_OBJS = CFLAGS += -DGHASHPREC=$(GHASHPREC) +CFLAGS += -Imdb/ +OTR_OBJS += gcache.o +LIBS += mdb/liblmdb.a -lpthread +TARGETS += mdb/liblmdb.a + ifeq ($(WITH_MQTT),yes) CFLAGS += -DWITH_MQTT=1 CFLAGS += $(MOSQUITTO_INC) @@ -45,15 +50,8 @@ endif ifeq ($(WITH_RONLY),yes) CFLAGS += -DWITH_RONLY=1 - WITH_LMDB = yes endif -ifeq ($(WITH_LMDB),yes) - CFLAGS += -DWITH_LMDB=1 -Imdb/ - OTR_OBJS += gcache.o - LIBS += mdb/liblmdb.a -lpthread - TARGETS += mdb/liblmdb.a -endif ifeq ($(WITH_HTTP),yes) CFLAGS += -DWITH_HTTP=1 diff --git a/README.md b/README.md index 4665aa3..d6e04d5 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ You will require: * [libmosquitto](http://mosquitto.org), but see below for platform instructions * [libCurl](http://curl.haxx.se/libcurl/) -* [lmdb](http://symas.com/mdb) (included). While the use of lmdb is optional, we strongly recommend you configure the _recorder_ to use it. +* [lmdb](http://symas.com/mdb) (included) * Optionally [Lua](http://lua.org) 1. Obtain and download the software, via [our Homebrew Tap](https://github.com/owntracks/homebrew-recorder) on Mac OS X, directly as a clone of the repository, or as a [tar ball](https://github.com/owntracks/recorder/releases) which you unpack. diff --git a/config.mk.in b/config.mk.in index a3c015f..821b7d0 100644 --- a/config.mk.in +++ b/config.mk.in @@ -8,9 +8,6 @@ WITH_MQTT ?= yes # Do you want recorder's built-in HTTP REST API? WITH_HTTP ?= yes -# Do you want to use reverse-geo caching? (Highly recommended) -WITH_LMDB ?= yes - # Do you have Lua libraries installed and want the Lua hook integration? WITH_LUA ?= no diff --git a/etc/centos/config.mk.in b/etc/centos/config.mk.in index b440049..4a026c9 100644 --- a/etc/centos/config.mk.in +++ b/etc/centos/config.mk.in @@ -5,7 +5,6 @@ CONFIGFILE = /etc/default/ot-recorder WITH_MQTT ?= yes WITH_HTTP ?= yes -WITH_LMDB ?= yes WITH_LUA ?= yes WITH_PING ?= yes WITH_KILL ?= no diff --git a/etc/debian/config.mk.in b/etc/debian/config.mk.in index 964a197..d19e93e 100644 --- a/etc/debian/config.mk.in +++ b/etc/debian/config.mk.in @@ -5,7 +5,6 @@ CONFIGFILE = /etc/default/ot-recorder WITH_MQTT ?= yes WITH_HTTP ?= yes -WITH_LMDB ?= yes WITH_LUA ?= yes WITH_PING ?= yes WITH_KILL ?= no diff --git a/gcache.h b/gcache.h index df283c5..df74163 100644 --- a/gcache.h +++ b/gcache.h @@ -1,8 +1,6 @@ #ifndef _GCACHE_H_INCLUDED_ # define _GCACHE_H_INCLUDED_ -#ifdef WITH_LMDB - #include "json.h" #include "lmdb.h" @@ -24,4 +22,3 @@ void gcache_load(char *path, char *lmdbname); int gcache_del(struct gcache *gc, char *keystr); #endif -#endif diff --git a/hooks.c b/hooks.c index 14e1814..31645c7 100644 --- a/hooks.c +++ b/hooks.c @@ -38,12 +38,10 @@ static int otr_log(lua_State *lua); static int otr_strftime(lua_State *lua); -#if WITH_LMDB static int otr_putdb(lua_State *lua); static int otr_getdb(lua_State *lua); static struct gcache *LuaDB = NULL; -#endif /* @@ -98,19 +96,15 @@ struct luadata *hooks_init(struct udata *ud, char *script) lua_pushcfunction(ld->L, otr_strftime); lua_setfield(ld->L, -2, "strftime"); -#if WITH_LMDB lua_pushcfunction(ld->L, otr_putdb); lua_setfield(ld->L, -2, "putdb"); lua_pushcfunction(ld->L, otr_getdb); lua_setfield(ld->L, -2, "getdb"); -#endif lua_setglobal(ld->L, "otr"); -#ifdef WITH_LMDB LuaDB = ud->luadb; -#endif olog(LOG_DEBUG, "initializing Lua hooks from `%s'", script); @@ -294,8 +288,6 @@ static int otr_strftime(lua_State *lua) return (0); } -#ifdef WITH_LMDB - /* * Requires two string arguments: key, value * These are written into the named LMDB database @@ -335,5 +327,4 @@ static int otr_getdb(lua_State *lua) } return (rc); } -#endif /* LMDB */ #endif /* WITH_LUA */ diff --git a/http.c b/http.c index bb0b8ab..1490c11 100644 --- a/http.c +++ b/http.c @@ -682,9 +682,7 @@ static int dispatch(struct mg_connection *conn, const char *uri) char *time_from = NULL, *time_to = NULL; time_t s_lo, s_hi; JsonNode *json, *obj, *locs; -#ifdef WITH_LMDB struct udata *ud = (struct udata *)conn->server_param; -#endif if ((nparts = splitter((char *)uri, "/", uparts)) == -1) { @@ -859,7 +857,6 @@ static int dispatch(struct mg_connection *conn, const char *uri) } } -#ifdef WITH_LMDB if (nparts == 1 && !strcmp(uparts[0], "q")) { JsonNode *geo = NULL; char *lat = field(conn, "lat"); @@ -879,7 +876,6 @@ static int dispatch(struct mg_connection *conn, const char *uri) return (json_response(conn, geo)); } -#endif CLEANUP; // mg_printf_data(conn, "user=[%s], device=[%s]\n", (u) ? u : "", (d) ? d : ""); @@ -1007,9 +1003,7 @@ static int authorize(struct mg_connection *conn) int ev_handler(struct mg_connection *conn, enum mg_event ev) { -#ifdef WITH_LMDB struct udata *ud = (struct udata *)conn->server_param; -#endif switch (ev) { case MG_AUTH: @@ -1079,7 +1073,6 @@ int ev_handler(struct mg_connection *conn, enum mg_event ev) if (!strcmp(conn->request_method, "POST")) { -#ifdef WITH_LMDB if (!strcmp(conn->uri, "/block")) { int blocked = TRUE; char buf[BUFSIZ], *u; @@ -1094,7 +1087,6 @@ int ev_handler(struct mg_connection *conn, enum mg_event ev) mg_printf_data(conn, "User %s %s", buf, (blocked) ? "BLOCKED" : "UNblocked"); return (MG_TRUE); } -#endif } /* * We can't handle this request ourselves. Return diff --git a/ocat.c b/ocat.c index 6321d59..ff0cba2 100644 --- a/ocat.c +++ b/ocat.c @@ -74,9 +74,7 @@ void usage(char *prog) printf(" --norevgeo -G disable ghash to reverge-geo lookups\n"); printf(" --precision ghash precision (dflt: %d)\n", GHASHPREC); printf(" --version -v print version information\n"); -#if WITH_LMDB printf(" --dump / --load [] dump/load content of db (default ghash)\n"); -#endif printf("\n"); printf("Options override these environment variables:\n"); printf(" $OCAT_USERNAME\n"); @@ -91,9 +89,6 @@ void print_versioninfo() { printf("This is OwnTracks Recorder, version %s\n", VERSION); printf("built with:\n"); -#ifdef WITH_LMDB - printf("\tWITH_LMDB = yes\n"); -#endif #ifdef WITH_LUA printf("\tWITH_LUA = yes\n"); #endif @@ -124,9 +119,7 @@ void print_versioninfo() LIBMOSQUITTO_MINOR, LIBMOSQUITTO_REVISION); #endif -#ifdef WITH_LMDB printf("\tMDB VERSION = %s\n", MDB_VERSION_STRING); -#endif #ifdef WITH_ENCRYPT printf("\tSODIUM VERSION = %s\n", SODIUM_VERSION_STRING); #endif @@ -139,10 +132,8 @@ int main(int argc, char **argv) char *progname = *argv, *p; int c; int list = 0, last = 0, limit = 0; -#if WITH_LMDB char *lmdbname = NULL; int dumpghash = FALSE, loadghash = FALSE; -#endif #if WITH_KILL int killdata = FALSE; #endif @@ -195,10 +186,8 @@ int main(int argc, char **argv) { "last", no_argument, 0, 'L'}, { "fields", required_argument, 0, 1}, { "precision", required_argument, 0, 2}, -#if WITH_LMDB { "dump", optional_argument, 0, 3}, { "load", optional_argument, 0, 4}, -#endif #if WITH_KILL { "killdata", no_argument, 0, 'K'}, #endif @@ -219,7 +208,6 @@ int main(int argc, char **argv) case 2: geohash_setprec(atoi(optarg)); break; -#if WITH_LMDB case 3: dumpghash = TRUE; if (optarg) @@ -230,7 +218,6 @@ int main(int argc, char **argv) if (optarg) lmdbname = strdup(optarg); break; -#endif /* LMDB */ case 'v': print_versioninfo(); break; @@ -304,7 +291,6 @@ int main(int argc, char **argv) // printf("lmdbname = %s\n", (lmdbname) ? lmdbname : "NULL"); -#ifdef WITH_LMDB if (loadghash) { storage_gcache_load(lmdbname); exit(0); @@ -314,7 +300,6 @@ int main(int argc, char **argv) storage_gcache_dump(lmdbname); exit(0); } -#endif storage_init(revgeo); diff --git a/recorder.c b/recorder.c index 2dfdb27..9acf48d 100644 --- a/recorder.c +++ b/recorder.c @@ -41,9 +41,7 @@ #include "misc.h" #include "util.h" #include "storage.h" -#ifdef WITH_LMDB -# include "gcache.h" -#endif +#include "gcache.h" #ifdef WITH_HTTP # include "http.h" #endif @@ -929,7 +927,6 @@ void handle_message(void *userdata, char *topic, char *payload, size_t payloadle } #endif -#ifdef WITH_LMDB /* * If the topic we are handling is in topic2tid, replace the TID * in this payload with that from the database. @@ -945,7 +942,6 @@ void handle_message(void *userdata, char *topic, char *payload, size_t payloadle json_append_member(json, "tid", json_mkstring(newtid)); } } -#endif /* * Chances are high that what we have now contains lat, lon. Attempt to @@ -964,7 +960,6 @@ void handle_message(void *userdata, char *topic, char *payload, size_t payloadle cached = FALSE; if (ud->revgeo == TRUE) { -#ifdef WITH_LMDB if ((geo = gcache_json_get(ud->gc, UB(ghash))) != NULL) { /* Habemus cached data */ @@ -993,11 +988,6 @@ void handle_message(void *userdata, char *topic, char *payload, size_t payloadle } } } -#else /* !LMDB */ - if ((geo = revgeo(ud, lat, lon, addr, cc)) != NULL) { - ; - } -#endif /* LMDB */ } else { utstring_printf(cc, "??"); utstring_printf(addr, "n.a."); @@ -1083,11 +1073,9 @@ void handle_message(void *userdata, char *topic, char *payload, size_t payloadle #endif #ifdef WITH_LUA -# ifdef WITH_LMDB if (ud->luadata && !pingping) { hooks_hook(ud, topic, json); } -# endif /* LMDB */ #endif if (ud->verbose) { @@ -1177,14 +1165,10 @@ static char *mosquitto_reason(int rc) void on_disconnect(struct mosquitto *mosq, void *userdata, int reason) { -#ifdef WITH_LMDB struct udata *ud = (struct udata *)userdata; -#endif if (reason == 0) { // client wish -#ifdef WITH_LMDB gcache_close(ud->gc); -#endif } else { olog(LOG_INFO, "Disconnected. Reason: 0x%X [%s]", reason, mosquitto_reason(reason)); } @@ -1286,21 +1270,17 @@ int main(int argc, char **argv) udata.revgeo = TRUE; udata.verbose = TRUE; udata.norec = FALSE; -#ifdef WITH_LMDB udata.gc = NULL; udata.t2t = NULL; /* Topic to TID */ # ifdef WITH_RONLY udata.ronlydb = NULL; /* RONLY db */ # endif -#endif #ifdef WITH_HTTP udata.mgserver = NULL; #endif #ifdef WITH_LUA -# ifdef WITH_LMDB udata.luadata = NULL; udata.luadb = NULL; -# endif /* WITH_LMDB */ #endif /* WITH_LUA */ udata.label = strdup("OwnTracks"); udata.geokey = NULL; /* default: no API key */ @@ -1463,9 +1443,7 @@ int main(int argc, char **argv) */ if (initialize == TRUE) { -#ifdef WITH_LMDB struct gcache *gt; -#endif char path[BUFSIZ], *pp; snprintf(path, BUFSIZ, "%s/ghash", STORAGEDIR); @@ -1480,7 +1458,6 @@ int main(int argc, char **argv) } -#ifdef WITH_LMDB if ((gt = gcache_open(path, NULL, FALSE)) == NULL) { fprintf(stderr, "Cannot lmdb-open MainDB\n"); exit(2); @@ -1513,7 +1490,6 @@ int main(int argc, char **argv) } gcache_close(gt); #endif /* !ENCRYPT */ -#endif exit(0); } @@ -1545,7 +1521,6 @@ int main(int argc, char **argv) olog(LOG_DEBUG, "version %s starting with STORAGEDIR=%s", VERSION, STORAGEDIR); if (ud->revgeo == TRUE) { -#ifdef WITH_LMDB char db_filename[BUFSIZ], *pa; snprintf(db_filename, BUFSIZ, "%s/ghash", STORAGEDIR); @@ -1558,11 +1533,9 @@ int main(int argc, char **argv) exit(1); } storage_init(ud->revgeo); /* For the HTTP server */ -#endif revgeo_init(); } -#ifdef WITH_LMDB snprintf(err, sizeof(err), "%s/ghash", STORAGEDIR); ud->t2t = gcache_open(err, "topic2tid", TRUE); # ifdef WITH_LUA @@ -1574,9 +1547,8 @@ int main(int argc, char **argv) # ifdef WITH_ENCRYPT ud->keydb = gcache_open(err, "keys", TRUE); # endif -#endif -#if WITH_LUA && WITH_LMDB +#if WITH_LUA /* * If option for lua-script has not been given, ignore all hooks. */ @@ -1725,13 +1697,11 @@ int main(int argc, char **argv) json_delete(ud->topics); -#ifdef WITH_LMDB if (ud->t2t) gcache_close(ud->t2t); -# ifdef WITH_LUA +#ifdef WITH_LUA if (ud->luadb) gcache_close(ud->luadb); -# endif #endif free(ud->label); @@ -1740,7 +1710,7 @@ int main(int argc, char **argv) mg_destroy_server(&udata.mgserver); #endif -#if WITH_LUA && WITH_LMDB +#if WITH_LUA hooks_exit(ud->luadata, "recorder stops"); #endif diff --git a/storage.c b/storage.c index d59b14f..8fb8813 100644 --- a/storage.c +++ b/storage.c @@ -40,15 +40,12 @@ char STORAGEDIR[BUFSIZ] = STORAGEDEFAULT; #define LINESIZE 8192 -#ifdef WITH_LMDB static struct gcache *gc = NULL; -#endif void storage_init(int revgeo) { setenv("TZ", "UTC", 1); -#ifdef WITH_LMDB if (revgeo) { char path[BUFSIZ]; @@ -58,10 +55,8 @@ void storage_init(int revgeo) olog(LOG_ERR, "storage_init(): gc is NULL"); } } -#endif } -#ifdef WITH_LMDB void storage_gcache_dump(char *lmdbname) { char path[BUFSIZ]; @@ -77,19 +72,16 @@ void storage_gcache_load(char *lmdbname) snprintf(path, BUFSIZ, "%s/ghash", STORAGEDIR); gcache_load(path, lmdbname); } -#endif /* !LMDB */ void get_geo(JsonNode *o, char *ghash) { -#ifdef WITH_LMDB JsonNode *geo; if ((geo = gcache_json_get(gc, ghash)) != NULL) { json_copy_to_object(o, geo, FALSE); json_delete(geo); } -#endif } diff --git a/udata.h b/udata.h index dd4ce91..8097e91 100644 --- a/udata.h +++ b/udata.h @@ -6,9 +6,7 @@ #ifdef WITH_HTTP # include "mongoose.h" #endif -#ifdef WITH_LMDB -# include "gcache.h" -#endif +#include "gcache.h" struct udata { @@ -22,21 +20,17 @@ struct udata { int revgeo; /* True (default) if we should do reverse Geo lookups */ int verbose; /* TRUE if print verbose messages to stdout */ int norec; /* If TRUE, no .REC files are written to */ -#ifdef WITH_LMDB struct gcache *gc; struct gcache *t2t; /* topic to tid */ -# ifdef WITH_RONLY +#ifdef WITH_RONLY struct gcache *ronlydb; /* RONLY db */ -# endif #endif #ifdef WITH_HTTP struct mg_server *mgserver; /* Mongoose */ #endif #ifdef WITH_LUA struct luadata *luadata; /* Lua stuff */ -# ifdef WITH_LMDB struct gcache *luadb; /* lmdb named database 'luadb' */ -# endif #endif #ifdef WITH_ENCRYPT struct gcache *keydb; /* encryption keys */