2b2a14a1ceb640639d4ce5b4d3e7b1641294cb7b
[strongswan.git] / Source / charon / encoding / message.h
1 /**
2 * @file message.h
3 *
4 * @brief Class message_t. Object of this type represents an IKEv2-Message.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #ifndef MESSAGE_H_
24 #define MESSAGE_H_
25
26 #include <types.h>
27 #include <sa/ike_sa_id.h>
28 #include <network/packet.h>
29 #include <encoding/payloads/ike_header.h>
30 #include <utils/linked_list.h>
31
32
33 typedef struct message_t message_t;
34
35 /**
36 * @brief This class is used to represent an IKEv2-Message.
37 *
38 * An IKEv2-Message is either a request or response.
39 */
40 struct message_t {
41
42 /**
43 * @brief Sets the IKE major version of the message.
44 *
45 * @param this message_t object
46 * @param major_version major version to set
47 * @return SUCCESS
48 */
49 status_t (*set_major_version) (message_t *this,u_int8_t major_version);
50
51 /**
52 * @brief Gets the IKE major version of the message.
53 *
54 * @param this message_t object
55 * @return major version of the message
56 */
57 u_int8_t (*get_major_version) (message_t *this);
58
59 /**
60 * @brief Sets the IKE minor version of the message.
61 *
62 * @param this message_t object
63 * @param minor_version minor version to set
64 * @return SUCCESS
65 */
66 status_t (*set_minor_version) (message_t *this,u_int8_t minor_version);
67
68 /**
69 * @brief Gets the IKE minor version of the message.
70 *
71 * @param this message_t object
72 * @return minor version of the message
73 */
74 u_int8_t (*get_minor_version) (message_t *this);
75
76 /**
77 * @brief Sets the Message ID of the message.
78 *
79 * @param this message_t object
80 * @param message_id message_id to set
81 * @return SUCCESS
82 */
83 status_t (*set_message_id) (message_t *this,u_int32_t message_id);
84
85 /**
86 * @brief Gets the Message ID of the message.
87 *
88 * @param this message_t object
89 * @return message_id type of the message
90 */
91 u_int32_t (*get_message_id) (message_t *this);
92
93 /**
94 * @brief Gets the responder SPI of the message.
95 *
96 * @param this message_t object
97 * @return responder spi of the message
98 */
99 u_int64_t (*get_responder_spi) (message_t *this);
100
101 /**
102 * @brief Sets the IKE_SA ID of the message.
103 *
104 * @warning ike_sa_id gets cloned internaly and
105 * so can be destroyed afterwards.
106 *
107 * @param this message_t object
108 * @param ike_sa_id ike_sa_id to set
109 * @return
110 * - SUCCESS
111 * - OUT_OF_RES
112 * @return SUCCESS
113 */
114 status_t (*set_ike_sa_id) (message_t *this,ike_sa_id_t * ike_sa_id);
115
116 /**
117 * @brief Gets the IKE_SA ID of the message.
118 *
119 * @warning The returned ike_sa_id is a clone of the internal one.
120 * So it has to be destroyed by the caller.
121 *
122 * @param this message_t object
123 * @param ike_sa_id pointer to ike_sa_id pointer which will be set
124 * @return
125 * - SUCCESS
126 * - OUT_OF_RES
127 * - FAILED if no ike_sa_id is set
128 */
129 status_t (*get_ike_sa_id) (message_t *this,ike_sa_id_t **ike_sa_id);
130
131 /**
132 * @brief Sets the exchange type of the message.
133 *
134 * @param this message_t object
135 * @param exchange_type exchange_type to set
136 * @return SUCCESS
137 */
138 status_t (*set_exchange_type) (message_t *this,exchange_type_t exchange_type);
139
140 /**
141 * @brief Gets the exchange type of the message.
142 *
143 * @param this message_t object
144 * @return exchange type of the message
145 */
146 exchange_type_t (*get_exchange_type) (message_t *this);
147
148 /**
149 * @brief Sets the original initiator flag.
150 *
151 * @param this message_t object
152 * @param original_initiator TRUE if message is from original initiator
153 * @return SUCCESS
154 */
155 status_t (*set_original_initiator) (message_t *this,bool original_initiator);
156
157 /**
158 * @brief Gets original initiator flag.
159 *
160 * @param this message_t object
161 * @return TRUE if message is from original initiator, FALSE otherwise
162 */
163 bool (*get_original_initiator) (message_t *this);
164
165 /**
166 * @brief Sets the request flag.
167 *
168 * @param this message_t object
169 * @param original_initiator TRUE if message is a request, FALSE if it is a reply
170 * @return SUCCESS
171 */
172 status_t (*set_request) (message_t *this,bool request);
173
174 /**
175 * @brief Gets request flag.
176 *
177 * @param this message_t object
178 * @return TRUE if message is a request, FALSE if it is a reply
179 */
180 bool (*get_request) (message_t *this);
181
182 /**
183 * @brief Append a payload to the message.
184 *
185 * @param this message_t object
186 * @param payload payload to append
187 * @return
188 * - SUCCESS or
189 * - OUT_OF_RES
190 */
191 status_t (*add_payload) (message_t *this, payload_t *payload);
192
193 /**
194 * @brief Parses header of message
195 *
196 * @param this message_t object
197 * @return
198 * - SUCCESS if header could be parsed
199 * - OUT_OF_RES if out of ressources
200 * - PARSE_ERROR if corrupted/invalid data found
201 * - FAILED if consistence check of header failed
202 */
203 status_t (*parse_header) (message_t *this);
204
205 /**
206 * @brief Parses body of message.
207 *
208 * The body gets not only parsed, but rather it gets verified.
209 * All payloads are verified if they are allowed to exist in the message
210 * of this type and if their own structure is ok.
211 *
212 * @param this message_t object
213 * @return
214 * - SUCCESS if header could be parsed
215 * - NOT_SUPPORTED if unsupported payload are contained in body
216 * - OUT_OF_RES if out of ressources
217 * - FAILED if message type is not suppported!
218 * - PARSE_ERROR if corrupted/invalid data found
219 * - VERIFY_ERROR if verification of some payload failed
220 */
221 status_t (*parse_body) (message_t *this);
222
223 /**
224 * @brief Generates the UDP packet of specific message
225 *
226 * @param this message_t object
227 * @return
228 * - SUCCESS if packet could be generated
229 * - EXCHANGE_TYPE_NOT_SET if exchange type is currently not set
230 * ....
231 */
232 status_t (*generate) (message_t *this, packet_t **packet);
233 status_t (*get_source) (message_t *this, host_t **host);
234 status_t (*set_source) (message_t *this, host_t *host);
235 status_t (*get_destination) (message_t *this, host_t **host);
236 status_t (*set_destination) (message_t *this, host_t *host);
237 status_t (*get_payload_iterator) (message_t *this, iterator_t **iterator);
238
239 /**
240 * @brief Destroys a message and all including objects
241 *
242 * @param this message_t object
243 * @return SUCCESS
244 */
245 status_t (*destroy) (message_t *this);
246 };
247
248 /**
249 * Creates an message_t object from a incoming UDP Packet.
250 *
251 * @warning the given packet_t object is not copied and gets
252 * destroyed in message_t's destroy call.
253 *
254 * @warning Packet is not parsed in here!
255 *
256 * - exchange_type is set to NOT_SET
257 * - original_initiator is set to TRUE
258 * - is_request is set to TRUE
259 *
260 * @param packet packet_t object which is assigned to message
261 *
262 * @return
263 * - created message_t object
264 * - NULL if out of ressources
265 */
266 message_t * message_create_from_packet(packet_t *packet);
267
268
269 /**
270 * Creates an empty message_t object.
271 *
272 * - exchange_type is set to NOT_SET
273 * - original_initiator is set to TRUE
274 * - is_request is set to TRUE
275 *
276 * @return
277 * - created message_t object
278 * - NULL if out of ressources
279 */
280 message_t * message_create();
281
282 #endif /*MESSAGE_H_*/