From: Vsevolod Stakhov Date: Wed, 29 Oct 2014 14:10:57 +0000 (+0000) Subject: Fix surbl. X-Git-Tag: 0.7.3~29 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=809277294ff1f7e0887ece1c44735a203a5f5b96;p=rspamd.git Fix surbl. --- diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c index 9f961ab49..f57876c11 100644 --- a/src/plugins/surbl.c +++ b/src/plugins/surbl.c @@ -244,7 +244,7 @@ surbl_module_init (struct rspamd_config *cfg, struct module_ctx **ctx) surbl_module_ctx->tld2_file = NULL; surbl_module_ctx->whitelist_file = NULL; - surbl_module_ctx->redirectors_number = 0; + surbl_module_ctx->redirectors = NULL; surbl_module_ctx->redirector_trie = rspamd_trie_create (TRUE); surbl_module_ctx->redirector_ptrs = g_ptr_array_new (); @@ -320,35 +320,20 @@ surbl_module_config (struct rspamd_config *cfg) { i++; } - surbl_module_ctx->redirectors = rspamd_mempool_alloc0 ( - surbl_module_ctx->surbl_pool, - i * sizeof (struct redirector_upstream)); + surbl_module_ctx->redirectors = rspamd_upstreams_create (); + rspamd_mempool_add_destructor (surbl_module_ctx->surbl_pool, + (rspamd_mempool_destruct_t)rspamd_upstreams_destroy, + surbl_module_ctx->redirectors); idx = 0; LL_FOREACH (value, cur) { redir_val = ucl_obj_tostring (cur); - surbl_module_ctx->redirectors[idx].up.priority = 100; - if (!rspamd_parse_host_port_priority (surbl_module_ctx->surbl_pool, - redir_val, &surbl_module_ctx->redirectors[idx].addr, - &surbl_module_ctx->redirectors[idx].port, - &surbl_module_ctx->redirectors[idx].up.priority)) { - msg_warn ("invalid redirector definition: %s", redir_val); - } - else { - if (surbl_module_ctx->redirectors[idx].port != 0) { - surbl_module_ctx->redirectors[idx].name = - rspamd_mempool_strdup (surbl_module_ctx->surbl_pool, - redir_val); - msg_info ("add redirector %s", - surbl_module_ctx->redirectors[idx].name); - idx++; - } + if (rspamd_upstreams_add_upstream (surbl_module_ctx->redirectors, + redir_val, 80, NULL)) { + surbl_module_ctx->use_redirector = TRUE; } i++; } - surbl_module_ctx->redirectors_number = idx; - surbl_module_ctx->use_redirector = - (surbl_module_ctx->redirectors_number != 0); } if ((value = rspamd_config_get_module_opt (cfg, "surbl", @@ -547,7 +532,7 @@ surbl_module_reconfig (struct rspamd_config *cfg) surbl_module_ctx->tld2_file = NULL; surbl_module_ctx->whitelist_file = NULL; - surbl_module_ctx->redirectors_number = 0; + surbl_module_ctx->redirectors = NULL; surbl_module_ctx->redirector_trie = rspamd_trie_create (TRUE); surbl_module_ctx->redirector_hosts = g_hash_table_new (rspamd_strcase_hash, @@ -910,8 +895,8 @@ redirector_callback (gint fd, short what, void *arg) struri (param->url)); if (write (param->sock, url_buf, r) == -1) { msg_err ("write failed %s to %s", strerror ( - errno), param->redirector->name); - upstream_fail (¶m->redirector->up, param->task->tv.tv_sec); + errno), rspamd_upstream_name (param->redirector)); + rspamd_upstream_fail (param->redirector); remove_normal_event (param->task->s, free_redirector_session, param); @@ -923,8 +908,8 @@ redirector_callback (gint fd, short what, void *arg) msg_info ( "<%s> connection to redirector %s timed out while waiting for write", param->task->message_id, - param->redirector->name); - upstream_fail (¶m->redirector->up, param->task->tv.tv_sec); + rspamd_upstream_name (param->redirector)); + rspamd_upstream_fail (param->redirector); remove_normal_event (param->task->s, free_redirector_session, param); @@ -936,8 +921,8 @@ redirector_callback (gint fd, short what, void *arg) r = read (param->sock, url_buf, sizeof (url_buf) - 1); if (r <= 0) { msg_err ("read failed: %s from %s", strerror ( - errno), param->redirector->name); - upstream_fail (¶m->redirector->up, param->task->tv.tv_sec); + errno), rspamd_upstream_name (param->redirector)); + rspamd_upstream_fail (param->redirector); make_surbl_requests (param->url, param->task, param->suffix, @@ -980,16 +965,16 @@ redirector_callback (gint fd, short what, void *arg) } } } - upstream_ok (¶m->redirector->up, param->task->tv.tv_sec); + rspamd_upstream_ok (param->redirector); remove_normal_event (param->task->s, free_redirector_session, param); } else { msg_info ( "<%s> reading redirector %s timed out, while waiting for read", - param->redirector->name, + rspamd_upstream_name (param->redirector), param->task->message_id); - upstream_fail (¶m->redirector->up, param->task->tv.tv_sec); + rspamd_upstream_fail (param->redirector); remove_normal_event (param->task->s, free_redirector_session, param); } @@ -1005,24 +990,14 @@ register_redirector_call (struct uri *url, struct rspamd_task *task, gint s = -1; struct redirector_param *param; struct timeval *timeout; - struct redirector_upstream *selected; + struct upstream *selected; - selected = (struct redirector_upstream *)get_upstream_round_robin ( - surbl_module_ctx->redirectors, - surbl_module_ctx->redirectors_number, - sizeof (struct redirector_upstream), - task->tv.tv_sec, - DEFAULT_UPSTREAM_ERROR_TIME, - DEFAULT_UPSTREAM_DEAD_TIME, - DEFAULT_UPSTREAM_MAXERRORS); + selected = rspamd_upstream_get (surbl_module_ctx->redirectors, + RSPAMD_UPSTREAM_ROUND_ROBIN); if (selected) { - s = make_universal_socket (selected->addr, - selected->port, - SOCK_STREAM, - TRUE, - FALSE, - FALSE); + s = rspamd_inet_address_connect (rspamd_upstream_addr (selected), + SOCK_STREAM, TRUE); } if (s == -1) { @@ -1059,7 +1034,7 @@ register_redirector_call (struct uri *url, struct rspamd_task *task, "<%s> registered redirector call for %s to %s, according to rule: %s", task->message_id, struri (url), - selected->name, + rspamd_upstream_name (param->redirector), rule); } diff --git a/src/plugins/surbl.h b/src/plugins/surbl.h index bde284cf2..a224e895a 100644 --- a/src/plugins/surbl.h +++ b/src/plugins/surbl.h @@ -16,13 +16,6 @@ #define SURBL_OPTION_NOIP 1 #define MAX_LEVELS 10 -struct redirector_upstream { - struct upstream up; - gchar *addr; - guint16 port; - gchar *name; -}; - struct surbl_ctx { gint (*filter)(struct rspamd_task *task); guint16 weight; @@ -41,8 +34,7 @@ struct surbl_ctx { rspamd_trie_t *redirector_trie; GPtrArray *redirector_ptrs; guint use_redirector; - struct redirector_upstream *redirectors; - guint32 redirectors_number; + struct upstream_list *redirectors; rspamd_mempool_t *surbl_pool; }; @@ -63,7 +55,7 @@ struct dns_param { struct redirector_param { struct uri *url; struct rspamd_task *task; - struct redirector_upstream *redirector; + struct upstream *redirector; enum { STATE_CONNECT, STATE_READ