aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_url.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-09-22 09:17:55 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-09-22 09:17:55 +0100
commitf31b982955ca7ffac328514d4ba660e6f3f41941 (patch)
tree4ddd25e2c29182ed0f1c3182fe6f3055dd249fd9 /src/lua/lua_url.c
parent795a226bcae37179e58ba08c2fd41638bbbecd94 (diff)
downloadrspamd-f31b982955ca7ffac328514d4ba660e6f3f41941.tar.gz
rspamd-f31b982955ca7ffac328514d4ba660e6f3f41941.zip
[Minor] Improve tostring method for MAILTO urls
Diffstat (limited to 'src/lua/lua_url.c')
-rw-r--r--src/lua/lua_url.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/lua/lua_url.c b/src/lua/lua_url.c
index 5dee14224..8b18c7c3d 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, tostring);
LUA_FUNCTION_DEF (url, get_raw);
LUA_FUNCTION_DEF (url, get_tld);
LUA_FUNCTION_DEF (url, get_flags);
@@ -89,7 +90,7 @@ static const struct luaL_reg urllib_m[] = {
LUA_INTERFACE_DEF (url, get_count),
LUA_INTERFACE_DEF (url, get_flags),
{"get_redirected", lua_url_get_phished},
- {"__tostring", lua_url_get_text},
+ {"__tostring", lua_url_tostring},
{NULL, NULL}
};
@@ -275,6 +276,38 @@ lua_url_get_text (lua_State *L)
}
/***
+ * @method url:tostring()
+ * Get full content of the url or user@domain in case of email
+ * @return {string} url as a string
+ */
+static gint
+lua_url_tostring (lua_State *L)
+{
+ LUA_TRACE_POINT;
+ struct rspamd_lua_url *url = lua_check_url (L, 1);
+
+ if (url != NULL && url->url != NULL) {
+ if (url->url->protocol == PROTOCOL_MAILTO) {
+ if (url->url->userlen + 1 + url->url->hostlen >= url->url->urllen) {
+ lua_pushlstring (L, url->url->user,
+ url->url->userlen + 1 + url->url->hostlen);
+ }
+ else {
+ lua_pushlstring (L, url->url->string, url->url->urllen);
+ }
+ }
+ else {
+ lua_pushlstring (L, url->url->string, url->url->urllen);
+ }
+ }
+ else {
+ lua_pushnil (L);
+ }
+
+ return 1;
+}
+
+/***
* @method url:get_raw()
* Get full content of the url as it was parsed (e.g. with urldecode)
* @return {string} url string