]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Add Lua methods to get urls order
authorVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 26 Jul 2023 12:43:45 +0000 (13:43 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 26 Jul 2023 12:43:45 +0000 (13:43 +0100)
src/lua/lua_url.c

index 4dd09dec89636ec2d72c3d156489468a031a764c..3f25b3128e707fc95ea5ee0eb31945980e6e6eb9 100644 (file)
@@ -72,6 +72,8 @@ LUA_FUNCTION_DEF(url, init);
 LUA_FUNCTION_DEF(url, all);
 LUA_FUNCTION_DEF(url, lt);
 LUA_FUNCTION_DEF(url, eq);
+LUA_FUNCTION_DEF(url, get_order);
+LUA_FUNCTION_DEF(url, get_part_order);
 
 static const struct luaL_reg urllib_m[] = {
        LUA_INTERFACE_DEF(url, get_length),
@@ -97,6 +99,8 @@ static const struct luaL_reg urllib_m[] = {
        LUA_INTERFACE_DEF(url, get_count),
        LUA_INTERFACE_DEF(url, get_flags),
        LUA_INTERFACE_DEF(url, get_flags_num),
+       LUA_INTERFACE_DEF(url, get_order),
+       LUA_INTERFACE_DEF(url, get_part_order),
        {"get_redirected", lua_url_get_phished},
        LUA_INTERFACE_DEF(url, set_redirected),
        {"__tostring", lua_url_tostring},
@@ -942,6 +946,48 @@ lua_url_get_flags_num(lua_State *L)
        return 1;
 }
 
+static gint
+lua_url_get_order(lua_State *L)
+{
+       LUA_TRACE_POINT;
+       struct rspamd_lua_url *url = lua_check_url(L, 1);
+
+       if (url) {
+               if (url->url->order != (uint16_t) -1) {
+                       lua_pushinteger(L, url->url->order);
+               }
+               else {
+                       lua_pushnil(L);
+               }
+       }
+       else {
+               return luaL_error(L, "invalid arguments");
+       }
+
+       return 1;
+}
+
+static gint
+lua_url_get_part_order(lua_State *L)
+{
+       LUA_TRACE_POINT;
+       struct rspamd_lua_url *url = lua_check_url(L, 1);
+
+       if (url) {
+               if (url->url->part_order != (uint16_t) -1) {
+                       lua_pushinteger(L, url->url->part_order);
+               }
+               else {
+                       lua_pushnil(L);
+               }
+       }
+       else {
+               return luaL_error(L, "invalid arguments");
+       }
+
+       return 1;
+}
+
 void lua_tree_url_callback(gpointer key, gpointer value, gpointer ud)
 {
        struct rspamd_lua_url *lua_url;