Moving charon to libcharon.
[strongswan.git] / src / libcharon / encoding / payloads / sa_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
17 /**
18 * @defgroup sa_payload sa_payload
19 * @{ @ingroup payloads
20 */
21
22 #ifndef SA_PAYLOAD_H_
23 #define SA_PAYLOAD_H_
24
25 typedef struct sa_payload_t sa_payload_t;
26
27 #include <library.h>
28 #include <encoding/payloads/payload.h>
29 #include <encoding/payloads/proposal_substructure.h>
30 #include <utils/linked_list.h>
31
32 /**
33 * SA_PAYLOAD length in bytes without any proposal substructure.
34 */
35 #define SA_PAYLOAD_HEADER_LENGTH 4
36
37 /**
38 * Class representing an IKEv2-SA Payload.
39 *
40 * The SA Payload format is described in RFC section 3.3.
41 */
42 struct sa_payload_t {
43 /**
44 * The payload_t interface.
45 */
46 payload_t payload_interface;
47
48 /**
49 * Creates an iterator of stored proposal_substructure_t objects.
50 *
51 * When deleting an proposal using this iterator,
52 * the length of this transform substructure has to be refreshed
53 * by calling get_length()!
54 *
55 * @param forward iterator direction (TRUE: front to end)
56 * @return created iterator_t object
57 */
58 iterator_t *(*create_proposal_substructure_iterator) (sa_payload_t *this,
59 bool forward);
60
61 /**
62 * Adds a proposal_substructure_t object to this object.
63 *
64 * @param proposal proposal_substructure_t object to add
65 */
66 void (*add_proposal_substructure) (sa_payload_t *this,
67 proposal_substructure_t *proposal);
68
69 /**
70 * Gets the proposals in this payload as a list.
71 *
72 * @return a list containing proposal_t s
73 */
74 linked_list_t *(*get_proposals) (sa_payload_t *this);
75
76 /**
77 * Add a child proposal (AH/ESP) to the payload.
78 *
79 * @param proposal child proposal to add to the payload
80 */
81 void (*add_proposal) (sa_payload_t *this, proposal_t *proposal);
82
83 /**
84 * Destroys an sa_payload_t object.
85 */
86 void (*destroy) (sa_payload_t *this);
87 };
88
89 /**
90 * Creates an empty sa_payload_t object
91 *
92 * @return created sa_payload_t object
93 */
94 sa_payload_t *sa_payload_create(void);
95
96 /**
97 * Creates a sa_payload_t object from a list of proposals.
98 *
99 * @param proposals list of proposals to build the payload from
100 * @return sa_payload_t object
101 */
102 sa_payload_t *sa_payload_create_from_proposal_list(linked_list_t *proposals);
103
104 /**
105 * Creates a sa_payload_t object from a single proposal.
106 *
107 * This is only for convenience. Use sa_payload_create_from_proposal_list
108 * if you want to add more than one proposal.
109 *
110 * @param proposal proposal from which the payload should be built.
111 * @return sa_payload_t object
112 */
113 sa_payload_t *sa_payload_create_from_proposal(proposal_t *proposal);
114
115 #endif /** SA_PAYLOAD_H_ @}*/