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