Implemented limited payload parsing for IKEv1 SA payloads
[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 IKEv1/IKEv2 proposal substructure.
41 */
42 struct proposal_substructure_t {
43
44 /**
45 * The payload_t interface.
46 */
47 payload_t payload_interface;
48
49 /**
50 * Sets the proposal number of current proposal.
51 *
52 * @param id proposal number to set
53 */
54 void (*set_proposal_number) (proposal_substructure_t *this,
55 u_int8_t proposal_number);
56 /**
57 * get proposal number of current proposal.
58 *
59 * @return proposal number of current proposal substructure.
60 */
61 u_int8_t (*get_proposal_number) (proposal_substructure_t *this);
62
63 /**
64 * Sets the protocol id of current proposal.
65 *
66 * @param id protocol id to set
67 */
68 void (*set_protocol_id) (proposal_substructure_t *this,
69 u_int8_t protocol_id);
70
71 /**
72 * get protocol id of current proposal.
73 *
74 * @return protocol id of current proposal substructure.
75 */
76 u_int8_t (*get_protocol_id) (proposal_substructure_t *this);
77
78 /**
79 * Sets the next_payload field of this substructure
80 *
81 * If this is the last proposal, next payload field is set to 0,
82 * otherwise to 2
83 *
84 * @param is_last When TRUE, next payload field is set to 0, otherwise to 2
85 */
86 void (*set_is_last_proposal) (proposal_substructure_t *this, bool is_last);
87
88 /**
89 * Returns the currently set SPI of this proposal.
90 *
91 * @return chunk_t pointing to the value
92 */
93 chunk_t (*get_spi) (proposal_substructure_t *this);
94
95 /**
96 * Sets the SPI of the current proposal.
97 *
98 * @warning SPI is getting copied
99 *
100 * @param spi chunk_t pointing to the value to set
101 */
102 void (*set_spi) (proposal_substructure_t *this, chunk_t spi);
103
104 /**
105 * Get a proposal_t from the propsal_substructure_t.
106 *
107 * @return proposal_t
108 */
109 proposal_t * (*get_proposal) (proposal_substructure_t *this);
110
111 /**
112 * Create an enumerator over transform substructures.
113 *
114 * @return enumerator over transform_substructure_t
115 */
116 enumerator_t* (*create_substructure_enumerator)(proposal_substructure_t *this);
117
118 /**
119 * Destroys an proposal_substructure_t object.
120 */
121 void (*destroy) (proposal_substructure_t *this);
122 };
123
124 /**
125 * Creates an empty proposal_substructure_t object
126 *
127 * @param type PROPOSAL_SUBSTRUCTURE or PROPOSAL_SUBSTRUCTURE_V1
128 * @return proposal_substructure_t object
129 */
130 proposal_substructure_t *proposal_substructure_create(payload_type_t type);
131
132 /**
133 * Creates a proposal_substructure_t from a proposal_t.
134 *
135 * @param type PROPOSAL_SUBSTRUCTURE or PROPOSAL_SUBSTRUCTURE_V1
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 payload_type_t type, proposal_t *proposal);
141
142 #endif /** PROPOSAL_SUBSTRUCTURE_H_ @}*/