summaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-08-12 18:04:13 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-08-12 20:26:17 +0100
commit809d57ec6a1152b040a24c2ede1d22c5effc0dcb (patch)
treeb498358e699fa270fd4277ba460459f6f1fdf2bf /src/lua
parent9f825e53d329e67a15f77d09b546e8f840e81fa8 (diff)
downloadrspamd-809d57ec6a1152b040a24c2ede1d22c5effc0dcb.tar.gz
rspamd-809d57ec6a1152b040a24c2ede1d22c5effc0dcb.zip
[Minor] Store raw urls
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_http.c3
-rw-r--r--src/lua/lua_url.c22
2 files changed, 25 insertions, 0 deletions
diff --git a/src/lua/lua_http.c b/src/lua/lua_http.c
index a655b8ec0..34a31bde8 100644
--- a/src/lua/lua_http.c
+++ b/src/lua/lua_http.c
@@ -366,13 +366,16 @@ lua_http_request (lua_State *L)
if (lua_gettop (L) >= 2) {
/* url, callback and event_base format */
url = luaL_checkstring (L, 1);
+
if (url == NULL || lua_type (L, 2) != LUA_TFUNCTION) {
msg_err ("http request has bad params");
lua_pushboolean (L, FALSE);
return 1;
}
+
lua_pushvalue (L, 2);
cbref = luaL_ref (L, LUA_REGISTRYINDEX);
+
if (lua_gettop (L) >= 3 && rspamd_lua_check_udata_maybe (L, 3, "rspamd{ev_base}")) {
ev_base = *(struct event_base **)lua_touserdata (L, 3);
}
diff --git a/src/lua/lua_url.c b/src/lua/lua_url.c
index 15966bfa3..cbe9148a3 100644
--- a/src/lua/lua_url.c
+++ b/src/lua/lua_url.c
@@ -47,6 +47,7 @@ LUA_FUNCTION_DEF (url, get_path);
LUA_FUNCTION_DEF (url, get_query);
LUA_FUNCTION_DEF (url, get_fragment);
LUA_FUNCTION_DEF (url, get_text);
+LUA_FUNCTION_DEF (url, get_raw);
LUA_FUNCTION_DEF (url, get_tld);
LUA_FUNCTION_DEF (url, to_table);
LUA_FUNCTION_DEF (url, is_phished);
@@ -73,6 +74,7 @@ static const struct luaL_reg urllib_m[] = {
LUA_INTERFACE_DEF (url, get_fragment),
LUA_INTERFACE_DEF (url, get_text),
LUA_INTERFACE_DEF (url, get_tld),
+ LUA_INTERFACE_DEF (url, get_raw),
LUA_INTERFACE_DEF (url, to_table),
LUA_INTERFACE_DEF (url, is_phished),
LUA_INTERFACE_DEF (url, is_redirected),
@@ -263,6 +265,26 @@ lua_url_get_text (lua_State *L)
}
/***
+ * @method url:get_raw()
+ * Get full content of the url as it was parsed (e.g. with urldecode)
+ * @return {string} url string
+ */
+static gint
+lua_url_get_raw (lua_State *L)
+{
+ struct rspamd_lua_url *url = lua_check_url (L, 1);
+
+ if (url != NULL) {
+ lua_pushlstring (L, url->url->raw, url->url->rawlen);
+ }
+ else {
+ lua_pushnil (L);
+ }
+
+ return 1;
+}
+
+/***
* @method url:is_phished()
* Check whether URL is treated as phished
* @return {boolean} `true` if URL is phished