- implemented generate-method
[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 status_t (*generate) (message_t *this, packet_t **packet);
163 status_t (*get_source) (message_t *this, host_t **host);
164 status_t (*set_source) (message_t *this, host_t *host);
165 status_t (*get_destination) (message_t *this, host_t **host);
166 status_t (*set_destination) (message_t *this, host_t *host);
167
168 /**
169 * @brief Destroys a message and all including objects
170 *
171 * @param this message_t object
172 * @return SUCCESS
173 */
174 status_t (*destroy) (message_t *this);
175 };
176
177 /**
178 * Creates an message_t object from a incoming UDP Packet.
179 *
180 * @warning the given packet_t object is not copied and gets
181 * destroyed in message_t's destroy call.
182 *
183 * @warning Packet is not parsed in here!
184 *
185 * - exchange_type is set to NOT_SET
186 * - original_initiator is set to TRUE
187 * - is_request is set to TRUE
188 *
189 * @param packet packet_t object which is assigned to message
190 *
191 * @return
192 * - created message_t object
193 * - NULL if out of ressources
194 */
195 message_t * message_create_from_packet(packet_t *packet);
196
197
198 /**
199 * Creates an empty message_t object.
200 *
201 * - exchange_type is set to NOT_SET
202 * - original_initiator is set to TRUE
203 * - is_request is set to TRUE
204 *
205 * @return
206 * - created message_t object
207 * - NULL if out of ressources
208 */
209 message_t * message_create();
210
211 #endif /*MESSAGE_H_*/