aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/controller.c15
-rw-r--r--src/libmime/smtp_utils.c2
-rw-r--r--src/libserver/cfg_file.h2
-rw-r--r--src/libserver/cfg_utils.c2
-rw-r--r--src/libserver/task.c34
-rw-r--r--src/libserver/task.h7
-rw-r--r--src/libserver/worker_util.h1
-rw-r--r--src/lua/lua_task.c51
-rw-r--r--src/lua/lua_util.c11
-rw-r--r--src/plugins/fuzzy_check.c12
-rw-r--r--src/rspamadm/rspamadm.c2
-rw-r--r--src/rspamd.c4
-rw-r--r--src/worker.c4
13 files changed, 43 insertions, 104 deletions
diff --git a/src/controller.c b/src/controller.c
index 39312f48c..be60050fc 100644
--- a/src/controller.c
+++ b/src/controller.c
@@ -1262,7 +1262,7 @@ rspamd_controller_handle_learn_common (
return 0;
}
- task = rspamd_task_new (session->ctx->worker);
+ task = rspamd_task_new (session->ctx->worker, session->cfg);
task->resolver = ctx->resolver;
task->ev_base = ctx->ev_base;
@@ -1271,7 +1271,7 @@ rspamd_controller_handle_learn_common (
task->s = rspamd_session_create (session->pool,
rspamd_controller_learn_fin_task,
NULL,
- rspamd_task_free_hard,
+ (event_finalizer_t )rspamd_task_free,
task);
task->fin_arg = conn_ent;
task->http_conn = rspamd_http_connection_ref (conn_ent->conn);;
@@ -1355,7 +1355,7 @@ rspamd_controller_handle_scan (struct rspamd_http_connection_entry *conn_ent,
return 0;
}
- task = rspamd_task_new (session->ctx->worker);
+ task = rspamd_task_new (session->ctx->worker, session->cfg);
task->ev_base = session->ctx->ev_base;
task->resolver = ctx->resolver;
@@ -1364,7 +1364,7 @@ rspamd_controller_handle_scan (struct rspamd_http_connection_entry *conn_ent,
task->s = rspamd_session_create (session->pool,
rspamd_controller_check_fin_task,
NULL,
- rspamd_task_free_hard,
+ (event_finalizer_t )rspamd_task_free,
task);
task->fin_arg = conn_ent;
task->http_conn = rspamd_http_connection_ref (conn_ent->conn);
@@ -1765,7 +1765,7 @@ rspamd_controller_stat_cleanup_task (void *ud)
{
struct rspamd_stat_cbdata *cbdata = ud;
- rspamd_task_free_hard (cbdata->task);
+ rspamd_task_free (cbdata->task);
ucl_object_unref (cbdata->top);
}
@@ -1794,7 +1794,7 @@ rspamd_controller_handle_stat_common (
rspamd_mempool_stat (&mem_st);
memcpy (&stat_copy, session->ctx->worker->srv->stat, sizeof (stat_copy));
stat = &stat_copy;
- task = rspamd_task_new (session->ctx->worker);
+ task = rspamd_task_new (session->ctx->worker, session->cfg);
ctx = session->ctx;
task->resolver = ctx->resolver;
@@ -2033,6 +2033,7 @@ rspamd_controller_finish_handler (struct rspamd_http_connection_entry *conn_ent)
session->wrk->nconns --;
rspamd_inet_address_destroy (session->from_addr);
+ REF_RELEASE (session->cfg);
g_slice_free1 (sizeof (struct rspamd_controller_session), session);
}
@@ -2061,6 +2062,8 @@ rspamd_controller_accept_socket (gint fd, short what, void *arg)
session->pool = rspamd_mempool_new (rspamd_mempool_suggest_size (),
"csession");
session->ctx = ctx;
+ session->cfg = ctx->cfg;
+ REF_RETAIN (session->cfg);
session->from_addr = addr;
session->wrk = worker;
diff --git a/src/libmime/smtp_utils.c b/src/libmime/smtp_utils.c
index 0f8a84cc2..33750bae5 100644
--- a/src/libmime/smtp_utils.c
+++ b/src/libmime/smtp_utils.c
@@ -33,11 +33,11 @@ free_smtp_session (gpointer arg)
if (session) {
if (session->task) {
- rspamd_task_free (session->task, FALSE);
if (session->task->msg.begin) {
munmap ((gpointer)session->task->msg.begin,
session->task->msg.len);
}
+ rspamd_task_free (session->task);
}
if (session->rcpt) {
g_list_free (session->rcpt);
diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h
index a2ec19034..96fc56d52 100644
--- a/src/libserver/cfg_file.h
+++ b/src/libserver/cfg_file.h
@@ -341,7 +341,7 @@ gboolean rspamd_parse_bind_line (struct rspamd_config *cfg,
* Init default values
* @param cfg config file
*/
-struct rspamd_config * rspamd_config_defaults (void);
+struct rspamd_config *rspamd_config_new (void);
/**
* Free memory used by config structure
diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c
index 4146d51cb..23de0bef2 100644
--- a/src/libserver/cfg_utils.c
+++ b/src/libserver/cfg_utils.c
@@ -145,7 +145,7 @@ rspamd_parse_bind_line (struct rspamd_config *cfg,
}
struct rspamd_config *
-rspamd_config_defaults (void)
+rspamd_config_new (void)
{
struct rspamd_config *cfg;
diff --git a/src/libserver/task.c b/src/libserver/task.c
index f89ca4097..c4ae1762c 100644
--- a/src/libserver/task.c
+++ b/src/libserver/task.c
@@ -42,19 +42,19 @@ rspamd_task_quark (void)
* Create new task
*/
struct rspamd_task *
-rspamd_task_new (struct rspamd_worker *worker)
+rspamd_task_new (struct rspamd_worker *worker, struct rspamd_config *cfg)
{
struct rspamd_task *new_task;
- new_task = g_slice_alloc0 (sizeof (struct rspamd_task));
+ g_assert (cfg != NULL);
+ new_task = g_slice_alloc0 (sizeof (struct rspamd_task));
new_task->worker = worker;
+ new_task->cfg = cfg;
+ REF_RETAIN (cfg);
- if (worker) {
- new_task->cfg = worker->srv->cfg;
- if (new_task->cfg->check_all_filters) {
- new_task->flags |= RSPAMD_TASK_FLAG_PASS_ALL;
- }
+ if (cfg->check_all_filters) {
+ new_task->flags |= RSPAMD_TASK_FLAG_PASS_ALL;
}
gettimeofday (&new_task->tv, NULL);
@@ -169,7 +169,7 @@ rspamd_task_restore (void *arg)
* Free all structures of worker_task
*/
void
-rspamd_task_free (struct rspamd_task *task, gboolean is_soft)
+rspamd_task_free (struct rspamd_task *task)
{
struct mime_part *p;
struct mime_text_part *tp;
@@ -229,27 +229,13 @@ rspamd_task_free (struct rspamd_task *task, gboolean is_soft)
event_del (&task->timeout_ev);
}
+ REF_RELEASE (task->cfg);
+
rspamd_mempool_delete (task->task_pool);
g_slice_free1 (sizeof (struct rspamd_task), task);
}
}
-void
-rspamd_task_free_hard (gpointer ud)
-{
- struct rspamd_task *task = ud;
-
- rspamd_task_free (task, FALSE);
-}
-
-void
-rspamd_task_free_soft (gpointer ud)
-{
- struct rspamd_task *task = ud;
-
- rspamd_task_free (task, FALSE);
-}
-
static void
rspamd_task_unmapper (gpointer ud)
{
diff --git a/src/libserver/task.h b/src/libserver/task.h
index 8a9e913a4..b29bcebf6 100644
--- a/src/libserver/task.h
+++ b/src/libserver/task.h
@@ -180,13 +180,12 @@ struct rspamd_task {
/**
* Construct new task for worker
*/
-struct rspamd_task * rspamd_task_new (struct rspamd_worker *worker);
+struct rspamd_task * rspamd_task_new (struct rspamd_worker *worker,
+ struct rspamd_config *cfg);
/**
* Destroy task object and remove its IO dispatcher if it exists
*/
-void rspamd_task_free (struct rspamd_task *task, gboolean is_soft);
-void rspamd_task_free_hard (gpointer ud);
-void rspamd_task_free_soft (gpointer ud);
+void rspamd_task_free (struct rspamd_task *task);
/**
* Called if session was restored inside fin callback
diff --git a/src/libserver/worker_util.h b/src/libserver/worker_util.h
index 3242d1669..21c86f92e 100644
--- a/src/libserver/worker_util.h
+++ b/src/libserver/worker_util.h
@@ -86,6 +86,7 @@ struct rspamd_controller_session {
struct rspamd_task *task;
struct rspamd_classifier_config *cl;
rspamd_inet_addr_t *from_addr;
+ struct rspamd_config *cfg;
gboolean is_spam;
};
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 {
diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c
index 915fee49a..f8379d477 100644
--- a/src/plugins/fuzzy_check.c
+++ b/src/plugins/fuzzy_check.c
@@ -1180,7 +1180,7 @@ cleanup:
}
if (session->task != NULL) {
- rspamd_task_free (session->task, TRUE);
+ rspamd_task_free (session->task);
session->task = NULL;
}
@@ -1205,7 +1205,7 @@ fuzzy_controller_timer_callback (gint fd, short what, void *arg)
if (*session->saved > 0 ) {
(*session->saved)--;
if (*session->saved == 0 && session->task != NULL) {
- rspamd_task_free (session->task, TRUE);
+ rspamd_task_free (session->task);
session->task = NULL;
}
}
@@ -1489,7 +1489,7 @@ fuzzy_process_handler (struct rspamd_http_connection_entry *conn_ent,
gint r, *saved, rules = 0;
/* Prepare task */
- task = rspamd_task_new (NULL);
+ task = rspamd_task_new (session->wrk, session->cfg);
task->cfg = ctx->cfg;
task->ev_base = conn_ent->rt->ev_base;
@@ -1505,7 +1505,7 @@ fuzzy_process_handler (struct rspamd_http_connection_entry *conn_ent,
if (r == -1) {
msg_warn_task ("<%s>: cannot process message for fuzzy",
task->message_id);
- rspamd_task_free (task, FALSE);
+ rspamd_task_free (task);
rspamd_controller_send_error (conn_ent, 400,
"Message processing error");
return;
@@ -1550,7 +1550,7 @@ fuzzy_process_handler (struct rspamd_http_connection_entry *conn_ent,
msg_warn_task ("<%s>: cannot send fuzzy request: %s", task->message_id,
strerror (errno));
rspamd_controller_send_error (conn_ent, 400, "Message sending error");
- rspamd_task_free (task, FALSE);
+ rspamd_task_free (task);
return;
}
else if (!processed) {
@@ -1567,7 +1567,7 @@ fuzzy_process_handler (struct rspamd_http_connection_entry *conn_ent,
rspamd_controller_send_error (conn_ent, 404,
"No fuzzy rules matched for flag %d", flag);
}
- rspamd_task_free (task, FALSE);
+ rspamd_task_free (task);
return;
}
diff --git a/src/rspamadm/rspamadm.c b/src/rspamadm/rspamadm.c
index 5751c50d0..d0e1caf8b 100644
--- a/src/rspamadm/rspamadm.c
+++ b/src/rspamadm/rspamadm.c
@@ -208,7 +208,7 @@ main (gint argc, gchar **argv, gchar **env)
rspamd_strcase_equal, g_free, g_free);
ottery_init (NULL);
process_quark = g_quark_from_static_string ("rspamadm");
- cfg = rspamd_config_defaults ();
+ cfg = rspamd_config_new ();
cfg->libs_ctx = rspamd_init_libs ();
rspamd_main = g_malloc0 (sizeof (*rspamd_main));
rspamd_main->cfg = cfg;
diff --git a/src/rspamd.c b/src/rspamd.c
index 92b17b37e..a283abaa2 100644
--- a/src/rspamd.c
+++ b/src/rspamd.c
@@ -268,7 +268,7 @@ reread_config (struct rspamd_main *rspamd_main)
struct rspamd_config *tmp_cfg;
gchar *cfg_file;
- tmp_cfg = rspamd_config_defaults ();
+ tmp_cfg = rspamd_config_new ();
tmp_cfg->c_modules = g_hash_table_ref (rspamd_main->cfg->c_modules);
tmp_cfg->libs_ctx = rspamd_main->cfg->libs_ctx;
REF_RETAIN (tmp_cfg->libs_ctx);
@@ -805,7 +805,7 @@ main (gint argc, gchar **argv, gchar **env)
"main");
rspamd_main->stat = rspamd_mempool_alloc0_shared (rspamd_main->server_pool,
sizeof (struct rspamd_stat));
- rspamd_main->cfg = rspamd_config_defaults ();
+ rspamd_main->cfg = rspamd_config_new ();
#ifndef HAVE_SETPROCTITLE
init_title (argc, argv, env);
diff --git a/src/worker.c b/src/worker.c
index 8256b879e..933e83053 100644
--- a/src/worker.c
+++ b/src/worker.c
@@ -233,7 +233,7 @@ accept_socket (gint fd, short what, void *arg)
return;
}
- task = rspamd_task_new (worker);
+ task = rspamd_task_new (worker, ctx->cfg);
msg_info_task ("accepted connection from %s port %d",
rspamd_inet_address_to_string (addr),
@@ -267,7 +267,7 @@ accept_socket (gint fd, short what, void *arg)
/* Set up async session */
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 (ctx->key) {
rspamd_http_connection_set_key (task->http_conn, ctx->key);