capability API to allow plugin-controlled capability set
[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 #ifdef LEAK_DETECTIVE
27 #include <utils/leak_detective.h>
28 #endif
29
30 typedef struct private_library_t private_library_t;
31
32 /**
33 * private data of library
34 */
35 struct private_library_t {
36
37 /**
38 * public functions
39 */
40 library_t public;
41
42 #ifdef LEAK_DETECTIVE
43 /**
44 * Memory leak detective, if enabled
45 */
46 leak_detective_t *detective;
47 #endif /* LEAK_DETECTIVE */
48 };
49
50 /**
51 * library instance
52 */
53 library_t *lib;
54
55 /**
56 * Implementation of library_t.destroy
57 */
58 void library_deinit()
59 {
60 private_library_t *this = (private_library_t*)lib;
61
62 this->public.plugins->destroy(this->public.plugins);
63 this->public.settings->destroy(this->public.settings);
64 this->public.creds->destroy(this->public.creds);
65 this->public.crypto->destroy(this->public.crypto);
66 this->public.fetcher->destroy(this->public.fetcher);
67 this->public.db->destroy(this->public.db);
68 this->public.printf_hook->destroy(this->public.printf_hook);
69
70 #ifdef LEAK_DETECTIVE
71 if (this->detective)
72 {
73 this->detective->destroy(this->detective);
74 }
75 #endif /* LEAK_DETECTIVE */
76 free(this);
77 lib = NULL;
78 }
79
80 /*
81 * see header file
82 */
83 void library_init(char *settings)
84 {
85 printf_hook_t *pfh;
86 private_library_t *this = malloc_thing(private_library_t);
87 lib = &this->public;
88
89 lib->leak_detective = FALSE;
90
91 #ifdef LEAK_DETECTIVE
92 this->detective = leak_detective_create();
93 #endif /* LEAK_DETECTIVE */
94
95 pfh = printf_hook_create();
96 this->public.printf_hook = pfh;
97
98 pfh->add_handler(pfh, 'b', mem_get_printf_hooks());
99 pfh->add_handler(pfh, 'B', chunk_get_printf_hooks());
100 pfh->add_handler(pfh, 'D', identification_get_printf_hooks());
101 pfh->add_handler(pfh, 'H', host_get_printf_hooks());
102 pfh->add_handler(pfh, 'N', enum_get_printf_hooks());
103 pfh->add_handler(pfh, 'T', time_get_printf_hooks());
104 pfh->add_handler(pfh, 'V', time_delta_get_printf_hooks());
105
106 this->public.crypto = crypto_factory_create();
107 this->public.creds = credential_factory_create();
108 this->public.fetcher = fetcher_manager_create();
109 this->public.db = database_factory_create();
110 this->public.settings = settings_create(settings);
111 this->public.plugins = plugin_loader_create();
112 }
113