Browse Source

[Fix] Multimap: Fix operating with userdata

tags/1.9.0
Vsevolod Stakhov 5 years ago
parent
commit
221a576077
2 changed files with 12 additions and 5 deletions
  1. 3
    0
      src/lua/lua_ip.c
  2. 9
    5
      src/plugins/lua/multimap.lua

+ 3
- 0
src/lua/lua_ip.c View File

LUA_INTERFACE_DEF (ip, apply_mask), LUA_INTERFACE_DEF (ip, apply_mask),
LUA_INTERFACE_DEF (ip, copy), LUA_INTERFACE_DEF (ip, copy),
LUA_INTERFACE_DEF (ip, is_local), LUA_INTERFACE_DEF (ip, is_local),
{"tostring", lua_ip_to_string},
{"totable", lua_ip_to_table},
{"tonumber", lua_ip_to_number},
{"__tostring", lua_ip_to_string}, {"__tostring", lua_ip_to_string},
{"__eq", lua_ip_equal}, {"__eq", lua_ip_equal},
{"__gc", lua_ip_destroy}, {"__gc", lua_ip_destroy},

+ 9
- 5
src/plugins/lua/multimap.lua View File

if r['cdb'] then if r['cdb'] then
local srch = value local srch = value
if type(value) == 'userdata' then if type(value) == 'userdata' then
srch = value:to_string()
if value.class == 'rspamd{ip}' then
srch = value:tostring()
end
end end
ret = r['cdb']:lookup(srch) ret = r['cdb']:lookup(srch)
elseif r['redis_key'] then elseif r['redis_key'] then
local srch = {value} local srch = {value}
local cmd = 'HGET' local cmd = 'HGET'
if type(value) == 'userdata' then
srch = {value:to_string()}
if type(value) == 'userdata' and value.class == 'rspamd{ip}' then
srch = {value:tostring()}
cmd = 'HMGET' cmd = 'HMGET'
local maxbits = 128 local maxbits = 128
local minbits = 32 local minbits = 32
minbits = 8 minbits = 8
end end
for i=maxbits,minbits,-1 do for i=maxbits,minbits,-1 do
local nip = value:apply_mask(i):to_string() .. "/" .. i
local nip = value:apply_mask(i):tostring() .. "/" .. i
table.insert(srch, nip) table.insert(srch, nip)
end end
end end
ret = r['radix']:get_key(value) ret = r['radix']:get_key(value)
elseif r['hash'] then elseif r['hash'] then
if type(value) == 'userdata' then if type(value) == 'userdata' then
value = value:to_string()
if value.class == 'rspamd{ip}' then
value = value:tostring()
end
end end
ret = r['hash']:get_key(value) ret = r['hash']:get_key(value)
end end

Loading…
Cancel
Save