commit eb697d4: [Minor] Lua_url: Add method to get url protocol

Vsevolod Stakhov vsevolod at highsecure.ru
Sat Feb 16 14:28:05 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-02-16 13:53:14 +0000
URL: https://github.com/rspamd/rspamd/commit/eb697d4c984cca0f6e5566ac8c727f216b3f86fc

[Minor] Lua_url: Add method to get url protocol

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

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


More information about the Commits mailing list