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 "encodings/encodings.h"
30 * Generating is done in a data buffer.
31 * This is thehe start size of this buffer in Bytes.
33 #define GENERATOR_DATA_BUFFER_SIZE 3000
36 * Number of bytes to increase the buffer, if it is to small.
38 #define GENERATOR_DATA_BUFFER_INCREASE_VALUE 1000
41 * Used for generator operations internaly to store a generator context.
43 typedef struct generator_context_s generator_context_t
;
45 struct generator_context_s
{
47 * @brief Destroys a generator_infos_t object and its containing buffer
49 * @param generator_infos_t generator_infos_t object
50 * @return always SUCCESSFUL
52 status_t (*destroy
) (generator_context_t
*this);
58 *A generator_t object which generates payloads of specific type.
60 typedef struct generator_s generator_t
;
65 * Creates a generator_context_t object holding necessary informations
66 * for generating (buffer, data_struct, etc).
68 * After using, this context has to get destroyed!
70 * @param data_struct data struct where the specific payload informations are stored
72 * - pointer to created generator_infos_t object
73 * - NULL if memory allocation failed
75 generator_context_t
* (*create_context
) (generator_t
*this);
78 * @brief Generates a specific payload from given data struct.
80 * Remember: Header and substructures are also handled as payloads.
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
87 * - SUCCESSFUL if succeeded
88 * - NOT_SUPPORTED if payload_type is not supported
89 * - OUT_OF_RES if out of ressources
91 status_t (*generate_payload
) (generator_t
*this,payload_type_t payload_type
,void * data_struct
,generator_context_t
*generator_context
);
94 * Writes all generated data of current context to a chunk
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
101 * - SUCCESSFUL if succeeded
102 * - OUT_OF_RES otherwise
104 status_t (*write_to_chunk
) (generator_t
*this,generator_context_t
*generator_context
, chunk_t
*data
);
107 * @brief Destroys a generator_t object.
109 * @param this generator_t object
111 * @return always success
113 status_t (*destroy
) (generator_t
*this);
117 * Constructor to create a generator
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
123 generator_t
* generator_create(payload_info_t
** payload_infos
);
125 #endif /*GENERATOR_H_*/