diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-04-07 12:20:52 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-04-07 12:20:52 +0100 |
commit | d5bd63254fb2df011b1499c27bc3741890c8ed9f (patch) | |
tree | 3942cf821c99827b6ebd7c94e1d190f8f5281bc3 /src/lua/lua_url.c | |
parent | 33773cc81fe34d96d27aba8a3a752958302f93f3 (diff) | |
download | rspamd-d5bd63254fb2df011b1499c27bc3741890c8ed9f.tar.gz rspamd-d5bd63254fb2df011b1499c27bc3741890c8ed9f.zip |
[Feature] Add lua methods to get redirected urls
Diffstat (limited to 'src/lua/lua_url.c')
-rw-r--r-- | src/lua/lua_url.c | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/src/lua/lua_url.c b/src/lua/lua_url.c index 67856e298..8c43c2dcc 100644 --- a/src/lua/lua_url.c +++ b/src/lua/lua_url.c @@ -49,6 +49,7 @@ LUA_FUNCTION_DEF (url, get_text); LUA_FUNCTION_DEF (url, get_tld); LUA_FUNCTION_DEF (url, to_table); LUA_FUNCTION_DEF (url, is_phished); +LUA_FUNCTION_DEF (url, is_redirected); LUA_FUNCTION_DEF (url, is_obscured); LUA_FUNCTION_DEF (url, get_phished); LUA_FUNCTION_DEF (url, create); @@ -66,8 +67,10 @@ static const struct luaL_reg urllib_m[] = { LUA_INTERFACE_DEF (url, get_tld), LUA_INTERFACE_DEF (url, to_table), LUA_INTERFACE_DEF (url, is_phished), + LUA_INTERFACE_DEF (url, is_redirected), LUA_INTERFACE_DEF (url, is_obscured), LUA_INTERFACE_DEF (url, get_phished), + {"get_redirected", lua_url_get_phished}, {"__tostring", lua_url_get_text}, {NULL, NULL} }; @@ -265,6 +268,26 @@ lua_url_is_phished (lua_State *L) } /*** + * @method url:is_redirected() + * Check whether URL was redirected + * @return {boolean} `true` if URL is redirected + */ +static gint +lua_url_is_redirected (lua_State *L) +{ + struct rspamd_lua_url *url = lua_check_url (L, 1); + + if (url != NULL) { + lua_pushboolean (L, url->url->flags & RSPAMD_URL_FLAG_REDIRECTED); + } + else { + lua_pushnil (L); + } + + return 1; +} + +/*** * @method url:is_obscured() * Check whether URL is treated as obscured or obfusicated (e.g. numbers in IP address or other hacks) * @return {boolean} `true` if URL is obscured @@ -295,13 +318,15 @@ lua_url_get_phished (lua_State *L) struct rspamd_lua_url *purl, *url = lua_check_url (L, 1); if (url) { - if ((url->url->flags & RSPAMD_URL_FLAG_PHISHED) - && url->url->phished_url != NULL) { - purl = lua_newuserdata (L, sizeof (struct rspamd_lua_url)); - rspamd_lua_setclass (L, "rspamd{url}", -1); - purl->url = url->url->phished_url; + if (url->url->phished_url != NULL) { + if (url->url->flags & + (RSPAMD_URL_FLAG_PHISHED|RSPAMD_URL_FLAG_REDIRECTED)) { + purl = lua_newuserdata (L, sizeof (struct rspamd_lua_url)); + rspamd_lua_setclass (L, "rspamd{url}", -1); + purl->url = url->url->phished_url; - return 1; + return 1; + } } } |