5380d1c659dc78edc48bdad2e4d694475430b9d9
[strongswan.git] / Source / charon / encoding / payloads / proposal_substructure.h
1 /**
2 * @file proposal_substructure.h
3 *
4 * @brief Interface of proposal_substructure_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 PROPOSAL_SUBSTRUCTURE_H_
24 #define PROPOSAL_SUBSTRUCTURE_H_
25
26 #include <types.h>
27 #include <encoding/payloads/payload.h>
28 #include <encoding/payloads/transform_substructure.h>
29 #include <utils/linked_list.h>
30
31
32 /**
33 * Length of the proposal substructure header (without spi).
34 *
35 * @ingroup payloads
36 */
37 #define PROPOSAL_SUBSTRUCTURE_HEADER_LENGTH 8
38
39
40 typedef enum protocol_id_t protocol_id_t;
41
42 /**
43 * Protocol ID of a proposal.
44 *
45 * @ingroup payloads
46 */
47 enum protocol_id_t {
48 UNDEFINED_PROTOCOL_ID = 201,
49 IKE = 1,
50 AH = 2,
51 ESP = 3,
52 };
53
54 /**
55 * String mappings for protocol_id_t.
56 *
57 * @ingroup payloads
58 */
59 extern mapping_t protocol_id_m[];
60
61 typedef struct proposal_substructure_t proposal_substructure_t;
62
63 /**
64 * @brief Class representing an IKEv2-PROPOSAL SUBSTRUCTURE.
65 *
66 * The PROPOSAL SUBSTRUCTURE format is described in RFC section 3.3.1.
67 *
68 * @b Constructors:
69 * - proposal_substructure_create()
70 *
71 * @ingroup payloads
72 */
73 struct proposal_substructure_t {
74 /**
75 * The payload_t interface.
76 */
77 payload_t payload_interface;
78
79 /**
80 * @brief Creates an iterator of stored transform_substructure_t objects.
81 *
82 * @warning The created iterator has to get destroyed by the caller!
83 * When deleting any transform over this iterator, call
84 * get_size to make sure the length and number values are ok.
85 *
86 * @param this calling proposal_substructure_t object
87 * @param[in] forward iterator direction (TRUE: front to end)
88 * @return created iterator_t object
89 */
90 iterator_t * (*create_transform_substructure_iterator) (proposal_substructure_t *this, bool forward);
91
92 /**
93 * @brief Adds a transform_substructure_t object to this object.
94 *
95 * @warning The added transform_substructure_t object is
96 * getting destroyed in destroy function of proposal_substructure_t.
97 *
98 * @param this calling proposal_substructure_t object
99 * @param transform transform_substructure_t object to add
100 */
101 void (*add_transform_substructure) (proposal_substructure_t *this,transform_substructure_t *transform);
102
103 /**
104 * @brief Sets the proposal number of current proposal.
105 *
106 * @param this calling proposal_substructure_t object
107 * @param id proposal number to set
108 */
109 void (*set_proposal_number) (proposal_substructure_t *this,u_int8_t proposal_number);
110
111 /**
112 * @brief get proposal number of current proposal.
113 *
114 * @param this calling proposal_substructure_t object
115 * @return proposal number of current proposal substructure.
116 */
117 u_int8_t (*get_proposal_number) (proposal_substructure_t *this);
118
119 /**
120 * @brief get the number of transforms in current proposal.
121 *
122 * @param this calling proposal_substructure_t object
123 * @return transform count in current proposal
124 */
125 size_t (*get_transform_count) (proposal_substructure_t *this);
126
127 /**
128 * @brief get size of the set spi in bytes.
129 *
130 * @param this calling proposal_substructure_t object
131 * @return size of the spi in bytes
132 */
133 size_t (*get_spi_size) (proposal_substructure_t *this);
134
135 /**
136 * @brief Sets the protocol id of current proposal.
137 *
138 * @param this calling proposal_substructure_t object
139 * @param id protocol id to set
140 */
141 void (*set_protocol_id) (proposal_substructure_t *this,u_int8_t protocol_id);
142
143 /**
144 * @brief get protocol id of current proposal.
145 *
146 * @param this calling proposal_substructure_t object
147 * @return protocol id of current proposal substructure.
148 */
149 u_int8_t (*get_protocol_id) (proposal_substructure_t *this);
150
151 /**
152 * @brief Get informations for a specific transform type.
153 *
154 * @param this calling proposal_substructure_t object
155 * @param type type to get informations for
156 * @param transform_id transform id of the specific type
157 * @param key_length key length of the specific key length transform attribute
158 * @return
159 * - SUCCESS if transform type is part of this proposal and
160 * all data (incl. key length) could be fetched
161 * - NOT_FOUND if transform type is not part of this proposal
162 */
163 status_t (*get_info_for_transform_type) (proposal_substructure_t *this,transform_type_t type, u_int16_t *transform_id, u_int16_t *key_length);
164
165 /**
166 * @brief Sets the next_payload field of this substructure
167 *
168 * If this is the last proposal, next payload field is set to 0,
169 * otherwise to 2
170 *
171 * @param this calling proposal_substructure_t object
172 * @param is_last When TRUE, next payload field is set to 0, otherwise to 2
173 */
174 void (*set_is_last_proposal) (proposal_substructure_t *this, bool is_last);
175
176 /**
177 * @brief Returns the currently set SPI of this proposal.
178 *
179 * @warning Returned data are not copied
180 *
181 * @param this calling proposal_substructure_t object
182 * @return chunk_t pointing to the value
183 */
184 chunk_t (*get_spi) (proposal_substructure_t *this);
185
186 /**
187 * @brief Sets the SPI of the current proposal.
188 *
189 * @warning SPI is getting copied
190 *
191 * @param this calling proposal_substructure_t object
192 * @param spi chunk_t pointing to the value to set
193 */
194 void (*set_spi) (proposal_substructure_t *this, chunk_t spi);
195
196 /**
197 * @brief Clones an proposal_substructure_t object.
198 *
199 * @param this proposal_substructure_t object to clone
200 * @return cloned object
201 */
202 proposal_substructure_t* (*clone) (proposal_substructure_t *this);
203
204 /**
205 * @brief Destroys an proposal_substructure_t object.
206 *
207 * @param this proposal_substructure_t object to destroy
208 */
209 void (*destroy) (proposal_substructure_t *this);
210 };
211
212 /**
213 * @brief Creates an empty proposal_substructure_t object
214 *
215 * @return proposal_substructure_t object
216 *
217 * @ingroup payloads
218 */
219 proposal_substructure_t *proposal_substructure_create();
220
221
222 #endif /*PROPOSAL_SUBSTRUCTURE_H_*/