You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

global_functions.lua 1.8KB

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