commit 41e28d1: [Rework] Further project structure reorganisation

Vsevolod Stakhov vsevolod at highsecure.ru
Tue Feb 11 12:42:16 UTC 2020


Author: Vsevolod Stakhov
Date: 2020-02-11 12:34:40 +0000
URL: https://github.com/rspamd/rspamd/commit/41e28d1148a308957735875abb271d22ba0b4432 (HEAD -> master)

[Rework] Further project structure reorganisation

---
 cmake/Toolset.cmake                               |   9 -
 config.h.in                                       |   1 -
 src/client/rspamc.c                               |   4 +-
 src/client/rspamdclient.c                         |   4 +-
 src/controller.c                                  |  10 +-
 src/fuzzy_storage.c                               |   7 +-
 src/libmime/scan_result.c                         |   2 -
 src/libserver/CMakeLists.txt                      |  10 +-
 src/libserver/cfg_file.h                          |  30 +
 src/libserver/cfg_utils.c                         | 379 ++++++++++-
 src/libserver/dynamic_cfg.c                       |   2 +-
 src/{libutil => libserver/http}/http_connection.c |   2 +-
 src/{libutil => libserver/http}/http_connection.h |   0
 src/{libutil => libserver/http}/http_context.c    |   0
 src/{libutil => libserver/http}/http_context.h    |   0
 src/{libutil => libserver/http}/http_message.c    |   4 +-
 src/{libutil => libserver/http}/http_message.h    |   0
 src/{libutil => libserver/http}/http_private.h    |   0
 src/{libutil => libserver/http}/http_router.c     |   6 +-
 src/{libutil => libserver/http}/http_router.h     |   0
 src/{libutil => libserver/http}/http_util.c       |   2 +-
 src/{libutil => libserver/http}/http_util.h       |   0
 src/libserver/logger/logger.c                     |   4 +-
 src/libserver/logger/logger_file.c                |   1 -
 src/{libutil => libserver/maps}/map.c             |   4 +-
 src/{libutil => libserver/maps}/map.h             |   0
 src/{libutil => libserver/maps}/map_helpers.c     |   0
 src/{libutil => libserver/maps}/map_helpers.h     |   0
 src/{libutil => libserver/maps}/map_private.h     |   0
 src/libserver/milter.c                            |   4 +-
 src/libserver/protocol.c                          |   2 +-
 src/libserver/protocol.h                          |   2 +-
 src/libserver/rspamd_control.c                    |   4 +-
 src/{libutil => libserver}/ssl_util.c             |  49 ++
 src/{libutil => libserver}/ssl_util.h             |   3 +
 src/libserver/task.h                              |   2 +-
 src/libserver/worker_util.c                       |  21 +-
 src/libserver/worker_util.h                       |   2 +-
 src/libutil/CMakeLists.txt                        |  10 +-
 src/libutil/addr.c                                |   5 +-
 src/libutil/util.c                                | 739 +---------------------
 src/libutil/util.h                                |  88 +--
 src/lua/lua_http.c                                |   2 +-
 src/lua/lua_logger.c                              |   4 +-
 src/lua/lua_map.c                                 |   6 +-
 src/lua/lua_task.c                                |   2 +-
 src/lua/lua_tcp.c                                 |   2 +-
 src/plugins/dkim_check.c                          |   4 +-
 src/plugins/fuzzy_check.c                         |   9 +-
 src/plugins/regexp.c                              |   2 +-
 src/rspamadm/control.c                            |   4 +-
 src/rspamadm/lua_repl.c                           |   6 +-
 src/rspamadm/rspamadm.c                           |   1 -
 src/rspamd.c                                      |  56 +-
 src/rspamd.h                                      |  23 +-
 src/rspamd_proxy.c                                |   6 +-
 src/worker.c                                      |   4 +-
 test/rspamd_http_test.c                           |   2 -
 utils/rspamd_http_server.c                        |   2 -
 59 files changed, 619 insertions(+), 928 deletions(-)

