aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil/addr.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2014-10-29 11:26:08 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2014-10-29 11:26:08 +0000
commitf58fb61175aa8616b307ec29e919f5556d42777d (patch)
tree03057c6dcb1e3a6e5972afab958a11c290b31ae2 /src/libutil/addr.c
parentdb1fd009599ba9c60f569b2ce5a99c373ad9f478 (diff)
downloadrspamd-f58fb61175aa8616b307ec29e919f5556d42777d.tar.gz
rspamd-f58fb61175aa8616b307ec29e919f5556d42777d.zip
Allow addresses to be allocated in rspamd_mempool.
Diffstat (limited to 'src/libutil/addr.c')
-rw-r--r--src/libutil/addr.c39
1 files changed, 31 insertions, 8 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);
}