1b18d3646abcb8ef20c9ffde9052ef79be4189c0
[strongswan.git] / Source / charon / encoding / payloads / ts_payload.h
1 /**
2 * @file ts_payload.h
3 *
4 * @brief Interface of ts_payload_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
24 #ifndef TS_PAYLOAD_H_
25 #define TS_PAYLOAD_H_
26
27 #include <types.h>
28 #include <utils/iterator.h>
29 #include <config/traffic_selector.h>
30 #include <encoding/payloads/payload.h>
31 #include <encoding/payloads/traffic_selector_substructure.h>
32
33 /**
34 * Length of a TS payload without the Traffic selectors.
35 *
36 * @ingroup payloads
37 */
38 #define TS_PAYLOAD_HEADER_LENGTH 8
39
40
41 typedef struct ts_payload_t ts_payload_t;
42
43 /**
44 * @brief Class representing an IKEv2 TS payload.
45 *
46 * The TS payload format is described in draft section 3.13.
47 *
48 * @b Constructors:
49 * - ts_payload_create()
50 * - ts_payload_create_from_traffic_selectors()
51 *
52 * @ingroup payloads
53 */
54 struct ts_payload_t {
55 /**
56 * The payload_t interface.
57 */
58 payload_t payload_interface;
59
60 /**
61 * @brief Get the type of TSpayload (TSi or TSr).
62 *
63 * @param this calling id_payload_t object
64 * @return
65 * - TRUE if this payload is of type TSi
66 * - FALSE if this payload is of type TSr
67 */
68 bool (*get_initiator) (ts_payload_t *this);
69
70 /**
71 * @brief Set the type of TS payload (TSi or TSr).
72 *
73 * @param this calling id_payload_t object
74 * @param is_initiator
75 * - TRUE if this payload is of type TSi
76 * - FALSE if this payload is of type TSr
77 */
78 void (*set_initiator) (ts_payload_t *this,bool is_initiator);
79
80 /**
81 * @brief Adds a traffic_selector_substructure_t object to this object.
82 *
83 * @warning The added traffic_selector_substructure_t object is
84 * getting destroyed in destroy function of ts_payload_t.
85 *
86 * @param this calling ts_payload_t object
87 * @param traffic_selector traffic_selector_substructure_t object to add
88 */
89 void (*add_traffic_selector_substructure) (ts_payload_t *this,traffic_selector_substructure_t *traffic_selector);
90
91 /**
92 * @brief Creates an iterator of stored traffic_selector_substructure_t objects.
93 *
94 * @warning The created iterator has to get destroyed by the caller!
95 *
96 * @warning When removing an traffic_selector_substructure_t object
97 * using this iterator, the length of this payload
98 * has to get refreshed by calling payload_t.get_length!
99 *
100 * @param this calling ts_payload_t object
101 * @param[in] forward iterator direction (TRUE: front to end)
102 * @return created iterator_t object
103 */
104 iterator_t *(*create_traffic_selector_substructure_iterator) (ts_payload_t *this, bool forward);
105
106 /**
107 * @brief Create an array of the nested traffic_selector_t's.
108 *
109 * @warning Array must be freed after usage.
110 * @warnging traffic selector must be destroyed after usage.
111 *
112 * @param this calling ts_payload_t object
113 * @param[out] address of the array of traffic_selectors will be written here.
114 * @return number of ts in the allocated array
115 */
116 size_t (*get_traffic_selectors) (ts_payload_t *this, traffic_selector_t **traffic_selectors[]);
117
118 /**
119 * @brief Destroys an ts_payload_t object.
120 *
121 * @param this ts_payload_t object to destroy
122 */
123 void (*destroy) (ts_payload_t *this);
124 };
125
126 /**
127 * @brief Creates an empty ts_payload_t object.
128 *
129 *
130 * @param is_initiator
131 * - TRUE if this payload is of type TSi
132 * - FALSE if this payload is of type TSr
133 * @return ts_payload_t object
134 *
135 * @ingroup payloads
136 */
137 ts_payload_t *ts_payload_create(bool is_initiator);
138
139 /**
140 * @brief Creates ts_payload with the specified traffic_selectors.
141 *
142 *
143 * @param is_initiator
144 * - TRUE if this payload is of type TSi
145 * - FALSE if this payload is of type TSr
146 * @return ts_payload_t object
147 *
148 * @ingroup payloads
149 */
150 ts_payload_t *ts_payload_create_from_traffic_selectors(bool is_initiator, traffic_selector_t *traffic_selectors[], size_t count);
151
152
153 #endif //TS_PAYLOAD_H_