(no commit message)
[strongswan.git] / src / charon / encoding / parser.h
1 /**
2 * @file parser.h
3 *
4 * @brief Interface of parser_t.
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 <encoding/payloads/encodings.h>
28 #include <encoding/payloads/payload.h>
29
30
31 typedef struct parser_t parser_t;
32
33 /**
34 * @brief A parser_t class to parse IKEv2 payloads.
35 *
36 * A parser is used for parsing one chunk of data. Multiple
37 * payloads can be parsed out of the chunk using parse_payload.
38 * The parser remains the state until destroyed.
39 *
40 * @b Constructors:
41 * - parser_create()
42 *
43 * @ingroup encoding
44 */
45 struct parser_t {
46
47 /**
48 * @brief Parses the next payload.
49 *
50 * @warning Caller is responsible for freeing allocated payload.
51 *
52 * Rules for parsing are described in the payload definition.
53 *
54 * @param this parser_t bject
55 * @param payload_type payload type to parse
56 * @param[out] payload pointer where parsed payload was allocated
57 * @return
58 * - SUCCESSFUL if succeeded,
59 * - PARSE_ERROR if corrupted/invalid data found
60 */
61 status_t (*parse_payload) (parser_t *this, payload_type_t payload_type, payload_t **payload);
62
63 /**
64 * Gets the remaining byte count which is not currently parsed.
65 *
66 * @param parser parser_t object
67 */
68 int (*get_remaining_byte_count) (parser_t *this);
69
70 /**
71 * @brief Resets the current parser context.
72 *
73 * @param parser parser_t object
74 */
75 void (*reset_context) (parser_t *this);
76
77 /**
78 * @brief Destroys a parser_t object.
79 *
80 * @param parser parser_t object
81 */
82 void (*destroy) (parser_t *this);
83 };
84
85 /**
86 * @brief Constructor to create a parser_t object.
87 *
88 * @param data chunk of data to parse with this parser_t object
89 * @return parser_t object
90 *
91 * @ingroup encoding
92 */
93 parser_t *parser_create(chunk_t data);
94
95 #endif /*PARSER_H_*/