aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2014-07-23 12:53:08 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2014-07-23 12:53:08 +0100
commitfe79d8c5a39f2b717f78cc3f3ef21b3cfc46500b (patch)
treec84e6a5d4c5cd78a7a2cc3c7adbc7af5d0541682 /src/lua
parente0483657ff6cf1adc828ccce457814d61fe90a0d (diff)
downloadrspamd-fe79d8c5a39f2b717f78cc3f3ef21b3cfc46500b.tar.gz
rspamd-fe79d8c5a39f2b717f78cc3f3ef21b3cfc46500b.zip
Revert "Unify code style."
This reverts commit e0483657ff6cf1adc828ccce457814d61fe90a0d.
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_buffer.c122
-rw-r--r--src/lua/lua_cdb.c34
-rw-r--r--src/lua/lua_cfg_file.c119
-rw-r--r--src/lua/lua_classifier.c117
-rw-r--r--src/lua/lua_common.c284
-rw-r--r--src/lua/lua_common.h96
-rw-r--r--src/lua/lua_config.c397
-rw-r--r--src/lua/lua_dns.c124
-rw-r--r--src/lua/lua_http.c272
-rw-r--r--src/lua/lua_ip.c39
-rw-r--r--src/lua/lua_mempool.c53
-rw-r--r--src/lua/lua_message.c80
-rw-r--r--src/lua/lua_redis.c107
-rw-r--r--src/lua/lua_regexp.c58
-rw-r--r--src/lua/lua_rsa.c151
-rw-r--r--src/lua/lua_session.c79
-rw-r--r--src/lua/lua_task.c619
-rw-r--r--src/lua/lua_upstream.c137
-rw-r--r--src/lua/lua_xmlrpc.c171
19 files changed, 1268 insertions, 1791 deletions
diff --git a/src/lua/lua_buffer.c b/src/lua/lua_buffer.c
index d119f8e27..37c4fce61 100644
--- a/src/lua/lua_buffer.c
+++ b/src/lua/lua_buffer.c
@@ -21,11 +21,11 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "buffer.h"
#include "lua_common.h"
+#include "buffer.h"
/* Public prototypes */
-struct rspamd_io_dispatcher_s * lua_check_io_dispatcher (lua_State * L);
+struct rspamd_io_dispatcher_s *lua_check_io_dispatcher (lua_State * L);
gint luaopen_io_dispatcher (lua_State * L);
/* Lua bindings */
@@ -36,7 +36,7 @@ LUA_FUNCTION_DEF (io_dispatcher, pause);
LUA_FUNCTION_DEF (io_dispatcher, restore);
LUA_FUNCTION_DEF (io_dispatcher, destroy);
-static const struct luaL_reg io_dispatcherlib_m[] = {
+static const struct luaL_reg io_dispatcherlib_m[] = {
LUA_INTERFACE_DEF (io_dispatcher, set_policy),
LUA_INTERFACE_DEF (io_dispatcher, write),
LUA_INTERFACE_DEF (io_dispatcher, pause),
@@ -46,7 +46,7 @@ static const struct luaL_reg io_dispatcherlib_m[] = {
{NULL, NULL}
};
-static const struct luaL_reg io_dispatcherlib_f[] = {
+static const struct luaL_reg io_dispatcherlib_f[] = {
LUA_INTERFACE_DEF (io_dispatcher, create),
{NULL, NULL}
};
@@ -60,10 +60,10 @@ struct lua_dispatcher_cbdata {
gint cbref_err;
};
-struct rspamd_io_dispatcher_s *
+struct rspamd_io_dispatcher_s *
lua_check_io_dispatcher (lua_State * L)
{
- void *ud = luaL_checkudata (L, 1, "rspamd{io_dispatcher}");
+ void *ud = luaL_checkudata (L, 1, "rspamd{io_dispatcher}");
luaL_argcheck (L, ud != NULL, 1, "'io_dispatcher' expected");
return ud ? *((struct rspamd_io_dispatcher_s **)ud) : NULL;
}
@@ -71,31 +71,29 @@ lua_check_io_dispatcher (lua_State * L)
struct event_base *
lua_check_event_base (lua_State *L)
{
- void *ud = luaL_checkudata (L, 1, "rspamd{ev_base}");
+ void *ud = luaL_checkudata (L, 1, "rspamd{ev_base}");
luaL_argcheck (L, ud != NULL, 1, "'ev_base' expected");
return ud ? *((struct event_base **)ud) : NULL;
}
/* Dispatcher callbacks */
-static gboolean
+static gboolean
lua_io_read_cb (f_str_t * in, void *arg)
{
- struct lua_dispatcher_cbdata *cbdata = arg;
- gboolean res;
- rspamd_io_dispatcher_t **pdispatcher;
+ struct lua_dispatcher_cbdata *cbdata = arg;
+ gboolean res;
+ rspamd_io_dispatcher_t **pdispatcher;
/* callback (dispatcher, data) */
lua_rawgeti (cbdata->L, LUA_REGISTRYINDEX, cbdata->cbref_read);
- pdispatcher =
- lua_newuserdata (cbdata->L, sizeof (struct rspamd_io_dispatcher_s *));
+ pdispatcher = lua_newuserdata (cbdata->L, sizeof (struct rspamd_io_dispatcher_s *));
lua_setclass (cbdata->L, "rspamd{io_dispatcher}", -1);
*pdispatcher = cbdata->d;
lua_pushlstring (cbdata->L, in->begin, in->len);
if (lua_pcall (cbdata->L, 2, 1, 0) != 0) {
- msg_info ("call to session finalizer failed: %s",
- lua_tostring (cbdata->L, -1));
+ msg_info ("call to session finalizer failed: %s", lua_tostring (cbdata->L, -1));
}
res = lua_toboolean (cbdata->L, -1);
@@ -104,26 +102,23 @@ lua_io_read_cb (f_str_t * in, void *arg)
return res;
}
-static gboolean
+static gboolean
lua_io_write_cb (void *arg)
{
- struct lua_dispatcher_cbdata *cbdata = arg;
- gboolean res = FALSE;
- rspamd_io_dispatcher_t **pdispatcher;
+ struct lua_dispatcher_cbdata *cbdata = arg;
+ gboolean res = FALSE;
+ rspamd_io_dispatcher_t **pdispatcher;
if (cbdata->cbref_write) {
lua_rawgeti (cbdata->L, LUA_REGISTRYINDEX, cbdata->cbref_read);
/* callback (dispatcher) */
- pdispatcher =
- lua_newuserdata (cbdata->L,
- sizeof (struct rspamd_io_dispatcher_s *));
+ pdispatcher = lua_newuserdata (cbdata->L, sizeof (struct rspamd_io_dispatcher_s *));
lua_setclass (cbdata->L, "rspamd{io_dispatcher}", -1);
*pdispatcher = cbdata->d;
if (lua_pcall (cbdata->L, 1, 1, 0) != 0) {
- msg_info ("call to session finalizer failed: %s",
- lua_tostring (cbdata->L, -1));
+ msg_info ("call to session finalizer failed: %s", lua_tostring (cbdata->L, -1));
}
res = lua_toboolean (cbdata->L, -1);
@@ -136,20 +131,18 @@ lua_io_write_cb (void *arg)
static void
lua_io_err_cb (GError * err, void *arg)
{
- struct lua_dispatcher_cbdata *cbdata = arg;
- rspamd_io_dispatcher_t **pdispatcher;
+ struct lua_dispatcher_cbdata *cbdata = arg;
+ rspamd_io_dispatcher_t **pdispatcher;
/* callback (dispatcher, err) */
lua_rawgeti (cbdata->L, LUA_REGISTRYINDEX, cbdata->cbref_err);
- pdispatcher =
- lua_newuserdata (cbdata->L, sizeof (struct rspamd_io_dispatcher_s *));
+ pdispatcher = lua_newuserdata (cbdata->L, sizeof (struct rspamd_io_dispatcher_s *));
lua_setclass (cbdata->L, "rspamd{io_dispatcher}", -1);
*pdispatcher = cbdata->d;
lua_pushstring (cbdata->L, err->message);
if (lua_pcall (cbdata->L, 2, 0, 0) != 0) {
- msg_info ("call to session finalizer failed: %s",
- lua_tostring (cbdata->L, -1));
+ msg_info ("call to session finalizer failed: %s", lua_tostring (cbdata->L, -1));
}
/* Unref callbacks */
@@ -169,11 +162,11 @@ lua_io_err_cb (GError * err, void *arg)
static int
lua_io_dispatcher_create (lua_State *L)
{
- struct rspamd_io_dispatcher_s *io_dispatcher, **pdispatcher;
- gint fd;
- struct lua_dispatcher_cbdata *cbdata;
- struct timeval tv = {0, 0};
- double tv_num, tmp;
+ struct rspamd_io_dispatcher_s *io_dispatcher, **pdispatcher;
+ gint fd;
+ struct lua_dispatcher_cbdata *cbdata;
+ struct timeval tv = {0, 0};
+ double tv_num, tmp;
if (lua_gettop (L) >= 5 && lua_isfunction (L, 3) && lua_isfunction (L, 5)) {
cbdata = g_slice_alloc0 (sizeof (struct lua_dispatcher_cbdata));
@@ -200,36 +193,20 @@ lua_io_dispatcher_create (lua_State *L)
tv_num = lua_tonumber (L, 6);
tv.tv_sec = trunc (tv_num);
tv.tv_usec = modf (tv_num, &tmp) * 1000.;
- io_dispatcher = rspamd_create_dispatcher (cbdata->base,
- fd,
- BUFFER_LINE,
- lua_io_read_cb,
- lua_io_write_cb,
- lua_io_err_cb,
- &tv,
- cbdata);
+ io_dispatcher = rspamd_create_dispatcher (cbdata->base, fd, BUFFER_LINE, lua_io_read_cb, lua_io_write_cb, lua_io_err_cb, &tv, cbdata);
}
else {
- io_dispatcher = rspamd_create_dispatcher (cbdata->base,
- fd,
- BUFFER_LINE,
- lua_io_read_cb,
- lua_io_write_cb,
- lua_io_err_cb,
- NULL,
- cbdata);
+ io_dispatcher = rspamd_create_dispatcher (cbdata->base, fd, BUFFER_LINE, lua_io_read_cb, lua_io_write_cb, lua_io_err_cb, NULL, cbdata);
}
cbdata->d = io_dispatcher;
/* Push result */
- pdispatcher =
- lua_newuserdata (L, sizeof (struct rspamd_io_dispatcher_s *));
+ pdispatcher = lua_newuserdata (L, sizeof (struct rspamd_io_dispatcher_s *));
lua_setclass (L, "rspamd{io_dispatcher}", -1);
*pdispatcher = io_dispatcher;
}
else {
- msg_err ("invalid number of arguments to io_dispatcher.create: %d",
- lua_gettop (L));
+ msg_err ("invalid number of arguments to io_dispatcher.create: %d", lua_gettop (L));
lua_pushnil (L);
}
@@ -239,8 +216,8 @@ lua_io_dispatcher_create (lua_State *L)
static int
lua_io_dispatcher_set_policy (lua_State *L)
{
- struct rspamd_io_dispatcher_s *io_dispatcher = lua_check_io_dispatcher (L);
- gint policy, limit = -1;
+ struct rspamd_io_dispatcher_s *io_dispatcher = lua_check_io_dispatcher (L);
+ gint policy, limit = -1;
if (io_dispatcher) {
policy = lua_tonumber (L, 2);
@@ -265,15 +242,14 @@ lua_io_dispatcher_set_policy (lua_State *L)
static int
lua_io_dispatcher_write (lua_State *L)
{
- struct rspamd_io_dispatcher_s *io_dispatcher = lua_check_io_dispatcher (L);
- gboolean delayed = FALSE, res;
- const gchar *data;
- size_t len;
+ struct rspamd_io_dispatcher_s *io_dispatcher = lua_check_io_dispatcher (L);
+ gboolean delayed = FALSE, res;
+ const gchar *data;
+ size_t len;
if (io_dispatcher) {
if (lua_gettop (L) < 2) {
- msg_err ("invalid number of arguments to io_dispatcher.create: %d",
- lua_gettop (L));
+ msg_err ("invalid number of arguments to io_dispatcher.create: %d", lua_gettop (L));
lua_pushboolean (L, FALSE);
}
else {
@@ -281,11 +257,7 @@ lua_io_dispatcher_write (lua_State *L)
if (lua_gettop (L) > 2) {
delayed = lua_toboolean (L, 3);
}
- res = rspamd_dispatcher_write (io_dispatcher,
- (void *)data,
- len,
- delayed,
- FALSE);
+ res = rspamd_dispatcher_write (io_dispatcher, (void *)data, len, delayed, FALSE);
lua_pushboolean (L, res);
}
}
@@ -299,7 +271,7 @@ lua_io_dispatcher_write (lua_State *L)
static int
lua_io_dispatcher_pause (lua_State *L)
{
- struct rspamd_io_dispatcher_s *io_dispatcher = lua_check_io_dispatcher (L);
+ struct rspamd_io_dispatcher_s *io_dispatcher = lua_check_io_dispatcher (L);
if (io_dispatcher) {
rspamd_dispatcher_pause (io_dispatcher);
@@ -315,7 +287,7 @@ lua_io_dispatcher_pause (lua_State *L)
static int
lua_io_dispatcher_restore (lua_State *L)
{
- struct rspamd_io_dispatcher_s *io_dispatcher = lua_check_io_dispatcher (L);
+ struct rspamd_io_dispatcher_s *io_dispatcher = lua_check_io_dispatcher (L);
if (io_dispatcher) {
rspamd_dispatcher_restore (io_dispatcher);
@@ -331,7 +303,7 @@ lua_io_dispatcher_restore (lua_State *L)
static int
lua_io_dispatcher_destroy (lua_State *L)
{
- struct rspamd_io_dispatcher_s *io_dispatcher = lua_check_io_dispatcher (L);
+ struct rspamd_io_dispatcher_s *io_dispatcher = lua_check_io_dispatcher (L);
if (io_dispatcher) {
rspamd_remove_dispatcher (io_dispatcher);
@@ -357,16 +329,16 @@ luaopen_io_dispatcher (lua_State * L)
lua_pushstring (L, "rspamd{io_dispatcher}");
lua_rawset (L, -3);
- luaL_register (L, NULL, io_dispatcherlib_m);
+ luaL_register (L, NULL, io_dispatcherlib_m);
luaL_register (L, "rspamd_io_dispatcher", io_dispatcherlib_f);
- lua_pop (L, 1); /* remove metatable from stack */
+ lua_pop(L, 1); /* remove metatable from stack */
/* Simple event class */
lua_newclass (L, "rspamd{ev_base}", null_reg);
luaL_register (L, "rspamd_ev_base", null_reg);
- lua_pop (L, 1); /* remove metatable from stack */
+ lua_pop(L, 1); /* remove metatable from stack */
/* Set buffer types globals */
lua_pushnumber (L, BUFFER_LINE);
@@ -375,5 +347,5 @@ luaopen_io_dispatcher (lua_State * L)
lua_setglobal (L, "IO_BUFFER_CHARACTER");
lua_pushnumber (L, BUFFER_ANY);
lua_setglobal (L, "IO_BUFFER_ANY");
- return 1;
+ return 1;
}
diff --git a/src/lua/lua_cdb.c b/src/lua/lua_cdb.c
index 12ef7f501..6832dfe59 100644
--- a/src/lua/lua_cdb.c
+++ b/src/lua/lua_cdb.c
@@ -21,8 +21,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "cdb/cdb.h"
#include "lua_common.h"
+#include "cdb/cdb.h"
#define CDB_REFRESH_TIME 60
@@ -31,22 +31,22 @@ LUA_FUNCTION_DEF (cdb, lookup);
LUA_FUNCTION_DEF (cdb, get_name);
LUA_FUNCTION_DEF (cdb, destroy);
-static const struct luaL_reg cdblib_m[] = {
+static const struct luaL_reg cdblib_m[] = {
LUA_INTERFACE_DEF (cdb, lookup),
LUA_INTERFACE_DEF (cdb, get_name),
{"__tostring", lua_class_tostring},
{"__gc", lua_cdb_destroy},
{NULL, NULL}
};
-static const struct luaL_reg cdblib_f[] = {
+static const struct luaL_reg cdblib_f[] = {
LUA_INTERFACE_DEF (cdb, create),
{NULL, NULL}
};
-static struct cdb *
+static struct cdb *
lua_check_cdb (lua_State * L)
{
- void *ud = luaL_checkudata (L, 1, "rspamd{cdb}");
+ void *ud = luaL_checkudata (L, 1, "rspamd{cdb}");
luaL_argcheck (L, ud != NULL, 1, "'cdb' expected");
return ud ? *((struct cdb **)ud) : NULL;
@@ -55,9 +55,9 @@ lua_check_cdb (lua_State * L)
static gint
lua_cdb_create (lua_State *L)
{
- struct cdb *cdb, **pcdb;
- const gchar *filename;
- gint fd;
+ struct cdb *cdb, **pcdb;
+ const gchar *filename;
+ gint fd;
filename = luaL_checkstring (L, 1);
/* If file begins with cdb://, just skip it */
@@ -79,7 +79,7 @@ lua_cdb_create (lua_State *L)
lua_pushnil (L);
}
else {
- pcdb = lua_newuserdata (L, sizeof (struct cdb *));
+ pcdb = lua_newuserdata (L, sizeof (struct cdb*));
lua_setclass (L, "rspamd{cdb}", -1);
*pcdb = cdb;
}
@@ -91,7 +91,7 @@ lua_cdb_create (lua_State *L)
static gint
lua_cdb_get_name (lua_State *L)
{
- struct cdb *cdb = lua_check_cdb (L);
+ struct cdb *cdb = lua_check_cdb (L);
lua_pushstring (L, cdb->filename);
return 1;
@@ -100,11 +100,11 @@ lua_cdb_get_name (lua_State *L)
static gint
lua_cdb_lookup (lua_State *L)
{
- struct cdb *cdb = lua_check_cdb (L);
- const gchar *what;
- gchar *value;
- gsize vlen;
- gint64 vpos;
+ struct cdb *cdb = lua_check_cdb (L);
+ const gchar *what;
+ gchar *value;
+ gsize vlen;
+ gint64 vpos;
/*
* XXX: this code is placed here because event_loop is called inside workers, so start
@@ -134,7 +134,7 @@ lua_cdb_lookup (lua_State *L)
static gint
lua_cdb_destroy (lua_State *L)
{
- struct cdb *cdb = lua_check_cdb (L);
+ struct cdb *cdb = lua_check_cdb (L);
if (cdb) {
cdb_free (cdb);
@@ -158,7 +158,7 @@ luaopen_cdb (lua_State * L)
lua_pushstring (L, "rspamd{cdb}");
lua_rawset (L, -3);
- luaL_register (L, NULL, cdblib_m);
+ luaL_register (L, NULL, cdblib_m);
luaL_register (L, "cdb", cdblib_f);
lua_pop (L, 1); /* remove metatable from stack */
diff --git a/src/lua/lua_cfg_file.c b/src/lua/lua_cfg_file.c
index 08c14a825..83ac4545c 100644
--- a/src/lua/lua_cfg_file.c
+++ b/src/lua/lua_cfg_file.c
@@ -22,26 +22,26 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "expressions.h"
#include "lua_common.h"
+#include "expressions.h"
#include "symbols_cache.h"
#ifdef HAVE_SYS_UTSNAME_H
#include <sys/utsname.h>
#endif
-/*
- * This is implementation of lua routines to handle config file params
+/*
+ * This is implementation of lua routines to handle config file params
*/
/* Process a single item in 'metrics' table */
static void
lua_process_metric (lua_State *L, const gchar *name, struct rspamd_config *cfg)
{
- GList *metric_list;
- gchar *symbol, *old_desc;
- const gchar *desc;
- struct metric *metric;
- gdouble *score, *old_score;
+ GList *metric_list;
+ gchar *symbol, *old_desc;
+ const gchar *desc;
+ struct metric *metric;
+ gdouble *score, *old_score;
/* Get module opt structure */
if ((metric = g_hash_table_lookup (cfg->metrics, name)) == NULL) {
@@ -50,18 +50,16 @@ lua_process_metric (lua_State *L, const gchar *name, struct rspamd_config *cfg)
}
/* Now iterate throught module table */
- for (lua_pushnil (L); lua_next (L, -2); lua_pop (L, 1)) {
+ for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) {
/* key - -2, value - -1 */
- symbol =
- rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, -2));
+ symbol = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, -2));
if (symbol != NULL) {
if (lua_istable (L, -1)) {
/* We got a table, so extract individual attributes */
lua_pushstring (L, "weight");
lua_gettable (L, -2);
if (lua_isnumber (L, -1)) {
- score =
- rspamd_mempool_alloc (cfg->cfg_pool, sizeof (double));
+ score = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (double));
*score = lua_tonumber (L, -1);
}
else {
@@ -73,19 +71,15 @@ lua_process_metric (lua_State *L, const gchar *name, struct rspamd_config *cfg)
lua_gettable (L, -2);
if (lua_isstring (L, -1)) {
desc = lua_tostring (L, -1);
- old_desc =
- g_hash_table_lookup (metric->descriptions, symbol);
+ old_desc = g_hash_table_lookup (metric->descriptions, symbol);
if (old_desc) {
- msg_info ("replacing description for symbol %s",
- symbol);
+ msg_info ("replacing description for symbol %s", symbol);
g_hash_table_replace (metric->descriptions,
- symbol,
- rspamd_mempool_strdup (cfg->cfg_pool, desc));
+ symbol, rspamd_mempool_strdup (cfg->cfg_pool, desc));
}
else {
g_hash_table_insert (metric->descriptions,
- symbol,
- rspamd_mempool_strdup (cfg->cfg_pool, desc));
+ symbol, rspamd_mempool_strdup (cfg->cfg_pool, desc));
}
}
lua_pop (L, 1);
@@ -100,23 +94,17 @@ lua_process_metric (lua_State *L, const gchar *name, struct rspamd_config *cfg)
continue;
}
/* Insert symbol */
- if ((old_score =
- g_hash_table_lookup (metric->symbols, symbol)) != NULL) {
- msg_info ("replacing weight for symbol %s: %.2f -> %.2f",
- symbol,
- *old_score,
- *score);
+ if ((old_score = g_hash_table_lookup (metric->symbols, symbol)) != NULL) {
+ msg_info ("replacing weight for symbol %s: %.2f -> %.2f", symbol, *old_score, *score);
g_hash_table_replace (metric->symbols, symbol, score);
}
else {
g_hash_table_insert (metric->symbols, symbol, score);
}
- if ((metric_list =
- g_hash_table_lookup (cfg->metrics_symbols, symbol)) == NULL) {
+ if ((metric_list = g_hash_table_lookup (cfg->metrics_symbols, symbol)) == NULL) {
metric_list = g_list_prepend (NULL, metric);
- rspamd_mempool_add_destructor (cfg->cfg_pool,
- (rspamd_mempool_destruct_t)g_list_free, metric_list);
+ rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t)g_list_free, metric_list);
g_hash_table_insert (cfg->metrics_symbols, symbol, metric_list);
}
else {
@@ -133,30 +121,26 @@ lua_process_metric (lua_State *L, const gchar *name, struct rspamd_config *cfg)
void
lua_post_load_config (struct rspamd_config *cfg)
{
- lua_State *L = cfg->lua_state;
- const gchar *name, *val;
- gchar *sym;
- struct expression *expr, *old_expr;
- ucl_object_t *obj;
- gsize keylen;
+ lua_State *L = cfg->lua_state;
+ const gchar *name, *val;
+ gchar *sym;
+ struct expression *expr, *old_expr;
+ ucl_object_t *obj;
+ gsize keylen;
/* First check all module options that may be overriden in 'config' global */
lua_getglobal (L, "config");
if (lua_istable (L, -1)) {
/* Iterate */
- for (lua_pushnil (L); lua_next (L, -2); lua_pop (L, 1)) {
+ for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) {
/* 'key' is at index -2 and 'value' is at index -1 */
/* Key must be a string and value must be a table */
name = luaL_checklstring (L, -2, &keylen);
if (name != NULL && lua_istable (L, -1)) {
obj = ucl_object_lua_import (L, lua_gettop (L));
if (obj != NULL) {
- ucl_object_insert_key_merged (cfg->rcl_obj,
- obj,
- name,
- keylen,
- true);
+ ucl_object_insert_key_merged (cfg->rcl_obj, obj, name, keylen, true);
}
}
}
@@ -167,7 +151,7 @@ lua_post_load_config (struct rspamd_config *cfg)
if (lua_istable (L, -1)) {
/* Iterate */
- for (lua_pushnil (L); lua_next (L, -2); lua_pop (L, 1)) {
+ for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) {
/* 'key' is at index -2 and 'value' is at index -1 */
/* Key must be a string and value must be a table */
name = luaL_checkstring (L, -2);
@@ -182,23 +166,19 @@ lua_post_load_config (struct rspamd_config *cfg)
if (lua_istable (L, -1)) {
/* Iterate */
- for (lua_pushnil (L); lua_next (L, -2); lua_pop (L, 1)) {
+ for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) {
/* 'key' is at index -2 and 'value' is at index -1 */
/* Key must be a string and value must be a table */
name = luaL_checkstring (L, -2);
if (name != NULL && lua_isstring (L, -1)) {
val = lua_tostring (L, -1);
- sym = rspamd_mempool_strdup (cfg->cfg_pool, name);
- if ((expr =
- parse_expression (cfg->cfg_pool,
- rspamd_mempool_strdup (cfg->cfg_pool, val))) == NULL) {
+ sym = rspamd_mempool_strdup(cfg->cfg_pool, name);
+ if ((expr = parse_expression (cfg->cfg_pool, rspamd_mempool_strdup(cfg->cfg_pool, val))) == NULL) {
msg_err ("cannot parse composite expression: %s", val);
continue;
}
/* Now check hash table for this composite */
- if ((old_expr =
- g_hash_table_lookup (cfg->composite_symbols,
- name)) != NULL) {
+ if ((old_expr = g_hash_table_lookup (cfg->composite_symbols, name)) != NULL) {
msg_info ("replacing composite symbol %s", name);
g_hash_table_replace (cfg->composite_symbols, sym, expr);
}
@@ -213,14 +193,10 @@ lua_post_load_config (struct rspamd_config *cfg)
/* Handle lua dynamic config param */
gboolean
-lua_handle_param (struct rspamd_task *task,
- gchar *mname,
- gchar *optname,
- enum lua_var_type expected_type,
- gpointer *res)
+lua_handle_param (struct rspamd_task *task, gchar *mname, gchar *optname, enum lua_var_type expected_type, gpointer *res)
{
/* xxx: Adopt this for rcl */
-
+
/* Option not found */
*res = NULL;
return FALSE;
@@ -230,12 +206,12 @@ lua_handle_param (struct rspamd_task *task,
gboolean
lua_check_condition (struct rspamd_config *cfg, const gchar *condition)
{
- lua_State *L = cfg->lua_state;
- gchar *hostbuf, *condbuf;
- gsize hostlen;
- gboolean res;
+ lua_State *L = cfg->lua_state;
+ gchar *hostbuf, *condbuf;
+ gsize hostlen;
+ gboolean res;
#ifdef HAVE_SYS_UTSNAME_H
- struct utsname uts;
+ struct utsname uts;
#endif
/* Set some globals for condition */
@@ -274,12 +250,12 @@ lua_check_condition (struct rspamd_config *cfg, const gchar *condition)
/* Rspamd paths */
lua_newtable (L);
- lua_set_table_index (L, "confdir", RSPAMD_CONFDIR);
- lua_set_table_index (L, "rundir", RSPAMD_RUNDIR);
- lua_set_table_index (L, "dbdir", RSPAMD_DBDIR);
- lua_set_table_index (L, "logdir", RSPAMD_LOGDIR);
+ lua_set_table_index (L, "confdir", RSPAMD_CONFDIR);
+ lua_set_table_index (L, "rundir", RSPAMD_RUNDIR);
+ lua_set_table_index (L, "dbdir", RSPAMD_DBDIR);
+ lua_set_table_index (L, "logdir", RSPAMD_LOGDIR);
lua_set_table_index (L, "pluginsdir", RSPAMD_PLUGINSDIR);
- lua_set_table_index (L, "prefix", RSPAMD_PREFIX);
+ lua_set_table_index (L, "prefix", RSPAMD_PREFIX);
lua_setglobal (L, "rspamd_paths");
/* Make fake string */
@@ -295,11 +271,10 @@ lua_check_condition (struct rspamd_config *cfg, const gchar *condition)
}
/* Get global variable res to get result */
lua_getglobal (L, FAKE_RES_VAR);
- if (!lua_isboolean (L, -1)) {
- msg_err ("bad string evaluated: %s, type: %s", condbuf,
- lua_typename (L, lua_type (L, -1)));
+ if (! lua_isboolean (L, -1)) {
+ msg_err ("bad string evaluated: %s, type: %s", condbuf, lua_typename (L, lua_type (L, -1)));
g_free (condbuf);
- return FALSE;
+ return FALSE;
}
res = lua_toboolean (L, -1);
diff --git a/src/lua/lua_classifier.c b/src/lua/lua_classifier.c
index f1eade146..d227fc5da 100644
--- a/src/lua/lua_classifier.c
+++ b/src/lua/lua_classifier.c
@@ -23,9 +23,9 @@
*/
+#include "lua_common.h"
#include "cfg_file.h"
#include "classifiers/classifiers.h"
-#include "lua_common.h"
/* Classifier methods */
LUA_FUNCTION_DEF (classifier, register_pre_callback);
@@ -33,7 +33,7 @@ LUA_FUNCTION_DEF (classifier, register_post_callback);
LUA_FUNCTION_DEF (classifier, get_statfiles);
LUA_FUNCTION_DEF (classifier, get_statfile_by_label);
-static const struct luaL_reg classifierlib_m[] = {
+static const struct luaL_reg classifierlib_m[] = {
LUA_INTERFACE_DEF (classifier, register_pre_callback),
LUA_INTERFACE_DEF (classifier, register_post_callback),
LUA_INTERFACE_DEF (classifier, get_statfiles),
@@ -50,7 +50,7 @@ LUA_FUNCTION_DEF (statfile, get_size);
LUA_FUNCTION_DEF (statfile, is_spam);
LUA_FUNCTION_DEF (statfile, get_param);
-static const struct luaL_reg statfilelib_m[] = {
+static const struct luaL_reg statfilelib_m[] = {
LUA_INTERFACE_DEF (statfile, get_symbol),
LUA_INTERFACE_DEF (statfile, get_label),
LUA_INTERFACE_DEF (statfile, get_path),
@@ -66,30 +66,27 @@ struct classifier_callback_data {
const gchar *name;
};
-static struct rspamd_statfile_config * lua_check_statfile (lua_State * L);
+static struct rspamd_statfile_config* lua_check_statfile (lua_State * L);
/* Classifier implementation */
-static struct rspamd_classifier_config *
+static struct rspamd_classifier_config *
lua_check_classifier (lua_State * L)
{
- void *ud = luaL_checkudata (L, 1, "rspamd{classifier}");
+ void *ud = luaL_checkudata (L, 1, "rspamd{classifier}");
luaL_argcheck (L, ud != NULL, 1, "'classifier' expected");
return ud ? *((struct rspamd_classifier_config **)ud) : NULL;
}
static GList *
-call_classifier_pre_callback (struct rspamd_classifier_config *ccf,
- struct rspamd_task *task,
- lua_State *L,
- gboolean is_learn,
- gboolean is_spam)
+call_classifier_pre_callback (struct rspamd_classifier_config *ccf, struct rspamd_task *task,
+ lua_State *L, gboolean is_learn, gboolean is_spam)
{
- struct rspamd_classifier_config **pccf;
- struct rspamd_task **ptask;
- struct rspamd_statfile_config **pst;
- GList *res = NULL;
+ struct rspamd_classifier_config **pccf;
+ struct rspamd_task **ptask;
+ struct rspamd_statfile_config **pst;
+ GList *res = NULL;
pccf = lua_newuserdata (L, sizeof (struct rspamd_classifier_config *));
lua_setclass (L, "rspamd{classifier}", -1);
@@ -103,13 +100,12 @@ call_classifier_pre_callback (struct rspamd_classifier_config *ccf,
lua_pushboolean (L, is_spam);
if (lua_pcall (L, 4, 1, 0) != 0) {
- msg_warn ("error running pre classifier callback %s",
- lua_tostring (L, -1));
+ msg_warn ("error running pre classifier callback %s", lua_tostring (L, -1));
}
else {
if (lua_istable (L, -1)) {
lua_pushnil (L);
- while (lua_next (L, -2)) {
+ while(lua_next (L, -2)) {
pst = luaL_checkudata (L, -1, "rspamd{statfile}");
if (pst) {
res = g_list_prepend (res, *pst);
@@ -124,13 +120,10 @@ call_classifier_pre_callback (struct rspamd_classifier_config *ccf,
/* Return list of statfiles that should be checked for this message */
GList *
-call_classifier_pre_callbacks (struct rspamd_classifier_config *ccf,
- struct rspamd_task *task,
- gboolean is_learn,
- gboolean is_spam,
- lua_State *L)
+call_classifier_pre_callbacks (struct rspamd_classifier_config *ccf, struct rspamd_task *task,
+ gboolean is_learn, gboolean is_spam, lua_State *L)
{
- GList *res = NULL, *cur;
+ GList *res = NULL, *cur;
struct classifier_callback_data *cd;
@@ -140,9 +133,7 @@ call_classifier_pre_callbacks (struct rspamd_classifier_config *ccf,
cd = cur->data;
lua_getglobal (L, cd->name);
- res =
- g_list_concat (res,
- call_classifier_pre_callback (ccf, task, L, is_learn, is_spam));
+ res = g_list_concat (res, call_classifier_pre_callback (ccf, task, L, is_learn, is_spam));
cur = g_list_next (cur);
}
@@ -155,11 +146,7 @@ call_classifier_pre_callbacks (struct rspamd_classifier_config *ccf,
lua_gettable (L, -2);
/* Function is now on top */
if (lua_isfunction (L, -1)) {
- res = call_classifier_pre_callback (ccf,
- task,
- L,
- is_learn,
- is_spam);
+ res = call_classifier_pre_callback (ccf, task, L, is_learn, is_spam);
}
lua_pop (L, 1);
}
@@ -171,16 +158,13 @@ call_classifier_pre_callbacks (struct rspamd_classifier_config *ccf,
/* Return result mark for statfile */
double
-call_classifier_post_callbacks (struct rspamd_classifier_config *ccf,
- struct rspamd_task *task,
- double in,
- lua_State *L)
+call_classifier_post_callbacks (struct rspamd_classifier_config *ccf, struct rspamd_task *task, double in, lua_State *L)
{
struct classifier_callback_data *cd;
- struct rspamd_classifier_config **pccf;
- struct rspamd_task **ptask;
- double out = in;
- GList *cur;
+ struct rspamd_classifier_config **pccf;
+ struct rspamd_task **ptask;
+ double out = in;
+ GList *cur;
/* Go throught all callbacks and call them, appending results to list */
cur = g_list_first (ccf->pre_callbacks);
@@ -199,8 +183,7 @@ call_classifier_post_callbacks (struct rspamd_classifier_config *ccf,
lua_pushnumber (L, out);
if (lua_pcall (L, 3, 1, 0) != 0) {
- msg_warn ("error running function %s: %s", cd->name,
- lua_tostring (L, -1));
+ msg_warn ("error running function %s: %s", cd->name, lua_tostring (L, -1));
}
else {
if (lua_isnumber (L, 1)) {
@@ -219,9 +202,9 @@ call_classifier_post_callbacks (struct rspamd_classifier_config *ccf,
static gint
lua_classifier_register_pre_callback (lua_State *L)
{
- struct rspamd_classifier_config *ccf = lua_check_classifier (L);
+ struct rspamd_classifier_config *ccf = lua_check_classifier (L);
struct classifier_callback_data *cd;
- const gchar *name;
+ const gchar *name;
if (ccf) {
name = luaL_checkstring (L, 2);
@@ -240,9 +223,9 @@ lua_classifier_register_pre_callback (lua_State *L)
static gint
lua_classifier_register_post_callback (lua_State *L)
{
- struct rspamd_classifier_config *ccf = lua_check_classifier (L);
+ struct rspamd_classifier_config *ccf = lua_check_classifier (L);
struct classifier_callback_data *cd;
- const gchar *name;
+ const gchar *name;
if (ccf) {
name = luaL_checkstring (L, 2);
@@ -261,10 +244,10 @@ lua_classifier_register_post_callback (lua_State *L)
static gint
lua_classifier_get_statfiles (lua_State *L)
{
- struct rspamd_classifier_config *ccf = lua_check_classifier (L);
- GList *cur;
- struct rspamd_statfile_config *st, **pst;
- gint i;
+ struct rspamd_classifier_config *ccf = lua_check_classifier (L);
+ GList *cur;
+ struct rspamd_statfile_config *st, **pst;
+ gint i;
if (ccf) {
lua_newtable (L);
@@ -291,11 +274,11 @@ lua_classifier_get_statfiles (lua_State *L)
static gint
lua_classifier_get_statfile_by_label (lua_State *L)
{
- struct rspamd_classifier_config *ccf = lua_check_classifier (L);
- struct rspamd_statfile_config *st, **pst;
- const gchar *label;
- GList *cur;
- gint i;
+ struct rspamd_classifier_config *ccf = lua_check_classifier (L);
+ struct rspamd_statfile_config *st, **pst;
+ const gchar *label;
+ GList *cur;
+ gint i;
label = luaL_checkstring (L, 2);
if (ccf && label) {
@@ -305,9 +288,7 @@ lua_classifier_get_statfile_by_label (lua_State *L)
i = 1;
while (cur) {
st = cur->data;
- pst =
- lua_newuserdata (L,
- sizeof (struct rspamd_statfile_config *));
+ pst = lua_newuserdata (L, sizeof (struct rspamd_statfile_config *));
lua_setclass (L, "rspamd{statfile}", -1);
*pst = st;
lua_rawseti (L, -2, i++);
@@ -324,7 +305,7 @@ lua_classifier_get_statfile_by_label (lua_State *L)
static gint
lua_statfile_get_symbol (lua_State *L)
{
- struct rspamd_statfile_config *st = lua_check_statfile (L);
+ struct rspamd_statfile_config *st = lua_check_statfile (L);
if (st != NULL) {
lua_pushstring (L, st->symbol);
@@ -339,7 +320,7 @@ lua_statfile_get_symbol (lua_State *L)
static gint
lua_statfile_get_label (lua_State *L)
{
- struct rspamd_statfile_config *st = lua_check_statfile (L);
+ struct rspamd_statfile_config *st = lua_check_statfile (L);
if (st != NULL && st->label != NULL) {
lua_pushstring (L, st->label);
@@ -354,7 +335,7 @@ lua_statfile_get_label (lua_State *L)
static gint
lua_statfile_get_path (lua_State *L)
{
- struct rspamd_statfile_config *st = lua_check_statfile (L);
+ struct rspamd_statfile_config *st = lua_check_statfile (L);
if (st != NULL) {
lua_pushstring (L, st->path);
@@ -369,7 +350,7 @@ lua_statfile_get_path (lua_State *L)
static gint
lua_statfile_get_size (lua_State *L)
{
- struct rspamd_statfile_config *st = lua_check_statfile (L);
+ struct rspamd_statfile_config *st = lua_check_statfile (L);
if (st != NULL) {
lua_pushinteger (L, st->size);
@@ -384,7 +365,7 @@ lua_statfile_get_size (lua_State *L)
static gint
lua_statfile_is_spam (lua_State *L)
{
- struct rspamd_statfile_config *st = lua_check_statfile (L);
+ struct rspamd_statfile_config *st = lua_check_statfile (L);
if (st != NULL) {
lua_pushboolean (L, st->is_spam);
@@ -399,9 +380,9 @@ lua_statfile_is_spam (lua_State *L)
static gint
lua_statfile_get_param (lua_State *L)
{
- struct rspamd_statfile_config *st = lua_check_statfile (L);
- const gchar *param;
- const ucl_object_t *value;
+ struct rspamd_statfile_config *st = lua_check_statfile (L);
+ const gchar *param;
+ const ucl_object_t *value;
param = luaL_checkstring (L, 2);
@@ -417,10 +398,10 @@ lua_statfile_get_param (lua_State *L)
return 1;
}
-static struct rspamd_statfile_config *
+static struct rspamd_statfile_config *
lua_check_statfile (lua_State * L)
{
- void *ud = luaL_checkudata (L, 1, "rspamd{statfile}");
+ void *ud = luaL_checkudata (L, 1, "rspamd{statfile}");
luaL_argcheck (L, ud != NULL, 1, "'statfile' expected");
return ud ? *((struct rspamd_statfile_config **)ud) : NULL;
}
diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c
index cb2730231..ea1e43010 100644
--- a/src/lua/lua_common.c
+++ b/src/lua/lua_common.c
@@ -22,13 +22,13 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "expressions.h"
#include "lua_common.h"
+#include "expressions.h"
/* Lua module init function */
#define MODULE_INIT_FUNC "module_init"
-const luaL_reg null_reg[] = {
+const luaL_reg null_reg[] = {
{"__tostring", lua_class_tostring},
{NULL, NULL}
};
@@ -39,7 +39,7 @@ LUA_FUNCTION_DEF (logger, warn);
LUA_FUNCTION_DEF (logger, info);
LUA_FUNCTION_DEF (logger, debug);
-static const struct luaL_reg loggerlib_f[] = {
+static const struct luaL_reg loggerlib_f[] = {
LUA_INTERFACE_DEF (logger, err),
LUA_INTERFACE_DEF (logger, warn),
LUA_INTERFACE_DEF (logger, info),
@@ -57,18 +57,16 @@ static const struct luaL_reg loggerlib_f[] = {
* @param func table of class methods
*/
void
-lua_newclass (lua_State * L,
- const gchar *classname,
- const struct luaL_reg *methods)
+lua_newclass (lua_State * L, const gchar *classname, const struct luaL_reg *methods)
{
- luaL_newmetatable (L, classname); /* mt */
+ luaL_newmetatable (L, classname); /* mt */
lua_pushstring (L, "__index");
- lua_pushvalue (L, -2); /* pushes the metatable */
- lua_settable (L, -3); /* metatable.__index = metatable */
+ lua_pushvalue (L, -2); /* pushes the metatable */
+ lua_settable (L, -3); /* metatable.__index = metatable */
- lua_pushstring (L, "class"); /* mt,"__index",it,"class" */
- lua_pushstring (L, classname); /* mt,"__index",it,"class",classname */
- lua_rawset (L, -3); /* mt,"__index",it */
+ lua_pushstring (L, "class"); /* mt,"__index",it,"class" */
+ lua_pushstring (L, classname); /* mt,"__index",it,"class",classname */
+ lua_rawset (L, -3); /* mt,"__index",it */
luaL_register (L, NULL, methods);
}
@@ -76,11 +74,7 @@ lua_newclass (lua_State * L,
* Create and register new class with static methods and store metatable on top of the stack
*/
void
-lua_newclass_full (lua_State *L,
- const gchar *classname,
- const gchar *static_name,
- const struct luaL_reg *methods,
- const struct luaL_reg *func)
+lua_newclass_full (lua_State *L, const gchar *classname, const gchar *static_name, const struct luaL_reg *methods, const struct luaL_reg *func)
{
lua_newclass (L, classname, methods);
luaL_register (L, static_name, func);
@@ -89,7 +83,7 @@ lua_newclass_full (lua_State *L,
gint
lua_class_tostring (lua_State * L)
{
- gchar buf[32];
+ gchar buf[32];
if (!lua_getmetatable (L, 1)) {
goto error;
@@ -113,7 +107,7 @@ lua_class_tostring (lua_State * L)
return 1;
-error:
+ error:
lua_pushstring (L, "invalid object passed to 'lua_common.c:__tostring'");
lua_error (L);
return 1;
@@ -163,48 +157,31 @@ lua_get_table_index_str (lua_State *L, const gchar *index)
static void
lua_common_log (GLogLevelFlags level, lua_State *L, const gchar *msg)
{
- lua_Debug d;
- gchar func_buf[128], *p;
+ lua_Debug d;
+ gchar func_buf[128], *p;
if (lua_getstack (L, 1, &d) == 1) {
- (void)lua_getinfo (L, "Sl", &d);
+ (void)lua_getinfo(L, "Sl", &d);
if ((p = strrchr (d.short_src, '/')) == NULL) {
p = d.short_src;
}
else {
- p++;
+ p ++;
}
- rspamd_snprintf (func_buf, sizeof (func_buf), "%s:%d", p,
- d.currentline);
+ rspamd_snprintf (func_buf, sizeof (func_buf), "%s:%d", p, d.currentline);
if (level == G_LOG_LEVEL_DEBUG) {
- rspamd_conditional_debug (rspamd_main->logger,
- NULL,
- func_buf,
- "%s",
- msg);
+ rspamd_conditional_debug (rspamd_main->logger, NULL, func_buf, "%s", msg);
}
else {
- rspamd_common_log_function (rspamd_main->logger,
- level,
- func_buf,
- "%s",
- msg);
+ rspamd_common_log_function (rspamd_main->logger, level, func_buf, "%s", msg);
}
}
else {
if (level == G_LOG_LEVEL_DEBUG) {
- rspamd_conditional_debug (rspamd_main->logger,
- NULL,
- __FUNCTION__,
- "%s",
- msg);
+ rspamd_conditional_debug (rspamd_main->logger, NULL, __FUNCTION__, "%s", msg);
}
else {
- rspamd_common_log_function (rspamd_main->logger,
- level,
- __FUNCTION__,
- "%s",
- msg);
+ rspamd_common_log_function (rspamd_main->logger, level, __FUNCTION__, "%s", msg);
}
}
}
@@ -213,7 +190,7 @@ lua_common_log (GLogLevelFlags level, lua_State *L, const gchar *msg)
static gint
lua_logger_err (lua_State * L)
{
- const gchar *msg;
+ const gchar *msg;
msg = luaL_checkstring (L, 1);
lua_common_log (G_LOG_LEVEL_CRITICAL, L, msg);
return 1;
@@ -222,7 +199,7 @@ lua_logger_err (lua_State * L)
static gint
lua_logger_warn (lua_State * L)
{
- const gchar *msg;
+ const gchar *msg;
msg = luaL_checkstring (L, 1);
lua_common_log (G_LOG_LEVEL_WARNING, L, msg);
return 1;
@@ -231,7 +208,7 @@ lua_logger_warn (lua_State * L)
static gint
lua_logger_info (lua_State * L)
{
- const gchar *msg;
+ const gchar *msg;
msg = luaL_checkstring (L, 1);
lua_common_log (G_LOG_LEVEL_INFO, L, msg);
return 1;
@@ -240,7 +217,7 @@ lua_logger_info (lua_State * L)
static gint
lua_logger_debug (lua_State * L)
{
- const gchar *msg;
+ const gchar *msg;
msg = luaL_checkstring (L, 1);
lua_common_log (G_LOG_LEVEL_DEBUG, L, msg);
return 1;
@@ -273,11 +250,11 @@ luaopen_logger (lua_State * L)
static void
lua_add_actions_global (lua_State *L)
{
- gint i;
+ gint i;
lua_newtable (L);
- for (i = METRIC_ACTION_REJECT; i <= METRIC_ACTION_NOACTION; i++) {
+ for (i = METRIC_ACTION_REJECT; i <= METRIC_ACTION_NOACTION; i ++) {
lua_pushstring (L, str_action_metric (i));
lua_pushinteger (L, i);
lua_settable (L, -3);
@@ -289,7 +266,7 @@ lua_add_actions_global (lua_State *L)
lua_State *
init_lua (struct rspamd_config *cfg)
{
- lua_State *L;
+ lua_State *L;
L = luaL_newstate ();
luaL_openlibs (L);
@@ -329,10 +306,10 @@ init_lua (struct rspamd_config *cfg)
/**
* Initialize new locked lua_State structure
*/
-struct lua_locked_state *
+struct lua_locked_state*
init_lua_locked (struct rspamd_config *cfg)
{
- struct lua_locked_state *new;
+ struct lua_locked_state *new;
new = g_slice_alloc (sizeof (struct lua_locked_state));
new->L = init_lua (cfg);
@@ -360,19 +337,18 @@ free_lua_locked (struct lua_locked_state *st)
gboolean
init_lua_filters (struct rspamd_config *cfg)
{
- struct rspamd_config **pcfg;
- GList *cur, *tmp;
- struct script_module *module;
- struct rspamd_statfile_config *st;
- lua_State *L = cfg->lua_state;
+ struct rspamd_config **pcfg;
+ GList *cur, *tmp;
+ struct script_module *module;
+ struct rspamd_statfile_config *st;
+ lua_State *L = cfg->lua_state;
cur = g_list_first (cfg->script_modules);
while (cur) {
module = cur->data;
if (module->path) {
if (luaL_loadfile (L, module->path) != 0) {
- msg_info ("load of %s failed: %s", module->path,
- lua_tostring (L, -1));
+ msg_info ("load of %s failed: %s", module->path, lua_tostring (L, -1));
cur = g_list_next (cur);
return FALSE;
}
@@ -385,15 +361,12 @@ init_lua_filters (struct rspamd_config *cfg)
/* do the call (0 arguments, N result) */
if (lua_pcall (L, 0, LUA_MULTRET, 0) != 0) {
- msg_info ("init of %s failed: %s", module->path,
- lua_tostring (L, -1));
+ msg_info ("init of %s failed: %s", module->path, lua_tostring (L, -1));
return FALSE;
}
if (lua_gettop (L) != 0) {
if (lua_tonumber (L, -1) == -1) {
- msg_info (
- "%s returned -1 that indicates configuration error",
- module->path);
+ msg_info ("%s returned -1 that indicates configuration error", module->path);
return FALSE;
}
lua_pop (L, lua_gettop (L));
@@ -401,24 +374,24 @@ init_lua_filters (struct rspamd_config *cfg)
}
cur = g_list_next (cur);
}
- /* Init statfiles normalizers */
- cur = g_list_first (cfg->statfiles);
- while (cur) {
- st = cur->data;
- if (st->normalizer == lua_normalizer_func) {
- tmp = st->normalizer_data;
- if (tmp && (tmp = g_list_next (tmp))) {
- if (tmp->data) {
- /* Code must be loaded from data */
- if (luaL_loadstring (L, tmp->data) != 0) {
- msg_info ("cannot load normalizer code %s", tmp->data);
- return FALSE;
- }
- }
- }
- }
- cur = g_list_next (cur);
- }
+ /* Init statfiles normalizers */
+ cur = g_list_first (cfg->statfiles);
+ while (cur) {
+ st = cur->data;
+ if (st->normalizer == lua_normalizer_func) {
+ tmp = st->normalizer_data;
+ if (tmp && (tmp = g_list_next (tmp))) {
+ if (tmp->data) {
+ /* Code must be loaded from data */
+ if (luaL_loadstring (L, tmp->data) != 0) {
+ msg_info ("cannot load normalizer code %s", tmp->data);
+ return FALSE;
+ }
+ }
+ }
+ }
+ cur = g_list_next (cur);
+ }
/* Assign state */
cfg->lua_state = L;
@@ -430,9 +403,9 @@ init_lua_filters (struct rspamd_config *cfg)
gint
lua_call_filter (const gchar *function, struct rspamd_task *task)
{
- gint result;
- struct rspamd_task **ptask;
- lua_State *L = task->cfg->lua_state;
+ gint result;
+ struct rspamd_task **ptask;
+ lua_State *L = task->cfg->lua_state;
lua_getglobal (L, function);
ptask = lua_newuserdata (L, sizeof (struct rspamd_task *));
@@ -448,20 +421,17 @@ lua_call_filter (const gchar *function, struct rspamd_task *task)
msg_info ("function %s must return a number", function);
}
result = lua_tonumber (L, -1);
- lua_pop (L, 1); /* pop returned value */
+ lua_pop (L, 1); /* pop returned value */
return result;
}
gint
-lua_call_chain_filter (const gchar *function,
- struct rspamd_task *task,
- gint *marks,
- guint number)
+lua_call_chain_filter (const gchar *function, struct rspamd_task *task, gint *marks, guint number)
{
- gint result;
- guint i;
- lua_State *L = task->cfg->lua_state;
+ gint result;
+ guint i;
+ lua_State *L = task->cfg->lua_state;
lua_getglobal (L, function);
@@ -477,46 +447,46 @@ lua_call_chain_filter (const gchar *function,
msg_info ("function %s must return a number", function);
}
result = lua_tonumber (L, -1);
- lua_pop (L, 1); /* pop returned value */
+ lua_pop (L, 1); /* pop returned value */
return result;
}
/* Call custom lua function in rspamd expression */
-gboolean
+gboolean
lua_call_expression_func (gpointer lua_data,
- struct rspamd_task *task, GList *args, gboolean *res)
+ struct rspamd_task *task, GList *args, gboolean *res)
{
- lua_State *L = task->cfg->lua_state;
- struct rspamd_task **ptask;
- GList *cur;
- struct expression_argument *arg;
- int nargs = 1, pop = 0;
+ lua_State *L = task->cfg->lua_state;
+ struct rspamd_task **ptask;
+ GList *cur;
+ struct expression_argument *arg;
+ int nargs = 1, pop = 0;
lua_rawgeti (L, LUA_REGISTRYINDEX, GPOINTER_TO_INT (lua_data));
/* Now we got function in top of stack */
ptask = lua_newuserdata (L, sizeof (struct rspamd_task *));
lua_setclass (L, "rspamd{task}", -1);
*ptask = task;
-
+
/* Now push all arguments */
cur = args;
while (cur) {
arg = get_function_arg (cur->data, task, FALSE);
if (arg) {
switch (arg->type) {
- case EXPRESSION_ARGUMENT_NORMAL:
- lua_pushstring (L, (const gchar *)arg->data);
- break;
- case EXPRESSION_ARGUMENT_BOOL:
- lua_pushboolean (L, (gboolean) GPOINTER_TO_SIZE (arg->data));
- break;
- default:
- msg_err ("cannot pass custom params to lua function");
- return FALSE;
+ case EXPRESSION_ARGUMENT_NORMAL:
+ lua_pushstring (L, (const gchar *)arg->data);
+ break;
+ case EXPRESSION_ARGUMENT_BOOL:
+ lua_pushboolean (L, (gboolean) GPOINTER_TO_SIZE (arg->data));
+ break;
+ default:
+ msg_err ("cannot pass custom params to lua function");
+ return FALSE;
}
}
- nargs++;
+ nargs ++;
cur = g_list_next (cur);
}
@@ -524,7 +494,7 @@ lua_call_expression_func (gpointer lua_data,
msg_info ("call to lua function failed: %s", lua_tostring (L, -1));
return FALSE;
}
- pop++;
+ pop ++;
if (!lua_isboolean (L, -1)) {
lua_pop (L, pop);
@@ -542,19 +512,18 @@ lua_call_expression_func (gpointer lua_data,
* LUA custom consolidation function
*/
struct consolidation_callback_data {
- struct rspamd_task *task;
- double score;
- const gchar *func;
+ struct rspamd_task *task;
+ double score;
+ const gchar *func;
};
static void
lua_consolidation_callback (gpointer key, gpointer value, gpointer arg)
{
- double res;
- struct symbol *s = (struct symbol *)value;
- struct consolidation_callback_data *data =
- (struct consolidation_callback_data *)arg;
- lua_State *L = data->task->cfg->lua_state;
+ double res;
+ struct symbol *s = (struct symbol *)value;
+ struct consolidation_callback_data *data = (struct consolidation_callback_data *)arg;
+ lua_State *L = data->task->cfg->lua_state;
lua_getglobal (L, data->func);
@@ -569,17 +538,15 @@ lua_consolidation_callback (gpointer key, gpointer value, gpointer arg)
msg_info ("function %s must return a number", data->func);
}
res = lua_tonumber (L, -1);
- lua_pop (L, 1); /* pop returned value */
+ lua_pop (L, 1); /* pop returned value */
data->score += res;
}
double
-lua_consolidation_func (struct rspamd_task *task,
- const gchar *metric_name,
- const gchar *function_name)
+lua_consolidation_func (struct rspamd_task *task, const gchar *metric_name, const gchar *function_name)
{
- struct metric_result *metric_res;
- double res = 0.;
+ struct metric_result *metric_res;
+ double res = 0.;
struct consolidation_callback_data data = { task, 0, function_name };
if (function_name == NULL) {
@@ -591,29 +558,28 @@ lua_consolidation_func (struct rspamd_task *task,
return res;
}
- g_hash_table_foreach (metric_res->symbols, lua_consolidation_callback,
- &data);
+ g_hash_table_foreach (metric_res->symbols, lua_consolidation_callback, &data);
return data.score;
}
-double
+double
lua_normalizer_func (struct rspamd_config *cfg, long double score, void *params)
{
- GList *p = params;
- long double res = score;
- lua_State *L = cfg->lua_state;
-
- /* Call specified function and put input score on stack */
- if (!p->data) {
- msg_info ("bad function name while calling normalizer");
- return score;
- }
+ GList *p = params;
+ long double res = score;
+ lua_State *L = cfg->lua_state;
- lua_getglobal (L, p->data);
- lua_pushnumber (L, score);
+ /* Call specified function and put input score on stack */
+ if (!p->data) {
+ msg_info ("bad function name while calling normalizer");
+ return score;
+ }
- if (lua_pcall (L, 1, 1, 0) != 0) {
+ lua_getglobal (L, p->data);
+ lua_pushnumber (L, score);
+
+ if (lua_pcall (L, 1, 1, 0) != 0) {
msg_info ("call to %s failed", p->data);
}
@@ -624,16 +590,16 @@ lua_normalizer_func (struct rspamd_config *cfg, long double score, void *params)
res = lua_tonumber (L, -1);
lua_pop (L, 1);
- return res;
+ return res;
}
void
lua_dumpstack (lua_State *L)
{
- gint i, t, r = 0;
- gint top = lua_gettop (L);
- gchar buf[BUFSIZ];
+ gint i, t, r = 0;
+ gint top = lua_gettop (L);
+ gchar buf[BUFSIZ];
r += rspamd_snprintf (buf + r, sizeof (buf) - r, "lua stack: ");
for (i = 1; i <= top; i++) { /* repeat for each level */
@@ -641,29 +607,19 @@ lua_dumpstack (lua_State *L)
switch (t)
{
case LUA_TSTRING: /* strings */
- r += rspamd_snprintf (buf + r,
- sizeof (buf) - r,
- "str: %s",
- lua_tostring (L, i));
+ r += rspamd_snprintf (buf + r, sizeof (buf) - r, "str: %s", lua_tostring(L, i));
break;
case LUA_TBOOLEAN: /* booleans */
- r += rspamd_snprintf (buf + r, sizeof (buf) - r,lua_toboolean (L,
- i) ? "bool: true" : "bool: false");
+ r += rspamd_snprintf (buf + r, sizeof (buf) - r,lua_toboolean (L, i) ? "bool: true" : "bool: false");
break;
case LUA_TNUMBER: /* numbers */
- r += rspamd_snprintf (buf + r,
- sizeof (buf) - r,
- "number: %.2f",
- lua_tonumber (L, i));
+ r += rspamd_snprintf (buf + r, sizeof (buf) - r, "number: %.2f", lua_tonumber (L, i));
break;
default: /* other values */
- r += rspamd_snprintf (buf + r,
- sizeof (buf) - r,
- "type: %s",
- lua_typename (L, t));
+ r += rspamd_snprintf (buf + r, sizeof (buf) - r, "type: %s", lua_typename (L, t));
break;
}
@@ -677,7 +633,7 @@ lua_dumpstack (lua_State *L)
gpointer
lua_check_class (lua_State *L, gint index, const gchar *name)
{
- gpointer p;
+ gpointer p;
if (lua_type (L, index) == LUA_TUSERDATA) {
p = lua_touserdata (L, index);
@@ -699,6 +655,6 @@ int
rspamd_lua_typerror (lua_State *L, int narg, const char *tname)
{
const char *msg = lua_pushfstring (L, "%s expected, got %s", tname,
- luaL_typename (L, narg));
+ luaL_typename(L, narg));
return luaL_argerror (L, narg, msg);
}
diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h
index 093d27483..ca0ab6d28 100644
--- a/src/lua/lua_common.h
+++ b/src/lua/lua_common.h
@@ -4,26 +4,26 @@
#include "config.h"
#ifdef WITH_LUA
-#include "cfg_file.h"
-#include "lua_ucl.h"
#include "main.h"
+#include "cfg_file.h"
#include "ucl.h"
-#include <lauxlib.h>
+#include "lua_ucl.h"
#include <lua.h>
+#include <lauxlib.h>
#include <lualib.h>
#ifndef lua_open
-#define lua_open() luaL_newstate ()
+#define lua_open() luaL_newstate()
#endif
#ifndef luaL_reg
-#define luaL_reg luaL_Reg
+#define luaL_reg luaL_Reg
#endif
#define LUA_ENUM(L, name, val) \
- lua_pushlstring (L, # name, sizeof(# name) - 1); \
- lua_pushnumber (L, val); \
- lua_settable (L, -3);
+ lua_pushlstring(L, #name, sizeof(#name)-1); \
+ lua_pushnumber(L, val); \
+ lua_settable(L, -3);
#if LUA_VERSION_NUM > 501
static inline void
@@ -32,18 +32,17 @@ luaL_register (lua_State *L, const gchar *name, const struct luaL_reg *methods)
if (name != NULL) {
lua_newtable (L);
}
- luaL_setfuncs (L, methods, 0);
- if (name != NULL) {
- lua_pushvalue (L, -1);
- lua_setglobal (L, name);
- }
+ luaL_setfuncs (L, methods, 0);
+ if (name != NULL) {
+ lua_pushvalue (L, -1);
+ lua_setglobal (L, name);
+ }
}
#endif
/* Interface definitions */
-#define LUA_FUNCTION_DEF(class, name) static gint lua_ ## class ## _ ## name ( \
- lua_State * L)
-#define LUA_INTERFACE_DEF(class, name) { # name, lua_ ## class ## _ ## name }
+#define LUA_FUNCTION_DEF(class, name) static gint lua_##class##_##name(lua_State *L)
+#define LUA_INTERFACE_DEF(class, name) { #name, lua_##class##_##name }
extern const luaL_reg null_reg[];
@@ -60,18 +59,12 @@ struct lua_locked_state {
/**
* Create and register new class
*/
-void lua_newclass (lua_State *L,
- const gchar *classname,
- const struct luaL_reg *methods);
+void lua_newclass (lua_State *L, const gchar *classname, const struct luaL_reg *methods);
/**
* Create and register new class with static methods
*/
-void lua_newclass_full (lua_State *L,
- const gchar *classname,
- const gchar *static_name,
- const struct luaL_reg *methods,
- const struct luaL_reg *func);
+void lua_newclass_full (lua_State *L, const gchar *classname, const gchar *static_name, const struct luaL_reg *methods, const struct luaL_reg *func);
/**
* Set class name for object at @param objidx position
@@ -101,7 +94,7 @@ gpointer lua_check_class (lua_State *L, gint index, const gchar *name);
/**
* Initialize lua and bindings
*/
-lua_State * init_lua (struct rspamd_config *cfg);
+lua_State* init_lua (struct rspamd_config *cfg);
/**
* Load and initialize lua plugins
@@ -111,7 +104,7 @@ gboolean init_lua_filters (struct rspamd_config *cfg);
/**
* Initialize new locked lua_State structure
*/
-struct lua_locked_state * init_lua_locked (struct rspamd_config *cfg);
+struct lua_locked_state* init_lua_locked (struct rspamd_config *cfg);
/**
* Free locked state structure
*/
@@ -170,54 +163,29 @@ gint luaopen_rsa (lua_State * L);
gint luaopen_ip (lua_State * L);
gint lua_call_filter (const gchar *function, struct rspamd_task *task);
-gint lua_call_chain_filter (const gchar *function,
- struct rspamd_task *task,
- gint *marks,
- guint number);
-double lua_consolidation_func (struct rspamd_task *task,
- const gchar *metric_name,
- const gchar *function_name);
-gboolean lua_call_expression_func (gpointer lua_data,
- struct rspamd_task *task,
- GList *args,
- gboolean *res);
+gint lua_call_chain_filter (const gchar *function, struct rspamd_task *task, gint *marks, guint number);
+double lua_consolidation_func (struct rspamd_task *task, const gchar *metric_name, const gchar *function_name);
+gboolean lua_call_expression_func (gpointer lua_data, struct rspamd_task *task, GList *args, gboolean *res);
void lua_call_post_filters (struct rspamd_task *task);
void lua_call_pre_filters (struct rspamd_task *task);
void add_luabuf (const gchar *line);
/* Classify functions */
-GList * call_classifier_pre_callbacks (struct rspamd_classifier_config *ccf,
- struct rspamd_task *task,
- gboolean is_learn,
- gboolean is_spam,
- lua_State *L);
-double call_classifier_post_callbacks (struct rspamd_classifier_config *ccf,
- struct rspamd_task *task,
- double in,
- lua_State *L);
-
-double lua_normalizer_func (struct rspamd_config *cfg,
- long double score,
- void *params);
+GList *call_classifier_pre_callbacks (struct rspamd_classifier_config *ccf, struct rspamd_task *task, gboolean is_learn, gboolean is_spam, lua_State *L);
+double call_classifier_post_callbacks (struct rspamd_classifier_config *ccf, struct rspamd_task *task, double in, lua_State *L);
+
+double lua_normalizer_func (struct rspamd_config *cfg, long double score, void *params);
/* Config file functions */
void lua_post_load_config (struct rspamd_config *cfg);
-void lua_process_element (struct rspamd_config *cfg,
- const gchar *name,
- const gchar *module_name,
- struct rspamd_module_opt *opt,
- gint idx,
- gboolean allow_meta);
-gboolean lua_handle_param (struct rspamd_task *task,
- gchar *mname,
- gchar *optname,
- enum lua_var_type expected_type,
- gpointer *res);
-gboolean lua_check_condition (struct rspamd_config *cfg,
- const gchar *condition);
+void lua_process_element (struct rspamd_config *cfg, const gchar *name,
+ const gchar *module_name, struct rspamd_module_opt *opt, gint idx, gboolean allow_meta);
+gboolean lua_handle_param (struct rspamd_task *task, gchar *mname, gchar *optname,
+ enum lua_var_type expected_type, gpointer *res);
+gboolean lua_check_condition (struct rspamd_config *cfg, const gchar *condition);
void lua_dumpstack (lua_State *L);
-struct memory_pool_s * lua_check_mempool (lua_State * L);
+struct memory_pool_s *lua_check_mempool (lua_State * L);
#endif /* WITH_LUA */
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index e42e8af0a..162c7b842 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -23,13 +23,13 @@
*/
-#include "classifiers/classifiers.h"
-#include "expressions.h"
#include "lua_common.h"
+#include "expressions.h"
#include "map.h"
#include "message.h"
#include "radix.h"
#include "trie.h"
+#include "classifiers/classifiers.h"
/* Config file methods */
LUA_FUNCTION_DEF (config, get_module_opt);
@@ -51,7 +51,7 @@ LUA_FUNCTION_DEF (config, register_post_filter);
LUA_FUNCTION_DEF (config, register_module_option);
LUA_FUNCTION_DEF (config, get_api_version);
-static const struct luaL_reg configlib_m[] = {
+static const struct luaL_reg configlib_m[] = {
LUA_INTERFACE_DEF (config, get_module_opt),
LUA_INTERFACE_DEF (config, get_mempool),
LUA_INTERFACE_DEF (config, get_all_opt),
@@ -78,7 +78,7 @@ static const struct luaL_reg configlib_m[] = {
/* Radix tree */
LUA_FUNCTION_DEF (radix, get_key);
-static const struct luaL_reg radixlib_m[] = {
+static const struct luaL_reg radixlib_m[] = {
LUA_INTERFACE_DEF (radix, get_key),
{"__tostring", lua_class_tostring},
{NULL, NULL}
@@ -87,7 +87,7 @@ static const struct luaL_reg radixlib_m[] = {
/* Hash table */
LUA_FUNCTION_DEF (hash_table, get_key);
-static const struct luaL_reg hashlib_m[] = {
+static const struct luaL_reg hashlib_m[] = {
LUA_INTERFACE_DEF (hash_table, get_key),
{"__tostring", lua_class_tostring},
{NULL, NULL}
@@ -99,46 +99,46 @@ LUA_FUNCTION_DEF (trie, add_pattern);
LUA_FUNCTION_DEF (trie, search_text);
LUA_FUNCTION_DEF (trie, search_task);
-static const struct luaL_reg trielib_m[] = {
+static const struct luaL_reg trielib_m[] = {
LUA_INTERFACE_DEF (trie, add_pattern),
LUA_INTERFACE_DEF (trie, search_text),
LUA_INTERFACE_DEF (trie, search_task),
{"__tostring", lua_class_tostring},
{NULL, NULL}
};
-static const struct luaL_reg trielib_f[] = {
+static const struct luaL_reg trielib_f[] = {
LUA_INTERFACE_DEF (trie, create),
{NULL, NULL}
};
-static struct rspamd_config *
+static struct rspamd_config *
lua_check_config (lua_State * L)
{
- void *ud = luaL_checkudata (L, 1, "rspamd{config}");
+ void *ud = luaL_checkudata (L, 1, "rspamd{config}");
luaL_argcheck (L, ud != NULL, 1, "'config' expected");
return ud ? *((struct rspamd_config **)ud) : NULL;
}
-static radix_tree_t *
+static radix_tree_t *
lua_check_radix (lua_State * L)
{
- void *ud = luaL_checkudata (L, 1, "rspamd{radix}");
+ void *ud = luaL_checkudata (L, 1, "rspamd{radix}");
luaL_argcheck (L, ud != NULL, 1, "'radix' expected");
return ud ? **((radix_tree_t ***)ud) : NULL;
}
-static GHashTable *
+static GHashTable *
lua_check_hash_table (lua_State * L)
{
- void *ud = luaL_checkudata (L, 1, "rspamd{hash_table}");
+ void *ud = luaL_checkudata (L, 1, "rspamd{hash_table}");
luaL_argcheck (L, ud != NULL, 1, "'hash_table' expected");
return ud ? **((GHashTable ***)ud) : NULL;
}
-static rspamd_trie_t *
+static rspamd_trie_t *
lua_check_trie (lua_State * L)
{
- void *ud = luaL_checkudata (L, 1, "rspamd{trie}");
+ void *ud = luaL_checkudata (L, 1, "rspamd{trie}");
luaL_argcheck (L, ud != NULL, 1, "'trie' expected");
return ud ? *((rspamd_trie_t **)ud) : NULL;
@@ -155,9 +155,9 @@ lua_config_get_api_version (lua_State *L)
static gint
lua_config_get_module_opt (lua_State * L)
{
- struct rspamd_config *cfg = lua_check_config (L);
- const gchar *mname, *optname;
- const ucl_object_t *obj;
+ struct rspamd_config *cfg = lua_check_config (L);
+ const gchar *mname, *optname;
+ const ucl_object_t *obj;
if (cfg) {
mname = luaL_checkstring (L, 2);
@@ -177,8 +177,8 @@ lua_config_get_module_opt (lua_State * L)
static int
lua_config_get_mempool (lua_State * L)
{
- rspamd_mempool_t **ppool;
- struct rspamd_config *cfg = lua_check_config (L);
+ rspamd_mempool_t **ppool;
+ struct rspamd_config *cfg = lua_check_config (L);
if (cfg != NULL) {
ppool = lua_newuserdata (L, sizeof (rspamd_mempool_t *));
@@ -191,9 +191,9 @@ lua_config_get_mempool (lua_State * L)
static gint
lua_config_get_all_opt (lua_State * L)
{
- struct rspamd_config *cfg = lua_check_config (L);
- const gchar *mname;
- const ucl_object_t *obj;
+ struct rspamd_config *cfg = lua_check_config (L);
+ const gchar *mname;
+ const ucl_object_t *obj;
if (cfg) {
mname = luaL_checkstring (L, 2);
@@ -213,10 +213,10 @@ lua_config_get_all_opt (lua_State * L)
static gint
lua_config_get_classifier (lua_State * L)
{
- struct rspamd_config *cfg = lua_check_config (L);
- struct rspamd_classifier_config *clc = NULL, **pclc = NULL;
- const gchar *name;
- GList *cur;
+ struct rspamd_config *cfg = lua_check_config (L);
+ struct rspamd_classifier_config *clc = NULL, **pclc = NULL;
+ const gchar *name;
+ GList *cur;
if (cfg) {
name = luaL_checkstring (L, 2);
@@ -231,8 +231,7 @@ lua_config_get_classifier (lua_State * L)
cur = g_list_next (cur);
}
if (pclc) {
- pclc = lua_newuserdata (L,
- sizeof (struct rspamd_classifier_config *));
+ pclc = lua_newuserdata (L, sizeof (struct rspamd_classifier_config *));
lua_setclass (L, "rspamd{classifier}", -1);
*pclc = clc;
return 1;
@@ -246,12 +245,12 @@ lua_config_get_classifier (lua_State * L)
struct lua_callback_data {
union {
- gchar *name;
- gint ref;
+ gchar *name;
+ gint ref;
} callback;
- gboolean cb_is_ref;
- lua_State *L;
- gchar *symbol;
+ gboolean cb_is_ref;
+ lua_State *L;
+ gchar *symbol;
};
/*
@@ -260,7 +259,7 @@ struct lua_callback_data {
static void
lua_destroy_cfg_symbol (gpointer ud)
{
- struct lua_callback_data *cd = ud;
+ struct lua_callback_data *cd = ud;
/* Unref callback */
if (cd->cb_is_ref) {
@@ -269,16 +268,14 @@ lua_destroy_cfg_symbol (gpointer ud)
}
static gboolean
-lua_config_function_callback (struct rspamd_task *task,
- GList *args,
- void *user_data)
+lua_config_function_callback (struct rspamd_task *task, GList *args, void *user_data)
{
- struct lua_callback_data *cd = user_data;
- struct rspamd_task **ptask;
- gint i = 1;
- struct expression_argument *arg;
- GList *cur;
- gboolean res = FALSE;
+ struct lua_callback_data *cd = user_data;
+ struct rspamd_task **ptask;
+ gint i = 1;
+ struct expression_argument *arg;
+ GList *cur;
+ gboolean res = FALSE;
if (cd->cb_is_ref) {
lua_rawgeti (cd->L, LUA_REGISTRYINDEX, cd->callback.ref);
@@ -295,15 +292,13 @@ lua_config_function_callback (struct rspamd_task *task,
arg = get_function_arg (cur->data, task, TRUE);
lua_pushstring (cd->L, (const gchar *)arg->data);
cur = g_list_next (cur);
- i++;
+ i ++;
}
if (lua_pcall (cd->L, i, 1, 0) != 0) {
- msg_info ("error processing symbol %s: call to %s failed: %s",
- cd->symbol,
- cd->cb_is_ref ? "local function" :
- cd->callback.name,
- lua_tostring (cd->L, -1));
+ msg_info ("error processing symbol %s: call to %s failed: %s", cd->symbol,
+ cd->cb_is_ref ? "local function" :
+ cd->callback.name, lua_tostring (cd->L, -1));
}
else {
if (lua_isboolean (cd->L, 1)) {
@@ -318,19 +313,16 @@ lua_config_function_callback (struct rspamd_task *task,
static gint
lua_config_register_function (lua_State *L)
{
- struct rspamd_config *cfg = lua_check_config (L);
- gchar *name;
- struct lua_callback_data *cd;
-
+ struct rspamd_config *cfg = lua_check_config (L);
+ gchar *name;
+ struct lua_callback_data *cd;
+
if (cfg) {
name = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, 2));
- cd =
- rspamd_mempool_alloc (cfg->cfg_pool,
- sizeof (struct lua_callback_data));
+ cd = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (struct lua_callback_data));
if (lua_type (L, 3) == LUA_TSTRING) {
- cd->callback.name = rspamd_mempool_strdup (cfg->cfg_pool,
- luaL_checkstring (L, 3));
+ cd->callback.name = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, 3));
cd->cb_is_ref = FALSE;
}
else {
@@ -342,12 +334,9 @@ lua_config_register_function (lua_State *L)
if (name) {
cd->L = L;
cd->symbol = name;
- register_expression_function (name, lua_config_function_callback,
- cd);
+ register_expression_function (name, lua_config_function_callback, cd);
}
- rspamd_mempool_add_destructor (cfg->cfg_pool,
- (rspamd_mempool_destruct_t)lua_destroy_cfg_symbol,
- cd);
+ rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t)lua_destroy_cfg_symbol, cd);
}
return 1;
}
@@ -361,9 +350,9 @@ lua_config_register_module_option (lua_State *L)
void
lua_call_post_filters (struct rspamd_task *task)
{
- struct lua_callback_data *cd;
- struct rspamd_task **ptask;
- GList *cur;
+ struct lua_callback_data *cd;
+ struct rspamd_task **ptask;
+ GList *cur;
cur = task->cfg->post_filters;
while (cur) {
@@ -379,10 +368,8 @@ lua_call_post_filters (struct rspamd_task *task)
*ptask = task;
if (lua_pcall (cd->L, 1, 0, 0) != 0) {
- msg_info ("call to %s failed: %s",
- cd->cb_is_ref ? "local function" :
- cd->callback.name,
- lua_tostring (cd->L, -1));
+ msg_info ("call to %s failed: %s", cd->cb_is_ref ? "local function" :
+ cd->callback.name, lua_tostring (cd->L, -1));
}
cur = g_list_next (cur);
}
@@ -391,16 +378,13 @@ lua_call_post_filters (struct rspamd_task *task)
static gint
lua_config_register_post_filter (lua_State *L)
{
- struct rspamd_config *cfg = lua_check_config (L);
- struct lua_callback_data *cd;
+ struct rspamd_config *cfg = lua_check_config (L);
+ struct lua_callback_data *cd;
if (cfg) {
- cd =
- rspamd_mempool_alloc (cfg->cfg_pool,
- sizeof (struct lua_callback_data));
+ cd = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (struct lua_callback_data));
if (lua_type (L, 2) == LUA_TSTRING) {
- cd->callback.name = rspamd_mempool_strdup (cfg->cfg_pool,
- luaL_checkstring (L, 2));
+ cd->callback.name = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, 2));
cd->cb_is_ref = FALSE;
}
else {
@@ -411,9 +395,7 @@ lua_config_register_post_filter (lua_State *L)
}
cd->L = L;
cfg->post_filters = g_list_prepend (cfg->post_filters, cd);
- rspamd_mempool_add_destructor (cfg->cfg_pool,
- (rspamd_mempool_destruct_t)lua_destroy_cfg_symbol,
- cd);
+ rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t)lua_destroy_cfg_symbol, cd);
}
return 1;
}
@@ -421,9 +403,9 @@ lua_config_register_post_filter (lua_State *L)
void
lua_call_pre_filters (struct rspamd_task *task)
{
- struct lua_callback_data *cd;
- struct rspamd_task **ptask;
- GList *cur;
+ struct lua_callback_data *cd;
+ struct rspamd_task **ptask;
+ GList *cur;
cur = task->cfg->pre_filters;
while (cur) {
@@ -439,10 +421,8 @@ lua_call_pre_filters (struct rspamd_task *task)
*ptask = task;
if (lua_pcall (cd->L, 1, 0, 0) != 0) {
- msg_info ("call to %s failed: %s",
- cd->cb_is_ref ? "local function" :
- cd->callback.name,
- lua_tostring (cd->L, -1));
+ msg_info ("call to %s failed: %s", cd->cb_is_ref ? "local function" :
+ cd->callback.name, lua_tostring (cd->L, -1));
}
cur = g_list_next (cur);
}
@@ -451,16 +431,13 @@ lua_call_pre_filters (struct rspamd_task *task)
static gint
lua_config_register_pre_filter (lua_State *L)
{
- struct rspamd_config *cfg = lua_check_config (L);
- struct lua_callback_data *cd;
+ struct rspamd_config *cfg = lua_check_config (L);
+ struct lua_callback_data *cd;
if (cfg) {
- cd =
- rspamd_mempool_alloc (cfg->cfg_pool,
- sizeof (struct lua_callback_data));
+ cd = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (struct lua_callback_data));
if (lua_type (L, 2) == LUA_TSTRING) {
- cd->callback.name = rspamd_mempool_strdup (cfg->cfg_pool,
- luaL_checkstring (L, 2));
+ cd->callback.name = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, 2));
cd->cb_is_ref = FALSE;
}
else {
@@ -471,9 +448,7 @@ lua_config_register_pre_filter (lua_State *L)
}
cd->L = L;
cfg->pre_filters = g_list_prepend (cfg->pre_filters, cd);
- rspamd_mempool_add_destructor (cfg->cfg_pool,
- (rspamd_mempool_destruct_t)lua_destroy_cfg_symbol,
- cd);
+ rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t)lua_destroy_cfg_symbol, cd);
}
return 1;
}
@@ -481,17 +456,16 @@ lua_config_register_pre_filter (lua_State *L)
static gint
lua_config_add_radix_map (lua_State *L)
{
- struct rspamd_config *cfg = lua_check_config (L);
- const gchar *map_line, *description;
- radix_tree_t **r, ***ud;
+ struct rspamd_config *cfg = lua_check_config (L);
+ const gchar *map_line, *description;
+ radix_tree_t **r, ***ud;
if (cfg) {
map_line = luaL_checkstring (L, 2);
description = lua_tostring (L, 3);
r = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (radix_tree_t *));
*r = radix_tree_create ();
- if (!add_map (cfg, map_line, description, read_radix_list,
- fin_radix_list, (void **)r)) {
+ if (!add_map (cfg, map_line, description, read_radix_list, fin_radix_list, (void **)r)) {
msg_warn ("invalid radix map %s", map_line);
radix_tree_free (*r);
lua_pushnil (L);
@@ -512,25 +486,22 @@ lua_config_add_radix_map (lua_State *L)
static gint
lua_config_add_hash_map (lua_State *L)
{
- struct rspamd_config *cfg = lua_check_config (L);
- const gchar *map_line, *description;
- GHashTable **r, ***ud;
+ struct rspamd_config *cfg = lua_check_config (L);
+ const gchar *map_line, *description;
+ GHashTable **r, ***ud;
if (cfg) {
map_line = luaL_checkstring (L, 2);
description = lua_tostring (L, 3);
r = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (GHashTable *));
*r = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal);
- if (!add_map (cfg, map_line, description, read_host_list, fin_host_list,
- (void **)r)) {
+ if (!add_map (cfg, map_line, description, read_host_list, fin_host_list, (void **)r)) {
msg_warn ("invalid hash map %s", map_line);
g_hash_table_destroy (*r);
lua_pushnil (L);
return 1;
}
- rspamd_mempool_add_destructor (cfg->cfg_pool,
- (rspamd_mempool_destruct_t)g_hash_table_destroy,
- *r);
+ rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t)g_hash_table_destroy, *r);
ud = lua_newuserdata (L, sizeof (GHashTable *));
*ud = r;
lua_setclass (L, "rspamd{hash_table}", -1);
@@ -546,25 +517,22 @@ lua_config_add_hash_map (lua_State *L)
static gint
lua_config_add_kv_map (lua_State *L)
{
- struct rspamd_config *cfg = lua_check_config (L);
- const gchar *map_line, *description;
- GHashTable **r, ***ud;
+ struct rspamd_config *cfg = lua_check_config (L);
+ const gchar *map_line, *description;
+ GHashTable **r, ***ud;
if (cfg) {
map_line = luaL_checkstring (L, 2);
description = lua_tostring (L, 3);
r = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (GHashTable *));
*r = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal);
- if (!add_map (cfg, map_line, description, read_kv_list, fin_kv_list,
- (void **)r)) {
+ if (!add_map (cfg, map_line, description, read_kv_list, fin_kv_list, (void **)r)) {
msg_warn ("invalid hash map %s", map_line);
g_hash_table_destroy (*r);
lua_pushnil (L);
return 1;
}
- rspamd_mempool_add_destructor (cfg->cfg_pool,
- (rspamd_mempool_destruct_t)g_hash_table_destroy,
- *r);
+ rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t)g_hash_table_destroy, *r);
ud = lua_newuserdata (L, sizeof (GHashTable *));
*ud = r;
lua_setclass (L, "rspamd{hash_table}", -1);
@@ -585,7 +553,7 @@ struct lua_map_callback_data {
static gchar *
lua_map_read (rspamd_mempool_t *pool, gchar *chunk, gint len,
- struct map_cb_data *data)
+ struct map_cb_data *data)
{
struct lua_map_callback_data *cbdata, *old;
@@ -637,7 +605,7 @@ lua_map_fin (rspamd_mempool_t * pool, struct map_cb_data *data)
if (lua_pcall (cbdata->L, 1, 0, 0) != 0) {
msg_info ("call to %s failed: %s", "local function",
- lua_tostring (cbdata->L, -1));
+ lua_tostring (cbdata->L, -1));
}
}
}
@@ -645,9 +613,9 @@ lua_map_fin (rspamd_mempool_t * pool, struct map_cb_data *data)
static gint
lua_config_add_map (lua_State *L)
{
- struct rspamd_config *cfg = lua_check_config (L);
- const gchar *map_line, *description;
- struct lua_map_callback_data *cbdata, **pcbdata;
+ struct rspamd_config *cfg = lua_check_config (L);
+ const gchar *map_line, *description;
+ struct lua_map_callback_data *cbdata, **pcbdata;
if (cfg) {
map_line = luaL_checkstring (L, 2);
@@ -663,7 +631,7 @@ lua_config_add_map (lua_State *L)
pcbdata = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (cbdata));
*pcbdata = cbdata;
if (!add_map (cfg, map_line, description, lua_map_read, lua_map_fin,
- (void **)pcbdata)) {
+ (void **)pcbdata)) {
msg_warn ("invalid hash map %s", map_line);
lua_pushboolean (L, false);
}
@@ -689,8 +657,8 @@ lua_config_add_map (lua_State *L)
static void
lua_metric_symbol_callback (struct rspamd_task *task, gpointer ud)
{
- struct lua_callback_data *cd = ud;
- struct rspamd_task **ptask;
+ struct lua_callback_data *cd = ud;
+ struct rspamd_task **ptask;
if (cd->cb_is_ref) {
lua_rawgeti (cd->L, LUA_REGISTRYINDEX, cd->callback.ref);
@@ -704,27 +672,24 @@ lua_metric_symbol_callback (struct rspamd_task *task, gpointer ud)
if (lua_pcall (cd->L, 1, 0, 0) != 0) {
msg_info ("call to %s failed: %s", cd->cb_is_ref ? "local function" :
- cd->callback.name, lua_tostring (cd->L, -1));
+ cd->callback.name, lua_tostring (cd->L, -1));
}
}
static gint
lua_config_register_symbol (lua_State * L)
{
- struct rspamd_config *cfg = lua_check_config (L);
- gchar *name;
- double weight;
- struct lua_callback_data *cd;
+ struct rspamd_config *cfg = lua_check_config (L);
+ gchar *name;
+ double weight;
+ struct lua_callback_data *cd;
if (cfg) {
name = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, 2));
weight = luaL_checknumber (L, 3);
- cd =
- rspamd_mempool_alloc (cfg->cfg_pool,
- sizeof (struct lua_callback_data));
+ cd = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (struct lua_callback_data));
if (lua_type (L, 4) == LUA_TSTRING) {
- cd->callback.name = rspamd_mempool_strdup (cfg->cfg_pool,
- luaL_checkstring (L, 4));
+ cd->callback.name = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, 4));
cd->cb_is_ref = FALSE;
}
else {
@@ -736,15 +701,9 @@ lua_config_register_symbol (lua_State * L)
if (name) {
cd->symbol = name;
cd->L = L;
- register_symbol (&cfg->cache,
- name,
- weight,
- lua_metric_symbol_callback,
- cd);
+ register_symbol (&cfg->cache, name, weight, lua_metric_symbol_callback, cd);
}
- rspamd_mempool_add_destructor (cfg->cfg_pool,
- (rspamd_mempool_destruct_t)lua_destroy_cfg_symbol,
- cd);
+ rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t)lua_destroy_cfg_symbol, cd);
}
return 0;
}
@@ -752,23 +711,20 @@ lua_config_register_symbol (lua_State * L)
static gint
lua_config_register_symbols (lua_State *L)
{
- struct rspamd_config *cfg = lua_check_config (L);
- struct lua_callback_data *cd;
- gint i, top;
- gchar *sym;
- gdouble weight = 1.0;
+ struct rspamd_config *cfg = lua_check_config (L);
+ struct lua_callback_data *cd;
+ gint i, top;
+ gchar *sym;
+ gdouble weight = 1.0;
if (lua_gettop (L) < 3) {
msg_err ("not enough arguments to register a function");
return 0;
}
if (cfg) {
- cd =
- rspamd_mempool_alloc (cfg->cfg_pool,
- sizeof (struct lua_callback_data));
+ cd = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (struct lua_callback_data));
if (lua_type (L, 2) == LUA_TSTRING) {
- cd->callback.name = rspamd_mempool_strdup (cfg->cfg_pool,
- luaL_checkstring (L, 2));
+ cd->callback.name = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, 2));
cd->cb_is_ref = FALSE;
}
else {
@@ -787,15 +743,9 @@ lua_config_register_symbols (lua_State *L)
sym = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, top));
cd->symbol = sym;
cd->L = L;
- register_symbol (&cfg->cache,
- sym,
- weight,
- lua_metric_symbol_callback,
- cd);
- for (i = top; i < lua_gettop (L); i++) {
- sym =
- rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L,
- i + 1));
+ register_symbol (&cfg->cache, sym, weight, lua_metric_symbol_callback, cd);
+ for (i = top; i < lua_gettop (L); i ++) {
+ sym = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, i + 1));
register_virtual_symbol (&cfg->cache, sym, weight);
}
}
@@ -806,9 +756,9 @@ lua_config_register_symbols (lua_State *L)
static gint
lua_config_register_virtual_symbol (lua_State * L)
{
- struct rspamd_config *cfg = lua_check_config (L);
- gchar *name;
- double weight;
+ struct rspamd_config *cfg = lua_check_config (L);
+ gchar *name;
+ double weight;
if (cfg) {
name = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, 2));
@@ -823,20 +773,17 @@ lua_config_register_virtual_symbol (lua_State * L)
static gint
lua_config_register_callback_symbol (lua_State * L)
{
- struct rspamd_config *cfg = lua_check_config (L);
- gchar *name;
- double weight;
- struct lua_callback_data *cd;
+ struct rspamd_config *cfg = lua_check_config (L);
+ gchar *name;
+ double weight;
+ struct lua_callback_data *cd;
if (cfg) {
name = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, 2));
weight = luaL_checknumber (L, 3);
- cd =
- rspamd_mempool_alloc (cfg->cfg_pool,
- sizeof (struct lua_callback_data));
+ cd = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (struct lua_callback_data));
if (lua_type (L, 4) == LUA_TSTRING) {
- cd->callback.name = rspamd_mempool_strdup (cfg->cfg_pool,
- luaL_checkstring (L, 4));
+ cd->callback.name = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, 4));
cd->cb_is_ref = FALSE;
}
else {
@@ -848,15 +795,9 @@ lua_config_register_callback_symbol (lua_State * L)
if (name) {
cd->symbol = name;
cd->L = L;
- register_callback_symbol (&cfg->cache,
- name,
- weight,
- lua_metric_symbol_callback,
- cd);
+ register_callback_symbol (&cfg->cache, name, weight, lua_metric_symbol_callback, cd);
}
- rspamd_mempool_add_destructor (cfg->cfg_pool,
- (rspamd_mempool_destruct_t)lua_destroy_cfg_symbol,
- cd);
+ rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t)lua_destroy_cfg_symbol, cd);
}
return 0;
}
@@ -864,22 +805,19 @@ lua_config_register_callback_symbol (lua_State * L)
static gint
lua_config_register_callback_symbol_priority (lua_State * L)
{
- struct rspamd_config *cfg = lua_check_config (L);
- gchar *name;
- double weight;
- gint priority;
- struct lua_callback_data *cd;
+ struct rspamd_config *cfg = lua_check_config (L);
+ gchar *name;
+ double weight;
+ gint priority;
+ struct lua_callback_data *cd;
if (cfg) {
name = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, 2));
weight = luaL_checknumber (L, 3);
priority = luaL_checknumber (L, 4);
- cd =
- rspamd_mempool_alloc (cfg->cfg_pool,
- sizeof (struct lua_callback_data));
+ cd = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (struct lua_callback_data));
if (lua_type (L, 5) == LUA_TSTRING) {
- cd->callback.name = rspamd_mempool_strdup (cfg->cfg_pool,
- luaL_checkstring (L, 5));
+ cd->callback.name = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, 5));
cd->cb_is_ref = FALSE;
}
else {
@@ -892,16 +830,9 @@ lua_config_register_callback_symbol_priority (lua_State * L)
if (name) {
cd->L = L;
cd->symbol = name;
- register_callback_symbol_priority (&cfg->cache,
- name,
- weight,
- priority,
- lua_metric_symbol_callback,
- cd);
+ register_callback_symbol_priority (&cfg->cache, name, weight, priority, lua_metric_symbol_callback, cd);
}
- rspamd_mempool_add_destructor (cfg->cfg_pool,
- (rspamd_mempool_destruct_t)lua_destroy_cfg_symbol,
- cd);
+ rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t)lua_destroy_cfg_symbol, cd);
}
return 0;
@@ -912,8 +843,8 @@ lua_config_register_callback_symbol_priority (lua_State * L)
static gint
lua_radix_get_key (lua_State * L)
{
- radix_tree_t *radix = lua_check_radix (L);
- guint32 key;
+ radix_tree_t *radix = lua_check_radix (L);
+ guint32 key;
if (radix) {
key = luaL_checkint (L, 2);
@@ -931,8 +862,8 @@ lua_radix_get_key (lua_State * L)
static gint
lua_hash_table_get_key (lua_State * L)
{
- GHashTable *tbl = lua_check_hash_table (L);
- const gchar *key, *value;
+ GHashTable *tbl = lua_check_hash_table (L);
+ const gchar *key, *value;
if (tbl) {
key = luaL_checkstring (L, 2);
@@ -951,8 +882,8 @@ lua_hash_table_get_key (lua_State * L)
static gint
lua_trie_create (lua_State *L)
{
- rspamd_trie_t *trie, **ptrie;
- gboolean icase = FALSE;
+ rspamd_trie_t *trie, **ptrie;
+ gboolean icase = FALSE;
if (lua_gettop (L) == 1) {
icase = lua_toboolean (L, 1);
@@ -970,12 +901,12 @@ lua_trie_create (lua_State *L)
static gint
lua_trie_add_pattern (lua_State *L)
{
- rspamd_trie_t *trie = lua_check_trie (L);
- const gchar *pattern;
- gint id;
+ rspamd_trie_t *trie = lua_check_trie (L);
+ const gchar *pattern;
+ gint id;
if (trie) {
- pattern = luaL_checkstring (L, 2);
+ pattern = luaL_checkstring (L, 2);
id = luaL_checknumber (L, 3);
if (pattern != NULL) {
@@ -992,11 +923,11 @@ lua_trie_add_pattern (lua_State *L)
static gint
lua_trie_search_text (lua_State *L)
{
- rspamd_trie_t *trie = lua_check_trie (L);
- const gchar *text, *pos;
- gint id, i = 1;
- gsize len;
- gboolean found = FALSE;
+ rspamd_trie_t *trie = lua_check_trie (L);
+ const gchar *text, *pos;
+ gint id, i = 1;
+ gsize len;
+ gboolean found = FALSE;
if (trie) {
text = luaL_checkstring (L, 2);
@@ -1004,12 +935,11 @@ lua_trie_search_text (lua_State *L)
if (text) {
lua_newtable (L);
pos = text;
- while (pos < text + len &&
- (pos = rspamd_trie_lookup (trie, pos, len, &id)) != NULL) {
+ while (pos < text + len && (pos = rspamd_trie_lookup (trie, pos, len, &id)) != NULL) {
lua_pushinteger (L, i);
lua_pushinteger (L, id);
lua_settable (L, -3);
- i++;
+ i ++;
found = TRUE;
break;
}
@@ -1028,14 +958,14 @@ lua_trie_search_text (lua_State *L)
static gint
lua_trie_search_task (lua_State *L)
{
- rspamd_trie_t *trie = lua_check_trie (L);
- struct rspamd_task *task;
- struct mime_text_part *part;
- GList *cur;
- const gchar *pos, *end;
- gint id, i = 1;
- void *ud;
- gboolean found = FALSE;
+ rspamd_trie_t *trie = lua_check_trie (L);
+ struct rspamd_task *task;
+ struct mime_text_part *part;
+ GList *cur;
+ const gchar *pos, *end;
+ gint id, i = 1;
+ void *ud;
+ gboolean found = FALSE;
if (trie) {
ud = luaL_checkudata (L, 2, "rspamd{task}");
@@ -1049,14 +979,11 @@ lua_trie_search_task (lua_State *L)
if (!part->is_empty && part->content != NULL) {
pos = (const gchar *)part->content->data;
end = pos + part->content->len;
- while (pos < end &&
- (pos =
- rspamd_trie_lookup (trie, pos, part->content->len,
- &id)) != NULL) {
+ while (pos < end && (pos = rspamd_trie_lookup (trie, pos, part->content->len, &id)) != NULL) {
lua_pushinteger (L, i);
lua_pushinteger (L, id);
lua_settable (L, -3);
- i++;
+ i ++;
found = TRUE;
break;
}
@@ -1122,7 +1049,7 @@ luaopen_trie (lua_State * L)
lua_pushstring (L, "rspamd{trie}");
lua_rawset (L, -3);
- luaL_register (L, NULL, trielib_m);
+ luaL_register (L, NULL, trielib_m);
luaL_register (L, "rspamd_trie", trielib_f);
lua_pop (L, 1); /* remove metatable from stack */
diff --git a/src/lua/lua_dns.c b/src/lua/lua_dns.c
index 0e7857f42..49ed205da 100644
--- a/src/lua/lua_dns.c
+++ b/src/lua/lua_dns.c
@@ -21,11 +21,11 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "dns.h"
#include "lua_common.h"
+#include "dns.h"
/* Public prototypes */
-struct rspamd_dns_resolver * lua_check_dns_resolver (lua_State * L);
+struct rspamd_dns_resolver *lua_check_dns_resolver (lua_State * L);
gint luaopen_dns_resolver (lua_State * L);
/* Lua bindings */
@@ -36,12 +36,12 @@ LUA_FUNCTION_DEF (dns_resolver, resolve_txt);
LUA_FUNCTION_DEF (dns_resolver, resolve_mx);
LUA_FUNCTION_DEF (dns_resolver, resolve);
-static const struct luaL_reg dns_resolverlib_f[] = {
+static const struct luaL_reg dns_resolverlib_f[] = {
LUA_INTERFACE_DEF (dns_resolver, init),
{NULL, NULL}
};
-static const struct luaL_reg dns_resolverlib_m[] = {
+static const struct luaL_reg dns_resolverlib_m[] = {
LUA_INTERFACE_DEF (dns_resolver, resolve_a),
LUA_INTERFACE_DEF (dns_resolver, resolve_ptr),
LUA_INTERFACE_DEF (dns_resolver, resolve_txt),
@@ -51,20 +51,20 @@ static const struct luaL_reg dns_resolverlib_m[] = {
{NULL, NULL}
};
-struct rspamd_dns_resolver *
+struct rspamd_dns_resolver *
lua_check_dns_resolver (lua_State * L)
{
- void *ud = luaL_checkudata (L, 1, "rspamd{resolver}");
+ void *ud = luaL_checkudata (L, 1, "rspamd{resolver}");
luaL_argcheck (L, ud != NULL, 1, "'resolver' expected");
return ud ? *((struct rspamd_dns_resolver **)ud) : NULL;
}
struct lua_dns_cbdata {
- lua_State *L;
- struct rspamd_dns_resolver *resolver;
- gint cbref;
- const gchar *to_resolve;
- const gchar *user_str;
+ lua_State *L;
+ struct rspamd_dns_resolver *resolver;
+ gint cbref;
+ const gchar *to_resolve;
+ const gchar *user_str;
};
static int
@@ -86,11 +86,11 @@ lua_dns_get_type (lua_State *L, int argno)
static void
lua_dns_callback (struct rdns_reply *reply, gpointer arg)
{
- struct lua_dns_cbdata *cd = arg;
- gint i = 0;
- struct rspamd_dns_resolver **presolver;
- struct rdns_reply_entry *elt;
- rspamd_inet_addr_t addr;
+ struct lua_dns_cbdata *cd = arg;
+ gint i = 0;
+ struct rspamd_dns_resolver **presolver;
+ struct rdns_reply_entry *elt;
+ rspamd_inet_addr_t addr;
lua_rawgeti (cd->L, LUA_REGISTRYINDEX, cd->cbref);
presolver = lua_newuserdata (cd->L, sizeof (gpointer));
@@ -104,14 +104,13 @@ lua_dns_callback (struct rdns_reply *reply, gpointer arg)
*/
if (reply->code == RDNS_RC_NOERROR) {
lua_newtable (cd->L);
- LL_FOREACH (reply->entries, elt)
- {
+ LL_FOREACH (reply->entries, elt) {
switch (elt->type) {
case RDNS_REQUEST_A:
addr.af = AF_INET;
addr.slen = sizeof (addr.addr.s4);
memcpy (&addr.addr.s4.sin_addr, &elt->content.a.addr,
- sizeof (addr.addr.s4.sin_addr));
+ sizeof (addr.addr.s4.sin_addr));
lua_ip_push (cd->L, &addr);
lua_rawseti (cd->L, -2, ++i);
break;
@@ -119,7 +118,7 @@ lua_dns_callback (struct rdns_reply *reply, gpointer arg)
addr.af = AF_INET6;
addr.slen = sizeof (addr.addr.s6);
memcpy (&addr.addr.s6.sin6_addr, &elt->content.aaa.addr,
- sizeof (addr.addr.s6.sin6_addr));
+ sizeof (addr.addr.s6.sin6_addr));
lua_ip_push (cd->L, &addr);
lua_rawseti (cd->L, -2, ++i);
break;
@@ -169,16 +168,16 @@ lua_dns_callback (struct rdns_reply *reply, gpointer arg)
static int
lua_dns_resolver_init (lua_State *L)
{
- struct rspamd_dns_resolver *resolver, **presolver;
- struct rspamd_config *cfg, **pcfg;
- struct event_base *base, **pbase;
+ struct rspamd_dns_resolver *resolver, **presolver;
+ struct rspamd_config *cfg, **pcfg;
+ struct event_base *base, **pbase;
/* Check args */
pbase = luaL_checkudata (L, 1, "rspamd{ev_base}");
luaL_argcheck (L, pbase != NULL, 1, "'ev_base' expected");
base = pbase ? *(pbase) : NULL;
pcfg = luaL_checkudata (L, 2, "rspamd{config}");
- luaL_argcheck (L, pcfg != NULL, 2, "'config' expected");
+ luaL_argcheck (L, pcfg != NULL, 2, "'config' expected");
cfg = pcfg ? *(pcfg) : NULL;
if (base != NULL && cfg != NULL) {
@@ -200,27 +199,24 @@ lua_dns_resolver_init (lua_State *L)
}
static int
-lua_dns_resolver_resolve_common (lua_State *L,
- struct rspamd_dns_resolver *resolver,
- enum rdns_request_type type,
- int first)
+lua_dns_resolver_resolve_common (lua_State *L, struct rspamd_dns_resolver *resolver,
+ enum rdns_request_type type, int first)
{
- struct rspamd_async_session *session, **psession;
- rspamd_mempool_t *pool, **ppool;
- const gchar *to_resolve;
- struct lua_dns_cbdata *cbdata;
+ struct rspamd_async_session *session, **psession;
+ rspamd_mempool_t *pool, **ppool;
+ const gchar *to_resolve;
+ struct lua_dns_cbdata *cbdata;
/* Check arguments */
psession = luaL_checkudata (L, first, "rspamd{session}");
- luaL_argcheck (L, psession != NULL, first, "'session' expected");
+ luaL_argcheck (L, psession != NULL, first, "'session' expected");
session = psession ? *(psession) : NULL;
ppool = luaL_checkudata (L, first + 1, "rspamd{mempool}");
- luaL_argcheck (L, ppool != NULL, first + 1, "'mempool' expected");
+ luaL_argcheck (L, ppool != NULL, first + 1, "'mempool' expected");
pool = ppool ? *(ppool) : NULL;
to_resolve = luaL_checkstring (L, first + 2);
- if (pool != NULL && session != NULL && to_resolve != NULL &&
- lua_isfunction (L, first + 3)) {
+ if (pool != NULL && session != NULL && to_resolve != NULL && lua_isfunction (L, first + 3)) {
cbdata = rspamd_mempool_alloc (pool, sizeof (struct lua_dns_cbdata));
cbdata->L = L;
cbdata->resolver = resolver;
@@ -247,13 +243,7 @@ lua_dns_resolver_resolve_common (lua_State *L,
else {
cbdata->user_str = NULL;
}
- make_dns_request (resolver,
- session,
- pool,
- lua_dns_callback,
- cbdata,
- type,
- to_resolve);
+ make_dns_request (resolver, session, pool, lua_dns_callback, cbdata, type, to_resolve);
lua_pushboolean (L, TRUE);
}
else {
@@ -268,13 +258,10 @@ lua_dns_resolver_resolve_common (lua_State *L,
static int
lua_dns_resolver_resolve_a (lua_State *L)
{
- struct rspamd_dns_resolver *dns_resolver = lua_check_dns_resolver (L);
+ struct rspamd_dns_resolver *dns_resolver = lua_check_dns_resolver (L);
if (dns_resolver) {
- return lua_dns_resolver_resolve_common (L,
- dns_resolver,
- RDNS_REQUEST_A,
- 2);
+ return lua_dns_resolver_resolve_common (L, dns_resolver, RDNS_REQUEST_A, 2);
}
else {
lua_pushnil (L);
@@ -286,13 +273,10 @@ lua_dns_resolver_resolve_a (lua_State *L)
static int
lua_dns_resolver_resolve_ptr (lua_State *L)
{
- struct rspamd_dns_resolver *dns_resolver = lua_check_dns_resolver (L);
+ struct rspamd_dns_resolver *dns_resolver = lua_check_dns_resolver (L);
if (dns_resolver) {
- return lua_dns_resolver_resolve_common (L,
- dns_resolver,
- RDNS_REQUEST_PTR,
- 2);
+ return lua_dns_resolver_resolve_common (L, dns_resolver, RDNS_REQUEST_PTR, 2);
}
else {
lua_pushnil (L);
@@ -304,13 +288,10 @@ lua_dns_resolver_resolve_ptr (lua_State *L)
static int
lua_dns_resolver_resolve_txt (lua_State *L)
{
- struct rspamd_dns_resolver *dns_resolver = lua_check_dns_resolver (L);
+ struct rspamd_dns_resolver *dns_resolver = lua_check_dns_resolver (L);
if (dns_resolver) {
- return lua_dns_resolver_resolve_common (L,
- dns_resolver,
- RDNS_REQUEST_TXT,
- 2);
+ return lua_dns_resolver_resolve_common (L, dns_resolver, RDNS_REQUEST_TXT, 2);
}
else {
lua_pushnil (L);
@@ -322,13 +303,10 @@ lua_dns_resolver_resolve_txt (lua_State *L)
static int
lua_dns_resolver_resolve_mx (lua_State *L)
{
- struct rspamd_dns_resolver *dns_resolver = lua_check_dns_resolver (L);
+ struct rspamd_dns_resolver *dns_resolver = lua_check_dns_resolver (L);
if (dns_resolver) {
- return lua_dns_resolver_resolve_common (L,
- dns_resolver,
- RDNS_REQUEST_MX,
- 2);
+ return lua_dns_resolver_resolve_common (L, dns_resolver, RDNS_REQUEST_MX, 2);
}
else {
lua_pushnil (L);
@@ -340,7 +318,7 @@ lua_dns_resolver_resolve_mx (lua_State *L)
static int
lua_dns_resolver_resolve (lua_State *L)
{
- struct rspamd_dns_resolver *dns_resolver = lua_check_dns_resolver (L);
+ struct rspamd_dns_resolver *dns_resolver = lua_check_dns_resolver (L);
int type;
type = lua_dns_get_type (L, 2);
@@ -369,18 +347,18 @@ luaopen_dns_resolver (lua_State * L)
lua_rawset (L, -3);
{
- LUA_ENUM (L, RDNS_REQUEST_A, RDNS_REQUEST_A);
- LUA_ENUM (L, RDNS_REQUEST_PTR, RDNS_REQUEST_PTR);
- LUA_ENUM (L, RDNS_REQUEST_MX, RDNS_REQUEST_MX);
- LUA_ENUM (L, RDNS_REQUEST_TXT, RDNS_REQUEST_TXT);
- LUA_ENUM (L, RDNS_REQUEST_SRV, RDNS_REQUEST_SRV);
- LUA_ENUM (L, RDNS_REQUEST_SPF, RDNS_REQUEST_SRV);
- LUA_ENUM (L, RDNS_REQUEST_AAA, RDNS_REQUEST_SRV);
+ LUA_ENUM(L, RDNS_REQUEST_A, RDNS_REQUEST_A);
+ LUA_ENUM(L, RDNS_REQUEST_PTR, RDNS_REQUEST_PTR);
+ LUA_ENUM(L, RDNS_REQUEST_MX, RDNS_REQUEST_MX);
+ LUA_ENUM(L, RDNS_REQUEST_TXT, RDNS_REQUEST_TXT);
+ LUA_ENUM(L, RDNS_REQUEST_SRV, RDNS_REQUEST_SRV);
+ LUA_ENUM(L, RDNS_REQUEST_SPF, RDNS_REQUEST_SRV);
+ LUA_ENUM(L, RDNS_REQUEST_AAA, RDNS_REQUEST_SRV);
}
- luaL_register (L, NULL, dns_resolverlib_m);
+ luaL_register (L, NULL, dns_resolverlib_m);
luaL_register (L, "rspamd_resolver", dns_resolverlib_f);
lua_pop (L, 1); /* remove metatable from stack */
- return 1;
+ return 1;
}
diff --git a/src/lua/lua_http.c b/src/lua/lua_http.c
index 6d6201f03..60253c000 100644
--- a/src/lua/lua_http.c
+++ b/src/lua/lua_http.c
@@ -21,17 +21,17 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include "lua_common.h"
#include "buffer.h"
#include "dns.h"
#include "http.h"
-#include "lua_common.h"
#define MAX_HEADERS_SIZE 8192
LUA_FUNCTION_DEF (http, make_post_request);
LUA_FUNCTION_DEF (http, make_get_request);
-static const struct luaL_reg httplib_m[] = {
+static const struct luaL_reg httplib_m[] = {
LUA_INTERFACE_DEF (http, make_post_request),
LUA_INTERFACE_DEF (http, make_get_request),
{"__tostring", lua_class_tostring},
@@ -68,7 +68,7 @@ struct lua_http_ud {
static void
lua_http_fin (void *arg)
{
- struct lua_http_ud *ud = arg;
+ struct lua_http_ud *ud = arg;
if (ud->callback == NULL) {
/* Unref callback */
@@ -81,8 +81,8 @@ lua_http_fin (void *arg)
static void
lua_http_push_error (gint code, struct lua_http_ud *ud)
{
- struct rspamd_task **ptask;
- gint num;
+ struct rspamd_task **ptask;
+ gint num;
/* Push error */
if (ud->callback) {
@@ -104,9 +104,7 @@ lua_http_push_error (gint code, struct lua_http_ud *ud)
/* Reply */
lua_pushnil (ud->L);
if (lua_pcall (ud->L, num, 0, 0) != 0) {
- msg_info ("call to %s failed: %s",
- ud->callback ? ud->callback : "local function",
- lua_tostring (ud->L, -1));
+ msg_info ("call to %s failed: %s", ud->callback ? ud->callback : "local function", lua_tostring (ud->L, -1));
}
if (ud->headers != NULL) {
@@ -122,10 +120,10 @@ lua_http_push_error (gint code, struct lua_http_ud *ud)
static void
lua_http_push_reply (f_str_t *in, struct lua_http_ud *ud)
{
- GList *cur;
- struct lua_http_header *header;
- struct rspamd_task **ptask;
- gint num;
+ GList *cur;
+ struct lua_http_header *header;
+ struct rspamd_task **ptask;
+ gint num;
if (ud->callback) {
/* Push error */
@@ -158,14 +156,12 @@ lua_http_push_reply (f_str_t *in, struct lua_http_ud *ud)
/* Date */
if (ud->date != (time_t)-1) {
- num++;
+ num ++;
lua_pushnumber (ud->L, ud->date);
}
if (lua_pcall (ud->L, num, 0, 0) != 0) {
- msg_info ("call to %s failed: %s",
- ud->callback ? ud->callback : "local function",
- lua_tostring (ud->L, -1));
+ msg_info ("call to %s failed: %s", ud->callback ? ud->callback : "local function", lua_tostring (ud->L, -1));
}
if (ud->headers != NULL) {
@@ -183,7 +179,7 @@ lua_http_push_reply (f_str_t *in, struct lua_http_ud *ud)
static gboolean
lua_http_parse_first_line (struct lua_http_ud *ud, f_str_t *in)
{
- const gchar *p;
+ const gchar *p;
/* Assume first line is like this: HTTP/1.1 200 OK */
if (in->len < sizeof ("HTTP/1.1 OK") + 2) {
@@ -201,14 +197,14 @@ lua_http_parse_first_line (struct lua_http_ud *ud, f_str_t *in)
static gboolean
lua_http_parse_header_line (struct lua_http_ud *ud, f_str_t *in)
{
- const gchar *p = in->begin;
- struct lua_http_header *new;
+ const gchar *p = in->begin;
+ struct lua_http_header *new;
while (p < in->begin + in->len) {
if (*p == ':') {
break;
}
- p++;
+ p ++;
}
if (*p != ':') {
@@ -219,17 +215,16 @@ lua_http_parse_header_line (struct lua_http_ud *ud, f_str_t *in)
new->name = rspamd_mempool_alloc (ud->pool, p - in->begin + 1);
rspamd_strlcpy (new->name, in->begin, p - in->begin + 1);
- p++;
+ p ++;
/* Copy value */
while (p < in->begin + in->len && g_ascii_isspace (*p)) {
- p++;
+ p ++;
}
new->value = rspamd_mempool_alloc (ud->pool, in->begin + in->len - p + 1);
rspamd_strlcpy (new->value, p, in->begin + in->len - p + 1);
/* Check content-length */
- if (ud->rep_len == 0 &&
- g_ascii_strcasecmp (new->name, "content-length") == 0) {
+ if (ud->rep_len == 0 && g_ascii_strcasecmp (new->name, "content-length") == 0) {
ud->rep_len = strtoul (new->value, NULL, 10);
}
@@ -248,7 +243,7 @@ lua_http_parse_header_line (struct lua_http_ud *ud, f_str_t *in)
static gboolean
lua_http_read_cb (f_str_t * in, void *arg)
{
- struct lua_http_ud *ud = arg;
+ struct lua_http_ud *ud = arg;
switch (ud->parser_state) {
case 0:
@@ -270,9 +265,7 @@ lua_http_read_cb (f_str_t * in, void *arg)
}
else {
ud->parser_state = 2;
- rspamd_set_dispatcher_policy (ud->io_dispatcher,
- BUFFER_CHARACTER,
- ud->rep_len);
+ rspamd_set_dispatcher_policy (ud->io_dispatcher, BUFFER_CHARACTER, ud->rep_len);
}
}
else {
@@ -291,9 +284,8 @@ lua_http_read_cb (f_str_t * in, void *arg)
static void
lua_http_err_cb (GError * err, void *arg)
{
- struct lua_http_ud *ud = arg;
- msg_info ("abnormally closing connection to http server error: %s",
- err->message);
+ struct lua_http_ud *ud = arg;
+ msg_info ("abnormally closing connection to http server error: %s", err->message);
g_error_free (err);
if (ud->parser_state != 3) {
@@ -309,10 +301,10 @@ lua_http_err_cb (GError * err, void *arg)
static void
lua_http_dns_callback (struct rdns_reply *reply, gpointer arg)
{
- struct lua_http_ud *ud = arg;
- struct rdns_reply_entry *elt;
- struct in_addr ina;
- struct timeval tv;
+ struct lua_http_ud *ud = arg;
+ struct rdns_reply_entry *elt;
+ struct in_addr ina;
+ struct timeval tv;
if (reply->code != RDNS_RC_NOERROR) {
lua_http_push_error (450, ud);
@@ -323,8 +315,7 @@ lua_http_dns_callback (struct rdns_reply *reply, gpointer arg)
elt = reply->entries;
memcpy (&ina, &elt->content.a.addr, sizeof (struct in_addr));
- ud->fd = make_universal_socket (inet_ntoa (
- ina), ud->port, SOCK_STREAM, TRUE, FALSE, FALSE);
+ ud->fd = make_universal_socket (inet_ntoa (ina), ud->port, SOCK_STREAM, TRUE, FALSE, FALSE);
if (ud->fd == -1) {
lua_http_push_error (450, ud);
@@ -333,20 +324,12 @@ lua_http_dns_callback (struct rdns_reply *reply, gpointer arg)
/* Create dispatcher for HTTP protocol */
msec_to_tv (ud->timeout, &tv);
- ud->io_dispatcher = rspamd_create_dispatcher (ud->ev_base,
- ud->fd,
- BUFFER_LINE,
- lua_http_read_cb,
- NULL,
- lua_http_err_cb,
- &tv,
- ud);
+ ud->io_dispatcher = rspamd_create_dispatcher (ud->ev_base, ud->fd, BUFFER_LINE, lua_http_read_cb, NULL,
+ lua_http_err_cb, &tv, ud);
/* Write request */
- register_async_event (ud->s, lua_http_fin, ud,
- g_quark_from_static_string ("lua http"));
+ register_async_event (ud->s, lua_http_fin, ud, g_quark_from_static_string ("lua http"));
- if (!rspamd_dispatcher_write (ud->io_dispatcher, ud->req_buf, ud->req_len,
- TRUE, TRUE)) {
+ if (!rspamd_dispatcher_write (ud->io_dispatcher, ud->req_buf, ud->req_len, TRUE, TRUE)) {
lua_http_push_error (450, ud);
return;
}
@@ -356,22 +339,16 @@ lua_http_dns_callback (struct rdns_reply *reply, gpointer arg)
* Common request function
*/
static gint
-lua_http_make_request_common (lua_State *L,
- struct rspamd_task *task,
- const gchar *callback,
- const gchar *hostname,
- const gchar *path,
- const gchar *data,
- gint top)
+lua_http_make_request_common (lua_State *L, struct rspamd_task *task, const gchar *callback,
+ const gchar *hostname, const gchar *path, const gchar *data, gint top)
{
- gint r, s, datalen;
- struct lua_http_ud *ud;
+ gint r, s, datalen;
+ struct lua_http_ud *ud;
/* Calculate buffer size */
datalen = (data != NULL) ? strlen (data) : 0;
- s = MAX_HEADERS_SIZE + sizeof (CRLF) * 3 + strlen (hostname) +
- strlen (path) + datalen
- + sizeof ("POST HTTP/1.1");
+ s = MAX_HEADERS_SIZE + sizeof (CRLF) * 3 + strlen (hostname) + strlen (path) + datalen
+ + sizeof ("POST HTTP/1.1");
ud = rspamd_mempool_alloc0 (task->task_pool, sizeof (struct lua_http_ud));
ud->L = L;
@@ -385,14 +362,11 @@ lua_http_make_request_common (lua_State *L,
/* Print request */
r = rspamd_snprintf (ud->req_buf, s, "%s %s HTTP/1.1" CRLF
- "Connection: close" CRLF
- "Host: %s" CRLF,
- (data != NULL) ? "POST" : "GET", path, hostname);
+ "Connection: close" CRLF
+ "Host: %s" CRLF,
+ (data != NULL) ? "POST" : "GET", path, hostname);
if (datalen > 0) {
- r += rspamd_snprintf (ud->req_buf + r,
- s - r,
- "Content-Length: %d" CRLF,
- datalen);
+ r += rspamd_snprintf (ud->req_buf + r, s - r, "Content-Length: %d" CRLF, datalen);
}
/* Now assume that we have a table with headers at the top of the stack */
@@ -400,12 +374,8 @@ lua_http_make_request_common (lua_State *L,
/* Add headers */
lua_pushnil (L); /* first key */
while (lua_next (L, top + 1) != 0) {
- r += rspamd_snprintf (ud->req_buf + r,
- s - r,
- "%s: %s" CRLF,
- lua_tostring (L, -2),
- lua_tostring (L, -1));
- lua_pop (L, 1);
+ r += rspamd_snprintf (ud->req_buf + r, s - r, "%s: %s" CRLF, lua_tostring (L, -2), lua_tostring (L, -1));
+ lua_pop(L, 1);
}
}
/* Now check port and timeout */
@@ -433,10 +403,9 @@ lua_http_make_request_common (lua_State *L,
ud->req_len = r;
/* Resolve hostname */
- if (make_dns_request (task->resolver, task->s, task->task_pool,
- lua_http_dns_callback, ud,
- RDNS_REQUEST_A, hostname)) {
- task->dns_requests++;
+ if (make_dns_request (task->resolver, task->s, task->task_pool, lua_http_dns_callback, ud,
+ RDNS_REQUEST_A, hostname)) {
+ task->dns_requests ++;
}
return 0;
@@ -446,26 +415,18 @@ lua_http_make_request_common (lua_State *L,
* Common request function (new version)
*/
static gint
-lua_http_make_request_common_new (lua_State *L,
- struct rspamd_async_session *session,
- rspamd_mempool_t *pool,
- struct event_base *base,
- gint cbref,
- const gchar *hostname,
- const gchar *path,
- const gchar *data,
- gint top)
+lua_http_make_request_common_new (lua_State *L, struct rspamd_async_session *session, rspamd_mempool_t *pool, struct event_base *base, gint cbref,
+ const gchar *hostname, const gchar *path, const gchar *data, gint top)
{
- gint r, s, datalen;
- struct lua_http_ud *ud;
- struct in_addr ina;
- struct timeval tv;
+ gint r, s, datalen;
+ struct lua_http_ud *ud;
+ struct in_addr ina;
+ struct timeval tv;
/* Calculate buffer size */
datalen = (data != NULL) ? strlen (data) : 0;
- s = MAX_HEADERS_SIZE + sizeof (CRLF) * 3 + strlen (hostname) +
- strlen (path) + datalen
- + sizeof ("POST HTTP/1.1");
+ s = MAX_HEADERS_SIZE + sizeof (CRLF) * 3 + strlen (hostname) + strlen (path) + datalen
+ + sizeof ("POST HTTP/1.1");
ud = rspamd_mempool_alloc0 (pool, sizeof (struct lua_http_ud));
ud->L = L;
@@ -479,13 +440,10 @@ lua_http_make_request_common_new (lua_State *L,
/* Print request */
r = rspamd_snprintf (ud->req_buf, s, "%s %s HTTP/1.1" CRLF
- "Connection: close" CRLF,
- (data != NULL) ? "POST" : "GET", path);
+ "Connection: close" CRLF,
+ (data != NULL) ? "POST" : "GET", path);
if (datalen > 0) {
- r += rspamd_snprintf (ud->req_buf + r,
- s - r,
- "Content-Length: %d" CRLF,
- datalen);
+ r += rspamd_snprintf (ud->req_buf + r, s - r, "Content-Length: %d" CRLF, datalen);
}
/* Now assume that we have a table with headers at the top of the stack */
@@ -493,11 +451,7 @@ lua_http_make_request_common_new (lua_State *L,
/* Add headers */
lua_pushnil (L); /* first key */
while (lua_next (L, top + 1) != 0) {
- r += rspamd_snprintf (ud->req_buf + r,
- s - r,
- "%s: %s" CRLF,
- lua_tostring (L, -2),
- lua_tostring (L, -1));
+ r += rspamd_snprintf (ud->req_buf + r, s - r, "%s: %s" CRLF, lua_tostring (L, -2), lua_tostring (L, -1));
lua_pop (L, 1);
}
}
@@ -532,8 +486,7 @@ lua_http_make_request_common_new (lua_State *L,
return 1;
}
- ud->fd = make_universal_socket (inet_ntoa (
- ina), ud->port, SOCK_STREAM, TRUE, FALSE, FALSE);
+ ud->fd = make_universal_socket (inet_ntoa (ina), ud->port, SOCK_STREAM, TRUE, FALSE, FALSE);
if (ud->fd == -1) {
luaL_unref (L, LUA_REGISTRYINDEX, cbref);
@@ -543,20 +496,12 @@ lua_http_make_request_common_new (lua_State *L,
/* Create dispatcher for HTTP protocol */
msec_to_tv (ud->timeout, &tv);
- ud->io_dispatcher = rspamd_create_dispatcher (ud->ev_base,
- ud->fd,
- BUFFER_LINE,
- lua_http_read_cb,
- NULL,
- lua_http_err_cb,
- &tv,
- ud);
+ ud->io_dispatcher = rspamd_create_dispatcher (ud->ev_base, ud->fd, BUFFER_LINE, lua_http_read_cb, NULL,
+ lua_http_err_cb, &tv, ud);
/* Write request */
- register_async_event (ud->s, lua_http_fin, ud,
- g_quark_from_static_string ("lua http"));
+ register_async_event (ud->s, lua_http_fin, ud, g_quark_from_static_string ("lua http"));
- if (!rspamd_dispatcher_write (ud->io_dispatcher, ud->req_buf, ud->req_len,
- TRUE, TRUE)) {
+ if (!rspamd_dispatcher_write (ud->io_dispatcher, ud->req_buf, ud->req_len, TRUE, TRUE)) {
luaL_unref (L, LUA_REGISTRYINDEX, cbref);
lua_pushnil (L);
return 1;
@@ -573,12 +518,12 @@ lua_http_make_request_common_new (lua_State *L,
static gint
lua_http_make_post_request (lua_State *L)
{
- struct rspamd_task *task, **ptask;
- rspamd_mempool_t *pool, **ppool;
- struct rspamd_async_session *session, **psession;
- struct event_base *base, **pbase;
- const gchar *hostname, *path, *data, *callback;
- gint cbref;
+ struct rspamd_task *task, **ptask;
+ rspamd_mempool_t *pool, **ppool;
+ struct rspamd_async_session *session, **psession;
+ struct event_base *base, **pbase;
+ const gchar *hostname, *path, *data, *callback;
+ gint cbref;
/* Check whether we have a task object */
@@ -590,32 +535,23 @@ lua_http_make_post_request (lua_State *L)
luaL_argcheck (L, psession != NULL, 1, "'session' expected");
session = psession ? *(psession) : NULL;
ppool = luaL_checkudata (L, 2, "rspamd{mempool}");
- luaL_argcheck (L, ppool != NULL, 2, "'mempool' expected");
+ luaL_argcheck (L, ppool != NULL, 2, "'mempool' expected");
pool = ppool ? *(ppool) : NULL;
pbase = luaL_checkudata (L, 3, "rspamd{ev_base}");
- luaL_argcheck (L, ppool != NULL, 3, "'ev_base' expected");
+ luaL_argcheck (L, ppool != NULL, 3, "'ev_base' expected");
base = pbase ? *(pbase) : NULL;
}
/* Now extract hostname, path and data */
if (task) {
- callback =
- rspamd_mempool_strdup (task->task_pool, luaL_checkstring (L, 2));
- hostname =
- rspamd_mempool_strdup (task->task_pool, luaL_checkstring (L, 3));
+ callback = rspamd_mempool_strdup (task->task_pool, luaL_checkstring (L, 2));
+ hostname = rspamd_mempool_strdup (task->task_pool, luaL_checkstring (L, 3));
path = rspamd_mempool_strdup (task->task_pool, luaL_checkstring (L, 4));
data = rspamd_mempool_strdup (task->task_pool, luaL_checkstring (L, 5));
- if (callback != NULL && hostname != NULL && path != NULL && data !=
- NULL) {
- return lua_http_make_request_common (L,
- task,
- callback,
- hostname,
- path,
- data,
- 5);
+ if (callback != NULL && hostname != NULL && path != NULL && data != NULL) {
+ return lua_http_make_request_common (L, task, callback, hostname, path, data, 5);
}
else {
msg_info ("invalid arguments number");
@@ -626,19 +562,10 @@ lua_http_make_post_request (lua_State *L)
hostname = rspamd_mempool_strdup (pool, luaL_checkstring (L, 4));
path = rspamd_mempool_strdup (pool, luaL_checkstring (L, 5));
data = rspamd_mempool_strdup (pool, luaL_checkstring (L, 6));
- if (session != NULL && pool != NULL && hostname != NULL && path !=
- NULL && data != NULL && lua_isfunction (L, 7)) {
+ if (session != NULL && pool != NULL && hostname != NULL && path != NULL && data != NULL && lua_isfunction (L, 7)) {
lua_pushvalue (L, 7);
cbref = luaL_ref (L, LUA_REGISTRYINDEX);
- return lua_http_make_request_common_new (L,
- session,
- pool,
- base,
- cbref,
- hostname,
- path,
- data,
- 7);
+ return lua_http_make_request_common_new (L, session, pool, base, cbref, hostname, path, data, 7);
}
}
@@ -652,12 +579,12 @@ lua_http_make_post_request (lua_State *L)
static gint
lua_http_make_get_request (lua_State *L)
{
- struct rspamd_task *task, **ptask;
- rspamd_mempool_t *pool, **ppool;
- struct rspamd_async_session *session, **psession;
- struct event_base *base, **pbase;
- const gchar *hostname, *path, *callback;
- gint cbref;
+ struct rspamd_task *task, **ptask;
+ rspamd_mempool_t *pool, **ppool;
+ struct rspamd_async_session *session, **psession;
+ struct event_base *base, **pbase;
+ const gchar *hostname, *path, *callback;
+ gint cbref;
/* Check whether we have a task object */
@@ -669,30 +596,22 @@ lua_http_make_get_request (lua_State *L)
luaL_argcheck (L, psession != NULL, 1, "'session' expected");
session = psession ? *(psession) : NULL;
ppool = luaL_checkudata (L, 2, "rspamd{mempool}");
- luaL_argcheck (L, ppool != NULL, 2, "'mempool' expected");
+ luaL_argcheck (L, ppool != NULL, 2, "'mempool' expected");
pool = ppool ? *(ppool) : NULL;
pbase = luaL_checkudata (L, 3, "rspamd{ev_base}");
- luaL_argcheck (L, ppool != NULL, 3, "'ev_base' expected");
+ luaL_argcheck (L, ppool != NULL, 3, "'ev_base' expected");
base = pbase ? *(pbase) : NULL;
}
/* Now extract hostname, path and data */
if (task) {
- callback =
- rspamd_mempool_strdup (task->task_pool, luaL_checkstring (L, 2));
- hostname =
- rspamd_mempool_strdup (task->task_pool, luaL_checkstring (L, 3));
+ callback = rspamd_mempool_strdup (task->task_pool, luaL_checkstring (L, 2));
+ hostname = rspamd_mempool_strdup (task->task_pool, luaL_checkstring (L, 3));
path = rspamd_mempool_strdup (task->task_pool, luaL_checkstring (L, 4));
if (callback != NULL && hostname != NULL && path != NULL) {
- return lua_http_make_request_common (L,
- task,
- callback,
- hostname,
- path,
- NULL,
- 4);
+ return lua_http_make_request_common (L, task, callback, hostname, path, NULL, 4);
}
else {
msg_info ("invalid arguments number");
@@ -702,19 +621,10 @@ lua_http_make_get_request (lua_State *L)
/* Common version */
hostname = rspamd_mempool_strdup (pool, luaL_checkstring (L, 4));
path = rspamd_mempool_strdup (pool, luaL_checkstring (L, 5));
- if (session != NULL && pool != NULL && hostname != NULL && path !=
- NULL && lua_isfunction (L, 6)) {
+ if (session != NULL && pool != NULL && hostname != NULL && path != NULL && lua_isfunction (L, 6)) {
lua_pushvalue (L, 6);
cbref = luaL_ref (L, LUA_REGISTRYINDEX);
- return lua_http_make_request_common_new (L,
- session,
- pool,
- base,
- cbref,
- hostname,
- path,
- NULL,
- 6);
+ return lua_http_make_request_common_new (L, session, pool, base, cbref, hostname, path, NULL, 6);
}
}
diff --git a/src/lua/lua_ip.c b/src/lua/lua_ip.c
index 3292d93e7..f477e1d77 100644
--- a/src/lua/lua_ip.c
+++ b/src/lua/lua_ip.c
@@ -34,7 +34,7 @@ LUA_FUNCTION_DEF (ip, destroy);
LUA_FUNCTION_DEF (ip, get_version);
LUA_FUNCTION_DEF (ip, is_valid);
-static const struct luaL_reg iplib_m[] = {
+static const struct luaL_reg iplib_m[] = {
LUA_INTERFACE_DEF (ip, to_string),
LUA_INTERFACE_DEF (ip, to_table),
LUA_INTERFACE_DEF (ip, to_number),
@@ -47,13 +47,13 @@ static const struct luaL_reg iplib_m[] = {
{NULL, NULL}
};
-static const struct luaL_reg iplib_f[] = {
+static const struct luaL_reg iplib_f[] = {
LUA_INTERFACE_DEF (ip, from_string),
LUA_INTERFACE_DEF (ip, from_number),
{NULL, NULL}
};
-static struct rspamd_lua_ip *
+static struct rspamd_lua_ip *
lua_check_ip (lua_State * L, gint pos)
{
void *ud = luaL_checkudata (L, pos, "rspamd{ip}");
@@ -80,7 +80,7 @@ lua_ip_to_table (lua_State *L)
ptr = (guint8 *)&ip->addr.addr.s6.sin6_addr;
}
- for (i = 1; i <= max; i++, ptr++) {
+ for (i = 1; i <= max; i ++, ptr ++) {
lua_pushnumber (L, *ptr);
lua_rawseti (L, -2, i);
}
@@ -111,22 +111,19 @@ lua_ip_str_octets (lua_State *L)
ptr = (guint8 *)&ip->addr.addr.s6.sin6_addr;
}
- for (i = 1; i <= max; i++, ptr++) {
+ for (i = 1; i <= max; i ++, ptr ++) {
if (ip->addr.af == AF_INET) {
rspamd_snprintf (numbuf, sizeof (numbuf), "%d", *ptr);
lua_pushstring (L, numbuf);
lua_rawseti (L, -2, i);
}
else {
- rspamd_snprintf (numbuf,
- sizeof (numbuf),
- "%xd",
- (*ptr & 0xf0) >> 4);
+ rspamd_snprintf (numbuf, sizeof (numbuf), "%xd", (*ptr & 0xf0) >> 4);
lua_pushstring (L, numbuf);
- lua_rawseti (L, -2, i * 2 - 1);
+ lua_rawseti (L, -2, i*2 - 1);
rspamd_snprintf (numbuf, sizeof (numbuf), "%xd", *ptr & 0x0f);
lua_pushstring (L, numbuf);
- lua_rawseti (L, -2, i * 2);
+ lua_rawseti (L, -2, i*2);
}
}
}
@@ -157,7 +154,7 @@ lua_ip_inversed_str_octets (lua_State *L)
}
ptr += max - 1;
- for (i = 1; i <= max; i++, ptr--) {
+ for (i = 1; i <= max; i ++, ptr --) {
if (ip->addr.af == AF_INET) {
rspamd_snprintf (numbuf, sizeof (numbuf), "%d", *ptr);
lua_pushstring (L, numbuf);
@@ -166,13 +163,10 @@ lua_ip_inversed_str_octets (lua_State *L)
else {
rspamd_snprintf (numbuf, sizeof (numbuf), "%xd", *ptr & 0x0f);
lua_pushstring (L, numbuf);
- lua_rawseti (L, -2, i * 2 - 1);
- rspamd_snprintf (numbuf,
- sizeof (numbuf),
- "%xd",
- (*ptr & 0xf0) >> 4);
+ lua_rawseti (L, -2, i*2 - 1);
+ rspamd_snprintf (numbuf, sizeof (numbuf), "%xd", (*ptr & 0xf0) >> 4);
lua_pushstring (L, numbuf);
- lua_rawseti (L, -2, i * 2);
+ lua_rawseti (L, -2, i*2);
}
}
}
@@ -232,10 +226,9 @@ lua_ip_to_number (lua_State *L)
}
else {
/* 4 integers in host byte order */
- G_STATIC_ASSERT (sizeof (ip->addr.addr.s6.sin6_addr) >=
- sizeof (dst));
+ G_STATIC_ASSERT (sizeof (ip->addr.addr.s6.sin6_addr) >= sizeof (dst));
memcpy (dst, &ip->addr.addr.s6.sin6_addr, sizeof (dst));
- for (i = 0; i < G_N_ELEMENTS (dst); i++) {
+ for (i = 0; i < G_N_ELEMENTS (dst); i ++) {
lua_pushinteger (L, ntohl (dst[i]));
}
return 4;
@@ -267,7 +260,7 @@ lua_ip_from_number (lua_State *L)
}
else if (lua_gettop (L) == 4 && lua_isnumber (L, 1)) {
/* Ipv6 version */
- for (i = 0; i < 4; i++) {
+ for (i = 0; i < 4; i ++) {
src[i] = htonl (lua_tonumber (L, i + 1));
}
G_STATIC_ASSERT (sizeof (ip->addr.addr.s6.sin6_addr) >= sizeof (src));
@@ -377,7 +370,7 @@ luaopen_ip (lua_State * L)
lua_pushstring (L, "rspamd{ip}");
lua_rawset (L, -3);
- luaL_register (L, NULL, iplib_m);
+ luaL_register (L, NULL, iplib_m);
luaL_register (L, "rspamd_ip", iplib_f);
lua_pop (L, 1); /* remove metatable from stack */
diff --git a/src/lua/lua_mempool.c b/src/lua/lua_mempool.c
index 50de17dd1..2648a60b2 100644
--- a/src/lua/lua_mempool.c
+++ b/src/lua/lua_mempool.c
@@ -25,7 +25,7 @@
#include "mem_pool.h"
/* Public prototypes */
-struct memory_pool_s * lua_check_mempool (lua_State * L);
+struct memory_pool_s *lua_check_mempool (lua_State * L);
gint luaopen_mempool (lua_State * L);
/* Lua bindings */
@@ -37,7 +37,7 @@ LUA_FUNCTION_DEF (mempool, memory_pool_suggest_size);
LUA_FUNCTION_DEF (mempool, memory_pool_set_variable);
LUA_FUNCTION_DEF (mempool, memory_pool_get_variable);
-static const struct luaL_reg mempoollib_m[] = {
+static const struct luaL_reg mempoollib_m[] = {
LUA_INTERFACE_DEF (mempool, memory_pool_add_destructor),
LUA_INTERFACE_DEF (mempool, memory_pool_stat),
LUA_INTERFACE_DEF (mempool, memory_pool_suggest_size),
@@ -48,7 +48,7 @@ static const struct luaL_reg mempoollib_m[] = {
{NULL, NULL}
};
-static const struct luaL_reg mempoollib_f[] = {
+static const struct luaL_reg mempoollib_f[] = {
LUA_INTERFACE_DEF (mempool, create),
{NULL, NULL}
};
@@ -63,10 +63,10 @@ struct lua_mempool_udata {
rspamd_mempool_t *mempool;
};
-struct memory_pool_s *
+struct memory_pool_s *
lua_check_mempool (lua_State * L)
{
- void *ud = luaL_checkudata (L, 1, "rspamd{mempool}");
+ void *ud = luaL_checkudata (L, 1, "rspamd{mempool}");
luaL_argcheck (L, ud != NULL, 1, "'mempool' expected");
return ud ? *((struct memory_pool_s **)ud) : NULL;
}
@@ -75,8 +75,7 @@ lua_check_mempool (lua_State * L)
static int
lua_mempool_create (lua_State *L)
{
- struct memory_pool_s *mempool = rspamd_mempool_new (
- rspamd_mempool_suggest_size ()), **pmempool;
+ struct memory_pool_s *mempool = rspamd_mempool_new (rspamd_mempool_suggest_size ()), **pmempool;
if (mempool) {
pmempool = lua_newuserdata (L, sizeof (struct memory_pool_s *));
@@ -93,7 +92,7 @@ lua_mempool_create (lua_State *L)
static void
lua_mempool_destructor_func (gpointer p)
{
- struct lua_mempool_udata *ud = p;
+ struct lua_mempool_udata *ud = p;
lua_rawgeti (ud->L, LUA_REGISTRYINDEX, ud->cbref);
if (lua_pcall (ud->L, 0, 0, 0) != 0) {
@@ -105,21 +104,18 @@ lua_mempool_destructor_func (gpointer p)
static int
lua_mempool_memory_pool_add_destructor (lua_State *L)
{
- struct memory_pool_s *mempool = lua_check_mempool (L);
- struct lua_mempool_udata *ud;
+ struct memory_pool_s *mempool = lua_check_mempool (L);
+ struct lua_mempool_udata *ud;
if (mempool) {
if (lua_isfunction (L, 2)) {
- ud = rspamd_mempool_alloc (mempool,
- sizeof (struct lua_mempool_udata));
+ ud = rspamd_mempool_alloc (mempool, sizeof (struct lua_mempool_udata));
lua_pushvalue (L, 2);
/* Get a reference */
ud->cbref = luaL_ref (L, LUA_REGISTRYINDEX);
ud->L = L;
ud->mempool = mempool;
- rspamd_mempool_add_destructor (mempool,
- lua_mempool_destructor_func,
- ud);
+ rspamd_mempool_add_destructor (mempool, lua_mempool_destructor_func, ud);
}
else {
msg_err ("trying to add destructor without function");
@@ -135,7 +131,7 @@ lua_mempool_memory_pool_add_destructor (lua_State *L)
static int
lua_mempool_memory_pool_delete (lua_State *L)
{
- struct memory_pool_s *mempool = lua_check_mempool (L);
+ struct memory_pool_s *mempool = lua_check_mempool (L);
if (mempool) {
rspamd_mempool_delete (mempool);
@@ -151,10 +147,10 @@ lua_mempool_memory_pool_delete (lua_State *L)
static int
lua_mempool_memory_pool_stat (lua_State *L)
{
- struct memory_pool_s *mempool = lua_check_mempool (L);
+ struct memory_pool_s *mempool = lua_check_mempool (L);
if (mempool) {
-
+
}
else {
lua_pushnil (L);
@@ -166,7 +162,7 @@ lua_mempool_memory_pool_stat (lua_State *L)
static int
lua_mempool_memory_pool_suggest_size (lua_State *L)
{
- struct memory_pool_s *mempool = lua_check_mempool (L);
+ struct memory_pool_s *mempool = lua_check_mempool (L);
if (mempool) {
lua_pushinteger (L, rspamd_mempool_suggest_size ());
@@ -182,13 +178,12 @@ lua_mempool_memory_pool_suggest_size (lua_State *L)
static int
lua_mempool_memory_pool_set_variable (lua_State *L)
{
- struct memory_pool_s *mempool = lua_check_mempool (L);
- const gchar *var = luaL_checkstring (L, 2),
- *value = luaL_checkstring (L, 3);
+ struct memory_pool_s *mempool = lua_check_mempool (L);
+ const gchar *var = luaL_checkstring (L, 2),
+ *value = luaL_checkstring (L, 3);
if (mempool && var && value) {
- rspamd_mempool_set_variable (mempool, var,
- rspamd_mempool_strdup (mempool, value), NULL);
+ rspamd_mempool_set_variable (mempool, var, rspamd_mempool_strdup (mempool, value), NULL);
return 0;
}
else {
@@ -201,9 +196,9 @@ lua_mempool_memory_pool_set_variable (lua_State *L)
static int
lua_mempool_memory_pool_get_variable (lua_State *L)
{
- struct memory_pool_s *mempool = lua_check_mempool (L);
- const gchar *var = luaL_checkstring (L, 2);
- gchar *value;
+ struct memory_pool_s *mempool = lua_check_mempool (L);
+ const gchar *var = luaL_checkstring (L, 2);
+ gchar *value;
if (mempool && var) {
value = rspamd_mempool_get_variable (mempool, var);
@@ -233,10 +228,10 @@ luaopen_mempool (lua_State * L)
lua_pushstring (L, "rspamd{mempool}");
lua_rawset (L, -3);
- luaL_register (L, NULL, mempoollib_m);
+ luaL_register (L, NULL, mempoollib_m);
luaL_register (L, "rspamd_mempool", mempoollib_f);
lua_pop (L, 1); /* remove metatable from stack */
- return 1;
+ return 1;
}
diff --git a/src/lua/lua_message.c b/src/lua/lua_message.c
index 8dd89c75c..f02178d1a 100644
--- a/src/lua/lua_message.c
+++ b/src/lua/lua_message.c
@@ -26,35 +26,35 @@
#include "lua_common.h"
#include "message.h"
-#define LUA_GMIME_BRIDGE_GET(class, name, mime_class) \
- static gint \
- lua_ ## class ## _ ## name (lua_State * L) \
- { \
- GMime ## mime_class * obj = lua_check_ ## class (L); \
- if (obj != NULL) { \
- lua_pushstring (L, g_mime_ ## class ## _ ## name (obj)); \
- } \
- else { \
- lua_pushnil (L); \
- } \
- return 1; \
- }
+#define LUA_GMIME_BRIDGE_GET(class, name, mime_class) \
+static gint \
+lua_##class##_##name(lua_State *L) \
+{ \
+ GMime##mime_class *obj = lua_check_##class(L); \
+ if (obj != NULL) { \
+ lua_pushstring (L, g_mime_##class##_##name(obj)); \
+ } \
+ else { \
+ lua_pushnil (L); \
+ } \
+ return 1; \
+}
-#define LUA_GMIME_BRIDGE_SET(class, name, mime_class) \
- static gint \
- lua_ ## class ## _ ## name (lua_State * L) \
- { \
- const gchar *str; \
- GMime ## mime_class * obj = lua_check_ ## class (L); \
- if (obj != NULL) { \
- str = luaL_checkstring (L, 2); \
- g_mime_ ## class ## _ ## name (obj, str); \
- } \
- else { \
- lua_pushnil (L); \
- } \
- return 1; \
- }
+#define LUA_GMIME_BRIDGE_SET(class, name, mime_class) \
+static gint \
+lua_##class##_##name(lua_State *L) \
+{ \
+ const gchar *str; \
+ GMime##mime_class *obj = lua_check_##class(L); \
+ if (obj != NULL) { \
+ str = luaL_checkstring (L, 2); \
+ g_mime_##class##_##name(obj, str); \
+ } \
+ else { \
+ lua_pushnil (L); \
+ } \
+ return 1; \
+}
/* Message methods */
LUA_FUNCTION_DEF (message, get_subject);
@@ -70,7 +70,7 @@ LUA_FUNCTION_DEF (message, get_header_strong);
LUA_FUNCTION_DEF (message, set_header);
LUA_FUNCTION_DEF (message, get_date);
-static const struct luaL_reg msglib_m[] = {
+static const struct luaL_reg msglib_m[] = {
LUA_INTERFACE_DEF (message, get_subject),
LUA_INTERFACE_DEF (message, set_subject),
LUA_INTERFACE_DEF (message, get_message_id),
@@ -89,10 +89,10 @@ static const struct luaL_reg msglib_m[] = {
-static GMimeMessage *
+static GMimeMessage *
lua_check_message (lua_State * L)
{
- void *ud = luaL_checkudata (L, 1, "rspamd{message}");
+ void *ud = luaL_checkudata (L, 1, "rspamd{message}");
luaL_argcheck (L, ud != NULL, 1, "'message' expected");
return ud ? *((GMimeMessage **) ud) : NULL;
}
@@ -112,10 +112,10 @@ LUA_GMIME_BRIDGE_SET (message, set_reply_to, Message)
static gint
lua_message_get_header_common (lua_State * L, gboolean strong)
{
- const gchar *headern;
- GMimeMessage *obj = lua_check_message (L);
- GList *res = NULL, *cur;
- gint i = 1;
+ const gchar *headern;
+ GMimeMessage *obj = lua_check_message (L);
+ GList *res = NULL, *cur;
+ gint i = 1;
if (obj != NULL) {
headern = luaL_checkstring (L, 2);
@@ -162,8 +162,8 @@ lua_message_get_header_strong (lua_State * L)
static gint
lua_message_set_header (lua_State * L)
{
- const gchar *headern, *headerv;
- GMimeMessage *obj = lua_check_message (L);
+ const gchar *headern, *headerv;
+ GMimeMessage *obj = lua_check_message (L);
if (obj != NULL) {
headern = luaL_checkstring (L, 2);
@@ -185,9 +185,9 @@ lua_message_set_header (lua_State * L)
static gint
lua_message_get_date (lua_State * L)
{
- GMimeMessage *obj = lua_check_message (L);
- time_t msg_time;
- int offset;
+ GMimeMessage *obj = lua_check_message (L);
+ time_t msg_time;
+ int offset;
if (obj != NULL) {
g_mime_message_get_date (obj, &msg_time, &offset);
diff --git a/src/lua/lua_redis.c b/src/lua/lua_redis.c
index 9d5ab5a5f..2642daf9a 100644
--- a/src/lua/lua_redis.c
+++ b/src/lua/lua_redis.c
@@ -21,17 +21,17 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "dns.h"
#include "lua_common.h"
+#include "dns.h"
#ifndef WITH_SYSTEM_HIREDIS
-#include "adapters/libevent.h"
-#include "async.h"
#include "hiredis.h"
+#include "async.h"
+#include "adapters/libevent.h"
#else
-#include <hiredis/adapters/libevent.h>
-#include <hiredis/async.h>
#include <hiredis/hiredis.h>
+#include <hiredis/async.h>
+#include <hiredis/adapters/libevent.h>
#endif
@@ -41,7 +41,7 @@
LUA_FUNCTION_DEF (redis, make_request);
-static const struct luaL_reg redislib_m[] = {
+static const struct luaL_reg redislib_m[] = {
LUA_INTERFACE_DEF (redis, make_request),
{"__tostring", lua_class_tostring},
{NULL, NULL}
@@ -68,10 +68,10 @@ struct lua_redis_userdata {
* @param L lua stack
* @return worker task object
*/
-static struct rspamd_task *
+static struct rspamd_task *
lua_check_task (lua_State * L)
{
- void *ud = luaL_checkudata (L, 1, "rspamd{task}");
+ void *ud = luaL_checkudata (L, 1, "rspamd{task}");
luaL_argcheck (L, ud != NULL, 1, "'task' expected");
return ud ? *((struct rspamd_task **)ud) : NULL;
}
@@ -79,7 +79,7 @@ lua_check_task (lua_State * L)
static void
lua_redis_fin (void *arg)
{
- struct lua_redis_userdata *ud = arg;
+ struct lua_redis_userdata *ud = arg;
if (ud->ctx) {
redisAsyncFree (ud->ctx);
@@ -93,11 +93,9 @@ lua_redis_fin (void *arg)
* @param ud
*/
static void
-lua_redis_push_error (const gchar *err,
- struct lua_redis_userdata *ud,
- gboolean connected)
+lua_redis_push_error (const gchar *err, struct lua_redis_userdata *ud, gboolean connected)
{
- struct rspamd_task **ptask;
+ struct rspamd_task **ptask;
/* Push error */
lua_rawgeti (ud->L, LUA_REGISTRYINDEX, ud->cbref);
@@ -127,7 +125,7 @@ lua_redis_push_error (const gchar *err,
static void
lua_redis_push_data (const redisReply *r, struct lua_redis_userdata *ud)
{
- struct rspamd_task **ptask;
+ struct rspamd_task **ptask;
/* Push error */
lua_rawgeti (ud->L, LUA_REGISTRYINDEX, ud->cbref);
@@ -171,8 +169,8 @@ lua_redis_push_data (const redisReply *r, struct lua_redis_userdata *ud)
static void
lua_redis_callback (redisAsyncContext *c, gpointer r, gpointer priv)
{
- redisReply *reply = r;
- struct lua_redis_userdata *ud = priv;
+ redisReply *reply = r;
+ struct lua_redis_userdata *ud = priv;
if (c->err == 0) {
if (r != NULL) {
@@ -206,16 +204,11 @@ lua_redis_make_request_real (struct lua_redis_userdata *ud)
{
ud->ctx = redisAsyncConnect (inet_ntoa (ud->ina), ud->port);
if (ud->ctx == NULL || ud->ctx->err) {
- lua_redis_push_error (ud->ctx ? ud->ctx->errstr : "unknown error",
- ud,
- FALSE);
+ lua_redis_push_error (ud->ctx ? ud->ctx->errstr : "unknown error", ud, FALSE);
return FALSE;
}
else {
- register_async_event (ud->task->s,
- lua_redis_fin,
- ud,
- g_quark_from_static_string ("lua redis"));
+ register_async_event (ud->task->s, lua_redis_fin, ud, g_quark_from_static_string ("lua redis"));
}
redisLibeventAttach (ud->ctx, ud->task->ev_base);
/* Make a request now */
@@ -224,35 +217,17 @@ lua_redis_make_request_real (struct lua_redis_userdata *ud)
redisAsyncCommand (ud->ctx, lua_redis_callback, ud, ud->reqline);
break;
case 1:
- redisAsyncCommand (ud->ctx,
- lua_redis_callback,
- ud,
- ud->reqline,
- ud->args[0].begin,
- ud->args[0].len);
+ redisAsyncCommand (ud->ctx, lua_redis_callback, ud, ud->reqline, ud->args[0].begin, ud->args[0].len);
break;
case 2:
- redisAsyncCommand (ud->ctx,
- lua_redis_callback,
- ud,
- ud->reqline,
- ud->args[0].begin,
- ud->args[0].len,
- ud->args[1].begin,
- ud->args[1].len);
+ redisAsyncCommand (ud->ctx, lua_redis_callback, ud, ud->reqline, ud->args[0].begin, ud->args[0].len,
+ ud->args[1].begin, ud->args[1].len);
break;
default:
/* XXX: cannot handle more than 3 arguments */
- redisAsyncCommand (ud->ctx,
- lua_redis_callback,
- ud,
- ud->reqline,
- ud->args[0].begin,
- ud->args[0].len,
- ud->args[1].begin,
- ud->args[1].len,
- ud->args[2].begin,
- ud->args[2].len);
+ redisAsyncCommand (ud->ctx, lua_redis_callback, ud, ud->reqline, ud->args[0].begin, ud->args[0].len,
+ ud->args[1].begin, ud->args[1].len,
+ ud->args[2].begin, ud->args[2].len);
break;
}
@@ -267,8 +242,8 @@ lua_redis_make_request_real (struct lua_redis_userdata *ud)
static void
lua_redis_dns_callback (struct rdns_reply *reply, gpointer arg)
{
- struct lua_redis_userdata *ud = arg;
- struct rdns_reply_entry *elt;
+ struct lua_redis_userdata *ud = arg;
+ struct rdns_reply_entry *elt;
if (reply->code != RDNS_RC_NOERROR) {
@@ -296,21 +271,18 @@ lua_redis_dns_callback (struct rdns_reply *reply, gpointer arg)
static int
lua_redis_make_request (lua_State *L)
{
- struct rspamd_task *task;
- struct lua_redis_userdata *ud;
- const gchar *server, *tmp;
- guint port, i;
+ struct rspamd_task *task;
+ struct lua_redis_userdata *ud;
+ const gchar *server, *tmp;
+ guint port, i;
if ((task = lua_check_task (L)) != NULL) {
server = luaL_checkstring (L, 2);
port = luaL_checkint (L, 3);
/* Now get callback */
- if (lua_isfunction (L,
- 4) && server != NULL && port > 0 && port < G_MAXUINT16) {
+ if (lua_isfunction (L, 4) && server != NULL && port > 0 && port < G_MAXUINT16) {
/* Create userdata */
- ud =
- rspamd_mempool_alloc (task->task_pool,
- sizeof (struct lua_redis_userdata));
+ ud = rspamd_mempool_alloc (task->task_pool, sizeof (struct lua_redis_userdata));
ud->server = rspamd_mempool_strdup (task->task_pool, server);
ud->port = port;
ud->task = task;
@@ -320,17 +292,14 @@ lua_redis_make_request (lua_State *L)
lua_pushvalue (L, 4);
/* Get a reference */
ud->cbref = luaL_ref (L, LUA_REGISTRYINDEX);
- ud->reqline = rspamd_mempool_strdup (task->task_pool,
- luaL_checkstring (L, 5));
+ ud->reqline = rspamd_mempool_strdup (task->task_pool, luaL_checkstring (L, 5));
/* Now get remaining args */
ud->args_num = lua_gettop (L) - 5;
- ud->args = rspamd_mempool_alloc (task->task_pool,
- ud->args_num * sizeof (f_str_t));
- for (i = 0; i < ud->args_num; i++) {
+ ud->args = rspamd_mempool_alloc (task->task_pool, ud->args_num * sizeof (f_str_t));
+ for (i = 0; i < ud->args_num; i ++) {
tmp = lua_tolstring (L, i + 6, &ud->args[i].len);
/* Make a copy of argument */
- ud->args[i].begin = rspamd_mempool_alloc (task->task_pool,
- ud->args[i].len);
+ ud->args[i].begin = rspamd_mempool_alloc (task->task_pool, ud->args[i].len);
memcpy (ud->args[i].begin, tmp, ud->args[i].len);
}
/* Now check whether we need to perform DNS request */
@@ -338,9 +307,9 @@ lua_redis_make_request (lua_State *L)
/* Need to make dns request */
/* Resolve hostname */
if (make_dns_request (task->resolver, task->s, task->task_pool,
- lua_redis_dns_callback, ud,
- RDNS_REQUEST_A, ud->server)) {
- task->dns_requests++;
+ lua_redis_dns_callback, ud,
+ RDNS_REQUEST_A, ud->server)) {
+ task->dns_requests ++;
lua_pushboolean (L, TRUE);
}
else {
@@ -349,7 +318,7 @@ lua_redis_make_request (lua_State *L)
}
}
else {
- if (!lua_redis_make_request_real (ud)) {
+ if (! lua_redis_make_request_real (ud)) {
lua_pushboolean (L, FALSE);
}
else {
diff --git a/src/lua/lua_regexp.c b/src/lua/lua_regexp.c
index ba6379f54..ac489e53d 100644
--- a/src/lua/lua_regexp.c
+++ b/src/lua/lua_regexp.c
@@ -21,8 +21,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "expressions.h"
#include "lua_common.h"
+#include "expressions.h"
LUA_FUNCTION_DEF (regexp, create);
LUA_FUNCTION_DEF (regexp, get_cached);
@@ -31,7 +31,7 @@ LUA_FUNCTION_DEF (regexp, match);
LUA_FUNCTION_DEF (regexp, split);
LUA_FUNCTION_DEF (regexp, destroy);
-static const struct luaL_reg regexplib_m[] = {
+static const struct luaL_reg regexplib_m[] = {
LUA_INTERFACE_DEF (regexp, get_pattern),
LUA_INTERFACE_DEF (regexp, match),
LUA_INTERFACE_DEF (regexp, split),
@@ -39,7 +39,7 @@ static const struct luaL_reg regexplib_m[] = {
{"__tostring", lua_class_tostring},
{NULL, NULL}
};
-static const struct luaL_reg regexplib_f[] = {
+static const struct luaL_reg regexplib_f[] = {
LUA_INTERFACE_DEF (regexp, create),
LUA_INTERFACE_DEF (regexp, get_cached),
{NULL, NULL}
@@ -53,10 +53,10 @@ struct rspamd_lua_regexp {
gint re_flags;
};
-static struct rspamd_lua_regexp *
+static struct rspamd_lua_regexp *
lua_check_regexp (lua_State * L)
{
- void *ud = luaL_checkudata (L, 1, "rspamd{regexp}");
+ void *ud = luaL_checkudata (L, 1, "rspamd{regexp}");
luaL_argcheck (L, ud != NULL, 1, "'regexp' expected");
return ud ? *((struct rspamd_lua_regexp **)ud) : NULL;
@@ -65,11 +65,11 @@ lua_check_regexp (lua_State * L)
static int
lua_regexp_create (lua_State *L)
{
- gint regexp_flags = 0;
- GRegex *re;
- struct rspamd_lua_regexp *new, **pnew;
- const gchar *string, *flags_str = NULL;
- GError *err = NULL;
+ gint regexp_flags = 0;
+ GRegex *re;
+ struct rspamd_lua_regexp *new, **pnew;
+ const gchar *string, *flags_str = NULL;
+ GError *err = NULL;
string = luaL_checkstring (L, 1);
if (lua_gettop (L) == 2) {
@@ -104,16 +104,14 @@ lua_regexp_create (lua_State *L)
msg_info ("invalid regexp flag: %c", *flags_str);
break;
}
- flags_str++;
+ flags_str ++;
}
}
re = g_regex_new (string, regexp_flags, 0, &err);
if (re == NULL) {
lua_pushnil (L);
- msg_info ("cannot parse regexp: %s, error: %s",
- string,
- err == NULL ? "undefined" : err->message);
+ msg_info ("cannot parse regexp: %s, error: %s", string, err == NULL ? "undefined" : err->message);
}
else {
new = g_slice_alloc (sizeof (struct rspamd_lua_regexp));
@@ -132,8 +130,8 @@ lua_regexp_create (lua_State *L)
static int
lua_regexp_get_cached (lua_State *L)
{
- struct rspamd_lua_regexp *new, **pnew;
- const gchar *line;
+ struct rspamd_lua_regexp *new, **pnew;
+ const gchar *line;
line = luaL_checkstring (L, 1);
new = re_cache_check (line, regexp_static_pool);
@@ -152,7 +150,7 @@ lua_regexp_get_cached (lua_State *L)
static int
lua_regexp_get_pattern (lua_State *L)
{
- struct rspamd_lua_regexp *re = lua_check_regexp (L);
+ struct rspamd_lua_regexp *re = lua_check_regexp (L);
if (re) {
lua_pushstring (L, re->re_pattern);
@@ -164,11 +162,11 @@ lua_regexp_get_pattern (lua_State *L)
static int
lua_regexp_match (lua_State *L)
{
- struct rspamd_lua_regexp *re = lua_check_regexp (L);
- GMatchInfo *mi;
- const gchar *data;
- gchar **matches;
- gint i;
+ struct rspamd_lua_regexp *re = lua_check_regexp (L);
+ GMatchInfo *mi;
+ const gchar *data;
+ gchar **matches;
+ gint i;
if (re) {
data = luaL_checkstring (L, 2);
@@ -183,7 +181,7 @@ lua_regexp_match (lua_State *L)
if (g_regex_match_full (re->re, data, -1, 0, 0, &mi, NULL)) {
matches = g_match_info_fetch_all (mi);
lua_newtable (L);
- for (i = 1; matches[i - 1] != NULL; i++) {
+ for (i = 1; matches[i - 1] != NULL; i ++) {
lua_pushstring (L, matches[i - 1]);
lua_rawseti (L, -2, i);
}
@@ -204,10 +202,10 @@ lua_regexp_match (lua_State *L)
static int
lua_regexp_split (lua_State *L)
{
- struct rspamd_lua_regexp *re = lua_check_regexp (L);
- const gchar *data;
- gchar **parts;
- gint i;
+ struct rspamd_lua_regexp *re = lua_check_regexp (L);
+ const gchar *data;
+ gchar **parts;
+ gint i;
if (re) {
data = luaL_checkstring (L, 2);
@@ -221,7 +219,7 @@ lua_regexp_split (lua_State *L)
}
parts = g_regex_split (re->re, data, 0);
lua_newtable (L);
- for (i = 1; parts[i - 1] != NULL; i++) {
+ for (i = 1; parts[i - 1] != NULL; i ++) {
lua_pushstring (L, parts[i - 1]);
lua_rawseti (L, -2, i);
}
@@ -244,7 +242,7 @@ lua_regexp_split (lua_State *L)
static gint
lua_regexp_destroy (lua_State *L)
{
- struct rspamd_lua_regexp *to_del = lua_check_regexp (L);
+ struct rspamd_lua_regexp *to_del = lua_check_regexp (L);
if (to_del) {
re_cache_del (to_del->re_pattern, regexp_static_pool);
@@ -268,7 +266,7 @@ luaopen_glib_regexp (lua_State * L)
lua_pushstring (L, "rspamd{regexp}");
lua_rawset (L, -3);
- luaL_register (L, NULL, regexplib_m);
+ luaL_register (L, NULL, regexplib_m);
luaL_register (L, "regexp", regexplib_f);
regexp_static_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ());
diff --git a/src/lua/lua_rsa.c b/src/lua/lua_rsa.c
index e68fc3da1..38820e4e2 100644
--- a/src/lua/lua_rsa.c
+++ b/src/lua/lua_rsa.c
@@ -32,26 +32,26 @@
#ifdef HAVE_OPENSSL
#include <openssl/err.h>
-#include <openssl/pem.h>
-#include <openssl/rsa.h>
#include <openssl/sha.h>
+#include <openssl/rsa.h>
+#include <openssl/pem.h>
-LUA_FUNCTION_DEF (rsa_pubkey, load);
-LUA_FUNCTION_DEF (rsa_pubkey, create);
-LUA_FUNCTION_DEF (rsa_pubkey, gc);
-LUA_FUNCTION_DEF (rsa_privkey, load);
-LUA_FUNCTION_DEF (rsa_privkey, create);
-LUA_FUNCTION_DEF (rsa_privkey, gc);
+LUA_FUNCTION_DEF (rsa_pubkey, load);
+LUA_FUNCTION_DEF (rsa_pubkey, create);
+LUA_FUNCTION_DEF (rsa_pubkey, gc);
+LUA_FUNCTION_DEF (rsa_privkey, load);
+LUA_FUNCTION_DEF (rsa_privkey, create);
+LUA_FUNCTION_DEF (rsa_privkey, gc);
LUA_FUNCTION_DEF (rsa_signature, create);
LUA_FUNCTION_DEF (rsa_signature, load);
LUA_FUNCTION_DEF (rsa_signature, save);
LUA_FUNCTION_DEF (rsa_signature, gc);
-LUA_FUNCTION_DEF (rsa, verify_memory);
-LUA_FUNCTION_DEF (rsa, verify_file);
-LUA_FUNCTION_DEF (rsa, sign_file);
-LUA_FUNCTION_DEF (rsa, sign_memory);
+LUA_FUNCTION_DEF (rsa, verify_memory);
+LUA_FUNCTION_DEF (rsa, verify_file);
+LUA_FUNCTION_DEF (rsa, sign_file);
+LUA_FUNCTION_DEF (rsa, sign_memory);
-static const struct luaL_reg rsalib_f[] = {
+static const struct luaL_reg rsalib_f[] = {
LUA_INTERFACE_DEF (rsa, verify_memory),
LUA_INTERFACE_DEF (rsa, verify_file),
LUA_INTERFACE_DEF (rsa, sign_memory),
@@ -60,46 +60,46 @@ static const struct luaL_reg rsalib_f[] = {
};
static const struct luaL_reg rsapubkeylib_f[] = {
- LUA_INTERFACE_DEF (rsa_pubkey, load),
- LUA_INTERFACE_DEF (rsa_pubkey, create),
- {NULL, NULL}
+ LUA_INTERFACE_DEF (rsa_pubkey, load),
+ LUA_INTERFACE_DEF (rsa_pubkey, create),
+ {NULL, NULL}
};
static const struct luaL_reg rsapubkeylib_m[] = {
- {"__tostring", lua_class_tostring},
- {"__gc", lua_rsa_pubkey_gc},
- {NULL, NULL}
+ {"__tostring", lua_class_tostring},
+ {"__gc", lua_rsa_pubkey_gc},
+ {NULL, NULL}
};
static const struct luaL_reg rsaprivkeylib_f[] = {
- LUA_INTERFACE_DEF (rsa_privkey, load),
- LUA_INTERFACE_DEF (rsa_privkey, create),
- {NULL, NULL}
+ LUA_INTERFACE_DEF (rsa_privkey, load),
+ LUA_INTERFACE_DEF (rsa_privkey, create),
+ {NULL, NULL}
};
static const struct luaL_reg rsaprivkeylib_m[] = {
- {"__tostring", lua_class_tostring},
- {"__gc", lua_rsa_privkey_gc},
- {NULL, NULL}
+ {"__tostring", lua_class_tostring},
+ {"__gc", lua_rsa_privkey_gc},
+ {NULL, NULL}
};
static const struct luaL_reg rsasignlib_f[] = {
- LUA_INTERFACE_DEF (rsa_signature, load),
- LUA_INTERFACE_DEF (rsa_signature, create),
- {NULL, NULL}
+ LUA_INTERFACE_DEF (rsa_signature, load),
+ LUA_INTERFACE_DEF (rsa_signature, create),
+ {NULL, NULL}
};
static const struct luaL_reg rsasignlib_m[] = {
- LUA_INTERFACE_DEF (rsa_signature, save),
- {"__tostring", lua_class_tostring},
- {"__gc", lua_rsa_signature_gc},
- {NULL, NULL}
+ LUA_INTERFACE_DEF (rsa_signature, save),
+ {"__tostring", lua_class_tostring},
+ {"__gc", lua_rsa_signature_gc},
+ {NULL, NULL}
};
static RSA *
lua_check_rsa_pubkey (lua_State * L, int pos)
{
- void *ud = luaL_checkudata (L, pos, "rspamd{rsa_pubkey}");
+ void *ud = luaL_checkudata (L, pos, "rspamd{rsa_pubkey}");
luaL_argcheck (L, ud != NULL, 1, "'rsa_pubkey' expected");
return ud ? *((RSA **)ud) : NULL;
@@ -108,7 +108,7 @@ lua_check_rsa_pubkey (lua_State * L, int pos)
static RSA *
lua_check_rsa_privkey (lua_State * L, int pos)
{
- void *ud = luaL_checkudata (L, pos, "rspamd{rsa_privkey}");
+ void *ud = luaL_checkudata (L, pos, "rspamd{rsa_privkey}");
luaL_argcheck (L, ud != NULL, 1, "'rsa_privkey' expected");
return ud ? *((RSA **)ud) : NULL;
@@ -117,7 +117,7 @@ lua_check_rsa_privkey (lua_State * L, int pos)
static f_str_t *
lua_check_rsa_sign (lua_State * L, int pos)
{
- void *ud = luaL_checkudata (L, pos, "rspamd{rsa_signature}");
+ void *ud = luaL_checkudata (L, pos, "rspamd{rsa_signature}");
luaL_argcheck (L, ud != NULL, 1, "'rsa_signature' expected");
return ud ? *((f_str_t **)ud) : NULL;
@@ -126,7 +126,7 @@ lua_check_rsa_sign (lua_State * L, int pos)
static gint
lua_rsa_pubkey_load (lua_State *L)
{
- RSA *rsa = NULL, **prsa;
+ RSA *rsa = NULL, **prsa;
const gchar *filename;
FILE *f;
@@ -134,15 +134,13 @@ lua_rsa_pubkey_load (lua_State *L)
if (filename != NULL) {
f = fopen (filename, "r");
if (f == NULL) {
- msg_err ("cannot open pubkey from file: %s, %s",
- filename,
- strerror (errno));
+ msg_err ("cannot open pubkey from file: %s, %s", filename, strerror (errno));
lua_pushnil (L);
}
else {
- if (!PEM_read_RSA_PUBKEY (f, &rsa, NULL, NULL)) {
+ if (! PEM_read_RSA_PUBKEY (f, &rsa, NULL, NULL)) {
msg_err ("cannot open pubkey from file: %s, %s", filename,
- ERR_error_string (ERR_get_error (), NULL));
+ ERR_error_string (ERR_get_error (), NULL));
lua_pushnil (L);
}
else {
@@ -162,7 +160,7 @@ lua_rsa_pubkey_load (lua_State *L)
static gint
lua_rsa_pubkey_create (lua_State *L)
{
- RSA *rsa = NULL, **prsa;
+ RSA *rsa = NULL, **prsa;
const gchar *buf;
BIO *bp;
@@ -170,9 +168,9 @@ lua_rsa_pubkey_create (lua_State *L)
if (buf != NULL) {
bp = BIO_new_mem_buf ((void *)buf, -1);
- if (!PEM_read_bio_RSA_PUBKEY (bp, &rsa, NULL, NULL)) {
+ if (! PEM_read_bio_RSA_PUBKEY (bp, &rsa, NULL, NULL)) {
msg_err ("cannot parse pubkey: %s",
- ERR_error_string (ERR_get_error (), NULL));
+ ERR_error_string (ERR_get_error (), NULL));
lua_pushnil (L);
}
else {
@@ -203,7 +201,7 @@ lua_rsa_pubkey_gc (lua_State *L)
static gint
lua_rsa_privkey_load (lua_State *L)
{
- RSA *rsa = NULL, **prsa;
+ RSA *rsa = NULL, **prsa;
const gchar *filename;
FILE *f;
@@ -211,15 +209,13 @@ lua_rsa_privkey_load (lua_State *L)
if (filename != NULL) {
f = fopen (filename, "r");
if (f == NULL) {
- msg_err ("cannot open private key from file: %s, %s",
- filename,
- strerror (errno));
+ msg_err ("cannot open private key from file: %s, %s", filename, strerror (errno));
lua_pushnil (L);
}
else {
- if (!PEM_read_RSAPrivateKey (f, &rsa, NULL, NULL)) {
+ if (! PEM_read_RSAPrivateKey (f, &rsa, NULL, NULL)) {
msg_err ("cannot open private key from file: %s, %s", filename,
- ERR_error_string (ERR_get_error (), NULL));
+ ERR_error_string (ERR_get_error (), NULL));
lua_pushnil (L);
}
else {
@@ -239,7 +235,7 @@ lua_rsa_privkey_load (lua_State *L)
static gint
lua_rsa_privkey_create (lua_State *L)
{
- RSA *rsa = NULL, **prsa;
+ RSA *rsa = NULL, **prsa;
const gchar *buf;
BIO *bp;
@@ -247,9 +243,9 @@ lua_rsa_privkey_create (lua_State *L)
if (buf != NULL) {
bp = BIO_new_mem_buf ((void *)buf, -1);
- if (!PEM_read_bio_RSAPrivateKey (bp, &rsa, NULL, NULL)) {
+ if (! PEM_read_bio_RSAPrivateKey (bp, &rsa, NULL, NULL)) {
msg_err ("cannot parse private key: %s",
- ERR_error_string (ERR_get_error (), NULL));
+ ERR_error_string (ERR_get_error (), NULL));
lua_pushnil (L);
}
else {
@@ -290,16 +286,13 @@ lua_rsa_signature_load (lua_State *L)
if (filename != NULL) {
fd = open (filename, O_RDONLY);
if (fd == -1) {
- msg_err ("cannot open signature file: %s, %s", filename,
- strerror (errno));
+ msg_err ("cannot open signature file: %s, %s", filename, strerror (errno));
lua_pushnil (L);
}
else {
sig = g_malloc (sizeof (f_str_t));
if (fstat (fd, &st) == -1 ||
- (data =
- mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fd,
- 0)) == MAP_FAILED) {
+ (data = mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) {
msg_err ("cannot mmap file %s: %s", filename, strerror (errno));
lua_pushnil (L);
}
@@ -346,9 +339,7 @@ lua_rsa_signature_save (lua_State *L)
}
fd = open (filename, flags, 00644);
if (fd == -1) {
- msg_err ("cannot create a signature file: %s, %s",
- filename,
- strerror (errno));
+ msg_err ("cannot create a signature file: %s, %s", filename, strerror (errno));
lua_pushboolean (L, FALSE);
}
else {
@@ -356,9 +347,7 @@ lua_rsa_signature_save (lua_State *L)
if (errno == EINTR) {
continue;
}
- msg_err ("cannot write to a signature file: %s, %s",
- filename,
- strerror (errno));
+ msg_err ("cannot write to a signature file: %s, %s", filename, strerror (errno));
res = FALSE;
break;
}
@@ -438,7 +427,7 @@ lua_rsa_verify_memory (lua_State *L)
signature->begin, signature->len, rsa);
if (ret == 0) {
msg_info ("cannot check rsa signature for data: %s",
- ERR_error_string (ERR_get_error (), NULL));
+ ERR_error_string (ERR_get_error (), NULL));
lua_pushboolean (L, FALSE);
}
else {
@@ -485,21 +474,17 @@ lua_rsa_verify_file (lua_State *L)
}
else {
if (fstat (fd, &st) == -1 ||
- (data =
- mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fd,
- 0)) == MAP_FAILED) {
+ (data = mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) {
msg_err ("cannot mmap file %s: %s", filename, strerror (errno));
lua_pushnil (L);
}
else {
- data_sig = g_compute_checksum_for_data (G_CHECKSUM_SHA256,
- data,
- st.st_size);
+ data_sig = g_compute_checksum_for_data (G_CHECKSUM_SHA256, data, st.st_size);
ret = RSA_verify (NID_sha1, data_sig, strlen (data_sig),
signature->begin, signature->len, rsa);
if (ret == 0) {
msg_info ("cannot check rsa signature for file: %s, %s",
- filename, ERR_error_string (ERR_get_error (), NULL));
+ filename, ERR_error_string (ERR_get_error (), NULL));
lua_pushboolean (L, FALSE);
}
else {
@@ -550,7 +535,7 @@ lua_rsa_sign_memory (lua_State *L)
signature->begin, (guint *)&signature->len, rsa);
if (ret == 0) {
msg_info ("cannot make a signature for data: %s",
- ERR_error_string (ERR_get_error (), NULL));
+ ERR_error_string (ERR_get_error (), NULL));
lua_pushnil (L);
g_free (signature->begin);
g_free (signature);
@@ -600,9 +585,7 @@ lua_rsa_sign_file (lua_State *L)
}
else {
if (fstat (fd, &st) == -1 ||
- (data =
- mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fd,
- 0)) == MAP_FAILED) {
+ (data = mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) {
msg_err ("cannot mmap file %s: %s", filename, strerror (errno));
lua_pushnil (L);
}
@@ -611,14 +594,12 @@ lua_rsa_sign_file (lua_State *L)
signature->len = RSA_size (rsa);
signature->size = signature->len;
signature->begin = g_malloc (signature->len);
- data_sig = g_compute_checksum_for_string (G_CHECKSUM_SHA256,
- data,
- st.st_size);
+ data_sig = g_compute_checksum_for_string (G_CHECKSUM_SHA256, data, st.st_size);
ret = RSA_sign (NID_sha1, data_sig, strlen (data_sig),
signature->begin, (guint *)&signature->len, rsa);
if (ret == 0) {
msg_info ("cannot make a signature for data: %s",
- ERR_error_string (ERR_get_error (), NULL));
+ ERR_error_string (ERR_get_error (), NULL));
lua_pushnil (L);
g_free (signature->begin);
g_free (signature);
@@ -653,7 +634,7 @@ luaopen_rsa (lua_State * L)
lua_pushstring (L, "rspamd{rsa_pubkey}");
lua_rawset (L, -3);
- luaL_register (L, NULL, rsapubkeylib_m);
+ luaL_register (L, NULL, rsapubkeylib_m);
luaL_register (L, "rsa_pubkey", rsapubkeylib_f);
luaL_newmetatable (L, "rspamd{rsa_privkey}");
@@ -665,7 +646,7 @@ luaopen_rsa (lua_State * L)
lua_pushstring (L, "rspamd{rsa_privkey}");
lua_rawset (L, -3);
- luaL_register (L, NULL, rsaprivkeylib_m);
+ luaL_register (L, NULL, rsaprivkeylib_m);
luaL_register (L, "rsa_privkey", rsaprivkeylib_f);
luaL_newmetatable (L, "rspamd{rsa_signature}");
@@ -677,10 +658,10 @@ luaopen_rsa (lua_State * L)
lua_pushstring (L, "rspamd{rsa_signature}");
lua_rawset (L, -3);
- luaL_register (L, NULL, rsasignlib_m);
+ luaL_register (L, NULL, rsasignlib_m);
luaL_register (L, "rsa_signature", rsasignlib_f);
- luaL_register (L, "rsa", rsalib_f);
+ luaL_register (L, "rsa", rsalib_f);
return 1;
}
@@ -690,7 +671,7 @@ gint
luaopen_rsa (lua_State * L)
{
msg_info ("this rspamd version is not linked against openssl, therefore no "
- "RSA support is available");
+ "RSA support is available");
return 1;
diff --git a/src/lua/lua_session.c b/src/lua/lua_session.c
index 7cfdcccbe..193488cef 100644
--- a/src/lua/lua_session.c
+++ b/src/lua/lua_session.c
@@ -24,7 +24,7 @@
#include "lua_common.h"
/* Public prototypes */
-struct rspamd_async_session * lua_check_session (lua_State * L);
+struct rspamd_async_session *lua_check_session (lua_State * L);
gint luaopen_session (lua_State * L);
/* Lua bindings */
@@ -34,7 +34,7 @@ LUA_FUNCTION_DEF (session, check_session_pending);
LUA_FUNCTION_DEF (session, create);
LUA_FUNCTION_DEF (session, delete);
-static const struct luaL_reg sessionlib_m[] = {
+static const struct luaL_reg sessionlib_m[] = {
LUA_INTERFACE_DEF (session, register_async_event),
LUA_INTERFACE_DEF (session, remove_normal_event),
LUA_INTERFACE_DEF (session, check_session_pending),
@@ -43,12 +43,12 @@ static const struct luaL_reg sessionlib_m[] = {
{NULL, NULL}
};
-static const struct luaL_reg sessionlib_f[] = {
+static const struct luaL_reg sessionlib_f[] = {
LUA_INTERFACE_DEF (session, create),
{NULL, NULL}
};
-static const struct luaL_reg eventlib_m[] = {
+static const struct luaL_reg eventlib_m[] = {
{"__tostring", lua_class_tostring},
{NULL, NULL}
};
@@ -67,18 +67,18 @@ struct lua_event_udata {
struct rspamd_async_session *session;
};
-struct rspamd_async_session *
+struct rspamd_async_session *
lua_check_session (lua_State * L)
{
- void *ud = luaL_checkudata (L, 1, "rspamd{session}");
+ void *ud = luaL_checkudata (L, 1, "rspamd{session}");
luaL_argcheck (L, ud != NULL, 1, "'session' expected");
return ud ? *((struct rspamd_async_session **)ud) : NULL;
}
-struct rspamd_async_event *
+struct rspamd_async_event *
lua_check_event (lua_State * L, gint pos)
{
- void *ud = luaL_checkudata (L, pos, "rspamd{event}");
+ void *ud = luaL_checkudata (L, pos, "rspamd{event}");
luaL_argcheck (L, ud != NULL, 1, "'event' expected");
return ud ? *((struct rspamd_async_event **)ud) : NULL;
}
@@ -88,14 +88,13 @@ lua_check_event (lua_State * L, gint pos)
static gboolean
lua_session_finalizer (gpointer ud)
{
- struct lua_session_udata *cbdata = ud;
- gboolean res;
+ struct lua_session_udata *cbdata = ud;
+ gboolean res;
/* Call finalizer function */
lua_rawgeti (cbdata->L, LUA_REGISTRYINDEX, cbdata->cbref_fin);
if (lua_pcall (cbdata->L, 0, 1, 0) != 0) {
- msg_info ("call to session finalizer failed: %s",
- lua_tostring (cbdata->L, -1));
+ msg_info ("call to session finalizer failed: %s", lua_tostring (cbdata->L, -1));
}
res = lua_toboolean (cbdata->L, -1);
lua_pop (cbdata->L, 1);
@@ -108,15 +107,14 @@ lua_session_finalizer (gpointer ud)
static void
lua_session_restore (gpointer ud)
{
- struct lua_session_udata *cbdata = ud;
+ struct lua_session_udata *cbdata = ud;
if (cbdata->cbref_restore) {
/* Call restorer function */
lua_rawgeti (cbdata->L, LUA_REGISTRYINDEX, cbdata->cbref_restore);
if (lua_pcall (cbdata->L, 0, 0, 0) != 0) {
- msg_info ("call to session restorer failed: %s",
- lua_tostring (cbdata->L, -1));
+ msg_info ("call to session restorer failed: %s", lua_tostring (cbdata->L, -1));
}
luaL_unref (cbdata->L, LUA_REGISTRYINDEX, cbdata->cbref_restore);
}
@@ -125,15 +123,14 @@ lua_session_restore (gpointer ud)
static void
lua_session_cleanup (gpointer ud)
{
- struct lua_session_udata *cbdata = ud;
+ struct lua_session_udata *cbdata = ud;
if (cbdata->cbref_cleanup) {
/* Call restorer function */
lua_rawgeti (cbdata->L, LUA_REGISTRYINDEX, cbdata->cbref_cleanup);
if (lua_pcall (cbdata->L, 0, 0, 0) != 0) {
- msg_info ("call to session cleanup failed: %s",
- lua_tostring (cbdata->L, -1));
+ msg_info ("call to session cleanup failed: %s", lua_tostring (cbdata->L, -1));
}
luaL_unref (cbdata->L, LUA_REGISTRYINDEX, cbdata->cbref_cleanup);
}
@@ -144,9 +141,9 @@ lua_session_cleanup (gpointer ud)
static int
lua_session_create (lua_State *L)
{
- struct rspamd_async_session *session, **psession;
- struct lua_session_udata *cbdata;
- rspamd_mempool_t *mempool;
+ struct rspamd_async_session *session, **psession;
+ struct lua_session_udata *cbdata;
+ rspamd_mempool_t *mempool;
@@ -189,11 +186,7 @@ lua_session_create (lua_State *L)
cbdata->cbref_cleanup = luaL_ref (L, LUA_REGISTRYINDEX);
}
}
- session = new_async_session (mempool,
- lua_session_finalizer,
- lua_session_restore,
- lua_session_cleanup,
- cbdata);
+ session = new_async_session (mempool, lua_session_finalizer, lua_session_restore, lua_session_cleanup, cbdata);
cbdata->session = session;
psession = lua_newuserdata (L, sizeof (struct rspamd_async_session *));
lua_setclass (L, "rspamd{session}", -1);
@@ -205,7 +198,7 @@ lua_session_create (lua_State *L)
static int
lua_session_delete (lua_State *L)
{
- struct rspamd_async_session *session = lua_check_session (L);
+ struct rspamd_async_session *session = lua_check_session (L);
if (session) {
destroy_session (session);
@@ -221,14 +214,13 @@ lua_session_delete (lua_State *L)
static void
lua_event_fin (gpointer ud)
{
- struct lua_event_udata *cbdata = ud;
+ struct lua_event_udata *cbdata = ud;
if (cbdata->cbref) {
/* Call restorer function */
lua_rawgeti (cbdata->L, LUA_REGISTRYINDEX, cbdata->cbref);
if (lua_pcall (cbdata->L, 0, 0, 0) != 0) {
- msg_info ("call to event finalizer failed: %s",
- lua_tostring (cbdata->L, -1));
+ msg_info ("call to event finalizer failed: %s", lua_tostring (cbdata->L, -1));
}
luaL_unref (cbdata->L, LUA_REGISTRYINDEX, cbdata->cbref);
}
@@ -237,23 +229,18 @@ lua_event_fin (gpointer ud)
static int
lua_session_register_async_event (lua_State *L)
{
- struct rspamd_async_session *session = lua_check_session (L);
- struct lua_event_udata *cbdata;
- gpointer *pdata;
+ struct rspamd_async_session *session = lua_check_session (L);
+ struct lua_event_udata *cbdata;
+ gpointer *pdata;
if (session) {
if (lua_isfunction (L, 1)) {
- cbdata =
- rspamd_mempool_alloc (session->pool,
- sizeof (struct lua_event_udata));
+ cbdata = rspamd_mempool_alloc (session->pool, sizeof (struct lua_event_udata));
cbdata->L = L;
lua_pushvalue (L, 1);
cbdata->cbref = luaL_ref (L, LUA_REGISTRYINDEX);
cbdata->session = session;
- register_async_event (session,
- lua_event_fin,
- cbdata,
- g_quark_from_static_string ("lua event"));
+ register_async_event (session, lua_event_fin, cbdata, g_quark_from_static_string ("lua event"));
pdata = lua_newuserdata (L, sizeof (gpointer));
lua_setclass (L, "rspamd{event}", -1);
*pdata = cbdata;
@@ -270,8 +257,8 @@ lua_session_register_async_event (lua_State *L)
static int
lua_session_remove_normal_event (lua_State *L)
{
- struct rspamd_async_session *session = lua_check_session (L);
- gpointer data;
+ struct rspamd_async_session *session = lua_check_session (L);
+ gpointer data;
if (session) {
data = lua_check_event (L, 2);
@@ -290,10 +277,10 @@ lua_session_remove_normal_event (lua_State *L)
static int
lua_session_check_session_pending (lua_State *L)
{
- struct rspamd_async_session *session = lua_check_session (L);
+ struct rspamd_async_session *session = lua_check_session (L);
if (session) {
-
+
}
else {
lua_pushnil (L);
@@ -314,7 +301,7 @@ luaopen_session (lua_State * L)
lua_pushstring (L, "rspamd{session}");
lua_rawset (L, -3);
- luaL_register (L, NULL, sessionlib_m);
+ luaL_register (L, NULL, sessionlib_m);
luaL_register (L, "rspamd_session", sessionlib_f);
lua_pop (L, 1); /* remove metatable from stack */
@@ -325,5 +312,5 @@ luaopen_session (lua_State * L)
lua_pop (L, 1); /* remove metatable from stack */
- return 1;
+ return 1;
}
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index 6cf8f5d99..0572226be 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -23,27 +23,24 @@
*/
-#include "binlog.h"
-#include "cfg_file.h"
-#include "classifiers/classifiers.h"
-#include "diff.h"
-#include "dns.h"
-#include "expressions.h"
-#include "filter.h"
-#include "images.h"
#include "lua_common.h"
#include "message.h"
+#include "expressions.h"
#include "protocol.h"
+#include "filter.h"
+#include "dns.h"
+#include "util.h"
+#include "images.h"
+#include "cfg_file.h"
#include "statfile.h"
-#include "statfile_sync.h"
#include "tokenizers/tokenizers.h"
-#include "util.h"
+#include "classifiers/classifiers.h"
+#include "binlog.h"
+#include "statfile_sync.h"
+#include "diff.h"
-extern stat_file_t * get_statfile_by_symbol (statfile_pool_t *pool,
- struct rspamd_classifier_config *ccf,
- const gchar *symbol,
- struct rspamd_statfile_config **st,
- gboolean try_create);
+extern stat_file_t* get_statfile_by_symbol (statfile_pool_t *pool, struct rspamd_classifier_config *ccf,
+ const gchar *symbol, struct rspamd_statfile_config **st, gboolean try_create);
/* Task creation */
LUA_FUNCTION_DEF (task, create_empty);
@@ -93,13 +90,13 @@ LUA_FUNCTION_DEF (task, get_metric_score);
LUA_FUNCTION_DEF (task, get_metric_action);
LUA_FUNCTION_DEF (task, learn_statfile);
-static const struct luaL_reg tasklib_f[] = {
+static const struct luaL_reg tasklib_f[] = {
LUA_INTERFACE_DEF (task, create_empty),
LUA_INTERFACE_DEF (task, create_from_buffer),
{NULL, NULL}
};
-static const struct luaL_reg tasklib_m[] = {
+static const struct luaL_reg tasklib_m[] = {
LUA_INTERFACE_DEF (task, get_message),
LUA_INTERFACE_DEF (task, destroy),
LUA_INTERFACE_DEF (task, process_message),
@@ -156,7 +153,7 @@ LUA_FUNCTION_DEF (textpart, get_fuzzy);
LUA_FUNCTION_DEF (textpart, get_language);
LUA_FUNCTION_DEF (textpart, compare_distance);
-static const struct luaL_reg textpartlib_m[] = {
+static const struct luaL_reg textpartlib_m[] = {
LUA_INTERFACE_DEF (textpart, get_content),
LUA_INTERFACE_DEF (textpart, get_length),
LUA_INTERFACE_DEF (textpart, is_empty),
@@ -174,7 +171,7 @@ LUA_FUNCTION_DEF (mimepart, get_length);
LUA_FUNCTION_DEF (mimepart, get_type);
LUA_FUNCTION_DEF (mimepart, get_filename);
-static const struct luaL_reg mimepartlib_m[] = {
+static const struct luaL_reg mimepartlib_m[] = {
LUA_INTERFACE_DEF (mimepart, get_content),
LUA_INTERFACE_DEF (mimepart, get_length),
LUA_INTERFACE_DEF (mimepart, get_type),
@@ -191,7 +188,7 @@ LUA_FUNCTION_DEF (image, get_type);
LUA_FUNCTION_DEF (image, get_filename);
LUA_FUNCTION_DEF (image, get_size);
-static const struct luaL_reg imagelib_m[] = {
+static const struct luaL_reg imagelib_m[] = {
LUA_INTERFACE_DEF (image, get_width),
LUA_INTERFACE_DEF (image, get_height),
LUA_INTERFACE_DEF (image, get_type),
@@ -210,7 +207,7 @@ LUA_FUNCTION_DEF (url, get_text);
LUA_FUNCTION_DEF (url, is_phished);
LUA_FUNCTION_DEF (url, get_phished);
-static const struct luaL_reg urllib_m[] = {
+static const struct luaL_reg urllib_m[] = {
LUA_INTERFACE_DEF (url, get_length),
LUA_INTERFACE_DEF (url, get_host),
LUA_INTERFACE_DEF (url, get_user),
@@ -223,42 +220,42 @@ static const struct luaL_reg urllib_m[] = {
};
/* Utility functions */
-static struct rspamd_task *
+static struct rspamd_task *
lua_check_task (lua_State * L)
{
- void *ud = luaL_checkudata (L, 1, "rspamd{task}");
+ void *ud = luaL_checkudata (L, 1, "rspamd{task}");
luaL_argcheck (L, ud != NULL, 1, "'task' expected");
return ud ? *((struct rspamd_task **)ud) : NULL;
}
-static struct mime_text_part *
+static struct mime_text_part *
lua_check_textpart (lua_State * L)
{
- void *ud = luaL_checkudata (L, 1, "rspamd{textpart}");
+ void *ud = luaL_checkudata (L, 1, "rspamd{textpart}");
luaL_argcheck (L, ud != NULL, 1, "'textpart' expected");
return ud ? *((struct mime_text_part **)ud) : NULL;
}
-static struct mime_part *
+static struct mime_part *
lua_check_mimepart (lua_State * L)
{
- void *ud = luaL_checkudata (L, 1, "rspamd{mimepart}");
+ void *ud = luaL_checkudata (L, 1, "rspamd{mimepart}");
luaL_argcheck (L, ud != NULL, 1, "'mimepart' expected");
return ud ? *((struct mime_part **)ud) : NULL;
}
-static struct rspamd_image *
+static struct rspamd_image *
lua_check_image (lua_State * L)
{
- void *ud = luaL_checkudata (L, 1, "rspamd{image}");
+ void *ud = luaL_checkudata (L, 1, "rspamd{image}");
luaL_argcheck (L, ud != NULL, 1, "'image' expected");
return ud ? *((struct rspamd_image **)ud) : NULL;
}
-static struct uri *
+static struct uri *
lua_check_url (lua_State * L)
{
- void *ud = luaL_checkudata (L, 1, "rspamd{url}");
+ void *ud = luaL_checkudata (L, 1, "rspamd{url}");
luaL_argcheck (L, ud != NULL, 1, "'url' expected");
return ud ? *((struct uri **)ud) : NULL;
}
@@ -268,7 +265,7 @@ lua_check_url (lua_State * L)
static int
lua_task_create_empty (lua_State *L)
{
- struct rspamd_task **ptask, *task;
+ struct rspamd_task **ptask, *task;
task = rspamd_task_new (NULL);
ptask = lua_newuserdata (L, sizeof (gpointer));
@@ -280,9 +277,9 @@ lua_task_create_empty (lua_State *L)
static int
lua_task_create_from_buffer (lua_State *L)
{
- struct rspamd_task **ptask, *task;
- const gchar *data;
- size_t len;
+ struct rspamd_task **ptask, *task;
+ const gchar *data;
+ size_t len;
data = luaL_checklstring (L, 1, &len);
if (data) {
@@ -298,7 +295,7 @@ lua_task_create_from_buffer (lua_State *L)
static int
lua_task_process_message (lua_State *L)
{
- struct rspamd_task *task = lua_check_task (L);
+ struct rspamd_task *task = lua_check_task (L);
if (task != NULL && task->msg != NULL && task->msg->len > 0) {
if (process_message (task) == 0) {
@@ -317,8 +314,8 @@ lua_task_process_message (lua_State *L)
static int
lua_task_set_cfg (lua_State *L)
{
- struct rspamd_task *task = lua_check_task (L);
- void *ud = luaL_checkudata (L, 2, "rspamd{config}");
+ struct rspamd_task *task = lua_check_task (L);
+ void *ud = luaL_checkudata (L, 2, "rspamd{config}");
luaL_argcheck (L, ud != NULL, 1, "'config' expected");
task->cfg = ud ? *((struct rspamd_config **)ud) : NULL;
@@ -328,7 +325,7 @@ lua_task_set_cfg (lua_State *L)
static int
lua_task_destroy (lua_State *L)
{
- struct rspamd_task *task = lua_check_task (L);
+ struct rspamd_task *task = lua_check_task (L);
if (task != NULL) {
rspamd_task_free (task, FALSE);
@@ -340,8 +337,8 @@ lua_task_destroy (lua_State *L)
static int
lua_task_get_message (lua_State * L)
{
- GMimeMessage **pmsg;
- struct rspamd_task *task = lua_check_task (L);
+ GMimeMessage **pmsg;
+ struct rspamd_task *task = lua_check_task (L);
if (task != NULL && task->message != NULL) {
pmsg = lua_newuserdata (L, sizeof (GMimeMessage *));
@@ -357,8 +354,8 @@ lua_task_get_message (lua_State * L)
static int
lua_task_get_mempool (lua_State * L)
{
- rspamd_mempool_t **ppool;
- struct rspamd_task *task = lua_check_task (L);
+ rspamd_mempool_t **ppool;
+ struct rspamd_task *task = lua_check_task (L);
if (task != NULL) {
ppool = lua_newuserdata (L, sizeof (rspamd_mempool_t *));
@@ -374,8 +371,8 @@ lua_task_get_mempool (lua_State * L)
static int
lua_task_get_session (lua_State * L)
{
- struct rspamd_async_session **psession;
- struct rspamd_task *task = lua_check_task (L);
+ struct rspamd_async_session **psession;
+ struct rspamd_task *task = lua_check_task (L);
if (task != NULL) {
psession = lua_newuserdata (L, sizeof (void *));
@@ -391,8 +388,8 @@ lua_task_get_session (lua_State * L)
static int
lua_task_get_ev_base (lua_State * L)
{
- struct event_base **pbase;
- struct rspamd_task *task = lua_check_task (L);
+ struct event_base **pbase;
+ struct rspamd_task *task = lua_check_task (L);
if (task != NULL) {
pbase = lua_newuserdata (L, sizeof (struct event_base *));
@@ -408,23 +405,20 @@ lua_task_get_ev_base (lua_State * L)
static gint
lua_task_insert_result (lua_State * L)
{
- struct rspamd_task *task = lua_check_task (L);
- const gchar *symbol_name, *param;
- double flag;
- GList *params = NULL;
- gint i, top;
+ struct rspamd_task *task = lua_check_task (L);
+ const gchar *symbol_name, *param;
+ double flag;
+ GList *params = NULL;
+ gint i, top;
if (task != NULL) {
- symbol_name =
- rspamd_mempool_strdup (task->task_pool, luaL_checkstring (L, 2));
+ symbol_name = rspamd_mempool_strdup (task->task_pool, luaL_checkstring (L, 2));
flag = luaL_checknumber (L, 3);
top = lua_gettop (L);
/* Get additional options */
for (i = 4; i <= top; i++) {
param = luaL_checkstring (L, i);
- params =
- g_list_prepend (params,
- rspamd_mempool_strdup (task->task_pool, param));
+ params = g_list_prepend (params, rspamd_mempool_strdup (task->task_pool, param));
}
insert_result (task, symbol_name, flag, params);
@@ -435,17 +429,16 @@ lua_task_insert_result (lua_State * L)
static gint
lua_task_set_pre_result (lua_State * L)
{
- struct rspamd_task *task = lua_check_task (L);
- gchar *action_str;
- guint action;
+ struct rspamd_task *task = lua_check_task (L);
+ gchar *action_str;
+ guint action;
if (task != NULL) {
action = luaL_checkinteger (L, 2);
if (action < task->pre_result.action) {
task->pre_result.action = action;
if (lua_gettop (L) >= 3) {
- action_str = rspamd_mempool_strdup (task->task_pool,
- luaL_checkstring (L, 3));
+ action_str = rspamd_mempool_strdup (task->task_pool, luaL_checkstring (L, 3));
task->pre_result.str = action_str;
}
else {
@@ -457,15 +450,15 @@ lua_task_set_pre_result (lua_State * L)
}
struct lua_tree_cb_data {
- lua_State *L;
- int i;
+ lua_State *L;
+ int i;
};
static gboolean
lua_tree_url_callback (gpointer key, gpointer value, gpointer ud)
{
- struct uri **purl;
- struct lua_tree_cb_data *cb = ud;
+ struct uri **purl;
+ struct lua_tree_cb_data *cb = ud;
purl = lua_newuserdata (cb->L, sizeof (struct uri *));
lua_setclass (cb->L, "rspamd{url}", -1);
@@ -478,8 +471,8 @@ lua_tree_url_callback (gpointer key, gpointer value, gpointer ud)
static gint
lua_task_get_urls (lua_State * L)
{
- struct rspamd_task *task = lua_check_task (L);
- struct lua_tree_cb_data cb;
+ struct rspamd_task *task = lua_check_task (L);
+ struct lua_tree_cb_data cb;
if (task) {
lua_newtable (L);
@@ -496,8 +489,8 @@ lua_task_get_urls (lua_State * L)
static gint
lua_task_get_emails (lua_State * L)
{
- struct rspamd_task *task = lua_check_task (L);
- struct lua_tree_cb_data cb;
+ struct rspamd_task *task = lua_check_task (L);
+ struct lua_tree_cb_data cb;
if (task) {
lua_newtable (L);
@@ -514,10 +507,10 @@ lua_task_get_emails (lua_State * L)
static gint
lua_task_get_text_parts (lua_State * L)
{
- gint i = 1;
- struct rspamd_task *task = lua_check_task (L);
- GList *cur;
- struct mime_text_part *part, **ppart;
+ gint i = 1;
+ struct rspamd_task *task = lua_check_task (L);
+ GList *cur;
+ struct mime_text_part *part, **ppart;
if (task != NULL) {
lua_newtable (L);
@@ -540,10 +533,10 @@ lua_task_get_text_parts (lua_State * L)
static gint
lua_task_get_parts (lua_State * L)
{
- gint i = 1;
- struct rspamd_task *task = lua_check_task (L);
- GList *cur;
- struct mime_part *part, **ppart;
+ gint i = 1;
+ struct rspamd_task *task = lua_check_task (L);
+ GList *cur;
+ struct mime_part *part, **ppart;
if (task != NULL) {
lua_newtable (L);
@@ -567,7 +560,7 @@ lua_task_get_parts (lua_State * L)
static gint
lua_task_get_raw_headers (lua_State * L)
{
- struct rspamd_task *task = lua_check_task (L);
+ struct rspamd_task *task = lua_check_task (L);
if (task) {
lua_pushstring (L, task->raw_headers_str);
@@ -582,10 +575,10 @@ lua_task_get_raw_headers (lua_State * L)
static gint
lua_task_get_raw_header_common (lua_State * L, gboolean strong)
{
- struct rspamd_task *task = lua_check_task (L);
- struct raw_header *rh;
- gint i = 1;
- const gchar *name;
+ struct rspamd_task *task = lua_check_task (L);
+ struct raw_header *rh;
+ gint i = 1;
+ const gchar *name;
if (task) {
name = luaL_checkstring (L, 2);
@@ -620,7 +613,7 @@ lua_task_get_raw_header_common (lua_State * L, gboolean strong)
}
/* Create new associated table for a header */
lua_newtable (L);
- lua_set_table_index (L, "name", rh->name);
+ lua_set_table_index (L, "name", rh->name);
lua_set_table_index (L, "value", rh->value);
lua_pushstring (L, "tab_separated");
lua_pushboolean (L, rh->tab_separated);
@@ -656,17 +649,17 @@ lua_task_get_raw_header_strong (lua_State * L)
static gint
lua_task_get_received_headers (lua_State * L)
{
- struct rspamd_task *task = lua_check_task (L);
- GList *cur;
- struct received_header *rh;
- gint i = 1;
+ struct rspamd_task *task = lua_check_task (L);
+ GList *cur;
+ struct received_header *rh;
+ gint i = 1;
if (task) {
lua_newtable (L);
cur = g_list_first (task->received);
while (cur) {
rh = cur->data;
- if (rh->is_error || G_UNLIKELY (
+ if (rh->is_error || G_UNLIKELY(
rh->from_ip == NULL &&
rh->real_ip == NULL &&
rh->real_hostname == NULL &&
@@ -698,8 +691,8 @@ lua_task_get_received_headers (lua_State * L)
static gint
lua_task_get_resolver (lua_State *L)
{
- struct rspamd_task *task = lua_check_task (L);
- struct rspamd_dns_resolver **presolver;
+ struct rspamd_task *task = lua_check_task (L);
+ struct rspamd_dns_resolver **presolver;
if (task != NULL && task->resolver != NULL) {
presolver = lua_newuserdata (L, sizeof (void *));
@@ -716,10 +709,10 @@ lua_task_get_resolver (lua_State *L)
static gint
lua_task_inc_dns_req (lua_State *L)
{
- struct rspamd_task *task = lua_check_task (L);
+ struct rspamd_task *task = lua_check_task (L);
if (task != NULL) {
- task->dns_requests++;
+ task->dns_requests ++;
}
return 0;
@@ -728,11 +721,11 @@ lua_task_inc_dns_req (lua_State *L)
static gint
lua_task_call_rspamd_function (lua_State * L)
{
- struct rspamd_task *task = lua_check_task (L);
- struct expression_function f;
- gint i, top;
- gboolean res;
- gchar *arg;
+ struct rspamd_task *task = lua_check_task (L);
+ struct expression_function f;
+ gint i, top;
+ gboolean res;
+ gchar *arg;
if (task) {
f.name = (gchar *)luaL_checkstring (L, 2);
@@ -776,13 +769,12 @@ lua_push_internet_address (lua_State *L, InternetAddress *ia)
}
return FALSE;
#else
- InternetAddressMailbox *iamb;
+ InternetAddressMailbox *iamb;
if (ia && INTERNET_ADDRESS_IS_MAILBOX (ia)) {
lua_newtable (L);
iamb = INTERNET_ADDRESS_MAILBOX (ia);
lua_set_table_index (L, "name", internet_address_get_name (ia));
- lua_set_table_index (L, "addr",
- internet_address_mailbox_get_addr (iamb));
+ lua_set_table_index (L, "addr", internet_address_mailbox_get_addr (iamb));
return TRUE;
}
return FALSE;
@@ -795,12 +787,12 @@ lua_push_internet_address (lua_State *L, InternetAddress *ia)
static void
lua_push_internet_address_list (lua_State *L, InternetAddressList *addrs)
{
- InternetAddress *ia;
- gint idx = 1;
+ InternetAddress *ia;
+ gint idx = 1;
#ifndef GMIME24
/* Gmime 2.2 version */
- InternetAddressList *cur;
+ InternetAddressList *cur;
lua_newtable (L);
cur = addrs;
@@ -813,12 +805,12 @@ lua_push_internet_address_list (lua_State *L, InternetAddressList *addrs)
}
#else
/* Gmime 2.4 version */
- gsize len, i;
+ gsize len, i;
lua_newtable (L);
if (addrs != NULL) {
len = internet_address_list_length (addrs);
- for (i = 0; i < len; i++) {
+ for (i = 0; i < len; i ++) {
ia = internet_address_list_get_address (addrs, i);
if (lua_push_internet_address (L, ia)) {
lua_rawseti (L, -2, idx++);
@@ -831,10 +823,10 @@ lua_push_internet_address_list (lua_State *L, InternetAddressList *addrs)
static gint
lua_task_get_recipients (lua_State *L)
{
- struct rspamd_task *task = lua_check_task (L);
- GList *cur;
- InternetAddressList *addrs;
- gint idx = 1;
+ struct rspamd_task *task = lua_check_task (L);
+ GList *cur;
+ InternetAddressList *addrs;
+ gint idx = 1;
if (task) {
cur = task->rcpt;
@@ -844,8 +836,7 @@ lua_task_get_recipients (lua_State *L)
#ifndef GMIME24
addrs = internet_address_parse_string (cur->data);
if (addrs) {
- if (lua_push_internet_address (L,
- internet_address_list_get_address (addrs))) {
+ if (lua_push_internet_address (L, internet_address_list_get_address (addrs))) {
lua_rawseti (L, -2, idx++);
}
internet_address_list_destroy (addrs);
@@ -854,8 +845,7 @@ lua_task_get_recipients (lua_State *L)
addrs = internet_address_list_parse_string (cur->data);
if (addrs) {
- if (lua_push_internet_address (L,
- internet_address_list_get_address (addrs, 0))) {
+ if (lua_push_internet_address (L, internet_address_list_get_address (addrs, 0))) {
lua_rawseti (L, -2, idx++);
}
g_object_unref (addrs);
@@ -874,9 +864,9 @@ lua_task_get_recipients (lua_State *L)
static gint
lua_task_get_from (lua_State *L)
{
- struct rspamd_task *task = lua_check_task (L);
- InternetAddressList *addrs;
-
+ struct rspamd_task *task = lua_check_task (L);
+ InternetAddressList *addrs;
+
if (task) {
if (task->from != NULL) {
#ifndef GMIME24
@@ -886,7 +876,7 @@ lua_task_get_from (lua_State *L)
#endif
if (addrs != NULL) {
lua_push_internet_address_list (L, addrs);
-#ifndef GMIME24
+#ifndef GMIME24
internet_address_list_destroy (addrs);
#else
g_object_unref (addrs);
@@ -907,8 +897,8 @@ lua_task_get_from (lua_State *L)
static gint
lua_task_set_from (lua_State *L)
{
- struct rspamd_task *task = lua_check_task (L);
- const gchar *new_from;
+ struct rspamd_task *task = lua_check_task (L);
+ const gchar *new_from;
if (task) {
new_from = luaL_checkstring (L, 2);
@@ -923,7 +913,7 @@ lua_task_set_from (lua_State *L)
static gint
lua_task_get_user (lua_State *L)
{
- struct rspamd_task *task = lua_check_task (L);
+ struct rspamd_task *task = lua_check_task (L);
if (task && task->user != NULL) {
lua_pushstring (L, task->user);
@@ -937,8 +927,8 @@ lua_task_get_user (lua_State *L)
static gint
lua_task_set_user (lua_State *L)
{
- struct rspamd_task *task = lua_check_task (L);
- const gchar *new_user;
+ struct rspamd_task *task = lua_check_task (L);
+ const gchar *new_user;
if (task) {
new_user = luaL_checkstring (L, 2);
@@ -956,7 +946,7 @@ lua_task_set_user (lua_State *L)
static gint
lua_task_get_recipients_headers (lua_State *L)
{
- struct rspamd_task *task = lua_check_task (L);
+ struct rspamd_task *task = lua_check_task (L);
if (task && task->rcpts) {
lua_push_internet_address_list (L, task->rcpts);
@@ -970,22 +960,18 @@ lua_task_get_recipients_headers (lua_State *L)
static gint
lua_task_get_from_headers (lua_State *L)
{
- struct rspamd_task *task = lua_check_task (L);
- InternetAddressList *addrs;
+ struct rspamd_task *task = lua_check_task (L);
+ InternetAddressList *addrs;
if (task && task->message != NULL) {
#ifndef GMIME24
- addrs =
- internet_address_parse_string (g_mime_message_get_sender (
- task->message));
+ addrs = internet_address_parse_string (g_mime_message_get_sender (task->message));
#else
- addrs =
- internet_address_list_parse_string (g_mime_message_get_sender (task
- ->message));
+ addrs = internet_address_list_parse_string (g_mime_message_get_sender (task->message));
#endif
if (addrs) {
lua_push_internet_address_list (L, addrs);
-#ifndef GMIME24
+#ifndef GMIME24
internet_address_list_destroy (addrs);
#else
g_object_unref (addrs);
@@ -1004,8 +990,8 @@ lua_task_get_from_headers (lua_State *L)
static gint
lua_task_get_from_ip (lua_State *L)
{
- struct rspamd_task *task = lua_check_task (L);
-
+ struct rspamd_task *task = lua_check_task (L);
+
if (task) {
lua_ip_push (L, &task->from_addr);
}
@@ -1034,8 +1020,8 @@ lua_task_get_from_ip_num (lua_State *L)
static gint
lua_task_get_client_ip_num (lua_State *L)
{
- struct rspamd_task *task = lua_check_task (L);
-
+ struct rspamd_task *task = lua_check_task (L);
+
if (task) {
lua_ip_push (L, &task->client_addr);
}
@@ -1049,8 +1035,8 @@ lua_task_get_client_ip_num (lua_State *L)
static gint
lua_task_get_helo (lua_State *L)
{
- struct rspamd_task *task = lua_check_task (L);
-
+ struct rspamd_task *task = lua_check_task (L);
+
if (task) {
if (task->helo != NULL) {
lua_pushstring (L, (gchar *)task->helo);
@@ -1065,8 +1051,8 @@ lua_task_get_helo (lua_State *L)
static gint
lua_task_set_helo (lua_State *L)
{
- struct rspamd_task *task = lua_check_task (L);
- const gchar *new_helo;
+ struct rspamd_task *task = lua_check_task (L);
+ const gchar *new_helo;
if (task) {
new_helo = luaL_checkstring (L, 2);
@@ -1081,7 +1067,7 @@ lua_task_set_helo (lua_State *L)
static gint
lua_task_get_hostname (lua_State *L)
{
- struct rspamd_task *task = lua_check_task (L);
+ struct rspamd_task *task = lua_check_task (L);
if (task) {
if (task->hostname != NULL) {
@@ -1111,14 +1097,13 @@ lua_task_get_hostname (lua_State *L)
static gint
lua_task_set_hostname (lua_State *L)
{
- struct rspamd_task *task = lua_check_task (L);
- const gchar *new_hostname;
+ struct rspamd_task *task = lua_check_task (L);
+ const gchar *new_hostname;
if (task) {
new_hostname = luaL_checkstring (L, 2);
if (new_hostname) {
- task->hostname = rspamd_mempool_strdup (task->task_pool,
- new_hostname);
+ task->hostname = rspamd_mempool_strdup (task->task_pool, new_hostname);
}
}
@@ -1128,10 +1113,10 @@ lua_task_set_hostname (lua_State *L)
static gint
lua_task_get_images (lua_State *L)
{
- struct rspamd_task *task = lua_check_task (L);
- gint i = 1;
- GList *cur;
- struct rspamd_image **pimg;
+ struct rspamd_task *task = lua_check_task (L);
+ gint i = 1;
+ GList *cur;
+ struct rspamd_image **pimg;
if (task) {
cur = task->images;
@@ -1153,15 +1138,12 @@ lua_task_get_images (lua_State *L)
}
static inline gboolean
-lua_push_symbol_result (lua_State *L,
- struct rspamd_task *task,
- struct metric *metric,
- const gchar *symbol)
+lua_push_symbol_result (lua_State *L, struct rspamd_task *task, struct metric *metric, const gchar *symbol)
{
- struct metric_result *metric_res;
- struct symbol *s;
- gint j;
- GList *opt;
+ struct metric_result *metric_res;
+ struct symbol *s;
+ gint j;
+ GList *opt;
metric_res = g_hash_table_lookup (task->results, metric->name);
if (metric_res) {
@@ -1196,12 +1178,12 @@ lua_push_symbol_result (lua_State *L,
static gint
lua_task_get_symbol (lua_State *L)
{
- struct rspamd_task *task = lua_check_task (L);
- const gchar *symbol;
- struct metric *metric;
- GList *cur = NULL, *metric_list;
- gboolean found = FALSE;
- gint i = 1;
+ struct rspamd_task *task = lua_check_task (L);
+ const gchar *symbol;
+ struct metric *metric;
+ GList *cur = NULL, *metric_list;
+ gboolean found = FALSE;
+ gint i = 1;
symbol = luaL_checkstring (L, 2);
@@ -1242,8 +1224,8 @@ lua_task_get_symbol (lua_State *L)
static gint
lua_task_get_date (lua_State *L)
{
- struct rspamd_task *task = lua_check_task (L);
- time_t task_time;
+ struct rspamd_task *task = lua_check_task (L);
+ time_t task_time;
if (task != NULL) {
/* Get GMT date and store it to time_t */
@@ -1260,7 +1242,7 @@ lua_task_get_date (lua_State *L)
static gint
lua_task_get_message_id (lua_State *L)
{
- struct rspamd_task *task = lua_check_task (L);
+ struct rspamd_task *task = lua_check_task (L);
if (task != NULL && task->message_id != NULL) {
lua_pushstring (L, task->message_id);
@@ -1275,7 +1257,7 @@ lua_task_get_message_id (lua_State *L)
static gint
lua_task_get_timeval (lua_State *L)
{
- struct rspamd_task *task = lua_check_task (L);
+ struct rspamd_task *task = lua_check_task (L);
if (task != NULL) {
lua_newtable (L);
@@ -1297,13 +1279,13 @@ lua_task_get_timeval (lua_State *L)
static gint
lua_task_learn_statfile (lua_State *L)
{
- struct rspamd_task *task = lua_check_task (L);
- const gchar *symbol;
- struct rspamd_classifier_config *cl;
- GTree *tokens;
- struct rspamd_statfile_config *st;
- stat_file_t *statfile;
- struct classifier_ctx *ctx;
+ struct rspamd_task *task = lua_check_task (L);
+ const gchar *symbol;
+ struct rspamd_classifier_config *cl;
+ GTree *tokens;
+ struct rspamd_statfile_config *st;
+ stat_file_t *statfile;
+ struct classifier_ctx *ctx;
symbol = luaL_checkstring (L, 2);
@@ -1315,17 +1297,13 @@ lua_task_learn_statfile (lua_State *L)
return 1;
}
ctx = cl->classifier->init_func (task->task_pool, cl);
- if ((tokens =
- g_hash_table_lookup (task->tokens, cl->tokenizer)) == NULL) {
+ if ((tokens = g_hash_table_lookup (task->tokens, cl->tokenizer)) == NULL) {
msg_warn ("no tokens found learn failed!");
lua_pushboolean (L, FALSE);
return 1;
}
- statfile = get_statfile_by_symbol (task->worker->srv->statfile_pool,
- ctx->cfg,
- symbol,
- &st,
- TRUE);
+ statfile = get_statfile_by_symbol (task->worker->srv->statfile_pool, ctx->cfg,
+ symbol, &st, TRUE);
if (statfile == NULL) {
msg_warn ("opening statfile failed!");
@@ -1333,14 +1311,7 @@ lua_task_learn_statfile (lua_State *L)
return 1;
}
- cl->classifier->learn_func (ctx,
- task->worker->srv->statfile_pool,
- symbol,
- tokens,
- TRUE,
- NULL,
- 1.,
- NULL);
+ cl->classifier->learn_func (ctx, task->worker->srv->statfile_pool, symbol, tokens, TRUE, NULL, 1., NULL);
maybe_write_binlog (ctx->cfg, st, statfile, tokens);
lua_pushboolean (L, TRUE);
}
@@ -1351,23 +1322,20 @@ lua_task_learn_statfile (lua_State *L)
static gint
lua_task_get_metric_score (lua_State *L)
{
- struct rspamd_task *task = lua_check_task (L);
- const gchar *metric_name;
- struct metric_result *metric_res;
+ struct rspamd_task *task = lua_check_task (L);
+ const gchar *metric_name;
+ struct metric_result *metric_res;
metric_name = luaL_checkstring (L, 2);
if (task && metric_name) {
- if ((metric_res =
- g_hash_table_lookup (task->results, metric_name)) != NULL) {
+ if ((metric_res = g_hash_table_lookup (task->results, metric_name)) != NULL) {
lua_newtable (L);
lua_pushnumber (L, metric_res->score);
lua_rawseti (L, -2, 1);
- lua_pushnumber (L,
- metric_res->metric->actions[METRIC_ACTION_REJECT].score);
+ lua_pushnumber (L, metric_res->metric->actions[METRIC_ACTION_REJECT].score);
lua_rawseti (L, -2, 2);
- lua_pushnumber (L,
- metric_res->metric->actions[METRIC_ACTION_REJECT].score);
+ lua_pushnumber (L, metric_res->metric->actions[METRIC_ACTION_REJECT].score);
lua_rawseti (L, -2, 3);
}
else {
@@ -1382,19 +1350,17 @@ lua_task_get_metric_score (lua_State *L)
static gint
lua_task_get_metric_action (lua_State *L)
{
- struct rspamd_task *task = lua_check_task (L);
- const gchar *metric_name;
- struct metric_result *metric_res;
- enum rspamd_metric_action action;
+ struct rspamd_task *task = lua_check_task (L);
+ const gchar *metric_name;
+ struct metric_result *metric_res;
+ enum rspamd_metric_action action;
metric_name = luaL_checkstring (L, 2);
if (task && metric_name) {
- if ((metric_res =
- g_hash_table_lookup (task->results, metric_name)) != NULL) {
+ if ((metric_res = g_hash_table_lookup (task->results, metric_name)) != NULL) {
action = check_metric_action (metric_res->score,
- metric_res->metric->actions[METRIC_ACTION_REJECT].score,
- metric_res->metric);
+ metric_res->metric->actions[METRIC_ACTION_REJECT].score, metric_res->metric);
lua_pushstring (L, str_action_metric (action));
}
else {
@@ -1411,7 +1377,7 @@ lua_task_get_metric_action (lua_State *L)
static gint
lua_textpart_get_content (lua_State * L)
{
- struct mime_text_part *part = lua_check_textpart (L);
+ struct mime_text_part *part = lua_check_textpart (L);
if (part == NULL || part->is_empty) {
lua_pushnil (L);
@@ -1426,7 +1392,7 @@ lua_textpart_get_content (lua_State * L)
static gint
lua_textpart_get_length (lua_State * L)
{
- struct mime_text_part *part = lua_check_textpart (L);
+ struct mime_text_part *part = lua_check_textpart (L);
if (part == NULL) {
lua_pushnil (L);
@@ -1446,7 +1412,7 @@ lua_textpart_get_length (lua_State * L)
static gint
lua_textpart_is_empty (lua_State * L)
{
- struct mime_text_part *part = lua_check_textpart (L);
+ struct mime_text_part *part = lua_check_textpart (L);
if (part == NULL) {
lua_pushnil (L);
@@ -1461,7 +1427,7 @@ lua_textpart_is_empty (lua_State * L)
static gint
lua_textpart_is_html (lua_State * L)
{
- struct mime_text_part *part = lua_check_textpart (L);
+ struct mime_text_part *part = lua_check_textpart (L);
if (part == NULL) {
lua_pushnil (L);
@@ -1476,108 +1442,106 @@ lua_textpart_is_html (lua_State * L)
static gint
lua_textpart_get_fuzzy (lua_State * L)
{
- struct mime_text_part *part = lua_check_textpart (L);
+ struct mime_text_part *part = lua_check_textpart (L);
if (part == NULL || part->is_empty) {
lua_pushnil (L);
return 1;
}
- lua_pushlstring (L, part->fuzzy->hash_pipe,
- sizeof (part->fuzzy->hash_pipe));
+ lua_pushlstring (L, part->fuzzy->hash_pipe, sizeof (part->fuzzy->hash_pipe));
return 1;
}
static gint
lua_textpart_get_language (lua_State * L)
{
- struct mime_text_part *part = lua_check_textpart (L);
- static const gchar languages[][4] = {
- "", /* G_UNICODE_SCRIPT_COMMON */
- "", /* G_UNICODE_SCRIPT_INHERITED */
- "ar", /* G_UNICODE_SCRIPT_ARABIC */
- "hy", /* G_UNICODE_SCRIPT_ARMENIAN */
- "bn", /* G_UNICODE_SCRIPT_BENGALI */
- /* Used primarily in Taiwan, but not part of the standard
- * zh-tw orthography */
- "", /* G_UNICODE_SCRIPT_BOPOMOFO */
- "chr", /* G_UNICODE_SCRIPT_CHEROKEE */
- "cop", /* G_UNICODE_SCRIPT_COPTIC */
- "ru", /* G_UNICODE_SCRIPT_CYRILLIC */
- /* Deseret was used to write English */
- "", /* G_UNICODE_SCRIPT_DESERET */
- "hi", /* G_UNICODE_SCRIPT_DEVANAGARI */
- "am", /* G_UNICODE_SCRIPT_ETHIOPIC */
- "ka", /* G_UNICODE_SCRIPT_GEORGIAN */
- "", /* G_UNICODE_SCRIPT_GOTHIC */
- "el", /* G_UNICODE_SCRIPT_GREEK */
- "gu", /* G_UNICODE_SCRIPT_GUJARATI */
- "pa", /* G_UNICODE_SCRIPT_GURMUKHI */
- "", /* G_UNICODE_SCRIPT_HAN */
- "ko", /* G_UNICODE_SCRIPT_HANGUL */
- "he", /* G_UNICODE_SCRIPT_HEBREW */
- "ja", /* G_UNICODE_SCRIPT_HIRAGANA */
- "kn", /* G_UNICODE_SCRIPT_KANNADA */
- "ja", /* G_UNICODE_SCRIPT_KATAKANA */
- "km", /* G_UNICODE_SCRIPT_KHMER */
- "lo", /* G_UNICODE_SCRIPT_LAO */
- "en", /* G_UNICODE_SCRIPT_LATIN */
- "ml", /* G_UNICODE_SCRIPT_MALAYALAM */
- "mn", /* G_UNICODE_SCRIPT_MONGOLIAN */
- "my", /* G_UNICODE_SCRIPT_MYANMAR */
- /* Ogham was used to write old Irish */
- "", /* G_UNICODE_SCRIPT_OGHAM */
- "", /* G_UNICODE_SCRIPT_OLD_ITALIC */
- "or", /* G_UNICODE_SCRIPT_ORIYA */
- "", /* G_UNICODE_SCRIPT_RUNIC */
- "si", /* G_UNICODE_SCRIPT_SINHALA */
- "syr", /* G_UNICODE_SCRIPT_SYRIAC */
- "ta", /* G_UNICODE_SCRIPT_TAMIL */
- "te", /* G_UNICODE_SCRIPT_TELUGU */
- "dv", /* G_UNICODE_SCRIPT_THAANA */
- "th", /* G_UNICODE_SCRIPT_THAI */
- "bo", /* G_UNICODE_SCRIPT_TIBETAN */
- "iu", /* G_UNICODE_SCRIPT_CANADIAN_ABORIGINAL */
- "", /* G_UNICODE_SCRIPT_YI */
- "tl", /* G_UNICODE_SCRIPT_TAGALOG */
- /* Phillipino languages/scripts */
- "hnn", /* G_UNICODE_SCRIPT_HANUNOO */
- "bku", /* G_UNICODE_SCRIPT_BUHID */
- "tbw", /* G_UNICODE_SCRIPT_TAGBANWA */
-
- "", /* G_UNICODE_SCRIPT_BRAILLE */
- "", /* G_UNICODE_SCRIPT_CYPRIOT */
- "", /* G_UNICODE_SCRIPT_LIMBU */
- /* Used for Somali (so) in the past */
- "", /* G_UNICODE_SCRIPT_OSMANYA */
- /* The Shavian alphabet was designed for English */
- "", /* G_UNICODE_SCRIPT_SHAVIAN */
- "", /* G_UNICODE_SCRIPT_LINEAR_B */
- "", /* G_UNICODE_SCRIPT_TAI_LE */
- "uga", /* G_UNICODE_SCRIPT_UGARITIC */
-
- "", /* G_UNICODE_SCRIPT_NEW_TAI_LUE */
- "bug", /* G_UNICODE_SCRIPT_BUGINESE */
- /* The original script for Old Church Slavonic (chu), later
- * written with Cyrillic */
- "", /* G_UNICODE_SCRIPT_GLAGOLITIC */
- /* Used for for Berber (ber), but Arabic script is more common */
- "", /* G_UNICODE_SCRIPT_TIFINAGH */
- "syl", /* G_UNICODE_SCRIPT_SYLOTI_NAGRI */
- "peo", /* G_UNICODE_SCRIPT_OLD_PERSIAN */
- "", /* G_UNICODE_SCRIPT_KHAROSHTHI */
-
- "", /* G_UNICODE_SCRIPT_UNKNOWN */
- "", /* G_UNICODE_SCRIPT_BALINESE */
- "", /* G_UNICODE_SCRIPT_CUNEIFORM */
- "", /* G_UNICODE_SCRIPT_PHOENICIAN */
- "", /* G_UNICODE_SCRIPT_PHAGS_PA */
- "nqo" /* G_UNICODE_SCRIPT_NKO */
+ struct mime_text_part *part = lua_check_textpart (L);
+ static const gchar languages[][4] = {
+ "", /* G_UNICODE_SCRIPT_COMMON */
+ "", /* G_UNICODE_SCRIPT_INHERITED */
+ "ar", /* G_UNICODE_SCRIPT_ARABIC */
+ "hy", /* G_UNICODE_SCRIPT_ARMENIAN */
+ "bn", /* G_UNICODE_SCRIPT_BENGALI */
+ /* Used primarily in Taiwan, but not part of the standard
+ * zh-tw orthography */
+ "", /* G_UNICODE_SCRIPT_BOPOMOFO */
+ "chr", /* G_UNICODE_SCRIPT_CHEROKEE */
+ "cop", /* G_UNICODE_SCRIPT_COPTIC */
+ "ru", /* G_UNICODE_SCRIPT_CYRILLIC */
+ /* Deseret was used to write English */
+ "", /* G_UNICODE_SCRIPT_DESERET */
+ "hi", /* G_UNICODE_SCRIPT_DEVANAGARI */
+ "am", /* G_UNICODE_SCRIPT_ETHIOPIC */
+ "ka", /* G_UNICODE_SCRIPT_GEORGIAN */
+ "", /* G_UNICODE_SCRIPT_GOTHIC */
+ "el", /* G_UNICODE_SCRIPT_GREEK */
+ "gu", /* G_UNICODE_SCRIPT_GUJARATI */
+ "pa", /* G_UNICODE_SCRIPT_GURMUKHI */
+ "", /* G_UNICODE_SCRIPT_HAN */
+ "ko", /* G_UNICODE_SCRIPT_HANGUL */
+ "he", /* G_UNICODE_SCRIPT_HEBREW */
+ "ja", /* G_UNICODE_SCRIPT_HIRAGANA */
+ "kn", /* G_UNICODE_SCRIPT_KANNADA */
+ "ja", /* G_UNICODE_SCRIPT_KATAKANA */
+ "km", /* G_UNICODE_SCRIPT_KHMER */
+ "lo", /* G_UNICODE_SCRIPT_LAO */
+ "en", /* G_UNICODE_SCRIPT_LATIN */
+ "ml", /* G_UNICODE_SCRIPT_MALAYALAM */
+ "mn", /* G_UNICODE_SCRIPT_MONGOLIAN */
+ "my", /* G_UNICODE_SCRIPT_MYANMAR */
+ /* Ogham was used to write old Irish */
+ "", /* G_UNICODE_SCRIPT_OGHAM */
+ "", /* G_UNICODE_SCRIPT_OLD_ITALIC */
+ "or", /* G_UNICODE_SCRIPT_ORIYA */
+ "", /* G_UNICODE_SCRIPT_RUNIC */
+ "si", /* G_UNICODE_SCRIPT_SINHALA */
+ "syr", /* G_UNICODE_SCRIPT_SYRIAC */
+ "ta", /* G_UNICODE_SCRIPT_TAMIL */
+ "te", /* G_UNICODE_SCRIPT_TELUGU */
+ "dv", /* G_UNICODE_SCRIPT_THAANA */
+ "th", /* G_UNICODE_SCRIPT_THAI */
+ "bo", /* G_UNICODE_SCRIPT_TIBETAN */
+ "iu", /* G_UNICODE_SCRIPT_CANADIAN_ABORIGINAL */
+ "", /* G_UNICODE_SCRIPT_YI */
+ "tl", /* G_UNICODE_SCRIPT_TAGALOG */
+ /* Phillipino languages/scripts */
+ "hnn", /* G_UNICODE_SCRIPT_HANUNOO */
+ "bku", /* G_UNICODE_SCRIPT_BUHID */
+ "tbw", /* G_UNICODE_SCRIPT_TAGBANWA */
+
+ "", /* G_UNICODE_SCRIPT_BRAILLE */
+ "", /* G_UNICODE_SCRIPT_CYPRIOT */
+ "", /* G_UNICODE_SCRIPT_LIMBU */
+ /* Used for Somali (so) in the past */
+ "", /* G_UNICODE_SCRIPT_OSMANYA */
+ /* The Shavian alphabet was designed for English */
+ "", /* G_UNICODE_SCRIPT_SHAVIAN */
+ "", /* G_UNICODE_SCRIPT_LINEAR_B */
+ "", /* G_UNICODE_SCRIPT_TAI_LE */
+ "uga", /* G_UNICODE_SCRIPT_UGARITIC */
+
+ "", /* G_UNICODE_SCRIPT_NEW_TAI_LUE */
+ "bug", /* G_UNICODE_SCRIPT_BUGINESE */
+ /* The original script for Old Church Slavonic (chu), later
+ * written with Cyrillic */
+ "", /* G_UNICODE_SCRIPT_GLAGOLITIC */
+ /* Used for for Berber (ber), but Arabic script is more common */
+ "", /* G_UNICODE_SCRIPT_TIFINAGH */
+ "syl", /* G_UNICODE_SCRIPT_SYLOTI_NAGRI */
+ "peo", /* G_UNICODE_SCRIPT_OLD_PERSIAN */
+ "", /* G_UNICODE_SCRIPT_KHAROSHTHI */
+
+ "", /* G_UNICODE_SCRIPT_UNKNOWN */
+ "", /* G_UNICODE_SCRIPT_BALINESE */
+ "", /* G_UNICODE_SCRIPT_CUNEIFORM */
+ "", /* G_UNICODE_SCRIPT_PHOENICIAN */
+ "", /* G_UNICODE_SCRIPT_PHAGS_PA */
+ "nqo" /* G_UNICODE_SCRIPT_NKO */
};
- const gchar *sel;
+ const gchar *sel;
- if (part != NULL && part->script > 0 && part->script <
- (gint)G_N_ELEMENTS (languages)) {
+ if (part != NULL && part->script > 0 && part->script < (gint)G_N_ELEMENTS (languages)) {
sel = languages[part->script];
if (*sel != '\0') {
lua_pushstring (L, sel);
@@ -1592,11 +1556,11 @@ lua_textpart_get_language (lua_State * L)
static gint
lua_textpart_compare_distance (lua_State * L)
{
- struct mime_text_part *part = lua_check_textpart (L), *other;
- void *ud = luaL_checkudata (L, 2, "rspamd{textpart}");
- gint diff = -1;
- GMimeObject *parent;
- const GMimeContentType *ct;
+ struct mime_text_part *part = lua_check_textpart (L), *other;
+ void *ud = luaL_checkudata (L, 2, "rspamd{textpart}");
+ gint diff = -1;
+ GMimeObject *parent;
+ const GMimeContentType *ct;
luaL_argcheck (L, ud != NULL, 2, "'textpart' expected");
other = ud ? *((struct mime_text_part **)ud) : NULL;
@@ -1605,12 +1569,9 @@ lua_textpart_compare_distance (lua_State * L)
parent = part->parent;
ct = g_mime_object_get_content_type (parent);
#ifndef GMIME24
- if (ct == NULL ||
- !g_mime_content_type_is_type (ct, "multipart", "alternative")) {
+ if (ct == NULL || ! g_mime_content_type_is_type (ct, "multipart", "alternative")) {
#else
- if (ct == NULL ||
- !g_mime_content_type_is_type ((GMimeContentType *)ct, "multipart",
- "alternative")) {
+ if (ct == NULL || ! g_mime_content_type_is_type ((GMimeContentType *)ct, "multipart", "alternative")) {
#endif
diff = -1;
@@ -1618,22 +1579,20 @@ lua_textpart_compare_distance (lua_State * L)
else {
if (!part->is_empty && !other->is_empty) {
if (part->diff_str != NULL && other->diff_str != NULL) {
- diff = compare_diff_distance (part->diff_str,
- other->diff_str);
+ diff = compare_diff_distance (part->diff_str, other->diff_str);
}
else {
diff = fuzzy_compare_parts (part, other);
}
}
- else if ((part->is_empty &&
- !other->is_empty) || (!part->is_empty && other->is_empty)) {
+ else if ((part->is_empty && !other->is_empty) || (!part->is_empty && other->is_empty)) {
/* Empty and non empty parts are different */
diff = 0;
}
}
}
else {
- diff = -1;
+ diff = -1;
}
@@ -1647,7 +1606,7 @@ lua_textpart_compare_distance (lua_State * L)
static gint
lua_mimepart_get_content (lua_State * L)
{
- struct mime_part *part = lua_check_mimepart (L);
+ struct mime_part *part = lua_check_mimepart (L);
if (part == NULL) {
lua_pushnil (L);
@@ -1662,7 +1621,7 @@ lua_mimepart_get_content (lua_State * L)
static gint
lua_mimepart_get_length (lua_State * L)
{
- struct mime_part *part = lua_check_mimepart (L);
+ struct mime_part *part = lua_check_mimepart (L);
if (part == NULL) {
lua_pushnil (L);
@@ -1677,7 +1636,7 @@ lua_mimepart_get_length (lua_State * L)
static gint
lua_mimepart_get_type (lua_State * L)
{
- struct mime_part *part = lua_check_mimepart (L);
+ struct mime_part *part = lua_check_mimepart (L);
if (part == NULL) {
lua_pushnil (L);
@@ -1698,7 +1657,7 @@ lua_mimepart_get_type (lua_State * L)
static gint
lua_mimepart_get_filename (lua_State * L)
{
- struct mime_part *part = lua_check_mimepart (L);
+ struct mime_part *part = lua_check_mimepart (L);
if (part == NULL || part->filename == NULL) {
lua_pushnil (L);
@@ -1714,7 +1673,7 @@ lua_mimepart_get_filename (lua_State * L)
static gint
lua_image_get_width (lua_State *L)
{
- struct rspamd_image *img = lua_check_image (L);
+ struct rspamd_image *img = lua_check_image (L);
if (img != NULL) {
lua_pushnumber (L, img->width);
@@ -1728,7 +1687,7 @@ lua_image_get_width (lua_State *L)
static gint
lua_image_get_height (lua_State *L)
{
- struct rspamd_image *img = lua_check_image (L);
+ struct rspamd_image *img = lua_check_image (L);
if (img != NULL) {
lua_pushnumber (L, img->height);
@@ -1743,7 +1702,7 @@ lua_image_get_height (lua_State *L)
static gint
lua_image_get_type (lua_State *L)
{
- struct rspamd_image *img = lua_check_image (L);
+ struct rspamd_image *img = lua_check_image (L);
if (img != NULL) {
lua_pushstring (L, image_type_str (img->type));
@@ -1758,7 +1717,7 @@ lua_image_get_type (lua_State *L)
static gint
lua_image_get_size (lua_State *L)
{
- struct rspamd_image *img = lua_check_image (L);
+ struct rspamd_image *img = lua_check_image (L);
if (img != NULL) {
lua_pushinteger (L, img->data->len);
@@ -1773,7 +1732,7 @@ lua_image_get_size (lua_State *L)
static gint
lua_image_get_filename (lua_State *L)
{
- struct rspamd_image *img = lua_check_image (L);
+ struct rspamd_image *img = lua_check_image (L);
if (img != NULL && img->filename != NULL) {
lua_pushstring (L, img->filename);
@@ -1789,7 +1748,7 @@ lua_image_get_filename (lua_State *L)
static gint
lua_url_get_length (lua_State *L)
{
- struct uri *url = lua_check_url (L);
+ struct uri *url = lua_check_url (L);
if (url != NULL) {
lua_pushinteger (L, strlen (struri (url)));
@@ -1803,7 +1762,7 @@ lua_url_get_length (lua_State *L)
static gint
lua_url_get_host (lua_State *L)
{
- struct uri *url = lua_check_url (L);
+ struct uri *url = lua_check_url (L);
if (url != NULL) {
lua_pushlstring (L, url->host, url->hostlen);
@@ -1817,7 +1776,7 @@ lua_url_get_host (lua_State *L)
static gint
lua_url_get_user (lua_State *L)
{
- struct uri *url = lua_check_url (L);
+ struct uri *url = lua_check_url (L);
if (url != NULL) {
lua_pushlstring (L, url->user, url->userlen);
@@ -1832,7 +1791,7 @@ lua_url_get_user (lua_State *L)
static gint
lua_url_get_path (lua_State *L)
{
- struct uri *url = lua_check_url (L);
+ struct uri *url = lua_check_url (L);
if (url != NULL) {
lua_pushlstring (L, url->data, url->datalen);
@@ -1847,7 +1806,7 @@ lua_url_get_path (lua_State *L)
static gint
lua_url_get_text (lua_State *L)
{
- struct uri *url = lua_check_url (L);
+ struct uri *url = lua_check_url (L);
if (url != NULL) {
lua_pushstring (L, struri (url));
@@ -1862,7 +1821,7 @@ lua_url_get_text (lua_State *L)
static gint
lua_url_is_phished (lua_State *L)
{
- struct uri *url = lua_check_url (L);
+ struct uri *url = lua_check_url (L);
if (url != NULL) {
lua_pushboolean (L, url->is_phished);
@@ -1877,7 +1836,7 @@ lua_url_is_phished (lua_State *L)
static gint
lua_url_get_phished (lua_State *L)
{
- struct uri **purl, *url = lua_check_url (L);
+ struct uri **purl, *url = lua_check_url (L);
if (url) {
if (url->is_phished && url->phished_url != NULL) {
diff --git a/src/lua/lua_upstream.c b/src/lua/lua_upstream.c
index 255f2d194..ee06fe2c1 100644
--- a/src/lua/lua_upstream.c
+++ b/src/lua/lua_upstream.c
@@ -21,10 +21,10 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "cfg_file.h"
#include "config.h"
#include "lua_common.h"
#include "upstream.h"
+#include "cfg_file.h"
/* Upstream timeouts */
#define DEFAULT_UPSTREAM_ERROR_TIME 10
@@ -41,7 +41,7 @@ LUA_FUNCTION_DEF (upstream_list, get_upstream_by_hash);
LUA_FUNCTION_DEF (upstream_list, get_upstream_round_robin);
LUA_FUNCTION_DEF (upstream_list, get_upstream_master_slave);
-static const struct luaL_reg upstream_list_m[] = {
+static const struct luaL_reg upstream_list_m[] = {
LUA_INTERFACE_DEF (upstream_list, get_upstream_by_hash),
LUA_INTERFACE_DEF (upstream_list, get_upstream_round_robin),
@@ -50,7 +50,7 @@ static const struct luaL_reg upstream_list_m[] = {
{"__gc", lua_upstream_list_destroy},
{NULL, NULL}
};
-static const struct luaL_reg upstream_list_f[] = {
+static const struct luaL_reg upstream_list_f[] = {
LUA_INTERFACE_DEF (upstream_list, create),
{NULL, NULL}
};
@@ -65,7 +65,7 @@ LUA_FUNCTION_DEF (upstream, get_port);
LUA_FUNCTION_DEF (upstream, get_ip_string);
LUA_FUNCTION_DEF (upstream, get_priority);
-static const struct luaL_reg upstream_m[] = {
+static const struct luaL_reg upstream_m[] = {
LUA_INTERFACE_DEF (upstream, ok),
LUA_INTERFACE_DEF (upstream, fail),
LUA_INTERFACE_DEF (upstream, get_ip),
@@ -76,7 +76,7 @@ static const struct luaL_reg upstream_m[] = {
{"__tostring", lua_class_tostring},
{NULL, NULL}
};
-static const struct luaL_reg upstream_f[] = {
+static const struct luaL_reg upstream_f[] = {
LUA_INTERFACE_DEF (upstream, create),
{NULL, NULL}
};
@@ -89,10 +89,10 @@ struct lua_upstream {
gchar *addr;
};
-static struct lua_upstream *
+static struct lua_upstream *
lua_check_upstream (lua_State * L)
{
- void *ud = luaL_checkudata (L, 1, "rspamd{upstream}");
+ void *ud = luaL_checkudata (L, 1, "rspamd{upstream}");
luaL_argcheck (L, ud != NULL, 1, "'upstream' expected");
return ud ? *((struct lua_upstream **)ud) : NULL;
@@ -106,16 +106,15 @@ lua_check_upstream (lua_State * L)
static gint
lua_upstream_create (lua_State *L)
{
- struct lua_upstream *new, **pnew;
- const gchar *def;
+ struct lua_upstream *new, **pnew;
+ const gchar *def;
def = luaL_checkstring (L, 1);
if (def) {
new = g_slice_alloc0 (sizeof (struct lua_upstream));
new->def = g_strdup (def);
new->addr = g_malloc (INET6_ADDRSTRLEN);
- if (!rspamd_parse_host_port_priority (NULL, new->def, &new->addr,
- &new->port, &new->up.priority)) {
+ if (!rspamd_parse_host_port_priority (NULL, new->def, &new->addr, &new->port, &new->up.priority)) {
g_free (new->def);
g_slice_free1 (sizeof (struct lua_upstream), new);
lua_pushnil (L);
@@ -138,7 +137,7 @@ lua_upstream_create (lua_State *L)
static gint
lua_upstream_destroy (lua_State *L)
{
- struct lua_upstream *up = lua_check_upstream (L);
+ struct lua_upstream *up = lua_check_upstream (L);
if (up) {
g_free (up->def);
@@ -157,7 +156,7 @@ lua_upstream_destroy (lua_State *L)
static gint
lua_upstream_get_ip (lua_State *L)
{
- struct lua_upstream *up = lua_check_upstream (L);
+ struct lua_upstream *up = lua_check_upstream (L);
if (up) {
lua_pushstring (L, up->addr);
@@ -177,7 +176,7 @@ lua_upstream_get_ip (lua_State *L)
static gint
lua_upstream_get_ip_string (lua_State *L)
{
- struct lua_upstream *up = lua_check_upstream (L);
+ struct lua_upstream *up = lua_check_upstream (L);
if (up) {
lua_pushstring (L, up->addr);
@@ -197,7 +196,7 @@ lua_upstream_get_ip_string (lua_State *L)
static gint
lua_upstream_get_port (lua_State *L)
{
- struct lua_upstream *up = lua_check_upstream (L);
+ struct lua_upstream *up = lua_check_upstream (L);
if (up) {
lua_pushinteger (L, up->port);
@@ -217,7 +216,7 @@ lua_upstream_get_port (lua_State *L)
static gint
lua_upstream_get_priority (lua_State *L)
{
- struct lua_upstream *up = lua_check_upstream (L);
+ struct lua_upstream *up = lua_check_upstream (L);
if (up) {
lua_pushinteger (L, up->up.priority);
@@ -237,8 +236,8 @@ lua_upstream_get_priority (lua_State *L)
static gint
lua_upstream_fail (lua_State *L)
{
- struct lua_upstream *up = lua_check_upstream (L);
- time_t now;
+ struct lua_upstream *up = lua_check_upstream (L);
+ time_t now;
if (up) {
if (lua_gettop (L) >= 2) {
@@ -261,8 +260,8 @@ lua_upstream_fail (lua_State *L)
static gint
lua_upstream_ok (lua_State *L)
{
- struct lua_upstream *up = lua_check_upstream (L);
- time_t now;
+ struct lua_upstream *up = lua_check_upstream (L);
+ time_t now;
if (up) {
if (lua_gettop (L) >= 2) {
@@ -283,10 +282,10 @@ struct lua_upstream_list {
guint count;
};
-static struct lua_upstream_list *
+static struct lua_upstream_list *
lua_check_upstream_list (lua_State * L)
{
- void *ud = luaL_checkudata (L, 1, "rspamd{upstream_list}");
+ void *ud = luaL_checkudata (L, 1, "rspamd{upstream_list}");
luaL_argcheck (L, ud != NULL, 1, "'upstream_list' expected");
return ud ? *((struct lua_upstream_list **)ud) : NULL;
@@ -300,11 +299,11 @@ lua_check_upstream_list (lua_State * L)
static gint
lua_upstream_list_create (lua_State *L)
{
- struct lua_upstream_list *new, **pnew;
- struct lua_upstream *cur;
- const gchar *def;
- char **tokens;
- guint i, default_port = 0;
+ struct lua_upstream_list *new, **pnew;
+ struct lua_upstream *cur;
+ const gchar *def;
+ char **tokens;
+ guint i, default_port = 0;
def = luaL_checkstring (L, 1);
if (def) {
@@ -318,14 +317,12 @@ lua_upstream_list_create (lua_State *L)
goto err;
}
new->count = g_strv_length (tokens);
- new->upstreams =
- g_slice_alloc0 (new->count * sizeof (struct lua_upstream));
+ new->upstreams = g_slice_alloc0 (new->count * sizeof (struct lua_upstream));
- for (i = 0; i < new->count; i++) {
+ for (i = 0; i < new->count; i ++) {
cur = &new->upstreams[i];
cur->addr = g_malloc (INET6_ADDRSTRLEN);
- if (!rspamd_parse_host_port_priority (NULL, tokens[i], &cur->addr,
- &cur->port, &cur->up.priority)) {
+ if (!rspamd_parse_host_port_priority (NULL, tokens[i], &cur->addr, &cur->port, &cur->up.priority)) {
goto err;
}
if (cur->port == 0) {
@@ -343,14 +340,13 @@ err:
g_strfreev (tokens);
}
if (new->upstreams) {
- for (i = 0; i < new->count; i++) {
+ for (i = 0; i < new->count; i ++) {
cur = &new->upstreams[i];
if (cur->addr) {
g_free (cur->addr);
}
}
- g_slice_free1 (new->count * sizeof (struct lua_upstream),
- new->upstreams);
+ g_slice_free1 (new->count * sizeof (struct lua_upstream), new->upstreams);
}
g_slice_free1 (sizeof (struct lua_upstream_list), new);
lua_pushnil (L);
@@ -365,20 +361,19 @@ err:
static gint
lua_upstream_list_destroy (lua_State *L)
{
- struct lua_upstream_list *upl = lua_check_upstream_list (L);
- struct lua_upstream *cur;
- guint i;
+ struct lua_upstream_list *upl = lua_check_upstream_list (L);
+ struct lua_upstream *cur;
+ guint i;
if (upl) {
if (upl->upstreams) {
- for (i = 0; i < upl->count; i++) {
+ for (i = 0; i < upl->count; i ++) {
cur = &upl->upstreams[i];
if (cur->addr) {
g_free (cur->addr);
}
}
- g_slice_free1 (upl->count * sizeof (struct lua_upstream),
- upl->upstreams);
+ g_slice_free1 (upl->count * sizeof (struct lua_upstream), upl->upstreams);
}
g_slice_free1 (sizeof (struct lua_upstream_list), upl);
}
@@ -394,10 +389,10 @@ lua_upstream_list_destroy (lua_State *L)
static gint
lua_upstream_list_get_upstream_by_hash (lua_State *L)
{
- struct lua_upstream_list *upl;
- struct lua_upstream *selected, **pselected;
- time_t now;
- const gchar *key;
+ struct lua_upstream_list *upl;
+ struct lua_upstream *selected, **pselected;
+ time_t now;
+ const gchar *key;
upl = lua_check_upstream_list (L);
if (upl) {
@@ -409,16 +404,10 @@ lua_upstream_list_get_upstream_by_hash (lua_State *L)
else {
now = time (NULL);
}
- selected = (struct lua_upstream *)get_upstream_by_hash (
- upl->upstreams,
- upl->count,
- sizeof (struct lua_upstream),
- now,
- DEFAULT_UPSTREAM_ERROR_TIME,
- DEFAULT_UPSTREAM_DEAD_TIME,
- DEFAULT_UPSTREAM_MAXERRORS,
- key,
- 0);
+ selected = (struct lua_upstream *)get_upstream_by_hash (upl->upstreams, upl->count,
+ sizeof (struct lua_upstream), now,
+ DEFAULT_UPSTREAM_ERROR_TIME, DEFAULT_UPSTREAM_DEAD_TIME, DEFAULT_UPSTREAM_MAXERRORS,
+ key, 0);
if (selected) {
pselected = lua_newuserdata (L, sizeof (struct lua_upstream *));
lua_setclass (L, "rspamd{upstream}", -1);
@@ -447,9 +436,9 @@ lua_upstream_list_get_upstream_by_hash (lua_State *L)
static gint
lua_upstream_list_get_upstream_round_robin (lua_State *L)
{
- struct lua_upstream_list *upl;
- struct lua_upstream *selected, **pselected;
- time_t now;
+ struct lua_upstream_list *upl;
+ struct lua_upstream *selected, **pselected;
+ time_t now;
upl = lua_check_upstream_list (L);
if (upl) {
@@ -459,14 +448,9 @@ lua_upstream_list_get_upstream_round_robin (lua_State *L)
else {
now = time (NULL);
}
- selected = (struct lua_upstream *)get_upstream_round_robin (
- upl->upstreams,
- upl->count,
- sizeof (struct lua_upstream),
- now,
- DEFAULT_UPSTREAM_ERROR_TIME,
- DEFAULT_UPSTREAM_DEAD_TIME,
- DEFAULT_UPSTREAM_MAXERRORS);
+ selected = (struct lua_upstream *)get_upstream_round_robin (upl->upstreams, upl->count,
+ sizeof (struct lua_upstream), now,
+ DEFAULT_UPSTREAM_ERROR_TIME, DEFAULT_UPSTREAM_DEAD_TIME, DEFAULT_UPSTREAM_MAXERRORS);
if (selected) {
pselected = lua_newuserdata (L, sizeof (struct lua_upstream *));
lua_setclass (L, "rspamd{upstream}", -1);
@@ -491,9 +475,9 @@ lua_upstream_list_get_upstream_round_robin (lua_State *L)
static gint
lua_upstream_list_get_upstream_master_slave (lua_State *L)
{
- struct lua_upstream_list *upl;
- struct lua_upstream *selected, **pselected;
- time_t now;
+ struct lua_upstream_list *upl;
+ struct lua_upstream *selected, **pselected;
+ time_t now;
upl = lua_check_upstream_list (L);
if (upl) {
@@ -503,14 +487,9 @@ lua_upstream_list_get_upstream_master_slave (lua_State *L)
else {
now = time (NULL);
}
- selected = (struct lua_upstream *)get_upstream_master_slave (
- upl->upstreams,
- upl->count,
- sizeof (struct lua_upstream),
- now,
- DEFAULT_UPSTREAM_ERROR_TIME,
- DEFAULT_UPSTREAM_DEAD_TIME,
- DEFAULT_UPSTREAM_MAXERRORS);
+ selected = (struct lua_upstream *)get_upstream_master_slave (upl->upstreams, upl->count,
+ sizeof (struct lua_upstream), now,
+ DEFAULT_UPSTREAM_ERROR_TIME, DEFAULT_UPSTREAM_DEAD_TIME, DEFAULT_UPSTREAM_MAXERRORS);
if (selected) {
pselected = lua_newuserdata (L, sizeof (struct lua_upstream *));
lua_setclass (L, "rspamd{upstream}", -1);
@@ -540,7 +519,7 @@ luaopen_upstream (lua_State * L)
lua_pushstring (L, "rspamd{upstream_list}");
lua_rawset (L, -3);
- luaL_register (L, NULL, upstream_list_m);
+ luaL_register (L, NULL, upstream_list_m);
luaL_register (L, "upstream_list", upstream_list_f);
lua_pop (L, 1); /* remove metatable from stack */
@@ -554,7 +533,7 @@ luaopen_upstream (lua_State * L)
lua_pushstring (L, "rspamd{upstream}");
lua_rawset (L, -3);
- luaL_register (L, NULL, upstream_m);
+ luaL_register (L, NULL, upstream_m);
luaL_register (L, "upstream", upstream_f);
lua_pop (L, 1); /* remove metatable from stack */
diff --git a/src/lua/lua_xmlrpc.c b/src/lua/lua_xmlrpc.c
index 762711c30..4608d2328 100644
--- a/src/lua/lua_xmlrpc.c
+++ b/src/lua/lua_xmlrpc.c
@@ -27,7 +27,7 @@
LUA_FUNCTION_DEF (xmlrpc, parse_reply);
LUA_FUNCTION_DEF (xmlrpc, make_request);
-static const struct luaL_reg xmlrpclib_m[] = {
+static const struct luaL_reg xmlrpclib_m[] = {
LUA_INTERFACE_DEF (xmlrpc, parse_reply),
LUA_INTERFACE_DEF (xmlrpc, make_request),
{"__tostring", lua_class_tostring},
@@ -42,24 +42,13 @@ struct lua_xmlrpc_ud {
lua_State *L;
};
-static void xmlrpc_start_element (GMarkupParseContext *context,
- const gchar *name,
- const gchar **attribute_names,
- const gchar **attribute_values,
- gpointer user_data,
- GError **error);
-static void xmlrpc_end_element (GMarkupParseContext *context,
- const gchar *element_name,
- gpointer user_data,
- GError **error);
-static void xmlrpc_error (GMarkupParseContext *context,
- GError *error,
- gpointer user_data);
-static void xmlrpc_text (GMarkupParseContext *context,
- const gchar *text,
- gsize text_len,
- gpointer user_data,
- GError **error);
+static void xmlrpc_start_element (GMarkupParseContext *context, const gchar *name, const gchar **attribute_names,
+ const gchar **attribute_values, gpointer user_data, GError **error);
+static void xmlrpc_end_element (GMarkupParseContext *context, const gchar *element_name, gpointer user_data,
+ GError **error);
+static void xmlrpc_error (GMarkupParseContext *context, GError *error, gpointer user_data);
+static void xmlrpc_text (GMarkupParseContext *context, const gchar *text, gsize text_len, gpointer user_data,
+ GError **error);
static GMarkupParser xmlrpc_parser = {
.start_element = xmlrpc_start_element,
@@ -76,15 +65,11 @@ xmlrpc_error_quark (void)
}
static void
-xmlrpc_start_element (GMarkupParseContext *context,
- const gchar *name,
- const gchar **attribute_names,
- const gchar **attribute_values,
- gpointer user_data,
- GError **error)
+xmlrpc_start_element (GMarkupParseContext *context, const gchar *name, const gchar **attribute_names,
+ const gchar **attribute_values, gpointer user_data, GError **error)
{
- struct lua_xmlrpc_ud *ud = user_data;
- int last_state;
+ struct lua_xmlrpc_ud *ud = user_data;
+ int last_state;
last_state = ud->parser_state;
@@ -138,7 +123,7 @@ xmlrpc_start_element (GMarkupParseContext *context,
ud->parser_state = 5;
/* Create new param of table type */
lua_newtable (ud->L);
- ud->depth++;
+ ud->depth ++;
}
else if (g_ascii_strcasecmp (name, "string") == 0) {
ud->parser_state = 11;
@@ -208,7 +193,7 @@ xmlrpc_start_element (GMarkupParseContext *context,
ud->parser_state = 5;
/* Create new param of table type */
lua_newtable (ud->L);
- ud->depth++;
+ ud->depth ++;
}
else {
/* Error state */
@@ -218,20 +203,16 @@ xmlrpc_start_element (GMarkupParseContext *context,
}
if (ud->parser_state == 99) {
- g_set_error (error,
- xmlrpc_error_quark (), 1, "xmlrpc parse error on state: %d, while parsing start tag: %s",
- last_state, name);
+ g_set_error (error, xmlrpc_error_quark(), 1, "xmlrpc parse error on state: %d, while parsing start tag: %s",
+ last_state, name);
}
}
static void
-xmlrpc_end_element (GMarkupParseContext *context,
- const gchar *name,
- gpointer user_data,
- GError **error)
+xmlrpc_end_element (GMarkupParseContext *context, const gchar *name, gpointer user_data, GError **error)
{
- struct lua_xmlrpc_ud *ud = user_data;
- int last_state;
+ struct lua_xmlrpc_ud *ud = user_data;
+ int last_state;
last_state = ud->parser_state;
@@ -291,7 +272,7 @@ xmlrpc_end_element (GMarkupParseContext *context,
/* Got tag struct */
if (g_ascii_strcasecmp (name, "struct") == 0) {
ud->parser_state = 4;
- ud->depth--;
+ ud->depth --;
}
else {
/* Error state */
@@ -359,30 +340,25 @@ xmlrpc_end_element (GMarkupParseContext *context,
}
if (ud->parser_state == 99) {
- g_set_error (error,
- xmlrpc_error_quark (), 1, "xmlrpc parse error on state: %d, while parsing end tag: %s",
- last_state, name);
+ g_set_error (error, xmlrpc_error_quark(), 1, "xmlrpc parse error on state: %d, while parsing end tag: %s",
+ last_state, name);
}
}
static void
-xmlrpc_text (GMarkupParseContext *context,
- const gchar *text,
- gsize text_len,
- gpointer user_data,
- GError **error)
+xmlrpc_text (GMarkupParseContext *context, const gchar *text, gsize text_len, gpointer user_data, GError **error)
{
- struct lua_xmlrpc_ud *ud = user_data;
- gint num;
- gdouble dnum;
+ struct lua_xmlrpc_ud *ud = user_data;
+ gint num;
+ gdouble dnum;
/* Strip line */
while (text_len > 0 && g_ascii_isspace (*text)) {
- text++;
- text_len--;
+ text ++;
+ text_len --;
}
while (text_len > 0 && g_ascii_isspace (text[text_len - 1])) {
- text_len--;
+ text_len --;
}
if (text_len > 0) {
@@ -414,7 +390,7 @@ xmlrpc_text (GMarkupParseContext *context,
static void
xmlrpc_error (GMarkupParseContext *context, GError *error, gpointer user_data)
{
- struct lua_xmlrpc_ud *ud = user_data;
+ struct lua_xmlrpc_ud *ud = user_data;
msg_err ("xmlrpc parser error: %s", error->message, ud->parser_state);
}
@@ -422,12 +398,12 @@ xmlrpc_error (GMarkupParseContext *context, GError *error, gpointer user_data)
static gint
lua_xmlrpc_parse_reply (lua_State *L)
{
- const gchar *data;
- GMarkupParseContext *ctx;
- GError *err = NULL;
- struct lua_xmlrpc_ud ud;
- gsize s;
- gboolean res;
+ const gchar *data;
+ GMarkupParseContext *ctx;
+ GError *err = NULL;
+ struct lua_xmlrpc_ud ud;
+ gsize s;
+ gboolean res;
data = luaL_checklstring (L, 1, &s);
@@ -442,7 +418,7 @@ lua_xmlrpc_parse_reply (lua_State *L)
res = g_markup_parse_context_parse (ctx, data, s, &err);
g_markup_parse_context_free (ctx);
- if (!res) {
+ if (! res) {
lua_pushnil (L);
}
}
@@ -455,14 +431,10 @@ lua_xmlrpc_parse_reply (lua_State *L)
}
static gint
-lua_xmlrpc_parse_table (lua_State *L,
- gint pos,
- gchar *databuf,
- gint pr,
- gsize size)
+lua_xmlrpc_parse_table (lua_State *L, gint pos, gchar *databuf, gint pr, gsize size)
{
- gint r = pr, num;
- double dnum;
+ gint r = pr, num;
+ double dnum;
r += rspamd_snprintf (databuf + r, size - r, "<struct>");
lua_pushnil (L); /* first key */
@@ -470,12 +442,10 @@ lua_xmlrpc_parse_table (lua_State *L,
/* uses 'key' (at index -2) and 'value' (at index -1) */
if (lua_type (L, -2) != LUA_TSTRING) {
/* Ignore non sting keys */
- lua_pop (L, 1);
+ lua_pop(L, 1);
continue;
}
- r += rspamd_snprintf (databuf + r,
- size - r,
- "<member><name>%s</name><value>",
+ r += rspamd_snprintf (databuf + r, size - r, "<member><name>%s</name><value>",
lua_tostring (L, -2));
switch (lua_type (L, -1)) {
case LUA_TNUMBER:
@@ -484,22 +454,16 @@ lua_xmlrpc_parse_table (lua_State *L,
/* Try to avoid conversion errors */
if (dnum != (double)num) {
- r += rspamd_snprintf (databuf + r,
- sizeof (databuf) - r,
- "<double>%f</double>",
+ r += rspamd_snprintf (databuf + r, sizeof (databuf) - r, "<double>%f</double>",
dnum);
}
else {
- r += rspamd_snprintf (databuf + r,
- sizeof (databuf) - r,
- "<int>%d</int>",
+ r += rspamd_snprintf (databuf + r, sizeof (databuf) - r, "<int>%d</int>",
num);
}
break;
case LUA_TBOOLEAN:
- r += rspamd_snprintf (databuf + r,
- size - r,
- "<boolean>%d</boolean>",
+ r += rspamd_snprintf (databuf + r, size - r, "<boolean>%d</boolean>",
lua_toboolean (L, -1) ? 1 : 0);
break;
case LUA_TSTRING:
@@ -513,7 +477,7 @@ lua_xmlrpc_parse_table (lua_State *L,
}
r += rspamd_snprintf (databuf + r, size - r, "</value></member>");
/* removes 'value'; keeps 'key' for next iteration */
- lua_pop (L, 1);
+ lua_pop(L, 1);
}
r += rspamd_snprintf (databuf + r, size - r, "</struct>");
@@ -527,10 +491,10 @@ lua_xmlrpc_parse_table (lua_State *L,
static gint
lua_xmlrpc_make_request (lua_State *L)
{
- gchar databuf[BUFSIZ * 2];
- const gchar *func;
- gint r, top, i, num;
- double dnum;
+ gchar databuf[BUFSIZ * 2];
+ const gchar *func;
+ gint r, top, i, num;
+ double dnum;
func = luaL_checkstring (L, 1);
@@ -543,9 +507,7 @@ lua_xmlrpc_make_request (lua_State *L)
top = lua_gettop (L);
/* Get additional options */
for (i = 2; i <= top; i++) {
- r += rspamd_snprintf (databuf + r,
- sizeof (databuf) - r,
- "<param><value>");
+ r += rspamd_snprintf (databuf + r, sizeof (databuf) - r, "<param><value>");
switch (lua_type (L, i)) {
case LUA_TNUMBER:
num = lua_tointeger (L, i);
@@ -553,43 +515,30 @@ lua_xmlrpc_make_request (lua_State *L)
/* Try to avoid conversion errors */
if (dnum != (double)num) {
- r += rspamd_snprintf (databuf + r,
- sizeof (databuf) - r,
- "<double>%f</double>",
- dnum);
+ r += rspamd_snprintf (databuf + r, sizeof (databuf) - r, "<double>%f</double>",
+ dnum);
}
else {
- r += rspamd_snprintf (databuf + r,
- sizeof (databuf) - r,
- "<int>%d</int>",
- num);
+ r += rspamd_snprintf (databuf + r, sizeof (databuf) - r, "<int>%d</int>",
+ num);
}
break;
case LUA_TBOOLEAN:
- r += rspamd_snprintf (databuf + r,
- sizeof (databuf) - r,
- "<boolean>%d</boolean>",
+ r += rspamd_snprintf (databuf + r, sizeof (databuf) - r, "<boolean>%d</boolean>",
lua_toboolean (L, i) ? 1 : 0);
break;
case LUA_TSTRING:
- r += rspamd_snprintf (databuf + r,
- sizeof (databuf) - r,
- "<string>%s</string>",
+ r += rspamd_snprintf (databuf + r, sizeof (databuf) - r, "<string>%s</string>",
lua_tostring (L, i));
break;
case LUA_TTABLE:
- r +=
- lua_xmlrpc_parse_table (L, i, databuf, r, sizeof (databuf));
+ r += lua_xmlrpc_parse_table (L, i, databuf, r, sizeof (databuf));
break;
}
- r += rspamd_snprintf (databuf + r,
- sizeof (databuf) - r,
- "</value></param>");
+ r += rspamd_snprintf (databuf + r, sizeof (databuf) - r, "</value></param>");
}
- r += rspamd_snprintf (databuf + r,
- sizeof (databuf) - r,
- "</params></methodCall>");
+ r += rspamd_snprintf (databuf + r, sizeof (databuf) - r, "</params></methodCall>");
lua_pushlstring (L, databuf, r);
}
else {