diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-10-29 11:26:08 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-10-29 11:26:08 +0000 |
commit | f58fb61175aa8616b307ec29e919f5556d42777d (patch) | |
tree | 03057c6dcb1e3a6e5972afab958a11c290b31ae2 | |
parent | db1fd009599ba9c60f569b2ce5a99c373ad9f478 (diff) | |
download | rspamd-f58fb61175aa8616b307ec29e919f5556d42777d.tar.gz rspamd-f58fb61175aa8616b307ec29e919f5556d42777d.zip |
Allow addresses to be allocated in rspamd_mempool.
-rw-r--r-- | src/libutil/addr.c | 39 | ||||
-rw-r--r-- | src/libutil/addr.h | 8 | ||||
-rw-r--r-- | src/libutil/upstream.c | 2 |
3 files changed, 37 insertions, 12 deletions
diff --git a/src/libutil/addr.c b/src/libutil/addr.c index 6aeed21e9..3f5dd8e0e 100644 --- a/src/libutil/addr.c +++ b/src/libutil/addr.c @@ -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); } diff --git a/src/libutil/addr.h b/src/libutil/addr.h index 5989b740b..16fe58a8d 100644 --- a/src/libutil/addr.h +++ b/src/libutil/addr.h @@ -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_ */ diff --git a/src/libutil/upstream.c b/src/libutil/upstream.c index 0ed103111..43f2bcfcc 100644 --- a/src/libutil/upstream.c +++ b/src/libutil/upstream.c @@ -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; } |