Debian Codegraph @

lualib/global_functions.lua

raw
1 --[[
2 Copyright (c) 2022, Vsevolod Stakhov <[email protected]>
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 ]]--
16
17 local logger = require "rspamd_logger"
18 local lua_util = require "lua_util"
19 local lua_redis = require "lua_redis"
20 local meta_functions = require "lua_meta"
21 local maps = require "lua_maps"
22
23 local exports = {}
24
25 exports.rspamd_parse_redis_server = lua_redis.rspamd_parse_redis_server
26 exports.parse_redis_server = lua_redis.rspamd_parse_redis_server
27 exports.rspamd_redis_make_request = lua_redis.rspamd_redis_make_request
28 exports.redis_make_request = lua_redis.rspamd_redis_make_request
29
30 exports.rspamd_gen_metatokens = meta_functions.rspamd_gen_metatokens
31 exports.rspamd_count_metatokens = meta_functions.rspamd_count_metatokens
32
33 exports.rspamd_map_add = maps.rspamd_map_add
34
35 exports.rspamd_str_split = lua_util.rspamd_str_split
36
37 -- a special syntax sugar to export all functions to the global table
38 setmetatable(exports, {
39 __call = function(t, override)
40 for k, v in pairs(t) do
41 if _G[k] ~= nil then
42 local msg = 'function ' .. k .. ' already exists in global scope.'
43 if override then
44 _G[k] = v
45 logger.errx('WARNING: ' .. msg .. ' Overwritten.')
46 else
47 logger.errx('NOTICE: ' .. msg .. ' Skipped.')
48 end
49 else
50 _G[k] = v
51 end
52 end
53 end,
54 })
55
56 return exports