diff --git a/README.md b/README.md index 491d835..c9aa3fe 100644 --- a/README.md +++ b/README.md @@ -500,11 +500,11 @@ written by OwnTracks Recorder version 0.3.0 It is 14:10:01 in the year 2015 owntracks/jane/phone lat=48.858339 Avenue Anatole France, 75007 Paris, France ``` -### `putrec` +### `otr_putrec` -An optional function you provide is called `putrec(u, d, s)`. If it exists, +An optional function you provide is called `otr_putrec(u, d, s)`. If it exists, it is called with the current user in `u`, the device in `d` and the payload -(which is possibly not JSON) in the string `s`. If your function returns a +(which for OwnTracks apps is JSON but for, eg Greenwich devices might not be) in the string `s`. If your function returns a non-zero value, the _recorder_ will *not* write the REC file for this publish. ### Hooklets diff --git a/hooks.c b/hooks.c index e6dd90d..2d8f9ca 100644 --- a/hooks.c +++ b/hooks.c @@ -199,7 +199,7 @@ int hooks_norec(struct udata *ud, char *user, char *device, char *payload) return (0); lua_settop(ld->L, 0); - lua_getglobal(ld->L, "putrec"); + lua_getglobal(ld->L, "otr_putrec"); if (lua_type(ld->L, -1) != LUA_TFUNCTION) { return (0); } @@ -208,14 +208,13 @@ int hooks_norec(struct udata *ud, char *user, char *device, char *payload) lua_pushstring(ld->L, device); lua_pushstring(ld->L, payload); - /* Invoke `hook' function in Lua with our args */ + /* Invoke Lua function with our args */ if (lua_pcall(ld->L, 3, 1, 0)) { olog(LOG_ERR, "Failed to run putrec in Lua: %s", lua_tostring(ld->L, -1)); exit(1); } rc = (int)lua_tonumber(ld->L, -1); - printf("C: hooks_norec returns %d\n", rc); return (rc); } diff --git a/ot-recorder.c b/ot-recorder.c index bbabdb6..0a1edb1 100644 --- a/ot-recorder.c +++ b/ot-recorder.c @@ -268,8 +268,13 @@ JsonNode *csv_to_json(char *payload) static void putrec(struct udata *ud, time_t now, UT_string *reltopic, UT_string *username, UT_string *device, char *string) { FILE *fp; + int rc = 0; - if (hooks_norec(ud, UB(username), UB(device), string) == 0) { +#ifdef WITH_LUA + rc = hooks_norec(ud, UB(username), UB(device), string); +#endif + + if (rc == 0) { if ((fp = pathn("a", "rec", username, device, "rec")) == NULL) { olog(LOG_ERR, "Cannot write REC for %s/%s: %m", UB(username), UB(device));