aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-04-15 17:49:01 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-04-15 17:49:01 +0100
commit6d54321eb9fb0a45026fc4d343355993fa288946 (patch)
tree3a967988c484429dcf89e24393a1cb83ab8d3328 /src/lua
parent2ac0ad45badeb5e0d2c4d6ebbafdbd46bd491ac5 (diff)
downloadrspamd-6d54321eb9fb0a45026fc4d343355993fa288946.tar.gz
rspamd-6d54321eb9fb0a45026fc4d343355993fa288946.zip
Write documentation for lua_url.
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_url.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/lua/lua_url.c b/src/lua/lua_url.c
index 8c0fbd739..783136242 100644
--- a/src/lua/lua_url.c
+++ b/src/lua/lua_url.c
@@ -23,6 +23,28 @@
#include "lua_common.h"
+/***
+ * @module rspamd_url
+ * This module provides routines to handle URL's and extract URL's from the text.
+ * Objects of this class are returned, for example, by `task:get_urls()` or `task:get_emails()`.
+ * You can also create `rspamd_url` from any text.
+ * @example
+local url = require "rspamd_url"
+local pool = mpool.create()
+local res = url.create(pool, 'Look at: http://user@test.example.com/test?query")
+local t = res:to_table()
+-- Content of t:
+-- url = ['http://test.example.com/test?query']
+-- host = ['test.example.com']
+-- user = ['user']
+-- path = ['test']
+-- tld = ['example.com']
+
+pool:destroy() -- res is destroyed here, so you should not use it afterwards
+
+local mistake = res:to_table() -- INVALID! as pool is destroyed
+ */
+
/* URL methods */
LUA_FUNCTION_DEF (url, get_length);
LUA_FUNCTION_DEF (url, get_host);
@@ -63,6 +85,11 @@ lua_check_url (lua_State * L, gint pos)
}
+/***
+ * @method url:get_length()
+ * Get length of the url
+ * @return {number} length of url in bytes
+ */
static gint
lua_url_get_length (lua_State *L)
{
@@ -77,6 +104,11 @@ lua_url_get_length (lua_State *L)
return 1;
}
+/***
+ * @method url:get_host()
+ * Get domain part of the url
+ * @return {string} domain part of URL
+ */
static gint
lua_url_get_host (lua_State *L)
{
@@ -91,6 +123,11 @@ lua_url_get_host (lua_State *L)
return 1;
}
+/***
+ * @method url:get_user()
+ * Get user part of the url (e.g. username in email)
+ * @return {string} user part of URL
+ */
static gint
lua_url_get_user (lua_State *L)
{
@@ -106,6 +143,11 @@ lua_url_get_user (lua_State *L)
return 1;
}
+/***
+ * @method url:get_path()
+ * Get path of the url
+ * @return {string} path part of URL
+ */
static gint
lua_url_get_path (lua_State *L)
{
@@ -121,6 +163,11 @@ lua_url_get_path (lua_State *L)
return 1;
}
+/***
+ * @method url:get_text()
+ * Get full content of the url
+ * @return {string} url string
+ */
static gint
lua_url_get_text (lua_State *L)
{
@@ -136,6 +183,11 @@ lua_url_get_text (lua_State *L)
return 1;
}
+/***
+ * @method url:is_phished()
+ * Check whether URL is treated as phished
+ * @return {boolean} `true` if URL is phished
+ */
static gint
lua_url_is_phished (lua_State *L)
{
@@ -151,6 +203,11 @@ lua_url_is_phished (lua_State *L)
return 1;
}
+/***
+ * @method url:get_phished()
+ * Get another URL that pretends to be this URL (e.g. used in phishing)
+ * @return {url} phished URL
+ */
static gint
lua_url_get_phished (lua_State *L)
{
@@ -170,6 +227,11 @@ lua_url_get_phished (lua_State *L)
return 1;
}
+/***
+ * @method url:get_tld()
+ * Get top level domain part of the url host
+ * @return {string} top level part of the url host
+ */
static gint
lua_url_get_tld (lua_State *L)
{
@@ -185,6 +247,18 @@ lua_url_get_tld (lua_State *L)
return 1;
}
+/***
+ * @method url:to_table()
+ * Return url as a table with the following fields:
+ *
+ * - `url`: full content
+ * - `host`: hostname part
+ * - `user`: user part
+ * - `path`: path part
+ * - `tld`: top level domain
+ * - `protocol`: url protocol
+ * @return {table} URL as a table
+ */
static gint
lua_url_to_table (lua_State *L)
{
@@ -254,6 +328,12 @@ lua_url_to_table (lua_State *L)
return 1;
}
+/***
+ * @function url.create(mempool, str)
+ * @param {rspamd_mempool} memory pool for URL, e.g. `task:get_mempool()`
+ * @param {string} text that contains URL (can also contain other stuff)
+ * @return {url} new url object that exists as long as the corresponding mempool exists
+ */
static gint
lua_url_create (lua_State *L)
{