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