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