Moving charon to libcharon.
[strongswan.git] / src / libcharon / 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
17 /**
18 * @defgroup proposal_substructure proposal_substructure
19 * @{ @ingroup payloads
20 */
21
22 #ifndef PROPOSAL_SUBSTRUCTURE_H_
23 #define PROPOSAL_SUBSTRUCTURE_H_
24
25 typedef struct proposal_substructure_t proposal_substructure_t;
26
27 #include <library.h>
28 #include <encoding/payloads/payload.h>
29 #include <encoding/payloads/transform_substructure.h>
30 #include <config/proposal.h>
31 #include <utils/linked_list.h>
32
33
34 /**
35 * Length of the proposal substructure header (without spi).
36 */
37 #define PROPOSAL_SUBSTRUCTURE_HEADER_LENGTH 8
38
39 /**
40 * Class representing an IKEv2-PROPOSAL SUBSTRUCTURE.
41 *
42 * The PROPOSAL SUBSTRUCTURE format is described in RFC section 3.3.1.
43 */
44 struct proposal_substructure_t {
45 /**
46 * The payload_t interface.
47 */
48 payload_t payload_interface;
49
50 /**
51 * Creates an iterator of stored transform_substructure_t objects.
52 *
53 * @param forward iterator direction (TRUE: front to end)
54 * @return created iterator_t object
55 */
56 iterator_t *(*create_transform_substructure_iterator) (
57 proposal_substructure_t *this, bool forward);
58
59 /**
60 * Adds a transform_substructure_t object to this object.
61 *
62 * @param transform transform_substructure_t object to add
63 */
64 void (*add_transform_substructure) (proposal_substructure_t *this,
65 transform_substructure_t *transform);
66
67 /**
68 * Sets the proposal number of current proposal.
69 *
70 * @param id proposal number to set
71 */
72 void (*set_proposal_number) (proposal_substructure_t *this,
73 u_int8_t proposal_number);
74
75 /**
76 * get proposal number of current proposal.
77 *
78 * @return proposal number of current proposal substructure.
79 */
80 u_int8_t (*get_proposal_number) (proposal_substructure_t *this);
81
82 /**
83 * get the number of transforms in current proposal.
84 *
85 * @return transform count in current proposal
86 */
87 size_t (*get_transform_count) (proposal_substructure_t *this);
88
89 /**
90 * get size of the set spi in bytes.
91 *
92 * @return size of the spi in bytes
93 */
94 size_t (*get_spi_size) (proposal_substructure_t *this);
95
96 /**
97 * Sets the protocol id of current proposal.
98 *
99 * @param id protocol id to set
100 */
101 void (*set_protocol_id) (proposal_substructure_t *this,
102 u_int8_t protocol_id);
103
104 /**
105 * get protocol id of current proposal.
106 *
107 * @return protocol id of current proposal substructure.
108 */
109 u_int8_t (*get_protocol_id) (proposal_substructure_t *this);
110
111 /**
112 * Sets the next_payload field of this substructure
113 *
114 * If this is the last proposal, next payload field is set to 0,
115 * otherwise to 2
116 *
117 * @param is_last When TRUE, next payload field is set to 0, otherwise to 2
118 */
119 void (*set_is_last_proposal) (proposal_substructure_t *this, bool is_last);
120
121 /**
122 * Returns the currently set SPI of this proposal.
123 *
124 * @return chunk_t pointing to the value
125 */
126 chunk_t (*get_spi) (proposal_substructure_t *this);
127
128 /**
129 * Sets the SPI of the current proposal.
130 *
131 * @warning SPI is getting copied
132 *
133 * @param spi chunk_t pointing to the value to set
134 */
135 void (*set_spi) (proposal_substructure_t *this, chunk_t spi);
136
137 /**
138 * Get a proposal_t from the propsal_substructure_t.
139 *
140 * @return proposal_t
141 */
142 proposal_t * (*get_proposal) (proposal_substructure_t *this);
143
144 /**
145 * Clones an proposal_substructure_t object.
146 *
147 * @return cloned object
148 */
149 proposal_substructure_t* (*clone) (proposal_substructure_t *this);
150
151 /**
152 * Destroys an proposal_substructure_t object.
153 */
154 void (*destroy) (proposal_substructure_t *this);
155 };
156
157 /**
158 * Creates an empty proposal_substructure_t object
159 *
160 * @return proposal_substructure_t object
161 */
162 proposal_substructure_t *proposal_substructure_create(void);
163
164 /**
165 * Creates a proposal_substructure_t from a proposal_t.
166 *
167 * @param proposal proposal to build a substruct out of it
168 * @return proposal_substructure_t object
169 */
170 proposal_substructure_t *proposal_substructure_create_from_proposal(
171 proposal_t *proposal);
172
173 #endif /** PROPOSAL_SUBSTRUCTURE_H_ @}*/