diff --git a/cmake/Toolset.cmake b/cmake/Toolset.cmake
index 673479f11..02b3925e7 100644
--- a/cmake/Toolset.cmake
+++ b/cmake/Toolset.cmake
@@ -88,15 +88,6 @@ else ()
     endif ()
 endif ()
 
-# Google performance tools
-option (ENABLE_GPERF_TOOLS  "Enable google perftools [default: OFF]"             OFF)
-if (ENABLE_GPERF_TOOLS MATCHES "ON")
-    ProcessPackage(GPERF LIBRARY profiler INCLUDE profiler.h INCLUDE_SUFFIXES include/google
-            ROOT ${GPERF_ROOT_DIR})
-    set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer")
-    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer")
-    set (WITH_GPERF_TOOLS 1)
-endif (ENABLE_GPERF_TOOLS MATCHES "ON")
 
 # Legacy options support
 option (ENABLE_COVERAGE     "Build rspamd with code coverage options [default: OFF]" OFF)
diff --git a/config.h.in b/config.h.in
index 2f4eef401..cad62df81 100644
--- a/config.h.in
+++ b/config.h.in
@@ -146,7 +146,6 @@
 #cmakedefine WITH_LUA            1
 #cmakedefine WITH_LUAJIT         1
 #cmakedefine WITH_PCRE2          1
-#cmakedefine WITH_PROFILER       1
 #cmakedefine WITH_SNOWBALL       1
 #cmakedefine WITH_SQLITE         1
 #cmakedefine WITH_SYSTEM_HIREDIS 1
diff --git a/src/client/rspamc.c b/src/client/rspamc.c
index 6ca3de668..f759ec610 100644
--- a/src/client/rspamc.c
+++ b/src/client/rspamc.c
@@ -15,8 +15,8 @@
  */
 #include "config.h"
 #include "libutil/util.h"
-#include "libutil/http_connection.h"
-#include "libutil/http_private.h"
+#include "libserver/http/http_connection.h"
+#include "libserver/http/http_private.h"
 #include "rspamdclient.h"
 #include "utlist.h"
 #include "unix-std.h"
diff --git a/src/client/rspamdclient.c b/src/client/rspamdclient.c
index e80926087..98b51506b 100644
--- a/src/client/rspamdclient.c
+++ b/src/client/rspamdclient.c
@@ -15,8 +15,8 @@
  */
 #include "rspamdclient.h"
 #include "libutil/util.h"
-#include "libutil/http_connection.h"
-#include "libutil/http_private.h"
+#include "libserver/http/http_connection.h"
+#include "libserver/http/http_private.h"
 #include "libserver/protocol_internal.h"
 #include "unix-std.h"
 #include "contrib/zstd/zstd.h"
diff --git a/src/controller.c b/src/controller.c
index 23ff7237b..31c353e34 100644
--- a/src/controller.c
+++ b/src/controller.c
@@ -17,11 +17,11 @@
 #include "libserver/dynamic_cfg.h"
 #include "libserver/cfg_file_private.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 "libutil/http_router.h"
+#include "libserver/maps/map.h"
+#include "libserver/maps/map_helpers.h"
+#include "libserver/maps/map_private.h"
+#include "libserver/http/http_private.h"
+#include "libserver/http/http_router.h"
 #include "libstat/stat_api.h"
 #include "rspamd.h"
 #include "libserver/worker_util.h"
diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c
index 5bc8cf29d..f91fb61ac 100644
--- a/src/fuzzy_storage.c
+++ b/src/fuzzy_storage.c
@@ -21,8 +21,8 @@
 #include "libserver/fuzzy_wire.h"
 #include "util.h"
 #include "rspamd.h"
-#include "map.h"
-#include "map_helpers.h"
+#include "libserver/maps/map.h"
+#include "libserver/maps/map_helpers.h"
 #include "fuzzy_wire.h"
 #include "libserver/fuzzy_backend/fuzzy_backend.h"
 #include "ottery.h"
@@ -33,9 +33,8 @@
 #include "libcryptobox/cryptobox.h"
 #include "libcryptobox/keypairs_cache.h"
 #include "libcryptobox/keypair.h"
