commit 5331d42: [Minor] Add Lua methods to get urls order

Vsevolod Stakhov vsevolod at rspamd.com
Wed Jul 26 12:49:03 UTC 2023


Author: Vsevolod Stakhov
Date: 2023-07-26 13:43:45 +0100
URL: https://github.com/rspamd/rspamd/commit/5331d429f1bb3d615356c16f8ffe02632584938a (HEAD -> master)

[Minor] Add Lua methods to get urls order

---
 src/lua/lua_url.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/src/lua/lua_url.c b/src/lua/lua_url.c
index 4dd09dec8..3f25b3128 100644
--- a/src/lua/lua_url.c
+++ b/src/lua/lua_url.c
@@ -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;


More information about the Commits mailing list