sdp_data.c revision 1.2 1 1.2 plunky /* $NetBSD: sdp_data.c,v 1.2 2011/07/07 10:44:50 plunky Exp $ */
2 1.1 plunky
3 1.1 plunky /*-
4 1.1 plunky * Copyright (c) 2009 The NetBSD Foundation, Inc.
5 1.1 plunky * All rights reserved.
6 1.1 plunky *
7 1.1 plunky * This code is derived from software contributed to The NetBSD Foundation
8 1.1 plunky * by Iain Hibbert.
9 1.1 plunky *
10 1.1 plunky * Redistribution and use in source and binary forms, with or without
11 1.1 plunky * modification, are permitted provided that the following conditions
12 1.1 plunky * are met:
13 1.1 plunky * 1. Redistributions of source code must retain the above copyright
14 1.1 plunky * notice, this list of conditions and the following disclaimer.
15 1.1 plunky * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 plunky * notice, this list of conditions and the following disclaimer in the
17 1.1 plunky * documentation and/or other materials provided with the distribution.
18 1.1 plunky *
19 1.1 plunky * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 plunky * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 plunky * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 plunky * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 plunky * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 plunky * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 plunky * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 plunky * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 plunky * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 plunky * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 plunky * POSSIBILITY OF SUCH DAMAGE.
30 1.1 plunky */
31 1.1 plunky
32 1.1 plunky #include <sys/cdefs.h>
33 1.2 plunky __RCSID("$NetBSD: sdp_data.c,v 1.2 2011/07/07 10:44:50 plunky Exp $");
34 1.1 plunky
35 1.1 plunky #include <sdp.h>
36 1.1 plunky #include <stdarg.h>
37 1.1 plunky #include <stdio.h>
38 1.1 plunky #include <vis.h>
39 1.1 plunky
40 1.1 plunky #include "sdp-int.h"
41 1.1 plunky
42 1.1 plunky
43 1.1 plunky /******************************************************************************
44 1.1 plunky * sdp_data_type(data)
45 1.1 plunky *
46 1.1 plunky * return SDP data element type
47 1.1 plunky */
48 1.1 plunky int
49 1.1 plunky sdp_data_type(const sdp_data_t *data)
50 1.1 plunky {
51 1.1 plunky
52 1.1 plunky if (data->next + 1 > data->end)
53 1.1 plunky return -1;
54 1.1 plunky
55 1.1 plunky return data->next[0];
56 1.1 plunky }
57 1.1 plunky
58 1.1 plunky
59 1.1 plunky /******************************************************************************
60 1.1 plunky * sdp_data_size(data)
61 1.1 plunky *
62 1.1 plunky * return the size of SDP data element. This will fail (return -1) if
63 1.1 plunky * the data element does not fit into the data space.
64 1.1 plunky */
65 1.1 plunky ssize_t
66 1.1 plunky sdp_data_size(const sdp_data_t *data)
67 1.1 plunky {
68 1.1 plunky uint8_t *p = data->next;
69 1.1 plunky
70 1.1 plunky if (p + 1 > data->end)
71 1.1 plunky return -1;
72 1.1 plunky
73 1.1 plunky switch (*p++) {
74 1.1 plunky case SDP_DATA_NIL:
75 1.1 plunky break;
76 1.1 plunky
77 1.1 plunky case SDP_DATA_BOOL:
78 1.1 plunky case SDP_DATA_INT8:
79 1.1 plunky case SDP_DATA_UINT8:
80 1.1 plunky p += 1;
81 1.1 plunky break;
82 1.1 plunky
83 1.1 plunky case SDP_DATA_INT16:
84 1.1 plunky case SDP_DATA_UINT16:
85 1.1 plunky case SDP_DATA_UUID16:
86 1.1 plunky p += 2;
87 1.1 plunky break;
88 1.1 plunky
89 1.1 plunky case SDP_DATA_INT32:
90 1.1 plunky case SDP_DATA_UINT32:
91 1.1 plunky case SDP_DATA_UUID32:
92 1.1 plunky p += 4;
93 1.1 plunky break;
94 1.1 plunky
95 1.1 plunky case SDP_DATA_INT64:
96 1.1 plunky case SDP_DATA_UINT64:
97 1.1 plunky p += 8;
98 1.1 plunky break;
99 1.1 plunky
100 1.1 plunky case SDP_DATA_INT128:
101 1.1 plunky case SDP_DATA_UINT128:
102 1.1 plunky case SDP_DATA_UUID128:
103 1.1 plunky p += 16;
104 1.1 plunky break;
105 1.1 plunky
106 1.1 plunky case SDP_DATA_ALT8:
107 1.1 plunky case SDP_DATA_SEQ8:
108 1.1 plunky case SDP_DATA_STR8:
109 1.1 plunky case SDP_DATA_URL8:
110 1.1 plunky if (p + 1 > data->end)
111 1.1 plunky return -1;
112 1.1 plunky
113 1.1 plunky p += 1 + *p;
114 1.1 plunky break;
115 1.1 plunky
116 1.1 plunky case SDP_DATA_ALT16:
117 1.1 plunky case SDP_DATA_SEQ16:
118 1.1 plunky case SDP_DATA_STR16:
119 1.1 plunky case SDP_DATA_URL16:
120 1.1 plunky if (p + 2 > data->end)
121 1.1 plunky return -1;
122 1.1 plunky
123 1.1 plunky p += 2 + be16dec(p);
124 1.1 plunky break;
125 1.1 plunky
126 1.1 plunky case SDP_DATA_ALT32:
127 1.1 plunky case SDP_DATA_SEQ32:
128 1.1 plunky case SDP_DATA_STR32:
129 1.1 plunky case SDP_DATA_URL32:
130 1.1 plunky if (p + 4 > data->end)
131 1.1 plunky return -1;
132 1.1 plunky
133 1.1 plunky p += 4 + be32dec(p);
134 1.1 plunky break;
135 1.1 plunky
136 1.1 plunky default:
137 1.1 plunky return -1;
138 1.1 plunky }
139 1.1 plunky
140 1.1 plunky if (p > data->end)
141 1.1 plunky return -1;
142 1.1 plunky
143 1.1 plunky return (p - data->next);
144 1.1 plunky }
145 1.1 plunky
146 1.1 plunky /******************************************************************************
147 1.1 plunky * sdp_data_valid(data)
148 1.1 plunky *
149 1.1 plunky * validate an SDP data element list recursively, ensuring elements do not
150 1.1 plunky * expand past the claimed length and that there is no invalid data.
151 1.1 plunky */
152 1.1 plunky static bool
153 1.1 plunky _sdp_data_valid(uint8_t *ptr, uint8_t *end)
154 1.1 plunky {
155 1.1 plunky size_t len;
156 1.1 plunky
157 1.1 plunky while (ptr < end) {
158 1.1 plunky if (ptr + 1 > end)
159 1.1 plunky return false;
160 1.1 plunky
161 1.1 plunky switch (*ptr++) {
162 1.1 plunky case SDP_DATA_NIL:
163 1.1 plunky break;
164 1.1 plunky
165 1.1 plunky case SDP_DATA_BOOL:
166 1.1 plunky case SDP_DATA_INT8:
167 1.1 plunky case SDP_DATA_UINT8:
168 1.1 plunky if (ptr + 1 > end)
169 1.1 plunky return false;
170 1.1 plunky
171 1.1 plunky ptr += 1;
172 1.1 plunky break;
173 1.1 plunky
174 1.1 plunky case SDP_DATA_INT16:
175 1.1 plunky case SDP_DATA_UINT16:
176 1.1 plunky case SDP_DATA_UUID16:
177 1.1 plunky if (ptr + 2 > end)
178 1.1 plunky return false;
179 1.1 plunky
180 1.1 plunky ptr += 2;
181 1.1 plunky break;
182 1.1 plunky
183 1.1 plunky case SDP_DATA_INT32:
184 1.1 plunky case SDP_DATA_UINT32:
185 1.1 plunky case SDP_DATA_UUID32:
186 1.1 plunky if (ptr + 4 > end)
187 1.1 plunky return false;
188 1.1 plunky
189 1.1 plunky ptr += 4;
190 1.1 plunky break;
191 1.1 plunky
192 1.1 plunky case SDP_DATA_INT64:
193 1.1 plunky case SDP_DATA_UINT64:
194 1.1 plunky if (ptr + 8 > end)
195 1.1 plunky return false;
196 1.1 plunky
197 1.1 plunky ptr += 8;
198 1.1 plunky break;
199 1.1 plunky
200 1.1 plunky case SDP_DATA_INT128:
201 1.1 plunky case SDP_DATA_UINT128:
202 1.1 plunky case SDP_DATA_UUID128:
203 1.1 plunky if (ptr + 16 > end)
204 1.1 plunky return false;
205 1.1 plunky
206 1.1 plunky ptr += 16;
207 1.1 plunky break;
208 1.1 plunky
209 1.1 plunky case SDP_DATA_STR8:
210 1.1 plunky case SDP_DATA_URL8:
211 1.1 plunky if (ptr + 1 > end)
212 1.1 plunky return false;
213 1.1 plunky
214 1.1 plunky len = *ptr;
215 1.1 plunky ptr += 1;
216 1.1 plunky
217 1.1 plunky if (ptr + len > end)
218 1.1 plunky return false;
219 1.1 plunky
220 1.1 plunky ptr += len;
221 1.1 plunky break;
222 1.1 plunky
223 1.1 plunky case SDP_DATA_STR16:
224 1.1 plunky case SDP_DATA_URL16:
225 1.1 plunky if (ptr + 2 > end)
226 1.1 plunky return false;
227 1.1 plunky
228 1.1 plunky len = be16dec(ptr);
229 1.1 plunky ptr += 2;
230 1.1 plunky
231 1.1 plunky if (ptr + len > end)
232 1.1 plunky return false;
233 1.1 plunky
234 1.1 plunky ptr += len;
235 1.1 plunky break;
236 1.1 plunky
237 1.1 plunky case SDP_DATA_STR32:
238 1.1 plunky case SDP_DATA_URL32:
239 1.1 plunky if (ptr + 4 > end)
240 1.1 plunky return false;
241 1.1 plunky
242 1.1 plunky len = be32dec(ptr);
243 1.1 plunky ptr += 4;
244 1.1 plunky
245 1.1 plunky if (ptr + len > end)
246 1.1 plunky return false;
247 1.1 plunky
248 1.1 plunky ptr += len;
249 1.1 plunky break;
250 1.1 plunky
251 1.1 plunky case SDP_DATA_SEQ8:
252 1.1 plunky case SDP_DATA_ALT8:
253 1.1 plunky if (ptr + 1 > end)
254 1.1 plunky return false;
255 1.1 plunky
256 1.1 plunky len = *ptr;
257 1.1 plunky ptr += 1;
258 1.1 plunky
259 1.1 plunky if (ptr + len > end)
260 1.1 plunky return false;
261 1.1 plunky
262 1.1 plunky if (!_sdp_data_valid(ptr, ptr + len))
263 1.1 plunky return false;
264 1.1 plunky
265 1.1 plunky ptr += len;
266 1.1 plunky break;
267 1.1 plunky
268 1.1 plunky case SDP_DATA_SEQ16:
269 1.1 plunky case SDP_DATA_ALT16:
270 1.1 plunky if (ptr + 2 > end)
271 1.1 plunky return false;
272 1.1 plunky
273 1.1 plunky len = be16dec(ptr);
274 1.1 plunky ptr += 2;
275 1.1 plunky
276 1.1 plunky if (ptr + len > end)
277 1.1 plunky return false;
278 1.1 plunky
279 1.1 plunky if (!_sdp_data_valid(ptr, ptr + len))
280 1.1 plunky return false;
281 1.1 plunky
282 1.1 plunky ptr += len;
283 1.1 plunky break;
284 1.1 plunky
285 1.1 plunky case SDP_DATA_SEQ32:
286 1.1 plunky case SDP_DATA_ALT32:
287 1.1 plunky if (ptr + 4 > end)
288 1.1 plunky return false;
289 1.1 plunky
290 1.1 plunky len = be32dec(ptr);
291 1.1 plunky ptr += 4;
292 1.1 plunky
293 1.1 plunky if (ptr + len > end)
294 1.1 plunky return false;
295 1.1 plunky
296 1.1 plunky if (!_sdp_data_valid(ptr, ptr + len))
297 1.1 plunky return false;
298 1.1 plunky
299 1.1 plunky ptr += len;
300 1.1 plunky break;
301 1.1 plunky
302 1.1 plunky default:
303 1.1 plunky return false;
304 1.1 plunky }
305 1.1 plunky }
306 1.1 plunky
307 1.1 plunky return true;
308 1.1 plunky }
309 1.1 plunky
310 1.1 plunky bool
311 1.1 plunky sdp_data_valid(const sdp_data_t *data)
312 1.1 plunky {
313 1.1 plunky
314 1.1 plunky if (data->next == NULL || data->end == NULL)
315 1.1 plunky return false;
316 1.1 plunky
317 1.1 plunky if (data->next >= data->end)
318 1.1 plunky return false;
319 1.1 plunky
320 1.1 plunky return _sdp_data_valid(data->next, data->end);
321 1.1 plunky }
322 1.1 plunky
323 1.1 plunky /******************************************************************************
324 1.1 plunky * sdp_data_print(data, indent)
325 1.1 plunky *
326 1.1 plunky * print out a SDP data element list in human readable format
327 1.1 plunky */
328 1.1 plunky static void
329 1.1 plunky _sdp_put(int indent, const char *type, const char *fmt, ...)
330 1.1 plunky {
331 1.1 plunky va_list ap;
332 1.1 plunky
333 1.1 plunky indent = printf("%*s%s", indent, "", type);
334 1.1 plunky indent = 18 - indent;
335 1.1 plunky if (indent < 2)
336 1.1 plunky indent = 2;
337 1.1 plunky
338 1.1 plunky printf("%*s", indent, "");
339 1.1 plunky
340 1.1 plunky va_start(ap, fmt);
341 1.1 plunky vprintf(fmt, ap);
342 1.1 plunky va_end(ap);
343 1.1 plunky
344 1.1 plunky printf("\n");
345 1.1 plunky }
346 1.1 plunky
347 1.1 plunky static void
348 1.1 plunky _sdp_putstr(int indent, int style, const char *type,
349 1.1 plunky const uint8_t *str, size_t len)
350 1.1 plunky {
351 1.1 plunky char buf[50], *dst = buf;
352 1.1 plunky
353 1.1 plunky indent = printf("%*s%s(%zu)", indent, "", type, len);
354 1.1 plunky indent = 18 - indent;
355 1.1 plunky if (indent < 2)
356 1.1 plunky indent = 2;
357 1.1 plunky
358 1.1 plunky printf("%*s", indent, "");
359 1.1 plunky
360 1.1 plunky style |= VIS_NL;
361 1.2 plunky buf[0] = '\0';
362 1.1 plunky
363 1.1 plunky while (len > 0 && (dst + 5) < (buf + sizeof(buf))) {
364 1.1 plunky dst = vis(dst, str[0], style, (len > 0 ? str[1] : 0));
365 1.1 plunky str++;
366 1.1 plunky len--;
367 1.1 plunky }
368 1.1 plunky
369 1.1 plunky printf("\"%s%s\n", buf, (len == 0 ? "\"" : " ..."));
370 1.1 plunky }
371 1.1 plunky
372 1.1 plunky bool
373 1.1 plunky _sdp_data_print(const uint8_t *next, const uint8_t *end, int indent)
374 1.1 plunky {
375 1.1 plunky size_t len;
376 1.1 plunky
377 1.1 plunky while (next < end) {
378 1.1 plunky if (next + 1 > end)
379 1.1 plunky return false;
380 1.1 plunky
381 1.1 plunky switch (*next++) {
382 1.1 plunky case SDP_DATA_NIL:
383 1.1 plunky _sdp_put(indent, "nil", "");
384 1.1 plunky break;
385 1.1 plunky
386 1.1 plunky case SDP_DATA_BOOL:
387 1.1 plunky if (next + 1 > end)
388 1.1 plunky return false;
389 1.1 plunky
390 1.1 plunky _sdp_put(indent, "bool", "%s",
391 1.1 plunky (*next == 0x00 ? "false" : "true"));
392 1.1 plunky
393 1.1 plunky next += 1;
394 1.1 plunky break;
395 1.1 plunky
396 1.1 plunky case SDP_DATA_INT8:
397 1.1 plunky if (next + 1 > end)
398 1.1 plunky return false;
399 1.1 plunky
400 1.1 plunky _sdp_put(indent, "int8", "%" PRId8,
401 1.1 plunky *(const int8_t *)next);
402 1.1 plunky next += 1;
403 1.1 plunky break;
404 1.1 plunky
405 1.1 plunky case SDP_DATA_UINT8:
406 1.1 plunky if (next + 1 > end)
407 1.1 plunky return false;
408 1.1 plunky
409 1.1 plunky _sdp_put(indent, "uint8", "0x%02" PRIx8,
410 1.1 plunky *next);
411 1.1 plunky next += 1;
412 1.1 plunky break;
413 1.1 plunky
414 1.1 plunky case SDP_DATA_INT16:
415 1.1 plunky if (next + 2 > end)
416 1.1 plunky return false;
417 1.1 plunky
418 1.1 plunky _sdp_put(indent, "int16", "%" PRId16,
419 1.1 plunky (int16_t)be16dec(next));
420 1.1 plunky next += 2;
421 1.1 plunky break;
422 1.1 plunky
423 1.1 plunky case SDP_DATA_UINT16:
424 1.1 plunky if (next + 2 > end)
425 1.1 plunky return false;
426 1.1 plunky
427 1.1 plunky _sdp_put(indent, "uint16", "0x%04" PRIx16,
428 1.1 plunky be16dec(next));
429 1.1 plunky next += 2;
430 1.1 plunky break;
431 1.1 plunky
432 1.1 plunky case SDP_DATA_UUID16:
433 1.1 plunky if (next + 2 > end)
434 1.1 plunky return false;
435 1.1 plunky
436 1.1 plunky _sdp_put(indent, "uuid16", "0x%04" PRIx16,
437 1.1 plunky be16dec(next));
438 1.1 plunky next += 2;
439 1.1 plunky break;
440 1.1 plunky
441 1.1 plunky case SDP_DATA_INT32:
442 1.1 plunky if (next + 4 > end)
443 1.1 plunky return false;
444 1.1 plunky
445 1.1 plunky _sdp_put(indent, "int32", "%" PRId32,
446 1.1 plunky (int32_t)be32dec(next));
447 1.1 plunky next += 4;
448 1.1 plunky break;
449 1.1 plunky
450 1.1 plunky case SDP_DATA_UINT32:
451 1.1 plunky if (next + 4 > end)
452 1.1 plunky return false;
453 1.1 plunky
454 1.1 plunky _sdp_put(indent, "uint32", "0x%08" PRIx32,
455 1.1 plunky be32dec(next));
456 1.1 plunky next += 4;
457 1.1 plunky break;
458 1.1 plunky
459 1.1 plunky case SDP_DATA_UUID32:
460 1.1 plunky if (next + 4 > end)
461 1.1 plunky return false;
462 1.1 plunky
463 1.1 plunky _sdp_put(indent, "uuid32", "0x%08" PRIx32,
464 1.1 plunky be32dec(next));
465 1.1 plunky next += 4;
466 1.1 plunky break;
467 1.1 plunky
468 1.1 plunky case SDP_DATA_INT64:
469 1.1 plunky if (next + 8 > end)
470 1.1 plunky return false;
471 1.1 plunky
472 1.1 plunky _sdp_put(indent, "int64", "%" PRId64,
473 1.1 plunky (int64_t)be64dec(next));
474 1.1 plunky next += 8;
475 1.1 plunky break;
476 1.1 plunky
477 1.1 plunky case SDP_DATA_UINT64:
478 1.1 plunky if (next + 8 > end)
479 1.1 plunky return false;
480 1.1 plunky
481 1.1 plunky _sdp_put(indent, "uint64", "0x%016" PRIx64,
482 1.1 plunky be64dec(next));
483 1.1 plunky next += 8;
484 1.1 plunky break;
485 1.1 plunky
486 1.1 plunky case SDP_DATA_INT128:
487 1.1 plunky if (next + 16 > end)
488 1.1 plunky return false;
489 1.1 plunky
490 1.1 plunky _sdp_put(indent, "int128",
491 1.1 plunky "0x%02x%02x%02x%02x%02x%02x%02x%02x"
492 1.1 plunky "%02x%02x%02x%02x%02x%02x%02x%02x",
493 1.1 plunky next[0], next[1], next[2], next[3],
494 1.1 plunky next[4], next[5], next[6], next[7],
495 1.1 plunky next[8], next[9], next[10], next[11],
496 1.1 plunky next[12], next[13], next[14], next[15]);
497 1.1 plunky next += 16;
498 1.1 plunky break;
499 1.1 plunky
500 1.1 plunky case SDP_DATA_UINT128:
501 1.1 plunky if (next + 16 > end)
502 1.1 plunky return false;
503 1.1 plunky
504 1.1 plunky _sdp_put(indent, "uint128",
505 1.1 plunky "0x%02x%02x%02x%02x%02x%02x%02x%02x"
506 1.1 plunky "%02x%02x%02x%02x%02x%02x%02x%02x",
507 1.1 plunky next[0], next[1], next[2], next[3],
508 1.1 plunky next[4], next[5], next[6], next[7],
509 1.1 plunky next[8], next[9], next[10], next[11],
510 1.1 plunky next[12], next[13], next[14], next[15]);
511 1.1 plunky next += 16;
512 1.1 plunky break;
513 1.1 plunky
514 1.1 plunky case SDP_DATA_UUID128:
515 1.1 plunky if (next + 16 > end)
516 1.1 plunky return false;
517 1.1 plunky
518 1.1 plunky _sdp_put(indent, "uuid128",
519 1.1 plunky "%02x%02x%02x%02x-"
520 1.1 plunky "%02x%02x-"
521 1.1 plunky "%02x%02x-"
522 1.1 plunky "%02x%02x-"
523 1.1 plunky "%02x%02x%02x%02x%02x%02x",
524 1.1 plunky next[0], next[1], next[2], next[3],
525 1.1 plunky next[4], next[5],
526 1.1 plunky next[6], next[7],
527 1.1 plunky next[8], next[9],
528 1.1 plunky next[10], next[11], next[12],
529 1.1 plunky next[13], next[14], next[15]);
530 1.1 plunky next += 16;
531 1.1 plunky break;
532 1.1 plunky
533 1.1 plunky case SDP_DATA_STR8:
534 1.1 plunky if (next + 1 > end)
535 1.1 plunky return false;
536 1.1 plunky
537 1.1 plunky len = *next;
538 1.1 plunky next += 1;
539 1.1 plunky
540 1.1 plunky if (next + len > end)
541 1.1 plunky return false;
542 1.1 plunky
543 1.1 plunky _sdp_putstr(indent, VIS_CSTYLE, "str8", next, len);
544 1.1 plunky next += len;
545 1.1 plunky break;
546 1.1 plunky
547 1.1 plunky case SDP_DATA_URL8:
548 1.1 plunky if (next + 1 > end)
549 1.1 plunky return false;
550 1.1 plunky
551 1.1 plunky len = *next;
552 1.1 plunky next += 1;
553 1.1 plunky
554 1.1 plunky if (next + len > end)
555 1.1 plunky return false;
556 1.1 plunky
557 1.1 plunky _sdp_putstr(indent, VIS_HTTPSTYLE, "url8", next, len);
558 1.1 plunky next += len;
559 1.1 plunky break;
560 1.1 plunky
561 1.1 plunky case SDP_DATA_STR16:
562 1.1 plunky if (next + 2 > end)
563 1.1 plunky return false;
564 1.1 plunky
565 1.1 plunky len = be16dec(next);
566 1.1 plunky next += 2;
567 1.1 plunky
568 1.1 plunky if (next + len > end)
569 1.1 plunky return false;
570 1.1 plunky
571 1.1 plunky _sdp_putstr(indent, VIS_CSTYLE, "str16", next, len);
572 1.1 plunky next += len;
573 1.1 plunky break;
574 1.1 plunky
575 1.1 plunky case SDP_DATA_URL16:
576 1.1 plunky if (next + 2 > end)
577 1.1 plunky return false;
578 1.1 plunky
579 1.1 plunky len = be16dec(next);
580 1.1 plunky next += 2;
581 1.1 plunky
582 1.1 plunky if (next + len > end)
583 1.1 plunky return false;
584 1.1 plunky
585 1.1 plunky _sdp_putstr(indent, VIS_HTTPSTYLE, "url16", next, len);
586 1.1 plunky next += len;
587 1.1 plunky break;
588 1.1 plunky
589 1.1 plunky case SDP_DATA_STR32:
590 1.1 plunky if (next + 4 > end)
591 1.1 plunky return false;
592 1.1 plunky
593 1.1 plunky len = be32dec(next);
594 1.1 plunky next += 4;
595 1.1 plunky
596 1.1 plunky if (next + len > end)
597 1.1 plunky return false;
598 1.1 plunky
599 1.1 plunky _sdp_putstr(indent, VIS_CSTYLE, "str32", next, len);
600 1.1 plunky next += len;
601 1.1 plunky break;
602 1.1 plunky
603 1.1 plunky case SDP_DATA_URL32:
604 1.1 plunky if (next + 4 > end)
605 1.1 plunky return false;
606 1.1 plunky
607 1.1 plunky len = be32dec(next);
608 1.1 plunky next += 4;
609 1.1 plunky
610 1.1 plunky if (next + len > end)
611 1.1 plunky return false;
612 1.1 plunky
613 1.1 plunky _sdp_putstr(indent, VIS_HTTPSTYLE, "url32", next, len);
614 1.1 plunky next += len;
615 1.1 plunky break;
616 1.1 plunky
617 1.1 plunky case SDP_DATA_SEQ8:
618 1.1 plunky if (next + 1 > end)
619 1.1 plunky return false;
620 1.1 plunky
621 1.1 plunky len = *next;
622 1.1 plunky next += 1;
623 1.1 plunky
624 1.1 plunky if (next + len > end)
625 1.1 plunky return false;
626 1.1 plunky
627 1.1 plunky printf("%*sseq8(%zu)\n", indent, "", len);
628 1.1 plunky if (!_sdp_data_print(next, next + len, indent + 1))
629 1.1 plunky return false;
630 1.1 plunky
631 1.1 plunky next += len;
632 1.1 plunky break;
633 1.1 plunky
634 1.1 plunky case SDP_DATA_ALT8:
635 1.1 plunky if (next + 1 > end)
636 1.1 plunky return false;
637 1.1 plunky
638 1.1 plunky len = *next;
639 1.1 plunky next += 1;
640 1.1 plunky
641 1.1 plunky if (next + len > end)
642 1.1 plunky return false;
643 1.1 plunky
644 1.1 plunky printf("%*salt8(%zu)\n", indent, "", len);
645 1.1 plunky if (!_sdp_data_print(next, next + len, indent + 1))
646 1.1 plunky return false;
647 1.1 plunky
648 1.1 plunky next += len;
649 1.1 plunky break;
650 1.1 plunky
651 1.1 plunky case SDP_DATA_SEQ16:
652 1.1 plunky if (next + 2 > end)
653 1.1 plunky return false;
654 1.1 plunky
655 1.1 plunky len = be16dec(next);
656 1.1 plunky next += 2;
657 1.1 plunky
658 1.1 plunky if (next + len > end)
659 1.1 plunky return false;
660 1.1 plunky
661 1.1 plunky printf("%*sseq16(%zu)\n", indent, "", len);
662 1.1 plunky if (!_sdp_data_print(next, next + len, indent + 1))
663 1.1 plunky return false;
664 1.1 plunky
665 1.1 plunky next += len;
666 1.1 plunky break;
667 1.1 plunky
668 1.1 plunky case SDP_DATA_ALT16:
669 1.1 plunky if (next + 2 > end)
670 1.1 plunky return false;
671 1.1 plunky
672 1.1 plunky len = be16dec(next);
673 1.1 plunky next += 2;
674 1.1 plunky
675 1.1 plunky if (next + len > end)
676 1.1 plunky return false;
677 1.1 plunky
678 1.1 plunky printf("%*salt16(%zu)\n", indent, "", len);
679 1.1 plunky if (!_sdp_data_print(next, next + len, indent + 1))
680 1.1 plunky return false;
681 1.1 plunky
682 1.1 plunky next += len;
683 1.1 plunky break;
684 1.1 plunky
685 1.1 plunky case SDP_DATA_SEQ32:
686 1.1 plunky if (next + 4 > end)
687 1.1 plunky return false;
688 1.1 plunky
689 1.1 plunky len = be32dec(next);
690 1.1 plunky next += 4;
691 1.1 plunky
692 1.1 plunky if (next + len > end)
693 1.1 plunky return false;
694 1.1 plunky
695 1.1 plunky printf("%*sseq32(%zu)\n", indent, "", len);
696 1.1 plunky if (!_sdp_data_print(next, next + len, indent + 1))
697 1.1 plunky return false;
698 1.1 plunky
699 1.1 plunky next += len;
700 1.1 plunky break;
701 1.1 plunky
702 1.1 plunky case SDP_DATA_ALT32:
703 1.1 plunky if (next + 4 > end)
704 1.1 plunky return false;
705 1.1 plunky
706 1.1 plunky len = be32dec(next);
707 1.1 plunky next += 4;
708 1.1 plunky
709 1.1 plunky if (next + len > end)
710 1.1 plunky return false;
711 1.1 plunky
712 1.1 plunky printf("%*salt32(%zu)\n", indent, "", len);
713 1.1 plunky if (!_sdp_data_print(next, next + len, indent + 1))
714 1.1 plunky return false;
715 1.1 plunky
716 1.1 plunky next += len;
717 1.1 plunky break;
718 1.1 plunky
719 1.1 plunky default:
720 1.1 plunky return false;
721 1.1 plunky }
722 1.1 plunky }
723 1.1 plunky
724 1.1 plunky return true;
725 1.1 plunky }
726 1.1 plunky
727 1.1 plunky void
728 1.1 plunky sdp_data_print(const sdp_data_t *data, int indent)
729 1.1 plunky {
730 1.1 plunky
731 1.1 plunky if (!_sdp_data_print(data->next, data->end, indent))
732 1.1 plunky printf("SDP data error\n");
733 1.1 plunky }
734