]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Add lua methods to get redirected urls
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 7 Apr 2016 11:20:52 +0000 (12:20 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 7 Apr 2016 11:20:52 +0000 (12:20 +0100)
src/lua/lua_url.c

index 67856e298d6645e2c7c7b1cd88a2ad25bfdf0ab2..8c43c2dccb8cf096ae48737da30eeae39d45309f 100644 (file)
@@ -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}
 };
@@ -264,6 +267,26 @@ lua_url_is_phished (lua_State *L)
        return 1;
 }
 
+/***
+ * @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)
@@ -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;
+                       }
                }
        }