diff options
60 files changed, 580 insertions, 526 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c8f4dfdcc..0e2648198 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -35,6 +35,7 @@ SET(LIBRSPAMDSERVERSRC statfile.c statfile_sync.c symbols_cache.c + task.c url.c view.c) diff --git a/src/classifiers/bayes.c b/src/classifiers/bayes.c index 405336be7..9c81b2370 100644 --- a/src/classifiers/bayes.c +++ b/src/classifiers/bayes.c @@ -202,7 +202,7 @@ bayes_init (rspamd_mempool_t *pool, struct classifier_config *cfg) } gboolean -bayes_classify (struct classifier_ctx* ctx, statfile_pool_t *pool, GTree *input, struct worker_task *task, lua_State *L) +bayes_classify (struct classifier_ctx* ctx, statfile_pool_t *pool, GTree *input, struct rspamd_task *task, lua_State *L) { struct bayes_callback_data data; gchar *value; @@ -428,7 +428,7 @@ bayes_learn (struct classifier_ctx* ctx, statfile_pool_t *pool, const char *symb gboolean bayes_learn_spam (struct classifier_ctx* ctx, statfile_pool_t *pool, - GTree *input, struct worker_task *task, gboolean is_spam, lua_State *L, GError **err) + GTree *input, struct rspamd_task *task, gboolean is_spam, lua_State *L, GError **err) { struct bayes_callback_data data; gchar *value; @@ -528,7 +528,7 @@ bayes_learn_spam (struct classifier_ctx* ctx, statfile_pool_t *pool, } GList * -bayes_weights (struct classifier_ctx* ctx, statfile_pool_t *pool, GTree *input, struct worker_task *task) +bayes_weights (struct classifier_ctx* ctx, statfile_pool_t *pool, GTree *input, struct rspamd_task *task) { /* This function is unimplemented with new normalizer */ return NULL; diff --git a/src/classifiers/classifiers.h b/src/classifiers/classifiers.h index a316008cd..3f7b755f4 100644 --- a/src/classifiers/classifiers.h +++ b/src/classifiers/classifiers.h @@ -11,7 +11,7 @@ #define ALPHA 0.0001 struct classifier_config; -struct worker_task; +struct rspamd_task; struct classifier_ctx { rspamd_mempool_t *pool; @@ -29,13 +29,13 @@ struct classify_weight { struct classifier { char *name; struct classifier_ctx* (*init_func)(rspamd_mempool_t *pool, struct classifier_config *cf); - gboolean (*classify_func)(struct classifier_ctx* ctx, statfile_pool_t *pool, GTree *input, struct worker_task *task, lua_State *L); + gboolean (*classify_func)(struct classifier_ctx* ctx, statfile_pool_t *pool, GTree *input, struct rspamd_task *task, lua_State *L); gboolean (*learn_func)(struct classifier_ctx* ctx, statfile_pool_t *pool, const char *symbol, GTree *input, gboolean in_class, double *sum, double multiplier, GError **err); gboolean (*learn_spam_func)(struct classifier_ctx* ctx, statfile_pool_t *pool, - GTree *input, struct worker_task *task, gboolean is_spam, lua_State *L, GError **err); - GList* (*weights_func)(struct classifier_ctx* ctx, statfile_pool_t *pool, GTree *input, struct worker_task *task); + GTree *input, struct rspamd_task *task, gboolean is_spam, lua_State *L, GError **err); + GList* (*weights_func)(struct classifier_ctx* ctx, statfile_pool_t *pool, GTree *input, struct rspamd_task *task); }; /* Get classifier structure by name or return NULL if this name is not found */ @@ -43,21 +43,21 @@ struct classifier* get_classifier (const char *name); /* Winnow algorithm */ struct classifier_ctx* winnow_init (rspamd_mempool_t *pool, struct classifier_config *cf); -gboolean winnow_classify (struct classifier_ctx* ctx, statfile_pool_t *pool, GTree *input, struct worker_task *task, lua_State *L); +gboolean winnow_classify (struct classifier_ctx* ctx, statfile_pool_t *pool, GTree *input, struct rspamd_task *task, lua_State *L); gboolean winnow_learn (struct classifier_ctx* ctx, statfile_pool_t *pool, const char *symbol, GTree *input, gboolean in_class, double *sum, double multiplier, GError **err); gboolean winnow_learn_spam (struct classifier_ctx* ctx, statfile_pool_t *pool, - GTree *input, struct worker_task *task, gboolean is_spam, lua_State *L, GError **err); -GList *winnow_weights (struct classifier_ctx* ctx, statfile_pool_t *pool, GTree *input, struct worker_task *task); + GTree *input, struct rspamd_task *task, gboolean is_spam, lua_State *L, GError **err); +GList *winnow_weights (struct classifier_ctx* ctx, statfile_pool_t *pool, GTree *input, struct rspamd_task *task); /* Bayes algorithm */ struct classifier_ctx* bayes_init (rspamd_mempool_t *pool, struct classifier_config *cf); -gboolean bayes_classify (struct classifier_ctx* ctx, statfile_pool_t *pool, GTree *input, struct worker_task *task, lua_State *L); +gboolean bayes_classify (struct classifier_ctx* ctx, statfile_pool_t *pool, GTree *input, struct rspamd_task *task, lua_State *L); gboolean bayes_learn (struct classifier_ctx* ctx, statfile_pool_t *pool, const char *symbol, GTree *input, gboolean in_class, double *sum, double multiplier, GError **err); gboolean bayes_learn_spam (struct classifier_ctx* ctx, statfile_pool_t *pool, - GTree *input, struct worker_task *task, gboolean is_spam, lua_State *L, GError **err); -GList *bayes_weights (struct classifier_ctx* ctx, statfile_pool_t *pool, GTree *input, struct worker_task *task); + GTree *input, struct rspamd_task *task, gboolean is_spam, lua_State *L, GError **err); +GList *bayes_weights (struct classifier_ctx* ctx, statfile_pool_t *pool, GTree *input, struct rspamd_task *task); /* Array of all defined classifiers */ extern struct classifier classifiers[]; diff --git a/src/classifiers/winnow.c b/src/classifiers/winnow.c index b9b5b7af9..91d06aaf4 100644 --- a/src/classifiers/winnow.c +++ b/src/classifiers/winnow.c @@ -193,7 +193,7 @@ winnow_init (rspamd_mempool_t * pool, struct classifier_config *cfg) } gboolean -winnow_classify (struct classifier_ctx *ctx, statfile_pool_t * pool, GTree * input, struct worker_task *task, lua_State *L) +winnow_classify (struct classifier_ctx *ctx, statfile_pool_t * pool, GTree * input, struct rspamd_task *task, lua_State *L) { struct winnow_callback_data data; char *sumbuf, *value; @@ -282,7 +282,7 @@ winnow_classify (struct classifier_ctx *ctx, statfile_pool_t * pool, GTree * inp } GList * -winnow_weights (struct classifier_ctx *ctx, statfile_pool_t * pool, GTree * input, struct worker_task *task) +winnow_weights (struct classifier_ctx *ctx, statfile_pool_t * pool, GTree * input, struct rspamd_task *task) { struct winnow_callback_data data; long double res = 0.; @@ -593,7 +593,7 @@ end: gboolean winnow_learn_spam (struct classifier_ctx* ctx, statfile_pool_t *pool, - GTree *input, struct worker_task *task, gboolean is_spam, lua_State *L, GError **err) + GTree *input, struct rspamd_task *task, gboolean is_spam, lua_State *L, GError **err) { g_set_error (err, winnow_error_quark(), /* error domain */ diff --git a/src/controller.c b/src/controller.c index 01f2a6a83..3b48bf5cd 100644 --- a/src/controller.c +++ b/src/controller.c @@ -1279,7 +1279,7 @@ process_header (f_str_t *line, struct controller_session *session) static gboolean fin_learn_task (void *arg) { - struct worker_task *task = (struct worker_task *) arg; + struct rspamd_task *task = (struct rspamd_task *) arg; /* XXX: needs to be reworked */ @@ -1292,7 +1292,7 @@ fin_learn_task (void *arg) static void restore_learn_task (void *arg) { - struct worker_task *task = (struct worker_task *) arg; + struct rspamd_task *task = (struct rspamd_task *) arg; /* Special state */ } @@ -1305,7 +1305,7 @@ controller_read_socket (f_str_t * in, void *arg) gint len, i, r; gchar *s, **params, *cmd, out_buf[128]; struct controller_command *command; - struct worker_task *task; + struct rspamd_task *task; struct mime_text_part *part; GList *cur = NULL; GTree *tokens = NULL; diff --git a/src/dkim.c b/src/dkim.c index fd3807344..c7c8a35e1 100644 --- a/src/dkim.c +++ b/src/dkim.c @@ -1267,7 +1267,7 @@ rspamd_dkim_canonize_header_simple (rspamd_dkim_context_t *ctx, const gchar *hea } static gboolean -rspamd_dkim_canonize_header (rspamd_dkim_context_t *ctx, struct worker_task *task, const gchar *header_name, +rspamd_dkim_canonize_header (rspamd_dkim_context_t *ctx, struct rspamd_task *task, const gchar *header_name, guint count, gboolean is_sig) { struct raw_header *rh, *rh_iter; @@ -1337,7 +1337,7 @@ rspamd_dkim_canonize_header (rspamd_dkim_context_t *ctx, struct worker_task *tas * @return */ gint -rspamd_dkim_check (rspamd_dkim_context_t *ctx, rspamd_dkim_key_t *key, struct worker_task *task) +rspamd_dkim_check (rspamd_dkim_context_t *ctx, rspamd_dkim_key_t *key, struct rspamd_task *task) { const gchar *p, *headers_end = NULL, *end, *body_end; gboolean got_cr = FALSE, got_crlf = FALSE, got_lf = FALSE; diff --git a/src/dkim.h b/src/dkim.h index 897c65fef..29ec479b7 100644 --- a/src/dkim.h +++ b/src/dkim.h @@ -164,7 +164,7 @@ typedef struct rspamd_dkim_key_s { } rspamd_dkim_key_t; -struct worker_task; +struct rspamd_task; /* Err MUST be freed if it is not NULL, key is allocated by slice allocator */ typedef void (*dkim_key_handler_f)(rspamd_dkim_key_t *key, gsize keylen, rspamd_dkim_context_t *ctx, gpointer ud, GError *err); @@ -196,7 +196,7 @@ gboolean rspamd_get_dkim_key (rspamd_dkim_context_t *ctx, struct rspamd_dns_reso * @param task task to check * @return */ -gint rspamd_dkim_check (rspamd_dkim_context_t *ctx, rspamd_dkim_key_t *key, struct worker_task *task); +gint rspamd_dkim_check (rspamd_dkim_context_t *ctx, rspamd_dkim_key_t *key, struct rspamd_task *task); /** * Free DKIM key diff --git a/src/expressions.c b/src/expressions.c index 8642251da..5d19626bb 100644 --- a/src/expressions.c +++ b/src/expressions.c @@ -33,16 +33,16 @@ #include "lua/lua_common.h" #include "diff.h" -gboolean rspamd_compare_encoding (struct worker_task *task, GList * args, void *unused); -gboolean rspamd_header_exists (struct worker_task *task, GList * args, void *unused); -gboolean rspamd_parts_distance (struct worker_task *task, GList * args, void *unused); -gboolean rspamd_recipients_distance (struct worker_task *task, GList * args, void *unused); -gboolean rspamd_has_only_html_part (struct worker_task *task, GList * args, void *unused); -gboolean rspamd_is_recipients_sorted (struct worker_task *task, GList * args, void *unused); -gboolean rspamd_compare_transfer_encoding (struct worker_task *task, GList * args, void *unused); -gboolean rspamd_is_html_balanced (struct worker_task *task, GList * args, void *unused); -gboolean rspamd_has_html_tag (struct worker_task *task, GList * args, void *unused); -gboolean rspamd_has_fake_html (struct worker_task *task, GList * args, void *unused); +gboolean rspamd_compare_encoding (struct rspamd_task *task, GList * args, void *unused); +gboolean rspamd_header_exists (struct rspamd_task *task, GList * args, void *unused); +gboolean rspamd_parts_distance (struct rspamd_task *task, GList * args, void *unused); +gboolean rspamd_recipients_distance (struct rspamd_task *task, GList * args, void *unused); +gboolean rspamd_has_only_html_part (struct rspamd_task *task, GList * args, void *unused); +gboolean rspamd_is_recipients_sorted (struct rspamd_task *task, GList * args, void *unused); +gboolean rspamd_compare_transfer_encoding (struct rspamd_task *task, GList * args, void *unused); +gboolean rspamd_is_html_balanced (struct rspamd_task *task, GList * args, void *unused); +gboolean rspamd_has_html_tag (struct rspamd_task *task, GList * args, void *unused); +gboolean rspamd_has_fake_html (struct rspamd_task *task, GList * args, void *unused); /* * List of internal functions of rspamd @@ -792,7 +792,7 @@ parse_regexp (rspamd_mempool_t * pool, const gchar *line, gboolean raw_mode) } gboolean -call_expression_function (struct expression_function * func, struct worker_task * task, lua_State *L) +call_expression_function (struct expression_function * func, struct rspamd_task * task, lua_State *L) { struct _fl *selected, key; @@ -808,7 +808,7 @@ call_expression_function (struct expression_function * func, struct worker_task } struct expression_argument * -get_function_arg (struct expression *expr, struct worker_task *task, gboolean want_string) +get_function_arg (struct expression *expr, struct rspamd_task *task, gboolean want_string) { GQueue *stack; gsize cur, op1, op2; @@ -922,7 +922,7 @@ register_expression_function (const gchar *name, rspamd_internal_func_t func, vo } gboolean -rspamd_compare_encoding (struct worker_task *task, GList * args, void *unused) +rspamd_compare_encoding (struct rspamd_task *task, GList * args, void *unused) { struct expression_argument *arg; @@ -941,7 +941,7 @@ rspamd_compare_encoding (struct worker_task *task, GList * args, void *unused) } gboolean -rspamd_header_exists (struct worker_task * task, GList * args, void *unused) +rspamd_header_exists (struct rspamd_task * task, GList * args, void *unused) { struct expression_argument *arg; GList *headerlist; @@ -972,7 +972,7 @@ rspamd_header_exists (struct worker_task * task, GList * args, void *unused) * and return FALSE otherwise. */ gboolean -rspamd_parts_distance (struct worker_task * task, GList * args, void *unused) +rspamd_parts_distance (struct rspamd_task * task, GList * args, void *unused) { gint threshold, threshold2 = -1, diff; struct mime_text_part *p1, *p2; @@ -1103,7 +1103,7 @@ struct addr_list { #define MIN_RCPT_TO_COMPARE 7 gboolean -rspamd_recipients_distance (struct worker_task *task, GList * args, void *unused) +rspamd_recipients_distance (struct rspamd_task *task, GList * args, void *unused) { struct expression_argument *arg; InternetAddressList *cur; @@ -1188,7 +1188,7 @@ rspamd_recipients_distance (struct worker_task *task, GList * args, void *unused } gboolean -rspamd_has_only_html_part (struct worker_task * task, GList * args, void *unused) +rspamd_has_only_html_part (struct rspamd_task * task, GList * args, void *unused) { struct mime_text_part *p; GList *cur; @@ -1262,7 +1262,7 @@ is_recipient_list_sorted (const InternetAddressList * ia) } gboolean -rspamd_is_recipients_sorted (struct worker_task * task, GList * args, void *unused) +rspamd_is_recipients_sorted (struct rspamd_task * task, GList * args, void *unused) { /* Check all types of addresses */ if (is_recipient_list_sorted (g_mime_message_get_recipients (task->message, GMIME_RECIPIENT_TYPE_TO)) == TRUE) { @@ -1279,7 +1279,7 @@ rspamd_is_recipients_sorted (struct worker_task * task, GList * args, void *unus } gboolean -rspamd_compare_transfer_encoding (struct worker_task * task, GList * args, void *unused) +rspamd_compare_transfer_encoding (struct rspamd_task * task, GList * args, void *unused) { GMimeObject *part; #ifndef GMIME24 @@ -1340,7 +1340,7 @@ rspamd_compare_transfer_encoding (struct worker_task * task, GList * args, void } gboolean -rspamd_is_html_balanced (struct worker_task * task, GList * args, void *unused) +rspamd_is_html_balanced (struct rspamd_task * task, GList * args, void *unused) { struct mime_text_part *p; GList *cur; @@ -1388,7 +1388,7 @@ search_html_node_callback (GNode * node, gpointer data) } gboolean -rspamd_has_html_tag (struct worker_task * task, GList * args, void *unused) +rspamd_has_html_tag (struct rspamd_task * task, GList * args, void *unused) { struct mime_text_part *p; GList *cur; @@ -1426,7 +1426,7 @@ rspamd_has_html_tag (struct worker_task * task, GList * args, void *unused) } gboolean -rspamd_has_fake_html (struct worker_task * task, GList * args, void *unused) +rspamd_has_fake_html (struct rspamd_task * task, GList * args, void *unused) { struct mime_text_part *p; GList *cur; diff --git a/src/expressions.h b/src/expressions.h index 526af8686..954cc74f7 100644 --- a/src/expressions.h +++ b/src/expressions.h @@ -9,7 +9,7 @@ #include "config.h" #include <lua.h> -struct worker_task; +struct rspamd_task; struct rspamd_regexp; /** @@ -51,7 +51,7 @@ struct expression { struct expression *next; /**< chain link */ }; -typedef gboolean (*rspamd_internal_func_t)(struct worker_task *, GList *args, void *user_data); +typedef gboolean (*rspamd_internal_func_t)(struct rspamd_task *, GList *args, void *user_data); /** * Parse regexp line to regexp structure @@ -76,7 +76,7 @@ struct expression* parse_expression (rspamd_mempool_t *pool, gchar *line); * @param L lua specific state * @return TRUE or FALSE depending on function result */ -gboolean call_expression_function (struct expression_function *func, struct worker_task *task, lua_State *L); +gboolean call_expression_function (struct expression_function *func, struct rspamd_task *task, lua_State *L); /** * Register specified function to rspamd internal functions list @@ -111,7 +111,7 @@ void re_cache_del (const gchar *line, rspamd_mempool_t *pool); * @param pointer regexp data * @param result numeric result of this regexp */ -void task_cache_add (struct worker_task *task, struct rspamd_regexp *re, gint32 result); +void task_cache_add (struct rspamd_task *task, struct rspamd_regexp *re, gint32 result); /** * Check regexp in cache @@ -119,7 +119,7 @@ void task_cache_add (struct worker_task *task, struct rspamd_regexp *re, gint32 * @param pointer regexp data * @return numeric result if value exists or -1 if not */ -gint32 task_cache_check (struct worker_task *task, struct rspamd_regexp *re); +gint32 task_cache_check (struct rspamd_task *task, struct rspamd_regexp *re); /** * Parse and return a single function argument for a function (may recurse) @@ -128,6 +128,6 @@ gint32 task_cache_check (struct worker_task *task, struct rspamd_regexp *re); * @param want_string return NULL if argument is not a string * @return expression argument structure or NULL if failed */ -struct expression_argument *get_function_arg (struct expression *expr, struct worker_task *task, gboolean want_string); +struct expression_argument *get_function_arg (struct expression *expr, struct rspamd_task *task, gboolean want_string); #endif diff --git a/src/filter.c b/src/filter.c index d5e430e38..f0da620ad 100644 --- a/src/filter.c +++ b/src/filter.c @@ -63,7 +63,7 @@ filter_error_quark (void) } static void -insert_metric_result (struct worker_task *task, struct metric *metric, const gchar *symbol, +insert_metric_result (struct rspamd_task *task, struct metric *metric, const gchar *symbol, double flag, GList * opts, gboolean single) { struct metric_result *metric_res; @@ -164,7 +164,7 @@ G_LOCK_DEFINE (result_mtx); #endif static void -insert_result_common (struct worker_task *task, const gchar *symbol, double flag, GList * opts, gboolean single) +insert_result_common (struct rspamd_task *task, const gchar *symbol, double flag, GList * opts, gboolean single) { struct metric *metric; struct cache_item *item; @@ -212,21 +212,21 @@ insert_result_common (struct worker_task *task, const gchar *symbol, double flag /* Insert result that may be increased on next insertions */ void -insert_result (struct worker_task *task, const gchar *symbol, double flag, GList * opts) +insert_result (struct rspamd_task *task, const gchar *symbol, double flag, GList * opts) { insert_result_common (task, symbol, flag, opts, task->cfg->one_shot_mode); } /* Insert result as a single option */ void -insert_result_single (struct worker_task *task, const gchar *symbol, double flag, GList * opts) +insert_result_single (struct rspamd_task *task, const gchar *symbol, double flag, GList * opts) { insert_result_common (task, symbol, flag, opts, TRUE); } /* Return true if metric has score that is more than spam score for it */ static gboolean -check_metric_is_spam (struct worker_task *task, struct metric *metric) +check_metric_is_spam (struct rspamd_task *task, struct metric *metric) { struct metric_result *res; double ms, rs; @@ -260,7 +260,7 @@ check_metric_is_spam (struct worker_task *task, struct metric *metric) } gint -process_filters (struct worker_task *task) +process_filters (struct rspamd_task *task) { GList *cur; struct metric *metric; @@ -297,7 +297,7 @@ process_filters (struct worker_task *task) struct composites_data { - struct worker_task *task; + struct rspamd_task *task; struct metric_result *metric_res; GTree *symbols_to_remove; guint8 *checked; @@ -470,7 +470,7 @@ composites_foreach_callback (gpointer key, gpointer value, void *data) } static gboolean -check_autolearn (struct statfile_autolearn_params *params, struct worker_task *task) +check_autolearn (struct statfile_autolearn_params *params, struct rspamd_task *task) { gchar *metric_name = DEFAULT_METRIC; struct metric_result *metric_res; @@ -512,7 +512,7 @@ check_autolearn (struct statfile_autolearn_params *params, struct worker_task *t } void -process_autolearn (struct statfile *st, struct worker_task *task, GTree * tokens, struct classifier *classifier, gchar *filename, struct classifier_ctx *ctx) +process_autolearn (struct statfile *st, struct rspamd_task *task, GTree * tokens, struct classifier *classifier, gchar *filename, struct classifier_ctx *ctx) { stat_file_t *statfile; struct statfile *unused; @@ -557,7 +557,7 @@ composites_remove_symbols (gpointer key, gpointer value, gpointer data) static void composites_metric_callback (gpointer key, gpointer value, gpointer data) { - struct worker_task *task = (struct worker_task *)data; + struct rspamd_task *task = (struct rspamd_task *)data; struct composites_data *cd = rspamd_mempool_alloc (task->task_pool, sizeof (struct composites_data)); struct metric_result *metric_res = (struct metric_result *)value; @@ -576,13 +576,13 @@ composites_metric_callback (gpointer key, gpointer value, gpointer data) } void -make_composites (struct worker_task *task) +make_composites (struct rspamd_task *task) { g_hash_table_foreach (task->results, composites_metric_callback, task); } struct classifiers_cbdata { - struct worker_task *task; + struct rspamd_task *task; struct lua_locked_state *nL; }; @@ -590,7 +590,7 @@ static void classifiers_callback (gpointer value, void *arg) { struct classifiers_cbdata *cbdata = arg; - struct worker_task *task; + struct rspamd_task *task; struct classifier_config *cl = value; struct classifier_ctx *ctx; struct mime_text_part *text_part, *p1, *p2; @@ -706,7 +706,7 @@ classifiers_callback (gpointer value, void *arg) void -process_statfiles (struct worker_task *task) +process_statfiles (struct rspamd_task *task) { struct classifiers_cbdata cbdata; @@ -729,7 +729,7 @@ process_statfiles (struct worker_task *task) void process_statfiles_threaded (gpointer data, gpointer user_data) { - struct worker_task *task = (struct worker_task *)data; + struct rspamd_task *task = (struct rspamd_task *)data; struct lua_locked_state *nL = user_data; struct classifiers_cbdata cbdata; @@ -753,7 +753,7 @@ static void insert_metric_header (gpointer metric_name, gpointer metric_value, gpointer data) { #ifndef GLIB_HASH_COMPAT - struct worker_task *task = (struct worker_task *)data; + struct rspamd_task *task = (struct rspamd_task *)data; gint r = 0; /* Try to be rfc2822 compatible and avoid long headers with folding */ gchar header_name[128], outbuf[1000]; @@ -795,7 +795,7 @@ insert_metric_header (gpointer metric_name, gpointer metric_value, gpointer data } void -insert_headers (struct worker_task *task) +insert_headers (struct rspamd_task *task) { g_hash_table_foreach (task->results, insert_metric_header, task); } @@ -878,7 +878,7 @@ check_metric_action (double score, double required_score, struct metric *metric) } gboolean -learn_task (const gchar *statfile, struct worker_task *task, GError **err) +learn_task (const gchar *statfile, struct rspamd_task *task, GError **err) { GList *cur, *ex; struct classifier_config *cl; @@ -1006,7 +1006,7 @@ learn_task (const gchar *statfile, struct worker_task *task, GError **err) } gboolean -learn_task_spam (struct classifier_config *cl, struct worker_task *task, gboolean is_spam, GError **err) +learn_task_spam (struct classifier_config *cl, struct rspamd_task *task, gboolean is_spam, GError **err) { GList *cur, *ex; struct classifier_ctx *cls_ctx; diff --git a/src/filter.h b/src/filter.h index 79fae6449..b06dbeef1 100644 --- a/src/filter.h +++ b/src/filter.h @@ -9,12 +9,12 @@ #include "config.h" #include "symbols_cache.h" -struct worker_task; +struct rspamd_task; struct rspamd_settings; struct classifier_config; -typedef double (*metric_cons_func)(struct worker_task *task, const gchar *metric_name, const gchar *func_name); -typedef void (*filter_func)(struct worker_task *task); +typedef double (*metric_cons_func)(struct rspamd_task *task, const gchar *metric_name, const gchar *func_name); +typedef void (*filter_func)(struct rspamd_task *task); enum filter_type { C_FILTER, PERL_FILTER }; @@ -36,16 +36,6 @@ struct symbol { const gchar *name; }; -enum rspamd_metric_action { - METRIC_ACTION_REJECT = 0, - METRIC_ACTION_SOFT_REJECT, - METRIC_ACTION_REWRITE_SUBJECT, - METRIC_ACTION_ADD_HEADER, - METRIC_ACTION_GREYLIST, - METRIC_ACTION_NOACTION, - METRIC_ACTION_MAX -}; - struct metric_action { enum rspamd_metric_action action; gdouble score; @@ -91,13 +81,13 @@ struct rspamd_composite { * @param task worker's task that present message from user * @return 0 - if there is non-finished tasks and 1 if processing is completed */ -gint process_filters (struct worker_task *task); +gint process_filters (struct rspamd_task *task); /** * Process message with statfiles * @param task worker's task that present message from user */ -void process_statfiles (struct worker_task *task); +void process_statfiles (struct rspamd_task *task); /** * Process message with statfiles threaded @@ -113,7 +103,7 @@ void process_statfiles_threaded (gpointer data, gpointer user_data); * @param flag numeric weight for symbol * @param opts list of symbol's options */ -void insert_result (struct worker_task *task, const gchar *symbol, double flag, GList *opts); +void insert_result (struct rspamd_task *task, const gchar *symbol, double flag, GList *opts); /** * Insert a single result to task @@ -123,13 +113,13 @@ void insert_result (struct worker_task *task, const gchar *symbol, double flag, * @param flag numeric weight for symbol * @param opts list of symbol's options */ -void insert_result_single (struct worker_task *task, const gchar *symbol, double flag, GList *opts); +void insert_result_single (struct rspamd_task *task, const gchar *symbol, double flag, GList *opts); /** * Process all results and form composite metrics from existent metrics as it is defined in config * @param task worker's task that present message from user */ -void make_composites (struct worker_task *task); +void make_composites (struct rspamd_task *task); /** * Default consolidation function for metric, it get all symbols and multiply symbol @@ -138,7 +128,7 @@ void make_composites (struct worker_task *task); * @param metric_name name of metric * @return result metric weight */ -double factor_consolidation_func (struct worker_task *task, const gchar *metric_name, const gchar *unused); +double factor_consolidation_func (struct rspamd_task *task, const gchar *metric_name, const gchar *unused); /* * Learn specified statfile with message in a task @@ -147,7 +137,7 @@ double factor_consolidation_func (struct worker_task *task, const gchar *metric_ * @param err pointer to GError * @return true if learn succeed */ -gboolean learn_task (const gchar *statfile, struct worker_task *task, GError **err); +gboolean learn_task (const gchar *statfile, struct rspamd_task *task, GError **err); /* * Learn specified statfile with message in a task @@ -156,7 +146,7 @@ gboolean learn_task (const gchar *statfile, struct worker_task *task, GError **e * @param err pointer to GError * @return true if learn succeed */ -gboolean learn_task_spam (struct classifier_config *cl, struct worker_task *task, gboolean is_spam, GError **err); +gboolean learn_task_spam (struct classifier_config *cl, struct rspamd_task *task, gboolean is_spam, GError **err); /* * Get action from a string diff --git a/src/html.c b/src/html.c index 1f6d091d3..028c54f6c 100644 --- a/src/html.c +++ b/src/html.c @@ -656,7 +656,7 @@ decode_entitles (gchar *s, guint * len) } static void -check_phishing (struct worker_task *task, struct uri *href_url, const gchar *url_text, gsize remain, tag_id_t id) +check_phishing (struct rspamd_task *task, struct uri *href_url, const gchar *url_text, gsize remain, tag_id_t id) { struct uri *new; gchar *url_str; @@ -770,7 +770,7 @@ check_phishing (struct worker_task *task, struct uri *href_url, const gchar *url } static void -parse_tag_url (struct worker_task *task, struct mime_text_part *part, tag_id_t id, +parse_tag_url (struct rspamd_task *task, struct mime_text_part *part, tag_id_t id, gchar *tag_text, gsize tag_len, gsize remain) { gchar *c = NULL, *p, *url_text; @@ -869,7 +869,7 @@ parse_tag_url (struct worker_task *task, struct mime_text_part *part, tag_id_t i } gboolean -add_html_node (struct worker_task *task, rspamd_mempool_t * pool, struct mime_text_part *part, +add_html_node (struct rspamd_task *task, rspamd_mempool_t * pool, struct mime_text_part *part, gchar *tag_text, gsize tag_len, gsize remain, GNode ** cur_level) { GNode *new; diff --git a/src/html.h b/src/html.h index 601f076d2..3ea758e60 100644 --- a/src/html.h +++ b/src/html.h @@ -205,12 +205,12 @@ struct html_node { }; /* Forwarded declaration */ -struct worker_task; +struct rspamd_task; /* * Add a single node to the tags tree */ -gboolean add_html_node (struct worker_task *task, rspamd_mempool_t *pool, +gboolean add_html_node (struct rspamd_task *task, rspamd_mempool_t *pool, struct mime_text_part *part, gchar *tag_text, gsize tag_len, gsize remain, GNode **cur_level); /* diff --git a/src/images.c b/src/images.c index e3b300166..ff07bbd72 100644 --- a/src/images.c +++ b/src/images.c @@ -32,11 +32,11 @@ static const guint8 jpg_sig2[] = {'J', 'F', 'I', 'F'}; static const guint8 gif_signature[] = {'G', 'I', 'F', '8'}; static const guint8 bmp_signature[] = {'B', 'M'}; -static void process_image (struct worker_task *task, struct mime_part *part); +static void process_image (struct rspamd_task *task, struct mime_part *part); void -process_images (struct worker_task *task) +process_images (struct rspamd_task *task) { GList *cur; struct mime_part *part; @@ -83,7 +83,7 @@ detect_image_type (GByteArray *data) static struct rspamd_image * -process_png_image (struct worker_task *task, GByteArray *data) +process_png_image (struct rspamd_task *task, GByteArray *data) { struct rspamd_image *img; guint32 t; @@ -117,7 +117,7 @@ process_png_image (struct worker_task *task, GByteArray *data) } static struct rspamd_image * -process_jpg_image (struct worker_task *task, GByteArray *data) +process_jpg_image (struct rspamd_task *task, GByteArray *data) { guint8 *p; guint16 t; @@ -146,7 +146,7 @@ process_jpg_image (struct worker_task *task, GByteArray *data) } static struct rspamd_image * -process_gif_image (struct worker_task *task, GByteArray *data) +process_gif_image (struct rspamd_task *task, GByteArray *data) { struct rspamd_image *img; guint8 *p; @@ -171,7 +171,7 @@ process_gif_image (struct worker_task *task, GByteArray *data) } static struct rspamd_image * -process_bmp_image (struct worker_task *task, GByteArray *data) +process_bmp_image (struct rspamd_task *task, GByteArray *data) { struct rspamd_image *img; gint32 t; @@ -197,7 +197,7 @@ process_bmp_image (struct worker_task *task, GByteArray *data) } static void -process_image (struct worker_task *task, struct mime_part *part) +process_image (struct rspamd_task *task, struct mime_part *part) { enum known_image_types type; struct rspamd_image *img = NULL; diff --git a/src/images.h b/src/images.h index 5561ecb7d..c43941ebc 100644 --- a/src/images.h +++ b/src/images.h @@ -23,7 +23,7 @@ struct rspamd_image { /* * Process images from a worker task */ -void process_images (struct worker_task *task); +void process_images (struct rspamd_task *task); /* * Get textual representation of an image's type diff --git a/src/lmtp.c b/src/lmtp.c index 8ffef771f..c79c46376 100644 --- a/src/lmtp.c +++ b/src/lmtp.c @@ -103,7 +103,7 @@ sigusr1_handler (gint fd, short what, void *arg) static void rcpt_destruct (void *pointer) { - struct worker_task *task = (struct worker_task *)pointer; + struct rspamd_task *task = (struct rspamd_task *)pointer; if (task->rcpt) { g_list_free (task->rcpt); @@ -118,7 +118,7 @@ free_lmtp_task (struct rspamd_lmtp_proto *lmtp, gboolean is_soft) { GList *part; struct mime_part *p; - struct worker_task *task = lmtp->task; + struct rspamd_task *task = lmtp->task; if (lmtp) { debug_task ("free pointer %p", lmtp->task); @@ -149,7 +149,7 @@ static gboolean lmtp_read_socket (f_str_t * in, void *arg) { struct rspamd_lmtp_proto *lmtp = (struct rspamd_lmtp_proto *)arg; - struct worker_task *task = lmtp->task; + struct rspamd_task *task = lmtp->task; ssize_t r; switch (task->state) { @@ -195,7 +195,7 @@ static gboolean lmtp_write_socket (void *arg) { struct rspamd_lmtp_proto *lmtp = (struct rspamd_lmtp_proto *)arg; - struct worker_task *task = lmtp->task; + struct rspamd_task *task = lmtp->task; switch (lmtp->task->state) { case WRITE_REPLY: @@ -243,7 +243,7 @@ accept_socket (gint fd, short what, void *arg) { struct rspamd_worker *worker = (struct rspamd_worker *)arg; union sa_union su; - struct worker_task *new_task; + struct rspamd_task *new_task; struct rspamd_lmtp_proto *lmtp; socklen_t addrlen = sizeof (su.ss); gint nfd; diff --git a/src/lmtp_proto.c b/src/lmtp_proto.c index 06edc06ad..81cd13607 100644 --- a/src/lmtp_proto.c +++ b/src/lmtp_proto.c @@ -89,7 +89,7 @@ extract_mail (rspamd_mempool_t * pool, f_str_t * line) } static gboolean -out_lmtp_reply (struct worker_task *task, gint code, gchar *rcode, gchar *msg) +out_lmtp_reply (struct rspamd_task *task, gint code, gchar *rcode, gchar *msg) { gchar outbuf[OUTBUFSIZ]; gint r; @@ -252,7 +252,7 @@ read_lmtp_input_line (struct rspamd_lmtp_proto *lmtp, f_str_t * line) } struct mta_callback_data { - struct worker_task *task; + struct rspamd_task *task; rspamd_io_dispatcher_t *dispatcher; enum { LMTP_WANT_GREETING, @@ -445,7 +445,7 @@ mta_err_socket (GError * err, void *arg) * Deliver mail via smtp or lmtp */ static gint -lmtp_deliver_mta (struct worker_task *task) +lmtp_deliver_mta (struct rspamd_task *task) { gint sock; struct sockaddr_un *un; @@ -471,7 +471,7 @@ lmtp_deliver_mta (struct worker_task *task) } static gchar * -format_lda_args (struct worker_task *task) +format_lda_args (struct rspamd_task *task) { gchar *res, *c, *r; size_t len; @@ -555,7 +555,7 @@ format_lda_args (struct worker_task *task) } static gint -lmtp_deliver_lda (struct worker_task *task) +lmtp_deliver_lda (struct rspamd_task *task) { gchar *args, **argv; GMimeStream *stream; @@ -652,7 +652,7 @@ lmtp_deliver_lda (struct worker_task *task) } gint -lmtp_deliver_message (struct worker_task *task) +lmtp_deliver_message (struct rspamd_task *task) { if (task->cfg->deliver_agent_path != NULL) { /* Do deliver to LDA */ @@ -668,7 +668,7 @@ gint write_lmtp_reply (struct rspamd_lmtp_proto *lmtp) { gint r; - struct worker_task *task = lmtp->task; + struct rspamd_task *task = lmtp->task; debug_task ("writing reply to client"); if (lmtp->task->error_code != 0) { diff --git a/src/lmtp_proto.h b/src/lmtp_proto.h index 11d994e69..143915818 100644 --- a/src/lmtp_proto.h +++ b/src/lmtp_proto.h @@ -3,7 +3,7 @@ #include "config.h" -struct worker_task; +struct rspamd_task; enum lmtp_state { LMTP_READ_LHLO, @@ -15,7 +15,7 @@ enum lmtp_state { }; struct rspamd_lmtp_proto { - struct worker_task *task; + struct rspamd_task *task; enum lmtp_state state; }; @@ -32,7 +32,7 @@ gint read_lmtp_input_line (struct rspamd_lmtp_proto *lmtp, f_str_t *line); * @param task task object * @return 0 if we wrote message and -1 if there was some error */ -gint lmtp_deliver_message (struct worker_task *task); +gint lmtp_deliver_message (struct rspamd_task *task); /** * Write reply for specified lmtp object diff --git a/src/lua/lua_cfg_file.c b/src/lua/lua_cfg_file.c index cc9c71309..8325db107 100644 --- a/src/lua/lua_cfg_file.c +++ b/src/lua/lua_cfg_file.c @@ -193,7 +193,7 @@ lua_post_load_config (struct config_file *cfg) /* Handle lua dynamic config param */ gboolean -lua_handle_param (struct worker_task *task, gchar *mname, gchar *optname, enum lua_var_type expected_type, gpointer *res) +lua_handle_param (struct rspamd_task *task, gchar *mname, gchar *optname, enum lua_var_type expected_type, gpointer *res) { /* xxx: Adopt this for rcl */ diff --git a/src/lua/lua_classifier.c b/src/lua/lua_classifier.c index 82e7ea2b7..1e33f704d 100644 --- a/src/lua/lua_classifier.c +++ b/src/lua/lua_classifier.c @@ -80,11 +80,11 @@ lua_check_classifier (lua_State * L) } static GList * -call_classifier_pre_callback (struct classifier_config *ccf, struct worker_task *task, +call_classifier_pre_callback (struct classifier_config *ccf, struct rspamd_task *task, lua_State *L, gboolean is_learn, gboolean is_spam) { struct classifier_config **pccf; - struct worker_task **ptask; + struct rspamd_task **ptask; struct statfile **pst; GList *res = NULL; @@ -92,7 +92,7 @@ call_classifier_pre_callback (struct classifier_config *ccf, struct worker_task lua_setclass (L, "rspamd{classifier}", -1); *pccf = ccf; - ptask = lua_newuserdata (L, sizeof (struct worker_task *)); + ptask = lua_newuserdata (L, sizeof (struct rspamd_task *)); lua_setclass (L, "rspamd{task}", -1); *ptask = task; @@ -120,7 +120,7 @@ call_classifier_pre_callback (struct classifier_config *ccf, struct worker_task /* Return list of statfiles that should be checked for this message */ GList * -call_classifier_pre_callbacks (struct classifier_config *ccf, struct worker_task *task, +call_classifier_pre_callbacks (struct classifier_config *ccf, struct rspamd_task *task, gboolean is_learn, gboolean is_spam, lua_State *L) { GList *res = NULL, *cur; @@ -158,11 +158,11 @@ call_classifier_pre_callbacks (struct classifier_config *ccf, struct worker_task /* Return result mark for statfile */ double -call_classifier_post_callbacks (struct classifier_config *ccf, struct worker_task *task, double in, lua_State *L) +call_classifier_post_callbacks (struct classifier_config *ccf, struct rspamd_task *task, double in, lua_State *L) { struct classifier_callback_data *cd; struct classifier_config **pccf; - struct worker_task **ptask; + struct rspamd_task **ptask; double out = in; GList *cur; @@ -176,7 +176,7 @@ call_classifier_post_callbacks (struct classifier_config *ccf, struct worker_tas lua_setclass (L, "rspamd{classifier}", -1); *pccf = ccf; - ptask = lua_newuserdata (L, sizeof (struct worker_task *)); + ptask = lua_newuserdata (L, sizeof (struct rspamd_task *)); lua_setclass (L, "rspamd{task}", -1); *ptask = task; diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c index 0774615e5..ee624db3d 100644 --- a/src/lua/lua_common.c +++ b/src/lua/lua_common.c @@ -400,14 +400,14 @@ init_lua_filters (struct config_file *cfg) /* Callback functions */ gint -lua_call_filter (const gchar *function, struct worker_task *task) +lua_call_filter (const gchar *function, struct rspamd_task *task) { gint result; - struct worker_task **ptask; + struct rspamd_task **ptask; lua_State *L = task->cfg->lua_state; lua_getglobal (L, function); - ptask = lua_newuserdata (L, sizeof (struct worker_task *)); + ptask = lua_newuserdata (L, sizeof (struct rspamd_task *)); lua_setclass (L, "rspamd{task}", -1); *ptask = task; @@ -426,7 +426,7 @@ lua_call_filter (const gchar *function, struct worker_task *task) } gint -lua_call_chain_filter (const gchar *function, struct worker_task *task, gint *marks, guint number) +lua_call_chain_filter (const gchar *function, struct rspamd_task *task, gint *marks, guint number) { gint result; guint i; @@ -454,17 +454,17 @@ lua_call_chain_filter (const gchar *function, struct worker_task *task, gint *ma /* Call custom lua function in rspamd expression */ gboolean lua_call_expression_func (gpointer lua_data, - struct worker_task *task, GList *args, gboolean *res) + struct rspamd_task *task, GList *args, gboolean *res) { lua_State *L = task->cfg->lua_state; - struct worker_task **ptask; + struct rspamd_task **ptask; GList *cur; struct expression_argument *arg; int nargs = 1, pop = 0; lua_rawgeti (L, LUA_REGISTRYINDEX, GPOINTER_TO_INT (lua_data)); /* Now we got function in top of stack */ - ptask = lua_newuserdata (L, sizeof (struct worker_task *)); + ptask = lua_newuserdata (L, sizeof (struct rspamd_task *)); lua_setclass (L, "rspamd{task}", -1); *ptask = task; @@ -511,7 +511,7 @@ lua_call_expression_func (gpointer lua_data, * LUA custom consolidation function */ struct consolidation_callback_data { - struct worker_task *task; + struct rspamd_task *task; double score; const gchar *func; }; @@ -542,7 +542,7 @@ lua_consolidation_callback (gpointer key, gpointer value, gpointer arg) } double -lua_consolidation_func (struct worker_task *task, const gchar *metric_name, const gchar *function_name) +lua_consolidation_func (struct rspamd_task *task, const gchar *metric_name, const gchar *function_name) { struct metric_result *metric_res; double res = 0.; diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h index d03ca168e..9902fd845 100644 --- a/src/lua/lua_common.h +++ b/src/lua/lua_common.h @@ -179,17 +179,17 @@ gint luaopen_dns_resolver (lua_State * L); gint luaopen_rsa (lua_State * L); gint luaopen_ip (lua_State * L); -gint lua_call_filter (const gchar *function, struct worker_task *task); -gint lua_call_chain_filter (const gchar *function, struct worker_task *task, gint *marks, guint number); -double lua_consolidation_func (struct worker_task *task, const gchar *metric_name, const gchar *function_name); -gboolean lua_call_expression_func (gpointer lua_data, struct worker_task *task, GList *args, gboolean *res); -void lua_call_post_filters (struct worker_task *task); -void lua_call_pre_filters (struct worker_task *task); +gint lua_call_filter (const gchar *function, struct rspamd_task *task); +gint lua_call_chain_filter (const gchar *function, struct rspamd_task *task, gint *marks, guint number); +double lua_consolidation_func (struct rspamd_task *task, const gchar *metric_name, const gchar *function_name); +gboolean 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); /* Classify functions */ -GList *call_classifier_pre_callbacks (struct classifier_config *ccf, struct worker_task *task, gboolean is_learn, gboolean is_spam, lua_State *L); -double call_classifier_post_callbacks (struct classifier_config *ccf, struct worker_task *task, double in, lua_State *L); +GList *call_classifier_pre_callbacks (struct classifier_config *ccf, struct rspamd_task *task, gboolean is_learn, gboolean is_spam, lua_State *L); +double call_classifier_post_callbacks (struct classifier_config *ccf, struct rspamd_task *task, double in, lua_State *L); double lua_normalizer_func (struct config_file *cfg, long double score, void *params); @@ -197,7 +197,7 @@ double lua_normalizer_func (struct config_file *cfg, long double score, void *pa void lua_post_load_config (struct config_file *cfg); void lua_process_element (struct config_file *cfg, const gchar *name, const gchar *module_name, struct module_opt *opt, gint idx, gboolean allow_meta); -gboolean lua_handle_param (struct worker_task *task, gchar *mname, gchar *optname, +gboolean lua_handle_param (struct rspamd_task *task, gchar *mname, gchar *optname, enum lua_var_type expected_type, gpointer *res); gboolean lua_check_condition (struct config_file *cfg, const gchar *condition); void lua_dumpstack (lua_State *L); diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index b8be57896..d922cac47 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -266,10 +266,10 @@ lua_destroy_cfg_symbol (gpointer ud) } static gboolean -lua_config_function_callback (struct worker_task *task, GList *args, void *user_data) +lua_config_function_callback (struct rspamd_task *task, GList *args, void *user_data) { struct lua_callback_data *cd = user_data; - struct worker_task **ptask; + struct rspamd_task **ptask; gint i = 1; struct expression_argument *arg; GList *cur; @@ -281,7 +281,7 @@ lua_config_function_callback (struct worker_task *task, GList *args, void *user_ else { lua_getglobal (cd->L, cd->callback.name); } - ptask = lua_newuserdata (cd->L, sizeof (struct worker_task *)); + ptask = lua_newuserdata (cd->L, sizeof (struct rspamd_task *)); lua_setclass (cd->L, "rspamd{task}", -1); *ptask = task; /* Now push all arguments */ @@ -346,10 +346,10 @@ lua_config_register_module_option (lua_State *L) } void -lua_call_post_filters (struct worker_task *task) +lua_call_post_filters (struct rspamd_task *task) { struct lua_callback_data *cd; - struct worker_task **ptask; + struct rspamd_task **ptask; GList *cur; cur = task->cfg->post_filters; @@ -361,7 +361,7 @@ lua_call_post_filters (struct worker_task *task) else { lua_getglobal (cd->L, cd->callback.name); } - ptask = lua_newuserdata (cd->L, sizeof (struct worker_task *)); + ptask = lua_newuserdata (cd->L, sizeof (struct rspamd_task *)); lua_setclass (cd->L, "rspamd{task}", -1); *ptask = task; @@ -399,10 +399,10 @@ lua_config_register_post_filter (lua_State *L) } void -lua_call_pre_filters (struct worker_task *task) +lua_call_pre_filters (struct rspamd_task *task) { struct lua_callback_data *cd; - struct worker_task **ptask; + struct rspamd_task **ptask; GList *cur; cur = task->cfg->pre_filters; @@ -414,7 +414,7 @@ lua_call_pre_filters (struct worker_task *task) else { lua_getglobal (cd->L, cd->callback.name); } - ptask = lua_newuserdata (cd->L, sizeof (struct worker_task *)); + ptask = lua_newuserdata (cd->L, sizeof (struct rspamd_task *)); lua_setclass (cd->L, "rspamd{task}", -1); *ptask = task; @@ -547,10 +547,10 @@ lua_config_add_kv_map (lua_State *L) static void -lua_metric_symbol_callback (struct worker_task *task, gpointer ud) +lua_metric_symbol_callback (struct rspamd_task *task, gpointer ud) { struct lua_callback_data *cd = ud; - struct worker_task **ptask; + struct rspamd_task **ptask; if (cd->cb_is_ref) { lua_rawgeti (cd->L, LUA_REGISTRYINDEX, cd->callback.ref); @@ -558,7 +558,7 @@ lua_metric_symbol_callback (struct worker_task *task, gpointer ud) else { lua_getglobal (cd->L, cd->callback.name); } - ptask = lua_newuserdata (cd->L, sizeof (struct worker_task *)); + ptask = lua_newuserdata (cd->L, sizeof (struct rspamd_task *)); lua_setclass (cd->L, "rspamd{task}", -1); *ptask = task; @@ -851,7 +851,7 @@ static gint lua_trie_search_task (lua_State *L) { rspamd_trie_t *trie = lua_check_trie (L); - struct worker_task *task; + struct rspamd_task *task; struct mime_text_part *part; GList *cur; const gchar *pos, *end; @@ -862,7 +862,7 @@ lua_trie_search_task (lua_State *L) if (trie) { ud = luaL_checkudata (L, 2, "rspamd{task}"); luaL_argcheck (L, ud != NULL, 1, "'task' expected"); - task = ud ? *((struct worker_task **)ud) : NULL; + task = ud ? *((struct rspamd_task **)ud) : NULL; if (task) { lua_newtable (L); cur = task->text_parts; diff --git a/src/lua/lua_http.c b/src/lua/lua_http.c index 31bcffb77..60253c000 100644 --- a/src/lua/lua_http.c +++ b/src/lua/lua_http.c @@ -44,7 +44,7 @@ struct lua_http_header { }; struct lua_http_ud { - struct worker_task *task; + struct rspamd_task *task; gint parser_state; struct rspamd_async_session *s; rspamd_mempool_t *pool; @@ -81,13 +81,13 @@ lua_http_fin (void *arg) static void lua_http_push_error (gint code, struct lua_http_ud *ud) { - struct worker_task **ptask; + struct rspamd_task **ptask; gint num; /* Push error */ if (ud->callback) { lua_getglobal (ud->L, ud->callback); - ptask = lua_newuserdata (ud->L, sizeof (struct worker_task *)); + ptask = lua_newuserdata (ud->L, sizeof (struct rspamd_task *)); lua_setclass (ud->L, "rspamd{task}", -1); *ptask = ud->task; num = 4; @@ -122,13 +122,13 @@ lua_http_push_reply (f_str_t *in, struct lua_http_ud *ud) { GList *cur; struct lua_http_header *header; - struct worker_task **ptask; + struct rspamd_task **ptask; gint num; if (ud->callback) { /* Push error */ lua_getglobal (ud->L, ud->callback); - ptask = lua_newuserdata (ud->L, sizeof (struct worker_task *)); + ptask = lua_newuserdata (ud->L, sizeof (struct rspamd_task *)); lua_setclass (ud->L, "rspamd{task}", -1); *ptask = ud->task; @@ -339,7 +339,7 @@ lua_http_dns_callback (struct rdns_reply *reply, gpointer arg) * Common request function */ static gint -lua_http_make_request_common (lua_State *L, struct worker_task *task, const gchar *callback, +lua_http_make_request_common (lua_State *L, struct rspamd_task *task, const gchar *callback, const gchar *hostname, const gchar *path, const gchar *data, gint top) { gint r, s, datalen; @@ -518,7 +518,7 @@ lua_http_make_request_common_new (lua_State *L, struct rspamd_async_session *ses static gint lua_http_make_post_request (lua_State *L) { - struct worker_task *task, **ptask; + struct rspamd_task *task, **ptask; rspamd_mempool_t *pool, **ppool; struct rspamd_async_session *session, **psession; struct event_base *base, **pbase; @@ -579,7 +579,7 @@ lua_http_make_post_request (lua_State *L) static gint lua_http_make_get_request (lua_State *L) { - struct worker_task *task, **ptask; + struct rspamd_task *task, **ptask; rspamd_mempool_t *pool, **ppool; struct rspamd_async_session *session, **psession; struct event_base *base, **pbase; diff --git a/src/lua/lua_redis.c b/src/lua/lua_redis.c index 33caefad3..2642daf9a 100644 --- a/src/lua/lua_redis.c +++ b/src/lua/lua_redis.c @@ -53,7 +53,7 @@ static const struct luaL_reg redislib_m[] = { struct lua_redis_userdata { redisAsyncContext *ctx; lua_State *L; - struct worker_task *task; + struct rspamd_task *task; gint cbref; gchar *server; struct in_addr ina; @@ -68,12 +68,12 @@ struct lua_redis_userdata { * @param L lua stack * @return worker task object */ -static struct worker_task * +static struct rspamd_task * lua_check_task (lua_State * L) { void *ud = luaL_checkudata (L, 1, "rspamd{task}"); luaL_argcheck (L, ud != NULL, 1, "'task' expected"); - return ud ? *((struct worker_task **)ud) : NULL; + return ud ? *((struct rspamd_task **)ud) : NULL; } static void @@ -95,11 +95,11 @@ lua_redis_fin (void *arg) static void lua_redis_push_error (const gchar *err, struct lua_redis_userdata *ud, gboolean connected) { - struct worker_task **ptask; + struct rspamd_task **ptask; /* Push error */ lua_rawgeti (ud->L, LUA_REGISTRYINDEX, ud->cbref); - ptask = lua_newuserdata (ud->L, sizeof (struct worker_task *)); + ptask = lua_newuserdata (ud->L, sizeof (struct rspamd_task *)); lua_setclass (ud->L, "rspamd{task}", -1); *ptask = ud->task; @@ -125,11 +125,11 @@ lua_redis_push_error (const gchar *err, struct lua_redis_userdata *ud, gboolean static void lua_redis_push_data (const redisReply *r, struct lua_redis_userdata *ud) { - struct worker_task **ptask; + struct rspamd_task **ptask; /* Push error */ lua_rawgeti (ud->L, LUA_REGISTRYINDEX, ud->cbref); - ptask = lua_newuserdata (ud->L, sizeof (struct worker_task *)); + ptask = lua_newuserdata (ud->L, sizeof (struct rspamd_task *)); lua_setclass (ud->L, "rspamd{task}", -1); *ptask = ud->task; @@ -271,7 +271,7 @@ lua_redis_dns_callback (struct rdns_reply *reply, gpointer arg) static int lua_redis_make_request (lua_State *L) { - struct worker_task *task; + struct rspamd_task *task; struct lua_redis_userdata *ud; const gchar *server, *tmp; guint port, i; diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index 075260359..de42989da 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -220,12 +220,12 @@ static const struct luaL_reg urllib_m[] = { }; /* Utility functions */ -static struct worker_task * +static struct rspamd_task * lua_check_task (lua_State * L) { void *ud = luaL_checkudata (L, 1, "rspamd{task}"); luaL_argcheck (L, ud != NULL, 1, "'task' expected"); - return ud ? *((struct worker_task **)ud) : NULL; + return ud ? *((struct rspamd_task **)ud) : NULL; } static struct mime_text_part * @@ -265,7 +265,7 @@ lua_check_url (lua_State * L) static int lua_task_create_empty (lua_State *L) { - struct worker_task **ptask, *task; + struct rspamd_task **ptask, *task; task = construct_task (NULL); ptask = lua_newuserdata (L, sizeof (gpointer)); @@ -277,7 +277,7 @@ lua_task_create_empty (lua_State *L) static int lua_task_create_from_buffer (lua_State *L) { - struct worker_task **ptask, *task; + struct rspamd_task **ptask, *task; const gchar *data; size_t len; @@ -295,7 +295,7 @@ lua_task_create_from_buffer (lua_State *L) static int lua_task_process_message (lua_State *L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); if (task != NULL && task->msg != NULL && task->msg->len > 0) { if (process_message (task) == 0) { @@ -314,7 +314,7 @@ lua_task_process_message (lua_State *L) static int lua_task_set_cfg (lua_State *L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); void *ud = luaL_checkudata (L, 2, "rspamd{config}"); luaL_argcheck (L, ud != NULL, 1, "'config' expected"); @@ -325,7 +325,7 @@ lua_task_set_cfg (lua_State *L) static int lua_task_destroy (lua_State *L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); if (task != NULL) { free_task (task, FALSE); @@ -338,7 +338,7 @@ static int lua_task_get_message (lua_State * L) { GMimeMessage **pmsg; - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); if (task != NULL && task->message != NULL) { pmsg = lua_newuserdata (L, sizeof (GMimeMessage *)); @@ -355,7 +355,7 @@ static int lua_task_get_mempool (lua_State * L) { rspamd_mempool_t **ppool; - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); if (task != NULL) { ppool = lua_newuserdata (L, sizeof (rspamd_mempool_t *)); @@ -372,7 +372,7 @@ static int lua_task_get_session (lua_State * L) { struct rspamd_async_session **psession; - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); if (task != NULL) { psession = lua_newuserdata (L, sizeof (void *)); @@ -389,7 +389,7 @@ static int lua_task_get_ev_base (lua_State * L) { struct event_base **pbase; - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); if (task != NULL) { pbase = lua_newuserdata (L, sizeof (struct event_base *)); @@ -405,7 +405,7 @@ lua_task_get_ev_base (lua_State * L) static gint lua_task_insert_result (lua_State * L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); const gchar *symbol_name, *param; double flag; GList *params = NULL; @@ -429,7 +429,7 @@ lua_task_insert_result (lua_State * L) static gint lua_task_set_pre_result (lua_State * L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); gchar *action_str; guint action; @@ -471,7 +471,7 @@ lua_tree_url_callback (gpointer key, gpointer value, gpointer ud) static gint lua_task_get_urls (lua_State * L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); struct lua_tree_cb_data cb; if (task) { @@ -489,7 +489,7 @@ lua_task_get_urls (lua_State * L) static gint lua_task_get_emails (lua_State * L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); struct lua_tree_cb_data cb; if (task) { @@ -508,7 +508,7 @@ static gint lua_task_get_text_parts (lua_State * L) { gint i = 1; - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); GList *cur; struct mime_text_part *part, **ppart; @@ -534,7 +534,7 @@ static gint lua_task_get_parts (lua_State * L) { gint i = 1; - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); GList *cur; struct mime_part *part, **ppart; @@ -560,7 +560,7 @@ lua_task_get_parts (lua_State * L) static gint lua_task_get_raw_headers (lua_State * L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); if (task) { lua_pushstring (L, task->raw_headers_str); @@ -575,7 +575,7 @@ lua_task_get_raw_headers (lua_State * L) static gint lua_task_get_raw_header_common (lua_State * L, gboolean strong) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); struct raw_header *rh; gint i = 1; const gchar *name; @@ -649,7 +649,7 @@ lua_task_get_raw_header_strong (lua_State * L) static gint lua_task_get_received_headers (lua_State * L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); GList *cur; struct received_header *rh; gint i = 1; @@ -691,7 +691,7 @@ lua_task_get_received_headers (lua_State * L) static gint lua_task_get_resolver (lua_State *L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); struct rspamd_dns_resolver **presolver; if (task != NULL && task->resolver != NULL) { @@ -709,7 +709,7 @@ lua_task_get_resolver (lua_State *L) static gint lua_task_inc_dns_req (lua_State *L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); if (task != NULL) { task->dns_requests ++; @@ -721,7 +721,7 @@ lua_task_inc_dns_req (lua_State *L) static gint lua_task_call_rspamd_function (lua_State * L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); struct expression_function f; gint i, top; gboolean res; @@ -823,7 +823,7 @@ lua_push_internet_address_list (lua_State *L, InternetAddressList *addrs) static gint lua_task_get_recipients (lua_State *L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); GList *cur; InternetAddressList *addrs; gint idx = 1; @@ -864,7 +864,7 @@ lua_task_get_recipients (lua_State *L) static gint lua_task_get_from (lua_State *L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); InternetAddressList *addrs; if (task) { @@ -897,7 +897,7 @@ lua_task_get_from (lua_State *L) static gint lua_task_set_from (lua_State *L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); const gchar *new_from; if (task) { @@ -913,7 +913,7 @@ lua_task_set_from (lua_State *L) static gint lua_task_get_user (lua_State *L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); if (task && task->user != NULL) { lua_pushstring (L, task->user); @@ -927,7 +927,7 @@ lua_task_get_user (lua_State *L) static gint lua_task_set_user (lua_State *L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); const gchar *new_user; if (task) { @@ -946,7 +946,7 @@ lua_task_set_user (lua_State *L) static gint lua_task_get_recipients_headers (lua_State *L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); if (task && task->rcpts) { lua_push_internet_address_list (L, task->rcpts); @@ -960,7 +960,7 @@ lua_task_get_recipients_headers (lua_State *L) static gint lua_task_get_from_headers (lua_State *L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); InternetAddressList *addrs; if (task && task->message != NULL) { @@ -990,7 +990,7 @@ lua_task_get_from_headers (lua_State *L) static gint lua_task_get_from_ip (lua_State *L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); if (task) { lua_ip_push (L, task->from_addr.ipv6 ? AF_INET6 : AF_INET, &task->from_addr.d); @@ -1020,7 +1020,7 @@ lua_task_get_from_ip_num (lua_State *L) static gint lua_task_get_client_ip_num (lua_State *L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); if (task) { lua_ip_push (L, AF_INET, &task->client_addr); @@ -1035,7 +1035,7 @@ lua_task_get_client_ip_num (lua_State *L) static gint lua_task_get_helo (lua_State *L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); if (task) { if (task->helo != NULL) { @@ -1051,7 +1051,7 @@ lua_task_get_helo (lua_State *L) static gint lua_task_set_helo (lua_State *L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); const gchar *new_helo; if (task) { @@ -1067,7 +1067,7 @@ lua_task_set_helo (lua_State *L) static gint lua_task_get_hostname (lua_State *L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); if (task) { if (task->hostname != NULL) { @@ -1097,7 +1097,7 @@ lua_task_get_hostname (lua_State *L) static gint lua_task_set_hostname (lua_State *L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); const gchar *new_hostname; if (task) { @@ -1113,7 +1113,7 @@ lua_task_set_hostname (lua_State *L) static gint lua_task_get_images (lua_State *L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); gint i = 1; GList *cur; struct rspamd_image **pimg; @@ -1138,7 +1138,7 @@ lua_task_get_images (lua_State *L) } static inline gboolean -lua_push_symbol_result (lua_State *L, struct worker_task *task, struct metric *metric, const gchar *symbol) +lua_push_symbol_result (lua_State *L, struct rspamd_task *task, struct metric *metric, const gchar *symbol) { struct metric_result *metric_res; struct symbol *s; @@ -1178,7 +1178,7 @@ lua_push_symbol_result (lua_State *L, struct worker_task *task, struct metric *m static gint lua_task_get_symbol (lua_State *L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); const gchar *symbol; struct metric *metric; GList *cur = NULL, *metric_list; @@ -1224,7 +1224,7 @@ lua_task_get_symbol (lua_State *L) static gint lua_task_get_date (lua_State *L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); time_t task_time; if (task != NULL) { @@ -1242,7 +1242,7 @@ lua_task_get_date (lua_State *L) static gint lua_task_get_message_id (lua_State *L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); if (task != NULL && task->message_id != NULL) { lua_pushstring (L, task->message_id); @@ -1257,7 +1257,7 @@ lua_task_get_message_id (lua_State *L) static gint lua_task_get_timeval (lua_State *L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); if (task != NULL) { lua_newtable (L); @@ -1279,7 +1279,7 @@ lua_task_get_timeval (lua_State *L) static gint lua_task_learn_statfile (lua_State *L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); const gchar *symbol; struct classifier_config *cl; GTree *tokens; @@ -1322,7 +1322,7 @@ lua_task_learn_statfile (lua_State *L) static gint lua_task_get_metric_score (lua_State *L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); const gchar *metric_name; struct metric_result *metric_res; @@ -1350,7 +1350,7 @@ lua_task_get_metric_score (lua_State *L) static gint lua_task_get_metric_action (lua_State *L) { - struct worker_task *task = lua_check_task (L); + struct rspamd_task *task = lua_check_task (L); const gchar *metric_name; struct metric_result *metric_res; enum rspamd_metric_action action; diff --git a/src/main.h b/src/main.h index ec132fa9d..44b212664 100644 --- a/src/main.h +++ b/src/main.h @@ -21,6 +21,7 @@ #include "logger.h" #include "roll_history.h" #include "http.h" +#include "task.h" /* Default values */ #define FIXED_CONFIG_FILE RSPAMD_CONFDIR "/rspamd.conf" @@ -71,7 +72,7 @@ struct classifier_config; struct mime_part; struct rspamd_view; struct rspamd_dns_resolver; -struct worker_task; +struct rspamd_task; /** * Server statistics @@ -165,112 +166,16 @@ struct controller_session { void *other_data; /**< and its data */ controller_func_t custom_handler; /**< custom command handler */ struct rspamd_async_session* s; /**< async session object */ - struct worker_task *learn_task; + struct rspamd_task *learn_task; struct rspamd_dns_resolver *resolver; /**< DNS resolver */ struct event_base *ev_base; /**< Event base */ }; /** - * Worker task structure - */ -struct worker_task { - struct rspamd_worker *worker; /**< pointer to worker object */ - enum { - READ_MESSAGE, - WAIT_PRE_FILTER, - WAIT_FILTER, - WAIT_POST_FILTER, - WRITE_REPLY, - CLOSING_CONNECTION - } state; /**< current session state */ - enum rspamd_command cmd; /**< command */ - struct custom_command *custom_cmd; /**< custom command if any */ - gint sock; /**< socket descriptor */ - gboolean is_mime; /**< if this task is mime task */ - gboolean is_json; /**< output is JSON */ - gboolean allow_learn; /**< allow learning */ - gboolean is_skipped; /**< whether message was skipped by configuration */ - - gchar *helo; /**< helo header value */ - gchar *from; /**< from header value */ - gchar *queue_id; /**< queue id if specified */ - const gchar *message_id; /**< message id */ - GList *rcpt; /**< recipients list */ - guint nrcpt; /**< number of recipients */ -#ifdef HAVE_INET_PTON - struct { - union { - struct in_addr in4; - struct in6_addr in6; - } d; - gboolean ipv6; - gboolean has_addr; - } from_addr; -#else - struct in_addr from_addr; /**< client addr in numeric form */ -#endif - struct in_addr client_addr; /**< client addr in numeric form */ - gchar *deliver_to; /**< address to deliver */ - gchar *user; /**< user to deliver */ - gchar *subject; /**< subject (for non-mime) */ - gchar *hostname; /**< hostname reported by MTA */ - GString *msg; /**< message buffer */ - rspamd_io_dispatcher_t *dispatcher; /**< IO dispatcher object */ - struct rspamd_http_connection *http_conn; /**< HTTP server connection */ - struct rspamd_async_session* s; /**< async session object */ - gint parts_count; /**< mime parts count */ - GMimeMessage *message; /**< message, parsed with GMime */ - GMimeObject *parser_parent_part; /**< current parent part */ - InternetAddressList *rcpts; /**< list of all recipients */ - GList *parts; /**< list of parsed parts */ - GList *text_parts; /**< list of text parts */ - gchar *raw_headers_str; /**< list of raw headers */ - GList *received; /**< list of received headers */ - GTree *urls; /**< list of parsed urls */ - GTree *emails; /**< list of parsed emails */ - GList *images; /**< list of images */ - GHashTable *raw_headers; /**< list of raw headers */ - GHashTable *results; /**< hash table of metric_result indexed by - * metric's name */ - GHashTable *tokens; /**< hash table of tokens indexed by tokenizer - * pointer */ - GList *messages; /**< list of messages that would be reported */ - GHashTable *re_cache; /**< cache for matched or not matched regexps */ - struct config_file *cfg; /**< pointer to config object */ - gchar *last_error; /**< last error */ - gint error_code; /**< code of last error */ - rspamd_mempool_t *task_pool; /**< memory pool for task */ -#ifdef HAVE_CLOCK_GETTIME - struct timespec ts; /**< time of connection */ -#endif - struct timeval tv; /**< time of connection */ - struct rspamd_view *view; /**< matching view */ - guint32 scan_milliseconds; /**< how much milliseconds passed */ - gboolean view_checked; - gboolean pass_all_filters; /**< pass task throught every rule */ - gboolean no_log; /**< do not log or write this task to the history */ - guint32 parser_recursion; /**< for avoiding recursion stack overflow */ - gboolean (*fin_callback)(void *arg); /**< calback for filters finalizing */ - void *fin_arg; /**< argument for fin callback */ - - guint32 dns_requests; /**< number of DNS requests per this task */ - - struct rspamd_dns_resolver *resolver; /**< DNS resolver */ - struct event_base *ev_base; /**< Event base */ - - GThreadPool *classify_pool; /**< A pool of classify threads */ - - struct { - enum rspamd_metric_action action; /**< Action of pre filters */ - gchar *str; /**< String describing action */ - } pre_result; /**< Result of pre-filters */ -}; - -/** * Common structure representing C module context */ struct module_ctx { - gint (*filter)(struct worker_task *task); /**< pointer to headers process function */ + gint (*filter)(struct rspamd_task *task); /**< pointer to headers process function */ }; /** @@ -296,11 +201,11 @@ extern struct rspamd_main *rspamd_main; /** * Construct new task for worker */ -struct worker_task* construct_task (struct rspamd_worker *worker); +struct rspamd_task* construct_task (struct rspamd_worker *worker); /** * Destroy task object and remove its IO dispatcher if it exists */ -void free_task (struct worker_task *task, gboolean is_soft); +void free_task (struct rspamd_task *task, gboolean is_soft); void free_task_hard (gpointer ud); void free_task_soft (gpointer ud); diff --git a/src/message.c b/src/message.c index b8d9d9d13..4567869e9 100644 --- a/src/message.c +++ b/src/message.c @@ -34,7 +34,7 @@ #define UTF8_CHARSET "UTF-8" GByteArray * -strip_html_tags (struct worker_task *task, rspamd_mempool_t * pool, struct mime_text_part *part, GByteArray * src, gint *stateptr) +strip_html_tags (struct rspamd_task *task, rspamd_mempool_t * pool, struct mime_text_part *part, GByteArray * src, gint *stateptr) { uint8_t *p, *rp, *tbegin = NULL, *end, c, lc; gint br, i = 0, depth = 0, in_q = 0; @@ -550,7 +550,7 @@ parse_recv_header (rspamd_mempool_t * pool, gchar *line, struct received_header /* Convert raw headers to a list of struct raw_header * */ static void -process_raw_headers (struct worker_task *task) +process_raw_headers (struct rspamd_task *task) { struct raw_header *new = NULL, *lp; gchar *p, *c, *tmp, *tp; @@ -774,7 +774,7 @@ free_byte_array_callback (void *pointer) } static GByteArray * -convert_text_to_utf (struct worker_task *task, GByteArray * part_content, GMimeContentType * type, struct mime_text_part *text_part) +convert_text_to_utf (struct rspamd_task *task, GByteArray * part_content, GMimeContentType * type, struct mime_text_part *text_part) { GError *err = NULL; gsize read_bytes, write_bytes; @@ -823,7 +823,7 @@ convert_text_to_utf (struct worker_task *task, GByteArray * part_content, GMimeC } static void -process_text_part (struct worker_task *task, GByteArray *part_content, GMimeContentType *type, +process_text_part (struct rspamd_task *task, GByteArray *part_content, GMimeContentType *type, GMimeObject *part, GMimeObject *parent, gboolean is_empty) { struct mime_text_part *text_part; @@ -907,7 +907,7 @@ static void mime_foreach_callback (GMimeObject * part, gpointer user_data) #endif { - struct worker_task *task = (struct worker_task *)user_data; + struct rspamd_task *task = (struct rspamd_task *)user_data; struct mime_part *mime_part; GMimeContentType *type; GMimeDataWrapper *wrapper; @@ -1032,7 +1032,7 @@ destroy_message (void *pointer) } gint -process_message (struct worker_task *task) +process_message (struct rspamd_task *task) { GMimeMessage *message; GMimeParser *parser; @@ -1731,7 +1731,7 @@ message_get_header (rspamd_mempool_t * pool, GMimeMessage * message, const gchar } GList* -message_get_raw_header (struct worker_task *task, const gchar *field, gboolean strong) +message_get_raw_header (struct rspamd_task *task, const gchar *field, gboolean strong) { GList *gret = NULL; struct raw_header *rh; diff --git a/src/message.h b/src/message.h index f77c90825..5e27579d1 100644 --- a/src/message.h +++ b/src/message.h @@ -9,7 +9,7 @@ #include "config.h" #include "fuzzy.h" -struct worker_task; +struct rspamd_task; struct controller_session; struct mime_part { @@ -62,7 +62,7 @@ struct raw_header { * @param task worker_task object * @return 0 if we have delayed filters to process and 1 if we have finished with processing */ -gint process_message (struct worker_task *task); +gint process_message (struct rspamd_task *task); /* * Set header with specified name and value @@ -86,6 +86,6 @@ GList* message_get_header (rspamd_mempool_t *pool, GMimeMessage *message, const * @param strong if this flag is TRUE header's name is case sensitive, otherwise it is not * @return A list of header's values or NULL. Unlike previous function it is NOT required to free list or values. I should rework one of these functions some time. */ -GList* message_get_raw_header (struct worker_task *task, const gchar *field, gboolean strong); +GList* message_get_raw_header (struct rspamd_task *task, const gchar *field, gboolean strong); #endif diff --git a/src/plugins/chartable.c b/src/plugins/chartable.c index fc9ff3f49..937cf1dc0 100644 --- a/src/plugins/chartable.c +++ b/src/plugins/chartable.c @@ -54,7 +54,7 @@ module_t chartable_module = { }; struct chartable_ctx { - gint (*filter) (struct worker_task * task); + gint (*filter) (struct rspamd_task * task); const gchar *symbol; double threshold; @@ -63,8 +63,8 @@ struct chartable_ctx { static struct chartable_ctx *chartable_module_ctx = NULL; -static gint chartable_mime_filter (struct worker_task *task); -static void chartable_symbol_callback (struct worker_task *task, void *unused); +static gint chartable_mime_filter (struct rspamd_task *task); +static void chartable_symbol_callback (struct rspamd_task *task, void *unused); gint chartable_module_init (struct config_file *cfg, struct module_ctx **ctx) @@ -197,7 +197,7 @@ check_part (struct mime_text_part *part, gboolean raw_mode) } static void -chartable_symbol_callback (struct worker_task *task, void *unused) +chartable_symbol_callback (struct rspamd_task *task, void *unused) { GList *cur; struct mime_text_part *part; @@ -216,7 +216,7 @@ chartable_symbol_callback (struct worker_task *task, void *unused) } static gint -chartable_mime_filter (struct worker_task *task) +chartable_mime_filter (struct rspamd_task *task) { /* XXX: remove it */ return 0; diff --git a/src/plugins/dkim_check.c b/src/plugins/dkim_check.c index eb6cefb7d..9610db6a8 100644 --- a/src/plugins/dkim_check.c +++ b/src/plugins/dkim_check.c @@ -56,7 +56,7 @@ #define DEFAULT_TIME_JITTER 60 struct dkim_ctx { - gint (*filter) (struct worker_task * task); + gint (*filter) (struct rspamd_task * task); const gchar *symbol_reject; const gchar *symbol_tempfail; const gchar *symbol_allow; @@ -73,7 +73,7 @@ struct dkim_ctx { static struct dkim_ctx *dkim_module_ctx = NULL; -static void dkim_symbol_callback (struct worker_task *task, void *unused); +static void dkim_symbol_callback (struct rspamd_task *task, void *unused); /* Initialization */ gint dkim_module_init (struct config_file *cfg, struct module_ctx **ctx); @@ -238,7 +238,7 @@ dkim_module_parse_strict (const gchar *value, gint *allow, gint *deny) } static void -dkim_module_check (struct worker_task *task, rspamd_dkim_context_t *ctx, rspamd_dkim_key_t *key) +dkim_module_check (struct rspamd_task *task, rspamd_dkim_context_t *ctx, rspamd_dkim_key_t *key) { gint res, score_allow = 1, score_deny = 1; const gchar *strict_value; @@ -275,7 +275,7 @@ dkim_module_check (struct worker_task *task, rspamd_dkim_context_t *ctx, rspamd_ static void dkim_module_key_handler (rspamd_dkim_key_t *key, gsize keylen, rspamd_dkim_context_t *ctx, gpointer ud, GError *err) { - struct worker_task *task = ud; + struct rspamd_task *task = ud; if (key != NULL) { @@ -303,7 +303,7 @@ dkim_module_key_handler (rspamd_dkim_key_t *key, gsize keylen, rspamd_dkim_conte } static void -dkim_symbol_callback (struct worker_task *task, void *unused) +dkim_symbol_callback (struct rspamd_task *task, void *unused) { GList *hlist; rspamd_dkim_context_t *ctx; diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index 663613e4c..595cfc99b 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -88,7 +88,7 @@ struct fuzzy_rule { }; struct fuzzy_ctx { - gint (*filter) (struct worker_task * task); + gint (*filter) (struct rspamd_task * task); rspamd_mempool_t *fuzzy_pool; GList *fuzzy_rules; const gchar *default_symbol; @@ -105,7 +105,7 @@ struct fuzzy_client_session { fuzzy_hash_t *h; struct event ev; struct timeval tv; - struct worker_task *task; + struct rspamd_task *task; struct storage_server *server; struct fuzzy_rule *rule; gint fd; @@ -123,14 +123,14 @@ struct fuzzy_learn_session { struct controller_session *session; struct storage_server *server; struct fuzzy_rule *rule; - struct worker_task *task; + struct rspamd_task *task; gint fd; }; static struct fuzzy_ctx *fuzzy_module_ctx = NULL; static const gchar hex_digits[] = "0123456789abcdef"; -static void fuzzy_symbol_callback (struct worker_task *task, void *unused); +static void fuzzy_symbol_callback (struct rspamd_task *task, void *unused); static gboolean fuzzy_add_handler (gchar **args, struct controller_session *session); static gboolean fuzzy_delete_handler (gchar **args, struct controller_session *session); @@ -691,7 +691,7 @@ ok: } static inline void -register_fuzzy_call (struct worker_task *task, struct fuzzy_rule *rule, fuzzy_hash_t *h) +register_fuzzy_call (struct rspamd_task *task, struct fuzzy_rule *rule, fuzzy_hash_t *h) { struct fuzzy_client_session *session; struct storage_server *selected; @@ -730,7 +730,7 @@ register_fuzzy_call (struct worker_task *task, struct fuzzy_rule *rule, fuzzy_ha } static void -fuzzy_check_rule (struct worker_task *task, struct fuzzy_rule *rule) +fuzzy_check_rule (struct rspamd_task *task, struct fuzzy_rule *rule) { struct mime_text_part *part; struct mime_part *mime_part; @@ -816,7 +816,7 @@ fuzzy_check_rule (struct worker_task *task, struct fuzzy_rule *rule) /* This callback is called when we check message via fuzzy hashes storage */ static void -fuzzy_symbol_callback (struct worker_task *task, void *unused) +fuzzy_symbol_callback (struct rspamd_task *task, void *unused) { struct fuzzy_rule *rule; GList *cur; @@ -850,7 +850,7 @@ fuzzy_symbol_callback (struct worker_task *task, void *unused) static inline gboolean register_fuzzy_controller_call (struct controller_session *session, - struct fuzzy_rule *rule, struct worker_task *task, fuzzy_hash_t *h, + struct fuzzy_rule *rule, struct rspamd_task *task, fuzzy_hash_t *h, gint cmd, gint value, gint flag, gint *saved, GError **err) { struct fuzzy_learn_session *s; @@ -903,7 +903,7 @@ register_fuzzy_controller_call (struct controller_session *session, static int fuzzy_process_rule (struct controller_session *session, struct fuzzy_rule *rule, - struct worker_task *task, GError **err, gint cmd, gint flag, gint value, gint *saved) + struct rspamd_task *task, GError **err, gint cmd, gint flag, gint value, gint *saved) { struct mime_text_part *part; struct mime_part *mime_part; @@ -1002,7 +1002,7 @@ fuzzy_process_handler (struct controller_session *session, f_str_t * in) struct fuzzy_rule *rule; gboolean processed = FALSE, res = TRUE; GList *cur; - struct worker_task *task; + struct rspamd_task *task; GError **err; gint r, cmd = 0, value = 0, flag = 0, *saved, *sargs; gchar out_buf[BUFSIZ]; diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c index 2a7978c73..0229236f6 100644 --- a/src/plugins/regexp.c +++ b/src/plugins/regexp.c @@ -54,7 +54,7 @@ struct autolearn_data { }; struct regexp_ctx { - gint (*filter) (struct worker_task * task); + gint (*filter) (struct rspamd_task * task); GHashTable *autolearn_symbols; gchar *statfile_prefix; @@ -84,19 +84,19 @@ static const struct luaL_reg regexplib_m[] = { static struct regexp_ctx *regexp_module_ctx = NULL; static GMutex *workers_mtx = NULL; -static gint regexp_common_filter (struct worker_task *task); +static gint regexp_common_filter (struct rspamd_task *task); static void process_regexp_item_threaded (gpointer data, gpointer user_data); -static gboolean rspamd_regexp_match_number (struct worker_task *task, GList * args, void *unused); -static gboolean rspamd_raw_header_exists (struct worker_task *task, GList * args, void *unused); -static gboolean rspamd_check_smtp_data (struct worker_task *task, GList * args, void *unused); -static gboolean rspamd_regexp_occurs_number (struct worker_task *task, GList * args, void *unused); -static gboolean rspamd_content_type_is_type (struct worker_task * task, GList * args, void *unused); -static gboolean rspamd_content_type_is_subtype (struct worker_task *task, GList * args, void *unused); -static gboolean rspamd_content_type_has_param (struct worker_task * task, GList * args, void *unused); -static gboolean rspamd_content_type_compare_param (struct worker_task * task, GList * args, void *unused); -static gboolean rspamd_has_content_part (struct worker_task *task, GList * args, void *unused); -static gboolean rspamd_has_content_part_len (struct worker_task *task, GList * args, void *unused); -static void process_regexp_item (struct worker_task *task, void *user_data); +static gboolean rspamd_regexp_match_number (struct rspamd_task *task, GList * args, void *unused); +static gboolean rspamd_raw_header_exists (struct rspamd_task *task, GList * args, void *unused); +static gboolean rspamd_check_smtp_data (struct rspamd_task *task, GList * args, void *unused); +static gboolean rspamd_regexp_occurs_number (struct rspamd_task *task, GList * args, void *unused); +static gboolean rspamd_content_type_is_type (struct rspamd_task * task, GList * args, void *unused); +static gboolean rspamd_content_type_is_subtype (struct rspamd_task *task, GList * args, void *unused); +static gboolean rspamd_content_type_has_param (struct rspamd_task * task, GList * args, void *unused); +static gboolean rspamd_content_type_compare_param (struct rspamd_task * task, GList * args, void *unused); +static gboolean rspamd_has_content_part (struct rspamd_task *task, GList * args, void *unused); +static gboolean rspamd_has_content_part_len (struct rspamd_task *task, GList * args, void *unused); +static void process_regexp_item (struct rspamd_task *task, void *user_data); /* Initialization */ @@ -119,7 +119,7 @@ G_LOCK_DEFINE (task_cache_mtx); #endif void -task_cache_add (struct worker_task *task, struct rspamd_regexp *re, gint32 result) +task_cache_add (struct rspamd_task *task, struct rspamd_regexp *re, gint32 result) { if (result == 0) { result = -1; @@ -139,7 +139,7 @@ task_cache_add (struct worker_task *task, struct rspamd_regexp *re, gint32 resul } gint32 -task_cache_check (struct worker_task *task, struct rspamd_regexp *re) +task_cache_check (struct rspamd_task *task, struct rspamd_regexp *re) { gpointer res; gint32 r; @@ -179,7 +179,7 @@ luaopen_regexp (lua_State * L) } static void -regexp_dynamic_insert_result (struct worker_task *task, void *user_data) +regexp_dynamic_insert_result (struct rspamd_task *task, void *user_data) { gchar *symbol = user_data; @@ -639,7 +639,7 @@ regexp_module_reconfig (struct config_file *cfg) } struct url_regexp_param { - struct worker_task *task; + struct rspamd_task *task; GRegex *regexp; struct rspamd_regexp *re; gboolean found; @@ -671,7 +671,7 @@ tree_url_callback (gpointer key, gpointer value, void *data) } static gsize -process_regexp (struct rspamd_regexp *re, struct worker_task *task, const gchar *additional, +process_regexp (struct rspamd_regexp *re, struct rspamd_task *task, const gchar *additional, gint limit, int_compare_func f) { guint8 *ct; @@ -1025,14 +1025,14 @@ process_regexp (struct rspamd_regexp *re, struct worker_task *task, const gchar } static gboolean -maybe_call_lua_function (const gchar *name, struct worker_task *task, lua_State *L) +maybe_call_lua_function (const gchar *name, struct rspamd_task *task, lua_State *L) { - struct worker_task **ptask; + struct rspamd_task **ptask; gboolean res; lua_getglobal (L, name); if (lua_isfunction (L, -1)) { - ptask = lua_newuserdata (L, sizeof (struct worker_task *)); + ptask = lua_newuserdata (L, sizeof (struct rspamd_task *)); lua_setclass (L, "rspamd{task}", -1); *ptask = task; /* Call function */ @@ -1107,7 +1107,7 @@ optimize_regexp_expression (struct expression **e, GQueue * stack, gboolean res) } static gboolean -process_regexp_expression (struct expression *expr, const gchar *symbol, struct worker_task *task, +process_regexp_expression (struct expression *expr, const gchar *symbol, struct rspamd_task *task, const gchar *additional, struct lua_locked_state *nL) { GQueue *stack; @@ -1233,7 +1233,7 @@ process_regexp_expression (struct expression *expr, const gchar *symbol, struct struct regexp_threaded_ud { struct regexp_module_item *item; - struct worker_task *task; + struct rspamd_task *task; }; static void @@ -1252,7 +1252,7 @@ process_regexp_item_threaded (gpointer data, gpointer user_data) } static void -process_regexp_item (struct worker_task *task, void *user_data) +process_regexp_item (struct rspamd_task *task, void *user_data) { struct regexp_module_item *item = user_data; gboolean res = FALSE; @@ -1316,7 +1316,7 @@ process_regexp_item (struct worker_task *task, void *user_data) } static gboolean -rspamd_regexp_match_number (struct worker_task *task, GList * args, void *unused) +rspamd_regexp_match_number (struct rspamd_task *task, GList * args, void *unused) { gint param_count, res = 0; struct expression_argument *arg; @@ -1353,7 +1353,7 @@ rspamd_regexp_match_number (struct worker_task *task, GList * args, void *unused } static gboolean -rspamd_regexp_occurs_number (struct worker_task *task, GList * args, void *unused) +rspamd_regexp_occurs_number (struct rspamd_task *task, GList * args, void *unused) { gint limit; struct expression_argument *arg; @@ -1420,7 +1420,7 @@ rspamd_regexp_occurs_number (struct worker_task *task, GList * args, void *unuse return process_regexp (re, task, NULL, limit, f); } static gboolean -rspamd_raw_header_exists (struct worker_task *task, GList * args, void *unused) +rspamd_raw_header_exists (struct rspamd_task *task, GList * args, void *unused) { struct expression_argument *arg; @@ -1438,7 +1438,7 @@ rspamd_raw_header_exists (struct worker_task *task, GList * args, void *unused) } static gboolean -match_smtp_data (struct worker_task *task, const gchar *re_text, const gchar *what) +match_smtp_data (struct rspamd_task *task, const gchar *re_text, const gchar *what) { struct rspamd_regexp *re; gint r; @@ -1472,7 +1472,7 @@ match_smtp_data (struct worker_task *task, const gchar *re_text, const gchar *wh } static gboolean -rspamd_check_smtp_data (struct worker_task *task, GList * args, void *unused) +rspamd_check_smtp_data (struct rspamd_task *task, GList * args, void *unused) { struct expression_argument *arg; GList *cur, *rcpt_list = NULL; @@ -1595,13 +1595,13 @@ static gint lua_regexp_match (lua_State *L) { void *ud = luaL_checkudata (L, 1, "rspamd{task}"); - struct worker_task *task; + struct rspamd_task *task; const gchar *re_text; struct rspamd_regexp *re; gint r = 0; luaL_argcheck (L, ud != NULL, 1, "'task' expected"); - task = ud ? *((struct worker_task **)ud) : NULL; + task = ud ? *((struct rspamd_task **)ud) : NULL; re_text = luaL_checkstring (L, 2); /* This is a regexp */ @@ -1622,7 +1622,7 @@ lua_regexp_match (lua_State *L) } static gboolean -rspamd_content_type_compare_param (struct worker_task * task, GList * args, void *unused) +rspamd_content_type_compare_param (struct rspamd_task * task, GList * args, void *unused) { gchar *param_name, *param_pattern; const gchar *param_data; @@ -1733,7 +1733,7 @@ rspamd_content_type_compare_param (struct worker_task * task, GList * args, void } static gboolean -rspamd_content_type_has_param (struct worker_task * task, GList * args, void *unused) +rspamd_content_type_has_param (struct rspamd_task * task, GList * args, void *unused) { gchar *param_name; const gchar *param_data; @@ -1805,7 +1805,7 @@ rspamd_content_type_has_param (struct worker_task * task, GList * args, void *un } static gboolean -rspamd_content_type_is_subtype (struct worker_task *task, GList * args, void *unused) +rspamd_content_type_is_subtype (struct rspamd_task *task, GList * args, void *unused) { gchar *param_pattern; struct rspamd_regexp *re; @@ -1902,7 +1902,7 @@ rspamd_content_type_is_subtype (struct worker_task *task, GList * args, void *un } static gboolean -rspamd_content_type_is_type (struct worker_task * task, GList * args, void *unused) +rspamd_content_type_is_type (struct rspamd_task * task, GList * args, void *unused) { gchar *param_pattern; struct rspamd_regexp *re; @@ -2000,7 +2000,7 @@ rspamd_content_type_is_type (struct worker_task * task, GList * args, void *unus } static gboolean -compare_subtype (struct worker_task *task, GMimeContentType * ct, gchar *subtype) +compare_subtype (struct rspamd_task *task, GMimeContentType * ct, gchar *subtype) { struct rspamd_regexp *re; gint r; @@ -2059,7 +2059,7 @@ compare_len (struct mime_part *part, guint min, guint max) } static gboolean -common_has_content_part (struct worker_task * task, gchar *param_type, gchar *param_subtype, gint min_len, gint max_len) +common_has_content_part (struct rspamd_task * task, gchar *param_type, gchar *param_subtype, gint min_len, gint max_len) { struct rspamd_regexp *re; struct mime_part *part; @@ -2141,7 +2141,7 @@ common_has_content_part (struct worker_task * task, gchar *param_type, gchar *pa } static gboolean -rspamd_has_content_part (struct worker_task * task, GList * args, void *unused) +rspamd_has_content_part (struct rspamd_task * task, GList * args, void *unused) { gchar *param_type = NULL, *param_subtype = NULL; struct expression_argument *arg; @@ -2163,7 +2163,7 @@ rspamd_has_content_part (struct worker_task * task, GList * args, void *unused) } static gboolean -rspamd_has_content_part_len (struct worker_task * task, GList * args, void *unused) +rspamd_has_content_part_len (struct rspamd_task * task, GList * args, void *unused) { gchar *param_type = NULL, *param_subtype = NULL; gint min = 0, max = 0; diff --git a/src/plugins/spf.c b/src/plugins/spf.c index 239e58d3b..149e3104d 100644 --- a/src/plugins/spf.c +++ b/src/plugins/spf.c @@ -50,7 +50,7 @@ #define DEFAULT_CACHE_MAXAGE 86400 struct spf_ctx { - gint (*filter) (struct worker_task * task); + gint (*filter) (struct rspamd_task * task); const gchar *symbol_fail; const gchar *symbol_softfail; const gchar *symbol_allow; @@ -62,7 +62,7 @@ struct spf_ctx { static struct spf_ctx *spf_module_ctx = NULL; -static void spf_symbol_callback (struct worker_task *task, void *unused); +static void spf_symbol_callback (struct rspamd_task *task, void *unused); static GList * spf_record_copy (GList *addrs); static void spf_record_destroy (gpointer list); @@ -159,7 +159,7 @@ spf_module_reconfig (struct config_file *cfg) } static gboolean -spf_check_element (struct spf_addr *addr, struct worker_task *task) +spf_check_element (struct spf_addr *addr, struct rspamd_task *task) { gboolean res = FALSE; #ifdef HAVE_INET_PTON @@ -252,7 +252,7 @@ spf_check_element (struct spf_addr *addr, struct worker_task *task) } static gboolean -spf_check_list (GList *list, struct worker_task *task) +spf_check_list (GList *list, struct rspamd_task *task) { GList *cur; struct spf_addr *addr; @@ -279,7 +279,7 @@ spf_check_list (GList *list, struct worker_task *task) } static void -spf_plugin_callback (struct spf_record *record, struct worker_task *task) +spf_plugin_callback (struct spf_record *record, struct rspamd_task *task) { GList *l; @@ -296,7 +296,7 @@ spf_plugin_callback (struct spf_record *record, struct worker_task *task) static void -spf_symbol_callback (struct worker_task *task, void *unused) +spf_symbol_callback (struct rspamd_task *task, void *unused) { gchar *domain; GList *l; diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c index 58f9acb58..3358b65d0 100644 --- a/src/plugins/surbl.c +++ b/src/plugins/surbl.c @@ -56,9 +56,9 @@ static struct surbl_ctx *surbl_module_ctx = NULL; -static void surbl_test_url (struct worker_task *task, void *user_data); +static void surbl_test_url (struct rspamd_task *task, void *user_data); static void dns_callback (struct rdns_reply *reply, gpointer arg); -static void process_dns_results (struct worker_task *task, +static void process_dns_results (struct rspamd_task *task, struct suffix_item *suffix, gchar *url, guint32 addr); @@ -623,7 +623,7 @@ format_surbl_request (rspamd_mempool_t * pool, f_str_t * hostname, struct suffix } static void -make_surbl_requests (struct uri *url, struct worker_task *task, +make_surbl_requests (struct uri *url, struct rspamd_task *task, struct suffix_item *suffix, gboolean forced, GTree *tree) { gchar *surbl_req; @@ -663,7 +663,7 @@ make_surbl_requests (struct uri *url, struct worker_task *task, } static void -process_dns_results (struct worker_task *task, struct suffix_item *suffix, gchar *url, guint32 addr) +process_dns_results (struct rspamd_task *task, struct suffix_item *suffix, gchar *url, guint32 addr) { GList *cur; struct surbl_bit_item *bit; @@ -691,7 +691,7 @@ static void dns_callback (struct rdns_reply *reply, gpointer arg) { struct dns_param *param = (struct dns_param *)arg; - struct worker_task *task = param->task; + struct rspamd_task *task = param->task; struct rdns_reply_entry *elt; debug_task ("in surbl request callback"); @@ -759,7 +759,7 @@ memcached_callback (memcached_ctx_t * ctx, memc_error_t error, void *data) } static void -register_memcached_call (struct uri *url, struct worker_task *task, +register_memcached_call (struct uri *url, struct rspamd_task *task, struct suffix_item *suffix, GTree *tree) { struct memcached_param *param; @@ -825,7 +825,7 @@ static void redirector_callback (gint fd, short what, void *arg) { struct redirector_param *param = (struct redirector_param *)arg; - struct worker_task *task = param->task; + struct rspamd_task *task = param->task; gchar url_buf[512]; gint r; struct timeval *timeout; @@ -906,7 +906,7 @@ redirector_callback (gint fd, short what, void *arg) static void -register_redirector_call (struct uri *url, struct worker_task *task, +register_redirector_call (struct uri *url, struct rspamd_task *task, struct suffix_item *suffix, const gchar *rule, GTree *tree) { gint s = -1; @@ -954,7 +954,7 @@ static gboolean surbl_tree_url_callback (gpointer key, gpointer value, void *data) { struct redirector_param *param = data; - struct worker_task *task; + struct rspamd_task *task; struct uri *url = value; gchar *red_domain; const gchar *pos; @@ -1008,7 +1008,7 @@ surbl_tree_url_callback (gpointer key, gpointer value, void *data) } static void -surbl_test_url (struct worker_task *task, void *user_data) +surbl_test_url (struct rspamd_task *task, void *user_data) { struct redirector_param param; struct suffix_item *suffix = user_data; @@ -1027,7 +1027,7 @@ struct urls_tree_cb_data { gchar *buf; gsize len; gsize off; - struct worker_task *task; + struct rspamd_task *task; }; static gboolean @@ -1069,7 +1069,7 @@ write_urls_buffer (gpointer key, gpointer value, gpointer cbdata) static gboolean -urls_command_handler (struct worker_task *task) +urls_command_handler (struct rspamd_task *task) { struct urls_tree_cb_data cb; diff --git a/src/plugins/surbl.h b/src/plugins/surbl.h index 80554b713..a9b0c194c 100644 --- a/src/plugins/surbl.h +++ b/src/plugins/surbl.h @@ -26,7 +26,7 @@ struct redirector_upstream { }; struct surbl_ctx { - gint (*filter)(struct worker_task *task); + gint (*filter)(struct rspamd_task *task); guint16 weight; guint connect_timeout; guint read_timeout; @@ -57,14 +57,14 @@ struct suffix_item { struct dns_param { struct uri *url; - struct worker_task *task; + struct rspamd_task *task; gchar *host_resolve; struct suffix_item *suffix; }; struct redirector_param { struct uri *url; - struct worker_task *task; + struct rspamd_task *task; struct redirector_upstream *redirector; enum { STATE_CONNECT, @@ -79,7 +79,7 @@ struct redirector_param { struct memcached_param { struct uri *url; - struct worker_task *task; + struct rspamd_task *task; memcached_ctx_t *ctx; GTree *tree; struct suffix_item *suffix; diff --git a/src/protocol.c b/src/protocol.c index db1fa0bfd..9da4f445d 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -127,7 +127,7 @@ rspamd_protocol_escape_braces (GString *in) } static gboolean -rspamd_protocol_handle_url (struct worker_task *task, struct rspamd_http_message *msg) +rspamd_protocol_handle_url (struct rspamd_task *task, struct rspamd_http_message *msg) { GList *cur; struct custom_command *cmd; @@ -224,7 +224,7 @@ err: } static gboolean -rspamd_protocol_handle_headers (struct worker_task *task, struct rspamd_http_message *msg) +rspamd_protocol_handle_headers (struct rspamd_task *task, struct rspamd_http_message *msg) { gchar *headern, *err, *tmp; gboolean res = TRUE; @@ -412,7 +412,7 @@ rspamd_protocol_handle_headers (struct worker_task *task, struct rspamd_http_mes } gboolean -rspamd_protocol_handle_request (struct worker_task *task, +rspamd_protocol_handle_request (struct rspamd_task *task, struct rspamd_http_message *msg) { gboolean ret = TRUE; @@ -438,7 +438,7 @@ rspamd_protocol_handle_request (struct worker_task *task, } static void -write_hashes_to_log (struct worker_task *task, GString *logbuf) +write_hashes_to_log (struct rspamd_task *task, GString *logbuf) { GList *cur; struct mime_text_part *text_part; @@ -463,7 +463,7 @@ write_hashes_to_log (struct worker_task *task, GString *logbuf) /* Structure for writing tree data */ struct tree_cb_data { ucl_object_t *top; - struct worker_task *task; + struct rspamd_task *task; }; /* @@ -489,7 +489,7 @@ urls_protocol_cb (gpointer key, gpointer value, gpointer ud) } static ucl_object_t * -rspamd_urls_tree_ucl (GTree *input, struct worker_task *task) +rspamd_urls_tree_ucl (GTree *input, struct rspamd_task *task) { struct tree_cb_data cb; ucl_object_t *obj; @@ -517,7 +517,7 @@ emails_protocol_cb (gpointer key, gpointer value, gpointer ud) } static ucl_object_t * -rspamd_emails_tree_ucl (GTree *input, struct worker_task *task) +rspamd_emails_tree_ucl (GTree *input, struct rspamd_task *task) { struct tree_cb_data cb; ucl_object_t *obj; @@ -534,7 +534,7 @@ rspamd_emails_tree_ucl (GTree *input, struct worker_task *task) /* Write new subject */ static const gchar * -make_rewritten_subject (struct metric *metric, struct worker_task *task) +make_rewritten_subject (struct metric *metric, struct rspamd_task *task) { static gchar subj_buf[1024]; gchar *p = subj_buf, *end, *c, *res; @@ -583,7 +583,7 @@ rspamd_str_list_ucl (GList *str_list) } static ucl_object_t * -rspamd_metric_symbol_ucl (struct worker_task *task, struct metric *m, +rspamd_metric_symbol_ucl (struct rspamd_task *task, struct metric *m, struct symbol *sym, GString *logbuf) { ucl_object_t *obj = NULL; @@ -606,7 +606,7 @@ rspamd_metric_symbol_ucl (struct worker_task *task, struct metric *m, } static ucl_object_t * -rspamd_metric_result_ucl (struct worker_task *task, struct metric_result *mres, GString *logbuf) +rspamd_metric_result_ucl (struct rspamd_task *task, struct metric_result *mres, GString *logbuf) { GHashTableIter hiter; struct symbol *sym; @@ -684,7 +684,7 @@ rspamd_metric_result_ucl (struct worker_task *task, struct metric_result *mres, } static void -rspamd_ucl_tolegacy_output (struct worker_task *task, ucl_object_t *top, GString *out) +rspamd_ucl_tolegacy_output (struct rspamd_task *task, ucl_object_t *top, GString *out) { const ucl_object_t *metric, *score, *required_score, *is_spam, *elt, *symbols; @@ -724,7 +724,7 @@ rspamd_ucl_tolegacy_output (struct worker_task *task, ucl_object_t *top, GString } static void -write_check_reply (struct rspamd_http_message *msg, struct worker_task *task) +write_check_reply (struct rspamd_http_message *msg, struct rspamd_task *task) { GString *logbuf; struct metric_result *metric_res; @@ -788,7 +788,7 @@ write_check_reply (struct rspamd_http_message *msg, struct worker_task *task) } void -rspamd_protocol_write_reply (struct worker_task *task) +rspamd_protocol_write_reply (struct rspamd_task *task) { struct rspamd_http_message *msg; const gchar *ctype = "application/json"; diff --git a/src/protocol.h b/src/protocol.h index 30d3c51db..912b8744c 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -17,43 +17,23 @@ #define RSPAMD_LENGTH_ERROR RSPAMD_BASE_ERROR + 4 #define RSPAMD_STATFILE_ERROR RSPAMD_BASE_ERROR + 5 -struct worker_task; +struct rspamd_task; struct metric; - -enum rspamd_command { - CMD_CHECK, - CMD_SYMBOLS, - CMD_REPORT, - CMD_REPORT_IFSPAM, - CMD_SKIP, - CMD_PING, - CMD_PROCESS, - CMD_OTHER -}; - - -typedef gint (*protocol_reply_func)(struct worker_task *task); - -struct custom_command { - const gchar *name; - protocol_reply_func func; -}; - /** * Process HTTP request to the task structure * @param task * @param msg * @return */ -gboolean rspamd_protocol_handle_request (struct worker_task *task, struct rspamd_http_message *msg); +gboolean rspamd_protocol_handle_request (struct rspamd_task *task, struct rspamd_http_message *msg); /** * Write reply for specified task command * @param task task object * @return 0 if we wrote reply and -1 if there was some error */ -void rspamd_protocol_write_reply (struct worker_task *task); +void rspamd_protocol_write_reply (struct rspamd_task *task); /** diff --git a/src/roll_history.c b/src/roll_history.c index 1ffa9240f..504f8ae3b 100644 --- a/src/roll_history.c +++ b/src/roll_history.c @@ -74,7 +74,7 @@ roll_history_symbols_callback (gpointer key, gpointer value, void *user_data) * @param task task object */ void -rspamd_roll_history_update (struct roll_history *history, struct worker_task *task) +rspamd_roll_history_update (struct roll_history *history, struct rspamd_task *task) { gint row_num; struct roll_history_row *row; diff --git a/src/roll_history.h b/src/roll_history.h index a09584337..1dff93a4f 100644 --- a/src/roll_history.h +++ b/src/roll_history.h @@ -38,7 +38,7 @@ #define HISTORY_MAX_USER 20 #define HISTORY_MAX_ROWS 200 -struct worker_task; +struct rspamd_task; struct roll_history_row { struct timeval tv; @@ -85,7 +85,7 @@ struct roll_history* rspamd_roll_history_new (rspamd_mempool_t *pool); * @param history roll history object * @param task task object */ -void rspamd_roll_history_update (struct roll_history *history, struct worker_task *task); +void rspamd_roll_history_update (struct roll_history *history, struct rspamd_task *task); /** * Load previously saved history from file diff --git a/src/settings.c b/src/settings.c index 2e9b76fd8..c3292c8ab 100644 --- a/src/settings.c +++ b/src/settings.c @@ -381,7 +381,7 @@ init_settings (struct config_file *cfg) } static gboolean -check_setting (struct worker_task *task, struct rspamd_settings **user_settings, struct rspamd_settings **domain_settings) +check_setting (struct rspamd_task *task, struct rspamd_settings **user_settings, struct rspamd_settings **domain_settings) { gchar *field = NULL, *domain = NULL; gchar cmp_buf[1024]; @@ -437,7 +437,7 @@ check_setting (struct worker_task *task, struct rspamd_settings **user_settings, } static gboolean -check_bwhitelist (struct worker_task *task, struct rspamd_settings *s, gboolean *is_black) +check_bwhitelist (struct rspamd_task *task, struct rspamd_settings *s, gboolean *is_black) { gchar *src_email = NULL, *src_domain = NULL, *data; @@ -508,7 +508,7 @@ check_metric_settings (struct metric_result *res, double *score, double *rscore) } gboolean -check_metric_action_settings (struct worker_task *task, struct metric_result *res, +check_metric_action_settings (struct rspamd_task *task, struct metric_result *res, double score, enum rspamd_metric_action *result) { struct rspamd_settings *us = res->user_settings, *ds = res->domain_settings; @@ -571,7 +571,7 @@ check_metric_action_settings (struct worker_task *task, struct metric_result *re } gboolean -apply_metric_settings (struct worker_task *task, struct metric *metric, struct metric_result *res) +apply_metric_settings (struct rspamd_task *task, struct metric *metric, struct metric_result *res) { struct rspamd_settings *us = NULL, *ds = NULL; @@ -627,7 +627,7 @@ check_factor_settings (struct metric_result *res, const gchar *symbol, double *f gboolean -check_want_spam (struct worker_task *task) +check_want_spam (struct rspamd_task *task) { struct rspamd_settings *us = NULL, *ds = NULL; diff --git a/src/settings.h b/src/settings.h index 7f89dd4b9..361700094 100644 --- a/src/settings.h +++ b/src/settings.h @@ -35,7 +35,7 @@ gboolean check_metric_settings (struct metric_result *res, double *score, double /* * Check actions settings */ -gboolean check_metric_action_settings (struct worker_task *task, struct metric_result *res, double score, enum rspamd_metric_action *result); +gboolean check_metric_action_settings (struct rspamd_task *task, struct metric_result *res, double score, enum rspamd_metric_action *result); /* * Check individual weights for settings @@ -45,11 +45,11 @@ gboolean check_factor_settings (struct metric_result *res, const gchar *symbol, /* * Check want_spam flag */ -gboolean check_want_spam (struct worker_task *task); +gboolean check_want_spam (struct rspamd_task *task); /* * Search settings for metric and store pointers to settings into metric_result structure */ -gboolean apply_metric_settings (struct worker_task *task, struct metric *metric, struct metric_result *res); +gboolean apply_metric_settings (struct rspamd_task *task, struct metric *metric, struct metric_result *res); #endif diff --git a/src/smtp.h b/src/smtp.h index ab5bc9766..0f47cf0ee 100644 --- a/src/smtp.h +++ b/src/smtp.h @@ -73,7 +73,7 @@ struct smtp_session { enum rspamd_smtp_state state; enum rspamd_smtp_state upstream_state; struct rspamd_worker *worker; - struct worker_task *task; + struct rspamd_task *task; struct in_addr client_addr; gchar *hostname; gchar *error; diff --git a/src/smtp_utils.c b/src/smtp_utils.c index 68aed8e81..15551aa41 100644 --- a/src/smtp_utils.c +++ b/src/smtp_utils.c @@ -141,7 +141,7 @@ smtp_metric_callback (gpointer key, gpointer value, gpointer ud) enum rspamd_metric_action action = METRIC_ACTION_NOACTION; double ms = 0, rs = 0; gboolean is_spam = FALSE; - struct worker_task *task; + struct rspamd_task *task; task = cd->session->task; @@ -89,7 +89,7 @@ do { \ } \ } while (0) \ -static gboolean parse_spf_record (struct worker_task *task, struct spf_record *rec); +static gboolean parse_spf_record (struct rspamd_task *task, struct spf_record *rec); static void start_spf_parse (struct spf_record *rec, gchar *begin, guint ttl); /* Determine spf mech */ @@ -350,7 +350,7 @@ parse_spf_ipmask (const gchar *begin, struct spf_addr *addr, struct spf_record * } static gchar * -parse_spf_hostmask (struct worker_task *task, const gchar *begin, struct spf_addr *addr, struct spf_record *rec) +parse_spf_hostmask (struct rspamd_task *task, const gchar *begin, struct spf_addr *addr, struct spf_record *rec) { gchar *host = NULL, *p, mask_buf[3]; gint hostlen; @@ -393,7 +393,7 @@ spf_record_dns_callback (struct rdns_reply *reply, gpointer arg) gchar *begin; struct rdns_reply_entry *elt_data; GList *tmp = NULL; - struct worker_task *task; + struct rspamd_task *task; struct spf_addr *new_addr; task = cb->rec->task; @@ -600,7 +600,7 @@ spf_record_dns_callback (struct rdns_reply *reply, gpointer arg) } static gboolean -parse_spf_a (struct worker_task *task, const gchar *begin, struct spf_record *rec, struct spf_addr *addr) +parse_spf_a (struct rspamd_task *task, const gchar *begin, struct spf_record *rec, struct spf_addr *addr) { struct spf_dns_cb *cb; gchar *host; @@ -635,7 +635,7 @@ parse_spf_a (struct worker_task *task, const gchar *begin, struct spf_record *re } static gboolean -parse_spf_ptr (struct worker_task *task, const gchar *begin, struct spf_record *rec, struct spf_addr *addr) +parse_spf_ptr (struct rspamd_task *task, const gchar *begin, struct spf_record *rec, struct spf_addr *addr) { CHECK_REC (rec); @@ -645,7 +645,7 @@ parse_spf_ptr (struct worker_task *task, const gchar *begin, struct spf_record * } static gboolean -parse_spf_mx (struct worker_task *task, const gchar *begin, struct spf_record *rec, struct spf_addr *addr) +parse_spf_mx (struct rspamd_task *task, const gchar *begin, struct spf_record *rec, struct spf_addr *addr) { struct spf_dns_cb *cb; gchar *host; @@ -683,7 +683,7 @@ parse_spf_mx (struct worker_task *task, const gchar *begin, struct spf_record *r } static gboolean -parse_spf_all (struct worker_task *task, const gchar *begin, struct spf_record *rec, struct spf_addr *addr) +parse_spf_all (struct rspamd_task *task, const gchar *begin, struct spf_record *rec, struct spf_addr *addr) { /* All is 0/0 */ memset (&addr->data.normal.d, 0, sizeof (addr->data.normal.d)); @@ -700,7 +700,7 @@ parse_spf_all (struct worker_task *task, const gchar *begin, struct spf_record * } static gboolean -parse_spf_ip4 (struct worker_task *task, const gchar *begin, struct spf_record *rec, struct spf_addr *addr) +parse_spf_ip4 (struct rspamd_task *task, const gchar *begin, struct spf_record *rec, struct spf_addr *addr) { /* ip4:addr[/mask] */ @@ -710,7 +710,7 @@ parse_spf_ip4 (struct worker_task *task, const gchar *begin, struct spf_record * #ifdef HAVE_INET_PTON static gboolean -parse_spf_ip6 (struct worker_task *task, const gchar *begin, struct spf_record *rec, struct spf_addr *addr) +parse_spf_ip6 (struct rspamd_task *task, const gchar *begin, struct spf_record *rec, struct spf_addr *addr) { /* ip6:addr[/mask] */ @@ -720,7 +720,7 @@ parse_spf_ip6 (struct worker_task *task, const gchar *begin, struct spf_record * #endif static gboolean -parse_spf_include (struct worker_task *task, const gchar *begin, struct spf_record *rec, struct spf_addr *addr) +parse_spf_include (struct rspamd_task *task, const gchar *begin, struct spf_record *rec, struct spf_addr *addr) { struct spf_dns_cb *cb; gchar *domain; @@ -754,7 +754,7 @@ parse_spf_include (struct worker_task *task, const gchar *begin, struct spf_reco } static gboolean -parse_spf_exp (struct worker_task *task, const gchar *begin, struct spf_record *rec, struct spf_addr *addr) +parse_spf_exp (struct rspamd_task *task, const gchar *begin, struct spf_record *rec, struct spf_addr *addr) { CHECK_REC (rec); @@ -763,7 +763,7 @@ parse_spf_exp (struct worker_task *task, const gchar *begin, struct spf_record * } static gboolean -parse_spf_redirect (struct worker_task *task, const gchar *begin, struct spf_record *rec, struct spf_addr *addr) +parse_spf_redirect (struct rspamd_task *task, const gchar *begin, struct spf_record *rec, struct spf_addr *addr) { struct spf_dns_cb *cb; gchar *domain; @@ -794,7 +794,7 @@ parse_spf_redirect (struct worker_task *task, const gchar *begin, struct spf_rec } static gboolean -parse_spf_exists (struct worker_task *task, const gchar *begin, struct spf_record *rec, struct spf_addr *addr) +parse_spf_exists (struct rspamd_task *task, const gchar *begin, struct spf_record *rec, struct spf_addr *addr) { struct spf_dns_cb *cb; gchar *host; @@ -859,7 +859,7 @@ reverse_spf_ip (gchar *ip, gint len) } static gchar * -expand_spf_macro (struct worker_task *task, struct spf_record *rec, gchar *begin) +expand_spf_macro (struct rspamd_task *task, struct spf_record *rec, gchar *begin) { gchar *p, *c, *new, *tmp; gint len = 0, slen = 0, state = 0; @@ -1116,7 +1116,7 @@ expand_spf_macro (struct worker_task *task, struct spf_record *rec, gchar *begin /* Read current element and try to parse record */ static gboolean -parse_spf_record (struct worker_task *task, struct spf_record *rec) +parse_spf_record (struct rspamd_task *task, struct spf_record *rec) { struct spf_addr *new = NULL; gboolean need_shift, res = FALSE; @@ -1359,7 +1359,7 @@ spf_dns_callback (struct rdns_reply *reply, gpointer arg) } gchar * -get_spf_domain (struct worker_task *task) +get_spf_domain (struct rspamd_task *task) { gchar *domain, *res = NULL; GList *domains; @@ -1394,7 +1394,7 @@ get_spf_domain (struct worker_task *task) } gboolean -resolve_spf (struct worker_task *task, spf_cb_t callback) +resolve_spf (struct rspamd_task *task, spf_cb_t callback) { struct spf_record *rec; gchar *domain; @@ -3,10 +3,10 @@ #include "config.h" -struct worker_task; +struct rspamd_task; struct spf_record; -typedef void (*spf_cb_t)(struct spf_record *record, struct worker_task *task); +typedef void (*spf_cb_t)(struct spf_record *record, struct rspamd_task *task); typedef enum spf_mech_e { SPF_FAIL, @@ -63,7 +63,7 @@ struct spf_record { gchar *sender; gchar *sender_domain; gchar *local_part; - struct worker_task *task; + struct rspamd_task *task; spf_cb_t callback; gboolean in_include; @@ -73,12 +73,12 @@ struct spf_record { /* * Resolve spf record for specified task and call a callback after resolution fails/succeed */ -gboolean resolve_spf (struct worker_task *task, spf_cb_t callback); +gboolean resolve_spf (struct rspamd_task *task, spf_cb_t callback); /* * Get a domain for spf for specified task */ -gchar *get_spf_domain (struct worker_task *task); +gchar *get_spf_domain (struct rspamd_task *task); #endif diff --git a/src/symbols_cache.c b/src/symbols_cache.c index ae9fd605a..042f86998 100644 --- a/src/symbols_cache.c +++ b/src/symbols_cache.c @@ -643,7 +643,7 @@ init_symbols_cache (rspamd_mempool_t * pool, struct symbols_cache *cache, struct } static GList * -check_dynamic_item (struct worker_task *task, struct symbols_cache *cache) +check_dynamic_item (struct rspamd_task *task, struct symbols_cache *cache) { #ifdef HAVE_INET_PTON /* TODO: radix doesn't support ipv6 addrs */ @@ -665,7 +665,7 @@ check_dynamic_item (struct worker_task *task, struct symbols_cache *cache) } static gboolean -check_negative_dynamic_item (struct worker_task *task, struct symbols_cache *cache, struct cache_item *item) +check_negative_dynamic_item (struct rspamd_task *task, struct symbols_cache *cache, struct cache_item *item) { #ifdef HAVE_INET_PTON @@ -841,7 +841,7 @@ struct symbol_callback_data { }; gboolean -call_symbol_callback (struct worker_task * task, struct symbols_cache * cache, gpointer *save) +call_symbol_callback (struct rspamd_task * task, struct symbols_cache * cache, gpointer *save) { #ifdef HAVE_CLOCK_GETTIME struct timespec ts1, ts2; diff --git a/src/symbols_cache.h b/src/symbols_cache.h index cbbc9e8ff..bb2100fc1 100644 --- a/src/symbols_cache.h +++ b/src/symbols_cache.h @@ -6,10 +6,10 @@ #define MAX_SYMBOL 128 -struct worker_task; +struct rspamd_task; struct config_file; -typedef void (*symbol_func_t)(struct worker_task *task, gpointer user_data); +typedef void (*symbol_func_t)(struct rspamd_task *task, gpointer user_data); struct saved_cache_item { gchar symbol[MAX_SYMBOL]; @@ -130,7 +130,7 @@ void register_dynamic_symbol (rspamd_mempool_t *pool, struct symbols_cache **cac * @param cache symbols cache * @param saved_item pointer to currently saved item */ -gboolean call_symbol_callback (struct worker_task *task, struct symbols_cache *cache, gpointer *save); +gboolean call_symbol_callback (struct rspamd_task *task, struct symbols_cache *cache, gpointer *save); /** * Remove all dynamic rules from cache diff --git a/src/task.c b/src/task.c new file mode 100644 index 000000000..126ddcd1b --- /dev/null +++ b/src/task.c @@ -0,0 +1,23 @@ +/* Copyright (c) 2014, Vsevolod Stakhov + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + diff --git a/src/task.h b/src/task.h new file mode 100644 index 000000000..21948e117 --- /dev/null +++ b/src/task.h @@ -0,0 +1,147 @@ +/* Copyright (c) 2014, Vsevolod Stakhov + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef TASK_H_ +#define TASK_H_ + +#include "config.h" +#include "http.h" +#include "events.h" +#include "util.h" +#include "mem_pool.h" +#include "dns.h" + +enum rspamd_command { + CMD_CHECK, + CMD_SYMBOLS, + CMD_REPORT, + CMD_REPORT_IFSPAM, + CMD_SKIP, + CMD_PING, + CMD_PROCESS, + CMD_OTHER +}; + +enum rspamd_metric_action { + METRIC_ACTION_REJECT = 0, + METRIC_ACTION_SOFT_REJECT, + METRIC_ACTION_REWRITE_SUBJECT, + METRIC_ACTION_ADD_HEADER, + METRIC_ACTION_GREYLIST, + METRIC_ACTION_NOACTION, + METRIC_ACTION_MAX +}; + +typedef gint (*protocol_reply_func)(struct rspamd_task *task); + +struct custom_command { + const gchar *name; + protocol_reply_func func; +}; + +struct rspamd_view; + +/** + * Worker task structure + */ +struct rspamd_task { + struct rspamd_worker *worker; /**< pointer to worker object */ + enum { + READ_MESSAGE, + WAIT_PRE_FILTER, + WAIT_FILTER, + WAIT_POST_FILTER, + WRITE_REPLY, + CLOSING_CONNECTION + } state; /**< current session state */ + enum rspamd_command cmd; /**< command */ + struct custom_command *custom_cmd; /**< custom command if any */ + gint sock; /**< socket descriptor */ + gboolean is_mime; /**< if this task is mime task */ + gboolean is_json; /**< output is JSON */ + gboolean allow_learn; /**< allow learning */ + gboolean is_skipped; /**< whether message was skipped by configuration */ + + gchar *helo; /**< helo header value */ + gchar *from; /**< from header value */ + gchar *queue_id; /**< queue id if specified */ + const gchar *message_id; /**< message id */ + GList *rcpt; /**< recipients list */ + guint nrcpt; /**< number of recipients */ + rspamd_inet_addr_t from_addr; /**< from addr for a task */ + rspamd_inet_addr_t client_addr; /**< address of connected socket */ + gchar *deliver_to; /**< address to deliver */ + gchar *user; /**< user to deliver */ + gchar *subject; /**< subject (for non-mime) */ + gchar *hostname; /**< hostname reported by MTA */ + GString *msg; /**< message buffer */ + struct rspamd_http_connection *http_conn; /**< HTTP server connection */ + struct rspamd_async_session* s; /**< async session object */ + gint parts_count; /**< mime parts count */ + GMimeMessage *message; /**< message, parsed with GMime */ + GMimeObject *parser_parent_part; /**< current parent part */ + InternetAddressList *rcpts; /**< list of all recipients */ + GList *parts; /**< list of parsed parts */ + GList *text_parts; /**< list of text parts */ + gchar *raw_headers_str; /**< list of raw headers */ + GList *received; /**< list of received headers */ + GTree *urls; /**< list of parsed urls */ + GTree *emails; /**< list of parsed emails */ + GList *images; /**< list of images */ + GHashTable *raw_headers; /**< list of raw headers */ + GHashTable *results; /**< hash table of metric_result indexed by + * metric's name */ + GHashTable *tokens; /**< hash table of tokens indexed by tokenizer + * pointer */ + GList *messages; /**< list of messages that would be reported */ + GHashTable *re_cache; /**< cache for matched or not matched regexps */ + struct config_file *cfg; /**< pointer to config object */ + gchar *last_error; /**< last error */ + gint error_code; /**< code of last error */ + rspamd_mempool_t *task_pool; /**< memory pool for task */ +#ifdef HAVE_CLOCK_GETTIME + struct timespec ts; /**< time of connection */ +#endif + struct timeval tv; /**< time of connection */ + struct rspamd_view *view; /**< matching view */ + guint32 scan_milliseconds; /**< how much milliseconds passed */ + gboolean view_checked; + gboolean pass_all_filters; /**< pass task throught every rule */ + gboolean no_log; /**< do not log or write this task to the history */ + guint32 parser_recursion; /**< for avoiding recursion stack overflow */ + gboolean (*fin_callback)(void *arg); /**< calback for filters finalizing */ + void *fin_arg; /**< argument for fin callback */ + + guint32 dns_requests; /**< number of DNS requests per this task */ + + struct rspamd_dns_resolver *resolver; /**< DNS resolver */ + struct event_base *ev_base; /**< Event base */ + + GThreadPool *classify_pool; /**< A pool of classify threads */ + + struct { + enum rspamd_metric_action action; /**< Action of pre filters */ + gchar *str; /**< String describing action */ + } pre_result; /**< Result of pre-filters */ +}; + +#endif /* TASK_H_ */ diff --git a/src/tokenizers/tokenizers.c b/src/tokenizers/tokenizers.c index 0cdd0aaf4..448dcd53e 100644 --- a/src/tokenizers/tokenizers.c +++ b/src/tokenizers/tokenizers.c @@ -189,7 +189,7 @@ typedef struct _GMimeHeader { } local_GMimeHeader; int -tokenize_headers (rspamd_mempool_t * pool, struct worker_task *task, GTree ** tree) +tokenize_headers (rspamd_mempool_t * pool, struct rspamd_task *task, GTree ** tree) { token_node_t *new = NULL; f_str_t headername; @@ -252,7 +252,7 @@ tokenize_headers (rspamd_mempool_t * pool, struct worker_task *task, GTree ** tr } void -tokenize_subject (struct worker_task *task, GTree ** tree) +tokenize_subject (struct rspamd_task *task, GTree ** tree) { f_str_t subject; const gchar *sub; diff --git a/src/tokenizers/tokenizers.h b/src/tokenizers/tokenizers.h index 0a8d27d57..207602dc8 100644 --- a/src/tokenizers/tokenizers.h +++ b/src/tokenizers/tokenizers.h @@ -34,9 +34,9 @@ gchar* get_next_word (f_str_t *buf, f_str_t *token, GList **exceptions); int osb_tokenize_text (struct tokenizer *tokenizer, rspamd_mempool_t *pool, f_str_t *input, GTree **cur, gboolean save_token, gboolean is_utf, GList *exceptions); /* Common tokenizer for headers */ -int tokenize_headers (rspamd_mempool_t *pool, struct worker_task *task, GTree **cur); +int tokenize_headers (rspamd_mempool_t *pool, struct rspamd_task *task, GTree **cur); /* Make tokens for a subject */ -void tokenize_subject (struct worker_task *task, GTree ** tree); +void tokenize_subject (struct rspamd_task *task, GTree ** tree); /* Array of all defined tokenizers */ extern struct tokenizer tokenizers[]; @@ -1488,7 +1488,7 @@ url_email_end (const gchar *begin, const gchar *end, const gchar *pos, url_match } void -url_parse_text (rspamd_mempool_t * pool, struct worker_task *task, struct mime_text_part *part, gboolean is_html) +url_parse_text (rspamd_mempool_t * pool, struct rspamd_task *task, struct mime_text_part *part, gboolean is_html) { gint rc; gchar *url_str = NULL, *url_start, *url_end; @@ -5,7 +5,7 @@ #include "config.h" #include "mem_pool.h" -struct worker_task; +struct rspamd_task; struct mime_text_part; struct uri { @@ -81,7 +81,7 @@ enum protocol { * @param part current text part * @param is_html turn on html euristic */ -void url_parse_text (rspamd_mempool_t *pool, struct worker_task *task, struct mime_text_part *part, gboolean is_html); +void url_parse_text (rspamd_mempool_t *pool, struct rspamd_task *task, struct mime_text_part *part, gboolean is_html); /* * Parse a single url into an uri structure diff --git a/src/util.h b/src/util.h index 643c8ef38..972730d04 100644 --- a/src/util.h +++ b/src/util.h @@ -26,6 +26,13 @@ union sa_union { struct sockaddr_un su; }; +typedef struct _rspamd_inet_addr_s { + union sa_union addr; + socklen_t slen; + int af; +} rspamd_inet_addr_t; + + /* * Create socket and bind or connect it to specified address and port */ @@ -454,4 +461,5 @@ gboolean rspamd_ip_is_valid (void *ptr, int af); */ void rspamd_ucl_emit_gstring (ucl_object_t *obj, enum ucl_emitter emit_type, GString *target); + #endif diff --git a/src/view.c b/src/view.c index 7ff7968bc..f3534f84c 100644 --- a/src/view.c +++ b/src/view.c @@ -131,7 +131,7 @@ add_view_client_ip (struct rspamd_view * view, const gchar *line) static struct rspamd_view * -find_view_by_ip (GList * views, struct worker_task *task) +find_view_by_ip (GList * views, struct rspamd_task *task) { GList *cur; struct rspamd_view *v; @@ -172,7 +172,7 @@ find_view_by_ip (GList * views, struct worker_task *task) } static struct rspamd_view * -find_view_by_client_ip (GList * views, struct worker_task *task) +find_view_by_client_ip (GList * views, struct rspamd_task *task) { GList *cur; struct rspamd_view *v; @@ -195,7 +195,7 @@ find_view_by_client_ip (GList * views, struct worker_task *task) } static struct rspamd_view * -find_view_by_from (GList * views, struct worker_task *task) +find_view_by_from (GList * views, struct rspamd_task *task) { GList *cur, *cur_re; struct rspamd_view *v; @@ -239,7 +239,7 @@ find_view_by_from (GList * views, struct worker_task *task) } static inline gboolean -check_view_rcpt (struct rspamd_view *v, struct worker_task *task) +check_view_rcpt (struct rspamd_view *v, struct rspamd_task *task) { GList *cur, *cur_re; gchar rcpt_user[256], *p; @@ -292,7 +292,7 @@ check_view_rcpt (struct rspamd_view *v, struct worker_task *task) } static struct rspamd_view * -find_view_by_rcpt (GList * views, struct worker_task *task) +find_view_by_rcpt (GList * views, struct rspamd_task *task) { GList *cur; struct rspamd_view *v; @@ -342,7 +342,7 @@ match_view_symbol (struct rspamd_view *v, const gchar *symbol) } gboolean -check_view (GList * views, const gchar *symbol, struct worker_task * task) +check_view (GList * views, const gchar *symbol, struct rspamd_task * task) { struct rspamd_view *selected = NULL; @@ -384,7 +384,7 @@ check_view (GList * views, const gchar *symbol, struct worker_task * task) } gboolean -check_skip (GList * views, struct worker_task * task) +check_skip (GList * views, struct rspamd_task * task) { if (check_view (views, NULL, task) == FALSE) { return TRUE; diff --git a/src/view.h b/src/view.h index cb6fc6505..ecefa83cb 100644 --- a/src/view.h +++ b/src/view.h @@ -82,7 +82,7 @@ gboolean add_view_symbols (struct rspamd_view *view, const gchar *line); * @param task task object * @return whether to check this symbol for this task */ -gboolean check_view (GList *views, const gchar *symbol, struct worker_task *task); +gboolean check_view (GList *views, const gchar *symbol, struct rspamd_task *task); /** * Check whether this task should be skipped from checks @@ -90,6 +90,6 @@ gboolean check_view (GList *views, const gchar *symbol, struct worker_task *task * @param task task object * @return */ -gboolean check_skip (GList *views, struct worker_task *task); +gboolean check_skip (GList *views, struct rspamd_task *task); #endif diff --git a/src/webui.c b/src/webui.c index b0b44e5f4..5e8c33a35 100644 --- a/src/webui.c +++ b/src/webui.c @@ -120,7 +120,7 @@ struct rspamd_webui_worker_ctx { struct rspamd_webui_session { struct rspamd_webui_worker_ctx *ctx; rspamd_mempool_t *pool; - struct worker_task *task; + struct rspamd_task *task; struct classifier_config *cl; struct { union { @@ -284,7 +284,7 @@ rspamd_webui_check_password (struct rspamd_http_connection_entry *entry, } struct scan_callback_data { - struct worker_task *task; + struct rspamd_task *task; struct evhttp_request *req; struct rspamd_webui_worker_ctx *ctx; gboolean processed; @@ -434,7 +434,7 @@ rspamd_webui_scan_task_restore (gpointer arg) static struct scan_callback_data* rspamd_webui_prepare_scan (struct evhttp_request *req, struct rspamd_webui_worker_ctx *ctx, struct evbuffer *in, GError **err) { - struct worker_task *task; + struct rspamd_task *task; struct scan_callback_data *cbdata; /* Check for data */ @@ -483,7 +483,7 @@ rspamd_webui_prepare_scan (struct evhttp_request *req, struct rspamd_webui_worke } struct learn_callback_data { - struct worker_task *task; + struct rspamd_task *task; struct evhttp_request *req; struct classifier_config *classifier; struct rspamd_webui_worker_ctx *ctx; @@ -593,7 +593,7 @@ rspamd_webui_learn_task_restore (gpointer arg) static struct learn_callback_data* rspamd_webui_prepare_learn (struct evhttp_request *req, struct rspamd_webui_worker_ctx *ctx, struct evbuffer *in, gboolean is_spam, GError **err) { - struct worker_task *task; + struct rspamd_task *task; struct learn_callback_data *cbdata; struct classifier_config *cl; @@ -1221,7 +1221,7 @@ rspamd_webui_handle_history (struct rspamd_http_connection_entry *conn_ent, static gboolean rspamd_webui_learn_fin_task (void *ud) { - struct worker_task *task = ud; + struct rspamd_task *task = ud; struct rspamd_webui_session *session; struct rspamd_http_connection_entry *conn_ent; GError *err = NULL; @@ -1246,7 +1246,7 @@ rspamd_webui_handle_learn_common (struct rspamd_http_connection_entry *conn_ent, struct rspamd_webui_session *session = conn_ent->ud; struct rspamd_webui_worker_ctx *ctx; struct classifier_config *cl; - struct worker_task *task; + struct rspamd_task *task; const gchar *classifier; ctx = session->ctx; diff --git a/src/worker.c b/src/worker.c index 8f6766350..b67b02775 100644 --- a/src/worker.c +++ b/src/worker.c @@ -168,7 +168,7 @@ rspamd_worker_body_handler (struct rspamd_http_connection *conn, struct rspamd_http_message *msg, const gchar *chunk, gsize len) { - struct worker_task *task = (struct worker_task *) conn->ud; + struct rspamd_task *task = (struct rspamd_task *) conn->ud; struct rspamd_worker_ctx *ctx; ssize_t r; GError *err = NULL; @@ -251,7 +251,7 @@ rspamd_worker_body_handler (struct rspamd_http_connection *conn, static void rspamd_worker_error_handler (struct rspamd_http_connection *conn, GError *err) { - struct worker_task *task = (struct worker_task *) conn->ud; + struct rspamd_task *task = (struct rspamd_task *) conn->ud; msg_info ("abnormally closing connection from: %s, error: %s", inet_ntoa (task->client_addr), err->message); @@ -272,7 +272,7 @@ static gint rspamd_worker_finish_handler (struct rspamd_http_connection *conn, struct rspamd_http_message *msg) { - struct worker_task *task = (struct worker_task *) conn->ud; + struct rspamd_task *task = (struct rspamd_task *) conn->ud; if (task->state == CLOSING_CONNECTION) { msg_debug ("normally closing connection from: %s", inet_ntoa (task->client_addr)); @@ -299,7 +299,7 @@ accept_socket (gint fd, short what, void *arg) struct rspamd_worker *worker = (struct rspamd_worker *) arg; struct rspamd_worker_ctx *ctx; union sa_union su; - struct worker_task *new_task; + struct rspamd_task *new_task; char ip_str[INET6_ADDRSTRLEN + 1]; socklen_t addrlen = sizeof (su); diff --git a/src/worker_util.c b/src/worker_util.c index 9d86e8d3b..99bad83fd 100644 --- a/src/worker_util.c +++ b/src/worker_util.c @@ -34,7 +34,7 @@ extern struct rspamd_main *rspamd_main; static void rcpt_destruct (void *pointer) { - struct worker_task *task = (struct worker_task *) pointer; + struct rspamd_task *task = (struct rspamd_task *) pointer; if (task->rcpt) { g_list_free (task->rcpt); @@ -44,12 +44,12 @@ rcpt_destruct (void *pointer) /* * Create new task */ -struct worker_task * +struct rspamd_task * construct_task (struct rspamd_worker *worker) { - struct worker_task *new_task; + struct rspamd_task *new_task; - new_task = g_slice_alloc0 (sizeof (struct worker_task)); + new_task = g_slice_alloc0 (sizeof (struct rspamd_task)); new_task->worker = worker; new_task->state = READ_MESSAGE; @@ -130,7 +130,7 @@ get_worker_by_type (GQuark type) * Free all structures of worker_task */ void -free_task (struct worker_task *task, gboolean is_soft) +free_task (struct rspamd_task *task, gboolean is_soft) { GList *part; struct mime_part *p; @@ -171,14 +171,14 @@ free_task (struct worker_task *task, gboolean is_soft) close (task->sock); } rspamd_mempool_delete (task->task_pool); - g_slice_free1 (sizeof (struct worker_task), task); + g_slice_free1 (sizeof (struct rspamd_task), task); } } void free_task_hard (gpointer ud) { - struct worker_task *task = ud; + struct rspamd_task *task = ud; free_task (task, FALSE); } @@ -186,7 +186,7 @@ free_task_hard (gpointer ud) void free_task_soft (gpointer ud) { - struct worker_task *task = ud; + struct rspamd_task *task = ud; free_task (task, FALSE); } @@ -290,7 +290,7 @@ worker_stop_accept (struct rspamd_worker *worker) gboolean rspamd_fin_task (void *arg) { - struct worker_task *task = (struct worker_task *) arg; + struct rspamd_task *task = (struct rspamd_task *) arg; gint r; GError *err = NULL; @@ -387,7 +387,7 @@ rspamd_fin_task (void *arg) void rspamd_restore_task (void *arg) { - struct worker_task *task = (struct worker_task *) arg; + struct rspamd_task *task = (struct rspamd_task *) arg; /* Call post filters */ if (task->state == WAIT_POST_FILTER) { |