4 * @brief Generic parser class used to parse IKEv2-Header and Payload
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27 #include "payloads/encodings.h"
28 #include "payloads/payload.h"
31 * @brief The parser context stores state information for a parsing session.
33 typedef struct parser_context_s parser_context_t
;
35 struct parser_context_s
{
37 * @brief destructor of parsing_context
39 * called it when finished a parsing session
41 * @param this the parser_context_t to destroy
43 * - SUCCESS in any case
45 status_t (*destroy
) (parser_context_t
*this);
50 * @brief A parser_t object which parses payloads of specific type
52 typedef struct parser_s parser_t
;
57 * @brief generates a context for parsing
59 * a context is used for a parsing session. It safes the state, such as
60 * parsing position, available size, ...
62 * @param parser parser Object
63 * @param chunk chunk of data to parse in this session
64 * @return the parsing_context, or NULL if failed
67 parser_context_t
*(*create_context
) (parser_t
*this, chunk_t data
);
70 * @brief parses the next payload in the current context
72 * @warning caller is responsible for freeing allocated data_struct
74 * @param parser parser Object
75 * @param payload_type payload to parse
76 * @param[out] data_struct pointer where parsed data will be allocated
77 * @param context the parsing context, describing the current parsing session
79 * - SUCCESSFUL if succeeded,
80 * - NOT_SUPPORTED if payload_type is not supported
81 * - OUT_OF_RES if out of ressources
82 * - PARSE_ERROR if corrupted data found
84 status_t (*parse_payload
) (parser_t
*this, payload_type_t payload_type
, void **data_struct
, parser_context_t
* context
);
87 * @brief Destroys a parser object
89 * @param parser parser object
91 * - SUCCESSFUL in any case
93 status_t (*destroy
) (parser_t
*this);
97 * @brief Constructor to create a parser
99 * The parser uses a set of payload_infos to know how to
100 * parse different payloads.
102 * @param payload_infos list of payload_info_t
105 parser_t
*parser_create();