diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-02-27 12:16:23 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-02-27 12:16:23 +0000 |
commit | fd449b38e77db529a69dd44ccfd7e90dcbbd7717 (patch) | |
tree | 90be2f8960697531f1b5f3a88fc53d5316e9d483 /src/lua/lua_map.c | |
parent | e47d8db1f1c1b8983263075ad00401a49e90560c (diff) | |
download | rspamd-fd449b38e77db529a69dd44ccfd7e90dcbbd7717.tar.gz rspamd-fd449b38e77db529a69dd44ccfd7e90dcbbd7717.zip |
[Minor] Accept strign keys for radix maps
Diffstat (limited to 'src/lua/lua_map.c')
-rw-r--r-- | src/lua/lua_map.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/lua/lua_map.c b/src/lua/lua_map.c index c74bcf31b..c0ce00609 100644 --- a/src/lua/lua_map.c +++ b/src/lua/lua_map.c @@ -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; |