summaryrefslogtreecommitdiff
path: root/src/libstrongswan/library.c
diff options
context:
space:
mode:
authorYves-Alexis Perez <corsac@corsac.net>2012-06-28 21:16:07 +0200
committerYves-Alexis Perez <corsac@corsac.net>2012-06-28 21:16:07 +0200
commitb34738ed08c2227300d554b139e2495ca5da97d6 (patch)
tree62f33b52820f2e49f0e53c0f8c636312037c8054 /src/libstrongswan/library.c
parent0a9d51a49042a68daa15b0c74a2b7f152f52606b (diff)
downloadvyos-strongswan-b34738ed08c2227300d554b139e2495ca5da97d6.tar.gz
vyos-strongswan-b34738ed08c2227300d554b139e2495ca5da97d6.zip
Imported Upstream version 4.6.4
Diffstat (limited to 'src/libstrongswan/library.c')
-rw-r--r--src/libstrongswan/library.c79
1 files changed, 60 insertions, 19 deletions
diff --git a/src/libstrongswan/library.c b/src/libstrongswan/library.c
index b7e75aec5..cd6a41f44 100644
--- a/src/libstrongswan/library.c
+++ b/src/libstrongswan/library.c
@@ -22,12 +22,10 @@
#include <threading/thread.h>
#include <utils/identification.h>
#include <utils/host.h>
+#include <utils/hashtable.h>
#include <selectors/traffic_selector.h>
-#ifdef LEAK_DETECTIVE
-#include <utils/leak_detective.h>
-#endif
-#define CHECKSUM_LIBRARY IPSEC_DIR"/libchecksum.so"
+#define CHECKSUM_LIBRARY IPSEC_LIB_DIR"/libchecksum.so"
typedef struct private_library_t private_library_t;
@@ -41,12 +39,10 @@ struct private_library_t {
*/
library_t public;
-#ifdef LEAK_DETECTIVE
/**
- * Memory leak detective, if enabled
+ * Hashtable with registered objects (name => object)
*/
- leak_detective_t *detective;
-#endif /* LEAK_DETECTIVE */
+ hashtable_t *objects;
};
/**
@@ -55,7 +51,7 @@ struct private_library_t {
library_t *lib;
/**
- * Implementation of library_t.destroy
+ * Deinitialize library
*/
void library_deinit()
{
@@ -65,6 +61,9 @@ void library_deinit()
detailed = lib->settings->get_bool(lib->settings,
"libstrongswan.leak_detective.detailed", TRUE);
+ /* make sure the cache is clear before unloading plugins */
+ lib->credmgr->flush_cache(lib->credmgr, CERT_ANY);
+
this->public.scheduler->destroy(this->public.scheduler);
this->public.processor->destroy(this->public.processor);
this->public.plugins->destroy(this->public.plugins);
@@ -76,18 +75,17 @@ void library_deinit()
this->public.fetcher->destroy(this->public.fetcher);
this->public.db->destroy(this->public.db);
this->public.printf_hook->destroy(this->public.printf_hook);
+ this->objects->destroy(this->objects);
if (this->public.integrity)
{
this->public.integrity->destroy(this->public.integrity);
}
-#ifdef LEAK_DETECTIVE
- if (this->detective)
+ if (lib->leak_detective)
{
- this->detective->report(this->detective, detailed);
- this->detective->destroy(this->detective);
+ lib->leak_detective->report(lib->leak_detective, detailed);
+ lib->leak_detective->destroy(lib->leak_detective);
}
-#endif /* LEAK_DETECTIVE */
threads_deinit();
@@ -95,21 +93,63 @@ void library_deinit()
lib = NULL;
}
+METHOD(library_t, get, void*,
+ private_library_t *this, char *name)
+{
+ return this->objects->get(this->objects, name);
+}
+
+METHOD(library_t, set, bool,
+ private_library_t *this, char *name, void *object)
+{
+ if (object)
+ {
+ if (this->objects->get(this->objects, name))
+ {
+ return FALSE;
+ }
+ this->objects->put(this->objects, name, object);
+ return TRUE;
+ }
+ return this->objects->remove(this->objects, name) != NULL;
+}
+
+/**
+ * Hashtable hash function
+ */
+static u_int hash(char *key)
+{
+ return chunk_hash(chunk_create(key, strlen(key)));
+}
+
+/**
+ * Hashtable equals function
+ */
+static bool equals(char *a, char *b)
+{
+ return streq(a, b);
+}
+
/*
* see header file
*/
bool library_init(char *settings)
{
+ private_library_t *this;
printf_hook_t *pfh;
- private_library_t *this = malloc_thing(private_library_t);
+
+ INIT(this,
+ .public = {
+ .get = _get,
+ .set = _set,
+ },
+ );
lib = &this->public;
threads_init();
- lib->leak_detective = FALSE;
-
#ifdef LEAK_DETECTIVE
- this->detective = leak_detective_create();
+ lib->leak_detective = leak_detective_create();
#endif /* LEAK_DETECTIVE */
pfh = printf_hook_create();
@@ -136,6 +176,8 @@ bool library_init(char *settings)
pfh->add_handler(pfh, 'R', traffic_selector_printf_hook,
PRINTF_HOOK_ARGTYPE_POINTER, PRINTF_HOOK_ARGTYPE_END);
+ this->objects = hashtable_create((hashtable_hash_t)hash,
+ (hashtable_equals_t)equals, 4);
this->public.settings = settings_create(settings);
this->public.crypto = crypto_factory_create();
this->public.creds = credential_factory_create();
@@ -146,7 +188,6 @@ bool library_init(char *settings)
this->public.processor = processor_create();
this->public.scheduler = scheduler_create();
this->public.plugins = plugin_loader_create();
- this->public.integrity = NULL;
if (lib->settings->get_bool(lib->settings,
"libstrongswan.integrity_test", FALSE))