]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Add flag for embedded maps
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 13 Mar 2016 17:54:07 +0000 (17:54 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 13 Mar 2016 17:54:07 +0000 (17:54 +0000)
src/lua/lua_common.h
src/lua/lua_map.c

index 69e02142b8a5daaf174ee4f25b6f42febbd48b3b..5356c3821d68305b5d55dc614703c920c8fad45a 100644 (file)
@@ -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;
index 934d691227fbeef36cd38410b0f2acc0da82726d..6a2cb413917939c356ace0cca9b978742d097fc4 100644 (file)
@@ -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 {