Module rspamd_map

This module is used to manage rspamd maps and map like objects

All maps could be obtained by function rspamd_config:get_maps() Also see lua_maps module description.

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,

Brief content:

Methods:

Method Description
map:get_key(in) Variable method for different types of maps.
map:is_signed() Returns True if a map is signed.
map:get_proto() Returns protocol of map as string.
map:get_sign_key() Returns pubkey used for signing as base32 string or nil.
map:set_sign_key(key) Set trusted key for signatures for this map.
map:set_callback(cb) Set callback for a specified callback map.
map:get_uri() Get uri for a specified map.
map:get_stats(reset) Get statistics for specific map.
map:foreach(callback, is_text) Iterate over map elements and call callback for each element.
map:on_load(callback) Sets a callback for a map that is called when map is loaded.
map:get_data_digest() Get data digest for specific map.
map:get_nelts() Get number of elements for specific map.

Methods

The module rspamd_map defines the following methods.

Method map:get_key(in)

Variable method for different types of maps:

  • For hash maps it returns boolean and accepts string
  • For kv maps it returns string (or nil) and accepts string
  • For radix maps it returns boolean and accepts IP address (as object, string or number)

Parameters:

  • in {vary}: input to check

Returns:

  • {bool|string}: if a value is found then this function returns string or True if not - then it returns nil or False

Back to module description.

Method map:is_signed()

Returns True if a map is signed

Parameters:

No parameters

Returns:

  • {bool}: signed value

Back to module description.

Method map:get_proto()

Returns protocol of map as string:

  • http: for HTTP map
  • file: for file map

Parameters:

No parameters

Returns:

  • {string}: string representation of the map protocol

Back to module description.

Method map:get_sign_key()

Returns pubkey used for signing as base32 string or nil

Parameters:

No parameters

Returns:

  • {string}: base32 encoded string or nil

Back to module description.

Method map:set_sign_key(key)

Set trusted key for signatures for this map

Parameters:

  • key {string}: base32 encoded string or nil

Returns:

No return

Back to module description.

Method map:set_callback(cb)

Set callback for a specified callback map.

Parameters:

  • cb {function}: map callback function

Returns:

No return

Back to module description.

Method map:get_uri()

Get uri for a specified map

Parameters:

No parameters

Returns:

  • {string}: map’s URI

Back to module description.

Method map:get_stats(reset)

Get statistics for specific map. It returns table in form: [key] => [nhits]

Parameters:

  • reset {boolean}: reset stats if true

Returns:

  • {table}: map’s stat

Back to module description.

Method map:foreach(callback, is_text)

Iterate over map elements and call callback for each element.

Parameters:

  • callback {function}: callback function, that accepts two arguments: key and value, if it returns true then iteration is stopped
  • is_text {boolean}: if true then callback accepts rspamd_text instead of Lua strings

Returns:

  • {number}: number of elements iterated

Back to module description.

Method map:on_load(callback)

Sets a callback for a map that is called when map is loaded

Parameters:

  • callback {function}: callback function, that accepts no arguments (pass maps in a closure if needed)

Returns:

No return

Back to module description.

Method map:get_data_digest()

Get data digest for specific map

Parameters:

No parameters

Returns:

  • {string}: 64 bit number represented as string (due to Lua limitations)

Back to module description.

Method map:get_nelts()

Get number of elements for specific map

Parameters:

No parameters

Returns:

  • {number}: number of elements in the map

Back to module description.

Back to top.