Migrated transform_attribute to INIT/METHOD macros
[strongswan.git] / src / libcharon / encoding / payloads / proposal_substructure.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 proposal_substructure proposal_substructure
19 * @{ @ingroup payloads
20 */
21
22 #ifndef PROPOSAL_SUBSTRUCTURE_H_
23 #define PROPOSAL_SUBSTRUCTURE_H_
24
25 typedef struct proposal_substructure_t proposal_substructure_t;
26
27 #include <library.h>
28 #include <encoding/payloads/payload.h>
29 #include <encoding/payloads/transform_substructure.h>
30 #include <config/proposal.h>
31 #include <utils/linked_list.h>
32
33
34 /**
35 * Length of the proposal substructure header (without spi).
36 */
37 #define PROPOSAL_SUBSTRUCTURE_HEADER_LENGTH 8
38
39 /**
40 * Class representing an IKEv2-PROPOSAL SUBSTRUCTURE.
41 *
42 * The PROPOSAL SUBSTRUCTURE format is described in RFC section 3.3.1.
43 */
44 struct proposal_substructure_t {
45
46 /**
47 * The payload_t interface.
48 */
49 payload_t payload_interface;
50
51 /**
52 * Sets the proposal number of current proposal.
53 *
54 * @param id proposal number to set
55 */
56 void (*set_proposal_number) (proposal_substructure_t *this,
57 u_int8_t proposal_number);
58 /**
59 * get proposal number of current proposal.
60 *
61 * @return proposal number of current proposal substructure.
62 */
63 u_int8_t (*get_proposal_number) (proposal_substructure_t *this);
64
65 /**
66 * Sets the protocol id of current proposal.
67 *
68 * @param id protocol id to set
69 */
70 void (*set_protocol_id) (proposal_substructure_t *this,
71 u_int8_t protocol_id);
72
73 /**
74 * get protocol id of current proposal.
75 *
76 * @return protocol id of current proposal substructure.
77 */
78 u_int8_t (*get_protocol_id) (proposal_substructure_t *this);
79
80 /**
81 * Sets the next_payload field of this substructure
82 *
83 * If this is the last proposal, next payload field is set to 0,
84 * otherwise to 2
85 *
86 * @param is_last When TRUE, next payload field is set to 0, otherwise to 2
87 */
88 void (*set_is_last_proposal) (proposal_substructure_t *this, bool is_last);
89
90 /**
91 * Returns the currently set SPI of this proposal.
92 *
93 * @return chunk_t pointing to the value
94 */
95 chunk_t (*get_spi) (proposal_substructure_t *this);
96
97 /**
98 * Sets the SPI of the current proposal.
99 *
100 * @warning SPI is getting copied
101 *
102 * @param spi chunk_t pointing to the value to set
103 */
104 void (*set_spi) (proposal_substructure_t *this, chunk_t spi);
105
106 /**
107 * Get a proposal_t from the propsal_substructure_t.
108 *
109 * @return proposal_t
110 */
111 proposal_t * (*get_proposal) (proposal_substructure_t *this);
112
113 /**
114 * Clones an proposal_substructure_t object.
115 *
116 * @return cloned object
117 */
118 proposal_substructure_t* (*clone) (proposal_substructure_t *this);
119
120 /**
121 * Destroys an proposal_substructure_t object.
122 */
123 void (*destroy) (proposal_substructure_t *this);
124 };
125
126 /**
127 * Creates an empty proposal_substructure_t object
128 *
129 * @return proposal_substructure_t object
130 */
131 proposal_substructure_t *proposal_substructure_create(void);
132
133 /**
134 * Creates a proposal_substructure_t from a proposal_t.
135 *
136 * @param proposal proposal to build a substruct out of it
137 * @return proposal_substructure_t object
138 */
139 proposal_substructure_t *proposal_substructure_create_from_proposal(
140 proposal_t *proposal);
141
142 #endif /** PROPOSAL_SUBSTRUCTURE_H_ @}*/