d3bcbc20fb9653a444f98323f2000f59a39ad2d7
[strongswan.git] / src / charon / encoding / parser.h
1 /*
2 * Copyright (C) 2005-2006 Martin Willi
3 * Copyright (C) 2005 Jan Hutter
4 * Hochschule fuer Technik Rapperswil
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 *
16 * $Id$
17 */
18
19 /**
20 * @defgroup parser parser
21 * @{ @ingroup encoding
22 */
23
24 #ifndef PARSER_H_
25 #define PARSER_H_
26
27 typedef struct parser_t parser_t;
28
29 #include <library.h>
30 #include <encoding/payloads/encodings.h>
31 #include <encoding/payloads/payload.h>
32
33 /**
34 * 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 struct parser_t {
41
42 /**
43 * Parses the next payload.
44 *
45 * @warning Caller is responsible for freeing allocated payload.
46 *
47 * Rules for parsing are described in the payload definition.
48 *
49 * @param payload_type payload type to parse
50 * @param payload pointer where parsed payload was allocated
51 * @return
52 * - SUCCESSFUL if succeeded,
53 * - PARSE_ERROR if corrupted/invalid data found
54 */
55 status_t (*parse_payload) (parser_t *this, payload_type_t payload_type, payload_t **payload);
56
57 /**
58 * Gets the remaining byte count which is not currently parsed.
59 */
60 int (*get_remaining_byte_count) (parser_t *this);
61
62 /**
63 * Resets the current parser context.
64 */
65 void (*reset_context) (parser_t *this);
66
67 /**
68 * Destroys a parser_t object.
69 */
70 void (*destroy) (parser_t *this);
71 };
72
73 /**
74 * Constructor to create a parser_t object.
75 *
76 * @param data chunk of data to parse with this parser_t object
77 * @return parser_t object
78 */
79 parser_t *parser_create(chunk_t data);
80
81 #endif /*PARSER_H_ @} */