use signed lengths in parser and generator
This commit is contained in:
@@ -72,12 +72,12 @@ struct private_generator_t {
|
|||||||
/**
|
/**
|
||||||
* Current bit writing to in current byte (between 0 and 7).
|
* Current bit writing to in current byte (between 0 and 7).
|
||||||
*/
|
*/
|
||||||
size_t current_bit;
|
u_int8_t current_bit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Associated data struct to read informations from.
|
* Associated data struct to read informations from.
|
||||||
*/
|
*/
|
||||||
void * data_struct;
|
void *data_struct;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Last payload length position offset in the buffer.
|
* Last payload length position offset in the buffer.
|
||||||
@@ -112,7 +112,7 @@ struct private_generator_t {
|
|||||||
/**
|
/**
|
||||||
* Get size of current buffer in bytes.
|
* Get size of current buffer in bytes.
|
||||||
*/
|
*/
|
||||||
static size_t get_size(private_generator_t *this)
|
static int get_size(private_generator_t *this)
|
||||||
{
|
{
|
||||||
return this->roof_position - this->buffer;
|
return this->roof_position - this->buffer;
|
||||||
}
|
}
|
||||||
@@ -120,7 +120,7 @@ static size_t get_size(private_generator_t *this)
|
|||||||
/**
|
/**
|
||||||
* Get free space of current buffer in bytes.
|
* Get free space of current buffer in bytes.
|
||||||
*/
|
*/
|
||||||
static size_t get_space(private_generator_t *this)
|
static int get_space(private_generator_t *this)
|
||||||
{
|
{
|
||||||
return this->roof_position - this->out_position;
|
return this->roof_position - this->out_position;
|
||||||
}
|
}
|
||||||
@@ -128,7 +128,7 @@ static size_t get_space(private_generator_t *this)
|
|||||||
/**
|
/**
|
||||||
* Get length of data in buffer (in bytes).
|
* Get length of data in buffer (in bytes).
|
||||||
*/
|
*/
|
||||||
static size_t get_length(private_generator_t *this)
|
static int get_length(private_generator_t *this)
|
||||||
{
|
{
|
||||||
return this->out_position - this->buffer;
|
return this->out_position - this->buffer;
|
||||||
}
|
}
|
||||||
@@ -144,11 +144,11 @@ static u_int32_t get_offset(private_generator_t *this)
|
|||||||
/**
|
/**
|
||||||
* Makes sure enough space is available in buffer to store amount of bits.
|
* Makes sure enough space is available in buffer to store amount of bits.
|
||||||
*/
|
*/
|
||||||
static void make_space_available(private_generator_t *this, size_t bits)
|
static void make_space_available(private_generator_t *this, int bits)
|
||||||
{
|
{
|
||||||
while ((get_space(this) * 8 - this->current_bit) < bits)
|
while ((get_space(this) * 8 - this->current_bit) < bits)
|
||||||
{
|
{
|
||||||
size_t old_buffer_size, new_buffer_size, out_position_offset;
|
int old_buffer_size, new_buffer_size, out_position_offset;
|
||||||
|
|
||||||
old_buffer_size = get_size(this);
|
old_buffer_size = get_size(this);
|
||||||
new_buffer_size = old_buffer_size + GENERATOR_DATA_BUFFER_INCREASE_VALUE;
|
new_buffer_size = old_buffer_size + GENERATOR_DATA_BUFFER_INCREASE_VALUE;
|
||||||
@@ -167,7 +167,7 @@ static void make_space_available(private_generator_t *this, size_t bits)
|
|||||||
* Writes a specific amount of byte into the buffer.
|
* Writes a specific amount of byte into the buffer.
|
||||||
*/
|
*/
|
||||||
static void write_bytes_to_buffer(private_generator_t *this, void *bytes,
|
static void write_bytes_to_buffer(private_generator_t *this, void *bytes,
|
||||||
size_t number_of_bytes)
|
int number_of_bytes)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
u_int8_t *read_position = (u_int8_t *)bytes;
|
u_int8_t *read_position = (u_int8_t *)bytes;
|
||||||
@@ -185,8 +185,8 @@ static void write_bytes_to_buffer(private_generator_t *this, void *bytes,
|
|||||||
/**
|
/**
|
||||||
* Writes a specific amount of byte into the buffer at a specific offset.
|
* Writes a specific amount of byte into the buffer at a specific offset.
|
||||||
*/
|
*/
|
||||||
static void write_bytes_to_buffer_at_offset (private_generator_t *this,
|
static void write_bytes_to_buffer_at_offset(private_generator_t *this,
|
||||||
void *bytes, size_t number_of_bytes, u_int32_t offset)
|
void *bytes, int number_of_bytes, u_int32_t offset)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
u_int8_t *read_position = (u_int8_t *)bytes;
|
u_int8_t *read_position = (u_int8_t *)bytes;
|
||||||
@@ -215,7 +215,7 @@ static void write_bytes_to_buffer_at_offset (private_generator_t *this,
|
|||||||
static void generate_u_int_type(private_generator_t *this,
|
static void generate_u_int_type(private_generator_t *this,
|
||||||
encoding_type_t int_type,u_int32_t offset)
|
encoding_type_t int_type,u_int32_t offset)
|
||||||
{
|
{
|
||||||
size_t number_of_bits = 0;
|
int number_of_bits = 0;
|
||||||
|
|
||||||
/* find out number of bits of each U_INT type to check for enough space */
|
/* find out number of bits of each U_INT type to check for enough space */
|
||||||
switch (int_type)
|
switch (int_type)
|
||||||
@@ -458,7 +458,7 @@ static void generate_from_chunk(private_generator_t *this, u_int32_t offset)
|
|||||||
*/
|
*/
|
||||||
static void write_to_chunk(private_generator_t *this,chunk_t *data)
|
static void write_to_chunk(private_generator_t *this,chunk_t *data)
|
||||||
{
|
{
|
||||||
size_t data_length = get_length(this);
|
int data_length = get_length(this);
|
||||||
u_int32_t header_length_field = data_length;
|
u_int32_t header_length_field = data_length;
|
||||||
|
|
||||||
/* write length into header length field */
|
/* write length into header length field */
|
||||||
@@ -486,7 +486,7 @@ static void generate_payload (private_generator_t *this,payload_t *payload)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
this->data_struct = payload;
|
this->data_struct = payload;
|
||||||
size_t rule_count, offset_start;
|
int rule_count, offset_start;
|
||||||
encoding_rule_t *rules;
|
encoding_rule_t *rules;
|
||||||
payload_type_t payload_type;
|
payload_type_t payload_type;
|
||||||
|
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ static bool parse_uint32(private_parser_t *this, int rule_number,
|
|||||||
* Parse a given amount of bytes and writes them to a specific location
|
* Parse a given amount of bytes and writes them to a specific location
|
||||||
*/
|
*/
|
||||||
static bool parse_bytes(private_parser_t *this, int rule_number,
|
static bool parse_bytes(private_parser_t *this, int rule_number,
|
||||||
u_int8_t *output_pos, size_t bytes)
|
u_int8_t *output_pos, int bytes)
|
||||||
{
|
{
|
||||||
if (this->byte_pos + bytes > this->input_roof)
|
if (this->byte_pos + bytes > this->input_roof)
|
||||||
{
|
{
|
||||||
@@ -300,7 +300,7 @@ static bool parse_bit(private_parser_t *this, int rule_number,
|
|||||||
* Parse substructures in a list.
|
* Parse substructures in a list.
|
||||||
*/
|
*/
|
||||||
static bool parse_list(private_parser_t *this, int rule_number,
|
static bool parse_list(private_parser_t *this, int rule_number,
|
||||||
linked_list_t **output_pos, payload_type_t payload_type, size_t length)
|
linked_list_t **output_pos, payload_type_t payload_type, int length)
|
||||||
{
|
{
|
||||||
linked_list_t *list = *output_pos;
|
linked_list_t *list = *output_pos;
|
||||||
|
|
||||||
@@ -337,7 +337,7 @@ static bool parse_list(private_parser_t *this, int rule_number,
|
|||||||
* Parse data from current parsing position in a chunk.
|
* Parse data from current parsing position in a chunk.
|
||||||
*/
|
*/
|
||||||
static bool parse_chunk(private_parser_t *this, int rule_number,
|
static bool parse_chunk(private_parser_t *this, int rule_number,
|
||||||
chunk_t *output_pos, size_t length)
|
chunk_t *output_pos, int length)
|
||||||
{
|
{
|
||||||
if (this->byte_pos + length > this->input_roof)
|
if (this->byte_pos + length > this->input_roof)
|
||||||
{
|
{
|
||||||
@@ -365,7 +365,7 @@ static status_t parse_payload(private_parser_t *this,
|
|||||||
{
|
{
|
||||||
payload_t *pld;
|
payload_t *pld;
|
||||||
void *output;
|
void *output;
|
||||||
size_t rule_count, payload_length = 0, spi_size = 0, attribute_length = 0;
|
int rule_count, payload_length = 0, spi_size = 0, attribute_length = 0;
|
||||||
u_int16_t ts_type = 0;
|
u_int16_t ts_type = 0;
|
||||||
bool attribute_format = FALSE;
|
bool attribute_format = FALSE;
|
||||||
int rule_number;
|
int rule_number;
|
||||||
@@ -757,7 +757,7 @@ static status_t parse_payload(private_parser_t *this,
|
|||||||
}
|
}
|
||||||
case ADDRESS:
|
case ADDRESS:
|
||||||
{
|
{
|
||||||
size_t address_length = (ts_type == TS_IPV4_ADDR_RANGE) ? 4 : 16;
|
int address_length = (ts_type == TS_IPV4_ADDR_RANGE) ? 4 : 16;
|
||||||
|
|
||||||
if (!parse_chunk(this, rule_number, output + rule->offset,
|
if (!parse_chunk(this, rule_number, output + rule->offset,
|
||||||
address_length))
|
address_length))
|
||||||
|
|||||||
Reference in New Issue
Block a user