6b0984bdd5fc8b153a3c339508e4021c1365ab8c
[strongswan.git] / Source / charon / 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 "packet.h"
28 #include "ike_sa_id.h"
29 #include "payloads/ike_header.h"
30
31
32
33
34 /**
35 * @brief This class is used to represent an IKEv2-Message.
36 *
37 * An IKEv2-Message is either a request or response.
38 */
39 typedef struct message_s message_t;
40
41 struct message_s {
42
43 /**
44 * @brief Sets the Message ID of the message.
45 *
46 * @param this message_t object
47 * @param message_id message_id to set
48 * @return SUCCESS
49 */
50 status_t (*set_message_id) (message_t *this,u_int32_t message_id);
51
52 /**
53 * @brief Gets the Message ID of the message.
54 *
55 * @param this message_t object
56 * @return message_id type of the message
57 */
58 u_int32_t (*get_message_id) (message_t *this);
59
60 /**
61 * @brief Sets the IKE_SA ID of the message.
62 *
63 * @warning ike_sa_id gets cloned internaly and
64 * so can be destroyed afterwards.
65 *
66 * @param this message_t object
67 * @param ike_sa_id ike_sa_id to set
68 * @return
69 * - SUCCESS
70 * - OUT_OF_RES
71 * @return SUCCESS
72 */
73 status_t (*set_ike_sa_id) (message_t *this,ike_sa_id_t * ike_sa_id);
74
75 /**
76 * @brief Gets the IKE_SA ID of the message.
77 *
78 * @warning The returned ike_sa_id is a clone of the internal one.
79 * So it has to be destroyed by the caller.
80 *
81 * @param this message_t object
82 * @param ike_sa_id pointer to ike_sa_id pointer which will be set
83 * @return
84 * - SUCCESS
85 * - OUT_OF_RES
86 * - FAILED if no ike_sa_id is set
87 */
88 status_t (*get_ike_sa_id) (message_t *this,ike_sa_id_t **ike_sa_id);
89
90 /**
91 * @brief Sets the exchange type of the message.
92 *
93 * @param this message_t object
94 * @param exchange_type exchange_type to set
95 * @return SUCCESS
96 */
97 status_t (*set_exchange_type) (message_t *this,exchange_type_t exchange_type);
98
99 /**
100 * @brief Gets the exchange type of the message.
101 *
102 * @param this message_t object
103 * @return exchange type of the message
104 */
105 exchange_type_t (*get_exchange_type) (message_t *this);
106
107 /**
108 * @brief Sets the original initiator flag.
109 *
110 * @param this message_t object
111 * @param original_initiator TRUE if message is from original initiator
112 * @return SUCCESS
113 */
114 status_t (*set_original_initiator) (message_t *this,bool original_initiator);
115
116 /**
117 * @brief Gets original initiator flag.
118 *
119 * @param this message_t object
120 * @return TRUE if message is from original initiator, FALSE otherwise
121 */
122 bool (*get_original_initiator) (message_t *this);
123
124 /**
125 * @brief Sets the request flag.
126 *
127 * @param this message_t object
128 * @param original_initiator TRUE if message is a request, FALSE if it is a reply
129 * @return SUCCESS
130 */
131 status_t (*set_request) (message_t *this,bool request);
132
133 /**
134 * @brief Gets request flag.
135 *
136 * @param this message_t object
137 * @return TRUE if message is a request, FALSE if it is a reply
138 */
139 bool (*get_request) (message_t *this);
140
141 /**
142 * @brief Append a payload to the message.
143 *
144 * @param this message_t object
145 * @param payload payload to append
146 * @return
147 * - SUCCESS or
148 * - OUT_OF_RES
149 */
150 status_t (*add_payload) (message_t *this, payload_t *payload);
151
152 /**
153 * @brief Generates the UDP packet of specific message
154 *
155 * @param this message_t object
156 * @return
157 * - SUCCESS if packet could be generated
158 * - EXCHANGE_TYPE_NOT_SET if exchange type is currently not set
159 * ....
160 */
161
162 /**
163 * @brief Parses and verifies header of message
164 *
165 * @param this message_t object
166 * @return
167 * - SUCCESS if header could be parsed
168 * - NOT_SUPPORTED if payload_type is not supported
169 * - OUT_OF_RES if out of ressources
170 * - PARSE_ERROR if corrupted/invalid data found
171 * - VERIFY_ERROR if header contains wrong values
172 */
173 status_t (*parse_and_verify_header) (message_t *this);
174
175 status_t (*generate) (message_t *this, packet_t **packet);
176 status_t (*get_source) (message_t *this, host_t **host);
177 status_t (*set_source) (message_t *this, host_t *host);
178 status_t (*get_destination) (message_t *this, host_t **host);
179 status_t (*set_destination) (message_t *this, host_t *host);
180
181 /**
182 * @brief Destroys a message and all including objects
183 *
184 * @param this message_t object
185 * @return SUCCESS
186 */
187 status_t (*destroy) (message_t *this);
188 };
189
190 /**
191 * Creates an message_t object from a incoming UDP Packet.
192 *
193 * @warning the given packet_t object is not copied and gets
194 * destroyed in message_t's destroy call.
195 *
196 * @warning Packet is not parsed in here!
197 *
198 * - exchange_type is set to NOT_SET
199 * - original_initiator is set to TRUE
200 * - is_request is set to TRUE
201 *
202 * @param packet packet_t object which is assigned to message
203 *
204 * @return
205 * - created message_t object
206 * - NULL if out of ressources
207 */
208 message_t * message_create_from_packet(packet_t *packet);
209
210
211 /**
212 * Creates an empty message_t object.
213 *
214 * - exchange_type is set to NOT_SET
215 * - original_initiator is set to TRUE
216 * - is_request is set to TRUE
217 *
218 * @return
219 * - created message_t object
220 * - NULL if out of ressources
221 */
222 message_t * message_create();
223
224 #endif /*MESSAGE_H_*/