diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-11-18 16:01:05 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-11-18 16:01:05 +0000 |
commit | aef1cac108507fcefba54694f46c4f2e8069c31d (patch) | |
tree | 5944bb32de8f4ded1cc972bf101f8846338418f2 /src/lua | |
parent | 9b31d260b9bee44456fd2f37eee6c4ba2c8aba60 (diff) | |
download | rspamd-aef1cac108507fcefba54694f46c4f2e8069c31d.tar.gz rspamd-aef1cac108507fcefba54694f46c4f2e8069c31d.zip |
Implement refcounting for configuration
Diffstat (limited to 'src/lua')
-rw-r--r-- | src/lua/lua_task.c | 51 | ||||
-rw-r--r-- | src/lua/lua_util.c | 11 |
2 files changed, 6 insertions, 56 deletions
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index 3bc40efe4..e19200027 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -54,20 +54,6 @@ rspamd_config.DATE_IN_PAST = function(task) end */ -/* Task creation */ -/*** - * @function rspamd_task.create_empty() - * Creates new empty task object. - * @return {rspamd_task} task object - */ -LUA_FUNCTION_DEF (task, create_empty); -/*** - * @function rspamd_task.create_from_buffer(input) - * Creates new task object and load its content from the string provided. - * @param {string} input string that contains MIME message - * @return {rspamd_task} task object - */ -LUA_FUNCTION_DEF (task, create_from_buffer); /* Task methods */ LUA_FUNCTION_DEF (task, get_message); LUA_FUNCTION_DEF (task, process_message); @@ -492,8 +478,6 @@ LUA_FUNCTION_DEF (task, set_flag); LUA_FUNCTION_DEF (task, get_flags); static const struct luaL_reg tasklib_f[] = { - LUA_INTERFACE_DEF (task, create_empty), - LUA_INTERFACE_DEF (task, create_from_buffer), {NULL, NULL} }; @@ -612,39 +596,6 @@ lua_check_text (lua_State * L, gint pos) } /* Task methods */ - -static int -lua_task_create_empty (lua_State *L) -{ - struct rspamd_task **ptask, *task; - - task = rspamd_task_new (NULL); - ptask = lua_newuserdata (L, sizeof (gpointer)); - rspamd_lua_setclass (L, "rspamd{task}", -1); - *ptask = task; - return 1; -} - -static int -lua_task_create_from_buffer (lua_State *L) -{ - struct rspamd_task **ptask, *task; - const gchar *data; - size_t len; - - data = luaL_checklstring (L, 1, &len); - if (data) { - task = rspamd_task_new (NULL); - ptask = lua_newuserdata (L, sizeof (gpointer)); - rspamd_lua_setclass (L, "rspamd{task}", -1); - *ptask = task; - task->msg.begin = rspamd_mempool_alloc (task->task_pool, len); - memcpy ((gpointer)task->msg.begin, data, len); - task->msg.len = len; - } - return 1; -} - static int lua_task_process_message (lua_State *L) { @@ -695,7 +646,7 @@ lua_task_destroy (lua_State *L) struct rspamd_task *task = lua_check_task (L, 1); if (task != NULL) { - rspamd_task_free (task, FALSE); + rspamd_task_free (task); } return 0; diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c index 6a43206a5..32fc23fc1 100644 --- a/src/lua/lua_util.c +++ b/src/lua/lua_util.c @@ -161,7 +161,7 @@ lua_util_load_rspamd_config (lua_State *L) cfg_name = luaL_checkstring (L, 1); if (cfg_name) { - cfg = rspamd_config_defaults (); + cfg = rspamd_config_new (); if (rspamd_config_read (cfg, cfg_name, NULL, NULL, NULL, NULL)) { msg_err_config ("cannot load config from %s", cfg_name); @@ -190,7 +190,7 @@ lua_util_config_from_ucl (lua_State *L) if (obj) { cfg = g_malloc0 (sizeof (struct rspamd_config)); - cfg = rspamd_config_defaults (); + cfg = rspamd_config_new (); cfg->rcl_obj = obj; cfg->cache = rspamd_symbols_cache_new (cfg); @@ -238,8 +238,7 @@ lua_util_process_message (lua_State *L) if (cfg != NULL && message != NULL) { base = event_init (); rspamd_init_filters (cfg, FALSE); - task = rspamd_task_new (NULL); - task->cfg = cfg; + task = rspamd_task_new (NULL, cfg); task->ev_base = base; task->msg.begin = rspamd_mempool_alloc (task->task_pool, mlen); rspamd_strlcpy ((gpointer)task->msg.begin, message, mlen); @@ -248,7 +247,7 @@ lua_util_process_message (lua_State *L) task->fin_arg = &res; task->resolver = dns_resolver_init (NULL, base, cfg); task->s = rspamd_session_create (task->task_pool, rspamd_task_fin, - rspamd_task_restore, rspamd_task_free_hard, task); + rspamd_task_restore, (event_finalizer_t)rspamd_task_free, task); if (!rspamd_task_load_message (task, NULL, message, mlen)) { lua_pushnil (L); @@ -266,7 +265,7 @@ lua_util_process_message (lua_State *L) ucl_object_push_lua (L, rspamd_protocol_write_ucl (task), true); rdns_resolver_release (task->resolver->r); - rspamd_task_free_hard (task); + rspamd_session_destroy (task->s); } } else { |