]> source.dussan.org Git - rspamd.git/commitdiff
[Project] Adopt code
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 23 Apr 2018 16:03:16 +0000 (17:03 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 23 Apr 2018 16:03:16 +0000 (17:03 +0100)
src/controller.c
src/fuzzy_storage.c
src/libutil/addr.c
src/libutil/addr.h
src/libutil/logger.c
src/rspamd.h

index 3ae0dbe079fd3528e62b4e94ab78db7bd3efe878..4c08b5e1348513a504c2c3df2125d223915cd355 100644 (file)
@@ -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) {
index 1f7ba6820b52e500d47534728611a8f1de16794a..6c0c9b15e0f7b92c9af57a12e84a8be1e03e4ff5 100644 (file)
  * 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);
index 9ea25c1ee7ec5b13b4e9990e60bb1656f4519ca0..6735cb14d5fef3d6fee56e3ff177546cb24e420b 100644 (file)
@@ -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);
        }
 }
 
index 046d5f04034637c4e52d2cb2c4daf8106f553167..389cd1e97e5c64907475da46e27090e956be66ec 100644 (file)
  * 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);
 
 /**
index 0313638b63a66f4b74f4897ccfb4d6f8ac30ee2c..99c22390fc1fcd02a67309f2f7c660fabc19a2de 100644 (file)
@@ -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;
                        }
                }
index 4fdc626da052f9d5fe0ff4e0ba839022881cd450..1365a4b23fce7f2c4c0ce4496b284fd77a0d0fa0 100644 (file)
@@ -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;