56dc40322ce222dd7ca52d80865378b59c01b6c1
[strongswan.git] / src / libcharon / encoding / parser.h
1 /*
2 * Copyright (C) 2005-2006 Martin Willi
3 * Copyright (C) 2005 Jan Hutter
4 *
5 * Copyright (C) secunet Security Networks AG
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 */
17
18 /**
19 * @defgroup parser parser
20 * @{ @ingroup encoding
21 */
22
23 #ifndef PARSER_H_
24 #define PARSER_H_
25
26 typedef struct parser_t parser_t;
27
28 #include <library.h>
29 #include <encoding/payloads/encodings.h>
30 #include <encoding/payloads/payload.h>
31
32 /**
33 * A parser_t class to parse IKE payloads.
34 *
35 * A parser is used for parsing one chunk of data. Multiple
36 * payloads can be parsed out of the chunk using parse_payload.
37 * The parser remains the state until destroyed.
38 */
39 struct parser_t {
40
41 /**
42 * Parses the next payload.
43 *
44 * @warning Caller is responsible for freeing allocated payload.
45 *
46 * Rules for parsing are described in the payload definition.
47 *
48 * @param payload_type payload type to parse
49 * @param payload pointer where parsed payload was allocated
50 * @return
51 * - SUCCESSFUL if succeeded,
52 * - PARSE_ERROR if corrupted/invalid data found
53 */
54 status_t (*parse_payload) (parser_t *this, payload_type_t payload_type,
55 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 * Set the major IKE version.
69 *
70 * @param major_version the major IKE version
71 */
72 void (*set_major_version) (parser_t *this, uint8_t major_version);
73
74 /**
75 * Destroys a parser_t object.
76 */
77 void (*destroy) (parser_t *this);
78 };
79
80 /**
81 * Constructor to create a parser_t object.
82 *
83 * @param data chunk of data to parse with this parser_t object
84 * @return parser_t object
85 */
86 parser_t *parser_create(chunk_t data);
87
88 #endif /** PARSER_H_ @}*/