moved management of additional IMC/IMV IDs to agent
[strongswan.git] / src / libimcv / plugins / imc_test / imc_test_state.c
1 /*
2 * Copyright (C) 2011 Andreas Steffen, HSR Hochschule fuer Technik Rapperswil
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 */
14
15 #include "imc_test_state.h"
16
17 #include <debug.h>
18 #include <utils/linked_list.h>
19
20 typedef struct private_imc_test_state_t private_imc_test_state_t;
21
22 /**
23 * Private data of an imc_test_state_t object.
24 */
25 struct private_imc_test_state_t {
26
27 /**
28 * Public members of imc_test_state_t
29 */
30 imc_test_state_t public;
31
32 /**
33 * TNCCS connection ID
34 */
35 TNC_ConnectionID connection_id;
36
37 /**
38 * TNCCS connection state
39 */
40 TNC_ConnectionState state;
41
42 /**
43 * Does the TNCCS connection support long message types?
44 */
45 bool has_long;
46
47 /**
48 * Does the TNCCS connection support exclusive delivery?
49 */
50 bool has_excl;
51
52 /**
53 * Command to transmit to IMV
54 */
55 char *command;
56
57 /**
58 * Is it the first handshake?
59 */
60 bool first_handshake;
61
62 /**
63 * Do a handshake retry
64 */
65 bool handshake_retry;
66
67 };
68
69 METHOD(imc_state_t, get_connection_id, TNC_ConnectionID,
70 private_imc_test_state_t *this)
71 {
72 return this->connection_id;
73 }
74
75 METHOD(imc_state_t, has_long, bool,
76 private_imc_test_state_t *this)
77 {
78 return this->has_long;
79 }
80
81 METHOD(imc_state_t, has_excl, bool,
82 private_imc_test_state_t *this)
83 {
84 return this->has_excl;
85 }
86
87 METHOD(imc_state_t, set_flags, void,
88 private_imc_test_state_t *this, bool has_long, bool has_excl)
89 {
90 this->has_long = has_long;
91 this->has_excl = has_excl;
92 }
93
94 METHOD(imc_state_t, change_state, void,
95 private_imc_test_state_t *this, TNC_ConnectionState new_state)
96 {
97 this->state = new_state;
98 }
99
100 METHOD(imc_state_t, destroy, void,
101 private_imc_test_state_t *this)
102 {
103 free(this->command);
104 free(this);
105 }
106
107 METHOD(imc_test_state_t, get_command, char*,
108 private_imc_test_state_t *this)
109 {
110 return this->command;
111 }
112
113 METHOD(imc_test_state_t, set_command, void,
114 private_imc_test_state_t *this, char* command)
115 {
116 char *old_command;
117
118 old_command = this->command;
119 this->command = strdup(command);
120 free(old_command);
121 }
122
123 METHOD(imc_test_state_t, is_first_handshake, bool,
124 private_imc_test_state_t *this)
125 {
126 bool first;
127
128 /* test and reset first_handshake flag */
129 first= this->first_handshake;
130 this->first_handshake = FALSE;
131 return first;
132 }
133
134 METHOD(imc_test_state_t, do_handshake_retry, bool,
135 private_imc_test_state_t *this)
136 {
137 bool retry;
138
139 /* test and reset handshake_retry flag */
140 retry = this->handshake_retry;
141 this->handshake_retry = FALSE;
142 return retry;
143 }
144
145 /**
146 * Described in header.
147 */
148 imc_state_t *imc_test_state_create(TNC_ConnectionID connection_id,
149 char *command, bool retry)
150 {
151 private_imc_test_state_t *this;
152
153 INIT(this,
154 .public = {
155 .interface = {
156 .get_connection_id = _get_connection_id,
157 .has_long = _has_long,
158 .has_excl = _has_excl,
159 .set_flags = _set_flags,
160 .change_state = _change_state,
161 .destroy = _destroy,
162 },
163 .get_command = _get_command,
164 .set_command = _set_command,
165 .is_first_handshake = _is_first_handshake,
166 .do_handshake_retry = _do_handshake_retry,
167 },
168 .state = TNC_CONNECTION_STATE_CREATE,
169 .connection_id = connection_id,
170 .command = strdup(command),
171 .first_handshake = TRUE,
172 .handshake_retry = retry,
173 );
174
175 return &this->public.interface;
176 }
177
178