aboutsummaryrefslogtreecommitdiffstats
path: root/src/libcharon
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2010-08-17 12:54:16 +0200
committerMartin Willi <martin@revosec.ch>2010-08-19 12:35:53 +0200
commit92a4540aca0f1c8dbf9911454ee5702460add07d (patch)
tree5cea5e1836b9fb1d1233b8286df09baf533fc6d6 /src/libcharon
parent0cca7427c7758212f0f718f92f6694273db362d3 (diff)
downloadstrongswan-92a4540aca0f1c8dbf9911454ee5702460add07d.tar.bz2
strongswan-92a4540aca0f1c8dbf9911454ee5702460add07d.tar.xz
Migrated generator_t to INIT/METHOD macros
Diffstat (limited to 'src/libcharon')
-rw-r--r--src/libcharon/encoding/generator.c73
-rw-r--r--src/libcharon/encoding/generator.h14
2 files changed, 33 insertions, 54 deletions
diff --git a/src/libcharon/encoding/generator.c b/src/libcharon/encoding/generator.c
index 6485da492..c114eb2fd 100644
--- a/src/libcharon/encoding/generator.c
+++ b/src/libcharon/encoding/generator.c
@@ -42,6 +42,16 @@
#include <encoding/payloads/configuration_attribute.h>
#include <encoding/payloads/eap_payload.h>
+/**
+ * Generating is done in a data buffer.
+ * This is the start size of this buffer in bytes.
+ */
+#define GENERATOR_DATA_BUFFER_SIZE 500
+
+/**
+ * Number of bytes to increase the buffer, if it is too small.
+ */
+#define GENERATOR_DATA_BUFFER_INCREASE_VALUE 500
typedef struct private_generator_t private_generator_t;
@@ -453,36 +463,28 @@ static void generate_from_chunk(private_generator_t *this, u_int32_t offset)
write_bytes_to_buffer(this, value->ptr, value->len);
}
-/**
- * Implementation of private_generator_t.write_to_chunk.
- */
-static void write_to_chunk(private_generator_t *this,chunk_t *data)
+METHOD(generator_t, write_to_chunk, void,
+ private_generator_t *this, chunk_t *data)
{
- int data_length = get_length(this);
- u_int32_t header_length_field = data_length;
+ u_int32_t len, val;
+
+ len = get_length(this);
/* write length into header length field */
if (this->header_length_position_offset > 0)
{
- u_int32_t val = htonl(header_length_field);
+ val = htonl(len);
write_bytes_to_buffer_at_offset(this, &val, sizeof(u_int32_t),
this->header_length_position_offset);
}
-
- if (this->current_bit > 0)
- {
- data_length++;
- }
- *data = chunk_alloc(data_length);
- memcpy(data->ptr, this->buffer, data_length);
+ *data = chunk_alloc(len);
+ memcpy(data->ptr, this->buffer, len);
DBG3(DBG_ENC, "generated data of this generator %B", data);
}
-/**
- * Implementation of private_generator_t.generate_payload.
- */
-static void generate_payload (private_generator_t *this,payload_t *payload)
+METHOD(generator_t, generate_payload, void,
+ private_generator_t *this,payload_t *payload)
{
int i, offset_start;
size_t rule_count;
@@ -846,14 +848,11 @@ static void generate_payload (private_generator_t *this,payload_t *payload)
this->out_position - this->buffer - offset_start);
}
-/**
- * Implementation of generator_t.destroy.
- */
-static status_t destroy(private_generator_t *this)
+METHOD(generator_t, destroy, void,
+ private_generator_t *this)
{
free(this->buffer);
free(this);
- return SUCCESS;
}
/*
@@ -863,26 +862,18 @@ generator_t *generator_create()
{
private_generator_t *this;
- this = malloc_thing(private_generator_t);
-
- /* initiate public functions */
- this->public.generate_payload = (void(*)(generator_t*, payload_t *))generate_payload;
- this->public.destroy = (void(*)(generator_t*)) destroy;
- this->public.write_to_chunk = (void (*) (generator_t *,chunk_t *))write_to_chunk;
+ INIT(this,
+ .public = {
+ .write_to_chunk = _write_to_chunk,
+ .generate_payload = _generate_payload,
+ .destroy = _destroy,
+ },
+ .buffer = malloc(GENERATOR_DATA_BUFFER_SIZE),
+ );
- /* allocate memory for buffer */
- this->buffer = malloc(GENERATOR_DATA_BUFFER_SIZE);
-
- /* initiate private variables */
this->out_position = this->buffer;
this->roof_position = this->buffer + GENERATOR_DATA_BUFFER_SIZE;
- this->data_struct = NULL;
- this->current_bit = 0;
- this->last_payload_length_position_offset = 0;
- this->header_length_position_offset = 0;
- this->attribute_format = FALSE;
- this->attribute_length = 0;
-
- return &(this->public);
+
+ return &this->public;
}
diff --git a/src/libcharon/encoding/generator.h b/src/libcharon/encoding/generator.h
index 2221c84af..90a43de10 100644
--- a/src/libcharon/encoding/generator.h
+++ b/src/libcharon/encoding/generator.h
@@ -29,24 +29,12 @@ typedef struct generator_t generator_t;
#include <encoding/payloads/payload.h>
/**
- * Generating is done in a data buffer.
- * This is the start size of this buffer in bytes.
- */
-#define GENERATOR_DATA_BUFFER_SIZE 500
-
-/**
- * Number of bytes to increase the buffer, if it is too small.
- */
-#define GENERATOR_DATA_BUFFER_INCREASE_VALUE 500
-
-
-/**
* A generator_t class used to generate IKEv2 payloads.
*
* After creation, multiple payloads can be generated with the generate_payload
* method. The generated bytes are appended. After all payloads are added,
* the write_to_chunk method writes out all generated data since
- * the creation of the generator. After that, the generator must be destroyed.
+ * the creation of the generator.
* The generater uses a set of encoding rules, which it can get from
* the supplied payload. With this rules, the generater can generate
* the payload and all substructures automatically.