6f216a396869e796b5897f5d1d0e5b6e4eb2f37e
[strongswan.git] / src / charon / encoding / payloads / ts_payload.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 * $Id$
17 */
18
19 /**
20 * @defgroup ts_payload ts_payload
21 * @{ @ingroup payloads
22 */
23
24
25 #ifndef TS_PAYLOAD_H_
26 #define TS_PAYLOAD_H_
27
28 typedef struct ts_payload_t ts_payload_t;
29
30 #include <library.h>
31 #include <utils/linked_list.h>
32 #include <config/traffic_selector.h>
33 #include <encoding/payloads/payload.h>
34 #include <encoding/payloads/traffic_selector_substructure.h>
35
36 /**
37 * Length of a TS payload without the Traffic selectors.
38 */
39 #define TS_PAYLOAD_HEADER_LENGTH 8
40
41
42 /**
43 * Class representing an IKEv2 TS payload.
44 *
45 * The TS payload format is described in RFC section 3.13.
46 */
47 struct ts_payload_t {
48 /**
49 * The payload_t interface.
50 */
51 payload_t payload_interface;
52
53 /**
54 * Get the type of TSpayload (TSi or TSr).
55 *
56 * @return
57 * - TRUE if this payload is of type TSi
58 * - FALSE if this payload is of type TSr
59 */
60 bool (*get_initiator) (ts_payload_t *this);
61
62 /**
63 * Set the type of TS payload (TSi or TSr).
64 *
65 * @param is_initiator
66 * - TRUE if this payload is of type TSi
67 * - FALSE if this payload is of type TSr
68 */
69 void (*set_initiator) (ts_payload_t *this,bool is_initiator);
70
71 /**
72 * Adds a traffic_selector_substructure_t object to this object.
73 *
74 * @param traffic_selector traffic_selector_substructure_t object to add
75 */
76 void (*add_traffic_selector_substructure) (ts_payload_t *this,
77 traffic_selector_substructure_t *traffic_selector);
78
79 /**
80 * Creates an iterator of stored traffic_selector_substructure_t objects.
81 *
82 * When removing an traffic_selector_substructure_t object
83 * using this iterator, the length of this payload
84 * has to get refreshed by calling payload_t.get_length!
85 *
86 * @param forward iterator direction (TRUE: front to end)
87 * @return created iterator_t object
88 */
89 iterator_t *(*create_traffic_selector_substructure_iterator) (
90 ts_payload_t *this, bool forward);
91
92 /**
93 * Get a list of nested traffic selectors as traffic_selector_t.
94 *
95 * Resulting list and its traffic selectors must be destroyed after usage
96 *
97 * @return list of traffic selectors
98 */
99 linked_list_t *(*get_traffic_selectors) (ts_payload_t *this);
100
101 /**
102 * Destroys an ts_payload_t object.
103 */
104 void (*destroy) (ts_payload_t *this);
105 };
106
107 /**
108 * Creates an empty ts_payload_t object.
109 *
110 * @param is_initiator
111 * - TRUE if this payload is of type TSi
112 * - FALSE if this payload is of type TSr
113 * @return ts_payload_t object
114 */
115 ts_payload_t *ts_payload_create(bool is_initiator);
116
117 /**
118 * Creates ts_payload with a list of traffic_selector_t
119 *
120 * @param is_initiator
121 * - TRUE if this payload is of type TSi
122 * - FALSE if this payload is of type TSr
123 * @param traffic_selectors list of traffic selectors to include
124 * @return ts_payload_t object
125 */
126 ts_payload_t *ts_payload_create_from_traffic_selectors(bool is_initiator,
127 linked_list_t *traffic_selectors);
128
129 #endif /* TS_PAYLOAD_H_ @} */