aboutsummaryrefslogtreecommitdiffstats
path: root/src/protocol.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2011-01-19 20:07:09 +0300
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2011-01-19 20:07:09 +0300
commit17d7b071296c283ea04759dc26a640c77cf3c08d (patch)
tree1cc62375f830d4867c5c2a04a806865c3360eaf9 /src/protocol.c
parent87bbf31b5764f696d07632a8b06e6da25d057654 (diff)
downloadrspamd-17d7b071296c283ea04759dc26a640c77cf3c08d.tar.gz
rspamd-17d7b071296c283ea04759dc26a640c77cf3c08d.zip
Always write symbols to log.
Diffstat (limited to 'src/protocol.c')
-rw-r--r--src/protocol.c73
1 files changed, 42 insertions, 31 deletions
diff --git a/src/protocol.c b/src/protocol.c
index a9c6176b8..5e3c0fb04 100644
--- a/src/protocol.c
+++ b/src/protocol.c
@@ -445,6 +445,7 @@ struct metric_callback_data {
gchar *symbols_buf;
gint symbols_size;
gboolean alive;
+ gboolean report;
};
static void
@@ -559,43 +560,43 @@ metric_symbols_callback (gpointer key, gpointer value, void *user_data)
if (! cd->alive) {
return;
}
-
- if (s->options) {
- if (task->proto_ver >= 12) {
- r = rspamd_snprintf (outbuf, OUTBUFSIZ, "Symbol: %s(%.2f); ", (gchar *)key, s->score);
+ if (cd->task->cmd == CMD_SYMBOLS) {
+ if (s->options) {
+ if (task->proto_ver >= 12) {
+ r = rspamd_snprintf (outbuf, OUTBUFSIZ, "Symbol: %s(%.2f); ", (gchar *)key, s->score);
+ }
+ else {
+ r = rspamd_snprintf (outbuf, OUTBUFSIZ, "Symbol: %s; ", (gchar *)key);
+ }
+ cur = s->options;
+ while (cur) {
+ if (g_list_next (cur)) {
+ r += rspamd_snprintf (outbuf + r, OUTBUFSIZ - r, "%s,", (gchar *)cur->data);
+ }
+ else {
+ r += rspamd_snprintf (outbuf + r, OUTBUFSIZ - r, "%s" CRLF, (gchar *)cur->data);
+ }
+ cur = g_list_next (cur);
+ }
+ /* End line with CRLF strictly */
+ if (r >= OUTBUFSIZ - 1) {
+ outbuf[OUTBUFSIZ - 2] = '\r';
+ outbuf[OUTBUFSIZ - 1] = '\n';
+ }
}
else {
- r = rspamd_snprintf (outbuf, OUTBUFSIZ, "Symbol: %s; ", (gchar *)key);
- }
- cur = s->options;
- while (cur) {
- if (g_list_next (cur)) {
- r += rspamd_snprintf (outbuf + r, OUTBUFSIZ - r, "%s,", (gchar *)cur->data);
+ if (task->proto_ver >= 12) {
+ r = rspamd_snprintf (outbuf, OUTBUFSIZ, "Symbol: %s(%.2f)" CRLF, (gchar *)key, s->score);
}
else {
- r += rspamd_snprintf (outbuf + r, OUTBUFSIZ - r, "%s" CRLF, (gchar *)cur->data);
+ r = rspamd_snprintf (outbuf, OUTBUFSIZ, "Symbol: %s" CRLF, (gchar *)key);
}
- cur = g_list_next (cur);
- }
- /* End line with CRLF strictly */
- if (r >= OUTBUFSIZ - 1) {
- outbuf[OUTBUFSIZ - 2] = '\r';
- outbuf[OUTBUFSIZ - 1] = '\n';
}
- }
- else {
- if (task->proto_ver >= 12) {
- r = rspamd_snprintf (outbuf, OUTBUFSIZ, "Symbol: %s(%.2f)" CRLF, (gchar *)key, s->score);
- }
- else {
- r = rspamd_snprintf (outbuf, OUTBUFSIZ, "Symbol: %s" CRLF, (gchar *)key);
+ if (! rspamd_dispatcher_write (task->dispatcher, outbuf, r, FALSE, FALSE)) {
+ cd->alive = FALSE;
}
}
cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "%s,", (gchar *)key);
-
- if (! rspamd_dispatcher_write (task->dispatcher, outbuf, r, FALSE, FALSE)) {
- cd->alive = FALSE;
- }
}
static gboolean
@@ -609,12 +610,16 @@ show_metric_symbols (struct metric_result *metric_res, struct metric_callback_da
cur = symbols;
while (cur) {
if (g_list_next (cur) != NULL) {
- r += rspamd_snprintf (cd->symbols_buf + r, cd->symbols_size - r, "%s,", (gchar *)cur->data);
+ if (cd->task->cmd == CMD_SYMBOLS) {
+ r += rspamd_snprintf (cd->symbols_buf + r, cd->symbols_size - r, "%s,", (gchar *)cur->data);
+ }
cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset,
"%s,", (gchar *)cur->data);
}
else {
- r += rspamd_snprintf (cd->symbols_buf + r, cd->symbols_size - r, "%s" CRLF, (gchar *)cur->data);
+ if (cd->task->cmd == CMD_SYMBOLS) {
+ r += rspamd_snprintf (cd->symbols_buf + r, cd->symbols_size - r, "%s" CRLF, (gchar *)cur->data);
+ }
cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset,
"%s", (gchar *)cur->data);
}
@@ -745,7 +750,7 @@ show_metric_result (gpointer metric_name, gpointer metric_value, void *user_data
return;
}
- if (task->cmd == CMD_SYMBOLS && metric_value != NULL) {
+ if (metric_value != NULL) {
if (! show_metric_symbols (metric_res, cd)) {
cd->alive = FALSE;
return;
@@ -804,6 +809,7 @@ write_check_reply (struct worker_task *task)
"user: %s, ", task->user);
}
cd.alive = TRUE;
+ cd.report = FALSE;
if (task->proto == SPAMC_PROTO) {
/* Ignore metrics, just write report for 'default' metric */
@@ -875,6 +881,11 @@ write_check_reply (struct worker_task *task)
}
if (task->cmd == CMD_REPORT || task->cmd == CMD_REPORT_IFSPAM) {
+ cd.report = TRUE;
+ g_hash_table_foreach (task->results, show_metric_result, &cd);
+ if (!cd.alive) {
+ return FALSE;
+ }
if (default_score >= default_required_score) {
r = rspamd_snprintf (outbuf, sizeof (outbuf), CONTENT_LENGTH_HEADER ": %d" CRLF CRLF
"This message is likely spam" CRLF, sizeof ("This message is likely spam" CRLF) - 1);