]> git.ipfire.org Git - thirdparty/strongswan.git/blob - Source/charon/encoding/message.h
- created encoding package
[thirdparty/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 <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
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 typedef struct message_s message_t;
41
42 struct message_s {
43
44 /**
45 * @brief Sets the IKE major version of the message.
46 *
47 * @param this message_t object
48 * @param major_version major version to set
49 * @return SUCCESS
50 */
51 status_t (*set_major_version) (message_t *this,u_int8_t major_version);
52
53 /**
54 * @brief Gets the IKE major version of the message.
55 *
56 * @param this message_t object
57 * @return major version of the message
58 */
59 u_int8_t (*get_major_version) (message_t *this);
60
61 /**
62 * @brief Sets the IKE minor version of the message.
63 *
64 * @param this message_t object
65 * @param minor_version minor version to set
66 * @return SUCCESS
67 */
68 status_t (*set_minor_version) (message_t *this,u_int8_t minor_version);
69
70 /**
71 * @brief Gets the IKE minor version of the message.
72 *
73 * @param this message_t object
74 * @return minor version of the message
75 */
76 u_int8_t (*get_minor_version) (message_t *this);
77
78 /**
79 * @brief Sets the Message ID of the message.
80 *
81 * @param this message_t object
82 * @param message_id message_id to set
83 * @return SUCCESS
84 */
85 status_t (*set_message_id) (message_t *this,u_int32_t message_id);
86
87 /**
88 * @brief Gets the Message ID of the message.
89 *
90 * @param this message_t object
91 * @return message_id type of the message
92 */
93 u_int32_t (*get_message_id) (message_t *this);
94
95 /**
96 * @brief Gets the responder SPI of the message.
97 *
98 * @param this message_t object
99 * @return responder spi of the message
100 */
101 u_int64_t (*get_responder_spi) (message_t *this);
102
103 /**
104 * @brief Sets the IKE_SA ID of the message.
105 *
106 * @warning ike_sa_id gets cloned internaly and
107 * so can be destroyed afterwards.
108 *
109 * @param this message_t object
110 * @param ike_sa_id ike_sa_id to set
111 * @return
112 * - SUCCESS
113 * - OUT_OF_RES
114 * @return SUCCESS
115 */
116 status_t (*set_ike_sa_id) (message_t *this,ike_sa_id_t * ike_sa_id);
117
118 /**
119 * @brief Gets the IKE_SA ID of the message.
120 *
121 * @warning The returned ike_sa_id is a clone of the internal one.
122 * So it has to be destroyed by the caller.
123 *
124 * @param this message_t object
125 * @param ike_sa_id pointer to ike_sa_id pointer which will be set
126 * @return
127 * - SUCCESS
128 * - OUT_OF_RES
129 * - FAILED if no ike_sa_id is set
130 */
131 status_t (*get_ike_sa_id) (message_t *this,ike_sa_id_t **ike_sa_id);
132
133 /**
134 * @brief Sets the exchange type of the message.
135 *
136 * @param this message_t object
137 * @param exchange_type exchange_type to set
138 * @return SUCCESS
139 */
140 status_t (*set_exchange_type) (message_t *this,exchange_type_t exchange_type);
141
142 /**
143 * @brief Gets the exchange type of the message.
144 *
145 * @param this message_t object
146 * @return exchange type of the message
147 */
148 exchange_type_t (*get_exchange_type) (message_t *this);
149
150 /**
151 * @brief Sets the original initiator flag.
152 *
153 * @param this message_t object
154 * @param original_initiator TRUE if message is from original initiator
155 * @return SUCCESS
156 */
157 status_t (*set_original_initiator) (message_t *this,bool original_initiator);
158
159 /**
160 * @brief Gets original initiator flag.
161 *
162 * @param this message_t object
163 * @return TRUE if message is from original initiator, FALSE otherwise
164 */
165 bool (*get_original_initiator) (message_t *this);
166
167 /**
168 * @brief Sets the request flag.
169 *
170 * @param this message_t object
171 * @param original_initiator TRUE if message is a request, FALSE if it is a reply
172 * @return SUCCESS
173 */
174 status_t (*set_request) (message_t *this,bool request);
175
176 /**
177 * @brief Gets request flag.
178 *
179 * @param this message_t object
180 * @return TRUE if message is a request, FALSE if it is a reply
181 */
182 bool (*get_request) (message_t *this);
183
184 /**
185 * @brief Append a payload to the message.
186 *
187 * @param this message_t object
188 * @param payload payload to append
189 * @return
190 * - SUCCESS or
191 * - OUT_OF_RES
192 */
193 status_t (*add_payload) (message_t *this, payload_t *payload);
194
195 /**
196 * @brief Parses header of message
197 *
198 * @param this message_t object
199 * @return
200 * - SUCCESS if header could be parsed
201 * - OUT_OF_RES if out of ressources
202 * - PARSE_ERROR if corrupted/invalid data found
203 * - FAILED if consistence check of header failed
204 */
205 status_t (*parse_header) (message_t *this);
206
207 /**
208 * @brief Parses body of message
209 *
210 * @param this message_t object
211 * @return
212 * - SUCCESS if header could be parsed
213 * - NOT_SUPPORTED if unsupported payload are contained in body
214 * - OUT_OF_RES if out of ressources
215 * - FAILED if message type is not suppported!
216 * - PARSE_ERROR if corrupted/invalid data found
217 * - VERIFY_ERROR if verification of some payload failed
218 */
219 status_t (*parse_body) (message_t *this);
220
221 /**
222 * @brief Generates the UDP packet of specific message
223 *
224 * @param this message_t object
225 * @return
226 * - SUCCESS if packet could be generated
227 * - EXCHANGE_TYPE_NOT_SET if exchange type is currently not set
228 * ....
229 */
230 status_t (*generate) (message_t *this, packet_t **packet);
231 status_t (*get_source) (message_t *this, host_t **host);
232 status_t (*set_source) (message_t *this, host_t *host);
233 status_t (*get_destination) (message_t *this, host_t **host);
234 status_t (*set_destination) (message_t *this, host_t *host);
235 status_t (*get_payload_iterator) (message_t *this, linked_list_iterator_t **iterator);
236
237 /**
238 * @brief Destroys a message and all including objects
239 *
240 * @param this message_t object
241 * @return SUCCESS
242 */
243 status_t (*destroy) (message_t *this);
244 };
245
246 /**
247 * Creates an message_t object from a incoming UDP Packet.
248 *
249 * @warning the given packet_t object is not copied and gets
250 * destroyed in message_t's destroy call.
251 *
252 * @warning Packet is not parsed in here!
253 *
254 * - exchange_type is set to NOT_SET
255 * - original_initiator is set to TRUE
256 * - is_request is set to TRUE
257 *
258 * @param packet packet_t object which is assigned to message
259 *
260 * @return
261 * - created message_t object
262 * - NULL if out of ressources
263 */
264 message_t * message_create_from_packet(packet_t *packet);
265
266
267 /**
268 * Creates an empty message_t object.
269 *
270 * - exchange_type is set to NOT_SET
271 * - original_initiator is set to TRUE
272 * - is_request is set to TRUE
273 *
274 * @return
275 * - created message_t object
276 * - NULL if out of ressources
277 */
278 message_t * message_create();
279
280 #endif /*MESSAGE_H_*/