- documented
[strongswan.git] / Source / charon / parser.h
1 /**
2 * @file parser.h
3 *
4 * @brief Generic parser class used to parse IKEv2-Header and Payload
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
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>.
16 *
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
20 * for more details.
21 */
22
23 #ifndef PARSER_H_
24 #define PARSER_H_
25
26 #include "types.h"
27 #include "encodings.h"
28
29 /**
30 * @brief The parser context stores state information for a parsing session.
31 */
32 typedef struct parser_context_s parser_context_t;
33
34 struct parser_context_s {
35 /**
36 * @brief destructor of parsing_context
37 *
38 * called it when finished a parsing session
39 *
40 * @param this the parser_context_t to destroy
41 * @return
42 * - SUCCESS in any case
43 */
44 status_t (*destroy) (parser_context_t *this);
45 };
46
47
48 /**
49 * @brief A parser_t object which parses payloads of specific type
50 */
51 typedef struct parser_s parser_t;
52
53 struct parser_s {
54
55 /**
56 * @brief generates a context for parsing
57 *
58 * a context is used for a parsing session. It safes the state, such as
59 * parsing position, available size, ...
60 *
61 * @param parser parser Object
62 * @param chunk chunk of data to parse in this session
63 * @return the parsing_context, or NULL if failed
64 */
65
66 parser_context_t *(*create_context) (parser_t *this, chunk_t data);
67
68 /**
69 * @brief parses the next payload in the current context
70 *
71 * @warning caller is responsible for freeing allocated data_struct
72 *
73 * @param parser parser Object
74 * @param payload_type payload to parse
75 * @param[out] data_struct pointer where parsed data will be allocated
76 * @param context the parsing context, describing the current parsing session
77 * @return
78 * - SUCCESSFUL if succeeded,
79 * - NOT_SUPPORTED if payload_type is not supported
80 * - OUT_OF_RES if out of ressources
81 * - PARSE_ERROR if corrupted data found
82 */
83 status_t (*parse_payload) (parser_t *this, payload_type_t payload_type, void **data_struct, parser_context_t* context);
84
85 /**
86 * @brief Destroys a parser object
87 *
88 * @param parser parser object
89 * @return
90 * - SUCCESSFUL in any case
91 */
92 status_t (*destroy) (parser_t *this);
93 };
94
95 /**
96 * @brief Constructor to create a parser
97 *
98 * The parser uses a set of payload_infos to know how to
99 * parse different payloads.
100 *
101 * @param payload_infos list of payload_info_t
102 *
103 */
104 parser_t *parser_create(payload_info_t **payload_infos);
105
106 #endif /*PARSER_H_*/