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