2b86ffbe389931f1a54237401778eeaaedee3146
[strongswan.git] / src / charon / encoding / generator.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 generator generator
21 * @{ @ingroup encoding
22 */
23
24 #ifndef GENERATOR_H_
25 #define GENERATOR_H_
26
27 typedef struct generator_t generator_t;
28
29 #include <library.h>
30 #include <encoding/payloads/encodings.h>
31 #include <encoding/payloads/payload.h>
32
33 /**
34 * Generating is done in a data buffer.
35 * This is the start size of this buffer in bytes.
36 */
37 #define GENERATOR_DATA_BUFFER_SIZE 500
38
39 /**
40 * Number of bytes to increase the buffer, if it is too small.
41 */
42 #define GENERATOR_DATA_BUFFER_INCREASE_VALUE 500
43
44
45 /**
46 * A generator_t class used to generate IKEv2 payloads.
47 *
48 * After creation, multiple payloads can be generated with the generate_payload
49 * method. The generated bytes are appended. After all payloads are added,
50 * the write_to_chunk method writes out all generated data since
51 * the creation of the generator. After that, the generator must be destroyed.
52 * The generater uses a set of encoding rules, which it can get from
53 * the supplied payload. With this rules, the generater can generate
54 * the payload and all substructures automatically.
55 */
56 struct generator_t {
57
58 /**
59 * Generates a specific payload from given payload object.
60 *
61 * Remember: Header and substructures are also handled as payloads.
62 *
63 * @param payload interface payload_t implementing object
64 */
65 void (*generate_payload) (generator_t *this,payload_t *payload);
66
67 /**
68 * Writes all generated data of the generator to a chunk.
69 *
70 * @param data chunk to write the data to
71 */
72 void (*write_to_chunk) (generator_t *this,chunk_t *data);
73
74 /**
75 * Destroys a generator_t object.
76 */
77 void (*destroy) (generator_t *this);
78 };
79
80 /**
81 * Constructor to create a generator.
82 *
83 * @return generator_t object.
84 */
85 generator_t *generator_create(void);
86
87 #endif /*GENERATOR_H_ @} */