4 * @brief Implementation of parser_t.
9 * Copyright (C) 2005-2006 Martin Willi
10 * Copyright (C) 2005 Jan Hutter
11 * Hochschule fuer Technik Rapperswil
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 #include <arpa/inet.h>
31 #include <definitions.h>
33 #include <utils/linked_list.h>
34 #include <encoding/payloads/encodings.h>
35 #include <encoding/payloads/payload.h>
36 #include <encoding/payloads/sa_payload.h>
37 #include <encoding/payloads/proposal_substructure.h>
38 #include <encoding/payloads/transform_substructure.h>
39 #include <encoding/payloads/transform_attribute.h>
40 #include <encoding/payloads/ke_payload.h>
41 #include <encoding/payloads/nonce_payload.h>
42 #include <encoding/payloads/id_payload.h>
43 #include <encoding/payloads/notify_payload.h>
44 #include <encoding/payloads/encryption_payload.h>
45 #include <encoding/payloads/auth_payload.h>
46 #include <encoding/payloads/cert_payload.h>
47 #include <encoding/payloads/certreq_payload.h>
48 #include <encoding/payloads/ts_payload.h>
49 #include <encoding/payloads/delete_payload.h>
50 #include <encoding/payloads/vendor_id_payload.h>
51 #include <encoding/payloads/cp_payload.h>
52 #include <encoding/payloads/configuration_attribute.h>
53 #include <encoding/payloads/eap_payload.h>
54 #include <encoding/payloads/unknown_payload.h>
57 typedef struct private_parser_t private_parser_t
;
60 * Private data stored in a context.
62 * Contains pointers and counters to store current state.
64 struct private_parser_t
{
66 * Public members, see parser_t.
71 * @brief Parse a 4-Bit unsigned integer from the current parsing position.
73 * @param this parser_t object
74 * @param rule_number number of current rule
75 * @param[out] output_pos pointer where to write the parsed result
78 * - PARSE_ERROR when not successful
80 status_t (*parse_uint4
) (private_parser_t
*this, int rule_number
, u_int8_t
*output_pos
);
83 * @brief Parse a 8-Bit unsigned integer from the current parsing position.
85 * @param this parser_t object
86 * @param rule_number number of current rule
87 * @param[out] output_pos pointer where to write the parsed result
90 * - PARSE_ERROR when not successful
92 status_t (*parse_uint8
) (private_parser_t
*this, int rule_number
, u_int8_t
*output_pos
);
95 * @brief Parse a 15-Bit unsigned integer from the current parsing position.
97 * This is a special case used for ATTRIBUTE_TYPE.
98 * Big-/Little-endian conversion is done here.
100 * @param this parser_t object
101 * @param rule_number number of current rule
102 * @param[out] output_pos pointer where to write the parsed result
105 * - PARSE_ERROR when not successful
107 status_t (*parse_uint15
) (private_parser_t
*this, int rule_number
, u_int16_t
*output_pos
);
110 * @brief Parse a 16-Bit unsigned integer from the current parsing position.
112 * Big-/Little-endian conversion is done here.
114 * @param this parser_t object
115 * @param rule_number number of current rule
116 * @param[out] output_pos pointer where to write the parsed result
119 * - PARSE_ERROR when not successful
121 status_t (*parse_uint16
) (private_parser_t
*this, int rule_number
, u_int16_t
*output_pos
);
124 * @brief Parse a 32-Bit unsigned integer from the current parsing position.
126 * Big-/Little-endian conversion is done here.
128 * @param this parser_t object
129 * @param rule_number number of current rule
130 * @param[out] output_pos pointer where to write the parsed result
133 * - PARSE_ERROR when not successful
135 status_t (*parse_uint32
) (private_parser_t
*this, int rule_number
, u_int32_t
*output_pos
);
138 * @brief Parse a 64-Bit unsigned integer from the current parsing position.
140 * @todo add support for big-endian machines.
142 * @param this parser_t object
143 * @param rule_number number of current rule
144 * @param[out] output_pos pointer where to write the parsed result
147 * - PARSE_ERROR when not successful
149 status_t (*parse_uint64
) (private_parser_t
*this, int rule_number
, u_int64_t
*output_pos
);
152 * @brief Parse a given amount of bytes and writes them to a specific location
154 * @param this parser_t object
155 * @param rule_number number of current rule
156 * @param[out] output_pos pointer where to write the parsed result
157 * @param bytes number of bytes to parse
160 * - PARSE_ERROR when not successful
162 status_t (*parse_bytes
) (private_parser_t
*this, int rule_number
, u_int8_t
*output_pos
,size_t bytes
);
165 * @brief Parse a single Bit from the current parsing position
167 * @param this parser_t object
168 * @param rule_number number of current rule
169 * @param[out] output_pos pointer where to write the parsed result
172 * - PARSE_ERROR when not successful
174 status_t (*parse_bit
) (private_parser_t
*this, int rule_number
, bool *output_pos
);
177 * @brief Parse substructures in a list
179 * This function calls the parser recursively to parse contained substructures
180 * in a linked_list_t. The list must already be created. Payload defines
181 * the type of the substructures. parsing is continued until the specified length
182 * is completely parsed.
184 * @param this parser_t object
185 * @param rule_number number of current rule
186 * @param[out] output_pos pointer of a linked_list where substructures are added
187 * @param payload_type type of the contained substructures to parse
188 * @param length number of bytes to parse in this list
191 * - PARSE_ERROR when not successful
193 status_t (*parse_list
) (private_parser_t
*this, int rule_number
, linked_list_t
**output_pos
, payload_type_t payload_ype
, size_t length
);
196 * @brief Parse data from current parsing position in a chunk.
198 * This function clones length number of bytes to output_pos, without
199 * modifiyng them. Space will be allocated and must be freed by caller.
201 * @param this parser_t object
202 * @param rule_number number of current rule
203 * @param[out] output_pos pointer of a chunk which will point to the allocated data
204 * @param length number of bytes to clone
207 * - PARSE_ERROR when not successful
209 status_t (*parse_chunk
) (private_parser_t
*this, int rule_number
, chunk_t
*output_pos
, size_t length
);
212 * Current bit for reading in input data.
217 * Current byte for reading in input data.
222 * Input data to parse.
227 * Roof of input, used for length-checking.
229 u_int8_t
*input_roof
;
232 * Set of encoding rules for this parsing session.
234 encoding_rule_t
*rules
;
238 * Implementation of private_parser_t.parse_uint4.
240 static status_t
parse_uint4(private_parser_t
*this, int rule_number
, u_int8_t
*output_pos
)
242 if (this->byte_pos
+ sizeof(u_int8_t
) > this->input_roof
)
244 DBG1(SIG_DBG_ENC
, " not enough input to parse rule %d %N",
245 rule_number
, encoding_type_names
, this->rules
[rule_number
].type
);
248 switch (this->bit_pos
)
251 /* caller interested in result ? */
252 if (output_pos
!= NULL
)
254 *output_pos
= *(this->byte_pos
) >> 4;
259 /* caller interested in result ? */
260 if (output_pos
!= NULL
)
262 *output_pos
= *(this->byte_pos
) & 0x0F;
268 DBG2(SIG_DBG_ENC
, " found rule %d %N on bitpos %d",
269 rule_number
, encoding_type_names
,
270 this->rules
[rule_number
].type
, this->bit_pos
);
274 if (output_pos
!= NULL
)
276 DBG3(SIG_DBG_ENC
, " => %d", *output_pos
);
283 * Implementation of private_parser_t.parse_uint8.
285 static status_t
parse_uint8(private_parser_t
*this, int rule_number
, u_int8_t
*output_pos
)
287 if (this->byte_pos
+ sizeof(u_int8_t
) > this->input_roof
)
289 DBG1(SIG_DBG_ENC
, " not enough input to parse rule %d %N",
290 rule_number
, encoding_type_names
, this->rules
[rule_number
].type
);
295 DBG1(SIG_DBG_ENC
, " found rule %d %N on bitpos %d",
296 rule_number
, encoding_type_names
,
297 this->rules
[rule_number
].type
, this->bit_pos
);
301 /* caller interested in result ? */
302 if (output_pos
!= NULL
)
304 *output_pos
= *(this->byte_pos
);
305 DBG3(SIG_DBG_ENC
, " => %d", *output_pos
);
313 * Implementation of private_parser_t.parse_uint15.
315 static status_t
parse_uint15(private_parser_t
*this, int rule_number
, u_int16_t
*output_pos
)
317 if (this->byte_pos
+ sizeof(u_int16_t
) > this->input_roof
)
319 DBG1(SIG_DBG_ENC
, " not enough input to parse rule %d %N",
320 rule_number
, encoding_type_names
, this->rules
[rule_number
].type
);
323 if (this->bit_pos
!= 1)
325 DBG2(SIG_DBG_ENC
, " found rule %d %N on bitpos %d", rule_number
,
326 encoding_type_names
, this->rules
[rule_number
].type
, this->bit_pos
);
329 /* caller interested in result ? */
330 if (output_pos
!= NULL
)
332 *output_pos
= ntohs(*((u_int16_t
*)this->byte_pos
)) & ~0x8000;
333 DBG3(SIG_DBG_ENC
, " => %d", *output_pos
);
342 * Implementation of private_parser_t.parse_uint16.
344 static status_t
parse_uint16(private_parser_t
*this, int rule_number
, u_int16_t
*output_pos
)
346 if (this->byte_pos
+ sizeof(u_int16_t
) > this->input_roof
)
348 DBG1(SIG_DBG_ENC
, " not enough input to parse rule %d %N",
349 rule_number
, encoding_type_names
, this->rules
[rule_number
].type
);
354 DBG1(SIG_DBG_ENC
, " found rule %d %N on bitpos %d", rule_number
,
355 encoding_type_names
, this->rules
[rule_number
].type
, this->bit_pos
);
358 /* caller interested in result ? */
359 if (output_pos
!= NULL
)
361 *output_pos
= ntohs(*((u_int16_t
*)this->byte_pos
));
363 DBG3(SIG_DBG_ENC
, " => %d", *output_pos
);
370 * Implementation of private_parser_t.parse_uint32.
372 static status_t
parse_uint32(private_parser_t
*this, int rule_number
, u_int32_t
*output_pos
)
374 if (this->byte_pos
+ sizeof(u_int32_t
) > this->input_roof
)
376 DBG1(SIG_DBG_ENC
, " not enough input to parse rule %d %N",
377 rule_number
, encoding_type_names
, this->rules
[rule_number
].type
);
382 DBG1(SIG_DBG_ENC
, " found rule %d %N on bitpos %d", rule_number
,
383 encoding_type_names
, this->rules
[rule_number
].type
, this->bit_pos
);
386 /* caller interested in result ? */
387 if (output_pos
!= NULL
)
389 *output_pos
= ntohl(*((u_int32_t
*)this->byte_pos
));
391 DBG3(SIG_DBG_ENC
, " => %d", *output_pos
);
399 * Implementation of private_parser_t.parse_uint64.
401 static status_t
parse_uint64(private_parser_t
*this, int rule_number
, u_int64_t
*output_pos
)
403 if (this->byte_pos
+ sizeof(u_int64_t
) > this->input_roof
)
405 DBG1(SIG_DBG_ENC
, " not enough input to parse rule %d %N",
406 rule_number
, encoding_type_names
, this->rules
[rule_number
].type
);
411 DBG1(SIG_DBG_ENC
, " found rule %d %N on bitpos %d", rule_number
,
412 encoding_type_names
, this->rules
[rule_number
].type
, this->bit_pos
);
415 /* caller interested in result ? */
416 if (output_pos
!= NULL
)
418 /* assuming little endian host order */
419 *(output_pos
+ 1) = ntohl(*((u_int32_t
*)this->byte_pos
));
420 *output_pos
= ntohl(*(((u_int32_t
*)this->byte_pos
) + 1));
422 DBG3(SIG_DBG_ENC
, " => %b", (void*)output_pos
, sizeof(u_int64_t
));
430 * Implementation of private_parser_t.parse_bytes.
432 static status_t
parse_bytes (private_parser_t
*this, int rule_number
, u_int8_t
*output_pos
,size_t bytes
)
434 if (this->byte_pos
+ bytes
> this->input_roof
)
436 DBG1(SIG_DBG_ENC
, " not enough input to parse rule %d %N",
437 rule_number
, encoding_type_names
, this->rules
[rule_number
].type
);
442 DBG1(SIG_DBG_ENC
, " found rule %d %N on bitpos %d", rule_number
,
443 encoding_type_names
, this->rules
[rule_number
].type
, this->bit_pos
);
447 /* caller interested in result ? */
448 if (output_pos
!= NULL
)
450 memcpy(output_pos
,this->byte_pos
,bytes
);
452 DBG3(SIG_DBG_ENC
, " => %b", (void*)output_pos
, bytes
);
454 this->byte_pos
+= bytes
;
460 * Implementation of private_parser_t.parse_bit.
462 static status_t
parse_bit(private_parser_t
*this, int rule_number
, bool *output_pos
)
464 if (this->byte_pos
+ sizeof(u_int8_t
) > this->input_roof
)
466 DBG1(SIG_DBG_ENC
, " not enough input to parse rule %d %N",
467 rule_number
, encoding_type_names
, this->rules
[rule_number
].type
);
470 /* caller interested in result ? */
471 if (output_pos
!= NULL
)
474 mask
= 0x01 << (7 - this->bit_pos
);
475 *output_pos
= *this->byte_pos
& mask
;
479 /* set to a "clean", comparable true */
483 DBG3(SIG_DBG_ENC
, " => %d", *output_pos
);
485 this->bit_pos
= (this->bit_pos
+ 1) % 8;
486 if (this->bit_pos
== 0)
495 * Implementation of private_parser_t.parse_list.
497 static status_t
parse_list(private_parser_t
*this, int rule_number
, linked_list_t
**output_pos
, payload_type_t payload_type
, size_t length
)
499 linked_list_t
* list
= *output_pos
;
503 DBG1(SIG_DBG_ENC
, " invalid length for rule %d %N",
504 rule_number
, encoding_type_names
, this->rules
[rule_number
].type
);
510 DBG1(SIG_DBG_ENC
, " found rule %d %N on bitpos %d", rule_number
,
511 encoding_type_names
, this->rules
[rule_number
].type
, this->bit_pos
);
517 u_int8_t
*pos_before
= this->byte_pos
;
520 DBG2(SIG_DBG_ENC
, " %d bytes left, parsing recursively %N",
521 length
, payload_type_names
, payload_type
);
522 status
= this->public.parse_payload((parser_t
*)this, payload_type
, &payload
);
523 if (status
!= SUCCESS
)
525 DBG1(SIG_DBG_ENC
, " parsing of a %N substructure failed",
526 payload_type_names
, payload_type
);
529 list
->insert_last(list
, payload
);
530 length
-= this->byte_pos
- pos_before
;
537 * Implementation of private_parser_t.parse_chunk.
539 static status_t
parse_chunk(private_parser_t
*this, int rule_number
, chunk_t
*output_pos
, size_t length
)
541 if (this->byte_pos
+ length
> this->input_roof
)
543 DBG1(SIG_DBG_ENC
, " not enough input (%d bytes) to parse rule %d %N",
544 length
, rule_number
, encoding_type_names
, this->rules
[rule_number
].type
);
549 DBG1(SIG_DBG_ENC
, " found rule %d %N on bitpos %d", rule_number
,
550 encoding_type_names
, this->rules
[rule_number
].type
, this->bit_pos
);
553 if (output_pos
!= NULL
)
555 output_pos
->len
= length
;
556 output_pos
->ptr
= malloc(length
);
557 memcpy(output_pos
->ptr
, this->byte_pos
, length
);
559 this->byte_pos
+= length
;
560 DBG3(SIG_DBG_ENC
, " => %b", (void*)output_pos
->ptr
, length
);
566 * Implementation of parser_t.parse_payload.
568 static status_t
parse_payload(private_parser_t
*this, payload_type_t payload_type
, payload_t
**payload
)
572 size_t rule_count
, payload_length
= 0, spi_size
= 0, attribute_length
= 0;
573 u_int16_t ts_type
= 0;
574 bool attribute_format
= FALSE
;
576 encoding_rule_t
*rule
;
578 /* create instance of the payload to parse */
579 pld
= payload_create(payload_type
);
581 DBG2(SIG_DBG_ENC
, "parsing %N payload, %d bytes left",
582 payload_type_names
, payload_type
, this->input_roof
- this->byte_pos
);
584 DBG3(SIG_DBG_ENC
, "parsing payload from %b",
585 this->byte_pos
, this->input_roof
-this->byte_pos
);
587 if (pld
->get_type(pld
) == UNKNOWN_PAYLOAD
)
589 DBG1(SIG_DBG_ENC
, " payload type %d is unknown, handling as %N",
590 payload_type
, payload_type_names
, UNKNOWN_PAYLOAD
);
593 /* base pointer for output, avoids casting in every rule */
596 /* parse the payload with its own rulse */
597 pld
->get_encoding_rules(pld
, &(this->rules
), &rule_count
);
598 for (rule_number
= 0; rule_number
< rule_count
; rule_number
++)
600 rule
= &(this->rules
[rule_number
]);
601 DBG2(SIG_DBG_ENC
, " parsing rule %d %N",
602 rule_number
, encoding_type_names
, rule
->type
);
607 if (this->parse_uint4(this, rule_number
, output
+ rule
->offset
) != SUCCESS
)
616 if (this->parse_uint8(this, rule_number
, output
+ rule
->offset
) != SUCCESS
)
625 if (this->parse_uint16(this, rule_number
, output
+ rule
->offset
) != SUCCESS
)
634 if (this->parse_uint32(this, rule_number
, output
+ rule
->offset
) != SUCCESS
)
643 if (this->parse_uint64(this, rule_number
, output
+ rule
->offset
) != SUCCESS
)
652 if (this->parse_bytes(this, rule_number
, output
+ rule
->offset
,8) != SUCCESS
)
661 if (this->parse_bit(this, rule_number
, NULL
) != SUCCESS
)
670 if (this->parse_uint8(this, rule_number
, NULL
) != SUCCESS
)
679 if (this->parse_bit(this, rule_number
, output
+ rule
->offset
) != SUCCESS
)
688 if (this->parse_uint16(this, rule_number
, output
+ rule
->offset
) != SUCCESS
)
693 payload_length
= *(u_int16_t
*)(output
+ rule
->offset
);
698 if (this->parse_uint32(this, rule_number
, output
+ rule
->offset
) != SUCCESS
)
707 if (this->parse_uint8(this, rule_number
, output
+ rule
->offset
) != SUCCESS
)
712 spi_size
= *(u_int8_t
*)(output
+ rule
->offset
);
717 if (this->parse_chunk(this, rule_number
, output
+ rule
->offset
, spi_size
) != SUCCESS
)
726 size_t proposals_length
= payload_length
- SA_PAYLOAD_HEADER_LENGTH
;
727 if (this->parse_list(this, rule_number
, output
+ rule
->offset
, PROPOSAL_SUBSTRUCTURE
, proposals_length
) != SUCCESS
)
736 size_t transforms_length
= payload_length
- spi_size
- PROPOSAL_SUBSTRUCTURE_HEADER_LENGTH
;
737 if (this->parse_list(this, rule_number
, output
+ rule
->offset
, TRANSFORM_SUBSTRUCTURE
, transforms_length
) != SUCCESS
)
744 case TRANSFORM_ATTRIBUTES
:
746 size_t transform_a_length
= payload_length
- TRANSFORM_SUBSTRUCTURE_HEADER_LENGTH
;
747 if (this->parse_list(this, rule_number
, output
+ rule
->offset
, TRANSFORM_ATTRIBUTE
, transform_a_length
) != SUCCESS
)
754 case CONFIGURATION_ATTRIBUTES
:
756 size_t configuration_attributes_length
= payload_length
- CP_PAYLOAD_HEADER_LENGTH
;
757 if (this->parse_list(this, rule_number
, output
+ rule
->offset
, CONFIGURATION_ATTRIBUTE
, configuration_attributes_length
) != SUCCESS
)
764 case ATTRIBUTE_FORMAT
:
766 if (this->parse_bit(this, rule_number
, output
+ rule
->offset
) != SUCCESS
)
771 attribute_format
= *(bool*)(output
+ rule
->offset
);
776 if (this->parse_uint15(this, rule_number
, output
+ rule
->offset
) != SUCCESS
)
781 attribute_format
= *(bool*)(output
+ rule
->offset
);
784 case CONFIGURATION_ATTRIBUTE_LENGTH
:
786 if (this->parse_uint16(this, rule_number
, output
+ rule
->offset
) != SUCCESS
)
791 attribute_length
= *(u_int16_t
*)(output
+ rule
->offset
);
794 case ATTRIBUTE_LENGTH_OR_VALUE
:
796 if (this->parse_uint16(this, rule_number
, output
+ rule
->offset
) != SUCCESS
)
801 attribute_length
= *(u_int16_t
*)(output
+ rule
->offset
);
804 case ATTRIBUTE_VALUE
:
806 if (attribute_format
== FALSE
)
808 if (this->parse_chunk(this, rule_number
, output
+ rule
->offset
, attribute_length
) != SUCCESS
)
818 size_t nonce_length
= payload_length
- NONCE_PAYLOAD_HEADER_LENGTH
;
819 if (this->parse_chunk(this, rule_number
, output
+ rule
->offset
, nonce_length
) != SUCCESS
)
828 size_t data_length
= payload_length
- ID_PAYLOAD_HEADER_LENGTH
;
829 if (this->parse_chunk(this, rule_number
, output
+ rule
->offset
, data_length
) != SUCCESS
)
838 size_t data_length
= payload_length
- AUTH_PAYLOAD_HEADER_LENGTH
;
839 if (this->parse_chunk(this, rule_number
, output
+ rule
->offset
, data_length
) != SUCCESS
)
848 size_t data_length
= payload_length
- CERT_PAYLOAD_HEADER_LENGTH
;
849 if (this->parse_chunk(this, rule_number
, output
+ rule
->offset
, data_length
) != SUCCESS
)
858 size_t data_length
= payload_length
- CERTREQ_PAYLOAD_HEADER_LENGTH
;
859 if (this->parse_chunk(this, rule_number
, output
+ rule
->offset
, data_length
) != SUCCESS
)
868 size_t data_length
= payload_length
- EAP_PAYLOAD_HEADER_LENGTH
;
869 if (this->parse_chunk(this, rule_number
, output
+ rule
->offset
, data_length
) != SUCCESS
)
878 size_t data_length
= payload_length
- DELETE_PAYLOAD_HEADER_LENGTH
;
879 if (this->parse_chunk(this, rule_number
, output
+ rule
->offset
, data_length
) != SUCCESS
)
888 size_t data_length
= payload_length
- VENDOR_ID_PAYLOAD_HEADER_LENGTH
;
889 if (this->parse_chunk(this, rule_number
, output
+ rule
->offset
, data_length
) != SUCCESS
)
896 case CONFIGURATION_ATTRIBUTE_VALUE
:
898 size_t data_length
= attribute_length
;
899 if (this->parse_chunk(this, rule_number
, output
+ rule
->offset
, data_length
) != SUCCESS
)
906 case KEY_EXCHANGE_DATA
:
908 size_t keydata_length
= payload_length
- KE_PAYLOAD_HEADER_LENGTH
;
909 if (this->parse_chunk(this, rule_number
, output
+ rule
->offset
, keydata_length
) != SUCCESS
)
916 case NOTIFICATION_DATA
:
918 size_t notify_length
= payload_length
- NOTIFY_PAYLOAD_HEADER_LENGTH
- spi_size
;
919 if (this->parse_chunk(this, rule_number
, output
+ rule
->offset
, notify_length
) != SUCCESS
)
928 size_t data_length
= payload_length
- ENCRYPTION_PAYLOAD_HEADER_LENGTH
;
929 if (this->parse_chunk(this, rule_number
, output
+ rule
->offset
, data_length
) != SUCCESS
)
938 if (this->parse_uint8(this, rule_number
, output
+ rule
->offset
) != SUCCESS
)
943 ts_type
= *(u_int8_t
*)(output
+ rule
->offset
);
948 size_t address_length
= (ts_type
== TS_IPV4_ADDR_RANGE
) ?
4 : 16;
949 if (this->parse_chunk(this, rule_number
, output
+ rule
->offset
,address_length
) != SUCCESS
)
956 case TRAFFIC_SELECTORS
:
958 size_t traffic_selectors_length
= payload_length
- TS_PAYLOAD_HEADER_LENGTH
;
959 if (this->parse_list(this, rule_number
, output
+ rule
->offset
, TRAFFIC_SELECTOR_SUBSTRUCTURE
, traffic_selectors_length
) != SUCCESS
)
966 case UNKNOWN_PAYLOAD
:
968 size_t unknown_payload_data_length
= payload_length
- UNKNOWN_PAYLOAD_HEADER_LENGTH
;
969 if (this->parse_chunk(this, rule_number
, output
+ rule
->offset
, unknown_payload_data_length
) != SUCCESS
)
978 DBG1(SIG_DBG_ENC
, " no rule to parse rule %d %N",
979 rule_number
, encoding_type_names
, rule
->type
);
984 /* process next rulue */
989 DBG2(SIG_DBG_ENC
, "parsing %N payload finished",
990 payload_type_names
, payload_type
);
995 * Implementation of parser_t.get_remaining_byte_count.
997 static int get_remaining_byte_count (private_parser_t
*this)
999 int count
= (this->input_roof
- this->byte_pos
);
1004 * Implementation of parser_t.reset_context.
1006 static void reset_context (private_parser_t
*this)
1008 this->byte_pos
= this->input
;
1013 * Implementation of parser_t.destroy.
1015 static void destroy(private_parser_t
*this)
1021 * Described in header.
1023 parser_t
*parser_create(chunk_t data
)
1025 private_parser_t
*this = malloc_thing(private_parser_t
);
1027 this->public.parse_payload
= (status_t(*)(parser_t
*,payload_type_t
,payload_t
**)) parse_payload
;
1028 this->public.reset_context
= (void(*)(parser_t
*)) reset_context
;
1029 this->public.get_remaining_byte_count
= (int (*) (parser_t
*))get_remaining_byte_count
;
1030 this->public.destroy
= (void(*)(parser_t
*)) destroy
;
1032 this->parse_uint4
= parse_uint4
;
1033 this->parse_uint8
= parse_uint8
;
1034 this->parse_uint15
= parse_uint15
;
1035 this->parse_uint16
= parse_uint16
;
1036 this->parse_uint32
= parse_uint32
;
1037 this->parse_uint64
= parse_uint64
;
1038 this->parse_bytes
= parse_bytes
;
1039 this->parse_bit
= parse_bit
;
1040 this->parse_list
= parse_list
;
1041 this->parse_chunk
= parse_chunk
;
1043 this->input
= data
.ptr
;
1044 this->byte_pos
= data
.ptr
;
1046 this->input_roof
= data
.ptr
+ data
.len
;
1048 return (parser_t
*)this;