]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Insert redirected URL to the urls list
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 7 Apr 2016 11:14:01 +0000 (12:14 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 7 Apr 2016 11:14:01 +0000 (12:14 +0100)
src/libserver/protocol.c
src/libserver/url.h
src/plugins/surbl.c

index 35c912f59ef5159d157676483f715d3d792e1e3e..e32dfc6e57698c26a548c7473ad6c91c2c8e2cc9 100644 (file)
@@ -595,6 +595,39 @@ struct tree_cb_data {
        struct rspamd_task *task;
 };
 
+static ucl_object_t *
+rspamd_protocol_extended_url (struct rspamd_url *url)
+{
+       ucl_object_t *obj, *elt;
+
+       obj = ucl_object_typed_new (UCL_OBJECT);
+
+       elt = ucl_object_fromlstring (url->string, url->urllen);
+       ucl_object_insert_key (obj, elt, "url", 0, false);
+
+       if (url->surbllen > 0) {
+               elt = ucl_object_fromlstring (url->surbl, url->surbllen);
+               ucl_object_insert_key (obj, elt, "surbl", 0, false);
+       }
+       if (url->hostlen > 0) {
+               elt = ucl_object_fromlstring (url->host, url->hostlen);
+               ucl_object_insert_key (obj, elt, "host", 0, false);
+       }
+
+       elt = ucl_object_frombool (url->flags & RSPAMD_URL_FLAG_PHISHED);
+       ucl_object_insert_key (obj, elt, "phished", 0, false);
+
+       elt = ucl_object_frombool (url->flags & RSPAMD_URL_FLAG_REDIRECTED);
+       ucl_object_insert_key (obj, elt, "redirected", 0, false);
+
+       if (url->phished_url) {
+               elt = rspamd_protocol_extended_url (url->phished_url);
+               ucl_object_insert_key (obj, elt, "orig_url", 0, false);
+       }
+
+       return obj;
+}
+
 /*
  * Callback for writing urls
  */
@@ -603,7 +636,7 @@ urls_protocol_cb (gpointer key, gpointer value, gpointer ud)
 {
        struct tree_cb_data *cb = ud;
        struct rspamd_url *url = value;
-       ucl_object_t *obj, *elt;
+       ucl_object_t *obj;
        struct rspamd_task *task = cb->task;
        const gchar *user_field = "unknown";
        gboolean has_user = FALSE;
@@ -612,22 +645,7 @@ urls_protocol_cb (gpointer key, gpointer value, gpointer ud)
                obj = ucl_object_fromlstring (url->string, url->urllen);
        }
        else {
-               obj = ucl_object_typed_new (UCL_OBJECT);
-
-               elt = ucl_object_fromlstring (url->string, url->urllen);
-               ucl_object_insert_key (obj, elt, "url", 0, false);
-
-               if (url->surbllen > 0) {
-                       elt = ucl_object_fromlstring (url->surbl, url->surbllen);
-                       ucl_object_insert_key (obj, elt, "surbl", 0, false);
-               }
-               if (url->hostlen > 0) {
-                       elt = ucl_object_fromlstring (url->host, url->hostlen);
-                       ucl_object_insert_key (obj, elt, "host", 0, false);
-               }
-
-               elt = ucl_object_frombool (url->flags & RSPAMD_URL_FLAG_PHISHED);
-               ucl_object_insert_key (obj, elt, "phished", 0, false);
+               obj = rspamd_protocol_extended_url (url);
        }
 
        ucl_array_append (cb->top, obj);
index 4d38e3d79207cdc9d5267ec3434bb99c4718894f..7dfcb05af3fe70c6f8facbd4ef32eb9409dc0c08 100644 (file)
@@ -13,6 +13,7 @@ enum rspamd_url_flags {
        RSPAMD_URL_FLAG_PHISHED = 1 << 0,
        RSPAMD_URL_FLAG_NUMERIC = 1 << 1,
        RSPAMD_URL_FLAG_OBSCURED = 1 << 2,
+       RSPAMD_URL_FLAG_REDIRECTED = 1 << 3,
 };
 
 struct rspamd_url {
index dcf69f8f2ff4197bedf73bc94601a18321328075..ad2c3be9cf097d18ef9081fa443545817a083b08 100644 (file)
@@ -1281,6 +1281,13 @@ surbl_redirector_finish (struct rspamd_http_connection *conn,
                                        task->task_pool);
 
                        if (r == URI_ERRNO_OK) {
+                               if (!g_hash_table_lookup (task->urls, redirected_url)) {
+                                       g_hash_table_insert (task->urls, redirected_url,
+                                                       redirected_url);
+                                       redirected_url->phished_url = param->url;
+                                       redirected_url->flags |= RSPAMD_URL_FLAG_REDIRECTED;
+                               }
+
                                make_surbl_requests (redirected_url,
                                                param->task,
                                                param->suffix,