Initialize TKM client library in tkm.c
[strongswan.git] / src / charon-tkm / src / tkm / tkm.c
1 /*
2 * Copyright (C) 2012 Reto Buerki
3 * Copyright (C) 2012 Adrian-Ken Rueegsegger
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 <tkm/client.h>
18 #include <tkm/constants.h>
19
20 #include "tkm.h"
21
22 #define IKE_SOCKET "/tmp/tkm.rpc.ike"
23
24 typedef struct private_tkm_t private_tkm_t;
25
26 /**
27 * Private additions to tkm_t.
28 */
29 struct private_tkm_t {
30
31 /**
32 * Public members of tkm_t.
33 */
34 tkm_t public;
35 };
36
37 /**
38 * Single instance of tkm_t.
39 */
40 tkm_t *tkm = NULL;
41
42 /**
43 * Described in header.
44 */
45 bool tkm_init()
46 {
47 private_tkm_t *this;
48
49 /* initialize TKM client library */
50 tkmlib_init();
51 if (ike_init(IKE_SOCKET) != TKM_OK)
52 {
53 tkmlib_final();
54 return FALSE;
55 }
56
57 if (ike_tkm_reset() != TKM_OK)
58 {
59 tkmlib_final();
60 return FALSE;
61 }
62
63 INIT(this,
64 .public = {
65 .idmgr = tkm_id_manager_create(),
66 },
67 );
68 tkm = &this->public;
69
70 return TRUE;
71 }
72
73 /**
74 * Described in header.
75 */
76 void tkm_deinit()
77 {
78 if (!tkm)
79 {
80 return;
81 }
82 private_tkm_t *this = (private_tkm_t*)tkm;
83 this->public.idmgr->destroy(this->public.idmgr);
84
85 tkmlib_final();
86 free(this);
87 tkm = NULL;
88 }