generator now has its generator_context which is used to generate more
[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
29 /**
30 * @brief Different types of IKE-Exchanges.
31 *
32 * See RFC for different types.
33 */
34 typedef enum exchange_type_e exchange_type_t;
35
36 enum exchange_type_e{
37
38 /**
39 * NOT_SET, not a official message type :-)
40 */
41 NOT_SET = 0,
42
43 /**
44 * IKE_SA_INIT
45 */
46 IKE_SA_INIT = 34,
47 /**
48 * IKE_AUTH
49 */
50 IKE_AUTH = 35,
51 /**
52 * CREATE_CHILD_SA
53 */
54 CREATE_CHILD_SA = 36,
55 /**
56 * INFORMATIONAL
57 */
58 INFORMATIONAL = 37
59 };
60
61 /**
62 * @brief This class is used to represent an IKEv2-Message.
63 *
64 * An IKEv2-Message is either a request or response.
65 */
66 typedef struct message_s message_t;
67
68 struct message_s {
69
70 /**
71 * @brief Sets the exchange type of the message.
72 *
73 * @param this message_t object
74 * @param exchange_type exchange_type to set
75 * @return SUCCESS
76 */
77 status_t (*set_exchange_type) (message_t *this,exchange_type_t exchange_type);
78
79 /**
80 * @brief Gets the exchange type of the message.
81 *
82 * @param this message_t object
83 * @return exchange type of the message
84 */
85 exchange_type_t (*get_exchange_type) (message_t *this);
86
87 /**
88 * @brief Sets the original initiator flag.
89 *
90 * @param this message_t object
91 * @param original_initiator TRUE if message is from original initiator
92 * @return SUCCESS
93 */
94 status_t (*set_original_initiator) (message_t *this,bool original_initiator);
95
96 /**
97 * @brief Gets original initiator flag.
98 *
99 * @param this message_t object
100 * @return TRUE if message is from original initiator, FALSE otherwise
101 */
102 bool (*get_original_initiator) (message_t *this);
103
104 /**
105 * @brief Sets the request flag.
106 *
107 * @param this message_t object
108 * @param original_initiator TRUE if message is a request, FALSE if it is a reply
109 * @return SUCCESS
110 */
111 status_t (*set_request) (message_t *this,bool request);
112
113 /**
114 * @brief Gets request flag.
115 *
116 * @param this message_t object
117 * @return TRUE if message is a request, FALSE if it is a reply
118 */
119 bool (*get_request) (message_t *this);
120
121 /**
122 * @brief Generates the UDP packet of specific message
123 *
124 * @param this message_t object
125 * @return
126 * - SUCCESS if packet could be generated
127 * - EXCHANGE_TYPE_NOT_SET if exchange type is currently not set
128 * ....
129 */
130 status_t (*generate_packet) (message_t *this, packet_t **packet);
131
132 /**
133 * @brief Destroys a message and all including objects
134 *
135 * @param this message_t object
136 * @return SUCCESS
137 */
138 status_t (*destroy) (message_t *this);
139 };
140
141 /**
142 * Creates an message_t object from a incoming UDP Packet.
143 *
144 * @warning the given packet_t object is not copied and gets
145 * destroyed in message_t's destroy call.
146 *
147 * @warning Packet is not parsed in here!
148 *
149 * - exchange_type is set to NOT_SET
150 * - original_initiator is set to TRUE
151 * - is_request is set to TRUE
152 *
153 * @param packet packet_t object which is assigned to message
154 *
155 * @return
156 * - created message_t object
157 * - NULL if out of ressources
158 */
159 message_t * message_create_from_packet(packet_t *packet);
160
161
162 /**
163 * Creates an empty message_t object.
164 *
165 * - exchange_type is set to NOT_SET
166 * - original_initiator is set to TRUE
167 * - is_request is set to TRUE
168 *
169 * @return
170 * - created message_t object
171 * - NULL if out of ressources
172 */
173 message_t * message_create();
174
175 #endif /*MESSAGE_H_*/