]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Accept strign keys for radix maps
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 27 Feb 2017 12:16:23 +0000 (12:16 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 27 Feb 2017 12:16:23 +0000 (12:16 +0000)
src/lua/lua_map.c

index c74bcf31bcae3d4f25473b3d4aaf8f8630a03aae..c0ce00609ea6aa27b341b349645f3d0a053ced4f 100644 (file)
@@ -540,9 +540,18 @@ lua_map_get_key (lua_State * L)
                if (map->type == RSPAMD_LUA_MAP_RADIX) {
                        radix = map->data.radix;
 
-                       if (lua_type (L, 2) == LUA_TNUMBER) {
-                               key_num = luaL_checknumber (L, 2);
-                               key_num = htonl (key_num);
+                       if (lua_type (L, 2) == LUA_TSTRING) {
+                               const gchar *addr_str;
+                               gsize len;
+
+                               addr_str = luaL_checklstring (L, 2, &len);
+                               addr = g_alloca (sizeof (*addr));
+                               addr->addr = g_alloca (rspamd_inet_address_storage_size ());
+
+                               if (!rspamd_parse_inet_address_ip (addr_str, len, addr->addr)) {
+                                       addr = NULL;
+                                       msg_err ("invalid ip address: %*s", (gint)len, addr_str);
+                               }
                        }
                        else if (lua_type (L, 2) == LUA_TUSERDATA) {
                                ud = rspamd_lua_check_udata (L, 2, "rspamd{ip}");
@@ -557,6 +566,10 @@ lua_map_get_key (lua_State * L)
                                        msg_err ("invalid userdata type provided, rspamd{ip} expected");
                                }
                        }
+                       else if (lua_type (L, 2) == LUA_TNUMBER) {
+                               key_num = luaL_checknumber (L, 2);
+                               key_num = htonl (key_num);
+                       }
 
                        if (radix) {
                                guintptr p = 0;