- fixed parser to use new payload mechanisms
[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 of specific type
33 */
34 typedef struct parser_s parser_t;
35
36 struct parser_s {
37
38 /**
39 * @brief parses the next payload in the current context
40 *
41 * @warning caller is responsible for freeing allocated data_struct
42 *
43 * @param parser parser Object
44 * @param payload_type payload to parse
45 * @param[out] payload pointer where parsed payload was allocated
46 * @return
47 * - SUCCESSFUL if succeeded,
48 * - NOT_SUPPORTED if payload_type is not supported
49 * - OUT_OF_RES if out of ressources
50 * - PARSE_ERROR if corrupted data found
51 */
52 status_t (*parse_payload) (parser_t *this, payload_type_t payload_type, payload_t **payload);
53
54 /**
55 * @brief Destroys a parser object
56 *
57 * @param parser parser object
58 * @return
59 * - SUCCESSFUL in any case
60 */
61 status_t (*destroy) (parser_t *this);
62 };
63
64 /**
65 * @brief Constructor to create a parser
66 *
67 * The parser uses a set of payload_infos to know how to
68 * parse different payloads.
69 *
70 * @param chunk chunk of data to parse in this session
71 * @return the parser, or NULL if failed
72 *
73 */
74 parser_t *parser_create(chunk_t data);
75
76 #endif /*PARSER_H_*/