void
rspamd_map_helper_destroy_hash (struct rspamd_hash_map_helper *r)
{
+ if (r == NULL) {
+ return;
+ }
+
kh_destroy (rspamd_map_hash, r->htb);
rspamd_mempool_delete (r->pool);
}
void
rspamd_map_helper_destroy_radix (struct rspamd_radix_map_helper *r)
{
+ if (r == NULL) {
+ return;
+ }
+
kh_destroy (rspamd_map_hash, r->htb);
rspamd_mempool_delete (r->pool);
}
rspamd_regexp_t *re;
guint i;
+ if (!re_map) {
+ return;
+ }
+
for (i = 0; i < re_map->regexps->len; i ++) {
re = g_ptr_array_index (re_map->regexps, i);
rspamd_regexp_unref (re);
khiter_t k;
struct rspamd_map_helper_value *val;
+ if (map == NULL) {
+ return NULL;
+ }
+
k = kh_get (rspamd_map_hash, map->htb, in);
if (k != kh_end (map->htb)) {
{
struct rspamd_map_helper_value *val;
+ if (map == NULL) {
+ return NULL;
+ }
+
val = (struct rspamd_map_helper_value *)radix_find_compressed (map->trie,
in, inlen);
{
struct rspamd_map_helper_value *val;
+ if (map == NULL) {
+ return NULL;
+ }
+
val = (struct rspamd_map_helper_value *)radix_find_compressed_addr (map->trie, addr);
if (val != (gconstpointer)RADIX_NO_VALUE) {
#include "libserver/dkim.h"
#include "libutil/hash.h"
#include "libutil/map.h"
+#include "libutil/map_helpers.h"
#include "rspamd.h"
#include "utlist.h"
#include "lua/lua_common.h"
const gchar *symbol_permfail;
rspamd_mempool_t *dkim_pool;
- radix_compressed_t *whitelist_ip;
- GHashTable *dkim_domains;
+ struct rspamd_radix_map_helper *whitelist_ip;
+ struct rspamd_hash_map_helper *dkim_domains;
guint strict_multiplier;
guint time_jitter;
rspamd_lru_hash_t *dkim_hash;
}
lua_pop (cfg->lua_state, 1); /* Remove global function */
- dkim_module_ctx->whitelist_ip = radix_create_compressed ();
+ dkim_module_ctx->whitelist_ip = NULL;
if ((value =
rspamd_config_get_module_opt (cfg, "options", "check_local")) != NULL) {
rspamd_config_radix_from_ucl (cfg, value, "DKIM whitelist",
&dkim_module_ctx->whitelist_ip, NULL);
+ rspamd_mempool_add_destructor (dkim_module_ctx->dkim_pool,
+ (rspamd_mempool_destruct_t)rspamd_map_helper_destroy_radix,
+ dkim_module_ctx->whitelist_ip);
+
}
if ((value =
ucl_object_tostring (value));
}
else {
+ rspamd_mempool_add_destructor (dkim_module_ctx->dkim_pool,
+ (rspamd_mempool_destruct_t)rspamd_map_helper_destroy_hash,
+ dkim_module_ctx->dkim_domains);
got_trusted = TRUE;
}
}
ucl_object_tostring (value));
}
else {
+ rspamd_mempool_add_destructor (dkim_module_ctx->dkim_pool,
+ (rspamd_mempool_destruct_t)rspamd_map_helper_destroy_hash,
+ dkim_module_ctx->dkim_domains);
got_trusted = TRUE;
}
}
saved_ctx = dkim_module_ctx->ctx;
rspamd_mempool_delete (dkim_module_ctx->dkim_pool);
- radix_destroy_compressed (dkim_module_ctx->whitelist_ip);
-
- if (dkim_module_ctx->dkim_domains) {
- g_hash_table_destroy (dkim_module_ctx->dkim_domains);
- }
if (dkim_module_ctx->dkim_hash) {
rspamd_lru_hash_destroy (dkim_module_ctx->dkim_hash);
if (dkim_module_ctx->dkim_domains != NULL) {
/* Perform strict check */
if ((strict_value =
- g_hash_table_lookup (dkim_module_ctx->dkim_domains,
+ rspamd_match_hash_map (dkim_module_ctx->dkim_domains,
rspamd_dkim_get_domain (cur->ctx))) != NULL) {
if (!dkim_module_parse_strict (strict_value, &cur->mult_allow,
&cur->mult_deny)) {
return;
}
/* Check whitelist */
- if (radix_find_compressed_addr (dkim_module_ctx->whitelist_ip,
- task->from_addr) != RADIX_NO_VALUE) {
+ if (rspamd_match_radix_map_addr (dkim_module_ctx->whitelist_ip,
+ task->from_addr) != NULL) {
msg_info_task ("skip DKIM checks for whitelisted address");
return;
}
if (dkim_module_ctx->trusted_only &&
(dkim_module_ctx->dkim_domains == NULL ||
- g_hash_table_lookup (dkim_module_ctx->dkim_domains,
+ rspamd_match_hash_map (dkim_module_ctx->dkim_domains,
rspamd_dkim_get_domain (ctx)) == NULL)) {
msg_debug_task ("skip dkim check for %s domain",
rspamd_dkim_get_domain (ctx));
#include "config.h"
#include "libmime/message.h"
#include "libutil/map.h"
+#include "libutil/map_helpers.h"
#include "libmime/images.h"
#include "libserver/worker_util.h"
#include "fuzzy_wire.h"
gboolean fuzzy_images;
gboolean short_text_direct_hash;
gint learn_condition_cb;
- GHashTable *skip_map;
+ struct rspamd_hash_map_helper *skip_map;
};
struct fuzzy_ctx {
rspamd_map_add_from_ucl (cfg, value,
"Fuzzy hashes whitelist", rspamd_kv_list_read, rspamd_kv_list_fin,
(void **)&rule->skip_map);
+ rspamd_mempool_add_destructor (fuzzy_module_ctx->fuzzy_pool,
+ (rspamd_mempool_destruct_t)rspamd_map_helper_destroy_radix,
+ rule->skip_map);
}
else {
rule->skip_map = NULL;
rspamd_encode_hex_buf (cmd->digest, sizeof (cmd->digest),
hexbuf, sizeof (hexbuf) - 1);
hexbuf[sizeof (hexbuf) - 1] = '\0';
- if (g_hash_table_lookup (session->rule->skip_map, hexbuf)) {
+ if (rspamd_match_hash_map (session->rule->skip_map, hexbuf)) {
return;
}
}
#include "config.h"
#include "libmime/message.h"
#include "libutil/map.h"
+#include "libutil/map_helpers.h"
#include "rspamd.h"
-#include "surbl.h"
#include "utlist.h"
+#include "multipattern.h"
+#include "monitored.h"
#include "libserver/html.h"
#include "libutil/http_private.h"
#include "unix-std.h"
INIT_LOG_MODULE(surbl)
+#define DEFAULT_SURBL_WEIGHT 10
+#define DEFAULT_REDIRECTOR_READ_TIMEOUT 5.0
+#define DEFAULT_SURBL_SYMBOL "SURBL_DNS"
+#define SURBL_OPTION_NOIP (1 << 0)
+#define SURBL_OPTION_RESOLVEIP (1 << 1)
+#define SURBL_OPTION_CHECKIMAGES (1 << 2)
+#define MAX_LEVELS 10
+
+struct surbl_ctx {
+ struct module_ctx ctx;
+ guint16 weight;
+ gdouble read_timeout;
+ gboolean use_tags;
+ GList *suffixes;
+ gchar *metric;
+ const gchar *redirector_symbol;
+ GHashTable **exceptions;
+ struct rspamd_hash_map_helper *whitelist;
+ void *redirector_map_data;
+ GHashTable *redirector_tlds;
+ guint use_redirector;
+ guint max_redirected_urls;
+ gint redirector_cbid;
+ struct upstream_list *redirectors;
+ rspamd_mempool_t *surbl_pool;
+};
+
+struct suffix_item {
+ guint64 magic;
+ const gchar *monitored_domain;
+ const gchar *suffix;
+ const gchar *symbol;
+ guint32 options;
+ GArray *bits;
+ GHashTable *ips;
+ struct rspamd_monitored *m;
+ gint callback_id;
+ gint url_process_cbref;
+};
+
+struct dns_param {
+ struct rspamd_url *url;
+ struct rspamd_task *task;
+ gchar *host_resolve;
+ struct suffix_item *suffix;
+ struct rspamd_async_watcher *w;
+};
+
+struct redirector_param {
+ struct rspamd_url *url;
+ struct rspamd_task *task;
+ struct upstream *redirector;
+ struct rspamd_http_connection *conn;
+ GHashTable *tree;
+ struct suffix_item *suffix;
+ struct rspamd_async_watcher *w;
+ gint sock;
+ guint redirector_requests;
+};
+
+struct surbl_bit_item {
+ guint32 bit;
+ gchar *symbol;
+};
+
#define SURBL_REDIRECTOR_CALLBACK "SURBL_REDIRECTOR_CALLBACK"
static struct surbl_ctx *surbl_module_ctx = NULL;
surbl_module_ctx->surbl_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
surbl_module_ctx->redirectors = NULL;
- surbl_module_ctx->whitelist = g_hash_table_new (rspamd_strcase_hash,
- rspamd_strcase_equal);
+ surbl_module_ctx->whitelist = NULL;
rspamd_mempool_add_destructor (surbl_module_ctx->surbl_pool,
- (rspamd_mempool_destruct_t) g_hash_table_destroy,
+ (rspamd_mempool_destruct_t) rspamd_map_helper_destroy_hash,
surbl_module_ctx->whitelist);
surbl_module_ctx->exceptions = rspamd_mempool_alloc0 (
surbl_module_ctx->surbl_pool, MAX_LEVELS * sizeof (GHashTable *));
if ((value =
rspamd_config_get_module_opt (cfg, "surbl", "whitelist")) != NULL) {
rspamd_map_add_from_ucl (cfg, value,
- "SURBL whitelist", rspamd_hosts_read, rspamd_hosts_fin,
+ "SURBL whitelist", rspamd_kv_list_read, rspamd_kv_list_fin,
(void **)&surbl_module_ctx->whitelist);
}
surbl_module_ctx->surbl_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
surbl_module_ctx->redirectors = NULL;
- surbl_module_ctx->whitelist = g_hash_table_new (rspamd_strcase_hash,
- rspamd_strcase_equal);
+ surbl_module_ctx->whitelist = NULL;
/* Zero exceptions hashes */
surbl_module_ctx->exceptions = rspamd_mempool_alloc0 (
surbl_module_ctx->surbl_pool,
MAX_LEVELS * sizeof (GHashTable *));
/* Register destructors */
rspamd_mempool_add_destructor (surbl_module_ctx->surbl_pool,
- (rspamd_mempool_destruct_t) g_hash_table_destroy,
+ (rspamd_mempool_destruct_t) rspamd_map_helper_destroy_hash,
surbl_module_ctx->whitelist);
rspamd_mempool_add_destructor (surbl_module_ctx->surbl_pool,
(rspamd_mempool_destruct_t) g_hash_table_destroy,
url->surbllen = r;
if (!forced &&
- g_hash_table_lookup (surbl_module_ctx->whitelist, result) != NULL) {
+ rspamd_match_hash_map (surbl_module_ctx->whitelist, result) != NULL) {
msg_debug_pool ("url %s is whitelisted", result);
g_set_error (err, SURBL_ERROR,
WHITELIST_ERROR,
+++ /dev/null
-#ifndef RSPAMD_MODULE_SURBL
-#define RSPAMD_MODULE_SURBL
-
-#include "config.h"
-#include "multipattern.h"
-#include "monitored.h"
-
-#define DEFAULT_SURBL_WEIGHT 10
-#define DEFAULT_REDIRECTOR_READ_TIMEOUT 5.0
-#define DEFAULT_SURBL_SYMBOL "SURBL_DNS"
-#define SURBL_OPTION_NOIP (1 << 0)
-#define SURBL_OPTION_RESOLVEIP (1 << 1)
-#define SURBL_OPTION_CHECKIMAGES (1 << 2)
-#define MAX_LEVELS 10
-
-struct surbl_ctx {
- struct module_ctx ctx;
- guint16 weight;
- gdouble read_timeout;
- gboolean use_tags;
- GList *suffixes;
- gchar *metric;
- const gchar *redirector_symbol;
- GHashTable **exceptions;
- GHashTable *whitelist;
- void *redirector_map_data;
- GHashTable *redirector_tlds;
- guint use_redirector;
- guint max_redirected_urls;
- gint redirector_cbid;
- struct upstream_list *redirectors;
- rspamd_mempool_t *surbl_pool;
-};
-
-struct suffix_item {
- guint64 magic;
- const gchar *monitored_domain;
- const gchar *suffix;
- const gchar *symbol;
- guint32 options;
- GArray *bits;
- GHashTable *ips;
- struct rspamd_monitored *m;
- gint callback_id;
- gint url_process_cbref;
-};
-
-struct dns_param {
- struct rspamd_url *url;
- struct rspamd_task *task;
- gchar *host_resolve;
- struct suffix_item *suffix;
- struct rspamd_async_watcher *w;
-};
-
-struct redirector_param {
- struct rspamd_url *url;
- struct rspamd_task *task;
- struct upstream *redirector;
- struct rspamd_http_connection *conn;
- GHashTable *tree;
- struct suffix_item *suffix;
- struct rspamd_async_watcher *w;
- gint sock;
- guint redirector_requests;
-};
-
-struct surbl_bit_item {
- guint32 bit;
- gchar *symbol;
-};
-
-#endif