mirror of
https://github.com/owntracks/recorder.git
synced 2026-08-23 11:26:16 +00:00
LMDB is no longer optional
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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 : "<nil>", (d) ? d : "<NIL>");
|
||||
@@ -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
|
||||
|
||||
@@ -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 [<db>] 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);
|
||||
|
||||
|
||||
+4
-34
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user