summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-04-23 17:03:16 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-04-23 17:03:16 +0100
commit60403ad3baecbd5af0603c0b73c0bae7fe249600 (patch)
tree7a7f5673e1debc7d31084ba6be4a442a6e437857
parent09a949fdf2b2e500084c814db74b02b1dc5a7b89 (diff)
downloadrspamd-60403ad3baecbd5af0603c0b73c0bae7fe249600.tar.gz
rspamd-60403ad3baecbd5af0603c0b73c0bae7fe249600.zip
[Project] Adopt code
-rw-r--r--src/controller.c13
-rw-r--r--src/fuzzy_storage.c28
-rw-r--r--src/libutil/addr.c9
-rw-r--r--src/libutil/addr.h5
-rw-r--r--src/libutil/logger.c15
-rw-r--r--src/rspamd.h4
6 files changed, 40 insertions, 34 deletions
diff --git a/src/controller.c b/src/controller.c
index 3ae0dbe07..4c08b5e13 100644
--- a/src/controller.c
+++ b/src/controller.c
@@ -17,6 +17,7 @@
#include "libserver/dynamic_cfg.h"
#include "libutil/rrd.h"
#include "libutil/map.h"
+#include "libutil/map_helpers.h"
#include "libutil/map_private.h"
#include "libutil/http_private.h"
#include "libstat/stat_api.h"
@@ -157,7 +158,7 @@ struct rspamd_controller_worker_ctx {
gchar *ssl_key;
/* A map of secure IP */
const ucl_object_t *secure_ip;
- radix_compressed_t *secure_map;
+ struct rspamd_radix_map_helper *secure_map;
/* Static files dir */
gchar *static_files_dir;
@@ -436,8 +437,7 @@ rspamd_controller_check_forwarded (struct rspamd_controller_session *session,
(hdr->begin + hdr->len) - comma)) {
/* We have addr now, so check if it is still trusted */
if (ctx->secure_map &&
- radix_find_compressed_addr (ctx->secure_map,
- addr) != RADIX_NO_VALUE) {
+ rspamd_match_radix_map_addr (ctx->secure_map, addr) != NULL) {
/* rspamd_inet_address_to_string is not reentrant */
rspamd_strlcpy (ip_buf, rspamd_inet_address_to_string (addr),
sizeof (ip_buf));
@@ -466,8 +466,7 @@ rspamd_controller_check_forwarded (struct rspamd_controller_session *session,
if (rspamd_parse_inet_address (&addr, hdr->begin, hdr->len)) {
/* We have addr now, so check if it is still trusted */
if (ctx->secure_map &&
- radix_find_compressed_addr (ctx->secure_map,
- addr) != RADIX_NO_VALUE) {
+ rspamd_match_radix_map_addr (ctx->secure_map, addr) != NULL) {
/* rspamd_inet_address_to_string is not reentrant */
rspamd_strlcpy (ip_buf, rspamd_inet_address_to_string (addr),
sizeof (ip_buf));
@@ -526,8 +525,8 @@ rspamd_controller_check_password (struct rspamd_http_connection_entry *entry,
}
}
else if (ctx->secure_map
- && radix_find_compressed_addr (ctx->secure_map, session->from_addr)
- != RADIX_NO_VALUE) {
+ && rspamd_match_radix_map_addr (ctx->secure_map, session->from_addr)
+ != NULL) {
ret = rspamd_controller_check_forwarded (session, msg, ctx);
if (ret == 1) {
diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c
index 1f7ba6820..6c0c9b15e 100644
--- a/src/fuzzy_storage.c
+++ b/src/fuzzy_storage.c
@@ -17,22 +17,23 @@
* Rspamd fuzzy storage server
*/
-#include <libserver/rspamd_control.h>
-#include <src/libutil/map_private.h>
#include "config.h"
#include "util.h"
#include "rspamd.h"
#include "map.h"
+#include "map_helpers.h"
#include "fuzzy_wire.h"
#include "fuzzy_backend.h"
#include "ottery.h"
+#include "ref.h"
+#include "xxhash.h"
#include "libserver/worker_util.h"
#include "libserver/rspamd_control.h"
#include "libcryptobox/cryptobox.h"
#include "libcryptobox/keypairs_cache.h"
#include "libcryptobox/keypair.h"
-#include "ref.h"
-#include "xxhash.h"
+#include "libserver/rspamd_control.h"
+#include "libutil/map_private.h"
#include "libutil/hash.h"
#include "libutil/http_private.h"
#include "unix-std.h"
@@ -128,9 +129,9 @@ struct rspamd_fuzzy_storage_ctx {
char *hashfile;
gdouble expire;
gdouble sync_timeout;
- radix_compressed_t *update_ips;
- radix_compressed_t *master_ips;
- radix_compressed_t *blocked_ips;
+ struct rspamd_radix_map_helper *update_ips;
+ struct rspamd_radix_map_helper *master_ips;
+ struct rspamd_radix_map_helper *blocked_ips;
struct rspamd_cryptobox_keypair *sync_keypair;
struct rspamd_cryptobox_pubkey *master_key;
@@ -232,18 +233,19 @@ static gboolean
rspamd_fuzzy_check_client (struct fuzzy_session *session, gboolean is_write)
{
if (session->ctx->blocked_ips != NULL) {
- if (radix_find_compressed_addr (session->ctx->update_ips,
- session->addr) != RADIX_NO_VALUE) {
+ if (rspamd_match_radix_map_addr (session->ctx->blocked_ips,
+ session->addr) != NULL) {
return FALSE;
}
}
if (is_write) {
if (session->ctx->update_ips != NULL) {
- if (radix_find_compressed_addr (session->ctx->update_ips,
- session->addr) == RADIX_NO_VALUE) {
+ if (rspamd_match_radix_map_addr (session->ctx->update_ips,
+ session->addr) == NULL) {
return FALSE;
- } else {
+ }
+ else {
return TRUE;
}
}
@@ -1737,7 +1739,7 @@ accept_fuzzy_mirror_socket (gint fd, short what, void *arg)
return;
}
- else if (radix_find_compressed_addr (ctx->master_ips, addr) == RADIX_NO_VALUE) {
+ else if (rspamd_match_radix_map_addr (ctx->master_ips, addr) == NULL) {
msg_err ("deny update request from %s",
rspamd_inet_address_to_string (addr));
rspamd_inet_address_free (addr);
diff --git a/src/libutil/addr.c b/src/libutil/addr.c
index 9ea25c1ee..6735cb14d 100644
--- a/src/libutil/addr.c
+++ b/src/libutil/addr.c
@@ -16,6 +16,7 @@
#include "config.h"
#include "addr.h"
#include "util.h"
+#include "map_helpers.h"
#include "logger.h"
#include "cryptobox.h"
#include "unix-std.h"
@@ -28,7 +29,7 @@
#include <grp.h>
#endif
-static radix_compressed_t *local_addrs;
+static struct rspamd_radix_map_helper *local_addrs;
enum {
RSPAMD_IPV6_UNDEFINED = 0,
@@ -1732,7 +1733,7 @@ rspamd_inet_address_is_local (const rspamd_inet_addr_t *addr,
}
if (check_laddrs && local_addrs) {
- if (radix_find_compressed_addr (local_addrs, addr) != RADIX_NO_VALUE) {
+ if (rspamd_match_radix_map_addr (local_addrs, addr) != NULL) {
return TRUE;
}
}
@@ -1741,7 +1742,7 @@ rspamd_inet_address_is_local (const rspamd_inet_addr_t *addr,
return FALSE;
}
-radix_compressed_t **
+struct rspamd_radix_map_helper **
rspamd_inet_library_init (void)
{
return &local_addrs;
@@ -1751,7 +1752,7 @@ void
rspamd_inet_library_destroy (void)
{
if (local_addrs != NULL) {
- radix_destroy_compressed (local_addrs);
+ rspamd_map_helper_destroy_radix (local_addrs);
}
}
diff --git a/src/libutil/addr.h b/src/libutil/addr.h
index 046d5f040..389cd1e97 100644
--- a/src/libutil/addr.h
+++ b/src/libutil/addr.h
@@ -39,9 +39,10 @@
* Opaque structure
*/
typedef struct rspamd_inet_addr_s rspamd_inet_addr_t;
-struct radix_tree_compressed;
-struct radix_tree_compressed **rspamd_inet_library_init (void);
+struct rspamd_radix_map_helper;
+
+struct rspamd_radix_map_helper **rspamd_inet_library_init (void);
void rspamd_inet_library_destroy (void);
/**
diff --git a/src/libutil/logger.c b/src/libutil/logger.c
index 0313638b6..99c22390f 100644
--- a/src/libutil/logger.c
+++ b/src/libutil/logger.c
@@ -17,6 +17,7 @@
#include "logger.h"
#include "rspamd.h"
#include "map.h"
+#include "map_helpers.h"
#include "ottery.h"
#include "unix-std.h"
@@ -90,7 +91,7 @@ struct rspamd_logger_s {
pid_t pid;
guint32 repeats;
GQuark process_type;
- radix_compressed_t *debug_ip;
+ struct rspamd_radix_map_helper *debug_ip;
guint64 last_line_cksum;
gchar *saved_message;
gchar *saved_function;
@@ -462,7 +463,7 @@ rspamd_set_logger (struct rspamd_config *cfg,
if (cfg->debug_ip_map != NULL) {
/* Try to add it as map first of all */
if (logger->debug_ip) {
- radix_destroy_compressed (logger->debug_ip);
+ rspamd_map_helper_destroy_radix (logger->debug_ip);
}
logger->debug_ip = NULL;
@@ -472,7 +473,7 @@ rspamd_set_logger (struct rspamd_config *cfg,
&logger->debug_ip, NULL);
}
else if (logger->debug_ip) {
- radix_destroy_compressed (logger->debug_ip);
+ rspamd_map_helper_destroy_radix (logger->debug_ip);
logger->debug_ip = NULL;
}
@@ -1179,8 +1180,8 @@ rspamd_conditional_debug (rspamd_logger_t *rspamd_log,
if (rspamd_logger_need_log (rspamd_log, G_LOG_LEVEL_DEBUG, mod_id) ||
rspamd_log->is_debug) {
if (rspamd_log->debug_ip && addr != NULL) {
- if (radix_find_compressed_addr (rspamd_log->debug_ip, addr)
- == RADIX_NO_VALUE) {
+ if (rspamd_match_radix_map_addr (rspamd_log->debug_ip,
+ addr) == NULL) {
return;
}
}
@@ -1214,8 +1215,8 @@ rspamd_conditional_debug_fast (rspamd_logger_t *rspamd_log,
if (rspamd_logger_need_log (rspamd_log, G_LOG_LEVEL_DEBUG, mod_id) ||
rspamd_log->is_debug) {
if (rspamd_log->debug_ip && addr != NULL) {
- if (radix_find_compressed_addr (rspamd_log->debug_ip, addr)
- == RADIX_NO_VALUE) {
+ if (rspamd_match_radix_map_addr (rspamd_log->debug_ip, addr)
+ == NULL) {
return;
}
}
diff --git a/src/rspamd.h b/src/rspamd.h
index 4fdc626da..1365a4b23 100644
--- a/src/rspamd.h
+++ b/src/rspamd.h
@@ -314,9 +314,11 @@ struct zstd_dictionary {
guint id;
};
+struct rspamd_radix_map_helper;
+
struct rspamd_external_libs_ctx {
magic_t libmagic;
- radix_compressed_t **local_addrs;
+ struct rspamd_radix_map_helper **local_addrs;
struct rspamd_cryptobox_library_ctx *crypto_ctx;
struct ottery_config *ottery_cfg;
SSL_CTX *ssl_ctx;