aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-02-15 19:18:16 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-02-15 19:18:16 +0000
commit898bd618e4a62810a37de25f31bde4cf09cb3022 (patch)
tree597906aeee6b1d4b22addd36f1aac4342c8ae0f6 /src/lua
parent52a35856a381272acd689f2fc5c16e0e4d14040f (diff)
downloadrspamd-898bd618e4a62810a37de25f31bde4cf09cb3022.tar.gz
rspamd-898bd618e4a62810a37de25f31bde4cf09cb3022.zip
Allow to check radix maps from lua by rspamd{ip}
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_config.c37
1 files changed, 31 insertions, 6 deletions
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index df998b8a0..7c017df29 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -1369,19 +1369,44 @@ static gint
lua_radix_get_key (lua_State * L)
{
radix_compressed_t *radix = lua_check_radix (L);
- guint32 key;
+ struct rspamd_lua_ip *addr = NULL;
+ gpointer ud;
+ guint32 key_num = 0;
+ gboolean ret = FALSE;
if (radix) {
- key = htonl (luaL_checkint (L, 2));
+ if (lua_type (L, 2) == LUA_TNUMBER) {
+ key_num = htonl (luaL_checkint (L, 2));
+ }
+ else if (lua_type (L, 2) == LUA_TUSERDATA) {
+ ud = luaL_checkudata (L, 2, "rspamd{ip}");
+ if (ud != NULL) {
+ addr = (struct rspamd_lua_ip *)ud;
+ if (!addr->is_valid) {
+ msg_err ("rspamd{ip} is not valid");
+ addr = NULL;
+ }
+ }
+ else {
+ msg_err ("invalid userdata type provided, rspamd{ip} expected");
+ }
+ }
- if (radix_find_compressed (radix, (guint8 *)&key, sizeof (key))
+ if (addr != NULL) {
+ if (radix_find_compressed_addr (radix, &addr->addr)
+ != RADIX_NO_VALUE) {
+ ret = TRUE;
+ }
+ }
+ else if (key_num != 0) {
+ if (radix_find_compressed (radix, (guint8 *)&key_num, sizeof (key_num))
!= RADIX_NO_VALUE) {
- lua_pushboolean (L, 1);
- return 1;
+ ret = TRUE;
+ }
}
}
- lua_pushboolean (L, 0);
+ lua_pushboolean (L, ret);
return 1;
}