mirror of
https://github.com/owntracks/recorder.git
synced 2024-11-15 18:08:28 -07:00
Lua invokes otr_putrec
This commit is contained in:
parent
86fefd9f4b
commit
bb92d4f644
@ -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
|
||||
|
5
hooks.c
5
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);
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user