]> git.ipfire.org Git - thirdparty/strongswan.git/blob - src/libcharon/encoding/parser.c
Migrated parser_t to INIT/METHOD macros.
[thirdparty/strongswan.git] / src / libcharon / encoding / parser.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 <stdlib.h>
18 #include <arpa/inet.h>
19 #include <string.h>
20
21 #include "parser.h"
22
23 #include <library.h>
24 #include <daemon.h>
25 #include <utils/linked_list.h>
26 #include <encoding/payloads/encodings.h>
27 #include <encoding/payloads/payload.h>
28 #include <encoding/payloads/sa_payload.h>
29 #include <encoding/payloads/proposal_substructure.h>
30 #include <encoding/payloads/transform_substructure.h>
31 #include <encoding/payloads/transform_attribute.h>
32 #include <encoding/payloads/ke_payload.h>
33 #include <encoding/payloads/nonce_payload.h>
34 #include <encoding/payloads/id_payload.h>
35 #include <encoding/payloads/notify_payload.h>
36 #include <encoding/payloads/encryption_payload.h>
37 #include <encoding/payloads/auth_payload.h>
38 #include <encoding/payloads/cert_payload.h>
39 #include <encoding/payloads/certreq_payload.h>
40 #include <encoding/payloads/ts_payload.h>
41 #include <encoding/payloads/delete_payload.h>
42 #include <encoding/payloads/vendor_id_payload.h>
43 #include <encoding/payloads/cp_payload.h>
44 #include <encoding/payloads/configuration_attribute.h>
45 #include <encoding/payloads/eap_payload.h>
46 #include <encoding/payloads/unknown_payload.h>
47
48
49 typedef struct private_parser_t private_parser_t;
50
51 /**
52 * Private data stored in a context.
53 *
54 * Contains pointers and counters to store current state.
55 */
56 struct private_parser_t {
57 /**
58 * Public members, see parser_t.
59 */
60 parser_t public;
61
62 /**
63 * Current bit for reading in input data.
64 */
65 u_int8_t bit_pos;
66
67 /**
68 * Current byte for reading in input data.
69 */
70 u_int8_t *byte_pos;
71
72 /**
73 * Input data to parse.
74 */
75 u_int8_t *input;
76
77 /**
78 * Roof of input, used for length-checking.
79 */
80 u_int8_t *input_roof;
81
82 /**
83 * Set of encoding rules for this parsing session.
84 */
85 encoding_rule_t *rules;
86 };
87
88 /**
89 * Log invalid length error
90 */
91 static bool short_input(private_parser_t *this, int number)
92 {
93 DBG1(DBG_ENC, " not enough input to parse rule %d %N",
94 number, encoding_type_names, this->rules[number].type);
95 return FALSE;
96 }
97
98 /**
99 * Log unaligned rules
100 */
101 static bool bad_bitpos(private_parser_t *this, int number)
102 {
103 DBG1(DBG_ENC, " found rule %d %N on bitpos %d",
104 number, encoding_type_names, this->rules[number].type, this->bit_pos);
105 return FALSE;
106 }
107
108 /**
109 * Parse a 4-Bit unsigned integer from the current parsing position.
110 */
111 static bool parse_uint4(private_parser_t *this, int rule_number,
112 u_int8_t *output_pos)
113 {
114 if (this->byte_pos + sizeof(u_int8_t) > this->input_roof)
115 {
116 return short_input(this, rule_number);
117 }
118 switch (this->bit_pos)
119 {
120 case 0:
121 if (output_pos)
122 {
123 *output_pos = *(this->byte_pos) >> 4;
124 }
125 this->bit_pos = 4;
126 break;
127 case 4:
128 if (output_pos)
129 {
130 *output_pos = *(this->byte_pos) & 0x0F;
131 }
132 this->bit_pos = 0;
133 this->byte_pos++;
134 break;
135 default:
136 return bad_bitpos(this, rule_number);
137 }
138 if (output_pos)
139 {
140 DBG3(DBG_ENC, " => %d", *output_pos);
141 }
142 return TRUE;
143 }
144
145 /**
146 * Parse a 8-Bit unsigned integer from the current parsing position.
147 */
148 static bool parse_uint8(private_parser_t *this, int rule_number,
149 u_int8_t *output_pos)
150 {
151 if (this->byte_pos + sizeof(u_int8_t) > this->input_roof)
152 {
153 return short_input(this, rule_number);
154 }
155 if (this->bit_pos)
156 {
157 return bad_bitpos(this, rule_number);
158 }
159 if (output_pos)
160 {
161 *output_pos = *(this->byte_pos);
162 DBG3(DBG_ENC, " => %d", *output_pos);
163 }
164 this->byte_pos++;
165 return TRUE;
166 }
167
168 /**
169 * Parse a 15-Bit unsigned integer from the current parsing position.
170 */
171 static bool parse_uint15(private_parser_t *this, int rule_number,
172 u_int16_t *output_pos)
173 {
174 if (this->byte_pos + sizeof(u_int16_t) > this->input_roof)
175 {
176 return short_input(this, rule_number);
177 }
178 if (this->bit_pos != 1)
179 {
180 return bad_bitpos(this, rule_number);
181 }
182 if (output_pos)
183 {
184 memcpy(output_pos, this->byte_pos, sizeof(u_int16_t));
185 *output_pos = ntohs(*output_pos) & ~0x8000;
186 DBG3(DBG_ENC, " => %d", *output_pos);
187 }
188 this->byte_pos += sizeof(u_int16_t);
189 this->bit_pos = 0;
190 return TRUE;
191 }
192
193 /**
194 * Parse a 16-Bit unsigned integer from the current parsing position.
195 */
196 static bool parse_uint16(private_parser_t *this, int rule_number,
197 u_int16_t *output_pos)
198 {
199 if (this->byte_pos + sizeof(u_int16_t) > this->input_roof)
200 {
201 return short_input(this, rule_number);
202 }
203 if (this->bit_pos)
204 {
205 return bad_bitpos(this, rule_number);
206 }
207 if (output_pos)
208 {
209 memcpy(output_pos, this->byte_pos, sizeof(u_int16_t));
210 *output_pos = ntohs(*output_pos);
211 DBG3(DBG_ENC, " => %d", *output_pos);
212 }
213 this->byte_pos += sizeof(u_int16_t);
214 return TRUE;
215 }
216 /**
217 * Parse a 32-Bit unsigned integer from the current parsing position.
218 */
219 static bool parse_uint32(private_parser_t *this, int rule_number,
220 u_int32_t *output_pos)
221 {
222 if (this->byte_pos + sizeof(u_int32_t) > this->input_roof)
223 {
224 return short_input(this, rule_number);
225 }
226 if (this->bit_pos)
227 {
228 return bad_bitpos(this, rule_number);
229 }
230 if (output_pos)
231 {
232 memcpy(output_pos, this->byte_pos, sizeof(u_int32_t));
233 *output_pos = ntohl(*output_pos);
234 DBG3(DBG_ENC, " => %d", *output_pos);
235 }
236 this->byte_pos += sizeof(u_int32_t);
237 return TRUE;
238 }
239
240 /**
241 * Parse a given amount of bytes and writes them to a specific location
242 */
243 static bool parse_bytes(private_parser_t *this, int rule_number,
244 u_int8_t *output_pos, int bytes)
245 {
246 if (this->byte_pos + bytes > this->input_roof)
247 {
248 return short_input(this, rule_number);
249 }
250 if (this->bit_pos)
251 {
252 return bad_bitpos(this, rule_number);
253 }
254 if (output_pos)
255 {
256 memcpy(output_pos, this->byte_pos, bytes);
257 DBG3(DBG_ENC, " => %b", output_pos, bytes);
258 }
259 this->byte_pos += bytes;
260 return TRUE;
261 }
262
263 /**
264 * Parse a single Bit from the current parsing position
265 */
266 static bool parse_bit(private_parser_t *this, int rule_number,
267 bool *output_pos)
268 {
269 if (this->byte_pos + sizeof(u_int8_t) > this->input_roof)
270 {
271 return short_input(this, rule_number);
272 }
273 if (output_pos)
274 {
275 u_int8_t mask;
276 mask = 0x01 << (7 - this->bit_pos);
277 *output_pos = *this->byte_pos & mask;
278
279 if (*output_pos)
280 { /* set to a "clean", comparable true */
281 *output_pos = TRUE;
282 }
283 DBG3(DBG_ENC, " => %d", *output_pos);
284 }
285 this->bit_pos = (this->bit_pos + 1) % 8;
286 if (this->bit_pos == 0)
287 {
288 this->byte_pos++;
289 }
290 return TRUE;
291 }
292
293 /**
294 * Parse substructures in a list.
295 */
296 static bool parse_list(private_parser_t *this, int rule_number,
297 linked_list_t **output_pos, payload_type_t payload_type, int length)
298 {
299 linked_list_t *list = *output_pos;
300
301 if (length < 0)
302 {
303 return short_input(this, rule_number);
304 }
305 if (this->bit_pos)
306 {
307 return bad_bitpos(this, rule_number);
308 }
309 while (length > 0)
310 {
311 u_int8_t *pos_before = this->byte_pos;
312 payload_t *payload;
313
314 DBG2(DBG_ENC, " %d bytes left, parsing recursively %N",
315 length, payload_type_names, payload_type);
316
317 if (this->public.parse_payload(&this->public, payload_type,
318 &payload) != SUCCESS)
319 {
320 DBG1(DBG_ENC, " parsing of a %N substructure failed",
321 payload_type_names, payload_type);
322 return FALSE;
323 }
324 list->insert_last(list, payload);
325 length -= this->byte_pos - pos_before;
326 }
327 if (length != 0)
328 { /* must yield exactly to zero */
329 DBG1(DBG_ENC, " length of %N substructure list invalid",
330 payload_type_names, payload_type);
331 return FALSE;
332 }
333 *output_pos = list;
334 return TRUE;
335 }
336
337 /**
338 * Parse data from current parsing position in a chunk.
339 */
340 static bool parse_chunk(private_parser_t *this, int rule_number,
341 chunk_t *output_pos, int length)
342 {
343 if (this->byte_pos + length > this->input_roof)
344 {
345 return short_input(this, rule_number);
346 }
347 if (this->bit_pos)
348 {
349 return bad_bitpos(this, rule_number);
350 }
351 if (output_pos)
352 {
353 *output_pos = chunk_alloc(length);
354 memcpy(output_pos->ptr, this->byte_pos, length);
355 DBG3(DBG_ENC, " => %b", output_pos->ptr, length);
356 }
357 this->byte_pos += length;
358 return TRUE;
359 }
360
361 METHOD(parser_t, parse_payload, status_t,
362 private_parser_t *this, payload_type_t payload_type, payload_t **payload)
363 {
364 payload_t *pld;
365 void *output;
366 size_t rule_count;
367 int payload_length = 0, spi_size = 0, attribute_length = 0;
368 u_int16_t ts_type = 0;
369 bool attribute_format = FALSE;
370 int rule_number;
371 encoding_rule_t *rule;
372
373 /* create instance of the payload to parse */
374 pld = payload_create(payload_type);
375
376 DBG2(DBG_ENC, "parsing %N payload, %d bytes left",
377 payload_type_names, payload_type, this->input_roof - this->byte_pos);
378
379 DBG3(DBG_ENC, "parsing payload from %b",
380 this->byte_pos, this->input_roof - this->byte_pos);
381
382 /* base pointer for output, avoids casting in every rule */
383 output = pld;
384
385 /* parse the payload with its own rulse */
386 pld->get_encoding_rules(pld, &this->rules, &rule_count);
387 for (rule_number = 0; rule_number < rule_count; rule_number++)
388 {
389 rule = &(this->rules[rule_number]);
390 DBG2(DBG_ENC, " parsing rule %d %N",
391 rule_number, encoding_type_names, rule->type);
392 switch (rule->type)
393 {
394 case U_INT_4:
395 {
396 if (!parse_uint4(this, rule_number, output + rule->offset))
397 {
398 pld->destroy(pld);
399 return PARSE_ERROR;
400 }
401 break;
402 }
403 case U_INT_8:
404 case RESERVED_BYTE:
405 {
406 if (!parse_uint8(this, rule_number, output + rule->offset))
407 {
408 pld->destroy(pld);
409 return PARSE_ERROR;
410 }
411 break;
412 }
413 case U_INT_16:
414 {
415 if (!parse_uint16(this, rule_number, output + rule->offset))
416 {
417 pld->destroy(pld);
418 return PARSE_ERROR;
419 }
420 break;
421 }
422 case U_INT_32:
423 case HEADER_LENGTH:
424 {
425 if (!parse_uint32(this, rule_number, output + rule->offset))
426 {
427 pld->destroy(pld);
428 return PARSE_ERROR;
429 }
430 break;
431 }
432 case IKE_SPI:
433 {
434 if (!parse_bytes(this, rule_number, output + rule->offset, 8))
435 {
436 pld->destroy(pld);
437 return PARSE_ERROR;
438 }
439 break;
440 }
441 case RESERVED_BIT:
442 case FLAG:
443 {
444 if (!parse_bit(this, rule_number, output + rule->offset))
445 {
446 pld->destroy(pld);
447 return PARSE_ERROR;
448 }
449 break;
450 }
451 case PAYLOAD_LENGTH:
452 {
453 if (!parse_uint16(this, rule_number, output + rule->offset))
454 {
455 pld->destroy(pld);
456 return PARSE_ERROR;
457 }
458 /* parsed u_int16 should be aligned */
459 payload_length = *(u_int16_t*)(output + rule->offset);
460 if (payload_length < UNKNOWN_PAYLOAD_HEADER_LENGTH)
461 {
462 pld->destroy(pld);
463 return PARSE_ERROR;
464 }
465 break;
466 }
467 case SPI_SIZE:
468 {
469 if (!parse_uint8(this, rule_number, output + rule->offset))
470 {
471 pld->destroy(pld);
472 return PARSE_ERROR;
473 }
474 spi_size = *(u_int8_t*)(output + rule->offset);
475 break;
476 }
477 case SPI:
478 {
479 if (!parse_chunk(this, rule_number, output + rule->offset,
480 spi_size))
481 {
482 pld->destroy(pld);
483 return PARSE_ERROR;
484 }
485 break;
486 }
487 case PROPOSALS:
488 {
489 if (payload_length < SA_PAYLOAD_HEADER_LENGTH ||
490 !parse_list(this, rule_number, output + rule->offset,
491 PROPOSAL_SUBSTRUCTURE,
492 payload_length - SA_PAYLOAD_HEADER_LENGTH))
493 {
494 pld->destroy(pld);
495 return PARSE_ERROR;
496 }
497 break;
498 }
499 case TRANSFORMS:
500 {
501 if (payload_length <
502 spi_size + PROPOSAL_SUBSTRUCTURE_HEADER_LENGTH ||
503 !parse_list(this, rule_number, output + rule->offset,
504 TRANSFORM_SUBSTRUCTURE, payload_length - spi_size -
505 PROPOSAL_SUBSTRUCTURE_HEADER_LENGTH))
506 {
507 pld->destroy(pld);
508 return PARSE_ERROR;
509 }
510 break;
511 }
512 case TRANSFORM_ATTRIBUTES:
513 {
514 if (payload_length < TRANSFORM_SUBSTRUCTURE_HEADER_LENGTH ||
515 !parse_list(this, rule_number, output + rule->offset,
516 TRANSFORM_ATTRIBUTE,
517 payload_length - TRANSFORM_SUBSTRUCTURE_HEADER_LENGTH))
518 {
519 pld->destroy(pld);
520 return PARSE_ERROR;
521 }
522 break;
523 }
524 case CONFIGURATION_ATTRIBUTES:
525 {
526 if (payload_length < CP_PAYLOAD_HEADER_LENGTH ||
527 !parse_list(this, rule_number, output + rule->offset,
528 CONFIGURATION_ATTRIBUTE,
529 payload_length - CP_PAYLOAD_HEADER_LENGTH))
530 {
531 pld->destroy(pld);
532 return PARSE_ERROR;
533 }
534 break;
535 }
536 case ATTRIBUTE_FORMAT:
537 {
538 if (!parse_bit(this, rule_number, output + rule->offset))
539 {
540 pld->destroy(pld);
541 return PARSE_ERROR;
542 }
543 attribute_format = *(bool*)(output + rule->offset);
544 break;
545 }
546 case ATTRIBUTE_TYPE:
547 {
548 if (!parse_uint15(this, rule_number, output + rule->offset))
549 {
550 pld->destroy(pld);
551 return PARSE_ERROR;
552 }
553 break;
554 }
555 case CONFIGURATION_ATTRIBUTE_LENGTH:
556 {
557 if (!parse_uint16(this, rule_number, output + rule->offset))
558 {
559 pld->destroy(pld);
560 return PARSE_ERROR;
561 }
562 attribute_length = *(u_int16_t*)(output + rule->offset);
563 break;
564 }
565 case ATTRIBUTE_LENGTH_OR_VALUE:
566 {
567 if (!parse_uint16(this, rule_number, output + rule->offset))
568 {
569 pld->destroy(pld);
570 return PARSE_ERROR;
571 }
572 attribute_length = *(u_int16_t*)(output + rule->offset);
573 break;
574 }
575 case ATTRIBUTE_VALUE:
576 {
577 if (attribute_format == FALSE &&
578 !parse_chunk(this, rule_number, output + rule->offset,
579 attribute_length))
580 {
581 pld->destroy(pld);
582 return PARSE_ERROR;
583 }
584 break;
585 }
586 case NONCE_DATA:
587 {
588 if (payload_length < NONCE_PAYLOAD_HEADER_LENGTH ||
589 !parse_chunk(this, rule_number, output + rule->offset,
590 payload_length - NONCE_PAYLOAD_HEADER_LENGTH))
591 {
592 pld->destroy(pld);
593 return PARSE_ERROR;
594 }
595 break;
596 }
597 case ID_DATA:
598 {
599 if (payload_length < ID_PAYLOAD_HEADER_LENGTH ||
600 !parse_chunk(this, rule_number, output + rule->offset,
601 payload_length - ID_PAYLOAD_HEADER_LENGTH))
602 {
603 pld->destroy(pld);
604 return PARSE_ERROR;
605 }
606 break;
607 }
608 case AUTH_DATA:
609 {
610 if (payload_length < AUTH_PAYLOAD_HEADER_LENGTH ||
611 !parse_chunk(this, rule_number, output + rule->offset,
612 payload_length - AUTH_PAYLOAD_HEADER_LENGTH))
613 {
614 pld->destroy(pld);
615 return PARSE_ERROR;
616 }
617 break;
618 }
619 case CERT_DATA:
620 {
621 if (payload_length < CERT_PAYLOAD_HEADER_LENGTH ||
622 !parse_chunk(this, rule_number, output + rule->offset,
623 payload_length - CERT_PAYLOAD_HEADER_LENGTH))
624 {
625 pld->destroy(pld);
626 return PARSE_ERROR;
627 }
628 break;
629 }
630 case CERTREQ_DATA:
631 {
632 if (payload_length < CERTREQ_PAYLOAD_HEADER_LENGTH ||
633 !parse_chunk(this, rule_number, output + rule->offset,
634 payload_length - CERTREQ_PAYLOAD_HEADER_LENGTH))
635 {
636 pld->destroy(pld);
637 return PARSE_ERROR;
638 }
639 break;
640 }
641 case EAP_DATA:
642 {
643 if (payload_length < EAP_PAYLOAD_HEADER_LENGTH ||
644 !parse_chunk(this, rule_number, output + rule->offset,
645 payload_length - EAP_PAYLOAD_HEADER_LENGTH))
646 {
647 pld->destroy(pld);
648 return PARSE_ERROR;
649 }
650 break;
651 }
652 case SPIS:
653 {
654 if (payload_length < DELETE_PAYLOAD_HEADER_LENGTH ||
655 !parse_chunk(this, rule_number, output + rule->offset,
656 payload_length - DELETE_PAYLOAD_HEADER_LENGTH))
657 {
658 pld->destroy(pld);
659 return PARSE_ERROR;
660 }
661 break;
662 }
663 case VID_DATA:
664 {
665 if (payload_length < VENDOR_ID_PAYLOAD_HEADER_LENGTH ||
666 !parse_chunk(this, rule_number, output + rule->offset,
667 payload_length - VENDOR_ID_PAYLOAD_HEADER_LENGTH))
668 {
669 pld->destroy(pld);
670 return PARSE_ERROR;
671 }
672 break;
673 }
674 case CONFIGURATION_ATTRIBUTE_VALUE:
675 {
676 if (!parse_chunk(this, rule_number, output + rule->offset,
677 attribute_length))
678 {
679 pld->destroy(pld);
680 return PARSE_ERROR;
681 }
682 break;
683 }
684 case KEY_EXCHANGE_DATA:
685 {
686 if (payload_length < KE_PAYLOAD_HEADER_LENGTH ||
687 !parse_chunk(this, rule_number, output + rule->offset,
688 payload_length - KE_PAYLOAD_HEADER_LENGTH))
689 {
690 pld->destroy(pld);
691 return PARSE_ERROR;
692 }
693 break;
694 }
695 case NOTIFICATION_DATA:
696 {
697 if (payload_length < NOTIFY_PAYLOAD_HEADER_LENGTH + spi_size ||
698 !parse_chunk(this, rule_number, output + rule->offset,
699 payload_length - NOTIFY_PAYLOAD_HEADER_LENGTH - spi_size))
700 {
701 pld->destroy(pld);
702 return PARSE_ERROR;
703 }
704 break;
705 }
706 case ENCRYPTED_DATA:
707 {
708 if (payload_length < ENCRYPTION_PAYLOAD_HEADER_LENGTH ||
709 !parse_chunk(this, rule_number, output + rule->offset,
710 payload_length - ENCRYPTION_PAYLOAD_HEADER_LENGTH))
711 {
712 pld->destroy(pld);
713 return PARSE_ERROR;
714 }
715 break;
716 }
717 case TS_TYPE:
718 {
719 if (!parse_uint8(this, rule_number, output + rule->offset))
720 {
721 pld->destroy(pld);
722 return PARSE_ERROR;
723 }
724 ts_type = *(u_int8_t*)(output + rule->offset);
725 break;
726 }
727 case ADDRESS:
728 {
729 int address_length = (ts_type == TS_IPV4_ADDR_RANGE) ? 4 : 16;
730
731 if (!parse_chunk(this, rule_number, output + rule->offset,
732 address_length))
733 {
734 pld->destroy(pld);
735 return PARSE_ERROR;
736 }
737 break;
738 }
739 case TRAFFIC_SELECTORS:
740 {
741 if (payload_length < TS_PAYLOAD_HEADER_LENGTH ||
742 !parse_list(this, rule_number, output + rule->offset,
743 TRAFFIC_SELECTOR_SUBSTRUCTURE,
744 payload_length - TS_PAYLOAD_HEADER_LENGTH))
745 {
746 pld->destroy(pld);
747 return PARSE_ERROR;
748 }
749 break;
750 }
751 case UNKNOWN_DATA:
752 {
753 if (payload_length < UNKNOWN_PAYLOAD_HEADER_LENGTH ||
754 !parse_chunk(this, rule_number, output + rule->offset,
755 payload_length - UNKNOWN_PAYLOAD_HEADER_LENGTH))
756 {
757 pld->destroy(pld);
758 return PARSE_ERROR;
759 }
760 break;
761 }
762 default:
763 {
764 DBG1(DBG_ENC, " no rule to parse rule %d %N",
765 rule_number, encoding_type_names, rule->type);
766 pld->destroy(pld);
767 return PARSE_ERROR;
768 }
769 }
770 /* process next rulue */
771 rule++;
772 }
773
774 *payload = pld;
775 DBG2(DBG_ENC, "parsing %N payload finished",
776 payload_type_names, payload_type);
777 return SUCCESS;
778 }
779
780 METHOD(parser_t, get_remaining_byte_count, int,
781 private_parser_t *this)
782 {
783 return this->input_roof - this->byte_pos;
784 }
785
786 METHOD(parser_t, reset_context, void,
787 private_parser_t *this)
788 {
789 this->byte_pos = this->input;
790 this->bit_pos = 0;
791 }
792
793 METHOD(parser_t, destroy, void,
794 private_parser_t *this)
795 {
796 free(this);
797 }
798
799 /*
800 * Described in header.
801 */
802 parser_t *parser_create(chunk_t data)
803 {
804 private_parser_t *this;
805
806 INIT(this,
807 .public = {
808 .parse_payload = _parse_payload,
809 .reset_context = _reset_context,
810 .get_remaining_byte_count = _get_remaining_byte_count,
811 .destroy = _destroy,
812 },
813 .input = data.ptr,
814 .byte_pos = data.ptr,
815 .input_roof = data.ptr + data.len,
816 );
817
818 return &this->public;
819 }
820