aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-04-26 22:10:38 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-04-26 22:10:38 +0100
commitbb974d3e3f825b7ca9b9394acac683ee7c567867 (patch)
treec08c0eec35fcec093b79ffc0122a5ca7010e85bb
parentdffdfc8492fb524f0239d85cdfbc4d4e5afb6ef6 (diff)
parentf35f923d625287a899848016f4c116b613eded0f (diff)
downloadrspamd-bb974d3e3f825b7ca9b9394acac683ee7c567867.tar.gz
rspamd-bb974d3e3f825b7ca9b9394acac683ee7c567867.zip
Merge pull request #270 from awhitesong/liburl
extract all URLs from a text
-rw-r--r--src/lua/lua_url.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/lua/lua_url.c b/src/lua/lua_url.c
index 783136242..6ed9f06c0 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,56 @@ lua_url_create (lua_State *L)
}
static gint
+lua_url_all (lua_State *L)
+{
+ struct rspamd_url *url;
+ struct rspamd_lua_url *lua_url;
+ rspamd_mempool_t *pool = rspamd_lua_check_mempool (L, 1);
+ const gchar *text,*end;
+ gint i = 1;
+ size_t length;
+ const gchar **pos;
+
+ if (pool == NULL) {
+ lua_pushnil (L);
+ }
+ else {
+ text = luaL_checklstring (L, 2, &length);
+
+ if (text != NULL) {
+ *pos = text;
+ end = text + length;
+ lua_newtable (L);
+
+ while (*pos <= end) {
+ url = rspamd_url_get_next (pool, text, pos, NULL);
+
+ if (url != NULL) {
+ lua_url = lua_newuserdata (L, sizeof (struct rspamd_lua_url));
+ rspamd_lua_setclass (L, "rspamd{url}", -1);
+ lua_url->url = url;
+ lua_pushinteger (L, i++);
+ lua_pushlstring (L, url->string, url->urllen);
+ lua_settable (L, -3);
+ }
+ else{
+ break;
+ }
+ }
+
+ }
+ else {
+ lua_pushnil (L);
+ }
+ }
+
+
+ return 1;
+
+}
+
+
+static gint
lua_load_url (lua_State * L)
{
lua_newtable (L);