Removed strayed code fragment
[strongswan.git] / src / charon / encoding / payloads / vendor_id_payload.c
1 /*
2 * Copyright (C) 2005-2009 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 #include <stddef.h>
18
19 #include "vendor_id_payload.h"
20
21 typedef struct private_vendor_id_payload_t private_vendor_id_payload_t;
22
23 /**
24 * Private data of an vendor_id_payload_t object.
25 */
26 struct private_vendor_id_payload_t {
27
28 /**
29 * Public vendor_id_payload_t interface.
30 */
31 vendor_id_payload_t public;
32
33 /**
34 * Next payload type.
35 */
36 u_int8_t next_payload;
37
38 /**
39 * Critical flag.
40 */
41 bool critical;
42
43 /**
44 * Length of this payload.
45 */
46 u_int16_t payload_length;
47
48 /**
49 * The contained data.
50 */
51 chunk_t data;
52 };
53
54 /**
55 * Encoding rules to parse or generate a VENDOR ID payload
56 *
57 * The defined offsets are the positions in a object of type
58 * private_vendor_id_payload_t.
59 */
60 encoding_rule_t vendor_id_payload_encodings[] = {
61 /* 1 Byte next payload type, stored in the field next_payload */
62 { U_INT_8, offsetof(private_vendor_id_payload_t, next_payload) },
63 /* the critical bit */
64 { FLAG, offsetof(private_vendor_id_payload_t, critical) },
65 /* 7 Bit reserved bits, nowhere stored */
66 { RESERVED_BIT, 0 },
67 { RESERVED_BIT, 0 },
68 { RESERVED_BIT, 0 },
69 { RESERVED_BIT, 0 },
70 { RESERVED_BIT, 0 },
71 { RESERVED_BIT, 0 },
72 { RESERVED_BIT, 0 },
73 /* Length of the whole payload*/
74 { PAYLOAD_LENGTH, offsetof(private_vendor_id_payload_t, payload_length)},
75 /* some vendor_id data bytes, length is defined in PAYLOAD_LENGTH */
76 { VID_DATA, offsetof(private_vendor_id_payload_t, data) }
77 };
78
79 /*
80 1 2 3
81 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
82 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
83 ! Next Payload !C! RESERVED ! Payload Length !
84 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
85 + !
86 ~ VID Data ~
87 ! !
88 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
89 */
90
91 /**
92 * Implementation of payload_t.verify.
93 */
94 static status_t verify(private_vendor_id_payload_t *this)
95 {
96 return SUCCESS;
97 }
98
99 /**
100 * Implementation of vendor_id_payload_t.get_encoding_rules.
101 */
102 static void get_encoding_rules(private_vendor_id_payload_t *this,
103 encoding_rule_t **rules, size_t *rule_count)
104 {
105 *rules = vendor_id_payload_encodings;
106 *rule_count = sizeof(vendor_id_payload_encodings) / sizeof(encoding_rule_t);
107 }
108
109 /**
110 * Implementation of payload_t.get_type.
111 */
112 static payload_type_t get_payload_type(private_vendor_id_payload_t *this)
113 {
114 return VENDOR_ID;
115 }
116
117 /**
118 * Implementation of payload_t.get_next_type.
119 */
120 static payload_type_t get_next_type(private_vendor_id_payload_t *this)
121 {
122 return this->next_payload;
123 }
124
125 /**
126 * Implementation of payload_t.set_next_type.
127 */
128 static void set_next_type(private_vendor_id_payload_t *this,payload_type_t type)
129 {
130 this->next_payload = type;
131 }
132
133 /**
134 * Implementation of payload_t.get_length.
135 */
136 static size_t get_length(private_vendor_id_payload_t *this)
137 {
138 return this->payload_length;
139 }
140
141 /**
142 * Implementation of vendor_id_payload_t.get_data.
143 */
144 static chunk_t get_data(private_vendor_id_payload_t *this)
145 {
146 return this->data;
147 }
148
149 /**
150 * Implementation of payload_t.destroy and vendor_id_payload_t.destroy.
151 */
152 static void destroy(private_vendor_id_payload_t *this)
153 {
154 free(this->data.ptr);
155 free(this);
156 }
157
158 /*
159 * Described in header
160 */
161 vendor_id_payload_t *vendor_id_payload_create()
162 {
163 private_vendor_id_payload_t *this = malloc_thing(private_vendor_id_payload_t);
164
165 this->public.payload_interface.verify = (status_t (*) (payload_t *))verify;
166 this->public.payload_interface.get_encoding_rules = (void (*) (payload_t *, encoding_rule_t **, size_t *) ) get_encoding_rules;
167 this->public.payload_interface.get_length = (size_t (*) (payload_t *)) get_length;
168 this->public.payload_interface.get_next_type = (payload_type_t (*) (payload_t *)) get_next_type;
169 this->public.payload_interface.set_next_type = (void (*) (payload_t *,payload_type_t)) set_next_type;
170 this->public.payload_interface.get_type = (payload_type_t (*) (payload_t *)) get_payload_type;
171 this->public.payload_interface.destroy = (void (*) (payload_t *))destroy;
172 this->public.get_data = (chunk_t (*) (vendor_id_payload_t *)) get_data;
173
174 this->critical = FALSE;
175 this->next_payload = NO_PAYLOAD;
176 this->payload_length = VENDOR_ID_PAYLOAD_HEADER_LENGTH;
177 this->data = chunk_empty;
178
179 return &this->public;
180 }
181
182 /*
183 * Described in header
184 */
185 vendor_id_payload_t *vendor_id_payload_create_data(chunk_t data)
186 {
187 private_vendor_id_payload_t *this;
188
189 this = (private_vendor_id_payload_t*)vendor_id_payload_create();
190 this->payload_length += data.len;
191 this->data = data;
192
193 return &this->public;
194 }
195