]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Implement refcount for messages
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 18 Jul 2016 16:50:39 +0000 (17:50 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 18 Jul 2016 16:51:26 +0000 (17:51 +0100)
src/libutil/http.c
src/libutil/http.h
src/libutil/http_private.h

index f2d1675c4a2b8ae9d34168aa5cb17191173bf5a6..7aabba29647aec45c86f3e8fefa4377240f94dfe 100644 (file)
@@ -1243,7 +1243,7 @@ rspamd_http_connection_reset (struct rspamd_http_connection *conn)
                        priv->peer_key = msg->peer_key;
                        msg->peer_key = NULL;
                }
-               rspamd_http_message_free (msg);
+               rspamd_http_message_unref (msg);
                priv->msg = NULL;
        }
 
@@ -1290,19 +1290,15 @@ rspamd_http_connection_steal_msg (struct rspamd_http_connection *conn)
 }
 
 struct rspamd_http_message *
-rspamd_http_connection_copy_msg (struct rspamd_http_connection *conn)
+rspamd_http_connection_copy_msg (struct rspamd_http_message *msg)
 {
-       struct rspamd_http_connection_private *priv;
-       struct rspamd_http_message *new_msg, *msg;
+       struct rspamd_http_message *new_msg;
        struct rspamd_http_header *hdr, *nhdr, *thdr;
        const gchar *old_body;
        gsize old_len;
        struct stat st;
        union _rspamd_storage_u *storage;
 
-       priv = conn->priv;
-       msg = priv->msg;
-
        new_msg = rspamd_http_new_message (msg->type);
        new_msg->flags = msg->flags;
 
@@ -1316,12 +1312,12 @@ rspamd_http_connection_copy_msg (struct rspamd_http_connection *conn)
                        storage->shared.shm_fd = dup (msg->body_buf.c.shared.shm_fd);
 
                        if (storage->shared.shm_fd == -1) {
-                               rspamd_http_message_free (new_msg);
+                               rspamd_http_message_unref (new_msg);
                                return NULL;
                        }
 
                        if (fstat (storage->shared.shm_fd, &st) == -1) {
-                               rspamd_http_message_free (new_msg);
+                               rspamd_http_message_unref (new_msg);
                                return NULL;
                        }
 
@@ -1337,7 +1333,7 @@ rspamd_http_connection_copy_msg (struct rspamd_http_connection *conn)
                                        storage->shared.shm_fd, 0);
 
                        if (new_msg->body_buf.str == MAP_FAILED) {
-                               rspamd_http_message_free (new_msg);
+                               rspamd_http_message_unref (new_msg);
                                return NULL;
                        }
 
@@ -1350,7 +1346,7 @@ rspamd_http_connection_copy_msg (struct rspamd_http_connection *conn)
                        old_body = rspamd_http_message_get_body (msg, &old_len);
 
                        if (!rspamd_http_message_set_body (new_msg, old_body, old_len)) {
-                               rspamd_http_message_free (new_msg);
+                               rspamd_http_message_unref (new_msg);
                                return NULL;
                        }
                }
@@ -2120,6 +2116,8 @@ rspamd_http_new_message (enum http_parser_type type)
        new->type = type;
        new->method = HTTP_GET;
 
+       REF_INIT_RETAIN (new, rspamd_http_message_free);
+
        return new;
 }
 
@@ -2184,6 +2182,8 @@ rspamd_http_message_from_url (const gchar *url)
        msg->host = rspamd_fstring_new_init (host, pu.field_data[UF_HOST].len);
        msg->url = rspamd_fstring_append (msg->url, path, pathlen);
 
+       REF_INIT_RETAIN (msg, rspamd_http_message_free);
+
        return msg;
 }
 
@@ -3166,3 +3166,17 @@ rspamd_http_date_format (gchar *buf, gsize len, time_t time)
                        http_month[tms.tm_mon], tms.tm_year + 1900,
                        tms.tm_hour, tms.tm_min, tms.tm_sec);
 }
+
+struct rspamd_http_message *
+rspamd_http_message_ref (struct rspamd_http_message *msg)
+{
+       REF_RETAIN (msg);
+
+       return msg;
+}
+
+void
+rspamd_http_message_unref (struct rspamd_http_message *msg)
+{
+       REF_RELEASE (msg);
+}
index 140684b797e38883f30cd7ce58cfa53bec1ad5b1..2755638dba6ad7e3537aad0d0cf600fa4e99cec6 100644 (file)
@@ -268,7 +268,7 @@ struct rspamd_http_message * rspamd_http_connection_steal_msg (
  * @return
  */
 struct rspamd_http_message * rspamd_http_connection_copy_msg (
-               struct rspamd_http_connection *conn);
+               struct rspamd_http_message *msg);
 
 /**
  * Create new HTTP message
@@ -277,6 +277,17 @@ struct rspamd_http_message * rspamd_http_connection_copy_msg (
  */
 struct rspamd_http_message * rspamd_http_new_message (enum http_parser_type type);
 
+/**
+ * Increase refcount number for an HTTP message
+ * @param msg message to use
+ * @return
+ */
+struct rspamd_http_message * rspamd_http_message_ref (struct rspamd_http_message *msg);
+/**
+ * Decrease number of refcounts for http message
+ * @param msg
+ */
+void rspamd_http_message_unref (struct rspamd_http_message *msg);
 /**
  * Create HTTP message from URL
  * @param url
index 4cb2851d7cbb076010073896b2efde00819c917c..49575c03c2cc6df5594e136905fcfb186b956c7f 100644 (file)
@@ -69,6 +69,7 @@ struct rspamd_http_message {
        gint code;
        enum http_method method;
        gint flags;
+       ref_entry_t ref;
 };