From fed128523e71f89cb2222552cfbc7228ee5f89f6 Mon Sep 17 00:00:00 2001 From: Dhawal Arora Date: Fri, 24 Apr 2015 04:10:44 +0530 Subject: [PATCH] extract all URLs from a text --- src/lua/lua_url.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/lua/lua_url.c b/src/lua/lua_url.c index 783136242..5c6eb4135 100644 --- a/src/lua/lua_url.c +++ b/src/lua/lua_url.c @@ -56,6 +56,7 @@ LUA_FUNCTION_DEF (url, to_table); LUA_FUNCTION_DEF (url, is_phished); LUA_FUNCTION_DEF (url, get_phished); LUA_FUNCTION_DEF (url, create); +LUA_FUNCTION_DEF (url, all); static const struct luaL_reg urllib_m[] = { LUA_INTERFACE_DEF (url, get_length), @@ -73,6 +74,7 @@ static const struct luaL_reg urllib_m[] = { static const struct luaL_reg urllib_f[] = { LUA_INTERFACE_DEF (url, create), + LUA_INTERFACE_DEF (url, all), {NULL, NULL} }; @@ -369,6 +371,49 @@ lua_url_create (lua_State *L) return 1; } +static gint +lua_url_all (lua_State *L) +{ + struct rspamd_url *url; + rspamd_mempool_t *pool = rspamd_lua_check_mempool (L, 1); + const gchar *text,*end; + gint length,i; + const gchar **pos; + + if (pool == NULL) { + lua_pushnil (L); + } + else { + text = luaL_checkstring (L, 2); + + if (text != NULL) { + length = strlen(text); + *pos=text; + end=text+length; + lua_newtable(L); + while(*pos<=end){ + url = rspamd_url_get_next (pool, text, pos, NULL); + + if (url!=NULL) { + lua_pushinteger (L, i); + lua_pushlstring (L, url->string, url->urllen); + lua_settable (L, -3); + } + i++; + } + + } + else { + lua_pushnil (L); + } + } + + + return 1; + +} + + static gint lua_load_url (lua_State * L) { -- 2.39.5