diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-03-07 12:54:55 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-03-07 12:54:55 +0000 |
commit | fae817031dbca39bd94e0448f3d12ecdc1914d86 (patch) | |
tree | a026e8d3202c6cff1d2eff6a57c6d366d51d0b80 | |
parent | 84a76bc874c278da6fc2c442d61d2f42914626c0 (diff) | |
download | rspamd-fae817031dbca39bd94e0448f3d12ecdc1914d86.tar.gz rspamd-fae817031dbca39bd94e0448f3d12ecdc1914d86.zip |
[Feature] Add map:get_proto lua API method
-rw-r--r-- | src/lua/lua_map.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/lua/lua_map.c b/src/lua/lua_map.c index fe8f6a836..1f7ceb194 100644 --- a/src/lua/lua_map.c +++ b/src/lua/lua_map.c @@ -47,9 +47,21 @@ LUA_FUNCTION_DEF (map, get_key); */ LUA_FUNCTION_DEF (map, is_signed); +/*** + * @method map:get_proto() + * Returns protocol of map as string: + * + * - `http`: for HTTP map + * - `file`: for file map + * - `embedded`: for manually created maps + * @return {string} string representation of the map protocol + */ +LUA_FUNCTION_DEF (map, get_proto); + static const struct luaL_reg maplib_m[] = { LUA_INTERFACE_DEF (map, get_key), LUA_INTERFACE_DEF (map, is_signed), + LUA_INTERFACE_DEF (map, get_proto), {"__tostring", rspamd_lua_class_tostring}, {NULL, NULL} }; @@ -469,6 +481,36 @@ lua_map_is_signed (lua_State *L) return 1; } +static int +lua_map_get_proto (lua_State *L) +{ + struct rspamd_lua_map *map = lua_check_map (L); + const gchar *ret = "undefined"; + + if (map != NULL) { + if (map->map == NULL) { + ret = "embedded"; + } + else { + switch (map->map->protocol) { + case MAP_PROTO_FILE: + ret = "file"; + break; + case MAP_PROTO_HTTP: + ret = "http"; + break; + } + } + } + else { + return luaL_error (L, "invalid arguments"); + } + + lua_pushstring (L, ret); + return 1; +} + + void luaopen_map (lua_State * L) { |