diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2022-02-14 21:10:35 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2022-02-14 21:10:35 +0000 |
commit | c5fe1b05091d6f4a5848aaeb1d5707ca57f162c6 (patch) | |
tree | eab900f9611627a029f7b9f4d925603124414d9e /src/lua/lua_map.c | |
parent | b1bef4702ca704b65bb8d8c19d89fa4f3fd28c49 (diff) | |
download | rspamd-c5fe1b05091d6f4a5848aaeb1d5707ca57f162c6.tar.gz rspamd-c5fe1b05091d6f4a5848aaeb1d5707ca57f162c6.zip |
[Minor] Add an example for the lua_maps usage
Diffstat (limited to 'src/lua/lua_map.c')
-rw-r--r-- | src/lua/lua_map.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/lua/lua_map.c b/src/lua/lua_map.c index 923b9adcc..2e2f0e6db 100644 --- a/src/lua/lua_map.c +++ b/src/lua/lua_map.c @@ -27,6 +27,35 @@ * * All maps could be obtained by function `rspamd_config:get_maps()` * Also see [`lua_maps` module description](lua_maps.html). + * + * **Important notice** maps cannot be queried outside of the worker context. + * For example, you cannot add even a file map and query some keys from it during + * some module initialisation, you need to add the appropriate event loop context + * for a worker (e.g. you cannot use `get_key` outside of the symbols callbacks or + * a worker `on_load` scripts). + * +@example + +local hash_map = rspamd_config:add_map{ + type = "hash", + urls = ['file:///path/to/file'], + description = 'sample map' +} + +local function sample_symbol_cb(task) + -- Check whether hash map contains from address of message + if hash_map:get_key((task:get_from() or {})[1]) then + -- key found + end +end + +rspamd_config:register_symbol{ + name = 'SAMPLE_SYMBOL', + type = 'normal', + score = 1.0, + description = "A sample symbol", + callback = sample_symbol_cb, +} */ /*** |