-#include "libserver/rspamd_control.h"
 #include "libutil/hash.h"
-#include "libutil/map_private.h"
+#include "libserver/maps/map_private.h"
 #include "contrib/uthash/utlist.h"
 #include "unix-std.h"
 
diff --git a/src/libmime/scan_result.c b/src/libmime/scan_result.c
index e95f26799..babf80abe 100644
--- a/src/libmime/scan_result.c
+++ b/src/libmime/scan_result.c
@@ -510,8 +510,6 @@ rspamd_task_option_safe_copy (struct rspamd_task *task,
 							  gsize *outlen)
 {
 	const gchar *p, *end;
-	off_t r;
-	UChar32 uc;
 
 	p = val;
 	end = val + vlen;
diff --git a/src/libserver/CMakeLists.txt b/src/libserver/CMakeLists.txt
index 4b999c900..635c65b13 100644
--- a/src/libserver/CMakeLists.txt
+++ b/src/libserver/CMakeLists.txt
@@ -18,6 +18,7 @@ SET(LIBRSPAMDSERVERSRC
 				${CMAKE_CURRENT_SOURCE_DIR}/redis_pool.c
 				${CMAKE_CURRENT_SOURCE_DIR}/roll_history.c
 				${CMAKE_CURRENT_SOURCE_DIR}/spf.c
+				${CMAKE_CURRENT_SOURCE_DIR}/ssl_util.c
 				${CMAKE_CURRENT_SOURCE_DIR}/rspamd_symcache.c
 				${CMAKE_CURRENT_SOURCE_DIR}/task.c
 				${CMAKE_CURRENT_SOURCE_DIR}/url.c
@@ -25,7 +26,14 @@ SET(LIBRSPAMDSERVERSRC
 				${CMAKE_CURRENT_SOURCE_DIR}/logger/logger.c
 				${CMAKE_CURRENT_SOURCE_DIR}/logger/logger_file.c
 				${CMAKE_CURRENT_SOURCE_DIR}/logger/logger_syslog.c
-				${CMAKE_CURRENT_SOURCE_DIR}/logger/logger_console.c)
+				${CMAKE_CURRENT_SOURCE_DIR}/logger/logger_console.c
+				${CMAKE_CURRENT_SOURCE_DIR}/http/http_util.c
+				${CMAKE_CURRENT_SOURCE_DIR}/http/http_message.c
+				${CMAKE_CURRENT_SOURCE_DIR}/http/http_connection.c
+				${CMAKE_CURRENT_SOURCE_DIR}/http/http_router.c
+				${CMAKE_CURRENT_SOURCE_DIR}/http/http_context.c
+				${CMAKE_CURRENT_SOURCE_DIR}/maps/map.c
+				${CMAKE_CURRENT_SOURCE_DIR}/maps/map_helpers.c)
 
 # Librspamd-server
 SET(RSPAMD_SERVER ${LIBRSPAMDSERVERSRC} PARENT_SCOPE)
diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h
index cf1532692..4a8ab5bfc 100644
--- a/src/libserver/cfg_file.h
+++ b/src/libserver/cfg_file.h
@@ -821,6 +821,36 @@ struct rspamd_action *rspamd_config_get_action_by_type (struct rspamd_config *cf
 int rspamd_config_ev_backend_get (struct rspamd_config *cfg);
 const gchar * rspamd_config_ev_backend_to_string (int ev_backend, gboolean *effective);
 
+struct rspamd_external_libs_ctx;
+
+/**
+ * Initialize rspamd libraries
+ */
+struct rspamd_external_libs_ctx *rspamd_init_libs (void);
+
+/**
+ * Reset and initialize decompressor
+ * @param ctx
+ */
+gboolean rspamd_libs_reset_decompression (struct rspamd_external_libs_ctx *ctx);
+
+/**
+ * Reset and initialize compressor
+ * @param ctx
+ */
+gboolean rspamd_libs_reset_compression (struct rspamd_external_libs_ctx *ctx);
+
+/**
+ * Destroy external libraries context
+ */
+void rspamd_deinit_libs (struct rspamd_external_libs_ctx *ctx);
+
+/**
+ * Configure libraries
+ */
+gboolean rspamd_config_libs (struct rspamd_external_libs_ctx *ctx,
+							 struct rspamd_config *cfg);
+
 #define msg_err_config(...) rspamd_default_log_function (G_LOG_LEVEL_CRITICAL, \
         cfg->cfg_pool->tag.tagname, cfg->checksum, \
         G_STRFUNC, \
diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c
index cd85b73ac..961a2610e 100644
--- a/src/libserver/cfg_utils.c
+++ b/src/libserver/cfg_utils.c
@@ -21,9 +21,9 @@
 #include "scan_result.h"
 #include "lua/lua_common.h"
 #include "lua/lua_thread_pool.h"
-#include "map.h"
-#include "map_helpers.h"
-#include "map_private.h"
+#include "maps/map.h"
+#include "maps/map_helpers.h"
+#include "maps/map_private.h"
 #include "dynamic_cfg.h"
 #include "utlist.h"
 #include "stat_api.h"
@@ -31,6 +31,26 @@
 #include "libutil/multipattern.h"
 #include "monitored.h"
 #include "ref.h"
+#include "cryptobox.h"
+#include "ssl_util.h"
+#include "contrib/libottery/ottery.h"
+#include "contrib/fastutf8/fastutf8.h"
+
+#define ZSTD_STATIC_LINKING_ONLY
+#include "contrib/zstd/zstd.h"
+#include "contrib/zstd/zdict.h"
+
+#ifdef HAVE_OPENSSL
+#include <openssl/rand.h>
+#include <openssl/err.h>
+#include <openssl/evp.h>
+#include <openssl/ssl.h>
+#include <openssl/conf.h>
+#include <openssl/engine.h>
+#endif
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#endif
 #include <math.h>
 
 #define DEFAULT_SCORE 10.0
@@ -2614,4 +2634,357 @@ rspamd_config_ev_backend_to_string (int ev_backend, gboolean *effective)
 	SET_EFFECTIVE (FALSE);
 	return "unknown";
 #undef SET_EFFECTIVE
+}
+
+static void
+rspamd_openssl_maybe_init (void)
+{
+	static gboolean openssl_initialized = FALSE;
+
+	if (!openssl_initialized) {
+		ERR_load_crypto_strings ();
+		SSL_load_error_strings ();
+
+		OpenSSL_add_all_algorithms ();
+		OpenSSL_add_all_digests ();
+		OpenSSL_add_all_ciphers ();
+
+#if OPENSSL_VERSION_NUMBER >= 0x1000104fL && !defined(LIBRESSL_VERSION_NUMBER)
+		ENGINE_load_builtin_engines ();
+#endif
+#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
+		SSL_library_init ();
+#else
+		OPENSSL_init_ssl (0, NULL);
+#endif
+
+#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
+		OPENSSL_config (NULL);
+#endif
+		if (RAND_status () == 0) {
+			guchar seed[128];
+
+			/* Try to use ottery to seed rand */
+			ottery_rand_bytes (seed, sizeof (seed));
+			RAND_seed (seed, sizeof (seed));
+			rspamd_explicit_memzero (seed, sizeof (seed));
+		}
+
+		openssl_initialized = TRUE;
+	}
+}
+
+struct rspamd_external_libs_ctx *
+rspamd_init_libs (void)
+{
+	struct rlimit rlim;
+	struct rspamd_external_libs_ctx *ctx;
+	struct ottery_config *ottery_cfg;
+
+	ctx = g_malloc0 (sizeof (*ctx));
+	ctx->crypto_ctx = rspamd_cryptobox_init ();
+	ottery_cfg = g_malloc0 (ottery_get_sizeof_config ());
+	ottery_config_init (ottery_cfg);
+	ctx->ottery_cfg = ottery_cfg;
+
+	rspamd_openssl_maybe_init ();
+
+	/* Check if we have rdrand */
+	if ((ctx->crypto_ctx->cpu_config & CPUID_RDRAND) == 0) {
+		ottery_config_disable_entropy_sources (ottery_cfg,
+				OTTERY_ENTROPY_SRC_RDRAND);
+#if OPENSSL_VERSION_NUMBER >= 0x1000104fL && !defined(LIBRESSL_VERSION_NUMBER)
+		RAND_set_rand_engine (NULL);
+#endif
+	}
+
+	/* Configure utf8 library */
+	guint utf8_flags = 0;
+
+	if ((ctx->crypto_ctx->cpu_config & CPUID_SSE41)) {
+		utf8_flags |= RSPAMD_FAST_UTF8_FLAG_SSE41;
+	}
+	if ((ctx->crypto_ctx->cpu_config & CPUID_AVX2)) {
+		utf8_flags |= RSPAMD_FAST_UTF8_FLAG_AVX2;
+	}
+
+	rspamd_fast_utf8_library_init (utf8_flags);
+
+	g_assert (ottery_init (ottery_cfg) == 0);
+
+#ifdef HAVE_LOCALE_H
+	if (getenv ("LANG") == NULL) {
+		setlocale (LC_ALL, "C");
+		setlocale (LC_CTYPE, "C");
+		setlocale (LC_MESSAGES, "C");
+		setlocale (LC_TIME, "C");
+	}
+	else {
+		/* Just set the default locale */
+		setlocale (LC_ALL, "");
+		/* But for some issues we still want C locale */
+		setlocale (LC_NUMERIC, "C");
+	}
+#endif
+
+	ctx->ssl_ctx = rspamd_init_ssl_ctx ();
+	ctx->ssl_ctx_noverify = rspamd_init_ssl_ctx_noverify ();
+	rspamd_random_seed_fast ();
+
+	/* Set stack size for pcre */
+	getrlimit (RLIMIT_STACK, &rlim);
+	rlim.rlim_cur = 100 * 1024 * 1024;
+	rlim.rlim_max = rlim.rlim_cur;
+	setrlimit (RLIMIT_STACK, &rlim);
+
+	ctx->local_addrs = rspamd_inet_library_init ();
+	REF_INIT_RETAIN (ctx, rspamd_deinit_libs);
+
+	return ctx;
+}
+
+static struct zstd_dictionary *
+rspamd_open_zstd_dictionary (const char *path)
+{
+	struct zstd_dictionary *dict;
+
+	dict = g_malloc0 (sizeof (*dict));
+	dict->dict = rspamd_file_xmap (path, PROT_READ, &dict->size, TRUE);
+
+	if (dict->dict == NULL) {
+		g_free (dict);
+
+		return NULL;
+	}
+
+	dict->id = ZDICT_getDictID (dict->dict, dict->size);
+
+	if (dict->id == 0) {
+		g_free (dict);
+
+		return NULL;
+	}
+
+	return dict;
+}
+
+static void
+rspamd_free_zstd_dictionary (struct zstd_dictionary *dict)
+{
+	if (dict) {
+		munmap (dict->dict, dict->size);
+		g_free (dict);
+	}
+}
+
+gboolean
+rspamd_config_libs (struct rspamd_external_libs_ctx *ctx,
+					struct rspamd_config *cfg)
+{
+	static const char secure_ciphers[] = "HIGH:!aNULL:!kRSA:!PSK:!SRP:!MD5:!RC4";
+	size_t r;
+	gboolean ret = TRUE;
+
+	g_assert (cfg != NULL);
+
+	if (ctx != NULL) {
+		if (cfg->local_addrs) {
+			rspamd_config_radix_from_ucl (cfg, cfg->local_addrs,
+					"Local addresses",
+					ctx->local_addrs,
+					NULL,
+					NULL);
+		}
+
+		rspamd_free_zstd_dictionary (ctx->in_dict);
+		rspamd_free_zstd_dictionary (ctx->out_dict);
+
+		if (ctx->out_zstream) {
+			ZSTD_freeCStream (ctx->out_zstream);
+			ctx->out_zstream = NULL;
+		}
+
+		if (ctx->in_zstream) {
+			ZSTD_freeDStream (ctx->in_zstream);
+			ctx->in_zstream = NULL;
+		}
+
+		if (cfg->zstd_input_dictionary) {
+			ctx->in_dict = rspamd_open_zstd_dictionary (
+					cfg->zstd_input_dictionary);
+
+			if (ctx->in_dict == NULL) {
+				msg_err_config ("cannot open zstd dictionary in %s",
+						cfg->zstd_input_dictionary);
+			}
+		}
+		if (cfg->zstd_output_dictionary) {
+			ctx->out_dict = rspamd_open_zstd_dictionary (
+					cfg->zstd_output_dictionary);
+
+			if (ctx->out_dict == NULL) {
+				msg_err_config ("cannot open zstd dictionary in %s",
+						cfg->zstd_output_dictionary);
+			}
+		}
+
+		if (cfg->fips_mode) {
+#ifdef HAVE_FIPS_MODE
+			int mode = FIPS_mode ();
+			unsigned long err = (unsigned long)-1;
+
+			/* Toggle FIPS mode */
+			if (mode == 0) {
+				if (FIPS_mode_set (1) != 1) {
+					err = ERR_get_error ();
+				}
+			}
+			else {
+				msg_info_config ("OpenSSL FIPS mode is already enabled");
+			}
+
+			if (err != (unsigned long)-1) {
+				msg_err_config ("FIPS_mode_set failed: %s",
+						ERR_error_string (err, NULL));
+				ret = FALSE;
+			}
+			else {
+				msg_info_config ("OpenSSL FIPS mode is enabled");
+			}
+#else
+			msg_warn_config ("SSL FIPS mode is enabled but not supported by OpenSSL library!");
+#endif
+		}
+
+		if (cfg->ssl_ca_path) {
+			if (SSL_CTX_load_verify_locations (ctx->ssl_ctx, cfg->ssl_ca_path,
+					NULL) != 1) {
+				msg_err_config ("cannot load CA certs from %s: %s",
+						cfg->ssl_ca_path,
+						ERR_error_string (ERR_get_error (), NULL));
+			}
+		}
+		else {
+			msg_debug_config ("ssl_ca_path is not set, using default CA path");
+			SSL_CTX_set_default_verify_paths (ctx->ssl_ctx);
+		}
+
+		if (cfg->ssl_ciphers) {
+			if (SSL_CTX_set_cipher_list (ctx->ssl_ctx, cfg->ssl_ciphers) != 1) {
+				msg_err_config (
+						"cannot set ciphers set to %s: %s; fallback to %s",
+						cfg->ssl_ciphers,
+						ERR_error_string (ERR_get_error (), NULL),
+						secure_ciphers);
+				/* Default settings */
+				SSL_CTX_set_cipher_list (ctx->ssl_ctx, secure_ciphers);
+			}
+		}
+
+		/* Init decompression */
+		ctx->in_zstream = ZSTD_createDStream ();
+		r = ZSTD_initDStream (ctx->in_zstream);
+
+		if (ZSTD_isError (r)) {
+			msg_err ("cannot init decompression stream: %s",
+					ZSTD_getErrorName (r));
+			ZSTD_freeDStream (ctx->in_zstream);
+			ctx->in_zstream = NULL;
+		}
+
+		/* Init compression */
+		ctx->out_zstream = ZSTD_createCStream ();
+		r = ZSTD_initCStream (ctx->out_zstream, 1);
+
+		if (ZSTD_isError (r)) {
+			msg_err ("cannot init compression stream: %s",
+					ZSTD_getErrorName (r));
+			ZSTD_freeCStream (ctx->out_zstream);
+			ctx->out_zstream = NULL;
+		}
+#ifdef HAVE_CBLAS
+		openblas_set_num_threads (cfg->max_blas_threads);
+#endif
+	}
+
+	return ret;
+}
+
+gboolean
+rspamd_libs_reset_decompression (struct rspamd_external_libs_ctx *ctx)
+{
+	gsize r;
+
+	if (ctx->in_zstream == NULL) {
+		return FALSE;
+	}
+	else {
+		r = ZSTD_resetDStream (ctx->in_zstream);
+
+		if (ZSTD_isError (r)) {
+			msg_err ("cannot init decompression stream: %s",
+					ZSTD_getErrorName (r));
+			ZSTD_freeDStream (ctx->in_zstream);
+			ctx->in_zstream = NULL;
+
+			return FALSE;
+		}
+	}
+
+	return TRUE;
+}
+
+gboolean
+rspamd_libs_reset_compression (struct rspamd_external_libs_ctx *ctx)
+{
+	gsize r;
+
+	if (ctx->out_zstream == NULL) {
+		return FALSE;
+	}
+	else {
+		/* Dictionary will be reused automatically if specified */
+		r = ZSTD_resetCStream (ctx->out_zstream, 0);
+
+		if (ZSTD_isError (r)) {
+			msg_err ("cannot init compression stream: %s",
+					ZSTD_getErrorName (r));
+			ZSTD_freeCStream (ctx->out_zstream);
+			ctx->out_zstream = NULL;
+
+			return FALSE;
+		}
+	}
+
+	return TRUE;
+}
+
+void
+rspamd_deinit_libs (struct rspamd_external_libs_ctx *ctx)
+{
+	if (ctx != NULL) {
+		g_free (ctx->ottery_cfg);
+
+#ifdef HAVE_OPENSSL
+		EVP_cleanup ();
+		ERR_free_strings ();
+		SSL_CTX_free (ctx->ssl_ctx);
+		SSL_CTX_free (ctx->ssl_ctx_noverify);
+#endif
+		rspamd_inet_library_destroy ();
+		rspamd_free_zstd_dictionary (ctx->in_dict);
+		rspamd_free_zstd_dictionary (ctx->out_dict);
+
+		if (ctx->out_zstream) {
+			ZSTD_freeCStream (ctx->out_zstream);
+		}
+
+		if (ctx->in_zstream) {
+			ZSTD_freeDStream (ctx->in_zstream);
+		}
+
+		rspamd_cryptobox_deinit (ctx->crypto_ctx);
+
+		g_free (ctx);
+	}
 }
\ No newline at end of file
diff --git a/src/libserver/dynamic_cfg.c b/src/libserver/dynamic_cfg.c
index a39778ec2..8b1f464f1 100644
--- a/src/libserver/dynamic_cfg.c
+++ b/src/libserver/dynamic_cfg.c
@@ -15,7 +15,7 @@
  */
 #include "config.h"
 #include "rspamd.h"
-#include "map.h"
+#include "libserver/maps/map.h"
 #include "scan_result.h"
 #include "dynamic_cfg.h"
 #include "unix-std.h"
diff --git a/src/libutil/http_connection.c b/src/libserver/http/http_connection.c
similarity index 99%
rename from src/libutil/http_connection.c
rename to src/libserver/http/http_connection.c
index 027dc9d5b..28a13f7ba 100644
--- a/src/libutil/http_connection.c
+++ b/src/libserver/http/http_connection.c
@@ -26,7 +26,7 @@
 #include "keypair_private.h"
 #include "cryptobox.h"
 #include "libutil/libev_helper.h"
-#include "libutil/ssl_util.h"
+#include "libserver/ssl_util.h"
 #include "libserver/url.h"
 
 #include "contrib/mumhash/mum.h"
diff --git a/src/libutil/http_connection.h b/src/libserver/http/http_connection.h
similarity index 100%
rename from src/libutil/http_connection.h
rename to src/libserver/http/http_connection.h
diff --git a/src/libutil/http_context.c b/src/libserver/http/http_context.c
similarity index 100%
rename from src/libutil/http_context.c
rename to src/libserver/http/http_context.c
diff --git a/src/libutil/http_context.h b/src/libserver/http/http_context.h
*** OUTPUT TRUNCATED, 1942 LINES SKIPPED ***


More information about the Commits mailing list