}
}
- cur = call_classifier_pre_callbacks (ctx->cfg, task, FALSE, FALSE, L);
+ cur = rspamd_lua_call_cls_pre_callbacks (ctx->cfg, task, FALSE, FALSE, L);
if (cur) {
rspamd_mempool_add_destructor (task->task_pool,
(rspamd_mempool_destruct_t)g_list_free, cur);
}
}
- cur = call_classifier_pre_callbacks (ctx->cfg, task, TRUE, is_spam, L);
+ cur = rspamd_lua_call_cls_pre_callbacks (ctx->cfg, task, TRUE, is_spam, L);
if (cur) {
skip_labels = FALSE;
rspamd_mempool_add_destructor (task->task_pool,
}
}
- cur = call_classifier_pre_callbacks (ctx->cfg, task, FALSE, FALSE, L);
+ cur = rspamd_lua_call_cls_pre_callbacks (ctx->cfg, task, FALSE, FALSE, L);
if (cur) {
rspamd_mempool_add_destructor (task->task_pool,
(rspamd_mempool_destruct_t)g_list_free, cur);
if (sel != NULL) {
#ifdef WITH_LUA
- max = call_classifier_post_callbacks (ctx->cfg, task, max, L);
+ max = rspamd_lua_call_cls_post_callbacks (ctx->cfg, task, max, L);
#endif
#ifdef HAVE_TANHL
max = tanhl (max);
}
pcfg = lua_newuserdata (L, sizeof (struct rspamd_config *));
- lua_setclass (L, "rspamd{config}", -1);
+ rspamd_lua_setclass (L, "rspamd{config}", -1);
*pcfg = cfg;
lua_setglobal (L, "rspamd_config");
cfg->default_metric = def_metric;
/* Lua options */
- (void)lua_post_load_config (cfg);
+ (void)rspamd_lua_post_load_config (cfg);
init_dynamic_config (cfg);
}
/* Call post filters */
if (task->state == WAIT_POST_FILTER && !task->skip_extra_filters) {
- lua_call_post_filters (task);
+ rspamd_lua_call_post_filters (task);
}
task->s->wanna_die = TRUE;
}
}
}
else {
- lua_call_pre_filters (task);
+ rspamd_lua_call_pre_filters (task);
/* We want fin_task after pre filters are processed */
task->s->wanna_die = TRUE;
task->state = WAIT_PRE_FILTER;
LUA_INTERFACE_DEF (io_dispatcher, pause),
LUA_INTERFACE_DEF (io_dispatcher, restore),
LUA_INTERFACE_DEF (io_dispatcher, destroy),
- {"__tostring", lua_class_tostring},
+ {"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
};
lua_rawgeti (cbdata->L, LUA_REGISTRYINDEX, cbdata->cbref_read);
pdispatcher =
lua_newuserdata (cbdata->L, sizeof (struct rspamd_io_dispatcher_s *));
- lua_setclass (cbdata->L, "rspamd{io_dispatcher}", -1);
+ rspamd_lua_setclass (cbdata->L, "rspamd{io_dispatcher}", -1);
*pdispatcher = cbdata->d;
lua_pushlstring (cbdata->L, in->begin, in->len);
pdispatcher =
lua_newuserdata (cbdata->L,
sizeof (struct rspamd_io_dispatcher_s *));
- lua_setclass (cbdata->L, "rspamd{io_dispatcher}", -1);
+ rspamd_lua_setclass (cbdata->L, "rspamd{io_dispatcher}", -1);
*pdispatcher = cbdata->d;
lua_rawgeti (cbdata->L, LUA_REGISTRYINDEX, cbdata->cbref_err);
pdispatcher =
lua_newuserdata (cbdata->L, sizeof (struct rspamd_io_dispatcher_s *));
- lua_setclass (cbdata->L, "rspamd{io_dispatcher}", -1);
+ rspamd_lua_setclass (cbdata->L, "rspamd{io_dispatcher}", -1);
*pdispatcher = cbdata->d;
lua_pushstring (cbdata->L, err->message);
/* Push result */
pdispatcher =
lua_newuserdata (L, sizeof (struct rspamd_io_dispatcher_s *));
- lua_setclass (L, "rspamd{io_dispatcher}", -1);
+ rspamd_lua_setclass (L, "rspamd{io_dispatcher}", -1);
*pdispatcher = io_dispatcher;
}
else {
lua_pop (L, 1); /* remove metatable from stack */
/* Simple event class */
- lua_newclass (L, "rspamd{ev_base}", null_reg);
+ rspamd_lua_new_class (L, "rspamd{ev_base}", null_reg);
luaL_register (L, "rspamd_ev_base", null_reg);
lua_pop (L, 1); /* remove metatable from stack */
static const struct luaL_reg cdblib_m[] = {
LUA_INTERFACE_DEF (cdb, lookup),
LUA_INTERFACE_DEF (cdb, get_name),
- {"__tostring", lua_class_tostring},
+ {"__tostring", rspamd_lua_class_tostring},
{"__gc", lua_cdb_destroy},
{NULL, NULL}
};
}
else {
pcdb = lua_newuserdata (L, sizeof (struct cdb *));
- lua_setclass (L, "rspamd{cdb}", -1);
+ rspamd_lua_setclass (L, "rspamd{cdb}", -1);
*pcdb = cdb;
}
}
/* Do post load initialization based on lua */
void
-lua_post_load_config (struct rspamd_config *cfg)
+rspamd_lua_post_load_config (struct rspamd_config *cfg)
{
lua_State *L = cfg->lua_state;
const gchar *name, *val;
/* Handle lua dynamic config param */
gboolean
-lua_handle_param (struct rspamd_task *task,
+rspamd_lua_handle_param (struct rspamd_task *task,
gchar *mname,
gchar *optname,
enum lua_var_type expected_type,
#define FAKE_RES_VAR "rspamd_res"
gboolean
-lua_check_condition (struct rspamd_config *cfg, const gchar *condition)
+rspamd_lua_check_condition (struct rspamd_config *cfg, const gchar *condition)
{
lua_State *L = cfg->lua_state;
gchar *hostbuf, *condbuf;
/* 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, "pluginsdir", RSPAMD_PLUGINSDIR);
- lua_set_table_index (L, "prefix", RSPAMD_PREFIX);
+ rspamd_lua_table_set (L, "confdir", RSPAMD_CONFDIR);
+ rspamd_lua_table_set (L, "rundir", RSPAMD_RUNDIR);
+ rspamd_lua_table_set (L, "dbdir", RSPAMD_DBDIR);
+ rspamd_lua_table_set (L, "logdir", RSPAMD_LOGDIR);
+ rspamd_lua_table_set (L, "pluginsdir", RSPAMD_PLUGINSDIR);
+ rspamd_lua_table_set (L, "prefix", RSPAMD_PREFIX);
lua_setglobal (L, "rspamd_paths");
/* Make fake string */
LUA_INTERFACE_DEF (classifier, register_post_callback),
LUA_INTERFACE_DEF (classifier, get_statfiles),
LUA_INTERFACE_DEF (classifier, get_statfile_by_label),
- {"__tostring", lua_class_tostring},
+ {"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
};
LUA_INTERFACE_DEF (statfile, get_size),
LUA_INTERFACE_DEF (statfile, is_spam),
LUA_INTERFACE_DEF (statfile, get_param),
- {"__tostring", lua_class_tostring},
+ {"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
};
GList *res = NULL;
pccf = lua_newuserdata (L, sizeof (struct rspamd_classifier_config *));
- lua_setclass (L, "rspamd{classifier}", -1);
+ rspamd_lua_setclass (L, "rspamd{classifier}", -1);
*pccf = ccf;
ptask = lua_newuserdata (L, sizeof (struct rspamd_task *));
- lua_setclass (L, "rspamd{task}", -1);
+ rspamd_lua_setclass (L, "rspamd{task}", -1);
*ptask = task;
lua_pushboolean (L, is_learn);
/* Return list of statfiles that should be checked for this message */
GList *
-call_classifier_pre_callbacks (struct rspamd_classifier_config *ccf,
+rspamd_lua_call_cls_pre_callbacks (struct rspamd_classifier_config *ccf,
struct rspamd_task *task,
gboolean is_learn,
gboolean is_spam,
/* Return result mark for statfile */
double
-call_classifier_post_callbacks (struct rspamd_classifier_config *ccf,
+rspamd_lua_call_cls_post_callbacks (struct rspamd_classifier_config *ccf,
struct rspamd_task *task,
double in,
lua_State *L)
lua_getglobal (L, cd->name);
pccf = lua_newuserdata (L, sizeof (struct rspamd_classifier_config *));
- lua_setclass (L, "rspamd{classifier}", -1);
+ rspamd_lua_setclass (L, "rspamd{classifier}", -1);
*pccf = ccf;
ptask = lua_newuserdata (L, sizeof (struct rspamd_task *));
- lua_setclass (L, "rspamd{task}", -1);
+ rspamd_lua_setclass (L, "rspamd{task}", -1);
*ptask = task;
lua_pushnumber (L, out);
while (cur) {
st = cur->data;
pst = lua_newuserdata (L, sizeof (struct rspamd_statfile_config *));
- lua_setclass (L, "rspamd{statfile}", -1);
+ rspamd_lua_setclass (L, "rspamd{statfile}", -1);
*pst = st;
lua_rawseti (L, -2, i++);
pst =
lua_newuserdata (L,
sizeof (struct rspamd_statfile_config *));
- lua_setclass (L, "rspamd{statfile}", -1);
+ rspamd_lua_setclass (L, "rspamd{statfile}", -1);
*pst = st;
lua_rawseti (L, -2, i++);
cur = g_list_next (cur);
gint
luaopen_classifier (lua_State * L)
{
- lua_newclass (L, "rspamd{classifier}", classifierlib_m);
+ rspamd_lua_new_class (L, "rspamd{classifier}", classifierlib_m);
luaL_register (L, "rspamd_classifier", null_reg);
lua_pop (L, 1); /* remove metatable from stack */
gint
luaopen_statfile (lua_State * L)
{
- lua_newclass (L, "rspamd{statfile}", statfilelib_m);
+ rspamd_lua_new_class (L, "rspamd{statfile}", statfilelib_m);
luaL_register (L, "rspamd_statfile", null_reg);
lua_pop (L, 1); /* remove metatable from stack */
#define MODULE_INIT_FUNC "module_init"
const luaL_reg null_reg[] = {
- {"__tostring", lua_class_tostring},
+ {"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
};
LUA_INTERFACE_DEF (logger, warn),
LUA_INTERFACE_DEF (logger, info),
LUA_INTERFACE_DEF (logger, debug),
- {"__tostring", lua_class_tostring},
+ {"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
};
* @param func table of class methods
*/
void
-lua_newclass (lua_State * L,
+rspamd_lua_new_class (lua_State * L,
const gchar *classname,
const struct luaL_reg *methods)
{
* Create and register new class with static methods and store metatable on top of the stack
*/
void
-lua_newclass_full (lua_State *L,
+rspamd_lua_new_class_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);
+ rspamd_lua_new_class (L, classname, methods);
luaL_register (L, static_name, func);
}
gint
-lua_class_tostring (lua_State * L)
+rspamd_lua_class_tostring (lua_State * L)
{
gchar buf[32];
void
-lua_setclass (lua_State * L, const gchar *classname, gint objidx)
+rspamd_lua_setclass (lua_State * L, const gchar *classname, gint objidx)
{
luaL_getmetatable (L, classname);
if (objidx < 0) {
/* assume that table is at the top */
void
-lua_set_table_index (lua_State * L, const gchar *index, const gchar *value)
+rspamd_lua_table_set (lua_State * L, const gchar *index, const gchar *value)
{
lua_pushstring (L, index);
}
const gchar *
-lua_get_table_index_str (lua_State *L, const gchar *index)
+rspamd_lua_table_get (lua_State *L, const gchar *index)
{
const gchar *result;
}
lua_State *
-init_lua (struct rspamd_config *cfg)
+rspamd_lua_init (struct rspamd_config *cfg)
{
lua_State *L;
* Initialize new locked lua_State structure
*/
struct lua_locked_state *
-init_lua_locked (struct rspamd_config *cfg)
+rspamd_init_lua_locked (struct rspamd_config *cfg)
{
struct lua_locked_state *new;
new = g_slice_alloc (sizeof (struct lua_locked_state));
- new->L = init_lua (cfg);
+ new->L = rspamd_lua_init (cfg);
new->m = rspamd_mutex_new ();
return new;
* Free locked state structure
*/
void
-free_lua_locked (struct lua_locked_state *st)
+rspamd_free_lua_locked (struct lua_locked_state *st)
{
g_assert (st != NULL);
}
gboolean
-init_lua_filters (struct rspamd_config *cfg)
+rspamd_init_lua_filters (struct rspamd_config *cfg)
{
struct rspamd_config **pcfg;
GList *cur, *tmp;
/* Initialize config structure */
pcfg = lua_newuserdata (L, sizeof (struct rspamd_config *));
- lua_setclass (L, "rspamd{config}", -1);
+ rspamd_lua_setclass (L, "rspamd{config}", -1);
*pcfg = cfg;
lua_setglobal (L, "rspamd_config");
cur = g_list_first (cfg->statfiles);
while (cur) {
st = cur->data;
- if (st->normalizer == lua_normalizer_func) {
+ if (st->normalizer == rspamd_lua_normalize) {
tmp = st->normalizer_data;
if (tmp && (tmp = g_list_next (tmp))) {
if (tmp->data) {
/* Callback functions */
gint
-lua_call_filter (const gchar *function, struct rspamd_task *task)
+rspamd_lua_call_filter (const gchar *function, struct rspamd_task *task)
{
gint result;
struct rspamd_task **ptask;
lua_getglobal (L, function);
ptask = lua_newuserdata (L, sizeof (struct rspamd_task *));
- lua_setclass (L, "rspamd{task}", -1);
+ rspamd_lua_setclass (L, "rspamd{task}", -1);
*ptask = task;
if (lua_pcall (L, 1, 1, 0) != 0) {
}
gint
-lua_call_chain_filter (const gchar *function,
+rspamd_lua_call_chain_filter (const gchar *function,
struct rspamd_task *task,
gint *marks,
guint number)
/* Call custom lua function in rspamd expression */
gboolean
-lua_call_expression_func (gpointer lua_data,
+rspamd_lua_call_expression_func (gpointer lua_data,
struct rspamd_task *task, GList *args, gboolean *res)
{
lua_State *L = task->cfg->lua_state;
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);
+ rspamd_lua_setclass (L, "rspamd{task}", -1);
*ptask = task;
/* Now push all arguments */
}
double
-lua_consolidation_func (struct rspamd_task *task,
+rspamd_lua_consolidation_func (struct rspamd_task *task,
const gchar *metric_name,
const gchar *function_name)
{
}
double
-lua_normalizer_func (struct rspamd_config *cfg, long double score, void *params)
+rspamd_lua_normalize (struct rspamd_config *cfg, long double score, void *params)
{
GList *p = params;
long double res = score;
void
-lua_dumpstack (lua_State *L)
+rspamd_lua_dumpstack (lua_State *L)
{
gint i, t, r = 0;
gint top = lua_gettop (L);
}
gpointer
-lua_check_class (lua_State *L, gint index, const gchar *name)
+rspamd_lua_check_class (lua_State *L, gint index, const gchar *name)
{
gpointer p;
/**
* Create and register new class
*/
-void lua_newclass (lua_State *L,
+void rspamd_lua_new_class (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,
+void rspamd_lua_new_class_full (lua_State *L,
const gchar *classname,
const gchar *static_name,
const struct luaL_reg *methods,
/**
* Set class name for object at @param objidx position
*/
-void lua_setclass (lua_State *L, const gchar *classname, gint objidx);
+void rspamd_lua_setclass (lua_State *L, const gchar *classname, gint objidx);
/**
* Set index of table to value (like t['index'] = value)
*/
-void lua_set_table_index (lua_State *L, const gchar *index, const gchar *value);
+void rspamd_lua_table_set (lua_State *L, const gchar *index, const gchar *value);
/**
* Get string value of index in a table (return t['index'])
*/
-const gchar * lua_get_table_index_str (lua_State *L, const gchar *index);
+const gchar * rspamd_lua_table_get (lua_State *L, const gchar *index);
/**
* Convert classname to string
*/
-gint lua_class_tostring (lua_State *L);
+gint rspamd_lua_class_tostring (lua_State *L);
/**
* Check whether the argument at specified index is of the specified class
*/
-gpointer lua_check_class (lua_State *L, gint index, const gchar *name);
+gpointer rspamd_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 * rspamd_lua_init (struct rspamd_config *cfg);
/**
* Load and initialize lua plugins
*/
-gboolean init_lua_filters (struct rspamd_config *cfg);
+gboolean rspamd_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 * rspamd_init_lua_locked (struct rspamd_config *cfg);
/**
* Free locked state structure
*/
-void free_lua_locked (struct lua_locked_state *st);
+void rspamd_free_lua_locked (struct lua_locked_state *st);
/**
* Push lua ip address
*/
-void lua_ip_push (lua_State *L, rspamd_inet_addr_t *addr);
+void rspamd_lua_ip_push (lua_State *L, rspamd_inet_addr_t *addr);
/**
* Push ip address from a string (nil is pushed if a string cannot be converted)
*/
-void lua_ip_push_fromstring (lua_State *L, const gchar *ip_str);
+void rspamd_lua_ip_push_fromstring (lua_State *L, const gchar *ip_str);
/**
* Create type error
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,
+gint rspamd_lua_call_filter (const gchar *function, struct rspamd_task *task);
+gint rspamd_lua_call_chain_filter (const gchar *function,
struct rspamd_task *task,
gint *marks,
guint number);
-double lua_consolidation_func (struct rspamd_task *task,
+double rspamd_lua_consolidation_func (struct rspamd_task *task,
const gchar *metric_name,
const gchar *function_name);
-gboolean lua_call_expression_func (gpointer lua_data,
+gboolean rspamd_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);
+void rspamd_lua_call_post_filters (struct rspamd_task *task);
+void rspamd_lua_call_pre_filters (struct rspamd_task *task);
+void rspamd_lua_dostring (const gchar *line);
/* Classify functions */
-GList * call_classifier_pre_callbacks (struct rspamd_classifier_config *ccf,
+GList * rspamd_lua_call_cls_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,
+double rspamd_lua_call_cls_post_callbacks (struct rspamd_classifier_config *ccf,
struct rspamd_task *task,
double in,
lua_State *L);
-double lua_normalizer_func (struct rspamd_config *cfg,
+double rspamd_lua_normalize (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,
+void rspamd_lua_post_load_config (struct rspamd_config *cfg);
+void rspamd_lua_process_elt (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,
+gboolean rspamd_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,
+gboolean rspamd_lua_check_condition (struct rspamd_config *cfg,
const gchar *condition);
-void lua_dumpstack (lua_State *L);
+void rspamd_lua_dumpstack (lua_State *L);
-struct memory_pool_s * lua_check_mempool (lua_State * L);
+struct memory_pool_s * rspamd_lua_check_mempool (lua_State * L);
#endif /* WITH_LUA */
LUA_INTERFACE_DEF (config, register_post_filter),
LUA_INTERFACE_DEF (config, get_api_version),
LUA_INTERFACE_DEF (config, get_key),
- {"__tostring", lua_class_tostring},
+ {"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
};
static const struct luaL_reg radixlib_m[] = {
LUA_INTERFACE_DEF (radix, get_key),
- {"__tostring", lua_class_tostring},
+ {"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
};
static const struct luaL_reg hashlib_m[] = {
LUA_INTERFACE_DEF (hash_table, get_key),
- {"__tostring", lua_class_tostring},
+ {"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
};
LUA_INTERFACE_DEF (trie, add_pattern),
LUA_INTERFACE_DEF (trie, search_text),
LUA_INTERFACE_DEF (trie, search_task),
- {"__tostring", lua_class_tostring},
+ {"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
};
static const struct luaL_reg trielib_f[] = {
if (cfg != NULL) {
ppool = lua_newuserdata (L, sizeof (rspamd_mempool_t *));
- lua_setclass (L, "rspamd{mempool}", -1);
+ rspamd_lua_setclass (L, "rspamd{mempool}", -1);
*ppool = cfg->cfg_pool;
}
return 1;
if (pclc) {
pclc = lua_newuserdata (L,
sizeof (struct rspamd_classifier_config *));
- lua_setclass (L, "rspamd{classifier}", -1);
+ rspamd_lua_setclass (L, "rspamd{classifier}", -1);
*pclc = clc;
return 1;
}
lua_getglobal (cd->L, cd->callback.name);
}
ptask = lua_newuserdata (cd->L, sizeof (struct rspamd_task *));
- lua_setclass (cd->L, "rspamd{task}", -1);
+ rspamd_lua_setclass (cd->L, "rspamd{task}", -1);
*ptask = task;
/* Now push all arguments */
cur = args;
}
void
-lua_call_post_filters (struct rspamd_task *task)
+rspamd_lua_call_post_filters (struct rspamd_task *task)
{
struct lua_callback_data *cd;
struct rspamd_task **ptask;
lua_getglobal (cd->L, cd->callback.name);
}
ptask = lua_newuserdata (cd->L, sizeof (struct rspamd_task *));
- lua_setclass (cd->L, "rspamd{task}", -1);
+ rspamd_lua_setclass (cd->L, "rspamd{task}", -1);
*ptask = task;
if (lua_pcall (cd->L, 1, 0, 0) != 0) {
}
void
-lua_call_pre_filters (struct rspamd_task *task)
+rspamd_lua_call_pre_filters (struct rspamd_task *task)
{
struct lua_callback_data *cd;
struct rspamd_task **ptask;
lua_getglobal (cd->L, cd->callback.name);
}
ptask = lua_newuserdata (cd->L, sizeof (struct rspamd_task *));
- lua_setclass (cd->L, "rspamd{task}", -1);
+ rspamd_lua_setclass (cd->L, "rspamd{task}", -1);
*ptask = task;
if (lua_pcall (cd->L, 1, 0, 0) != 0) {
}
ud = lua_newuserdata (L, sizeof (radix_tree_t *));
*ud = r;
- lua_setclass (L, "rspamd{radix}", -1);
+ rspamd_lua_setclass (L, "rspamd{radix}", -1);
return 1;
}
*r);
ud = lua_newuserdata (L, sizeof (GHashTable *));
*ud = r;
- lua_setclass (L, "rspamd{hash_table}", -1);
+ rspamd_lua_setclass (L, "rspamd{hash_table}", -1);
return 1;
}
*r);
ud = lua_newuserdata (L, sizeof (GHashTable *));
*ud = r;
- lua_setclass (L, "rspamd{hash_table}", -1);
+ rspamd_lua_setclass (L, "rspamd{hash_table}", -1);
return 1;
}
lua_getglobal (cd->L, cd->callback.name);
}
ptask = lua_newuserdata (cd->L, sizeof (struct rspamd_task *));
- lua_setclass (cd->L, "rspamd{task}", -1);
+ rspamd_lua_setclass (cd->L, "rspamd{task}", -1);
*ptask = task;
if (lua_pcall (cd->L, 1, 0, 0) != 0) {
trie = rspamd_trie_create (icase);
ptrie = lua_newuserdata (L, sizeof (rspamd_trie_t *));
- lua_setclass (L, "rspamd{trie}", -1);
+ rspamd_lua_setclass (L, "rspamd{trie}", -1);
*ptrie = trie;
return 1;
gint
luaopen_config (lua_State * L)
{
- lua_newclass (L, "rspamd{config}", configlib_m);
+ rspamd_lua_new_class (L, "rspamd{config}", configlib_m);
luaL_register (L, "rspamd_config", null_reg);
lua_pop (L, 1); /* remove metatable from stack */
gint
luaopen_radix (lua_State * L)
{
- lua_newclass (L, "rspamd{radix}", radixlib_m);
+ rspamd_lua_new_class (L, "rspamd{radix}", radixlib_m);
luaL_register (L, "rspamd_radix", null_reg);
lua_pop (L, 1); /* remove metatable from stack */
gint
luaopen_hash_table (lua_State * L)
{
- lua_newclass (L, "rspamd{hash_table}", hashlib_m);
+ rspamd_lua_new_class (L, "rspamd{hash_table}", hashlib_m);
luaL_register (L, "rspamd_hash_table", null_reg);
lua_pop (L, 1); /* remove metatable from stack */
LUA_INTERFACE_DEF (dns_resolver, resolve_txt),
LUA_INTERFACE_DEF (dns_resolver, resolve_mx),
LUA_INTERFACE_DEF (dns_resolver, resolve),
- {"__tostring", lua_class_tostring},
+ {"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
};
lua_rawgeti (cd->L, LUA_REGISTRYINDEX, cd->cbref);
presolver = lua_newuserdata (cd->L, sizeof (gpointer));
- lua_setclass (cd->L, "rspamd{resolver}", -1);
+ rspamd_lua_setclass (cd->L, "rspamd{resolver}", -1);
*presolver = cd->resolver;
lua_pushstring (cd->L, cd->to_resolve);
addr.slen = sizeof (addr.addr.s4);
memcpy (&addr.addr.s4.sin_addr, &elt->content.a.addr,
sizeof (addr.addr.s4.sin_addr));
- lua_ip_push (cd->L, &addr);
+ rspamd_lua_ip_push (cd->L, &addr);
lua_rawseti (cd->L, -2, ++i);
break;
case RDNS_REQUEST_AAAA:
addr.slen = sizeof (addr.addr.s6);
memcpy (&addr.addr.s6.sin6_addr, &elt->content.aaa.addr,
sizeof (addr.addr.s6.sin6_addr));
- lua_ip_push (cd->L, &addr);
+ rspamd_lua_ip_push (cd->L, &addr);
lua_rawseti (cd->L, -2, ++i);
break;
case RDNS_REQUEST_PTR:
case RDNS_REQUEST_MX:
/* mx['name'], mx['priority'] */
lua_newtable (cd->L);
- lua_set_table_index (cd->L, "name", elt->content.mx.name);
+ rspamd_lua_table_set (cd->L, "name", elt->content.mx.name);
lua_pushstring (cd->L, "priority");
lua_pushnumber (cd->L, elt->content.mx.priority);
lua_settable (cd->L, -3);
resolver = dns_resolver_init (rspamd_main->logger, base, cfg);
if (resolver) {
presolver = lua_newuserdata (L, sizeof (gpointer));
- lua_setclass (L, "rspamd{resolver}", -1);
+ rspamd_lua_setclass (L, "rspamd{resolver}", -1);
*presolver = resolver;
}
else {
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},
+ {"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
};
if (ud->callback) {
lua_getglobal (ud->L, ud->callback);
ptask = lua_newuserdata (ud->L, sizeof (struct rspamd_task *));
- lua_setclass (ud->L, "rspamd{task}", -1);
+ rspamd_lua_setclass (ud->L, "rspamd{task}", -1);
*ptask = ud->task;
num = 4;
}
/* Push error */
lua_getglobal (ud->L, ud->callback);
ptask = lua_newuserdata (ud->L, sizeof (struct rspamd_task *));
- lua_setclass (ud->L, "rspamd{task}", -1);
+ rspamd_lua_setclass (ud->L, "rspamd{task}", -1);
*ptask = ud->task;
num = 4;
/* Check whether we have a task object */
- ptask = lua_check_class (L, 1, "rspamd{task}");
+ ptask = rspamd_lua_check_class (L, 1, "rspamd{task}");
task = ptask ? *(ptask) : NULL;
if (!task) {
/* Check whether we have a task object */
- ptask = lua_check_class (L, 1, "rspamd{task}");
+ ptask = rspamd_lua_check_class (L, 1, "rspamd{task}");
task = ptask ? *(ptask) : NULL;
if (!task) {
ip = g_slice_alloc (sizeof (struct rspamd_lua_ip));
ip->is_valid = rspamd_parse_inet_address (&ip->addr, ip_str);
pip = lua_newuserdata (L, sizeof (struct rspamd_lua_ip *));
- lua_setclass (L, "rspamd{ip}", -1);
+ rspamd_lua_setclass (L, "rspamd{ip}", -1);
*pip = ip;
}
else {
ip->is_valid = TRUE;
ip->addr.addr.s4.sin_addr.s_addr = htonl (src[0]);
pip = lua_newuserdata (L, sizeof (struct rspamd_lua_ip *));
- lua_setclass (L, "rspamd{ip}", -1);
+ rspamd_lua_setclass (L, "rspamd{ip}", -1);
*pip = ip;
}
else if (lua_gettop (L) == 4 && lua_isnumber (L, 1)) {
ip->is_valid = TRUE;
memcpy (&ip->addr.addr.s6.sin6_addr, src, sizeof (src));
pip = lua_newuserdata (L, sizeof (struct rspamd_lua_ip *));
- lua_setclass (L, "rspamd{ip}", -1);
+ rspamd_lua_setclass (L, "rspamd{ip}", -1);
*pip = ip;
}
else {
}
void
-lua_ip_push (lua_State *L, rspamd_inet_addr_t *addr)
+rspamd_lua_ip_push (lua_State *L, rspamd_inet_addr_t *addr)
{
struct rspamd_lua_ip *ip, **pip;
memcpy (&ip->addr, addr, sizeof (ip->addr));
}
pip = lua_newuserdata (L, sizeof (struct rspamd_lua_ip *));
- lua_setclass (L, "rspamd{ip}", -1);
+ rspamd_lua_setclass (L, "rspamd{ip}", -1);
*pip = ip;
}
void
-lua_ip_push_fromstring (lua_State *L, const gchar *ip_str)
+rspamd_lua_ip_push_fromstring (lua_State *L, const gchar *ip_str)
{
struct rspamd_lua_ip *ip, **pip;
ip->is_valid = rspamd_parse_inet_address (&ip->addr, ip_str);
pip = lua_newuserdata (L, sizeof (struct rspamd_lua_ip *));
- lua_setclass (L, "rspamd{ip}", -1);
+ rspamd_lua_setclass (L, "rspamd{ip}", -1);
*pip = ip;
}
}
#include "mem_pool.h"
/* Public prototypes */
-struct memory_pool_s * lua_check_mempool (lua_State * L);
+struct memory_pool_s * rspamd_lua_check_mempool (lua_State * L);
gint luaopen_mempool (lua_State * L);
/* Lua bindings */
LUA_INTERFACE_DEF (mempool, memory_pool_set_variable),
LUA_INTERFACE_DEF (mempool, memory_pool_get_variable),
{"destroy", lua_mempool_memory_pool_delete},
- {"__tostring", lua_class_tostring},
+ {"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
};
};
struct memory_pool_s *
-lua_check_mempool (lua_State * L)
+rspamd_lua_check_mempool (lua_State * L)
{
void *ud = luaL_checkudata (L, 1, "rspamd{mempool}");
luaL_argcheck (L, ud != NULL, 1, "'mempool' expected");
if (mempool) {
pmempool = lua_newuserdata (L, sizeof (struct memory_pool_s *));
- lua_setclass (L, "rspamd{mempool}", -1);
+ rspamd_lua_setclass (L, "rspamd{mempool}", -1);
*pmempool = mempool;
}
else {
static int
lua_mempool_memory_pool_add_destructor (lua_State *L)
{
- struct memory_pool_s *mempool = lua_check_mempool (L);
+ struct memory_pool_s *mempool = rspamd_lua_check_mempool (L);
struct lua_mempool_udata *ud;
if (mempool) {
static int
lua_mempool_memory_pool_delete (lua_State *L)
{
- struct memory_pool_s *mempool = lua_check_mempool (L);
+ struct memory_pool_s *mempool = rspamd_lua_check_mempool (L);
if (mempool) {
rspamd_mempool_delete (mempool);
static int
lua_mempool_memory_pool_stat (lua_State *L)
{
- struct memory_pool_s *mempool = lua_check_mempool (L);
+ struct memory_pool_s *mempool = rspamd_lua_check_mempool (L);
if (mempool) {
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 = rspamd_lua_check_mempool (L);
if (mempool) {
lua_pushinteger (L, rspamd_mempool_suggest_size ());
static int
lua_mempool_memory_pool_set_variable (lua_State *L)
{
- struct memory_pool_s *mempool = lua_check_mempool (L);
+ struct memory_pool_s *mempool = rspamd_lua_check_mempool (L);
const gchar *var = luaL_checkstring (L, 2),
*value = luaL_checkstring (L, 3);
static int
lua_mempool_memory_pool_get_variable (lua_State *L)
{
- struct memory_pool_s *mempool = lua_check_mempool (L);
+ struct memory_pool_s *mempool = rspamd_lua_check_mempool (L);
const gchar *var = luaL_checkstring (L, 2);
gchar *value;
LUA_INTERFACE_DEF (message, get_header_strong),
LUA_INTERFACE_DEF (message, set_header),
LUA_INTERFACE_DEF (message, get_date),
- {"__tostring", lua_class_tostring},
+ {"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
};
gint
luaopen_message (lua_State * L)
{
- lua_newclass (L, "rspamd{message}", msglib_m);
+ rspamd_lua_new_class (L, "rspamd{message}", msglib_m);
luaL_register (L, "rspamd_message", null_reg);
lua_pop (L, 1); /* remove metatable from stack */
static const struct luaL_reg redislib_m[] = {
LUA_INTERFACE_DEF (redis, make_request),
- {"__tostring", lua_class_tostring},
+ {"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
};
/* Push error */
lua_rawgeti (ud->L, LUA_REGISTRYINDEX, ud->cbref);
ptask = lua_newuserdata (ud->L, sizeof (struct rspamd_task *));
- lua_setclass (ud->L, "rspamd{task}", -1);
+ rspamd_lua_setclass (ud->L, "rspamd{task}", -1);
*ptask = ud->task;
/* String of error */
/* Push error */
lua_rawgeti (ud->L, LUA_REGISTRYINDEX, ud->cbref);
ptask = lua_newuserdata (ud->L, sizeof (struct rspamd_task *));
- lua_setclass (ud->L, "rspamd{task}", -1);
+ rspamd_lua_setclass (ud->L, "rspamd{task}", -1);
*ptask = ud->task;
/* Error is nil */
LUA_INTERFACE_DEF (regexp, match),
LUA_INTERFACE_DEF (regexp, split),
LUA_INTERFACE_DEF (regexp, destroy),
- {"__tostring", lua_class_tostring},
+ {"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
};
static const struct luaL_reg regexplib_f[] = {
new->re_flags = regexp_flags;
new->re_pattern = g_strdup (string);
pnew = lua_newuserdata (L, sizeof (struct rspamd_lua_regexp *));
- lua_setclass (L, "rspamd{regexp}", -1);
+ rspamd_lua_setclass (L, "rspamd{regexp}", -1);
*pnew = new;
re_cache_add (new->re_pattern, new, regexp_static_pool);
}
new = re_cache_check (line, regexp_static_pool);
if (new) {
pnew = lua_newuserdata (L, sizeof (struct rspamd_lua_regexp *));
- lua_setclass (L, "rspamd{regexp}", -1);
+ rspamd_lua_setclass (L, "rspamd{regexp}", -1);
*pnew = new;
}
else {
};
static const struct luaL_reg rsapubkeylib_m[] = {
- {"__tostring", lua_class_tostring},
+ {"__tostring", rspamd_lua_class_tostring},
{"__gc", lua_rsa_pubkey_gc},
{NULL, NULL}
};
};
static const struct luaL_reg rsaprivkeylib_m[] = {
- {"__tostring", lua_class_tostring},
+ {"__tostring", rspamd_lua_class_tostring},
{"__gc", lua_rsa_privkey_gc},
{NULL, NULL}
};
static const struct luaL_reg rsasignlib_m[] = {
LUA_INTERFACE_DEF (rsa_signature, save),
- {"__tostring", lua_class_tostring},
+ {"__tostring", rspamd_lua_class_tostring},
{"__gc", lua_rsa_signature_gc},
{NULL, NULL}
};
}
else {
prsa = lua_newuserdata (L, sizeof (RSA *));
- lua_setclass (L, "rspamd{rsa_pubkey}", -1);
+ rspamd_lua_setclass (L, "rspamd{rsa_pubkey}", -1);
*prsa = rsa;
}
fclose (f);
}
else {
prsa = lua_newuserdata (L, sizeof (RSA *));
- lua_setclass (L, "rspamd{rsa_pubkey}", -1);
+ rspamd_lua_setclass (L, "rspamd{rsa_pubkey}", -1);
*prsa = rsa;
}
BIO_free (bp);
}
else {
prsa = lua_newuserdata (L, sizeof (RSA *));
- lua_setclass (L, "rspamd{rsa_privkey}", -1);
+ rspamd_lua_setclass (L, "rspamd{rsa_privkey}", -1);
*prsa = rsa;
}
fclose (f);
}
else {
prsa = lua_newuserdata (L, sizeof (RSA *));
- lua_setclass (L, "rspamd{rsa_privkey}", -1);
+ rspamd_lua_setclass (L, "rspamd{rsa_privkey}", -1);
*prsa = rsa;
}
BIO_free (bp);
sig->begin = g_malloc (sig->len);
memcpy (sig->begin, data, sig->len);
psig = lua_newuserdata (L, sizeof (f_str_t *));
- lua_setclass (L, "rspamd{rsa_signature}", -1);
+ rspamd_lua_setclass (L, "rspamd{rsa_signature}", -1);
*psig = sig;
munmap (data, st.st_size);
}
sig->begin = g_malloc (sig->len);
memcpy (sig->begin, data, sig->len);
psig = lua_newuserdata (L, sizeof (f_str_t *));
- lua_setclass (L, "rspamd{rsa_signature}", -1);
+ rspamd_lua_setclass (L, "rspamd{rsa_signature}", -1);
*psig = sig;
}
}
else {
psig = lua_newuserdata (L, sizeof (f_str_t *));
- lua_setclass (L, "rspamd{rsa_signature}", -1);
+ rspamd_lua_setclass (L, "rspamd{rsa_signature}", -1);
*psig = signature;
}
g_free (data_sig);
}
else {
psig = lua_newuserdata (L, sizeof (f_str_t *));
- lua_setclass (L, "rspamd{rsa_signature}", -1);
+ rspamd_lua_setclass (L, "rspamd{rsa_signature}", -1);
*psig = signature;
}
g_free (data_sig);
LUA_INTERFACE_DEF (session, remove_normal_event),
LUA_INTERFACE_DEF (session, check_session_pending),
LUA_INTERFACE_DEF (session, delete),
- {"__tostring", lua_class_tostring},
+ {"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
};
};
static const struct luaL_reg eventlib_m[] = {
- {"__tostring", lua_class_tostring},
+ {"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
};
return 1;
}
- mempool = lua_check_mempool (L);
+ mempool = rspamd_lua_check_mempool (L);
if (mempool == NULL) {
msg_err ("invalid mempool argument to rspamd_session.create");
lua_pushnil (L);
cbdata);
cbdata->session = session;
psession = lua_newuserdata (L, sizeof (struct rspamd_async_session *));
- lua_setclass (L, "rspamd{session}", -1);
+ rspamd_lua_setclass (L, "rspamd{session}", -1);
*psession = session;
return 1;
cbdata,
g_quark_from_static_string ("lua event"));
pdata = lua_newuserdata (L, sizeof (gpointer));
- lua_setclass (L, "rspamd{event}", -1);
+ rspamd_lua_setclass (L, "rspamd{event}", -1);
*pdata = cbdata;
}
else {
lua_pop (L, 1); /* remove metatable from stack */
/* Simple event class */
- lua_newclass (L, "rspamd{event}", eventlib_m);
+ rspamd_lua_new_class (L, "rspamd{event}", eventlib_m);
luaL_register (L, "rspamd_event", null_reg);
lua_pop (L, 1); /* remove metatable from stack */
LUA_INTERFACE_DEF (task, get_metric_action),
LUA_INTERFACE_DEF (task, learn),
LUA_INTERFACE_DEF (task, set_settings),
- {"__tostring", lua_class_tostring},
+ {"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
};
LUA_INTERFACE_DEF (textpart, get_fuzzy),
LUA_INTERFACE_DEF (textpart, get_language),
LUA_INTERFACE_DEF (textpart, compare_distance),
- {"__tostring", lua_class_tostring},
+ {"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
};
LUA_INTERFACE_DEF (mimepart, get_length),
LUA_INTERFACE_DEF (mimepart, get_type),
LUA_INTERFACE_DEF (mimepart, get_filename),
- {"__tostring", lua_class_tostring},
+ {"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
};
LUA_INTERFACE_DEF (image, get_type),
LUA_INTERFACE_DEF (image, get_filename),
LUA_INTERFACE_DEF (image, get_size),
- {"__tostring", lua_class_tostring},
+ {"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
};
LUA_INTERFACE_DEF (url, get_text),
LUA_INTERFACE_DEF (url, is_phished),
LUA_INTERFACE_DEF (url, get_phished),
- {"__tostring", lua_class_tostring},
+ {"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
};
task = rspamd_task_new (NULL);
ptask = lua_newuserdata (L, sizeof (gpointer));
- lua_setclass (L, "rspamd{task}", -1);
+ rspamd_lua_setclass (L, "rspamd{task}", -1);
*ptask = task;
return 1;
}
if (data) {
task = rspamd_task_new (NULL);
ptask = lua_newuserdata (L, sizeof (gpointer));
- lua_setclass (L, "rspamd{task}", -1);
+ rspamd_lua_setclass (L, "rspamd{task}", -1);
*ptask = task;
task->msg = g_string_new_len (data, len);
}
struct rspamd_config **pcfg;
pcfg = lua_newuserdata (L, sizeof (gpointer));
- lua_setclass (L, "rspamd{config}", -1);
+ rspamd_lua_setclass (L, "rspamd{config}", -1);
*pcfg = task->cfg;
return 1;
if (task != NULL && task->message != NULL) {
pmsg = lua_newuserdata (L, sizeof (GMimeMessage *));
- lua_setclass (L, "rspamd{message}", -1);
+ rspamd_lua_setclass (L, "rspamd{message}", -1);
*pmsg = task->message;
}
else {
if (task != NULL) {
ppool = lua_newuserdata (L, sizeof (rspamd_mempool_t *));
- lua_setclass (L, "rspamd{mempool}", -1);
+ rspamd_lua_setclass (L, "rspamd{mempool}", -1);
*ppool = task->task_pool;
}
else {
if (task != NULL) {
psession = lua_newuserdata (L, sizeof (void *));
- lua_setclass (L, "rspamd{session}", -1);
+ rspamd_lua_setclass (L, "rspamd{session}", -1);
*psession = task->s;
}
else {
if (task != NULL) {
pbase = lua_newuserdata (L, sizeof (struct event_base *));
- lua_setclass (L, "rspamd{ev_base}", -1);
+ rspamd_lua_setclass (L, "rspamd{ev_base}", -1);
*pbase = task->ev_base;
}
else {
struct lua_tree_cb_data *cb = ud;
purl = lua_newuserdata (cb->L, sizeof (struct uri *));
- lua_setclass (cb->L, "rspamd{url}", -1);
+ rspamd_lua_setclass (cb->L, "rspamd{url}", -1);
*purl = value;
lua_rawseti (cb->L, -2, cb->i++);
part = cur->data;
ppart = lua_newuserdata (L, sizeof (struct mime_text_part *));
*ppart = part;
- lua_setclass (L, "rspamd{textpart}", -1);
+ rspamd_lua_setclass (L, "rspamd{textpart}", -1);
/* Make it array */
lua_rawseti (L, -2, i++);
cur = g_list_next (cur);
part = cur->data;
ppart = lua_newuserdata (L, sizeof (struct mime_part *));
*ppart = part;
- lua_setclass (L, "rspamd{mimepart}", -1);
+ rspamd_lua_setclass (L, "rspamd{mimepart}", -1);
/* Make it array */
lua_rawseti (L, -2, i++);
cur = g_list_next (cur);
}
/* Create new associated table for a header */
lua_newtable (L);
- lua_set_table_index (L, "name", rh->name);
- lua_set_table_index (L, "value", rh->value);
+ rspamd_lua_table_set (L, "name", rh->name);
+ rspamd_lua_table_set (L, "value", rh->value);
lua_pushstring (L, "tab_separated");
lua_pushboolean (L, rh->tab_separated);
lua_settable (L, -3);
lua_pushstring (L, "empty_separator");
lua_pushboolean (L, rh->empty_separator);
lua_settable (L, -3);
- lua_set_table_index (L, "separator", rh->separator);
+ rspamd_lua_table_set (L, "separator", rh->separator);
lua_rawseti (L, -2, i++);
/* Process next element */
rh = rh->next;
continue;
}
lua_newtable (L);
- lua_set_table_index (L, "from_hostname", rh->from_hostname);
+ rspamd_lua_table_set (L, "from_hostname", rh->from_hostname);
lua_pushstring (L, "from_ip");
- lua_ip_push_fromstring (L, rh->from_ip);
+ rspamd_lua_ip_push_fromstring (L, rh->from_ip);
lua_settable (L, -3);
- lua_set_table_index (L, "real_hostname", rh->real_hostname);
+ rspamd_lua_table_set (L, "real_hostname", rh->real_hostname);
lua_pushstring (L, "real_ip");
- lua_ip_push_fromstring (L, rh->real_ip);
+ rspamd_lua_ip_push_fromstring (L, rh->real_ip);
lua_settable (L, -3);
- lua_set_table_index (L, "by_hostname", rh->by_hostname);
+ rspamd_lua_table_set (L, "by_hostname", rh->by_hostname);
lua_rawseti (L, -2, i++);
cur = g_list_next (cur);
}
if (task != NULL && task->resolver != NULL) {
presolver = lua_newuserdata (L, sizeof (void *));
- lua_setclass (L, "rspamd{resolver}", -1);
+ rspamd_lua_setclass (L, "rspamd{resolver}", -1);
*presolver = task->resolver;
}
else {
#ifndef GMIME24
if (internet_address_get_type (ia) == INTERNET_ADDRESS_NAME) {
lua_newtable (L);
- lua_set_table_index (L, "name", internet_address_get_name (ia));
- lua_set_table_index (L, "addr", internet_address_get_addr (ia));
+ rspamd_lua_table_set (L, "name", internet_address_get_name (ia));
+ rspamd_lua_table_set (L, "addr", internet_address_get_addr (ia));
return TRUE;
}
return FALSE;
iamb = INTERNET_ADDRESS_MAILBOX (ia);
addr = internet_address_mailbox_get_addr (iamb);
if (addr) {
- lua_set_table_index (L, "name", internet_address_get_name (ia));
- lua_set_table_index (L, "addr", addr);
+ rspamd_lua_table_set (L, "name", internet_address_get_name (ia));
+ rspamd_lua_table_set (L, "addr", addr);
/* Set optional fields */
at = strchr (addr, '@');
struct rspamd_task *task = lua_check_task (L);
if (task) {
- lua_ip_push (L, &task->from_addr);
+ rspamd_lua_ip_push (L, &task->from_addr);
}
else {
lua_pushnil (L);
struct rspamd_task *task = lua_check_task (L);
if (task) {
- lua_ip_push (L, &task->client_addr);
+ rspamd_lua_ip_push (L, &task->client_addr);
}
else {
lua_pushnil (L);
lua_newtable (L);
while (cur) {
pimg = lua_newuserdata (L, sizeof (struct rspamd_image *));
- lua_setclass (L, "rspamd{image}", -1);
+ rspamd_lua_setclass (L, "rspamd{image}", -1);
*pimg = cur->data;
lua_rawseti (L, -2, i++);
cur = g_list_next (cur);
if (url) {
if (url->is_phished && url->phished_url != NULL) {
purl = lua_newuserdata (L, sizeof (struct uri *));
- lua_setclass (L, "rspamd{url}", -1);
+ rspamd_lua_setclass (L, "rspamd{url}", -1);
*purl = url->phished_url;
return 1;
gint
luaopen_task (lua_State * L)
{
- lua_newclass_full (L, "rspamd{task}", "rspamd_task", tasklib_m, tasklib_f);
+ rspamd_lua_new_class_full (L, "rspamd{task}", "rspamd_task", tasklib_m, tasklib_f);
lua_pop (L, 1); /* remove metatable from stack */
gint
luaopen_textpart (lua_State * L)
{
- lua_newclass (L, "rspamd{textpart}", textpartlib_m);
+ rspamd_lua_new_class (L, "rspamd{textpart}", textpartlib_m);
luaL_register (L, "rspamd_textpart", null_reg);
lua_pop (L, 1); /* remove metatable from stack */
gint
luaopen_mimepart (lua_State * L)
{
- lua_newclass (L, "rspamd{mimepart}", mimepartlib_m);
+ rspamd_lua_new_class (L, "rspamd{mimepart}", mimepartlib_m);
luaL_register (L, "rspamd_mimepart", null_reg);
lua_pop (L, 1); /* remove metatable from stack */
gint
luaopen_image (lua_State * L)
{
- lua_newclass (L, "rspamd{image}", imagelib_m);
+ rspamd_lua_new_class (L, "rspamd{image}", imagelib_m);
luaL_register (L, "rspamd_image", null_reg);
lua_pop (L, 1); /* remove metatable from stack */
gint
luaopen_url (lua_State * L)
{
- lua_newclass (L, "rspamd{url}", urllib_m);
+ rspamd_lua_new_class (L, "rspamd{url}", urllib_m);
luaL_register (L, "rspamd_url", null_reg);
lua_pop (L, 1); /* remove metatable from stack */
LUA_INTERFACE_DEF (upstream_list, get_upstream_by_hash),
LUA_INTERFACE_DEF (upstream_list, get_upstream_round_robin),
LUA_INTERFACE_DEF (upstream_list, get_upstream_master_slave),
- {"__tostring", lua_class_tostring},
+ {"__tostring", rspamd_lua_class_tostring},
{"__gc", lua_upstream_list_destroy},
{NULL, NULL}
};
LUA_INTERFACE_DEF (upstream, get_port),
LUA_INTERFACE_DEF (upstream, get_priority),
LUA_INTERFACE_DEF (upstream, destroy),
- {"__tostring", lua_class_tostring},
+ {"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
};
static const struct luaL_reg upstream_f[] = {
}
else {
pnew = lua_newuserdata (L, sizeof (struct lua_upstream *));
- lua_setclass (L, "rspamd{upstream}", -1);
+ rspamd_lua_setclass (L, "rspamd{upstream}", -1);
*pnew = new;
}
}
}
}
pnew = lua_newuserdata (L, sizeof (struct upstream_list *));
- lua_setclass (L, "rspamd{upstream_list}", -1);
+ rspamd_lua_setclass (L, "rspamd{upstream_list}", -1);
*pnew = new;
}
0);
if (selected) {
pselected = lua_newuserdata (L, sizeof (struct lua_upstream *));
- lua_setclass (L, "rspamd{upstream}", -1);
+ rspamd_lua_setclass (L, "rspamd{upstream}", -1);
*pselected = selected;
}
else {
DEFAULT_UPSTREAM_MAXERRORS);
if (selected) {
pselected = lua_newuserdata (L, sizeof (struct lua_upstream *));
- lua_setclass (L, "rspamd{upstream}", -1);
+ rspamd_lua_setclass (L, "rspamd{upstream}", -1);
*pselected = selected;
}
else {
DEFAULT_UPSTREAM_MAXERRORS);
if (selected) {
pselected = lua_newuserdata (L, sizeof (struct lua_upstream *));
- lua_setclass (L, "rspamd{upstream}", -1);
+ rspamd_lua_setclass (L, "rspamd{upstream}", -1);
*pselected = selected;
}
else {
static const struct luaL_reg xmlrpclib_m[] = {
LUA_INTERFACE_DEF (xmlrpc, parse_reply),
LUA_INTERFACE_DEF (xmlrpc, make_request),
- {"__tostring", lua_class_tostring},
+ {"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
};
LUA_INTERFACE_DEF (worker, get_option),
LUA_INTERFACE_DEF (worker, get_resolver),
LUA_INTERFACE_DEF (worker, get_cfg),
- {"__tostring", lua_class_tostring},
+ {"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
};
static gint
luaopen_lua_worker (lua_State * L)
{
- lua_newclass (L, "rspamd{worker}", lua_workerlib_m);
+ rspamd_lua_new_class (L, "rspamd{worker}", lua_workerlib_m);
luaL_register (L, "rspamd_worker", null_reg);
lua_pop (L, 1); /* remove metatable from stack */
if (ctx) {
pbase = lua_newuserdata (L, sizeof (struct event_base *));
- lua_setclass (L, "rspamd{ev_base}", -1);
+ rspamd_lua_setclass (L, "rspamd{ev_base}", -1);
*pbase = ctx->ev_base;
}
else {
if (ctx) {
presolver = lua_newuserdata (L, sizeof (gpointer));
- lua_setclass (L, "rspamd{resolver}", -1);
+ rspamd_lua_setclass (L, "rspamd{resolver}", -1);
*presolver = ctx->resolver;
}
else {
if (ctx) {
pcfg = lua_newuserdata (L, sizeof (gpointer));
- lua_setclass (L, "rspamd{config}", -1);
+ rspamd_lua_setclass (L, "rspamd{config}", -1);
*pcfg = ctx->cfg;
}
else {
/* Call finalizer function */
lua_rawgeti (L, LUA_REGISTRYINDEX, ctx->cbref_accept);
pctx = lua_newuserdata (L, sizeof (gpointer));
- lua_setclass (L, "rspamd{worker}", -1);
+ rspamd_lua_setclass (L, "rspamd{worker}", -1);
*pctx = ctx;
lua_pushinteger (L, nfd);
lua_pushstring (L, rspamd_inet_address_to_string (&addr));
}
pctx = lua_newuserdata (L, sizeof (gpointer));
- lua_setclass (L, "rspamd{worker}", -1);
+ rspamd_lua_setclass (L, "rspamd{worker}", -1);
lua_setglobal (L, "rspamd_worker");
*pctx = ctx;
/* Call finalizer function */
lua_rawgeti (L, LUA_REGISTRYINDEX, ctx->cbref_fin);
pctx = lua_newuserdata (L, sizeof (gpointer));
- lua_setclass (L, "rspamd{worker}", -1);
+ rspamd_lua_setclass (L, "rspamd{worker}", -1);
*pctx = ctx;
if (lua_pcall (L, 1, 0, 0) != 0) {
msg_info ("call to worker finalizer failed: %s", lua_tostring (L,
rspamd->cfg->cfg_name);
/* Save some variables */
tmp_cfg->cfg_name = cfg_file;
- tmp_cfg->lua_state = init_lua (tmp_cfg);
+ tmp_cfg->lua_state = rspamd_lua_init (tmp_cfg);
rspamd_mempool_add_destructor (tmp_cfg->cfg_pool,
(rspamd_mempool_destruct_t)lua_close, tmp_cfg->lua_state);
}
l = g_list_next (l);
}
- init_lua_filters (rspamd->cfg);
+ rspamd_init_lua_filters (rspamd->cfg);
init_cfg_cache (rspamd->cfg);
msg_info ("config rereaded successfully");
}
g_log_set_default_handler (rspamd_glib_log_function, rspamd_main->logger);
detect_priv (rspamd_main);
- rspamd_main->cfg->lua_state = init_lua (rspamd_main->cfg);
+ rspamd_main->cfg->lua_state = rspamd_lua_init (rspamd_main->cfg);
rspamd_mempool_add_destructor (rspamd_main->cfg->cfg_pool,
(rspamd_mempool_destruct_t)lua_close, rspamd_main->cfg->lua_state);
/* Init events to test modules */
event_init ();
res = TRUE;
- if (!init_lua_filters (rspamd_main->cfg)) {
+ if (!rspamd_init_lua_filters (rspamd_main->cfg)) {
res = FALSE;
}
/* Perform modules configuring */
g_mime_init (0);
/* Init lua filters */
- if (!init_lua_filters (rspamd_main->cfg)) {
+ if (!rspamd_init_lua_filters (rspamd_main->cfg)) {
msg_err ("error loading lua plugins");
exit (EXIT_FAILURE);
}
static const struct luaL_reg regexplib_m[] = {
LUA_INTERFACE_DEF (regexp, match),
- {"__tostring", lua_class_tostring},
+ {"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
};
lua_getglobal (L, name);
if (lua_isfunction (L, -1)) {
ptask = lua_newuserdata (L, sizeof (struct rspamd_task *));
- lua_setclass (L, "rspamd{task}", -1);
+ rspamd_lua_setclass (L, "rspamd{task}", -1);
*ptask = task;
/* Call function */
if (lua_pcall (L, 1, 1, 0) != 0) {
sizeof (GMutex));
g_mutex_init (workers_mtx);
#endif
- nL = init_lua_locked (task->cfg);
+ nL = rspamd_init_lua_locked (task->cfg);
luaopen_regexp (nL->L);
regexp_module_ctx->workers = g_thread_pool_new (
process_regexp_item_threaded,
/* Non-threaded version */
if (item->lua_function) {
/* Just call function */
- if (lua_call_expression_func (item->lua_function, task, NULL,
+ if (rspamd_lua_call_expression_func (item->lua_function, task, NULL,
&res) && res) {
insert_result (task, item->symbol, 1, NULL);
}
}
}
else {
- lua_call_pre_filters (session->task);
+ rspamd_lua_call_pre_filters (session->task);
/* We want fin_task after pre filters are processed */
session->task->s->wanna_die = TRUE;
session->task->state = WAIT_PRE_FILTER;
/* Create classify pool */
ctx->classify_pool = NULL;
if (ctx->classify_threads > 1) {
- nL = init_lua_locked (worker->srv->cfg);
+ nL = rspamd_init_lua_locked (worker->srv->cfg);
ctx->classify_pool = g_thread_pool_new (process_statfiles_threaded,
nL,
ctx->classify_threads,