- fixed doxygen warnings
[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 *
111 * @warning traffic selector must be destroyed after usage.
112 *
113 * @param this calling ts_payload_t object
114 * @param[out] address of the array of traffic_selectors will be written here.
115 * @return number of ts in the allocated array
116 */
117 size_t (*get_traffic_selectors) (ts_payload_t *this, traffic_selector_t **traffic_selectors[]);
118
119 /**
120 * @brief Destroys an ts_payload_t object.
121 *
122 * @param this ts_payload_t object to destroy
123 */
124 void (*destroy) (ts_payload_t *this);
125 };
126
127 /**
128 * @brief Creates an empty ts_payload_t object.
129 *
130 *
131 * @param is_initiator
132 * - TRUE if this payload is of type TSi
133 * - FALSE if this payload is of type TSr
134 * @return ts_payload_t object
135 *
136 * @ingroup payloads
137 */
138 ts_payload_t *ts_payload_create(bool is_initiator);
139
140 /**
141 * @brief Creates ts_payload with the specified traffic_selectors.
142 *
143 *
144 * @param is_initiator
145 * - TRUE if this payload is of type TSi
146 * - FALSE if this payload is of type TSr
147 * @param traffic_selectors an array of traffic_selector_t-pointers
148 * @param count number of pointers in the array
149 * @return ts_payload_t object
150 *
151 * @ingroup payloads
152 */
153 ts_payload_t *ts_payload_create_from_traffic_selectors(bool is_initiator, traffic_selector_t *traffic_selectors[], size_t count);
154
155
156 #endif //TS_PAYLOAD_H_