<commit_before>/* Copyright (c) 2009-2014 Dovecot authors, see the included COPYING file */

#include "lib.h"
#include "module-dir.h"
#include "iostream-ssl-private.h"

#include <stdlib.h>

static bool ssl_module_loaded = FALSE;
#ifdef HAVE_SSL
static struct module *ssl_module = NULL;
#endif
static const struct iostream_ssl_vfuncs *ssl_vfuncs = NULL;

#ifdef HAVE_SSL
static void ssl_module_unload(void)
{
	module_dir_deinit(ssl_module);
	ssl_vfuncs->global_deinit();
	module_dir_unload(&ssl_module);
}
#endif

static int ssl_module_load(const char **error_r)
{
#ifdef HAVE_SSL
	const char *plugin_name = "ssl_iostream_openssl";
	struct module_dir_load_settings mod_set;

	memset(&mod_set, 0, sizeof(mod_set));
	mod_set.abi_version = DOVECOT_ABI_VERSION;
	mod_set.setting_name = "<built-in lib-ssl-iostream lookup>";
	ssl_module = module_dir_load(MODULE_DIR, plugin_name, &mod_set);

	ssl_vfuncs = module_get_symbol(ssl_module, "ssl_vfuncs");
	if (ssl_vfuncs == NULL) {
		*error_r = t_strdup_printf("%s: Broken plugin: "
			"ssl_vfuncs symbol not found", plugin_name);
		module_dir_unload(&ssl_module);
		return -1;
	}

	lib_atexit(ssl_module_unload);
	ssl_module_loaded = TRUE;
	return 0;
#else
	*error_r = "SSL support not compiled in";
	return -1;
#endif
}

int ssl_iostream_context_init_client(const struct ssl_iostream_settings *set,
				     struct ssl_iostream_context **ctx_r,<commit_msg>lib-ssl-iostream: Destroy SSL module later in the atexit-callbacks.<commit_after>/* Copyright (c) 2009-2014 Dovecot authors, see the included COPYING file */

#include "lib.h"
#include "module-dir.h"
#include "iostream-ssl-private.h"

#include <stdlib.h>

static bool ssl_module_loaded = FALSE;
#ifdef HAVE_SSL
static struct module *ssl_module = NULL;
#endif
static const struct iostream_ssl_vfuncs *ssl_vfuncs = NULL;

#ifdef HAVE_SSL
static void ssl_module_unload(void)
{
	module_dir_deinit(ssl_module);
	ssl_vfuncs->global_deinit();
	module_dir_unload(&ssl_module);
}
#endif

static int ssl_module_load(const char **error_r)
{
#ifdef HAVE_SSL
	const char *plugin_name = "ssl_iostream_openssl";
	struct module_dir_load_settings mod_set;

	memset(&mod_set, 0, sizeof(mod_set));
	mod_set.abi_version = DOVECOT_ABI_VERSION;
	mod_set.setting_name = "<built-in lib-ssl-iostream lookup>";
	ssl_module = module_dir_load(MODULE_DIR, plugin_name, &mod_set);

	ssl_vfuncs = module_get_symbol(ssl_module, "ssl_vfuncs");
	if (ssl_vfuncs == NULL) {
		*error_r = t_strdup_printf("%s: Broken plugin: "
			"ssl_vfuncs symbol not found", plugin_name);
		module_dir_unload(&ssl_module);
		return -1;
	}

	/* Destroy SSL module after (most of) the others. Especially lib-fs
	   backends may still want to access SSL module in their own
	   atexit-callbacks. */
	lib_atexit_priority(ssl_module_unload, LIB_ATEXIT_PRIORITY_LOW);
	ssl_module_loaded = TRUE;
	return 0;
#else
	*error_r = "SSL support not compiled in";
	return -1;
#endif
}

int ssl_iostream_context_init_client(const struct ssl_iostream_settings *set,
				     struct ssl_iostream_context **ctx_r,
{'fraction_non_alphanumeric': 0.10526315789473684, 'fraction_numerical': 0.007894736842105263, 'mean_word_length': 5.880090497737557, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2538314', 'n_tokens_mistral': 1177, 'n_tokens_neox': 1126, 'n_words': 257}