diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-02-22 09:59:43 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-02-22 09:59:43 +0000 |
commit | b0cf71db435fa0e010b1cc372f6b7ef834d7bb22 (patch) | |
tree | 466f027efc4efeb20d58df1ef8c0a7785828fb04 /src/lua | |
parent | 18a9a0b584a6e469bedbf431d0f310e3bd9736c2 (diff) | |
download | rspamd-b0cf71db435fa0e010b1cc372f6b7ef834d7bb22.tar.gz rspamd-b0cf71db435fa0e010b1cc372f6b7ef834d7bb22.zip |
[Minor] Allow lua maps to process opaque texts
Diffstat (limited to 'src/lua')
-rw-r--r-- | src/lua/lua_map.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/lua/lua_map.c b/src/lua/lua_map.c index 087478ccc..b279bacbd 100644 --- a/src/lua/lua_map.c +++ b/src/lua/lua_map.c @@ -129,6 +129,7 @@ static const struct luaL_reg maplib_m[] = { struct lua_map_callback_data { lua_State *L; gint ref; + gboolean opaque; rspamd_fstring_t *data; struct rspamd_lua_map *lua_map; }; @@ -442,7 +443,19 @@ lua_map_fin (struct map_cb_data *data, void **target) } else if (cbdata->data != NULL && cbdata->data->len != 0) { lua_rawgeti (cbdata->L, LUA_REGISTRYINDEX, cbdata->ref); - lua_pushlstring (cbdata->L, cbdata->data->str, cbdata->data->len); + + if (cbdata->opaque) { + lua_pushlstring (cbdata->L, cbdata->data->str, cbdata->data->len); + } + else { + struct rspamd_lua_text *t; + + t = lua_newuserdata (cbdata->L, sizeof (*t)); + t->flags = 0; + t->len = cbdata->data->len; + t->start = cbdata->data->str; + } + pmap = lua_newuserdata (cbdata->L, sizeof (void *)); *pmap = cbdata->lua_map; rspamd_lua_setclass (cbdata->L, "rspamd{map}", -1); @@ -493,14 +506,15 @@ lua_config_add_map (lua_State *L) struct lua_map_callback_data *cbdata; struct rspamd_lua_map *map, **pmap; struct rspamd_map *m; + gboolean opaque_data = FALSE; int cbidx = -1, ret; GError *err = NULL; if (cfg) { if (!rspamd_lua_parse_table_arguments (L, 2, &err, RSPAMD_LUA_PARSE_ARGUMENTS_DEFAULT, - "*url=O;description=S;callback=F;type=S", - &map_obj, &description, &cbidx, &type)) { + "*url=O;description=S;callback=F;type=S;opaque_data=B", + &map_obj, &description, &cbidx, &type, &opaque_data)) { ret = luaL_error (L, "invalid table arguments: %s", err->message); g_error_free (err); if (map_obj) { @@ -529,6 +543,7 @@ lua_config_add_map (lua_State *L) cbdata->data = NULL; cbdata->lua_map = map; cbdata->ref = cbidx; + cbdata->opaque = opaque_data; if ((m = rspamd_map_add_from_ucl (cfg, map_obj, description, lua_map_read, |