diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-07-26 10:49:23 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-07-26 10:49:23 +0100 |
commit | 537a7180a0d5132c11636c4fd8b1450cd99d352c (patch) | |
tree | fb9f8c84955a411bdffbd6371ea32f2716fb3687 /src/lua/lua_classifier.c | |
parent | 5fd7a90fdaa33f52c59bdb0ca84451e5c1e22365 (diff) | |
download | rspamd-537a7180a0d5132c11636c4fd8b1450cd99d352c.tar.gz rspamd-537a7180a0d5132c11636c4fd8b1450cd99d352c.zip |
[Rework] Use clang-format to unify formatting in all sources
No meaningful changes.
Diffstat (limited to 'src/lua/lua_classifier.c')
-rw-r--r-- | src/lua/lua_classifier.c | 155 |
1 files changed, 75 insertions, 80 deletions
diff --git a/src/lua/lua_classifier.c b/src/lua/lua_classifier.c index cab488e84..39580a60d 100644 --- a/src/lua/lua_classifier.c +++ b/src/lua/lua_classifier.c @@ -16,220 +16,215 @@ #include "lua_common.h" /* Classifier methods */ -LUA_FUNCTION_DEF (classifier, get_statfiles); -LUA_FUNCTION_DEF (classifier, get_statfile_by_label); -LUA_FUNCTION_DEF (classifier, get_param); +LUA_FUNCTION_DEF(classifier, get_statfiles); +LUA_FUNCTION_DEF(classifier, get_statfile_by_label); +LUA_FUNCTION_DEF(classifier, get_param); static const struct luaL_reg classifierlib_m[] = { - LUA_INTERFACE_DEF (classifier, get_statfiles), - LUA_INTERFACE_DEF (classifier, get_param), - LUA_INTERFACE_DEF (classifier, get_statfile_by_label), + LUA_INTERFACE_DEF(classifier, get_statfiles), + LUA_INTERFACE_DEF(classifier, get_param), + LUA_INTERFACE_DEF(classifier, get_statfile_by_label), {"__tostring", rspamd_lua_class_tostring}, - {NULL, NULL} -}; + {NULL, NULL}}; -LUA_FUNCTION_DEF (statfile, get_symbol); -LUA_FUNCTION_DEF (statfile, get_label); -LUA_FUNCTION_DEF (statfile, is_spam); -LUA_FUNCTION_DEF (statfile, get_param); +LUA_FUNCTION_DEF(statfile, get_symbol); +LUA_FUNCTION_DEF(statfile, get_label); +LUA_FUNCTION_DEF(statfile, is_spam); +LUA_FUNCTION_DEF(statfile, get_param); static const struct luaL_reg statfilelib_m[] = { - LUA_INTERFACE_DEF (statfile, get_symbol), - LUA_INTERFACE_DEF (statfile, get_label), - LUA_INTERFACE_DEF (statfile, is_spam), - LUA_INTERFACE_DEF (statfile, get_param), + LUA_INTERFACE_DEF(statfile, get_symbol), + LUA_INTERFACE_DEF(statfile, get_label), + LUA_INTERFACE_DEF(statfile, is_spam), + LUA_INTERFACE_DEF(statfile, get_param), {"__tostring", rspamd_lua_class_tostring}, - {NULL, NULL} -}; + {NULL, NULL}}; -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 * -lua_check_classifier (lua_State * L) +lua_check_classifier(lua_State *L) { - void *ud = rspamd_lua_check_udata (L, 1, "rspamd{classifier}"); - luaL_argcheck (L, ud != NULL, 1, "'classifier' expected"); - return ud ? *((struct rspamd_classifier_config **)ud) : NULL; + void *ud = rspamd_lua_check_udata(L, 1, "rspamd{classifier}"); + luaL_argcheck(L, ud != NULL, 1, "'classifier' expected"); + return ud ? *((struct rspamd_classifier_config **) ud) : NULL; } /* Return table of statfiles indexed by name */ static gint -lua_classifier_get_statfiles (lua_State *L) +lua_classifier_get_statfiles(lua_State *L) { - struct rspamd_classifier_config *ccf = lua_check_classifier (L); + struct rspamd_classifier_config *ccf = lua_check_classifier(L); GList *cur; struct rspamd_statfile_config *st, **pst; gint i; if (ccf) { - lua_newtable (L); - cur = g_list_first (ccf->statfiles); + lua_newtable(L); + cur = g_list_first(ccf->statfiles); i = 1; while (cur) { st = cur->data; - pst = lua_newuserdata (L, sizeof (struct rspamd_statfile_config *)); - rspamd_lua_setclass (L, "rspamd{statfile}", -1); + pst = lua_newuserdata(L, sizeof(struct rspamd_statfile_config *)); + rspamd_lua_setclass(L, "rspamd{statfile}", -1); *pst = st; - lua_rawseti (L, -2, i++); + lua_rawseti(L, -2, i++); - cur = g_list_next (cur); + cur = g_list_next(cur); } } else { - lua_pushnil (L); + lua_pushnil(L); } return 1; } static gint -lua_classifier_get_param (lua_State *L) +lua_classifier_get_param(lua_State *L) { - struct rspamd_classifier_config *ccf = lua_check_classifier (L); + struct rspamd_classifier_config *ccf = lua_check_classifier(L); const gchar *param; const ucl_object_t *value; - param = luaL_checkstring (L, 2); + param = luaL_checkstring(L, 2); if (ccf != NULL && param != NULL) { - value = ucl_object_lookup (ccf->opts, param); + value = ucl_object_lookup(ccf->opts, param); if (value != NULL) { - ucl_object_push_lua (L, value, true); + ucl_object_push_lua(L, value, true); return 1; } } - lua_pushnil (L); + lua_pushnil(L); return 1; } /* Get statfile with specified label */ static gint -lua_classifier_get_statfile_by_label (lua_State *L) +lua_classifier_get_statfile_by_label(lua_State *L) { - struct rspamd_classifier_config *ccf = lua_check_classifier (L); + 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); + label = luaL_checkstring(L, 2); if (ccf && label) { - cur = g_hash_table_lookup (ccf->labels, label); + cur = g_hash_table_lookup(ccf->labels, label); if (cur) { - lua_newtable (L); + lua_newtable(L); i = 1; while (cur) { st = cur->data; pst = - lua_newuserdata (L, - sizeof (struct rspamd_statfile_config *)); - rspamd_lua_setclass (L, "rspamd{statfile}", -1); + lua_newuserdata(L, + sizeof(struct rspamd_statfile_config *)); + rspamd_lua_setclass(L, "rspamd{statfile}", -1); *pst = st; - lua_rawseti (L, -2, i++); - cur = g_list_next (cur); + lua_rawseti(L, -2, i++); + cur = g_list_next(cur); } return 1; } } - lua_pushnil (L); + lua_pushnil(L); return 1; } /* Statfile functions */ static gint -lua_statfile_get_symbol (lua_State *L) +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); + lua_pushstring(L, st->symbol); } else { - lua_pushnil (L); + lua_pushnil(L); } return 1; } static gint -lua_statfile_get_label (lua_State *L) +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); + lua_pushstring(L, st->label); } else { - lua_pushnil (L); + lua_pushnil(L); } return 1; } static gint -lua_statfile_is_spam (lua_State *L) +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); + lua_pushboolean(L, st->is_spam); } else { - lua_pushnil (L); + lua_pushnil(L); } return 1; } static gint -lua_statfile_get_param (lua_State *L) +lua_statfile_get_param(lua_State *L) { - struct rspamd_statfile_config *st = lua_check_statfile (L); + struct rspamd_statfile_config *st = lua_check_statfile(L); const gchar *param; const ucl_object_t *value; - param = luaL_checkstring (L, 2); + param = luaL_checkstring(L, 2); if (st != NULL && param != NULL) { - value = ucl_object_lookup (st->opts, param); + value = ucl_object_lookup(st->opts, param); if (value != NULL) { - lua_pushstring (L, ucl_object_tostring_forced (value)); + lua_pushstring(L, ucl_object_tostring_forced(value)); return 1; } } - lua_pushnil (L); + lua_pushnil(L); return 1; } static struct rspamd_statfile_config * -lua_check_statfile (lua_State * L) +lua_check_statfile(lua_State *L) { - void *ud = rspamd_lua_check_udata (L, 1, "rspamd{statfile}"); - luaL_argcheck (L, ud != NULL, 1, "'statfile' expected"); - return ud ? *((struct rspamd_statfile_config **)ud) : NULL; + void *ud = rspamd_lua_check_udata(L, 1, "rspamd{statfile}"); + luaL_argcheck(L, ud != NULL, 1, "'statfile' expected"); + return ud ? *((struct rspamd_statfile_config **) ud) : NULL; } /* Open functions */ -void -luaopen_classifier (lua_State * L) +void luaopen_classifier(lua_State *L) { - rspamd_lua_new_class (L, "rspamd{classifier}", classifierlib_m); - lua_pop (L, 1); /* remove metatable from stack */ + rspamd_lua_new_class(L, "rspamd{classifier}", classifierlib_m); + lua_pop(L, 1); /* remove metatable from stack */ } -void -luaopen_statfile (lua_State * L) +void luaopen_statfile(lua_State *L) { - rspamd_lua_new_class (L, "rspamd{statfile}", statfilelib_m); - lua_pop (L, 1); /* remove metatable from stack */ + rspamd_lua_new_class(L, "rspamd{statfile}", statfilelib_m); + lua_pop(L, 1); /* remove metatable from stack */ } - |