diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2013-06-01 15:52:11 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2013-06-01 15:52:11 +0100 |
commit | 37845898cbf779c7d3b5664997d0db48968c929c (patch) | |
tree | a190b5ee9d152ba60135136bbe8108d7da81166c /src/plugins | |
parent | 8cc2aee8859731ee2fe280070423f79e7d009ca3 (diff) | |
download | rspamd-37845898cbf779c7d3b5664997d0db48968c929c.tar.gz rspamd-37845898cbf779c7d3b5664997d0db48968c929c.zip |
Rework socket creation logic to support both ipv4 and ipv6 sockets.
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/fuzzy_check.c | 52 | ||||
-rw-r--r-- | src/plugins/surbl.c | 5 | ||||
-rw-r--r-- | src/plugins/surbl.h | 2 |
3 files changed, 15 insertions, 44 deletions
diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index 984163858..d16bc94b0 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -62,7 +62,7 @@ struct storage_server { struct upstream up; gchar *name; - struct in_addr addr; + gchar *addr; guint16 port; }; @@ -237,10 +237,9 @@ fuzzy_check_content_type (GMimeContentType *type) static void parse_servers_string (gchar *str) { - gchar **strvec, *p, portbuf[6], *name; - gint num, i, j, port; - struct hostent *hent; - struct in_addr addr; + gchar **strvec; + gint i, num; + struct storage_server *cur; strvec = g_strsplit_set (str, ",", 0); num = g_strv_length (strvec); @@ -250,43 +249,14 @@ parse_servers_string (gchar *str) for (i = 0; i < num; i++) { g_strstrip (strvec[i]); - if ((p = strchr (strvec[i], ':')) != NULL) { - j = 0; - p++; - while (g_ascii_isdigit (*(p + j)) && j < (gint)sizeof (portbuf) - 1) { - portbuf[j] = *(p + j); - j++; + cur = &fuzzy_module_ctx->servers[fuzzy_module_ctx->servers_num]; + if (parse_host_port (fuzzy_module_ctx->fuzzy_pool, strvec[i], &cur->addr, &cur->port)) { + if (cur->port == 0) { + cur->port = DEFAULT_PORT; } - portbuf[j] = '\0'; - port = atoi (portbuf); - } - else { - /* Default http port */ - port = DEFAULT_PORT; - } - name = memory_pool_alloc (fuzzy_module_ctx->fuzzy_pool, p - strvec[i]); - rspamd_strlcpy (name, strvec[i], p - strvec[i]); - if (!inet_aton (name, &addr)) { - /* Resolve using dns */ - hent = gethostbyname (name); - if (hent == NULL) { - msg_info ("cannot resolve: %s", name); - continue; - } - else { - fuzzy_module_ctx->servers[fuzzy_module_ctx->servers_num].port = port; - fuzzy_module_ctx->servers[fuzzy_module_ctx->servers_num].name = name; - memcpy (&fuzzy_module_ctx->servers[fuzzy_module_ctx->servers_num].addr, hent->h_addr, sizeof (struct in_addr)); - fuzzy_module_ctx->servers_num++; - } - } - else { - fuzzy_module_ctx->servers[fuzzy_module_ctx->servers_num].port = port; - fuzzy_module_ctx->servers[fuzzy_module_ctx->servers_num].name = name; - memcpy (&fuzzy_module_ctx->servers[fuzzy_module_ctx->servers_num].addr, &addr, sizeof (struct in_addr)); + cur->name = memory_pool_strdup (fuzzy_module_ctx->fuzzy_pool, strvec[i]); fuzzy_module_ctx->servers_num++; } - } g_strfreev (strvec); @@ -653,7 +623,7 @@ register_fuzzy_call (struct worker_task *task, fuzzy_hash_t *h) DEFAULT_UPSTREAM_ERROR_TIME, DEFAULT_UPSTREAM_DEAD_TIME, DEFAULT_UPSTREAM_MAXERRORS, h->hash_pipe, sizeof (h->hash_pipe)); #endif if (selected) { - if ((sock = make_udp_socket (&selected->addr, selected->port, FALSE, TRUE)) == -1) { + if ((sock = make_universal_socket (selected->addr, selected->port, SOCK_DGRAM, TRUE, FALSE, FALSE)) == -1) { msg_warn ("cannot connect to %s, %d, %s", selected->name, errno, strerror (errno)); } else { @@ -782,7 +752,7 @@ register_fuzzy_controller_call (struct controller_session *session, struct worke #endif if (selected) { /* Create UDP socket */ - if ((sock = make_udp_socket (&selected->addr, selected->port, FALSE, TRUE)) == -1) { + if ((sock = make_universal_socket (selected->addr, selected->port, SOCK_DGRAM, TRUE, FALSE, FALSE)) == -1) { msg_warn ("cannot connect to %s, %d, %s", selected->name, errno, strerror (errno)); session->state = STATE_REPLY; if (session->restful) { diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c index 57bd257c7..1491b1b62 100644 --- a/src/plugins/surbl.c +++ b/src/plugins/surbl.c @@ -313,7 +313,8 @@ surbl_module_config (struct config_file *cfg) idx = 0; i --; for (; i >= 0; i --) { - if (! parse_host_port (strvec[i], &surbl_module_ctx->redirectors[idx].ina, + if (! parse_host_port (surbl_module_ctx->surbl_pool, + strvec[i], &surbl_module_ctx->redirectors[idx].addr, &surbl_module_ctx->redirectors[idx].port)) { msg_warn ("invalid redirector definition: %s", strvec[idx]); } @@ -922,7 +923,7 @@ register_redirector_call (struct uri *url, struct worker_task *task, DEFAULT_UPSTREAM_DEAD_TIME, DEFAULT_UPSTREAM_MAXERRORS); if (selected) { - s = make_tcp_socket (&selected->ina, selected->port, FALSE, TRUE); + s = make_universal_socket (selected->addr, selected->port, SOCK_STREAM, TRUE, FALSE, FALSE); } if (s == -1) { diff --git a/src/plugins/surbl.h b/src/plugins/surbl.h index 950e55bcb..7a2ed58b5 100644 --- a/src/plugins/surbl.h +++ b/src/plugins/surbl.h @@ -20,7 +20,7 @@ struct redirector_upstream { struct upstream up; - struct in_addr ina; + gchar *addr; guint16 port; gchar *name; }; |