]> source.dussan.org Git - rspamd.git/commitdiff
* Add new map 'redirector_hosts_map' for determining which hosts should be checked...
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Tue, 28 Jul 2009 11:33:45 +0000 (15:33 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Tue, 28 Jul 2009 11:33:45 +0000 (15:33 +0400)
src/plugins/surbl.c
src/plugins/surbl.h
utils/redirector.pl.in

index 1b3ae8712c464273876aa32110d0ef018d9bf54f..e7b9daec87f3928662b7293f163c273908c989f3 100644 (file)
@@ -66,13 +66,14 @@ surbl_module_init (struct config_file *cfg, struct module_ctx **ctx)
        
        surbl_module_ctx->tld2_file = NULL;
        surbl_module_ctx->whitelist_file = NULL;
-       surbl_module_ctx->tld2 = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal);
-       /* Register destructors */
-       memory_pool_add_destructor (surbl_module_ctx->surbl_pool, (pool_destruct_func)g_hash_table_remove_all, surbl_module_ctx->tld2);
 
+       surbl_module_ctx->tld2 = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal);
+       surbl_module_ctx->redirector_hosts = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal);
        surbl_module_ctx->whitelist = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal);
        /* Register destructors */
-       memory_pool_add_destructor (surbl_module_ctx->surbl_pool, (pool_destruct_func)g_hash_table_remove_all, surbl_module_ctx->whitelist);
+       memory_pool_add_destructor (surbl_module_ctx->surbl_pool, (pool_destruct_func)g_hash_table_destroy, surbl_module_ctx->tld2);
+       memory_pool_add_destructor (surbl_module_ctx->surbl_pool, (pool_destruct_func)g_hash_table_destroy, surbl_module_ctx->whitelist);
+       memory_pool_add_destructor (surbl_module_ctx->surbl_pool, (pool_destruct_func)g_hash_table_destroy, surbl_module_ctx->redirector_hosts);
        
        memory_pool_add_destructor (surbl_module_ctx->surbl_pool, (pool_destruct_func)g_list_free, surbl_module_ctx->suffixes);
        memory_pool_add_destructor (surbl_module_ctx->surbl_pool, (pool_destruct_func)g_list_free, surbl_module_ctx->bits);
@@ -146,6 +147,12 @@ surbl_module_config (struct config_file *cfg)
        else {
                surbl_module_ctx->read_timeout = DEFAULT_REDIRECTOR_READ_TIMEOUT;
        }
+       if ((value = get_module_opt (cfg, "surbl", "redirector_hosts_map")) != NULL) {
+               add_map (value, read_host_list, fin_host_list, (void **)&surbl_module_ctx->redirector_hosts);
+       }
+       else {
+               surbl_module_ctx->read_timeout = DEFAULT_REDIRECTOR_READ_TIMEOUT;
+       }
        if ((value = get_module_opt (cfg, "surbl", "max_urls")) != NULL) {
                surbl_module_ctx->max_urls = atoi (value);
        }
@@ -251,7 +258,7 @@ format_surbl_request (memory_pool_t *pool, f_str_t *hostname, struct suffix_item
        GMatchInfo *info;
        char *result = NULL;
     int len, slen, r;
-       
+       
        if (suffix != NULL) {
                slen = strlen (suffix->suffix);
        }
@@ -282,8 +289,8 @@ format_surbl_request (memory_pool_t *pool, f_str_t *hostname, struct suffix_item
                        msg_debug ("format_surbl_request: url %s is whitelisted", result);
                        g_set_error (err,
                    SURBL_ERROR,                 /* error domain */
-                   WHITELIST_ERROR,                    /* error code */
-                   "URL is whitelisted: %s",   /* error message format string */
+                   WHITELIST_ERROR,                            /* error code */
+                   "URL is whitelisted: %s",   /* error message format string */
                    result);
 
                        return NULL;
@@ -327,8 +334,8 @@ format_surbl_request (memory_pool_t *pool, f_str_t *hostname, struct suffix_item
                                        msg_debug ("format_surbl_request: url %s is whitelisted", result);
                                        g_set_error (err,
                                                   SURBL_ERROR,                 /* error domain */
-                                                  WHITELIST_ERROR,             /* error code */
-                                                  "URL is whitelisted: %s",    /* error message format string */
+                                                  WHITELIST_ERROR,                             /* error code */
+                                                  "URL is whitelisted: %s",    /* error message format string */
                                                   result);
                                        return NULL;
                                }
@@ -353,8 +360,8 @@ format_surbl_request (memory_pool_t *pool, f_str_t *hostname, struct suffix_item
                                msg_debug ("format_surbl_request: url %s is whitelisted", result);
                                g_set_error (err,
                                           SURBL_ERROR,                 /* error domain */
-                                          WHITELIST_ERROR,             /* error code */
-                                          "URL is whitelisted: %s",    /* error message format string */
+                                          WHITELIST_ERROR,                             /* error code */
+                                          "URL is whitelisted: %s",    /* error message format string */
                                           result);
                                return NULL;
                        }
@@ -734,12 +741,24 @@ tree_url_callback (gpointer key, gpointer value, void *data)
 {
        struct redirector_param *param = data;
        struct uri *url = value;
+       f_str_t f;
+       char *urlstr, *host_end;
+       GError *err = NULL;
 
        msg_debug ("surbl_test_url: check url %s", struri (url));
 
+       
        if (surbl_module_ctx->use_redirector) {
-               register_redirector_call (url, param->task, param->tree, param->suffix);
-               param->task->save.saved++;
+               f.begin = url->host;
+               f.len = url->hostlen;
+               if ((urlstr = format_surbl_request (param->task->task_pool, &f, NULL, &host_end, FALSE, &err)) != NULL) {
+                       if (g_hash_table_lookup (surbl_module_ctx->redirector_hosts, urlstr) != NULL) {
+                               register_redirector_call (url, param->task, param->tree, param->suffix);
+                               param->task->save.saved++;
+                               return FALSE;
+                       }
+               }
+               make_surbl_requests (url, param->task, param->tree, param->suffix);
        }
        else {
                if (param->task->worker->srv->cfg->memcached_servers_num > 0) {
index cfe17b4046b099b08174eeca7371d6e72a413727..ea7f9359b940fca0878f423ee20faccf9de9b9ab 100644 (file)
@@ -32,6 +32,7 @@ struct surbl_ctx {
        const char *whitelist_file;
        GHashTable *tld2;
        GHashTable *whitelist;
+       GHashTable *redirector_hosts;
        unsigned use_redirector;
        memory_pool_t *surbl_pool;
     GRegex *extract_hoster_regexp;
index 0fc79beea37f7e82858187701170abcc0419fd9d..b67f70f9c837d479ad6e71a62e6a74cad3ecce18 100755 (executable)
@@ -43,7 +43,6 @@ our %cfg = (
     do_log  =>  0,
     debug   =>  0,
     check_regexp => 'http://[^/]+/',
-    check_domains =>  [ 'narod.ru', 'test.ru' ],
     memcached_servers => [ { address => 'localhost:11211', weight => 2.5 }, 
                           ],
     digest_bits => 256,