statfile.c
statfile_sync.c
symbols_cache.c
+ task.c
url.c
view.c)
}
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;
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;
}
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;
#define ALPHA 0.0001
struct classifier_config;
-struct worker_task;
+struct rspamd_task;
struct classifier_ctx {
rspamd_mempool_t *pool;
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 */
/* 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[];
}
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;
}
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.;
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 */
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 */
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 */
}
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;
}
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;
* @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;
}
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);
* @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
#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
}
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;
}
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;
}
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;
}
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;
* 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;
#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;
}
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;
}
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) {
}
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
}
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;
}
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;
}
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;
#include "config.h"
#include <lua.h>
-struct worker_task;
+struct rspamd_task;
struct rspamd_regexp;
/**
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
* @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
* @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
* @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)
* @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
}
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;
#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;
/* 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;
}
gint
-process_filters (struct worker_task *task)
+process_filters (struct rspamd_task *task)
{
GList *cur;
struct metric *metric;
struct composites_data {
- struct worker_task *task;
+ struct rspamd_task *task;
struct metric_result *metric_res;
GTree *symbols_to_remove;
guint8 *checked;
}
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;
}
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;
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;
}
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;
};
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;
void
-process_statfiles (struct worker_task *task)
+process_statfiles (struct rspamd_task *task)
{
struct classifiers_cbdata cbdata;
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;
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];
}
void
-insert_headers (struct worker_task *task)
+insert_headers (struct rspamd_task *task)
{
g_hash_table_foreach (task->results, insert_metric_header, task);
}
}
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;
}
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;
#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 };
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;
* @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
* @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
* @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
* @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
* @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
* @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
}
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;
}
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;
}
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;
};
/* 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);
/*
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;
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;
}
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;
}
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;
}
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;
}
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;
/*
* 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
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);
{
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);
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) {
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:
{
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;
}
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;
}
struct mta_callback_data {
- struct worker_task *task;
+ struct rspamd_task *task;
rspamd_io_dispatcher_t *dispatcher;
enum {
LMTP_WANT_GREETING,
* 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;
}
static gchar *
-format_lda_args (struct worker_task *task)
+format_lda_args (struct rspamd_task *task)
{
gchar *res, *c, *r;
size_t len;
}
static gint
-lmtp_deliver_lda (struct worker_task *task)
+lmtp_deliver_lda (struct rspamd_task *task)
{
gchar *args, **argv;
GMimeStream *stream;
}
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 */
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) {
#include "config.h"
-struct worker_task;
+struct rspamd_task;
enum lmtp_state {
LMTP_READ_LHLO,
};
struct rspamd_lmtp_proto {
- struct worker_task *task;
+ struct rspamd_task *task;
enum lmtp_state state;
};
* @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
/* 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 */
}
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;
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;
/* 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;
/* 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;
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;
/* 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;
}
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;
/* 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;
* LUA custom consolidation function
*/
struct consolidation_callback_data {
- struct worker_task *task;
+ struct rspamd_task *task;
double score;
const gchar *func;
};
}
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.;
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);
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);
}
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;
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 */
}
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;
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;
}
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;
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;
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);
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;
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;
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;
};
struct lua_http_ud {
- struct worker_task *task;
+ struct rspamd_task *task;
gint parser_state;
struct rspamd_async_session *s;
rspamd_mempool_t *pool;
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;
{
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;
* 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;
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;
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;
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;
* @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
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;
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;
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;
};
/* 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 *
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));
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;
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) {
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");
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);
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 *));
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 *));
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 *));
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 *));
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;
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;
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) {
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) {
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;
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;
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);
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;
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;
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) {
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 ++;
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;
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;
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) {
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) {
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);
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) {
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);
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) {
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);
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);
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) {
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) {
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) {
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) {
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;
}
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;
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;
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) {
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);
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);
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;
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;
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;
#include "logger.h"
#include "roll_history.h"
#include "http.h"
+#include "task.h"
/* Default values */
#define FIXED_CONFIG_FILE RSPAMD_CONFDIR "/rspamd.conf"
struct mime_part;
struct rspamd_view;
struct rspamd_dns_resolver;
-struct worker_task;
+struct rspamd_task;
/**
* Server statistics
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 */
};
/**
/**
* 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);
#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;
/* 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;
}
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;
}
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;
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;
}
gint
-process_message (struct worker_task *task)
+process_message (struct rspamd_task *task)
{
GMimeMessage *message;
GMimeParser *parser;
}
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;
#include "config.h"
#include "fuzzy.h"
-struct worker_task;
+struct rspamd_task;
struct controller_session;
struct mime_part {
* @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
* @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
};
struct chartable_ctx {
- gint (*filter) (struct worker_task * task);
+ gint (*filter) (struct rspamd_task * task);
const gchar *symbol;
double threshold;
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)
}
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;
}
static gint
-chartable_mime_filter (struct worker_task *task)
+chartable_mime_filter (struct rspamd_task *task)
{
/* XXX: remove it */
return 0;
#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;
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);
}
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;
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) {
}
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;
};
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;
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;
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);
}
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;
}
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;
/* 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;
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;
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;
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];
};
struct regexp_ctx {
- gint (*filter) (struct worker_task * task);
+ gint (*filter) (struct rspamd_task * task);
GHashTable *autolearn_symbols;
gchar *statfile_prefix;
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 */
#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;
}
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;
}
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;
}
struct url_regexp_param {
- struct worker_task *task;
+ struct rspamd_task *task;
GRegex *regexp;
struct rspamd_regexp *re;
gboolean found;
}
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;
}
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 */
}
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;
struct regexp_threaded_ud {
struct regexp_module_item *item;
- struct worker_task *task;
+ struct rspamd_task *task;
};
static void
}
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;
}
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;
}
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;
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;
}
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;
}
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;
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 */
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
#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;
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);
}
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
}
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;
}
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;
static void
-spf_symbol_callback (struct worker_task *task, void *unused)
+spf_symbol_callback (struct rspamd_task *task, void *unused)
{
gchar *domain;
GList *l;
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);
}
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;
}
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;
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");
}
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;
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;
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;
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;
}
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;
gchar *buf;
gsize len;
gsize off;
- struct worker_task *task;
+ struct rspamd_task *task;
};
static gboolean
static gboolean
-urls_command_handler (struct worker_task *task)
+urls_command_handler (struct rspamd_task *task)
{
struct urls_tree_cb_data cb;
};
struct surbl_ctx {
- gint (*filter)(struct worker_task *task);
+ gint (*filter)(struct rspamd_task *task);
guint16 weight;
guint connect_timeout;
guint read_timeout;
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,
struct memcached_param {
struct uri *url;
- struct worker_task *task;
+ struct rspamd_task *task;
memcached_ctx_t *ctx;
GTree *tree;
struct suffix_item *suffix;
}
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;
}
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;
}
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;
}
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;
/* Structure for writing tree data */
struct tree_cb_data {
ucl_object_t *top;
- struct worker_task *task;
+ struct rspamd_task *task;
};
/*
}
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;
}
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;
/* 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;
}
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;
}
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;
}
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;
}
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;
}
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";
#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);
/**
* @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;
#define HISTORY_MAX_USER 20
#define HISTORY_MAX_ROWS 200
-struct worker_task;
+struct rspamd_task;
struct roll_history_row {
struct timeval tv;
* @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
}
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];
}
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;
}
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;
}
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;
gboolean
-check_want_spam (struct worker_task *task)
+check_want_spam (struct rspamd_task *task)
{
struct rspamd_settings *us = NULL, *ds = NULL;
/*
* 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
/*
* 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
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;
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;
} \
} 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 */
}
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;
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;
}
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;
}
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);
}
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;
}
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));
}
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] */
#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] */
#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;
}
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);
}
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;
}
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;
}
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;
/* 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;
}
gchar *
-get_spf_domain (struct worker_task *task)
+get_spf_domain (struct rspamd_task *task)
{
gchar *domain, *res = NULL;
GList *domains;
}
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;
#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,
gchar *sender;
gchar *sender_domain;
gchar *local_part;
- struct worker_task *task;
+ struct rspamd_task *task;
spf_cb_t callback;
gboolean in_include;
/*
* 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
}
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 */
}
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
};
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;
#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];
* @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
--- /dev/null
+/* 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.
+ */
+
--- /dev/null
+/* 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_ */
} 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;
}
void
-tokenize_subject (struct worker_task *task, GTree ** tree)
+tokenize_subject (struct rspamd_task *task, GTree ** tree)
{
f_str_t subject;
const gchar *sub;
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[];
}
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;
#include "config.h"
#include "mem_pool.h"
-struct worker_task;
+struct rspamd_task;
struct mime_text_part;
struct uri {
* @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
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
*/
*/
void rspamd_ucl_emit_gstring (ucl_object_t *obj, enum ucl_emitter emit_type, GString *target);
+
#endif
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
* @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
* @param task task object
* @return
*/
-gboolean check_skip (GList *views, struct worker_task *task);
+gboolean check_skip (GList *views, struct rspamd_task *task);
#endif
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 {
}
struct scan_callback_data {
- struct worker_task *task;
+ struct rspamd_task *task;
struct evhttp_request *req;
struct rspamd_webui_worker_ctx *ctx;
gboolean processed;
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 */
}
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;
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;
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;
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;
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;
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);
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));
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);
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);
/*
* 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;
* 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;
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);
}
void
free_task_soft (gpointer ud)
{
- struct worker_task *task = ud;
+ struct rspamd_task *task = ud;
free_task (task, FALSE);
}
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;
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) {