From b4ba6f65a0231eae9a777e42e4662b104049554a Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sun, 13 Mar 2016 17:54:07 +0000 Subject: [PATCH] [Minor] Add flag for embedded maps --- src/lua/lua_common.h | 3 +++ src/lua/lua_map.c | 12 +++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h index 69e02142b..5356c3821 100644 --- a/src/lua/lua_common.h +++ b/src/lua/lua_common.h @@ -93,9 +93,12 @@ enum rspamd_lua_map_type { RSPAMD_LUA_MAP_CALLBACK }; +#define RSPAMD_LUA_MAP_FLAG_EMBEDDED (1 << 0) + struct rspamd_lua_map { struct rspamd_map *map; enum rspamd_lua_map_type type; + guint flags; union { struct radix_tree_compressed *radix; diff --git a/src/lua/lua_map.c b/src/lua/lua_map.c index 934d69122..6a2cb4139 100644 --- a/src/lua/lua_map.c +++ b/src/lua/lua_map.c @@ -173,6 +173,7 @@ lua_config_radix_from_config (lua_State *L) map->data.radix = radix_create_compressed (); map->type = RSPAMD_LUA_MAP_RADIX; map->data.radix = radix_create_compressed (); + map->flags |= RSPAMD_LUA_MAP_FLAG_EMBEDDED; radix_add_generic_iplist (ucl_obj_tostring (obj), &map->data.radix); pmap = lua_newuserdata (L, sizeof (void *)); *pmap = map; @@ -507,7 +508,7 @@ lua_map_get_proto (lua_State *L) const gchar *ret = "undefined"; if (map != NULL) { - if (map->map == NULL) { + if ((map->flags & RSPAMD_LUA_MAP_FLAG_EMBEDDED) || map->map == NULL) { ret = "embedded"; } else { @@ -536,6 +537,11 @@ lua_map_get_sign_key (lua_State *L) GString *ret = NULL; if (map != NULL) { + if (map->flags & RSPAMD_LUA_MAP_FLAG_EMBEDDED) { + lua_pushnil (L); + + return 1; + } if (map->map && map->map->trusted_pubkey) { ret = rspamd_pubkey_print (map->map->trusted_pubkey, RSPAMD_KEYPAIR_PUBKEY|RSPAMD_KEYPAIR_BASE32); @@ -568,7 +574,7 @@ lua_map_set_sign_key (lua_State *L) if (map && pk_str) { - if (!map->map) { + if ((map->flags & RSPAMD_LUA_MAP_FLAG_EMBEDDED) || !map->map) { return luaL_error (L, "cannot set key for embedded maps"); } @@ -620,7 +626,7 @@ lua_map_get_uri (lua_State *L) const gchar *ret = "undefined"; if (map != NULL) { - if (map->map == NULL) { + if ((map->flags & RSPAMD_LUA_MAP_FLAG_EMBEDDED) || map->map == NULL) { ret = "embedded"; } else { -- 2.39.5