Browse Source

[Minor] Improve tostring method for MAILTO urls

tags/1.8.0
Vsevolod Stakhov 5 years ago
parent
commit
f31b982955
1 changed files with 34 additions and 1 deletions
  1. 34
    1
      src/lua/lua_url.c

+ 34
- 1
src/lua/lua_url.c View File

@@ -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}
};

@@ -274,6 +275,38 @@ lua_url_get_text (lua_State *L)
return 1;
}

/***
* @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)

Loading…
Cancel
Save