]> source.dussan.org Git - rspamd.git/commitdiff
Add extended output format for URLs.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 25 Nov 2014 18:03:30 +0000 (18:03 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 25 Nov 2014 18:03:30 +0000 (18:03 +0000)
src/libserver/protocol.c
src/libserver/task.h
src/libserver/url.h

index f4e8da09d953d3d033c413e71950720cbac76ce6..d735d62fd217ed9461f6b679607b83be942cd073 100644 (file)
@@ -90,6 +90,7 @@
 #define QUEUE_ID_HEADER "Queue-ID"
 #define ERROR_HEADER "Error"
 #define USER_HEADER "User"
+#define URLS_HEADER "URL-Format"
 #define PASS_HEADER "Pass"
 #define JSON_HEADER "Json"
 #define HOSTNAME_HEADER "Hostname"
@@ -383,6 +384,13 @@ rspamd_protocol_handle_headers (struct rspamd_task *task,
                        if (g_ascii_strcasecmp (headern, USER_HEADER) == 0) {
                                task->user = h->value->str;
                        }
+                       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;
+                                       debug_task ("extended urls information");
+                               }
+                       }
                        else {
                                validh = FALSE;
                        }
@@ -485,9 +493,31 @@ urls_protocol_cb (gpointer key, gpointer value, gpointer ud)
 {
        struct tree_cb_data *cb = ud;
        struct uri *url = value;
-       ucl_object_t *obj;
+       ucl_object_t *obj, *elt;
+
+       if (!cb->task->extended_urls) {
+               obj = ucl_object_fromlstring (url->host, url->hostlen);
+       }
+       else {
+               obj = ucl_object_typed_new (UCL_OBJECT);
 
-       obj = ucl_object_fromlstring (url->host, url->hostlen);
+               elt = ucl_object_fromstring (url->string);
+               ucl_object_insert_key (obj, elt, "url", 0, false);
+
+               elt = ucl_object_fromlstring (url->host, url->hostlen);
+               ucl_object_insert_key (obj, elt, "host", 0, false);
+
+               elt = ucl_object_fromlstring (url->data, url->datalen);
+               ucl_object_insert_key (obj, elt, "data", 0, false);
+
+               if (url->surbl) {
+                       elt = ucl_object_fromlstring (url->surbl, url->surbllen);
+                       ucl_object_insert_key (obj, elt, "surbl", 0, false);
+               }
+
+               elt = ucl_object_frombool (url->is_phished);
+               ucl_object_insert_key (obj, elt, "phished", 0, false);
+       }
        DL_APPEND (cb->top->value.av, obj);
 
        if (cb->task->cfg->log_urls) {
index 2fd634e54357f49febcb7780da6355d815a2280b..1261dd1345dfc9f5131d12971c76c21901084ee5 100644 (file)
@@ -79,6 +79,7 @@ struct rspamd_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                                                     */
 
        gchar *helo;                                                    /**< helo header value                                                          */
        gchar *queue_id;                                                /**< queue id if specified                                                      */
index 5b508e056d2acf453f78bc53139986cd4b16c82f..c9700436b3c9b3805baa68bb6d484042b7ded0e2 100644 (file)
@@ -21,14 +21,10 @@ struct uri {
        gchar *password;
        gchar *host;
        gchar *port;
-       /* @data can contain both the path and query uri fields.
-        * It can never be NULL but can have zero length. */
        gchar *data;
        gchar *fragment;
-       /* @post can contain some special encoded form data, used internally
-        * to make form data handling more efficient. The data is marked by
-        * POST_CHAR in the uri string. */
        gchar *post;
+       gchar *surbl;
 
        struct uri *phished_url;
 
@@ -41,6 +37,7 @@ struct uri {
        guint portlen;
        guint datalen;
        guint fragmentlen;
+       guint surbllen;
 
        /* Flags */
        gboolean ipv6;  /* URI contains IPv6 host */