- creation of ts payloads using ts
[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 * Object representing an IKEv2 TS payload.
45 *
46 * The TS payload format is described in draft section 3.13.
47 *
48 * @ingroup payloads
49 *
50 */
51 struct ts_payload_t {
52 /**
53 * The payload_t interface.
54 */
55 payload_t payload_interface;
56
57 /**
58 * @brief Get the type of TSpayload (TSi or TSr).
59 *
60 * @param this calling id_payload_t object
61 * @return
62 * - TRUE if this payload is of type TSi
63 * - FALSE if this payload is of type TSr
64 *
65 */
66 bool (*get_initiator) (ts_payload_t *this);
67
68 /**
69 * @brief Set the type of TS payload (TSi or TSr).
70 *
71 * @param this calling id_payload_t object
72 * @param is_initiator
73 * - TRUE if this payload is of type TSi
74 * - FALSE if this payload is of type TSr
75 *
76 */
77 void (*set_initiator) (ts_payload_t *this,bool is_initiator);
78
79 /**
80 * @brief Adds a traffic_selector_substructure_t object to this object.
81 *
82 * @warning The added traffic_selector_substructure_t object is
83 * getting destroyed in destroy function of ts_payload_t.
84 *
85 * @param this calling ts_payload_t object
86 * @param traffic_selector traffic_selector_substructure_t object to add
87 */
88 void (*add_traffic_selector_substructure) (ts_payload_t *this,traffic_selector_substructure_t *traffic_selector);
89
90 /**
91 * @brief Creates an iterator of stored traffic_selector_substructure_t objects.
92 *
93 * @warning The created iterator has to get destroyed by the caller!
94 *
95 * @warning When removing an traffic_selector_substructure_t object
96 * using this iterator, the length of this payload
97 * has to get refreshed by calling payload_t.get_length!
98 *
99 * @param this calling ts_payload_t object
100 * @param[in] forward iterator direction (TRUE: front to end)
101 * @return created iterator_t object
102 */
103 iterator_t *(*create_traffic_selector_substructure_iterator) (ts_payload_t *this, bool forward);
104
105 /**
106 * @brief Create an array of the nested traffic_selector_t's.
107 *
108 * @warning Array must be freed after usage.
109 * @warnging traffic selector must be destroyed after usage.
110 *
111 * @param this calling ts_payload_t object
112 * @param[out] address of the array of traffic_selectors will be written here.
113 * @return number of ts in the allocated array
114 */
115 size_t (*get_traffic_selectors) (ts_payload_t *this, traffic_selector_t **traffic_selectors[]);
116
117 /**
118 * @brief Destroys an ts_payload_t object.
119 *
120 * @param this ts_payload_t object to destroy
121 */
122 void (*destroy) (ts_payload_t *this);
123 };
124
125 /**
126 * @brief Creates an empty ts_payload_t object.
127 *
128 *
129 * @param is_initiator
130 * - TRUE if this payload is of type TSi
131 * - FALSE if this payload is of type TSr
132 *
133 * @return created 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 *
147 * @return created ts_payload_t object
148 *
149 * @ingroup payloads
150 */
151 ts_payload_t *ts_payload_create_from_traffic_selectors(bool is_initiator, traffic_selector_t *traffic_selectors[], size_t count);
152
153
154 #endif //TS_PAYLOAD_H_