/*
- * Copyright (C) 2009-2018 Tobias Brunner
+ * Copyright (C) 2009-2025 Tobias Brunner
* Copyright (C) 2008 Martin Willi
*
* Copyright (C) secunet Security Networks AG
}
}
+#define MAX_LIBSTRONGSWAN_INIT_FUNCTIONS 10
+
+/**
+ * Static array for init function registration using __attribute__((constructor))
+ */
+static library_init_t init_functions[MAX_LIBSTRONGSWAN_INIT_FUNCTIONS];
+static int init_function_count;
+
+/**
+ * Described in header
+ */
+void library_init_register(library_init_t init)
+{
+ if (init_function_count < MAX_LIBSTRONGSWAN_INIT_FUNCTIONS - 1)
+ {
+ init_functions[init_function_count++] = init;
+ }
+ else
+ {
+ fprintf(stderr, "failed to register init function, please increase "
+ "MAX_LIBSTRONGSWAN_INIT_FUNCTIONS");
+ }
+}
+
/**
* Register plugins if built statically
*/
{
private_library_t *this = (private_library_t*)lib;
bool detailed;
+ int i;
if (!this || !ref_put(&this->ref))
{ /* have more users */
/* make sure the cache is clear before unloading plugins */
lib->credmgr->flush_cache(lib->credmgr, CERT_ANY);
+ for (i = 0; i < init_function_count; ++i)
+ {
+ init_functions[i](FALSE);
+ }
+
key_exchange_deinit();
this->public.streams->destroy(this->public.streams);
key_exchange_init();
+ for (i = 0; i < init_function_count; ++i)
+ {
+ if (!init_functions[i](TRUE))
+ {
+ this->init_failed = TRUE;
+ }
+ }
return !this->init_failed;
}
/*
- * Copyright (C) 2010-2018 Tobias Brunner
+ * Copyright (C) 2010-2025 Tobias Brunner
* Copyright (C) 2008 Martin Willi
*
* Copyright (C) secunet Security Networks AG
*/
void library_deinit();
+/**
+ * Custom function called during init/deinit of a library.
+ *
+ * @param init TRUE during init, FALSE during deinit
+ * @return FALSE if an error occurred and init should fail
+ */
+typedef bool (*library_init_t)(bool init);
+
+/**
+ * Register a custom init function that's called at the end of library_init()
+ * and the start of library_deinit().
+ *
+ * To be called from __attribute__((constructor)) functions.
+ *
+ * @param init init function
+ */
+void library_init_register(library_init_t init);
+
/**
* Library instance, set after library_init() and before library_deinit() calls.
*/