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