From: Vsevolod Stakhov Date: Sat, 16 Feb 2019 13:53:14 +0000 (+0000) Subject: [Minor] Lua_url: Add method to get url protocol X-Git-Tag: 1.9.0~138 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=eb697d4c984cca0f6e5566ac8c727f216b3f86fc;p=rspamd.git [Minor] Lua_url: Add method to get url protocol --- diff --git a/src/lua/lua_url.c b/src/lua/lua_url.c index 8bc0cf657..69a12e028 100644 --- a/src/lua/lua_url.c +++ b/src/lua/lua_url.c @@ -51,6 +51,7 @@ LUA_FUNCTION_DEF (url, tostring); LUA_FUNCTION_DEF (url, get_raw); LUA_FUNCTION_DEF (url, get_tld); LUA_FUNCTION_DEF (url, get_flags); +LUA_FUNCTION_DEF (url, get_protocol); LUA_FUNCTION_DEF (url, to_table); LUA_FUNCTION_DEF (url, is_phished); LUA_FUNCTION_DEF (url, is_redirected); @@ -77,6 +78,7 @@ static const struct luaL_reg urllib_m[] = { LUA_INTERFACE_DEF (url, get_text), LUA_INTERFACE_DEF (url, get_tld), LUA_INTERFACE_DEF (url, get_raw), + LUA_INTERFACE_DEF (url, get_protocol), LUA_INTERFACE_DEF (url, to_table), LUA_INTERFACE_DEF (url, is_phished), LUA_INTERFACE_DEF (url, is_redirected), @@ -606,6 +608,27 @@ lua_url_get_tld (lua_State *L) return 1; } +/*** + * @method url:get_protocol() + * Get protocol name + * @return {string} protocol as a string + */ +static gint +lua_url_get_protocol (lua_State *L) +{ + LUA_TRACE_POINT; + struct rspamd_lua_url *url = lua_check_url (L, 1); + + if (url != NULL && url->url->protocol != PROTOCOL_UNKNOWN) { + lua_pushstring (L, rspamd_url_protocol_name (url->url->protocol)); + } + else { + lua_pushnil (L); + } + + return 1; +} + /*** * @method url:get_count() * Return number of occurrencies for this particular URL