aboutsummaryrefslogtreecommitdiffstats
path: root/src/charon/encoding/generator.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/charon/encoding/generator.c')
-rw-r--r--src/charon/encoding/generator.c88
1 files changed, 41 insertions, 47 deletions
diff --git a/src/charon/encoding/generator.c b/src/charon/encoding/generator.c
index 34e87fadb..392a4602d 100644
--- a/src/charon/encoding/generator.c
+++ b/src/charon/encoding/generator.c
@@ -32,7 +32,6 @@
#include <types.h>
#include <daemon.h>
#include <utils/linked_list.h>
-#include <utils/logger_manager.h>
#include <encoding/payloads/payload.h>
#include <encoding/payloads/proposal_substructure.h>
#include <encoding/payloads/transform_substructure.h>
@@ -222,24 +221,19 @@ struct private_generator_t {
*/
u_int8_t last_spi_size;
- /*
+ /**
* Attribute format of the last generated transform attribute.
- *
+ *
* Used to check if a variable value field is used or not for
* the transform attribute value.
*/
bool attribute_format;
- /*
+ /**
* Depending on the value of attribute_format this field is used
* to hold the length of the transform attribute in bytes.
*/
u_int16_t attribute_length;
-
- /**
- * Associated Logger.
- */
- logger_t *logger;
};
/**
@@ -312,16 +306,16 @@ static void generate_u_int_type (private_generator_t *this,encoding_type_t int_t
break;
default:
- this->logger->log(this->logger, ERROR, "U_INT Type %s is not supported",
- mapping_find(encoding_type_m,int_type));
+ DBG1(SIG_DBG_ENC, "U_INT Type %N is not supported",
+ encoding_type_names, int_type);
return;
}
/* U_INT Types of multiple then 8 bits must be aligned */
if (((number_of_bits % 8) == 0) && (this->current_bit != 0))
{
- this->logger->log(this->logger, ERROR, "U_INT Type %s is not 8 Bit aligned",
- mapping_find(encoding_type_m,int_type));
+ DBG1(SIG_DBG_ENC, "U_INT Type %N is not 8 Bit aligned",
+ encoding_type_names, int_type);
/* current bit has to be zero for values multiple of 8 bits */
return;
}
@@ -341,7 +335,7 @@ static void generate_u_int_type (private_generator_t *this,encoding_type_t int_t
u_int8_t low_val = *(this->out_position) & 0x0F;
/* highval is set, low_val is not changed */
*(this->out_position) = high_val | low_val;
- this->logger->log(this->logger, RAW|LEVEL2, " => %d", *(this->out_position));
+ DBG3(SIG_DBG_ENC, " => %d", *(this->out_position));
/* write position is not changed, just bit position is moved */
this->current_bit = 4;
}
@@ -352,14 +346,14 @@ static void generate_u_int_type (private_generator_t *this,encoding_type_t int_t
/* lowval of current byte in buffer has to be set to the new value*/
u_int low_val = *((u_int8_t *)(this->data_struct + offset)) & 0x0F;
*(this->out_position) = high_val | low_val;
- this->logger->log(this->logger, RAW|LEVEL2, " => %d", *(this->out_position));
+ DBG3(SIG_DBG_ENC, " => %d", *(this->out_position));
this->out_position++;
this->current_bit = 0;
}
else
{
- this->logger->log(this->logger, ERROR, "U_INT_4 Type is not 4 Bit aligned");
+ DBG1(SIG_DBG_ENC, "U_INT_4 Type is not 4 Bit aligned");
/* 4 Bit integers must have a 4 bit alignment */
return;
};
@@ -370,7 +364,7 @@ static void generate_u_int_type (private_generator_t *this,encoding_type_t int_t
{
/* 8 bit values are written as they are */
*this->out_position = *((u_int8_t *)(this->data_struct + offset));
- this->logger->log(this->logger, RAW|LEVEL2, " => %d", *(this->out_position));
+ DBG3(SIG_DBG_ENC, " => %d", *(this->out_position));
this->out_position++;
break;
@@ -380,7 +374,7 @@ static void generate_u_int_type (private_generator_t *this,encoding_type_t int_t
/* attribute type must not change first bit uf current byte ! */
if (this->current_bit != 1)
{
- this->logger->log(this->logger, ERROR, "ATTRIBUTE FORMAT flag is not set");
+ DBG1(SIG_DBG_ENC, "ATTRIBUTE FORMAT flag is not set");
/* first bit has to be set! */
return;
}
@@ -392,7 +386,7 @@ static void generate_u_int_type (private_generator_t *this,encoding_type_t int_t
int16_val = int16_val & 0xFF7F;
int16_val = int16_val | attribute_format_flag;
- this->logger->log(this->logger, RAW|LEVEL2, " => %d", int16_val);
+ DBG3(SIG_DBG_ENC, " => %d", int16_val);
/* write bytes to buffer (set bit is overwritten)*/
this->write_bytes_to_buffer(this,&int16_val,sizeof(u_int16_t));
this->current_bit = 0;
@@ -403,14 +397,14 @@ static void generate_u_int_type (private_generator_t *this,encoding_type_t int_t
case CONFIGURATION_ATTRIBUTE_LENGTH:
{
u_int16_t int16_val = htons(*((u_int16_t*)(this->data_struct + offset)));
- this->logger->log_bytes(this->logger, RAW|LEVEL2, " =>", (void*)&int16_val, sizeof(int16_val));
+ DBG3(SIG_DBG_ENC, " => %b", (void*)&int16_val, sizeof(int16_val));
this->write_bytes_to_buffer(this,&int16_val,sizeof(u_int16_t));
break;
}
case U_INT_32:
{
u_int32_t int32_val = htonl(*((u_int32_t*)(this->data_struct + offset)));
- this->logger->log_bytes(this->logger, RAW|LEVEL2, " =>", (void*)&int32_val, sizeof(int32_val));
+ DBG3(SIG_DBG_ENC, " => %b", (void*)&int32_val, sizeof(int32_val));
this->write_bytes_to_buffer(this,&int32_val,sizeof(u_int32_t));
break;
}
@@ -419,8 +413,9 @@ static void generate_u_int_type (private_generator_t *this,encoding_type_t int_t
/* 64 bit integers are written as two 32 bit integers */
u_int32_t int32_val_low = htonl(*((u_int32_t*)(this->data_struct + offset)));
u_int32_t int32_val_high = htonl(*((u_int32_t*)(this->data_struct + offset) + 1));
- this->logger->log_bytes(this->logger, RAW|LEVEL2, " => (low)", (void*)&int32_val_low, sizeof(int32_val_low));
- this->logger->log_bytes(this->logger, RAW|LEVEL2, " => (high)", (void*)&int32_val_high, sizeof(int32_val_high));
+ DBG3(SIG_DBG_ENC, " => %b %b",
+ (void*)&int32_val_low, sizeof(int32_val_low),
+ (void*)&int32_val_high, sizeof(int32_val_high));
/* TODO add support for big endian machines */
this->write_bytes_to_buffer(this,&int32_val_high,sizeof(u_int32_t));
this->write_bytes_to_buffer(this,&int32_val_low,sizeof(u_int32_t));
@@ -431,12 +426,13 @@ static void generate_u_int_type (private_generator_t *this,encoding_type_t int_t
{
/* 64 bit are written as they come :-) */
this->write_bytes_to_buffer(this,(this->data_struct + offset),sizeof(u_int64_t));
- this->logger->log_bytes(this->logger, RAW|LEVEL2, " =>", (void*)(this->data_struct + offset), sizeof(u_int64_t));
+ DBG3(SIG_DBG_ENC, " => %b", (void*)(this->data_struct + offset), sizeof(u_int64_t));
break;
}
default:
{
- this->logger->log(this->logger, ERROR, "U_INT Type %s is not supported", mapping_find(encoding_type_m,int_type));
+ DBG1(SIG_DBG_ENC, "U_INT Type %N is not supported",
+ encoding_type_names, int_type);
return;
}
}
@@ -450,7 +446,7 @@ static void generate_reserved_field(private_generator_t *this,int bits)
/* only one bit or 8 bit fields are supported */
if ((bits != 1) && (bits != 8))
{
- this->logger->log(this->logger, ERROR, "Reserved field of %d bits cannot be generated", bits);
+ DBG1(SIG_DBG_ENC, "reserved field of %d bits cannot be generated", bits);
return ;
}
/* make sure enough space is available in buffer */
@@ -480,9 +476,8 @@ static void generate_reserved_field(private_generator_t *this,int bits)
/* one byte processing*/
if (this->current_bit > 0)
{
- this->logger->log(this->logger, ERROR,
- "Reserved field cannot be written cause allignement of current bit is %d",
- this->current_bit);
+ DBG1(SIG_DBG_ENC, "reserved field cannot be written cause "
+ "alignement of current bit is %d", this->current_bit);
return;
}
*(this->out_position) = 0x00;
@@ -516,7 +511,7 @@ static void generate_flag (private_generator_t *this,u_int32_t offset)
*(this->out_position) = *(this->out_position) | flag;
- this->logger->log(this->logger, RAW|LEVEL2, " => %d", *(this->out_position));
+ DBG3(SIG_DBG_ENC, " => %d", *(this->out_position));
this->current_bit++;
if (this->current_bit >= 8)
@@ -533,14 +528,14 @@ static void generate_from_chunk (private_generator_t *this,u_int32_t offset)
{
if (this->current_bit != 0)
{
- this->logger->log(this->logger, ERROR, "can not generate a chunk at Bitpos %d", this->current_bit);
+ DBG1(SIG_DBG_ENC, "can not generate a chunk at Bitpos %d", this->current_bit);
return ;
}
/* position in buffer */
chunk_t *attribute_value = (chunk_t *)(this->data_struct + offset);
- this->logger->log_chunk(this->logger, RAW|LEVEL2, " =>", *attribute_value);
+ DBG3(SIG_DBG_ENC, " => %B", attribute_value);
/* use write_bytes_to_buffer function to do the job */
this->write_bytes_to_buffer(this,attribute_value->ptr,attribute_value->len);
@@ -558,8 +553,8 @@ static void make_space_available (private_generator_t *this, size_t bits)
size_t new_buffer_size = old_buffer_size + GENERATOR_DATA_BUFFER_INCREASE_VALUE;
size_t out_position_offset = ((this->out_position) - (this->buffer));
- this->logger->log(this->logger, CONTROL|LEVEL3, "increased gen buffer from %d to %d byte",
- old_buffer_size, new_buffer_size);
+ DBG2(SIG_DBG_ENC, "increased gen buffer from %d to %d byte",
+ old_buffer_size, new_buffer_size);
/* Reallocate space for new buffer */
this->buffer = realloc(this->buffer,new_buffer_size);
@@ -633,7 +628,7 @@ static void write_to_chunk (private_generator_t *this,chunk_t *data)
memcpy(data->ptr,this->buffer,data_length);
data->len = data_length;
- this->logger->log_chunk(this->logger, RAW|LEVEL3, "generated data of this generator", *data);
+ DBG3(SIG_DBG_ENC, "generated data of this generator %B", data);
}
/**
@@ -655,16 +650,16 @@ static void generate_payload (private_generator_t *this,payload_t *payload)
payload_start = this->out_position;
- this->logger->log(this->logger, CONTROL|LEVEL1, "generating payload of type %s",
- mapping_find(payload_type_m,payload_type));
+ DBG2(SIG_DBG_ENC, "generating payload of type %N",
+ payload_type_names, payload_type);
/* each payload has its own encoding rules */
payload->get_encoding_rules(payload,&rules,&rule_count);
for (i = 0; i < rule_count;i++)
{
- this->logger->log(this->logger, CONTROL|LEVEL2, " generating rule %d %s",
- i, mapping_find(encoding_type_m,rules[i].type));
+ DBG2(SIG_DBG_ENC, " generating rule %d %N",
+ i, encoding_type_names, rules[i].type);
switch (rules[i].type)
{
/* all u int values, IKE_SPI,TS_TYPE and ATTRIBUTE_TYPE are generated in generate_u_int_type */
@@ -964,7 +959,7 @@ static void generate_payload (private_generator_t *this,payload_t *payload)
{
if (this->attribute_format == FALSE)
{
- this->logger->log(this->logger, CONTROL|LEVEL3, "attribute value has not fixed size");
+ DBG2(SIG_DBG_ENC, "attribute value has not fixed size");
/* the attribute value is generated */
this->generate_from_chunk(this,rules[i].offset);
}
@@ -1012,15 +1007,15 @@ static void generate_payload (private_generator_t *this,payload_t *payload)
break;
}
default:
- this->logger->log(this->logger, ERROR, "field type %s is not supported",
- mapping_find(encoding_type_m,rules[i].type));
+ DBG1(SIG_DBG_ENC, "field type %N is not supported",
+ encoding_type_names, rules[i].type);
return;
}
}
- this->logger->log(this->logger, CONTROL|LEVEL2, "generating %s payload finished.",
- mapping_find(payload_type_m, payload_type));
- this->logger->log_bytes(this->logger, RAW|LEVEL3, "generated data for this payload",
- payload_start, this->out_position-payload_start);
+ DBG2(SIG_DBG_ENC, "generating %N payload finished",
+ payload_type_names, payload_type);
+ DBG3(SIG_DBG_ENC, "generated data for this payload %b",
+ payload_start, this->out_position-payload_start);
}
/**
@@ -1072,7 +1067,6 @@ generator_t *generator_create()
this->current_bit = 0;
this->last_payload_length_position_offset = 0;
this->header_length_position_offset = 0;
- this->logger = logger_manager->get_logger(logger_manager, GENERATOR);
return &(this->public);
}