aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_classifier.c
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/lua_classifier.c
parente0483657ff6cf1adc828ccce457814d61fe90a0d (diff)
downloadrspamd-fe79d8c5a39f2b717f78cc3f3ef21b3cfc46500b.tar.gz
rspamd-fe79d8c5a39f2b717f78cc3f3ef21b3cfc46500b.zip
Revert "Unify code style."
This reverts commit e0483657ff6cf1adc828ccce457814d61fe90a0d.
Diffstat (limited to 'src/lua/lua_classifier.c')
-rw-r--r--src/lua/lua_classifier.c117
1 files changed, 49 insertions, 68 deletions
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;
}