aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_url.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2023-07-26 10:49:23 +0100
committerVsevolod Stakhov <vsevolod@rspamd.com>2023-07-26 10:49:23 +0100
commit537a7180a0d5132c11636c4fd8b1450cd99d352c (patch)
treefb9f8c84955a411bdffbd6371ea32f2716fb3687 /src/lua/lua_url.c
parent5fd7a90fdaa33f52c59bdb0ca84451e5c1e22365 (diff)
downloadrspamd-537a7180a0d5132c11636c4fd8b1450cd99d352c.tar.gz
rspamd-537a7180a0d5132c11636c4fd8b1450cd99d352c.zip
[Rework] Use clang-format to unify formatting in all sources
No meaningful changes.
Diffstat (limited to 'src/lua/lua_url.c')
-rw-r--r--src/lua/lua_url.c808
1 files changed, 402 insertions, 406 deletions
diff --git a/src/lua/lua_url.c b/src/lua/lua_url.c
index 809bd36d3..4dd09dec8 100644
--- a/src/lua/lua_url.c
+++ b/src/lua/lua_url.c
@@ -43,92 +43,90 @@ local mistake = res:to_table() -- INVALID! as pool is destroyed
*/
/* URL methods */
-LUA_FUNCTION_DEF (url, get_length);
-LUA_FUNCTION_DEF (url, get_host);
-LUA_FUNCTION_DEF (url, get_port);
-LUA_FUNCTION_DEF (url, get_user);
-LUA_FUNCTION_DEF (url, get_path);
-LUA_FUNCTION_DEF (url, get_query);
-LUA_FUNCTION_DEF (url, get_fragment);
-LUA_FUNCTION_DEF (url, get_text);
-LUA_FUNCTION_DEF (url, tostring);
-LUA_FUNCTION_DEF (url, get_raw);
-LUA_FUNCTION_DEF (url, get_tld);
-LUA_FUNCTION_DEF (url, get_flags);
-LUA_FUNCTION_DEF (url, get_flags_num);
-LUA_FUNCTION_DEF (url, get_protocol);
-LUA_FUNCTION_DEF (url, to_table);
-LUA_FUNCTION_DEF (url, is_phished);
-LUA_FUNCTION_DEF (url, is_redirected);
-LUA_FUNCTION_DEF (url, is_obscured);
-LUA_FUNCTION_DEF (url, is_html_displayed);
-LUA_FUNCTION_DEF (url, is_subject);
-LUA_FUNCTION_DEF (url, get_phished);
-LUA_FUNCTION_DEF (url, set_redirected);
-LUA_FUNCTION_DEF (url, get_count);
-LUA_FUNCTION_DEF (url, get_visible);
-LUA_FUNCTION_DEF (url, create);
-LUA_FUNCTION_DEF (url, init);
-LUA_FUNCTION_DEF (url, all);
-LUA_FUNCTION_DEF (url, lt);
-LUA_FUNCTION_DEF (url, eq);
+LUA_FUNCTION_DEF(url, get_length);
+LUA_FUNCTION_DEF(url, get_host);
+LUA_FUNCTION_DEF(url, get_port);
+LUA_FUNCTION_DEF(url, get_user);
+LUA_FUNCTION_DEF(url, get_path);
+LUA_FUNCTION_DEF(url, get_query);
+LUA_FUNCTION_DEF(url, get_fragment);
+LUA_FUNCTION_DEF(url, get_text);
+LUA_FUNCTION_DEF(url, tostring);
+LUA_FUNCTION_DEF(url, get_raw);
+LUA_FUNCTION_DEF(url, get_tld);
+LUA_FUNCTION_DEF(url, get_flags);
+LUA_FUNCTION_DEF(url, get_flags_num);
+LUA_FUNCTION_DEF(url, get_protocol);
+LUA_FUNCTION_DEF(url, to_table);
+LUA_FUNCTION_DEF(url, is_phished);
+LUA_FUNCTION_DEF(url, is_redirected);
+LUA_FUNCTION_DEF(url, is_obscured);
+LUA_FUNCTION_DEF(url, is_html_displayed);
+LUA_FUNCTION_DEF(url, is_subject);
+LUA_FUNCTION_DEF(url, get_phished);
+LUA_FUNCTION_DEF(url, set_redirected);
+LUA_FUNCTION_DEF(url, get_count);
+LUA_FUNCTION_DEF(url, get_visible);
+LUA_FUNCTION_DEF(url, create);
+LUA_FUNCTION_DEF(url, init);
+LUA_FUNCTION_DEF(url, all);
+LUA_FUNCTION_DEF(url, lt);
+LUA_FUNCTION_DEF(url, eq);
static const struct luaL_reg urllib_m[] = {
- LUA_INTERFACE_DEF (url, get_length),
- LUA_INTERFACE_DEF (url, get_host),
- LUA_INTERFACE_DEF (url, get_port),
- LUA_INTERFACE_DEF (url, get_user),
- LUA_INTERFACE_DEF (url, get_path),
- LUA_INTERFACE_DEF (url, get_query),
- LUA_INTERFACE_DEF (url, get_fragment),
- LUA_INTERFACE_DEF (url, get_text),
- LUA_INTERFACE_DEF (url, get_tld),
- LUA_INTERFACE_DEF (url, get_raw),
- LUA_INTERFACE_DEF (url, get_protocol),
- LUA_INTERFACE_DEF (url, to_table),
- LUA_INTERFACE_DEF (url, is_phished),
- LUA_INTERFACE_DEF (url, is_redirected),
- LUA_INTERFACE_DEF (url, is_obscured),
- LUA_INTERFACE_DEF (url, is_html_displayed),
- LUA_INTERFACE_DEF (url, is_subject),
- LUA_INTERFACE_DEF (url, get_phished),
-
- LUA_INTERFACE_DEF (url, get_visible),
- LUA_INTERFACE_DEF (url, get_count),
- LUA_INTERFACE_DEF (url, get_flags),
- LUA_INTERFACE_DEF (url, get_flags_num),
+ LUA_INTERFACE_DEF(url, get_length),
+ LUA_INTERFACE_DEF(url, get_host),
+ LUA_INTERFACE_DEF(url, get_port),
+ LUA_INTERFACE_DEF(url, get_user),
+ LUA_INTERFACE_DEF(url, get_path),
+ LUA_INTERFACE_DEF(url, get_query),
+ LUA_INTERFACE_DEF(url, get_fragment),
+ LUA_INTERFACE_DEF(url, get_text),
+ LUA_INTERFACE_DEF(url, get_tld),
+ LUA_INTERFACE_DEF(url, get_raw),
+ LUA_INTERFACE_DEF(url, get_protocol),
+ LUA_INTERFACE_DEF(url, to_table),
+ LUA_INTERFACE_DEF(url, is_phished),
+ LUA_INTERFACE_DEF(url, is_redirected),
+ LUA_INTERFACE_DEF(url, is_obscured),
+ LUA_INTERFACE_DEF(url, is_html_displayed),
+ LUA_INTERFACE_DEF(url, is_subject),
+ LUA_INTERFACE_DEF(url, get_phished),
+
+ LUA_INTERFACE_DEF(url, get_visible),
+ LUA_INTERFACE_DEF(url, get_count),
+ LUA_INTERFACE_DEF(url, get_flags),
+ LUA_INTERFACE_DEF(url, get_flags_num),
{"get_redirected", lua_url_get_phished},
- LUA_INTERFACE_DEF (url, set_redirected),
+ LUA_INTERFACE_DEF(url, set_redirected),
{"__tostring", lua_url_tostring},
{"__eq", lua_url_eq},
{"__lt", lua_url_lt},
- {NULL, NULL}
-};
+ {NULL, NULL}};
static const struct luaL_reg urllib_f[] = {
- LUA_INTERFACE_DEF (url, init),
- LUA_INTERFACE_DEF (url, create),
- LUA_INTERFACE_DEF (url, all),
- {NULL, NULL}
-};
+ LUA_INTERFACE_DEF(url, init),
+ LUA_INTERFACE_DEF(url, create),
+ LUA_INTERFACE_DEF(url, all),
+ {NULL, NULL}};
struct rspamd_lua_url *
-lua_check_url (lua_State * L, gint pos)
+lua_check_url(lua_State *L, gint pos)
{
- void *ud = rspamd_lua_check_udata (L, pos, "rspamd{url}");
- luaL_argcheck (L, ud != NULL, pos, "'url' expected");
- return ud ? ((struct rspamd_lua_url *)ud) : NULL;
+ void *ud = rspamd_lua_check_udata(L, pos, "rspamd{url}");
+ luaL_argcheck(L, ud != NULL, pos, "'url' expected");
+ return ud ? ((struct rspamd_lua_url *) ud) : NULL;
}
static gboolean
-lua_url_single_inserter (struct rspamd_url *url, gsize start_offset,
- gsize end_offset, gpointer ud)
+lua_url_single_inserter(struct rspamd_url *url, gsize start_offset,
+ gsize end_offset, gpointer ud)
{
lua_State *L = ud;
struct rspamd_lua_url *lua_url;
- lua_url = lua_newuserdata (L, sizeof (struct rspamd_lua_url));
- rspamd_lua_setclass (L, "rspamd{url}", -1);
+ lua_url = lua_newuserdata(L, sizeof(struct rspamd_lua_url));
+ rspamd_lua_setclass(L, "rspamd{url}", -1);
lua_url->url = url;
return TRUE;
@@ -140,16 +138,16 @@ lua_url_single_inserter (struct rspamd_url *url, gsize start_offset,
* @return {number} length of url in bytes
*/
static gint
-lua_url_get_length (lua_State *L)
+lua_url_get_length(lua_State *L)
{
LUA_TRACE_POINT;
- struct rspamd_lua_url *url = lua_check_url (L, 1);
+ struct rspamd_lua_url *url = lua_check_url(L, 1);
if (url != NULL) {
- lua_pushinteger (L, url->url->urllen);
+ lua_pushinteger(L, url->url->urllen);
}
else {
- lua_pushnil (L);
+ lua_pushnil(L);
}
return 1;
}
@@ -160,16 +158,16 @@ lua_url_get_length (lua_State *L)
* @return {string} domain part of URL
*/
static gint
-lua_url_get_host (lua_State *L)
+lua_url_get_host(lua_State *L)
{
LUA_TRACE_POINT;
- struct rspamd_lua_url *url = lua_check_url (L, 1);
+ struct rspamd_lua_url *url = lua_check_url(L, 1);
if (url != NULL && url->url && url->url->hostlen > 0) {
- lua_pushlstring (L, rspamd_url_host (url->url), url->url->hostlen);
+ lua_pushlstring(L, rspamd_url_host(url->url), url->url->hostlen);
}
else {
- lua_pushnil (L);
+ lua_pushnil(L);
}
return 1;
}
@@ -180,21 +178,21 @@ lua_url_get_host (lua_State *L)
* @return {number} url port
*/
static gint
-lua_url_get_port (lua_State *L)
+lua_url_get_port(lua_State *L)
{
LUA_TRACE_POINT;
- struct rspamd_lua_url *url = lua_check_url (L, 1);
+ struct rspamd_lua_url *url = lua_check_url(L, 1);
if (url != NULL) {
if (rspamd_url_get_port_if_special(url->url) == 0) {
- lua_pushnil (L);
+ lua_pushnil(L);
}
else {
- lua_pushinteger (L, rspamd_url_get_port_if_special(url->url));
+ lua_pushinteger(L, rspamd_url_get_port_if_special(url->url));
}
}
else {
- lua_pushnil (L);
+ lua_pushnil(L);
}
return 1;
}
@@ -205,16 +203,16 @@ lua_url_get_port (lua_State *L)
* @return {string} user part of URL
*/
static gint
-lua_url_get_user (lua_State *L)
+lua_url_get_user(lua_State *L)
{
LUA_TRACE_POINT;
- struct rspamd_lua_url *url = lua_check_url (L, 1);
+ struct rspamd_lua_url *url = lua_check_url(L, 1);
- if (url != NULL && rspamd_url_user (url->url) != NULL) {
- lua_pushlstring (L, rspamd_url_user (url->url), url->url->userlen);
+ if (url != NULL && rspamd_url_user(url->url) != NULL) {
+ lua_pushlstring(L, rspamd_url_user(url->url), url->url->userlen);
}
else {
- lua_pushnil (L);
+ lua_pushnil(L);
}
return 1;
@@ -226,16 +224,16 @@ lua_url_get_user (lua_State *L)
* @return {string} path part of URL
*/
static gint
-lua_url_get_path (lua_State *L)
+lua_url_get_path(lua_State *L)
{
LUA_TRACE_POINT;
- struct rspamd_lua_url *url = lua_check_url (L, 1);
+ struct rspamd_lua_url *url = lua_check_url(L, 1);
if (url != NULL && url->url->datalen > 0) {
- lua_pushlstring (L, rspamd_url_data_unsafe (url->url), url->url->datalen);
+ lua_pushlstring(L, rspamd_url_data_unsafe(url->url), url->url->datalen);
}
else {
- lua_pushnil (L);
+ lua_pushnil(L);
}
return 1;
@@ -247,16 +245,16 @@ lua_url_get_path (lua_State *L)
* @return {string} query part of URL
*/
static gint
-lua_url_get_query (lua_State *L)
+lua_url_get_query(lua_State *L)
{
LUA_TRACE_POINT;
- struct rspamd_lua_url *url = lua_check_url (L, 1);
+ struct rspamd_lua_url *url = lua_check_url(L, 1);
if (url != NULL && url->url->querylen > 0) {
- lua_pushlstring (L, rspamd_url_query_unsafe (url->url), url->url->querylen);
+ lua_pushlstring(L, rspamd_url_query_unsafe(url->url), url->url->querylen);
}
else {
- lua_pushnil (L);
+ lua_pushnil(L);
}
return 1;
@@ -268,16 +266,16 @@ lua_url_get_query (lua_State *L)
* @return {string} fragment part of URL
*/
static gint
-lua_url_get_fragment (lua_State *L)
+lua_url_get_fragment(lua_State *L)
{
LUA_TRACE_POINT;
- struct rspamd_lua_url *url = lua_check_url (L, 1);
+ struct rspamd_lua_url *url = lua_check_url(L, 1);
if (url != NULL && url->url->fragmentlen > 0) {
- lua_pushlstring (L, rspamd_url_fragment_unsafe (url->url), url->url->fragmentlen);
+ lua_pushlstring(L, rspamd_url_fragment_unsafe(url->url), url->url->fragmentlen);
}
else {
- lua_pushnil (L);
+ lua_pushnil(L);
}
return 1;
@@ -289,16 +287,16 @@ lua_url_get_fragment (lua_State *L)
* @return {string} url string
*/
static gint
-lua_url_get_text (lua_State *L)
+lua_url_get_text(lua_State *L)
{
LUA_TRACE_POINT;
- struct rspamd_lua_url *url = lua_check_url (L, 1);
+ struct rspamd_lua_url *url = lua_check_url(L, 1);
if (url != NULL) {
- lua_pushlstring (L, url->url->string, url->url->urllen);
+ lua_pushlstring(L, url->url->string, url->url->urllen);
}
else {
- lua_pushnil (L);
+ lua_pushnil(L);
}
return 1;
@@ -310,32 +308,32 @@ lua_url_get_text (lua_State *L)
* @return {string} url as a string
*/
static gint
-lua_url_tostring (lua_State *L)
+lua_url_tostring(lua_State *L)
{
LUA_TRACE_POINT;
- struct rspamd_lua_url *url = lua_check_url (L, 1);
+ struct rspamd_lua_url *url = lua_check_url(L, 1);
if (url != NULL && url->url != NULL) {
if (url->url->protocol == PROTOCOL_MAILTO) {
- gchar *tmp = g_malloc (url->url->userlen + 1 +
- url->url->hostlen);
+ gchar *tmp = g_malloc(url->url->userlen + 1 +
+ url->url->hostlen);
if (url->url->userlen) {
- memcpy (tmp, url->url->string + url->url->usershift, url->url->userlen);
+ memcpy(tmp, url->url->string + url->url->usershift, url->url->userlen);
}
tmp[url->url->userlen] = '@';
- memcpy (tmp + url->url->userlen + 1, rspamd_url_host_unsafe (url->url),
- url->url->hostlen);
+ memcpy(tmp + url->url->userlen + 1, rspamd_url_host_unsafe(url->url),
+ url->url->hostlen);
- lua_pushlstring (L, tmp, url->url->userlen + 1 + url->url->hostlen);
- g_free (tmp);
+ lua_pushlstring(L, tmp, url->url->userlen + 1 + url->url->hostlen);
+ g_free(tmp);
}
else {
- lua_pushlstring (L, url->url->string, url->url->urllen);
+ lua_pushlstring(L, url->url->string, url->url->urllen);
}
}
else {
- lua_pushnil (L);
+ lua_pushnil(L);
}
return 1;
@@ -347,16 +345,16 @@ lua_url_tostring (lua_State *L)
* @return {string} url string
*/
static gint
-lua_url_get_raw (lua_State *L)
+lua_url_get_raw(lua_State *L)
{
LUA_TRACE_POINT;
- struct rspamd_lua_url *url = lua_check_url (L, 1);
+ struct rspamd_lua_url *url = lua_check_url(L, 1);
if (url != NULL) {
- lua_pushlstring (L, url->url->raw, url->url->rawlen);
+ lua_pushlstring(L, url->url->raw, url->url->rawlen);
}
else {
- lua_pushnil (L);
+ lua_pushnil(L);
}
return 1;
@@ -368,16 +366,16 @@ lua_url_get_raw (lua_State *L)
* @return {boolean} `true` if URL is phished
*/
static gint
-lua_url_is_phished (lua_State *L)
+lua_url_is_phished(lua_State *L)
{
LUA_TRACE_POINT;
- struct rspamd_lua_url *url = lua_check_url (L, 1);
+ struct rspamd_lua_url *url = lua_check_url(L, 1);
if (url != NULL) {
- lua_pushboolean (L, url->url->flags & RSPAMD_URL_FLAG_PHISHED);
+ lua_pushboolean(L, url->url->flags & RSPAMD_URL_FLAG_PHISHED);
}
else {
- lua_pushnil (L);
+ lua_pushnil(L);
}
return 1;
@@ -389,16 +387,16 @@ lua_url_is_phished (lua_State *L)
* @return {boolean} `true` if URL is redirected
*/
static gint
-lua_url_is_redirected (lua_State *L)
+lua_url_is_redirected(lua_State *L)
{
LUA_TRACE_POINT;
- struct rspamd_lua_url *url = lua_check_url (L, 1);
+ struct rspamd_lua_url *url = lua_check_url(L, 1);
if (url != NULL) {
- lua_pushboolean (L, url->url->flags & RSPAMD_URL_FLAG_REDIRECTED);
+ lua_pushboolean(L, url->url->flags & RSPAMD_URL_FLAG_REDIRECTED);
}
else {
- lua_pushnil (L);
+ lua_pushnil(L);
}
return 1;
@@ -410,16 +408,16 @@ lua_url_is_redirected (lua_State *L)
* @return {boolean} `true` if URL is obscured
*/
static gint
-lua_url_is_obscured (lua_State *L)
+lua_url_is_obscured(lua_State *L)
{
LUA_TRACE_POINT;
- struct rspamd_lua_url *url = lua_check_url (L, 1);
+ struct rspamd_lua_url *url = lua_check_url(L, 1);
if (url != NULL) {
- lua_pushboolean (L, url->url->flags & RSPAMD_URL_FLAG_OBSCURED);
+ lua_pushboolean(L, url->url->flags & RSPAMD_URL_FLAG_OBSCURED);
}
else {
- lua_pushnil (L);
+ lua_pushnil(L);
}
return 1;
@@ -432,16 +430,16 @@ lua_url_is_obscured (lua_State *L)
* @return {boolean} `true` if URL is displayed only
*/
static gint
-lua_url_is_html_displayed (lua_State *L)
+lua_url_is_html_displayed(lua_State *L)
{
LUA_TRACE_POINT;
- struct rspamd_lua_url *url = lua_check_url (L, 1);
+ struct rspamd_lua_url *url = lua_check_url(L, 1);
if (url != NULL) {
- lua_pushboolean (L, url->url->flags & RSPAMD_URL_FLAG_HTML_DISPLAYED);
+ lua_pushboolean(L, url->url->flags & RSPAMD_URL_FLAG_HTML_DISPLAYED);
}
else {
- lua_pushnil (L);
+ lua_pushnil(L);
}
return 1;
@@ -453,16 +451,16 @@ lua_url_is_html_displayed (lua_State *L)
* @return {boolean} `true` if URL is found in subject
*/
static gint
-lua_url_is_subject (lua_State *L)
+lua_url_is_subject(lua_State *L)
{
LUA_TRACE_POINT;
- struct rspamd_lua_url *url = lua_check_url (L, 1);
+ struct rspamd_lua_url *url = lua_check_url(L, 1);
if (url != NULL) {
- lua_pushboolean (L, url->url->flags & RSPAMD_URL_FLAG_SUBJECT);
+ lua_pushboolean(L, url->url->flags & RSPAMD_URL_FLAG_SUBJECT);
}
else {
- lua_pushnil (L);
+ lua_pushnil(L);
}
return 1;
@@ -474,18 +472,18 @@ lua_url_is_subject (lua_State *L)
* @return {url} phished URL
*/
static gint
-lua_url_get_phished (lua_State *L)
+lua_url_get_phished(lua_State *L)
{
LUA_TRACE_POINT;
- struct rspamd_lua_url *purl, *url = lua_check_url (L, 1);
+ struct rspamd_lua_url *purl, *url = lua_check_url(L, 1);
if (url) {
if (url->url->ext && url->url->ext->linked_url != NULL) {
/* XXX: in fact, this is the only possible combination of flags, so this check is redundant */
if (url->url->flags &
- (RSPAMD_URL_FLAG_PHISHED|RSPAMD_URL_FLAG_REDIRECTED)) {
- purl = lua_newuserdata (L, sizeof (struct rspamd_lua_url));
- rspamd_lua_setclass (L, "rspamd{url}", -1);
+ (RSPAMD_URL_FLAG_PHISHED | RSPAMD_URL_FLAG_REDIRECTED)) {
+ purl = lua_newuserdata(L, sizeof(struct rspamd_lua_url));
+ rspamd_lua_setclass(L, "rspamd{url}", -1);
purl->url = url->url->ext->linked_url;
return 1;
@@ -493,7 +491,7 @@ lua_url_get_phished (lua_State *L)
}
}
- lua_pushnil (L);
+ lua_pushnil(L);
return 1;
}
@@ -505,40 +503,40 @@ lua_url_get_phished (lua_State *L)
* @return {url} parsed redirected url (if needed)
*/
static gint
-lua_url_set_redirected (lua_State *L)
+lua_url_set_redirected(lua_State *L)
{
LUA_TRACE_POINT;
- struct rspamd_lua_url *url = lua_check_url (L, 1), *redir;
+ struct rspamd_lua_url *url = lua_check_url(L, 1), *redir;
rspamd_mempool_t *pool = NULL;
if (url == NULL) {
- return luaL_error (L, "url is required as the first argument");
+ return luaL_error(L, "url is required as the first argument");
}
- if (lua_type (L, 2) == LUA_TSTRING) {
+ if (lua_type(L, 2) == LUA_TSTRING) {
/* Parse url */
- if (lua_type (L, 3) != LUA_TUSERDATA) {
- return luaL_error (L, "mempool is required as the third argument");
+ if (lua_type(L, 3) != LUA_TUSERDATA) {
+ return luaL_error(L, "mempool is required as the third argument");
}
- pool = rspamd_lua_check_mempool (L, 3);
+ pool = rspamd_lua_check_mempool(L, 3);
if (pool == NULL) {
- return luaL_error (L, "mempool is required as the third argument");
+ return luaL_error(L, "mempool is required as the third argument");
}
gsize len;
- const gchar *urlstr = lua_tolstring (L, 2, &len);
+ const gchar *urlstr = lua_tolstring(L, 2, &len);
- rspamd_url_find_single (pool, urlstr, len, RSPAMD_URL_FIND_ALL,
- lua_url_single_inserter, L);
+ rspamd_url_find_single(pool, urlstr, len, RSPAMD_URL_FIND_ALL,
+ lua_url_single_inserter, L);
- if (lua_type (L, -1) != LUA_TUSERDATA) {
+ if (lua_type(L, -1) != LUA_TUSERDATA) {
/* URL is actually not found */
- lua_pushnil (L);
+ lua_pushnil(L);
}
else {
- redir = lua_check_url (L, -1);
+ redir = lua_check_url(L, -1);
url->url->flags |= RSPAMD_URL_FLAG_REDIRECTED;
@@ -549,10 +547,10 @@ lua_url_set_redirected (lua_State *L)
}
}
else {
- redir = lua_check_url (L, 2);
+ redir = lua_check_url(L, 2);
if (redir == NULL) {
- return luaL_error (L, "url is required as the second argument");
+ return luaL_error(L, "url is required as the second argument");
}
url->url->flags |= RSPAMD_URL_FLAG_REDIRECTED;
@@ -562,7 +560,7 @@ lua_url_set_redirected (lua_State *L)
url->url->ext->linked_url = redir->url;
/* Push back on stack */
- lua_pushvalue (L, 2);
+ lua_pushvalue(L, 2);
}
return 1;
@@ -574,16 +572,16 @@ lua_url_set_redirected (lua_State *L)
* @return {string} effective second level domain part (eSLD) of the url host
*/
static gint
-lua_url_get_tld (lua_State *L)
+lua_url_get_tld(lua_State *L)
{
LUA_TRACE_POINT;
- struct rspamd_lua_url *url = lua_check_url (L, 1);
+ struct rspamd_lua_url *url = lua_check_url(L, 1);
if (url != NULL && url->url->tldlen > 0) {
- lua_pushlstring (L, rspamd_url_tld_unsafe (url->url), url->url->tldlen);
+ lua_pushlstring(L, rspamd_url_tld_unsafe(url->url), url->url->tldlen);
}
else {
- lua_pushnil (L);
+ lua_pushnil(L);
}
return 1;
@@ -595,16 +593,16 @@ lua_url_get_tld (lua_State *L)
* @return {string} protocol as a string
*/
static gint
-lua_url_get_protocol (lua_State *L)
+lua_url_get_protocol(lua_State *L)
{
LUA_TRACE_POINT;
- struct rspamd_lua_url *url = lua_check_url (L, 1);
+ struct rspamd_lua_url *url = lua_check_url(L, 1);
if (url != NULL && url->url->protocol != PROTOCOL_UNKNOWN) {
- lua_pushstring (L, rspamd_url_protocol_name (url->url->protocol));
+ lua_pushstring(L, rspamd_url_protocol_name(url->url->protocol));
}
else {
- lua_pushnil (L);
+ lua_pushnil(L);
}
return 1;
@@ -616,40 +614,40 @@ lua_url_get_protocol (lua_State *L)
* @return {number} number of occurrences
*/
static gint
-lua_url_get_count (lua_State *L)
+lua_url_get_count(lua_State *L)
{
LUA_TRACE_POINT;
- struct rspamd_lua_url *url = lua_check_url (L, 1);
+ struct rspamd_lua_url *url = lua_check_url(L, 1);
if (url != NULL && url->url != NULL) {
- lua_pushinteger (L, url->url->count);
+ lua_pushinteger(L, url->url->count);
}
else {
- lua_pushnil (L);
+ lua_pushnil(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_url_get_visible(lua_State *L)
{
LUA_TRACE_POINT;
- struct rspamd_lua_url *url = lua_check_url (L, 1);
+ struct rspamd_lua_url *url = lua_check_url(L, 1);
if (url != NULL && url->url->ext && url->url->ext->visible_part) {
- lua_pushstring (L, url->url->ext->visible_part);
+ lua_pushstring(L, url->url->ext->visible_part);
}
else {
- lua_pushnil (L);
+ lua_pushnil(L);
}
-return 1;
+ return 1;
}
/***
@@ -665,68 +663,68 @@ return 1;
* @return {table} URL as a table
*/
static gint
-lua_url_to_table (lua_State *L)
+lua_url_to_table(lua_State *L)
{
LUA_TRACE_POINT;
- struct rspamd_lua_url *url = lua_check_url (L, 1);
+ struct rspamd_lua_url *url = lua_check_url(L, 1);
struct rspamd_url *u;
if (url != NULL) {
u = url->url;
- lua_createtable (L, 0, 12);
- lua_pushstring (L, "url");
- lua_pushlstring (L, u->string, u->urllen);
- lua_settable (L, -3);
+ lua_createtable(L, 0, 12);
+ lua_pushstring(L, "url");
+ lua_pushlstring(L, u->string, u->urllen);
+ lua_settable(L, -3);
if (u->hostlen > 0) {
- lua_pushstring (L, "host");
- lua_pushlstring (L, rspamd_url_host_unsafe (u), u->hostlen);
- lua_settable (L, -3);
+ lua_pushstring(L, "host");
+ lua_pushlstring(L, rspamd_url_host_unsafe(u), u->hostlen);
+ lua_settable(L, -3);
}
if (rspamd_url_get_port_if_special(u) != 0) {
- lua_pushstring (L, "port");
- lua_pushinteger (L, rspamd_url_get_port_if_special(u));
- lua_settable (L, -3);
+ lua_pushstring(L, "port");
+ lua_pushinteger(L, rspamd_url_get_port_if_special(u));
+ lua_settable(L, -3);
}
if (u->tldlen > 0) {
- lua_pushstring (L, "tld");
- lua_pushlstring (L, rspamd_url_tld_unsafe (u), u->tldlen);
- lua_settable (L, -3);
+ lua_pushstring(L, "tld");
+ lua_pushlstring(L, rspamd_url_tld_unsafe(u), u->tldlen);
+ lua_settable(L, -3);
}
if (u->userlen > 0) {
- lua_pushstring (L, "user");
- lua_pushlstring (L, rspamd_url_user (u), u->userlen);
- lua_settable (L, -3);
+ lua_pushstring(L, "user");
+ lua_pushlstring(L, rspamd_url_user(u), u->userlen);
+ lua_settable(L, -3);
}
if (u->datalen > 0) {
- lua_pushstring (L, "path");
- lua_pushlstring (L, rspamd_url_data_unsafe (u), u->datalen);
- lua_settable (L, -3);
+ lua_pushstring(L, "path");
+ lua_pushlstring(L, rspamd_url_data_unsafe(u), u->datalen);
+ lua_settable(L, -3);
}
if (u->querylen > 0) {
- lua_pushstring (L, "query");
- lua_pushlstring (L, rspamd_url_query_unsafe (u), u->querylen);
- lua_settable (L, -3);
+ lua_pushstring(L, "query");
+ lua_pushlstring(L, rspamd_url_query_unsafe(u), u->querylen);
+ lua_settable(L, -3);
}
if (u->fragmentlen > 0) {
- lua_pushstring (L, "fragment");
- lua_pushlstring (L, rspamd_url_fragment_unsafe (u), u->fragmentlen);
- lua_settable (L, -3);
+ lua_pushstring(L, "fragment");
+ lua_pushlstring(L, rspamd_url_fragment_unsafe(u), u->fragmentlen);
+ lua_settable(L, -3);
}
- lua_pushstring (L, "protocol");
- lua_pushstring (L, rspamd_url_protocol_name (u->protocol));
- lua_settable (L, -3);
+ lua_pushstring(L, "protocol");
+ lua_pushstring(L, rspamd_url_protocol_name(u->protocol));
+ lua_settable(L, -3);
}
else {
- lua_pushnil (L);
+ lua_pushnil(L);
}
return 1;
@@ -734,13 +732,15 @@ lua_url_to_table (lua_State *L)
static rspamd_mempool_t *static_lua_url_pool;
-RSPAMD_CONSTRUCTOR(rspamd_urls_static_pool_ctor) {
- static_lua_url_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (),
- "static_lua_url", 0);
+RSPAMD_CONSTRUCTOR(rspamd_urls_static_pool_ctor)
+{
+ static_lua_url_pool = rspamd_mempool_new(rspamd_mempool_suggest_size(),
+ "static_lua_url", 0);
}
-RSPAMD_DESTRUCTOR(rspamd_urls_static_pool_dtor) {
- rspamd_mempool_delete (static_lua_url_pool);
+RSPAMD_DESTRUCTOR(rspamd_urls_static_pool_dtor)
+{
+ rspamd_mempool_delete(static_lua_url_pool);
}
/***
@@ -750,50 +750,50 @@ RSPAMD_DESTRUCTOR(rspamd_urls_static_pool_dtor) {
* @return {url} new url object that exists as long as the corresponding mempool exists
*/
static gint
-lua_url_create (lua_State *L)
+lua_url_create(lua_State *L)
{
LUA_TRACE_POINT;
rspamd_mempool_t *pool;
struct rspamd_lua_text *t;
struct rspamd_lua_url *u;
- if (lua_type (L, 1) == LUA_TUSERDATA) {
- pool = rspamd_lua_check_mempool (L, 1);
- t = lua_check_text_or_string (L, 2);
+ if (lua_type(L, 1) == LUA_TUSERDATA) {
+ pool = rspamd_lua_check_mempool(L, 1);
+ t = lua_check_text_or_string(L, 2);
}
else {
pool = static_lua_url_pool;
- t = lua_check_text_or_string (L, 2);
+ t = lua_check_text_or_string(L, 2);
}
if (pool == NULL || t == NULL) {
- return luaL_error (L, "invalid arguments");
+ return luaL_error(L, "invalid arguments");
}
else {
- rspamd_url_find_single (pool, t->start, t->len, RSPAMD_URL_FIND_ALL,
- lua_url_single_inserter, L);
+ rspamd_url_find_single(pool, t->start, t->len, RSPAMD_URL_FIND_ALL,
+ lua_url_single_inserter, L);
- if (lua_type (L, -1) != LUA_TUSERDATA) {
+ if (lua_type(L, -1) != LUA_TUSERDATA) {
/* URL is actually not found */
- lua_pushnil (L);
+ lua_pushnil(L);
return 1;
}
- u = (struct rspamd_lua_url *)lua_touserdata (L, -1);
+ u = (struct rspamd_lua_url *) lua_touserdata(L, -1);
- if (lua_type (L, 3) == LUA_TTABLE) {
+ if (lua_type(L, 3) == LUA_TTABLE) {
/* Add flags */
- for (lua_pushnil (L); lua_next (L, 3); lua_pop (L, 1)) {
+ for (lua_pushnil(L); lua_next(L, 3); lua_pop(L, 1)) {
int nmask = 0;
- const gchar *fname = lua_tostring (L, -1);
+ const gchar *fname = lua_tostring(L, -1);
- if (rspamd_url_flag_from_string (fname, &nmask)) {
+ if (rspamd_url_flag_from_string(fname, &nmask)) {
u->url->flags |= nmask;
}
else {
- lua_pop (L, 1);
- return luaL_error (L, "invalid flag: %s", fname);
+ lua_pop(L, 1);
+ return luaL_error(L, "invalid flag: %s", fname);
}
}
}
@@ -809,58 +809,57 @@ lua_url_create (lua_State *L)
* @return nothing
*/
static gint
-lua_url_init (lua_State *L)
+lua_url_init(lua_State *L)
{
const gchar *tld_path;
- tld_path = luaL_checkstring (L, 1);
+ tld_path = luaL_checkstring(L, 1);
- rspamd_url_init (tld_path);
+ rspamd_url_init(tld_path);
return 0;
}
static gboolean
-lua_url_table_inserter (struct rspamd_url *url, gsize start_offset,
- gsize end_offset, gpointer ud)
+lua_url_table_inserter(struct rspamd_url *url, gsize start_offset,
+ gsize end_offset, gpointer ud)
{
lua_State *L = ud;
struct rspamd_lua_url *lua_url;
gint n;
- n = rspamd_lua_table_size (L, -1);
- lua_url = lua_newuserdata (L, sizeof (struct rspamd_lua_url));
- rspamd_lua_setclass (L, "rspamd{url}", -1);
+ n = rspamd_lua_table_size(L, -1);
+ lua_url = lua_newuserdata(L, sizeof(struct rspamd_lua_url));
+ rspamd_lua_setclass(L, "rspamd{url}", -1);
lua_url->url = url;
- lua_rawseti (L, -2, n + 1);
+ lua_rawseti(L, -2, n + 1);
return TRUE;
}
static gint
-lua_url_all (lua_State *L)
+lua_url_all(lua_State *L)
{
LUA_TRACE_POINT;
- rspamd_mempool_t *pool = rspamd_lua_check_mempool (L, 1);
+ rspamd_mempool_t *pool = rspamd_lua_check_mempool(L, 1);
const gchar *text;
size_t length;
if (pool == NULL) {
- lua_pushnil (L);
+ lua_pushnil(L);
}
else {
- text = luaL_checklstring (L, 2, &length);
+ text = luaL_checklstring(L, 2, &length);
if (text != NULL) {
- lua_newtable (L);
- rspamd_url_find_multiple (pool, text, length,
- RSPAMD_URL_FIND_ALL, NULL,
- lua_url_table_inserter, L);
-
+ lua_newtable(L);
+ rspamd_url_find_multiple(pool, text, length,
+ RSPAMD_URL_FIND_ALL, NULL,
+ lua_url_table_inserter, L);
}
else {
- lua_pushnil (L);
+ lua_pushnil(L);
}
}
@@ -893,32 +892,33 @@ lua_url_all (lua_State *L)
* - `image`: URL is from src attribute of img HTML tag
* @return {table} URL flags
*/
-#define PUSH_FLAG(fl) do { \
- if (flags & (fl)) { \
- lua_pushstring (L, rspamd_url_flag_to_string (fl)); \
- lua_pushboolean (L, true); \
- lua_settable (L, -3); \
- } \
-} while (0)
+#define PUSH_FLAG(fl) \
+ do { \
+ if (flags & (fl)) { \
+ lua_pushstring(L, rspamd_url_flag_to_string(fl)); \
+ lua_pushboolean(L, true); \
+ lua_settable(L, -3); \
+ } \
+ } while (0)
static gint
-lua_url_get_flags (lua_State *L)
+lua_url_get_flags(lua_State *L)
{
LUA_TRACE_POINT;
- struct rspamd_lua_url *url = lua_check_url (L, 1);
+ struct rspamd_lua_url *url = lua_check_url(L, 1);
enum rspamd_url_flags flags;
if (url != NULL) {
flags = url->url->flags;
- lua_createtable (L, 0, 4);
+ lua_createtable(L, 0, 4);
- for (gint i = 0; i < RSPAMD_URL_MAX_FLAG_SHIFT; i ++) {
- PUSH_FLAG (1u << i);
+ for (gint i = 0; i < RSPAMD_URL_MAX_FLAG_SHIFT; i++) {
+ PUSH_FLAG(1u << i);
}
}
else {
- return luaL_error (L, "invalid arguments");
+ return luaL_error(L, "invalid arguments");
}
return 1;
@@ -927,26 +927,25 @@ lua_url_get_flags (lua_State *L)
#undef PUSH_FLAG
static gint
-lua_url_get_flags_num (lua_State *L)
+lua_url_get_flags_num(lua_State *L)
{
LUA_TRACE_POINT;
- struct rspamd_lua_url *url = lua_check_url (L, 1);
+ struct rspamd_lua_url *url = lua_check_url(L, 1);
if (url) {
- lua_pushinteger (L, url->url->flags);
+ lua_pushinteger(L, url->url->flags);
}
else {
- return luaL_error (L, "invalid arguments");
+ return luaL_error(L, "invalid arguments");
}
return 1;
}
-void
-lua_tree_url_callback (gpointer key, gpointer value, gpointer ud)
+void lua_tree_url_callback(gpointer key, gpointer value, gpointer ud)
{
struct rspamd_lua_url *lua_url;
- struct rspamd_url *url = (struct rspamd_url *)value;
+ struct rspamd_url *url = (struct rspamd_url *) value;
struct lua_tree_cb_data *cb = ud;
if ((url->protocol & cb->protocols_mask) == url->protocol) {
@@ -974,57 +973,57 @@ lua_tree_url_callback (gpointer key, gpointer value, gpointer ud)
}
if (cb->skip_prob > 0) {
- gdouble coin = rspamd_random_double_fast_seed (&cb->random_seed);
+ gdouble coin = rspamd_random_double_fast_seed(&cb->random_seed);
if (coin < cb->skip_prob) {
return;
}
}
- lua_url = lua_newuserdata (cb->L, sizeof (struct rspamd_lua_url));
- lua_pushvalue (cb->L, cb->metatable_pos);
- lua_setmetatable (cb->L, -2);
+ lua_url = lua_newuserdata(cb->L, sizeof(struct rspamd_lua_url));
+ lua_pushvalue(cb->L, cb->metatable_pos);
+ lua_setmetatable(cb->L, -2);
lua_url->url = url;
- lua_rawseti (cb->L, -2, cb->i++);
+ lua_rawseti(cb->L, -2, cb->i++);
}
}
gboolean
-lua_url_cbdata_fill (lua_State *L,
- gint pos,
- struct lua_tree_cb_data *cbd,
- guint default_protocols,
- guint default_flags,
- gsize max_urls)
+lua_url_cbdata_fill(lua_State *L,
+ gint pos,
+ struct lua_tree_cb_data *cbd,
+ guint default_protocols,
+ guint default_flags,
+ gsize max_urls)
{
gint protocols_mask = 0;
- gint pos_arg_type = lua_type (L, pos);
+ gint pos_arg_type = lua_type(L, pos);
guint flags_mask = default_flags;
gboolean seen_flags = FALSE, seen_protocols = FALSE;
- memset (cbd, 0, sizeof (*cbd));
+ memset(cbd, 0, sizeof(*cbd));
cbd->flags_mode = url_flags_mode_include_any;
if (pos_arg_type == LUA_TBOOLEAN) {
protocols_mask = default_protocols;
- if (lua_toboolean (L, 2)) {
+ if (lua_toboolean(L, 2)) {
protocols_mask |= PROTOCOL_MAILTO;
}
}
else if (pos_arg_type == LUA_TTABLE) {
- if (rspamd_lua_geti (L, 1, pos) == LUA_TNIL) {
+ if (rspamd_lua_geti(L, 1, pos) == LUA_TNIL) {
/* New method: indexed table */
- lua_getfield (L, pos, "flags");
- if (lua_istable (L, -1)) {
- gint top = lua_gettop (L);
+ lua_getfield(L, pos, "flags");
+ if (lua_istable(L, -1)) {
+ gint top = lua_gettop(L);
- lua_getfield (L, pos, "flags_mode");
- if (lua_isstring (L, -1)) {
- const gchar *mode_str = lua_tostring (L, -1);
+ lua_getfield(L, pos, "flags_mode");
+ if (lua_isstring(L, -1)) {
+ const gchar *mode_str = lua_tostring(L, -1);
- if (strcmp (mode_str, "explicit") == 0) {
+ if (strcmp(mode_str, "explicit") == 0) {
cbd->flags_mode = url_flags_mode_include_explicit;
/*
* Ignore default flags in this mode and include
@@ -1033,26 +1032,26 @@ lua_url_cbdata_fill (lua_State *L,
flags_mask = 0;
}
}
- lua_pop (L, 1);
+ lua_pop(L, 1);
- for (lua_pushnil (L); lua_next (L, top); lua_pop (L, 1)) {
+ for (lua_pushnil(L); lua_next(L, top); lua_pop(L, 1)) {
int nmask = 0;
- if (lua_type (L, -1) == LUA_TSTRING) {
- const gchar *fname = lua_tostring (L, -1);
+ if (lua_type(L, -1) == LUA_TSTRING) {
+ const gchar *fname = lua_tostring(L, -1);
- if (rspamd_url_flag_from_string (fname, &nmask)) {
+ if (rspamd_url_flag_from_string(fname, &nmask)) {
flags_mask |= nmask;
}
else {
- msg_info ("bad url flag: %s", fname);
+ msg_info("bad url flag: %s", fname);
return FALSE;
}
}
else {
- flags_mask |= lua_tointeger (L, -1);
+ flags_mask |= lua_tointeger(L, -1);
}
}
@@ -1061,23 +1060,23 @@ lua_url_cbdata_fill (lua_State *L,
else {
flags_mask |= default_flags;
}
- lua_pop (L, 1);
+ lua_pop(L, 1);
- lua_getfield (L, pos, "protocols");
- if (lua_istable (L, -1)) {
- gint top = lua_gettop (L);
+ lua_getfield(L, pos, "protocols");
+ if (lua_istable(L, -1)) {
+ gint top = lua_gettop(L);
- for (lua_pushnil (L); lua_next (L, top); lua_pop (L, 1)) {
+ for (lua_pushnil(L); lua_next(L, top); lua_pop(L, 1)) {
int nmask;
- const gchar *pname = lua_tostring (L, -1);
+ const gchar *pname = lua_tostring(L, -1);
- nmask = rspamd_url_protocol_from_string (pname);
+ nmask = rspamd_url_protocol_from_string(pname);
if (nmask != PROTOCOL_UNKNOWN) {
protocols_mask |= nmask;
}
else {
- msg_info ("bad url protocol: %s", pname);
+ msg_info("bad url protocol: %s", pname);
return FALSE;
}
}
@@ -1086,22 +1085,22 @@ lua_url_cbdata_fill (lua_State *L,
else {
protocols_mask = default_protocols;
}
- lua_pop (L, 1);
+ lua_pop(L, 1);
if (!seen_protocols) {
- lua_getfield (L, pos, "emails");
- if (lua_isboolean (L, -1)) {
- if (lua_toboolean (L, -1)) {
+ lua_getfield(L, pos, "emails");
+ if (lua_isboolean(L, -1)) {
+ if (lua_toboolean(L, -1)) {
protocols_mask |= PROTOCOL_MAILTO;
}
}
- lua_pop (L, 1);
+ lua_pop(L, 1);
}
if (!seen_flags) {
- lua_getfield (L, pos, "images");
- if (lua_isboolean (L, -1)) {
- if (lua_toboolean (L, -1)) {
+ lua_getfield(L, pos, "images");
+ if (lua_isboolean(L, -1)) {
+ if (lua_toboolean(L, -1)) {
flags_mask |= RSPAMD_URL_FLAG_IMAGE;
}
else {
@@ -1111,13 +1110,13 @@ lua_url_cbdata_fill (lua_State *L,
else {
flags_mask &= ~RSPAMD_URL_FLAG_IMAGE;
}
- lua_pop (L, 1);
+ lua_pop(L, 1);
}
if (!seen_flags) {
- lua_getfield (L, pos, "content");
- if (lua_isboolean (L, -1)) {
- if (lua_toboolean (L, -1)) {
+ lua_getfield(L, pos, "content");
+ if (lua_isboolean(L, -1)) {
+ if (lua_toboolean(L, -1)) {
flags_mask |= RSPAMD_URL_FLAG_CONTENT;
}
else {
@@ -1127,68 +1126,68 @@ lua_url_cbdata_fill (lua_State *L,
else {
flags_mask &= ~RSPAMD_URL_FLAG_CONTENT;
}
- lua_pop (L, 1);
+ lua_pop(L, 1);
}
- lua_getfield (L, pos, "max_urls");
- if (lua_isnumber (L, -1)) {
- max_urls = lua_tonumber (L, -1);
+ lua_getfield(L, pos, "max_urls");
+ if (lua_isnumber(L, -1)) {
+ max_urls = lua_tonumber(L, -1);
}
- lua_pop (L, 1);
+ lua_pop(L, 1);
- lua_getfield (L, pos, "sort");
- if (lua_isboolean (L, -1)) {
+ lua_getfield(L, pos, "sort");
+ if (lua_isboolean(L, -1)) {
cbd->sort = TRUE;
}
- lua_pop (L, 1);
+ lua_pop(L, 1);
}
else {
/* Plain table of the protocols */
- for (lua_pushnil (L); lua_next (L, pos); lua_pop (L, 1)) {
+ for (lua_pushnil(L); lua_next(L, pos); lua_pop(L, 1)) {
int nmask;
- const gchar *pname = lua_tostring (L, -1);
+ const gchar *pname = lua_tostring(L, -1);
- nmask = rspamd_url_protocol_from_string (pname);
+ nmask = rspamd_url_protocol_from_string(pname);
if (nmask != PROTOCOL_UNKNOWN) {
protocols_mask |= nmask;
}
else {
- msg_info ("bad url protocol: %s", pname);
+ msg_info("bad url protocol: %s", pname);
return FALSE;
}
}
}
- lua_pop (L, 1); /* After rspamd_lua_geti */
+ lua_pop(L, 1); /* After rspamd_lua_geti */
}
else if (pos_arg_type == LUA_TSTRING) {
- const gchar *plist = lua_tostring (L, pos);
+ const gchar *plist = lua_tostring(L, pos);
gchar **strvec;
- gchar * const *cvec;
+ gchar *const *cvec;
- strvec = g_strsplit_set (plist, ",;", -1);
+ strvec = g_strsplit_set(plist, ",;", -1);
cvec = strvec;
while (*cvec) {
int nmask;
- nmask = rspamd_url_protocol_from_string (*cvec);
+ nmask = rspamd_url_protocol_from_string(*cvec);
if (nmask != PROTOCOL_UNKNOWN) {
protocols_mask |= nmask;
}
else {
- msg_info ("bad url protocol: %s", *cvec);
- g_strfreev (strvec);
+ msg_info("bad url protocol: %s", *cvec);
+ g_strfreev(strvec);
return FALSE;
}
- cvec ++;
+ cvec++;
}
- g_strfreev (strvec);
+ g_strfreev(strvec);
}
else if (pos_arg_type == LUA_TNONE || pos_arg_type == LUA_TNIL) {
protocols_mask = default_protocols;
@@ -1198,8 +1197,8 @@ lua_url_cbdata_fill (lua_State *L,
return FALSE;
}
- if (lua_type (L, pos + 1) == LUA_TBOOLEAN) {
- if (lua_toboolean (L, pos + 1)) {
+ if (lua_type(L, pos + 1) == LUA_TBOOLEAN) {
+ if (lua_toboolean(L, pos + 1)) {
flags_mask |= RSPAMD_URL_FLAG_IMAGE;
}
else {
@@ -1214,48 +1213,48 @@ lua_url_cbdata_fill (lua_State *L,
cbd->flags_mask = flags_mask;
/* This needs to be removed from the stack */
- rspamd_lua_class_metatable (L, "rspamd{url}");
- cbd->metatable_pos = lua_gettop (L);
- (void)lua_checkstack (L, cbd->metatable_pos + 4);
+ rspamd_lua_class_metatable(L, "rspamd{url}");
+ cbd->metatable_pos = lua_gettop(L);
+ (void) lua_checkstack(L, cbd->metatable_pos + 4);
return TRUE;
}
gboolean
-lua_url_cbdata_fill_exclude_include (lua_State *L,
- gint pos,
- struct lua_tree_cb_data *cbd,
- guint default_protocols,
- gsize max_urls)
+lua_url_cbdata_fill_exclude_include(lua_State *L,
+ gint pos,
+ struct lua_tree_cb_data *cbd,
+ guint default_protocols,
+ gsize max_urls)
{
guint protocols_mask = default_protocols;
guint include_flags_mask, exclude_flags_mask;
- gint pos_arg_type = lua_type (L, pos);
+ gint pos_arg_type = lua_type(L, pos);
- memset (cbd, 0, sizeof (*cbd));
+ memset(cbd, 0, sizeof(*cbd));
cbd->flags_mode = url_flags_mode_exclude_include;
/* Include flags */
if (pos_arg_type == LUA_TTABLE) {
include_flags_mask = 0; /* Reset to no flags */
- for (lua_pushnil(L); lua_next(L, pos); lua_pop (L, 1)) {
+ for (lua_pushnil(L); lua_next(L, pos); lua_pop(L, 1)) {
int nmask = 0;
- if (lua_type (L, -1) == LUA_TSTRING) {
- const gchar *fname = lua_tostring (L, -1);
+ if (lua_type(L, -1) == LUA_TSTRING) {
+ const gchar *fname = lua_tostring(L, -1);
if (rspamd_url_flag_from_string(fname, &nmask)) {
include_flags_mask |= nmask;
}
else {
- msg_info ("bad url include flag: %s", fname);
+ msg_info("bad url include flag: %s", fname);
return FALSE;
}
}
else {
- include_flags_mask |= lua_tointeger (L, -1);
+ include_flags_mask |= lua_tointeger(L, -1);
}
}
}
@@ -1264,31 +1263,31 @@ lua_url_cbdata_fill_exclude_include (lua_State *L,
include_flags_mask = ~0U;
}
else {
- msg_info ("bad arguments: wrong include mask");
+ msg_info("bad arguments: wrong include mask");
return FALSE;
}
/* Exclude flags */
- pos_arg_type = lua_type (L, pos + 1);
+ pos_arg_type = lua_type(L, pos + 1);
if (pos_arg_type == LUA_TTABLE) {
exclude_flags_mask = 0; /* Reset to no flags */
- for (lua_pushnil(L); lua_next(L, pos + 1); lua_pop (L, 1)) {
+ for (lua_pushnil(L); lua_next(L, pos + 1); lua_pop(L, 1)) {
int nmask = 0;
- if (lua_type (L, -1) == LUA_TSTRING) {
- const gchar *fname = lua_tostring (L, -1);
+ if (lua_type(L, -1) == LUA_TSTRING) {
+ const gchar *fname = lua_tostring(L, -1);
if (rspamd_url_flag_from_string(fname, &nmask)) {
exclude_flags_mask |= nmask;
}
else {
- msg_info ("bad url exclude flag: %s", fname);
+ msg_info("bad url exclude flag: %s", fname);
return FALSE;
}
}
else {
- exclude_flags_mask |= lua_tointeger (L, -1);
+ exclude_flags_mask |= lua_tointeger(L, -1);
}
}
}
@@ -1297,24 +1296,24 @@ lua_url_cbdata_fill_exclude_include (lua_State *L,
exclude_flags_mask = 0U;
}
else {
- msg_info ("bad arguments: wrong exclude mask");
+ msg_info("bad arguments: wrong exclude mask");
return FALSE;
}
- if (lua_type (L, pos + 2) == LUA_TTABLE) {
+ if (lua_type(L, pos + 2) == LUA_TTABLE) {
protocols_mask = 0U; /* Reset all protocols */
- for (lua_pushnil (L); lua_next (L, pos + 2); lua_pop (L, 1)) {
+ for (lua_pushnil(L); lua_next(L, pos + 2); lua_pop(L, 1)) {
int nmask;
- const gchar *pname = lua_tostring (L, -1);
+ const gchar *pname = lua_tostring(L, -1);
- nmask = rspamd_url_protocol_from_string (pname);
+ nmask = rspamd_url_protocol_from_string(pname);
if (nmask != PROTOCOL_UNKNOWN) {
protocols_mask |= nmask;
}
else {
- msg_info ("bad url protocol: %s", pname);
+ msg_info("bad url protocol: %s", pname);
return FALSE;
}
}
@@ -1331,30 +1330,28 @@ lua_url_cbdata_fill_exclude_include (lua_State *L,
cbd->flags_exclude_mask = exclude_flags_mask;
/* This needs to be removed from the stack */
- rspamd_lua_class_metatable (L, "rspamd{url}");
- cbd->metatable_pos = lua_gettop (L);
- (void)lua_checkstack (L, cbd->metatable_pos + 4);
+ rspamd_lua_class_metatable(L, "rspamd{url}");
+ cbd->metatable_pos = lua_gettop(L);
+ (void) lua_checkstack(L, cbd->metatable_pos + 4);
return TRUE;
}
-void
-lua_url_cbdata_dtor (struct lua_tree_cb_data *cbd)
+void lua_url_cbdata_dtor(struct lua_tree_cb_data *cbd)
{
if (cbd->metatable_pos != -1) {
- lua_remove (cbd->L, cbd->metatable_pos);
+ lua_remove(cbd->L, cbd->metatable_pos);
}
}
-gsize
-lua_url_adjust_skip_prob (float timestamp,
- guchar digest[16],
- struct lua_tree_cb_data *cb,
- gsize sz)
+gsize lua_url_adjust_skip_prob(float timestamp,
+ guchar digest[16],
+ struct lua_tree_cb_data *cb,
+ gsize sz)
{
if (cb->max_urls > 0 && sz > cb->max_urls) {
- cb->skip_prob = 1.0 - ((gdouble)cb->max_urls) / (gdouble)sz;
+ cb->skip_prob = 1.0 - ((gdouble) cb->max_urls) / (gdouble) sz;
/*
* Use task dependent probabilistic seed to ensure that
* consequent task:get_urls return the same list of urls
@@ -1362,7 +1359,7 @@ lua_url_adjust_skip_prob (float timestamp,
* based just on digest.
*/
memcpy(&cb->random_seed, digest, 4);
- memcpy(((unsigned char *)&cb->random_seed) + 4, &timestamp, 4);
+ memcpy(((unsigned char *) &cb->random_seed) + 4, &timestamp, 4);
sz = cb->max_urls;
}
@@ -1370,64 +1367,63 @@ lua_url_adjust_skip_prob (float timestamp,
}
static gint
-lua_url_eq (lua_State *L)
+lua_url_eq(lua_State *L)
{
LUA_TRACE_POINT;
- struct rspamd_lua_url *u1 = lua_check_url (L, 1),
- *u2 = lua_check_url (L, 2);
+ struct rspamd_lua_url *u1 = lua_check_url(L, 1),
+ *u2 = lua_check_url(L, 2);
if (u1 && u2) {
- lua_pushboolean (L, (rspamd_url_cmp (u1->url, u2->url) == 0));
+ lua_pushboolean(L, (rspamd_url_cmp(u1->url, u2->url) == 0));
}
else {
- lua_pushboolean (L, false);
+ lua_pushboolean(L, false);
}
return 1;
}
static gint
-lua_url_lt (lua_State *L)
+lua_url_lt(lua_State *L)
{
LUA_TRACE_POINT;
- struct rspamd_lua_url *u1 = lua_check_url (L, 1),
- *u2 = lua_check_url (L, 2);
+ struct rspamd_lua_url *u1 = lua_check_url(L, 1),
+ *u2 = lua_check_url(L, 2);
if (u1 && u2) {
- lua_pushinteger (L, rspamd_url_cmp (u1->url, u2->url));
+ lua_pushinteger(L, rspamd_url_cmp(u1->url, u2->url));
}
else {
- return luaL_error (L, "invalid arguments");
+ return luaL_error(L, "invalid arguments");
}
return 1;
}
static gint
-lua_load_url (lua_State * L)
+lua_load_url(lua_State *L)
{
- lua_newtable (L);
- luaL_register (L, NULL, urllib_f);
+ lua_newtable(L);
+ luaL_register(L, NULL, urllib_f);
/* Push flags */
- lua_createtable (L, 0, RSPAMD_URL_MAX_FLAG_SHIFT);
- for (int i = 0; i < RSPAMD_URL_MAX_FLAG_SHIFT; i ++) {
+ lua_createtable(L, 0, RSPAMD_URL_MAX_FLAG_SHIFT);
+ for (int i = 0; i < RSPAMD_URL_MAX_FLAG_SHIFT; i++) {
guint flag = 1u << i;
- lua_pushinteger (L, flag);
- lua_setfield (L, -2, rspamd_url_flag_to_string (flag));
+ lua_pushinteger(L, flag);
+ lua_setfield(L, -2, rspamd_url_flag_to_string(flag));
}
- lua_setfield (L, -2, "flags");
+ lua_setfield(L, -2, "flags");
return 1;
}
-void
-luaopen_url (lua_State * L)
+void luaopen_url(lua_State *L)
{
- rspamd_lua_new_class (L, "rspamd{url}", urllib_m);
- lua_pop (L, 1);
+ rspamd_lua_new_class(L, "rspamd{url}", urllib_m);
+ lua_pop(L, 1);
- rspamd_lua_add_preload (L, "rspamd_url", lua_load_url);
+ rspamd_lua_add_preload(L, "rspamd_url", lua_load_url);
}