Implement Esa Event Service (EES)
[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 #define EES_SOCKET "/tmp/tkm.rpc.ees"
24
25 typedef struct private_tkm_t private_tkm_t;
26
27 extern result_type ees_server_init(const char * const address);
28 extern void ees_server_finalize(void);
29
30 /*
31 * Private additions to tkm_t.
32 */
33 struct private_tkm_t {
34
35 /**
36 * Public members of tkm_t.
37 */
38 tkm_t public;
39 };
40
41 /**
42 * Single instance of tkm_t.
43 */
44 tkm_t *tkm = NULL;
45
46 /**
47 * Described in header.
48 */
49 bool tkm_init()
50 {
51 private_tkm_t *this;
52
53 active_requests_type max_requests;
54 nc_id_type nc;
55 dh_id_type dh;
56 cc_id_type cc;
57 ae_id_type ae;
58 isa_id_type isa;
59 esa_id_type esa;
60
61 /* initialize TKM client library */
62 tkmlib_init();
63 if (ike_init(IKE_SOCKET) != TKM_OK)
64 {
65 tkmlib_final();
66 return FALSE;
67 }
68 /* init esa event service */
69 if (ees_server_init(EES_SOCKET) != TKM_OK)
70 {
71 tkmlib_final();
72 return FALSE;
73 }
74
75 if (ike_tkm_reset() != TKM_OK)
76 {
77 ees_server_finalize();
78 tkmlib_final();
79 return FALSE;
80 }
81
82 /* get limits from tkm */
83 if (ike_tkm_limits(&max_requests, &nc, &dh, &cc, &ae, &isa, &esa) != TKM_OK)
84 {
85 ees_server_finalize();
86 tkmlib_final();
87 return FALSE;
88 }
89
90 const tkm_limits_t limits = {nc, dh, isa, ae, esa};
91
92 INIT(this,
93 .public = {
94 .idmgr = tkm_id_manager_create(limits),
95 .chunk_map = tkm_chunk_map_create(),
96 },
97 );
98 tkm = &this->public;
99
100 return TRUE;
101 }
102
103 /**
104 * Described in header.
105 */
106 void tkm_deinit()
107 {
108 if (!tkm)
109 {
110 return;
111 }
112 private_tkm_t *this = (private_tkm_t*)tkm;
113 this->public.idmgr->destroy(this->public.idmgr);
114 this->public.chunk_map->destroy(this->public.chunk_map);
115
116 ees_server_finalize();
117
118 tkmlib_final();
119 free(this);
120 tkm = NULL;
121 }