aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-03-11 15:19:15 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-03-11 15:19:15 +0000
commit82870c1b5aaa92a3fe0ce0c6ac5d5da8165f4a85 (patch)
treeb55d0f252f6c09ea4289c8f1f9c65643f94daba1 /src
parentfa0e3fbb9120b4b004aa497dbe5c5faa811b3a93 (diff)
downloadrspamd-82870c1b5aaa92a3fe0ce0c6ac5d5da8165f4a85.tar.gz
rspamd-82870c1b5aaa92a3fe0ce0c6ac5d5da8165f4a85.zip
Add support of spamc compatible output.
Diffstat (limited to 'src')
-rw-r--r--src/libserver/protocol.c53
-rw-r--r--src/libserver/task.h2
2 files changed, 52 insertions, 3 deletions
diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c
index 599d6e4ce..3a35efba3 100644
--- a/src/libserver/protocol.c
+++ b/src/libserver/protocol.c
@@ -429,6 +429,10 @@ rspamd_protocol_handle_request (struct rspamd_task *task,
ret = rspamd_protocol_handle_url (task, msg);
}
+ if (msg->flags & RSPAMD_HTTP_FLAG_SPAMC) {
+ task->is_spamc = TRUE;
+ }
+
return ret;
}
@@ -728,7 +732,7 @@ rspamd_metric_result_ucl (struct rspamd_task *task,
}
static void
-rspamd_ucl_tolegacy_output (struct rspamd_task *task,
+rspamd_ucl_torspamc_output (struct rspamd_task *task,
ucl_object_t *top,
GString *out)
{
@@ -786,6 +790,40 @@ rspamd_ucl_tolegacy_output (struct rspamd_task *task,
g_string_append_printf (out, "Message-ID: %s\r\n", task->message_id);
}
+static void
+rspamd_ucl_tospamc_output (struct rspamd_task *task,
+ ucl_object_t *top,
+ GString *out)
+{
+ const ucl_object_t *metric, *score,
+ *required_score, *is_spam, *elt;
+ ucl_object_iter_t iter = NULL;
+
+ metric = ucl_object_find_key (top, DEFAULT_METRIC);
+ if (metric != NULL) {
+ score = ucl_object_find_key (metric, "score");
+ required_score = ucl_object_find_key (metric, "required_score");
+ is_spam = ucl_object_find_key (metric, "is_spam");
+ g_string_append_printf (out,
+ "Spam: %s ; %.2f / %.2f\r\n\r\n",
+ ucl_object_toboolean (is_spam) ? "True" : "False",
+ ucl_object_todouble (score),
+ ucl_object_todouble (required_score));
+
+ while ((elt = ucl_iterate_object (metric, &iter, true)) != NULL) {
+ if (elt->type == UCL_OBJECT) {
+ g_string_append_printf (out, "%s,",
+ ucl_object_key (elt));
+ }
+ }
+ /* Ugly hack, but the whole spamc is ugly */
+ if (out->str[out->len - 1] == ',') {
+ g_string_truncate (out, out->len - 1);
+ g_string_append (out, CRLF);
+ }
+ }
+}
+
void
rspamd_protocol_http_reply (struct rspamd_http_message *msg,
struct rspamd_task *task)
@@ -855,11 +893,16 @@ rspamd_protocol_http_reply (struct rspamd_http_message *msg,
msg->body = g_string_sized_new (BUFSIZ);
- if (msg->method < HTTP_SYMBOLS) {
+ if (msg->method < HTTP_SYMBOLS && !task->is_spamc) {
rspamd_ucl_emit_gstring (top, UCL_EMIT_JSON_COMPACT, msg->body);
}
else {
- rspamd_ucl_tolegacy_output (task, top, msg->body);
+ if (task->is_spamc) {
+ rspamd_ucl_tospamc_output (task, top, msg->body);
+ }
+ else {
+ rspamd_ucl_torspamc_output (task, top, msg->body);
+ }
}
ucl_object_unref (top);
@@ -893,6 +936,10 @@ rspamd_protocol_write_reply (struct rspamd_task *task)
/* Turn compatibility on */
msg->method = HTTP_SYMBOLS;
}
+ if (task->is_spamc) {
+ msg->flags |= RSPAMD_HTTP_FLAG_SPAMC;
+ }
+
msg->date = time (NULL);
task->state = WRITING_REPLY;
diff --git a/src/libserver/task.h b/src/libserver/task.h
index 135e8bf92..917ef8bcc 100644
--- a/src/libserver/task.h
+++ b/src/libserver/task.h
@@ -75,11 +75,13 @@ struct rspamd_task {
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 */
gchar *helo; /**< helo header value */
gchar *queue_id; /**< queue id if specified */