The introduced SHA1_NOFINAL hasher was not sufficient for EAP-AKA,
[strongswan.git] / src / libstrongswan / library.c
index 0394f32..e265a1a 100644 (file)
@@ -1,13 +1,5 @@
-/**
- * @file library.c
- *
- * @brief Library (de-)initialization.
- *
- */
-
 /*
- * Copyright (C) 2005-2006 Martin Willi
- * Copyright (C) 2005 Jan Hutter
+ * Copyright (C) 2008 Martin Willi
  * Hochschule fuer Technik Rapperswil
  *
  * This program is free software; you can redistribute it and/or modify it
  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  * for more details.
+ *
+ * $Id$
  */
 
-#include <stdarg.h>
-#include <stdio.h>
-
 #include "library.h"
 
+#include <stdlib.h>
+
+#include <utils.h>
+#include <chunk.h>
+#include <utils/identification.h>
+#include <utils/host.h>
+#include <utils/leak_detective.h>
+
+typedef struct private_library_t private_library_t;
+
+/**
+ * private data of library
+ */
+struct private_library_t {
+
+       /**
+        * public functions
+        */
+       library_t public;
+
+#ifdef LEAK_DETECTIVE
+       /**
+        * Memory leak detective, if enabled
+        */
+       leak_detective_t *detective;
+#endif /* LEAK_DETECTIVE */
+};
+
+/**
+ * library instance
+ */
+library_t *lib;
+
 /**
- * default dbg function which printf all to stderr
+ * Implementation of library_t.destroy
+ */
+void library_deinit()
+{
+       private_library_t *this = (private_library_t*)lib;
+
+       this->public.plugins->destroy(this->public.plugins);
+       this->public.settings->destroy(this->public.settings);
+       this->public.creds->destroy(this->public.creds);
+       this->public.crypto->destroy(this->public.crypto);
+       this->public.fetcher->destroy(this->public.fetcher);
+       this->public.db->destroy(this->public.db);
+       this->public.printf_hook->destroy(this->public.printf_hook);
+       
+#ifdef LEAK_DETECTIVE
+       if (this->detective)
+       {
+               this->detective->destroy(this->detective);
+       }
+#endif /* LEAK_DETECTIVE */
+       free(this);
+       lib = NULL;
+}
+
+/*
+ * see header file
  */
-static void dbg_stderr(int level, char *fmt, ...)
+void library_init(char *settings)
 {
-       va_list args;
+       printf_hook_t *pfh;
+       private_library_t *this = malloc_thing(private_library_t);
+       lib = &this->public;
+       
+#ifdef LEAK_DETECTIVE
+       this->detective = leak_detective_create();
+#endif /* LEAK_DETECTIVE */
+
+       pfh = printf_hook_create();
+       this->public.printf_hook = pfh;
+       
+       pfh->add_handler(pfh, 'b', mem_get_printf_hooks());
+       pfh->add_handler(pfh, 'B', chunk_get_printf_hooks());
+       pfh->add_handler(pfh, 'D', identification_get_printf_hooks());
+       pfh->add_handler(pfh, 'H', host_get_printf_hooks());
+       pfh->add_handler(pfh, 'N', enum_get_printf_hooks());
+       pfh->add_handler(pfh, 'T', time_get_printf_hooks());
+       pfh->add_handler(pfh, 'V', time_delta_get_printf_hooks());
        
-       va_start(args, fmt);
-       vfprintf(stderr, fmt, args);
-       fprintf(stderr, "\n");
-       va_end(args);
+       this->public.crypto = crypto_factory_create();
+       this->public.creds = credential_factory_create();
+       this->public.fetcher = fetcher_manager_create();
+       this->public.db = database_factory_create();
+       this->public.settings = settings_create(settings);
+       this->public.plugins = plugin_loader_create();
 }
 
-void (*dbg) (int level, char *fmt, ...) = dbg_stderr;