already had the correct formatting
[strongswan.git] / src / pluto / 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 * $Id: library.c 4936 2009-03-12 18:07:32Z tobias $
17 */
18
19 #include "library.h"
20
21 #include <stdlib.h>
22
23 #include <utils.h>
24 #include <chunk.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.settings->destroy(this->public.settings);
62 this->public.printf_hook->destroy(this->public.printf_hook);
63
64 #ifdef LEAK_DETECTIVE
65 if (this->detective)
66 {
67 this->detective->destroy(this->detective);
68 }
69 #endif /* LEAK_DETECTIVE */
70 free(this);
71 lib = NULL;
72 }
73
74 /*
75 * see header file
76 */
77 void library_init(char *settings)
78 {
79 printf_hook_t *pfh;
80 private_library_t *this = malloc_thing(private_library_t);
81 lib = &this->public;
82
83 lib->leak_detective = FALSE;
84
85 #ifdef LEAK_DETECTIVE
86 this->detective = leak_detective_create();
87 #endif /* LEAK_DETECTIVE */
88
89 pfh = printf_hook_create();
90 this->public.printf_hook = pfh;
91
92 pfh->add_handler(pfh, 'b', mem_printf_hook,
93 PRINTF_HOOK_ARGTYPE_POINTER, PRINTF_HOOK_ARGTYPE_INT,
94 PRINTF_HOOK_ARGTYPE_END);
95 pfh->add_handler(pfh, 'B', chunk_printf_hook,
96 PRINTF_HOOK_ARGTYPE_POINTER, PRINTF_HOOK_ARGTYPE_END);
97 pfh->add_handler(pfh, 'T', time_printf_hook,
98 PRINTF_HOOK_ARGTYPE_POINTER, PRINTF_HOOK_ARGTYPE_INT,
99 PRINTF_HOOK_ARGTYPE_END);
100 pfh->add_handler(pfh, 'V', time_delta_printf_hook,
101 PRINTF_HOOK_ARGTYPE_POINTER, PRINTF_HOOK_ARGTYPE_POINTER,
102 PRINTF_HOOK_ARGTYPE_END);
103
104 this->public.settings = settings_create(settings);
105 }
106