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;
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);;
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;
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);
{
struct rspamd_stat_cbdata *cbdata = ud;
- rspamd_task_free_hard (cbdata->task);
+ rspamd_task_free (cbdata->task);
ucl_object_unref (cbdata->top);
}
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;
session->wrk->nconns --;
rspamd_inet_address_destroy (session->from_addr);
+ REF_RELEASE (session->cfg);
g_slice_free1 (sizeof (struct rspamd_controller_session), session);
}
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;
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);
* 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
}
struct rspamd_config *
-rspamd_config_defaults (void)
+rspamd_config_new (void)
{
struct rspamd_config *cfg;
* 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);
* 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;
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)
{
/**
* 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
struct rspamd_task *task;
struct rspamd_classifier_config *cl;
rspamd_inet_addr_t *from_addr;
+ struct rspamd_config *cfg;
gboolean is_spam;
};
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);
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}
};
}
/* 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)
{
struct rspamd_task *task = lua_check_task (L, 1);
if (task != NULL) {
- rspamd_task_free (task, FALSE);
+ rspamd_task_free (task);
}
return 0;
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);
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);
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);
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);
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 {
}
if (session->task != NULL) {
- rspamd_task_free (session->task, TRUE);
+ rspamd_task_free (session->task);
session->task = NULL;
}
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;
}
}
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;
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;
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) {
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;
}
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;
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);
"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);
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),
/* 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);