fb491113d5f577c8750ed8dcb0544e9be170bb9b
[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 "payloads/encodings.h"
28 #include "payloads/payload.h"
29
30 /**
31 * @brief The parser context stores state information for a parsing session.
32 */
33 typedef struct parser_context_s parser_context_t;
34
35 struct parser_context_s {
36 /**
37 * @brief destructor of parsing_context
38 *
39 * called it when finished a parsing session
40 *
41 * @param this the parser_context_t to destroy
42 * @return
43 * - SUCCESS in any case
44 */
45 status_t (*destroy) (parser_context_t *this);
46 };
47
48
49 /**
50 * @brief A parser_t object which parses payloads of specific type
51 */
52 typedef struct parser_s parser_t;
53
54 struct parser_s {
55
56 /**
57 * @brief generates a context for parsing
58 *
59 * a context is used for a parsing session. It safes the state, such as
60 * parsing position, available size, ...
61 *
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
65 */
66
67 parser_context_t *(*create_context) (parser_t *this, chunk_t data);
68
69 /**
70 * @brief parses the next payload in the current context
71 *
72 * @warning caller is responsible for freeing allocated data_struct
73 *
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
78 * @return
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
83 */
84 status_t (*parse_payload) (parser_t *this, payload_type_t payload_type, void **data_struct, parser_context_t* context);
85
86 /**
87 * @brief Destroys a parser object
88 *
89 * @param parser parser object
90 * @return
91 * - SUCCESSFUL in any case
92 */
93 status_t (*destroy) (parser_t *this);
94 };
95
96 /**
97 * @brief Constructor to create a parser
98 *
99 * The parser uses a set of payload_infos to know how to
100 * parse different payloads.
101 *
102 * @param payload_infos list of payload_info_t
103 *
104 */
105 parser_t *parser_create();
106
107 #endif /*PARSER_H_*/