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