store the long and excl flags in the connection state
[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
19 typedef struct private_imc_test_state_t private_imc_test_state_t;
20
21 /**
22 * Private data of an imc_test_state_t object.
23 */
24 struct private_imc_test_state_t {
25
26 /**
27 * Public members of imc_test_state_t
28 */
29 imc_test_state_t public;
30
31 /**
32 * TNCCS connection ID
33 */
34 TNC_ConnectionID connection_id;
35
36 /**
37 * TNCCS connection state
38 */
39 TNC_ConnectionState state;
40
41 /**
42 * Does the TNCCS connection support long message types?
43 */
44 bool has_long;
45
46 /**
47 * Does the TNCCS connection support exclusive delivery?
48 */
49 bool has_excl;
50
51 /**
52 * Command to transmit to IMV
53 */
54 char *command;
55
56 /**
57 * Is it the first handshake?
58 */
59 bool first_handshake;
60
61 /**
62 * Do a handshake retry
63 */
64 bool handshake_retry;
65 };
66
67 METHOD(imc_state_t, get_connection_id, TNC_ConnectionID,
68 private_imc_test_state_t *this)
69 {
70 return this->connection_id;
71 }
72
73 METHOD(imc_state_t, has_long, bool,
74 private_imc_test_state_t *this)
75 {
76 return this->has_long;
77 }
78
79 METHOD(imc_state_t, has_excl, bool,
80 private_imc_test_state_t *this)
81 {
82 return this->has_excl;
83 }
84
85 METHOD(imc_state_t, set_flags, void,
86 private_imc_test_state_t *this, bool has_long, bool has_excl)
87 {
88 this->has_long = has_long;
89 this->has_excl = has_excl;
90 }
91
92 METHOD(imc_state_t, change_state, void,
93 private_imc_test_state_t *this, TNC_ConnectionState new_state)
94 {
95 this->state = new_state;
96 }
97
98 METHOD(imc_state_t, destroy, void,
99 private_imc_test_state_t *this)
100 {
101 free(this->command);
102 free(this);
103 }
104
105 METHOD(imc_test_state_t, get_command, char*,
106 private_imc_test_state_t *this)
107 {
108 return this->command;
109 }
110
111 METHOD(imc_test_state_t, set_command, void,
112 private_imc_test_state_t *this, char* command)
113 {
114 char *old_command;
115
116 old_command = this->command;
117 this->command = strdup(command);
118 free(old_command);
119 }
120
121 METHOD(imc_test_state_t, is_first_handshake, bool,
122 private_imc_test_state_t *this)
123 {
124 bool first;
125
126 /* test and reset first_handshake flag */
127 first= this->first_handshake;
128 this->first_handshake = FALSE;
129 return first;
130 }
131
132 METHOD(imc_test_state_t, do_handshake_retry, bool,
133 private_imc_test_state_t *this)
134 {
135 bool retry;
136
137 /* test and reset handshake_retry flag */
138 retry = this->handshake_retry;
139 this->handshake_retry = FALSE;
140 return retry;
141 }
142
143 /**
144 * Described in header.
145 */
146 imc_state_t *imc_test_state_create(TNC_ConnectionID connection_id,
147 char *command, bool retry)
148 {
149 private_imc_test_state_t *this;
150
151 INIT(this,
152 .public = {
153 .interface = {
154 .get_connection_id = _get_connection_id,
155 .has_long = _has_long,
156 .has_excl = _has_excl,
157 .set_flags = _set_flags,
158 .change_state = _change_state,
159 .destroy = _destroy,
160 },
161 .get_command = _get_command,
162 .set_command = _set_command,
163 .is_first_handshake = _is_first_handshake,
164 .do_handshake_retry = _do_handshake_retry,
165 },
166 .state = TNC_CONNECTION_STATE_CREATE,
167 .connection_id = connection_id,
168 .command = strdup(command),
169 .first_handshake = TRUE,
170 .handshake_retry = retry,
171 );
172
173 return &this->public.interface;
174 }
175
176