c3a57ab22eccd70c996eb1d054582c0217917736
[strongswan.git] / src / charon / encoding / payloads / proposal_substructure.h
1 /*
2 * Copyright (C) 2005-2006 Martin Willi
3 * Copyright (C) 2005 Jan Hutter
4 * Hochschule fuer Technik Rapperswil
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 *
16 * $Id$
17 */
18
19 /**
20 * @defgroup proposal_substructure proposal_substructure
21 * @{ @ingroup payloads
22 */
23
24 #ifndef PROPOSAL_SUBSTRUCTURE_H_
25 #define PROPOSAL_SUBSTRUCTURE_H_
26
27 typedef struct proposal_substructure_t proposal_substructure_t;
28
29 #include <library.h>
30 #include <encoding/payloads/payload.h>
31 #include <encoding/payloads/transform_substructure.h>
32 #include <config/proposal.h>
33 #include <utils/linked_list.h>
34
35
36 /**
37 * Length of the proposal substructure header (without spi).
38 */
39 #define PROPOSAL_SUBSTRUCTURE_HEADER_LENGTH 8
40
41 /**
42 * Class representing an IKEv2-PROPOSAL SUBSTRUCTURE.
43 *
44 * The PROPOSAL SUBSTRUCTURE format is described in RFC section 3.3.1.
45 */
46 struct proposal_substructure_t {
47 /**
48 * The payload_t interface.
49 */
50 payload_t payload_interface;
51
52 /**
53 * Creates an iterator of stored transform_substructure_t objects.
54 *
55 * @param forward iterator direction (TRUE: front to end)
56 * @return created iterator_t object
57 */
58 iterator_t *(*create_transform_substructure_iterator) (
59 proposal_substructure_t *this, bool forward);
60
61 /**
62 * Adds a transform_substructure_t object to this object.
63 *
64 * @param transform transform_substructure_t object to add
65 */
66 void (*add_transform_substructure) (proposal_substructure_t *this,
67 transform_substructure_t *transform);
68
69 /**
70 * Sets the proposal number of current proposal.
71 *
72 * @param id proposal number to set
73 */
74 void (*set_proposal_number) (proposal_substructure_t *this,
75 u_int8_t proposal_number);
76
77 /**
78 * get proposal number of current proposal.
79 *
80 * @return proposal number of current proposal substructure.
81 */
82 u_int8_t (*get_proposal_number) (proposal_substructure_t *this);
83
84 /**
85 * get the number of transforms in current proposal.
86 *
87 * @return transform count in current proposal
88 */
89 size_t (*get_transform_count) (proposal_substructure_t *this);
90
91 /**
92 * get size of the set spi in bytes.
93 *
94 * @return size of the spi in bytes
95 */
96 size_t (*get_spi_size) (proposal_substructure_t *this);
97
98 /**
99 * Sets the protocol id of current proposal.
100 *
101 * @param id protocol id to set
102 */
103 void (*set_protocol_id) (proposal_substructure_t *this,
104 u_int8_t protocol_id);
105
106 /**
107 * get protocol id of current proposal.
108 *
109 * @return protocol id of current proposal substructure.
110 */
111 u_int8_t (*get_protocol_id) (proposal_substructure_t *this);
112
113 /**
114 * Sets the next_payload field of this substructure
115 *
116 * If this is the last proposal, next payload field is set to 0,
117 * otherwise to 2
118 *
119 * @param is_last When TRUE, next payload field is set to 0, otherwise to 2
120 */
121 void (*set_is_last_proposal) (proposal_substructure_t *this, bool is_last);
122
123 /**
124 * Returns the currently set SPI of this proposal.
125 *
126 * @return chunk_t pointing to the value
127 */
128 chunk_t (*get_spi) (proposal_substructure_t *this);
129
130 /**
131 * Sets the SPI of the current proposal.
132 *
133 * @warning SPI is getting copied
134 *
135 * @param spi chunk_t pointing to the value to set
136 */
137 void (*set_spi) (proposal_substructure_t *this, chunk_t spi);
138
139 /**
140 * Get a proposal_t from the propsal_substructure_t.
141 *
142 * @return proposal_t
143 */
144 proposal_t * (*get_proposal) (proposal_substructure_t *this);
145
146 /**
147 * Clones an proposal_substructure_t object.
148 *
149 * @return cloned object
150 */
151 proposal_substructure_t* (*clone) (proposal_substructure_t *this);
152
153 /**
154 * Destroys an proposal_substructure_t object.
155 */
156 void (*destroy) (proposal_substructure_t *this);
157 };
158
159 /**
160 * Creates an empty proposal_substructure_t object
161 *
162 * @return proposal_substructure_t object
163 */
164 proposal_substructure_t *proposal_substructure_create(void);
165
166 /**
167 * Creates a proposal_substructure_t from a proposal_t.
168 *
169 * @param proposal proposal to build a substruct out of it
170 * @return proposal_substructure_t object
171 */
172 proposal_substructure_t *proposal_substructure_create_from_proposal(
173 proposal_t *proposal);
174
175 #endif /*PROPOSAL_SUBSTRUCTURE_H_ @} */