wl = ucl_object_find_key (task->settings, "whitelist");
if (wl != NULL) {
msg_info ("<%s> is whitelisted", task->message_id);
- task->is_skipped = TRUE;
+ task->flags |= RSPAMD_TASK_FLAG_SKIP;
return 0;
}
}
cur = task->cfg->metrics_list;
while (cur) {
metric = cur->data;
- if (!task->pass_all_filters &&
+ if (!(task->flags & RSPAMD_TASK_FLAG_PASS_ALL) &&
metric->actions[METRIC_ACTION_REJECT].score > 0 &&
check_metric_is_spam (task, metric)) {
msg_info ("<%s> has already scored more than %.2f, so do not "
void
rspamd_process_statistics (struct rspamd_task *task)
{
- if (task->is_skipped) {
+ if (RSPAMD_TASK_IS_SKIPPED (task)) {
return;
}
struct rspamd_task *task = (struct rspamd_task *)data;
struct lua_locked_state *nL = user_data;
- if (task->is_skipped) {
+ if (RSPAMD_TASK_IS_SKIPPED (task)) {
remove_async_thread (task->s);
return;
}
*/
g_mime_stream_mem_set_owner (GMIME_STREAM_MEM (stream), FALSE);
- if (task->is_mime) {
+ if (task->flags & RSPAMD_TASK_FLAG_MIME) {
debug_task ("construct mime parser from string length %d",
(gint)task->msg.len);
cd->res = metric_res;
}
- if (!task->is_skipped) {
+ if (!RSPAMD_TASK_IS_SKIPPED (task)) {
cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset,
cd->log_size - cd->log_offset,
"(%s: %c (%s): [%.2f/%.2f/%.2f] [",
struct rspamd_http_message *msg)
{
gchar *headern, *tmp;
- gboolean res = TRUE, validh;
+ gboolean res = TRUE, validh, fl;
struct rspamd_http_header *h;
LL_FOREACH (msg->headers, h)
case 'j':
case 'J':
if (g_ascii_strcasecmp (headern, JSON_HEADER) == 0) {
- task->is_json = rspamd_config_parse_flag (h->value->str);
+ fl = rspamd_config_parse_flag (h->value->str);
+ if (fl) {
+ task->flags |= RSPAMD_TASK_FLAG_JSON;
+ }
+ else {
+ task->flags &= ~RSPAMD_TASK_FLAG_JSON;
+ }
}
else {
debug_task ("wrong header: %s", headern);
if (g_ascii_strcasecmp (headern, PASS_HEADER) == 0) {
if (h->value->len == sizeof ("all") - 1 &&
g_ascii_strcasecmp (h->value->str, "all") == 0) {
- task->pass_all_filters = TRUE;
+ task->flags |= RSPAMD_TASK_FLAG_PASS_ALL;
debug_task ("pass all filters");
}
}
if (g_ascii_strcasecmp (headern, URLS_HEADER) == 0) {
if (h->value->len == sizeof ("extended") - 1 &&
g_ascii_strcasecmp (h->value->str, "extended") == 0) {
- task->extended_urls = TRUE;
+ task->flags |= RSPAMD_TASK_FLAG_EXT_URLS;
debug_task ("extended urls information");
}
}
case 'L':
if (g_ascii_strcasecmp (headern, NO_LOG_HEADER) == 0) {
if (g_ascii_strcasecmp (h->value->str, "no") == 0) {
- task->no_log = TRUE;
+ task->flags |= RSPAMD_TASK_FLAG_NO_LOG;
}
}
else {
if (msg->method == HTTP_SYMBOLS) {
task->cmd = CMD_SYMBOLS;
- task->is_json = FALSE;
+ task->flags &= ~RSPAMD_TASK_FLAG_JSON;
}
else if (msg->method == HTTP_CHECK) {
task->cmd = CMD_CHECK;
- task->is_json = FALSE;
+ task->flags &= ~RSPAMD_TASK_FLAG_JSON;
}
else {
- task->is_json = TRUE;
+ task->flags |= RSPAMD_TASK_FLAG_JSON;
ret = rspamd_protocol_handle_url (task, msg);
}
if (msg->flags & RSPAMD_HTTP_FLAG_SPAMC) {
- task->is_spamc = TRUE;
+ task->flags &= ~RSPAMD_TASK_FLAG_JSON;
+ task->flags |= RSPAMD_TASK_FLAG_SPAMC;
}
return ret;
struct rspamd_url *url = value;
ucl_object_t *obj, *elt;
- if (!cb->task->extended_urls) {
+ if (!(cb->task->flags & RSPAMD_TASK_FLAG_EXT_URLS)) {
obj = ucl_object_fromlstring (url->host, url->hostlen);
}
else {
action = mres->action;
is_spam = (action == METRIC_ACTION_REJECT);
- if (task->is_skipped) {
+ if (RSPAMD_TASK_IS_SKIPPED (task)) {
action_char = 'S';
}
else if (is_spam) {
obj = ucl_object_typed_new (UCL_OBJECT);
ucl_object_insert_key (obj, ucl_object_frombool (is_spam),
"is_spam", 0, false);
- ucl_object_insert_key (obj, ucl_object_frombool (task->is_skipped),
+ ucl_object_insert_key (obj, ucl_object_frombool (RSPAMD_TASK_IS_SKIPPED (task)),
"is_skipped", 0, false);
ucl_object_insert_key (obj, ucl_object_fromdouble (mres->score),
"score", 0, false);
rspamd_printf_gstring (logbuf, "user: %s, ", task->user);
}
- if (!task->no_log) {
+ if (!(task->flags & RSPAMD_TASK_FLAG_NO_LOG)) {
rspamd_roll_history_update (task->worker->srv->history, task);
}
"message-id", 0, false);
write_hashes_to_log (task, logbuf);
- if (!task->no_log) {
+ if (!(task->flags & RSPAMD_TASK_FLAG_NO_LOG)) {
msg_info ("%v", logbuf);
}
g_string_free (logbuf, TRUE);
msg->body = g_string_sized_new (BUFSIZ);
- if (msg->method < HTTP_SYMBOLS && !task->is_spamc) {
+ if (msg->method < HTTP_SYMBOLS && !RSPAMD_TASK_IS_SPAMC (task)) {
rspamd_ucl_emit_gstring (top, UCL_EMIT_JSON_COMPACT, msg->body);
}
else {
- if (task->is_spamc) {
+ if (RSPAMD_TASK_IS_SPAMC (task)) {
rspamd_ucl_tospamc_output (task, top, msg->body);
}
else {
msg->peer_key = rspamd_http_connection_key_ref (task->peer_key);
msg_info ("<%s> writing encrypted reply", task->message_id);
}
- if (!task->is_json) {
+ if (!RSPAMD_TASK_IS_JSON (task)) {
/* Turn compatibility on */
msg->method = HTTP_SYMBOLS;
}
- if (task->is_spamc) {
+ if (RSPAMD_TASK_IS_SPAMC (task)) {
msg->flags |= RSPAMD_HTTP_FLAG_SPAMC;
}
new_task->state = READ_MESSAGE;
if (worker) {
new_task->cfg = worker->srv->cfg;
- new_task->pass_all_filters = new_task->cfg->check_all_filters;
+ if (new_task->cfg->check_all_filters) {
+ new_task->flags |= RSPAMD_TASK_FLAG_PASS_ALL;
+ }
}
#ifdef HAVE_CLOCK_GETTIME
# ifdef HAVE_CLOCK_PROCESS_CPUTIME_ID
(rspamd_mempool_destruct_t) g_tree_destroy,
new_task->urls);
new_task->sock = -1;
- new_task->is_mime = TRUE;
- new_task->is_json = TRUE;
+ new_task->flags |= (RSPAMD_TASK_FLAG_MIME|RSPAMD_TASK_FLAG_JSON);
new_task->pre_result.action = METRIC_ACTION_NOACTION;
new_task->message_id = new_task->queue_id = "undef";
return TRUE;
}
/* Add task to classify to classify pool */
- if (!task->is_skipped && task->classify_pool) {
+ if (!RSPAMD_TASK_IS_SKIPPED (task) && task->classify_pool) {
register_async_thread (task->s);
g_thread_pool_push (task->classify_pool, task, &err);
if (err != NULL) {
g_error_free (err);
}
}
- if (task->is_skipped) {
+ if (RSPAMD_TASK_IS_SKIPPED (task)) {
rspamd_task_reply (task);
}
else {
struct rspamd_task *task = (struct rspamd_task *) arg;
/* Call post filters */
- if (task->state == WAIT_POST_FILTER && !task->skip_extra_filters) {
+ if (task->state == WAIT_POST_FILTER &&
+ !(task->flags & RSPAMD_TASK_FLAG_SKIP_EXTRA)) {
rspamd_lua_call_post_filters (task);
}
task->s->wanna_die = TRUE;
task->state = WRITE_REPLY;
return FALSE;
}
- task->skip_extra_filters = !process_extra_filters;
+ if (!process_extra_filters) {
+ task->flags |= RSPAMD_TASK_FLAG_SKIP_EXTRA;
+ }
if (!process_extra_filters || task->cfg->pre_filters == NULL) {
r = rspamd_process_filters (task);
if (r == -1) {
return FALSE;
}
/* Add task to classify to classify pool */
- if (!task->is_skipped && classify_pool) {
+ if (!RSPAMD_TASK_IS_SKIPPED (task) && classify_pool) {
register_async_thread (task->s);
g_thread_pool_push (classify_pool, task, &err);
if (err != NULL) {
task->classify_pool = classify_pool;
}
}
- if (task->is_skipped) {
+ if (RSPAMD_TASK_IS_SKIPPED (task)) {
/* Call write_socket to write reply and exit */
task->state = WRITE_REPLY;
}
METRIC_ACTION_MAX
};
+#define RSPAMD_TASK_FLAG_MIME (1 << 0)
+#define RSPAMD_TASK_FLAG_JSON (1 << 1)
+#define RSPAMD_TASK_FLAG_SKIP_EXTRA (1 << 2)
+#define RSPAMD_TASK_FLAG_SKIP (1 << 3)
+#define RSPAMD_TASK_FLAG_EXT_URLS (1 << 4)
+#define RSPAMD_TASK_FLAG_SPAMC (1 << 5)
+#define RSPAMD_TASK_FLAG_PASS_ALL (1 << 6)
+#define RSPAMD_TASK_FLAG_NO_LOG (1 << 7)
+
+#define RSPAMD_TASK_IS_SKIPPED(task) (((task)->flags & RSPAMD_TASK_FLAG_SKIP))
+#define RSPAMD_TASK_IS_JSON(task) (((task)->flags & RSPAMD_TASK_FLAG_JSON))
+#define RSPAMD_TASK_IS_SPAMC(task) (((task)->flags & RSPAMD_TASK_FLAG_SPAMC))
+
typedef gint (*protocol_reply_func)(struct rspamd_task *task);
struct custom_command {
enum rspamd_command cmd; /**< command */
struct custom_command *custom_cmd; /**< custom command if any */
gint sock; /**< socket descriptor */
- /* TODO: all these fields should be converted to flags */
- gboolean is_mime; /**< if this task is mime task */
- gboolean is_json; /**< output is JSON */
- gboolean skip_extra_filters; /**< skip pre and post filters */
- gboolean is_skipped; /**< whether message was skipped by configuration */
- gboolean extended_urls; /**< output URLs in details */
- gboolean is_spamc; /**< need legacy spamc output */
+ gint flags;
gchar *helo; /**< helo header value */
gchar *queue_id; /**< queue id if specified */
#endif
struct timeval tv; /**< time of connection */
guint32 scan_milliseconds; /**< how much milliseconds passed */
- 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 */
rspamd_inet_address_get_port (&addr));
/* Copy some variables */
+ if (ctx->is_mime) {
+ new_task->flags |= RSPAMD_TASK_FLAG_MIME;
+ }
+ else {
+ new_task->flags &= ~RSPAMD_TASK_FLAG_MIME;
+ }
new_task->sock = nfd;
- new_task->is_mime = ctx->is_mime;
memcpy (&new_task->client_addr, &addr, sizeof (addr));
worker->srv->stat->connections_count++;