diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2021-02-22 16:26:44 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2021-02-22 16:26:44 +0000 |
commit | c218a0dcefc2afcd82c8aff016630d5fe34aaee1 (patch) | |
tree | 606432edbca4aa71c8bf9a0d0ece3f71824efdaf /src/lua/lua_url.c | |
parent | e170d0f7d9037b58b8e1c47bd37ccffbc7587044 (diff) | |
download | rspamd-c218a0dcefc2afcd82c8aff016630d5fe34aaee1.tar.gz rspamd-c218a0dcefc2afcd82c8aff016630d5fe34aaee1.zip |
[Minor] Lua_url: Add comparison metamethods
Diffstat (limited to 'src/lua/lua_url.c')
-rw-r--r-- | src/lua/lua_url.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/lua/lua_url.c b/src/lua/lua_url.c index 7909444d5..13a75b40b 100644 --- a/src/lua/lua_url.c +++ b/src/lua/lua_url.c @@ -70,6 +70,8 @@ LUA_FUNCTION_DEF (url, get_visible); LUA_FUNCTION_DEF (url, create); LUA_FUNCTION_DEF (url, init); LUA_FUNCTION_DEF (url, all); +LUA_FUNCTION_DEF (url, lt); +LUA_FUNCTION_DEF (url, eq); static const struct luaL_reg urllib_m[] = { LUA_INTERFACE_DEF (url, get_length), @@ -98,6 +100,8 @@ static const struct luaL_reg urllib_m[] = { {"get_redirected", lua_url_get_phished}, LUA_INTERFACE_DEF (url, set_redirected), {"__tostring", lua_url_tostring}, + {"__eq", lua_url_eq}, + {"__lt", lua_url_lt}, {NULL, NULL} }; @@ -1234,6 +1238,41 @@ lua_url_adjust_skip_prob (gdouble timestamp, } static gint +lua_url_eq (lua_State *L) +{ + LUA_TRACE_POINT; + struct rspamd_lua_url *u1 = lua_check_url (L, 1), + *u2 = lua_check_url (L, 2); + + if (u1 && u2) { + lua_pushboolean (L, (rspamd_url_cmp (u1->url, u2->url) == 0)); + } + else { + lua_pushboolean (L, false); + } + + return 1; +} + +static gint +lua_text_lt (lua_State *L) +{ + LUA_TRACE_POINT; + struct rspamd_lua_url *u1 = lua_check_url (L, 1), + *u2 = lua_check_url (L, 2); + + if (u1 && u2) { + lua_pushinteger (L, rspamd_url_cmp (u1->url, u2->url)); + } + else { + return luaL_error (L, "invalid arguments"); + } + + return 1; +} + + +static gint lua_load_url (lua_State * L) { lua_newtable (L); |