496a352ca09385410549e4aa13202a9848ebc0a1
[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 * Class representing an IKEv1/IKEv2 proposal substructure.
35 */
36 struct proposal_substructure_t {
37
38 /**
39 * The payload_t interface.
40 */
41 payload_t payload_interface;
42
43 /**
44 * Sets the proposal number of current proposal.
45 *
46 * @param id proposal number to set
47 */
48 void (*set_proposal_number) (proposal_substructure_t *this,
49 u_int8_t proposal_number);
50 /**
51 * get proposal number of current proposal.
52 *
53 * @return proposal number of current proposal substructure.
54 */
55 u_int8_t (*get_proposal_number) (proposal_substructure_t *this);
56
57 /**
58 * Sets the protocol id of current proposal.
59 *
60 * @param id protocol id to set
61 */
62 void (*set_protocol_id) (proposal_substructure_t *this,
63 u_int8_t protocol_id);
64
65 /**
66 * get protocol id of current proposal.
67 *
68 * @return protocol id of current proposal substructure.
69 */
70 u_int8_t (*get_protocol_id) (proposal_substructure_t *this);
71
72 /**
73 * Sets the next_payload field of this substructure
74 *
75 * If this is the last proposal, next payload field is set to 0,
76 * otherwise to 2
77 *
78 * @param is_last When TRUE, next payload field is set to 0, otherwise to 2
79 */
80 void (*set_is_last_proposal) (proposal_substructure_t *this, bool is_last);
81
82 /**
83 * Returns the currently set SPI of this proposal.
84 *
85 * @return chunk_t pointing to the value
86 */
87 chunk_t (*get_spi) (proposal_substructure_t *this);
88
89 /**
90 * Sets the SPI of the current proposal.
91 *
92 * @warning SPI is getting copied
93 *
94 * @param spi chunk_t pointing to the value to set
95 */
96 void (*set_spi) (proposal_substructure_t *this, chunk_t spi);
97
98 /**
99 * Get proposals contained in a propsal_substructure_t.
100 *
101 * @param list list to add created proposals to
102 */
103 void (*get_proposals) (proposal_substructure_t *this, linked_list_t *list);
104
105 /**
106 * Create an enumerator over transform substructures.
107 *
108 * @return enumerator over transform_substructure_t
109 */
110 enumerator_t* (*create_substructure_enumerator)(proposal_substructure_t *this);
111
112 /**
113 * Destroys an proposal_substructure_t object.
114 */
115 void (*destroy) (proposal_substructure_t *this);
116 };
117
118 /**
119 * Creates an empty proposal_substructure_t object
120 *
121 * @param type PROPOSAL_SUBSTRUCTURE or PROPOSAL_SUBSTRUCTURE_V1
122 * @return proposal_substructure_t object
123 */
124 proposal_substructure_t *proposal_substructure_create(payload_type_t type);
125
126 /**
127 * Creates a proposal_substructure_t from a proposal_t.
128 *
129 * @param type PROPOSAL_SUBSTRUCTURE or PROPOSAL_SUBSTRUCTURE_V1
130 * @param proposal proposal to build a substruct out of it
131 * @return proposal_substructure_t object
132 */
133 proposal_substructure_t *proposal_substructure_create_from_proposal(
134 payload_type_t type, proposal_t *proposal);
135
136 /**
137 * Creates a proposal_substructure_t from a list of proposal_t (IKEv1 only).
138 *
139 * @param proposal proposal to build a substruct out of it
140 * @return IKEv1 proposal_substructure_t PROPOSAL_SUBSTRUCTURE_V1
141 */
142 proposal_substructure_t *proposal_substructure_create_from_proposals(
143 linked_list_t *proposals);
144
145 #endif /** PROPOSAL_SUBSTRUCTURE_H_ @}*/