/* Get statfile with specified label */ 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; label = luaL_checkstring (L, 2); if (ccf && label) { cur = g_hash_table_lookup (ccf->labels, label); if (cur) { 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); *pst = st; lua_rawseti (L, -2, i++); cur = g_list_next (cur); } return 1; } } lua_pushnil (L); return 1; }
/* Return table of statfiles indexed by name */ 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; if (ccf) { 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 = st; lua_rawseti (L, -2, i++); cur = g_list_next (cur); } } else { lua_pushnil (L); } return 1; }
static gint lua_classifier_register_post_callback (lua_State *L) { struct rspamd_classifier_config *ccf = lua_check_classifier (L); struct classifier_callback_data *cd; const gchar *name; if (ccf) { name = luaL_checkstring (L, 2); if (name) { cd = g_malloc (sizeof (struct classifier_callback_data)); cd->name = g_strdup (name); cd->L = L; ccf->pre_callbacks = g_list_prepend (ccf->pre_callbacks, cd); } } return 0; }
static gint lua_classifier_get_param (lua_State *L) { struct rspamd_classifier_config *ccf = lua_check_classifier (L); const gchar *param; const ucl_object_t *value; param = luaL_checkstring (L, 2); if (ccf != NULL && param != NULL) { value = ucl_object_lookup (ccf->opts, param); if (value != NULL) { ucl_object_push_lua (L, value, true); return 1; } } lua_pushnil (L); return 1; }