diff options
author | Dhawal Arora <d.p.arora1@gmail.com> | 2015-04-24 04:10:44 +0530 |
---|---|---|
committer | Dhawal Arora <d.p.arora1@gmail.com> | 2015-04-24 04:10:44 +0530 |
commit | fed128523e71f89cb2222552cfbc7228ee5f89f6 (patch) | |
tree | abd9bc3dd5fa241b6bfe4cd840b1ab13d1096cb0 | |
parent | 1e479ff05948433d35602b0443260de904d405c1 (diff) | |
download | rspamd-fed128523e71f89cb2222552cfbc7228ee5f89f6.tar.gz rspamd-fed128523e71f89cb2222552cfbc7228ee5f89f6.zip |
extract all URLs from a text
-rw-r--r-- | src/lua/lua_url.c | 45 |
1 files changed, 45 insertions, 0 deletions
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} }; @@ -370,6 +372,49 @@ lua_url_create (lua_State *L) } 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) { lua_newtable (L); |