]> source.dussan.org Git - rspamd.git/commitdiff
Allow addresses to be allocated in rspamd_mempool.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 29 Oct 2014 11:26:08 +0000 (11:26 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 29 Oct 2014 11:26:08 +0000 (11:26 +0000)
src/libutil/addr.c
src/libutil/addr.h
src/libutil/upstream.c

index 6aeed21e9319214fc84932474dd7f1d17e898cea..3f5dd8e0efd4621a0fff49fa53d565e2d7efeb12 100644 (file)
@@ -93,7 +93,16 @@ rspamd_parse_inet_address (rspamd_inet_addr_t *target, const char *src)
 {
        gboolean ret = FALSE;
 
-       if (inet_pton (AF_INET6, src, &target->addr.s6.sin6_addr) == 1) {
+       if (src[0] == '/' || src[0] == '.') {
+               target->af = AF_UNIX;
+               target->slen = sizeof (target->addr.su);
+               rspamd_strlcpy (target->addr.su.sun_path, src,
+                               sizeof (target->addr.su.sun_path));
+#ifdef FREEBSD
+               target->addr.su.sun_len = SUN_LEN (addr);
+#endif
+       }
+       else if (inet_pton (AF_INET6, src, &target->addr.s6.sin6_addr) == 1) {
                target->af = AF_INET6;
                target->slen = sizeof (target->addr.s6);
                ret = TRUE;
@@ -189,7 +198,8 @@ rspamd_parse_host_port_priority_strv (gchar **tokens,
        guint *max_addrs,
        guint *priority,
        gchar **name,
-       guint default_port)
+       guint default_port,
+       rspamd_mempool_t *pool)
 {
        gchar *err_str, portbuf[8];
        const gchar *cur_tok, *cur_port;
@@ -279,7 +289,13 @@ rspamd_parse_host_port_priority_strv (gchar **tokens,
                        addr_cnt ++;
                }
 
-               *addr = g_new (rspamd_inet_addr_t, addr_cnt);
+               if (pool == NULL) {
+                       *addr = g_new (rspamd_inet_addr_t, addr_cnt);
+               }
+               else {
+                       *addr = rspamd_mempool_alloc (pool, addr_cnt *
+                                       sizeof (rspamd_inet_addr_t));
+               }
 
                cur = res;
                addr_cnt = 0;
@@ -305,7 +321,12 @@ rspamd_parse_host_port_priority_strv (gchar **tokens,
 
        /* Restore errno */
        if (name != NULL) {
-               *name = g_strdup (tokens[0]);
+               if (pool == NULL) {
+                       *name = g_strdup (tokens[0]);
+               }
+               else {
+                       *name = rspamd_mempool_strdup (pool, tokens[0]);
+               }
        }
        errno = saved_errno;
        return TRUE;
@@ -322,7 +343,8 @@ rspamd_parse_host_port_priority (
        guint *max_addrs,
        guint *priority,
        gchar **name,
-       guint default_port)
+       guint default_port,
+       rspamd_mempool_t *pool)
 {
        gchar **tokens;
        gboolean ret;
@@ -333,7 +355,7 @@ rspamd_parse_host_port_priority (
        }
 
        ret = rspamd_parse_host_port_priority_strv (tokens, addr, max_addrs,
-                       priority, name, default_port);
+                       priority, name, default_port, pool);
 
        g_strfreev (tokens);
 
@@ -345,8 +367,9 @@ rspamd_parse_host_port (const gchar *str,
        rspamd_inet_addr_t **addr,
        guint *max_addrs,
        gchar **name,
-       guint default_port)
+       guint default_port,
+       rspamd_mempool_t *pool)
 {
        return rspamd_parse_host_port_priority (str, addr, max_addrs, NULL,
-                       name, default_port);
+                       name, default_port, pool);
 }
index 5989b740ba8a2a4b45b0e807e88908d49554fd4a..16fe58a8df7f853a181d0ec391bb6621c899ea7e 100644 (file)
@@ -24,6 +24,7 @@
 #define ADDR_H_
 
 #include "config.h"
+#include "mem_pool.h"
 
 /**
  * Union that is used for storing sockaddrs
@@ -97,7 +98,7 @@ gint rspamd_accept_from_socket (gint sock, rspamd_inet_addr_t *addr);
 
 gboolean rspamd_parse_host_port_priority_strv (gchar **tokens,
        rspamd_inet_addr_t **addr, guint *max_addrs, guint *priority,
-       gchar **name, guint default_port);
+       gchar **name, guint default_port, rspamd_mempool_t *pool);
 
 /**
  * Parse host[:port[:priority]] line
@@ -108,7 +109,8 @@ gboolean rspamd_parse_host_port_priority_strv (gchar **tokens,
  */
 gboolean rspamd_parse_host_port_priority (const gchar *str,
                rspamd_inet_addr_t **addr, guint *max_addrs,
-               guint *priority, gchar **name, guint default_port);
+               guint *priority, gchar **name, guint default_port,
+               rspamd_mempool_t *pool);
 
 /**
  * Parse host:port line
@@ -118,7 +120,7 @@ gboolean rspamd_parse_host_port_priority (const gchar *str,
  */
 gboolean rspamd_parse_host_port (const gchar *str,
        rspamd_inet_addr_t **addr, guint *max_addrs,
-       gchar **name, guint default_port);
+       gchar **name, guint default_port, rspamd_mempool_t *pool);
 
 
 #endif /* ADDR_H_ */
index 0ed103111b7ad9efa91510e27b1eb14d85faa68a..43f2bcfcc2acb7a0c2f80e9e854cc2ad6c1a584f 100644 (file)
@@ -313,7 +313,7 @@ rspamd_upstreams_add_upstream (struct upstream_list *ups,
        up->addrs.count = default_max_addresses;
        if (!rspamd_parse_host_port_priority (str, &up->addrs.addr,
                        &up->addrs.count, &up->weight,
-                       &up->name, def_port)) {
+                       &up->name, def_port, NULL)) {
                g_slice_free1 (sizeof (*up), up);
                return FALSE;
        }