The introduced SHA1_NOFINAL hasher was not sufficient for EAP-AKA,
[strongswan.git] / src / libstrongswan / library.c
1 /*
2 * Copyright (C) 2008 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 *
15 * $Id$
16 */
17
18 #include "library.h"
19
20 #include <stdlib.h>
21
22 #include <utils.h>
23 #include <chunk.h>
24 #include <utils/identification.h>
25 #include <utils/host.h>
26 #include <utils/leak_detective.h>
27
28 typedef struct private_library_t private_library_t;
29
30 /**
31 * private data of library
32 */
33 struct private_library_t {
34
35 /**
36 * public functions
37 */
38 library_t public;
39
40 #ifdef LEAK_DETECTIVE
41 /**
42 * Memory leak detective, if enabled
43 */
44 leak_detective_t *detective;
45 #endif /* LEAK_DETECTIVE */
46 };
47
48 /**
49 * library instance
50 */
51 library_t *lib;
52
53 /**
54 * Implementation of library_t.destroy
55 */
56 void library_deinit()
57 {
58 private_library_t *this = (private_library_t*)lib;
59
60 this->public.plugins->destroy(this->public.plugins);
61 this->public.settings->destroy(this->public.settings);
62 this->public.creds->destroy(this->public.creds);
63 this->public.crypto->destroy(this->public.crypto);
64 this->public.fetcher->destroy(this->public.fetcher);
65 this->public.db->destroy(this->public.db);
66 this->public.printf_hook->destroy(this->public.printf_hook);
67
68 #ifdef LEAK_DETECTIVE
69 if (this->detective)
70 {
71 this->detective->destroy(this->detective);
72 }
73 #endif /* LEAK_DETECTIVE */
74 free(this);
75 lib = NULL;
76 }
77
78 /*
79 * see header file
80 */
81 void library_init(char *settings)
82 {
83 printf_hook_t *pfh;
84 private_library_t *this = malloc_thing(private_library_t);
85 lib = &this->public;
86
87 #ifdef LEAK_DETECTIVE
88 this->detective = leak_detective_create();
89 #endif /* LEAK_DETECTIVE */
90
91 pfh = printf_hook_create();
92 this->public.printf_hook = pfh;
93
94 pfh->add_handler(pfh, 'b', mem_get_printf_hooks());
95 pfh->add_handler(pfh, 'B', chunk_get_printf_hooks());
96 pfh->add_handler(pfh, 'D', identification_get_printf_hooks());
97 pfh->add_handler(pfh, 'H', host_get_printf_hooks());
98 pfh->add_handler(pfh, 'N', enum_get_printf_hooks());
99 pfh->add_handler(pfh, 'T', time_get_printf_hooks());
100 pfh->add_handler(pfh, 'V', time_delta_get_printf_hooks());
101
102 this->public.crypto = crypto_factory_create();
103 this->public.creds = credential_factory_create();
104 this->public.fetcher = fetcher_manager_create();
105 this->public.db = database_factory_create();
106 this->public.settings = settings_create(settings);
107 this->public.plugins = plugin_loader_create();
108 }
109