From: Miecio Za Date: Wed, 27 Feb 2019 10:56:35 +0000 (+0100) Subject: [Feature] Export visible part of url to lua X-Git-Tag: 1.9.0~19^2~2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=add9595913c3f456c6328a53801739cdca70da9d;p=rspamd.git [Feature] Export visible part of url to lua Export visible part of url to lua --- diff --git a/src/libserver/html.c b/src/libserver/html.c index 31438ddad..70b66ccc0 100644 --- a/src/libserver/html.c +++ b/src/libserver/html.c @@ -2373,6 +2373,12 @@ rspamd_html_check_displayed_url (rspamd_mempool_t *pool, return; } + gint visible_part_len = dest->len - href_offset; + url->visible_part = rspamd_mempool_alloc0(pool, visible_part_len +1); + url->visible_partlen = visible_part_len; + gchar *visible_part = g_strndup(dest->data + href_offset, visible_part_len); + g_stpcpy(url->visible_part, visible_part); + rspamd_html_url_is_phished (pool, url, dest->data + href_offset, dest->len - href_offset, diff --git a/src/libserver/url.h b/src/libserver/url.h index 4d1948921..571424099 100644 --- a/src/libserver/url.h +++ b/src/libserver/url.h @@ -48,6 +48,7 @@ struct rspamd_url { gchar *fragment; gchar *surbl; gchar *tld; + gchar *visible_part; struct rspamd_url *phished_url; @@ -61,6 +62,7 @@ struct rspamd_url { guint tldlen; guint urllen; guint rawlen; + guint visible_partlen; enum rspamd_url_flags flags; guint count; diff --git a/src/lua/lua_url.c b/src/lua/lua_url.c index 0a301e96d..7bad50359 100644 --- a/src/lua/lua_url.c +++ b/src/lua/lua_url.c @@ -63,6 +63,7 @@ LUA_FUNCTION_DEF (url, get_tag); LUA_FUNCTION_DEF (url, get_count); LUA_FUNCTION_DEF (url, get_tags); LUA_FUNCTION_DEF (url, add_tag); +LUA_FUNCTION_DEF (url, get_visible); LUA_FUNCTION_DEF (url, create); LUA_FUNCTION_DEF (url, init); LUA_FUNCTION_DEF (url, all); @@ -89,6 +90,7 @@ static const struct luaL_reg urllib_m[] = { LUA_INTERFACE_DEF (url, get_tag), LUA_INTERFACE_DEF (url, get_tags), LUA_INTERFACE_DEF (url, add_tag), + LUA_INTERFACE_DEF (url, get_visible), LUA_INTERFACE_DEF (url, get_count), LUA_INTERFACE_DEF (url, get_flags), {"get_redirected", lua_url_get_phished}, @@ -650,6 +652,27 @@ lua_url_get_count (lua_State *L) return 1; } + /*** +* @method url:get_visible() +* Get visible part of the url with html tags stripped +* @return {string} url string +*/ +static gint +lua_url_get_visible (lua_State *L) +{ + LUA_TRACE_POINT; + struct rspamd_lua_url *url = lua_check_url (L, 1); + + if (url != NULL) { + lua_pushlstring (L, url->url->visible_part, url->url->visible_partlen); + } + else { + lua_pushnil (L); + } + +return 1; +} + /*** * @method url:to_table() * Return url as a table with the following fields: