fc307de7e7b2eb0e452280da0a758d3c089ad686
[strongswan.git] / Source / charon / generator.h
1 /**
2 * @file generator.h
3 *
4 * @brief Generic generator class used to generate IKEv2-header and payloads.
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 GENERATOR_H_
24 #define GENERATOR_H_
25
26 #include "types.h"
27 #include "encodings/encodings.h"
28
29 /**
30 * Generating is done in a data buffer.
31 * This is thehe start size of this buffer in Bytes.
32 */
33 #define GENERATOR_DATA_BUFFER_SIZE 3000
34
35 /**
36 * Number of bytes to increase the buffer, if it is to small.
37 */
38 #define GENERATOR_DATA_BUFFER_INCREASE_VALUE 1000
39
40 /**
41 * Used for generator operations internaly to store a generator context.
42 */
43 typedef struct generator_context_s generator_context_t;
44
45 struct generator_context_s {
46 /**
47 * @brief Destroys a generator_infos_t object and its containing buffer
48 *
49 * @param generator_infos_t generator_infos_t object
50 * @return always SUCCESSFUL
51 */
52 status_t (*destroy) (generator_context_t *this);
53 };
54
55
56
57 /**
58 *A generator_t object which generates payloads of specific type.
59 */
60 typedef struct generator_s generator_t;
61
62 struct generator_s {
63
64 /**
65 * Creates a generator_context_t object holding necessary informations
66 * for generating (buffer, data_struct, etc).
67 *
68 * After using, this context has to get destroyed!
69 *
70 * @param data_struct data struct where the specific payload informations are stored
71 * @return
72 * - pointer to created generator_infos_t object
73 * - NULL if memory allocation failed
74 */
75 generator_context_t * (*create_context) (generator_t *this);
76
77 /**
78 * @brief Generates a specific payload from given data struct.
79 *
80 * Remember: Header and substructures are also handled as payloads.
81 *
82 * @param this generator_t object
83 * @param payload_type payload type to generate using the given data struct
84 * @param[in] data_struct data struct where the needed data for generating are stored
85 * @param generator_context generator context to use when generating
86 * @return
87 * - SUCCESSFUL if succeeded
88 * - NOT_SUPPORTED if payload_type is not supported
89 * - OUT_OF_RES if out of ressources
90 */
91 status_t (*generate_payload) (generator_t *this,payload_type_t payload_type,void * data_struct,generator_context_t *generator_context);
92
93 /**
94 * Writes all generated data of current context to a chunk
95 *
96 * @param this generator_t object
97 * @param generator_context generator context to use when generating
98 * * @param[out] data chunk to write the data to
99 * @return
100 * @return
101 * - SUCCESSFUL if succeeded
102 * - OUT_OF_RES otherwise
103 */
104 status_t (*write_to_chunk) (generator_t *this,generator_context_t *generator_context, chunk_t *data);
105
106 /**
107 * @brief Destroys a generator_t object.
108 *
109 * @param this generator_t object
110 *
111 * @return always success
112 */
113 status_t (*destroy) (generator_t *this);
114 };
115
116 /**
117 * Constructor to create a generator
118 *
119 * @param payload_infos pointer to the payload_info_t-array containing
120 * all the payload informations needed to
121 * automatic generate a specific payload
122 */
123 generator_t * generator_create(payload_info_t ** payload_infos);
124
125 #endif /*GENERATOR_H_*/