4 * @brief Generic generator class used to generate IKEv2-header and payloads.
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
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>.
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
27 #include "payloads/encodings.h"
28 #include "payloads/payload.h"
31 * Generating is done in a data buffer.
32 * This is thehe start size of this buffer in Bytes.
34 #define GENERATOR_DATA_BUFFER_SIZE 3000
37 * Number of bytes to increase the buffer, if it is to small.
39 #define GENERATOR_DATA_BUFFER_INCREASE_VALUE 1000
42 * Used for generator operations internaly to store a generator context.
44 typedef struct generator_context_s generator_context_t
;
46 struct generator_context_s
{
48 * @brief Destroys a generator_infos_t object and its containing buffer
50 * @param generator_infos_t generator_infos_t object
51 * @return always SUCCESSFUL
53 status_t (*destroy
) (generator_context_t
*this);
59 *A generator_t object which generates payloads of specific type.
61 typedef struct generator_s generator_t
;
66 * Creates a generator_context_t object holding necessary informations
67 * for generating (buffer, data_struct, etc).
69 * After using, this context has to get destroyed!
71 * @param data_struct data struct where the specific payload informations are stored
73 * - pointer to created generator_infos_t object
74 * - NULL if memory allocation failed
76 generator_context_t
* (*create_context
) (generator_t
*this);
79 * @brief Generates a specific payload from given data struct.
81 * Remember: Header and substructures are also handled as payloads.
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
88 * - SUCCESSFUL if succeeded
89 * - NOT_SUPPORTED if payload_type is not supported
90 * - OUT_OF_RES if out of ressources
92 status_t (*generate_payload
) (generator_t
*this,payload_type_t payload_type
,void * data_struct
,generator_context_t
*generator_context
);
95 * Writes all generated data of current context to a chunk
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
102 * - SUCCESSFUL if succeeded
103 * - OUT_OF_RES otherwise
105 status_t (*write_to_chunk
) (generator_t
*this,generator_context_t
*generator_context
, chunk_t
*data
);
108 * @brief Destroys a generator_t object.
110 * @param this generator_t object
112 * @return always success
114 status_t (*destroy
) (generator_t
*this);
118 * Constructor to create a generator
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
124 generator_t
* generator_create();
126 #endif /*GENERATOR_H_*/