diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-01-24 23:23:37 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-01-24 23:23:37 +0000 |
commit | d100debaa37a7477fa06bb95ca5087ed70f99cba (patch) | |
tree | c913d1c541646f68b95d444f0b0ce00218bf8fc6 /src/libserver/cfg_utils.c | |
parent | 1678075da31b6939396a95b9aa2c93c90ee7485b (diff) | |
download | rspamd-d100debaa37a7477fa06bb95ca5087ed70f99cba.tar.gz rspamd-d100debaa37a7477fa06bb95ca5087ed70f99cba.zip |
Rework parsing of IP addresses
Diffstat (limited to 'src/libserver/cfg_utils.c')
-rw-r--r-- | src/libserver/cfg_utils.c | 48 |
1 files changed, 5 insertions, 43 deletions
diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c index 32651dd20..475850f95 100644 --- a/src/libserver/cfg_utils.c +++ b/src/libserver/cfg_utils.c @@ -63,59 +63,23 @@ rspamd_parse_bind_line (struct rspamd_config *cfg, const gchar *str) { struct rspamd_worker_bind_conf *cnf; - gchar **tokens, *err; + gchar *err; gboolean ret = TRUE; if (str == NULL) { return FALSE; } - if (str[0] == '[') { - /* This is an ipv6 address */ - gsize len, ntok; - const gchar *start, *ip_pos; - - start = str + 1; - - len = strcspn (start, "]"); - if (start[len] != ']') { - return FALSE; - } - - ip_pos = start; - start += len + 1; - ntok = 1; - - if (*start == ':') { - ntok = 2; - start ++; - } - - tokens = g_malloc_n (ntok + 1, sizeof (gchar *)); - tokens[ntok] = NULL; - tokens[0] = g_malloc (len + 1); - rspamd_strlcpy (tokens[0], ip_pos, len + 1); - - if (ntok > 1) { - tokens[1] = g_strdup (start); - } - } - else { - tokens = g_strsplit_set (str, ":", 0); - } - if (!tokens || !tokens[0]) { - return FALSE; - } - cnf = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (struct rspamd_worker_bind_conf)); cnf->cnt = 1024; - if (strcmp (tokens[0], "systemd") == 0) { + + if (strcmp (str, "systemd") == 0) { /* The actual socket will be passed by systemd environment */ cnf->is_systemd = TRUE; - cnf->cnt = strtoul (tokens[1], &err, 10); + cnf->cnt = strtoul (str, &err, 10); cnf->addrs = NULL; if (err == NULL || *err == '\0') { @@ -128,7 +92,7 @@ rspamd_parse_bind_line (struct rspamd_config *cfg, } } else { - if (!rspamd_parse_host_port_priority_strv (tokens, &cnf->addrs, + if (!rspamd_parse_host_port_priority (str, &cnf->addrs, NULL, &cnf->name, DEFAULT_BIND_PORT, cfg->cfg_pool)) { msg_err_config ("cannot parse bind line: %s", str); ret = FALSE; @@ -139,8 +103,6 @@ rspamd_parse_bind_line (struct rspamd_config *cfg, } } - g_strfreev (tokens); - return ret; } |