62ab11d022e86f56d2f9ac0300d6f0c9d9e93e7b
[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 * @brief This class is used to represent an IKEv2-Message.
33 *
34 * An IKEv2-Message is either a request or response.
35 */
36 typedef struct message_s message_t;
37
38 struct message_s {
39
40 /**
41 * @brief Sets the Message ID of the message.
42 *
43 * @param this message_t object
44 * @param message_id message_id to set
45 * @return SUCCESS
46 */
47 status_t (*set_message_id) (message_t *this,u_int32_t message_id);
48
49 /**
50 * @brief Gets the Message ID of the message.
51 *
52 * @param this message_t object
53 * @return message_id type of the message
54 */
55 u_int32_t (*get_message_id) (message_t *this);
56
57 /**
58 * @brief Sets the IKE_SA ID of the message.
59 *
60 * @warning ike_sa_id gets cloned internaly and
61 * so can be destroyed afterwards.
62 *
63 * @param this message_t object
64 * @param ike_sa_id ike_sa_id to set
65 * @return
66 * - SUCCESS
67 * - OUT_OF_RES
68 * @return SUCCESS
69 */
70 status_t (*set_ike_sa_id) (message_t *this,ike_sa_id_t * ike_sa_id);
71
72 /**
73 * @brief Gets the IKE_SA ID of the message.
74 *
75 * @warning The returned ike_sa_id is a clone of the internal one.
76 * So it has to be destroyed by the caller.
77 *
78 * @param this message_t object
79 * @param ike_sa_id pointer to ike_sa_id pointer which will be set
80 * @return
81 * - SUCCESS
82 * - OUT_OF_RES
83 * - FAILED if no ike_sa_id is set
84 */
85 status_t (*get_ike_sa_id) (message_t *this,ike_sa_id_t **ike_sa_id);
86
87 /**
88 * @brief Sets the exchange type of the message.
89 *
90 * @param this message_t object
91 * @param exchange_type exchange_type to set
92 * @return SUCCESS
93 */
94 status_t (*set_exchange_type) (message_t *this,exchange_type_t exchange_type);
95
96 /**
97 * @brief Gets the exchange type of the message.
98 *
99 * @param this message_t object
100 * @return exchange type of the message
101 */
102 exchange_type_t (*get_exchange_type) (message_t *this);
103
104 /**
105 * @brief Sets the original initiator flag.
106 *
107 * @param this message_t object
108 * @param original_initiator TRUE if message is from original initiator
109 * @return SUCCESS
110 */
111 status_t (*set_original_initiator) (message_t *this,bool original_initiator);
112
113 /**
114 * @brief Gets original initiator flag.
115 *
116 * @param this message_t object
117 * @return TRUE if message is from original initiator, FALSE otherwise
118 */
119 bool (*get_original_initiator) (message_t *this);
120
121 /**
122 * @brief Sets the request flag.
123 *
124 * @param this message_t object
125 * @param original_initiator TRUE if message is a request, FALSE if it is a reply
126 * @return SUCCESS
127 */
128 status_t (*set_request) (message_t *this,bool request);
129
130 /**
131 * @brief Gets request flag.
132 *
133 * @param this message_t object
134 * @return TRUE if message is a request, FALSE if it is a reply
135 */
136 bool (*get_request) (message_t *this);
137
138 /**
139 * @brief Generates the UDP packet of specific message
140 *
141 * @param this message_t object
142 * @return
143 * - SUCCESS if packet could be generated
144 * - EXCHANGE_TYPE_NOT_SET if exchange type is currently not set
145 * ....
146 */
147 status_t (*generate_packet) (message_t *this, packet_t **packet);
148
149 /**
150 * @brief Destroys a message and all including objects
151 *
152 * @param this message_t object
153 * @return SUCCESS
154 */
155 status_t (*destroy) (message_t *this);
156 };
157
158 /**
159 * Creates an message_t object from a incoming UDP Packet.
160 *
161 * @warning the given packet_t object is not copied and gets
162 * destroyed in message_t's destroy call.
163 *
164 * @warning Packet is not parsed in here!
165 *
166 * - exchange_type is set to NOT_SET
167 * - original_initiator is set to TRUE
168 * - is_request is set to TRUE
169 *
170 * @param packet packet_t object which is assigned to message
171 *
172 * @return
173 * - created message_t object
174 * - NULL if out of ressources
175 */
176 message_t * message_create_from_packet(packet_t *packet);
177
178
179 /**
180 * Creates an empty message_t object.
181 *
182 * - exchange_type is set to NOT_SET
183 * - original_initiator is set to TRUE
184 * - is_request is set to TRUE
185 *
186 * @return
187 * - created message_t object
188 * - NULL if out of ressources
189 */
190 message_t * message_create();
191
192 #endif /*MESSAGE_H_*/