- commented parser
[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 /**
32 * @brief A parser_t object which parses payloads
33 *
34 * A parser is used for parsing one chunk of data. Multiple
35 * payloads can be parsed out of the chunk using parse_payload.
36 * The parser remains the state until destroyed.
37 */
38 typedef struct parser_s parser_t;
39
40 struct parser_s {
41
42 /**
43 * @brief 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 parser parser Object
50 * @param payload_type payload type to parse
51 * @param[out] payload pointer where parsed payload was allocated
52 * @return
53 * - SUCCESSFUL if succeeded,
54 * - NOT_SUPPORTED if payload_type is not supported
55 * - OUT_OF_RES if out of ressources
56 * - PARSE_ERROR if corrupted/invalid data found
57 */
58 status_t (*parse_payload) (parser_t *this, payload_type_t payload_type, payload_t **payload);
59
60 /**
61 * @brief Destroys a parser object
62 *
63 * @param parser parser object
64 * @return
65 * - SUCCESSFUL in any case
66 */
67 status_t (*destroy) (parser_t *this);
68 };
69
70 /**
71 * @brief Constructor to create a parser
72 *
73 * @param data chunk of data to parse with this parser object
74 * @return the parser, or NULL if failed
75 *
76 */
77 parser_t *parser_create(chunk_t data);
78
79 #endif /*PARSER_H_*/