parser_t public;
/**
- * Parse a 4-Bit unsigned integer from the current parsing position.
- *
- * @param this parser_t object
- * @param rule_number number of current rule
- * @param[out] output_pos pointer where to write the parsed result
- * @return
- * - SUCCESS or
- * - PARSE_ERROR when not successful
- */
- status_t (*parse_uint4) (private_parser_t *this, int rule_number, u_int8_t *output_pos);
-
- /**
- * Parse a 8-Bit unsigned integer from the current parsing position.
- *
- * @param this parser_t object
- * @param rule_number number of current rule
- * @param[out] output_pos pointer where to write the parsed result
- * @return
- * - SUCCESS or
- * - PARSE_ERROR when not successful
- */
- status_t (*parse_uint8) (private_parser_t *this, int rule_number, u_int8_t *output_pos);
-
- /**
- * Parse a 15-Bit unsigned integer from the current parsing position.
- *
- * This is a special case used for ATTRIBUTE_TYPE.
- * Big-/Little-endian conversion is done here.
- *
- * @param this parser_t object
- * @param rule_number number of current rule
- * @param[out] output_pos pointer where to write the parsed result
- * @return
- * - SUCCESS or
- * - PARSE_ERROR when not successful
- */
- status_t (*parse_uint15) (private_parser_t *this, int rule_number, u_int16_t *output_pos);
-
- /**
- * Parse a 16-Bit unsigned integer from the current parsing position.
- *
- * Big-/Little-endian conversion is done here.
- *
- * @param this parser_t object
- * @param rule_number number of current rule
- * @param[out] output_pos pointer where to write the parsed result
- * @return
- * - SUCCESS or
- * - PARSE_ERROR when not successful
- */
- status_t (*parse_uint16) (private_parser_t *this, int rule_number, u_int16_t *output_pos);
-
- /**
- * Parse a 32-Bit unsigned integer from the current parsing position.
- *
- * Big-/Little-endian conversion is done here.
- *
- * @param this parser_t object
- * @param rule_number number of current rule
- * @param[out] output_pos pointer where to write the parsed result
- * @return
- * - SUCCESS or
- * - PARSE_ERROR when not successful
- */
- status_t (*parse_uint32) (private_parser_t *this, int rule_number, u_int32_t *output_pos);
-
- /**
- * Parse a 64-Bit unsigned integer from the current parsing position.
- *
- * @todo add support for big-endian machines.
- *
- * @param this parser_t object
- * @param rule_number number of current rule
- * @param[out] output_pos pointer where to write the parsed result
- * @return
- * - SUCCESS or
- * - PARSE_ERROR when not successful
- */
- status_t (*parse_uint64) (private_parser_t *this, int rule_number, u_int64_t *output_pos);
-
- /**
- * Parse a given amount of bytes and writes them to a specific location
- *
- * @param this parser_t object
- * @param rule_number number of current rule
- * @param[out] output_pos pointer where to write the parsed result
- * @param bytes number of bytes to parse
- * @return
- * - SUCCESS or
- * - PARSE_ERROR when not successful
- */
- status_t (*parse_bytes) (private_parser_t *this, int rule_number, u_int8_t *output_pos,size_t bytes);
-
- /**
- * Parse a single Bit from the current parsing position
- *
- * @param this parser_t object
- * @param rule_number number of current rule
- * @param[out] output_pos pointer where to write the parsed result
- * @return
- * - SUCCESS or
- * - PARSE_ERROR when not successful
- */
- status_t (*parse_bit) (private_parser_t *this, int rule_number, bool *output_pos);
-
- /**
- * Parse substructures in a list
- *
- * This function calls the parser recursively to parse contained substructures
- * in a linked_list_t. The list must already be created. Payload defines
- * the type of the substructures. parsing is continued until the specified length
- * is completely parsed.
- *
- * @param this parser_t object
- * @param rule_number number of current rule
- * @param[out] output_pos pointer of a linked_list where substructures are added
- * @param payload_type type of the contained substructures to parse
- * @param length number of bytes to parse in this list
- * @return
- * - SUCCESS or
- * - PARSE_ERROR when not successful
- */
- status_t (*parse_list) (private_parser_t *this, int rule_number, linked_list_t **output_pos, payload_type_t payload_ype, size_t length);
-
- /**
- * Parse data from current parsing position in a chunk.
- *
- * This function clones length number of bytes to output_pos, without
- * modifiyng them. Space will be allocated and must be freed by caller.
- *
- * @param this parser_t object
- * @param rule_number number of current rule
- * @param[out] output_pos pointer of a chunk which will point to the allocated data
- * @param length number of bytes to clone
- * @return
- * - SUCCESS or
- * - PARSE_ERROR when not successful
- */
- status_t (*parse_chunk) (private_parser_t *this, int rule_number, chunk_t *output_pos, size_t length);
-
- /**
* Current bit for reading in input data.
*/
u_int8_t bit_pos;
};
/**
- * Implementation of private_parser_t.parse_uint4.
+ * Parse a 4-Bit unsigned integer from the current parsing position.
*/
static status_t parse_uint4(private_parser_t *this, int rule_number, u_int8_t *output_pos)
{
}
/**
- * Implementation of private_parser_t.parse_uint8.
+ * Parse a 8-Bit unsigned integer from the current parsing position.
*/
static status_t parse_uint8(private_parser_t *this, int rule_number, u_int8_t *output_pos)
{
}
/**
- * Implementation of private_parser_t.parse_uint15.
+ * Parse a 15-Bit unsigned integer from the current parsing position.
*/
static status_t parse_uint15(private_parser_t *this, int rule_number, u_int16_t *output_pos)
{
}
/**
- * Implementation of private_parser_t.parse_uint16.
+ * Parse a 16-Bit unsigned integer from the current parsing position.
*/
static status_t parse_uint16(private_parser_t *this, int rule_number, u_int16_t *output_pos)
{
return SUCCESS;
}
/**
- * Implementation of private_parser_t.parse_uint32.
+ * Parse a 32-Bit unsigned integer from the current parsing position.
*/
static status_t parse_uint32(private_parser_t *this, int rule_number, u_int32_t *output_pos)
{
}
/**
- * Implementation of private_parser_t.parse_uint64.
+ * Parse a 64-Bit unsigned integer from the current parsing position.
*/
static status_t parse_uint64(private_parser_t *this, int rule_number, u_int64_t *output_pos)
{
}
/**
- * Implementation of private_parser_t.parse_bytes.
+ * Parse a given amount of bytes and writes them to a specific location
*/
static status_t parse_bytes (private_parser_t *this, int rule_number, u_int8_t *output_pos,size_t bytes)
{
}
/**
- * Implementation of private_parser_t.parse_bit.
+ * Parse a single Bit from the current parsing position
*/
static status_t parse_bit(private_parser_t *this, int rule_number, bool *output_pos)
{
}
/**
- * Implementation of private_parser_t.parse_list.
+ * Parse substructures in a list.
*/
static status_t parse_list(private_parser_t *this, int rule_number, linked_list_t **output_pos, payload_type_t payload_type, size_t length)
{
}
/**
- * Implementation of private_parser_t.parse_chunk.
+ * Parse data from current parsing position in a chunk.
*/
static status_t parse_chunk(private_parser_t *this, int rule_number, chunk_t *output_pos, size_t length)
{
{
case U_INT_4:
{
- if (this->parse_uint4(this, rule_number, output + rule->offset) != SUCCESS)
+ if (parse_uint4(this, rule_number, output + rule->offset) != SUCCESS)
{
pld->destroy(pld);
return PARSE_ERROR;
}
case U_INT_8:
{
- if (this->parse_uint8(this, rule_number, output + rule->offset) != SUCCESS)
+ if (parse_uint8(this, rule_number, output + rule->offset) != SUCCESS)
{
pld->destroy(pld);
return PARSE_ERROR;
}
case U_INT_16:
{
- if (this->parse_uint16(this, rule_number, output + rule->offset) != SUCCESS)
+ if (parse_uint16(this, rule_number, output + rule->offset) != SUCCESS)
{
pld->destroy(pld);
return PARSE_ERROR;
}
case U_INT_32:
{
- if (this->parse_uint32(this, rule_number, output + rule->offset) != SUCCESS)
+ if (parse_uint32(this, rule_number, output + rule->offset) != SUCCESS)
{
pld->destroy(pld);
return PARSE_ERROR;
}
case U_INT_64:
{
- if (this->parse_uint64(this, rule_number, output + rule->offset) != SUCCESS)
+ if (parse_uint64(this, rule_number, output + rule->offset) != SUCCESS)
{
pld->destroy(pld);
return PARSE_ERROR;
}
case IKE_SPI:
{
- if (this->parse_bytes(this, rule_number, output + rule->offset,8) != SUCCESS)
+ if (parse_bytes(this, rule_number, output + rule->offset,8) != SUCCESS)
{
pld->destroy(pld);
return PARSE_ERROR;
}
case RESERVED_BIT:
{
- if (this->parse_bit(this, rule_number, NULL) != SUCCESS)
+ if (parse_bit(this, rule_number, NULL) != SUCCESS)
{
pld->destroy(pld);
return PARSE_ERROR;
}
case RESERVED_BYTE:
{
- if (this->parse_uint8(this, rule_number, NULL) != SUCCESS)
+ if (parse_uint8(this, rule_number, NULL) != SUCCESS)
{
pld->destroy(pld);
return PARSE_ERROR;
}
case FLAG:
{
- if (this->parse_bit(this, rule_number, output + rule->offset) != SUCCESS)
+ if (parse_bit(this, rule_number, output + rule->offset) != SUCCESS)
{
pld->destroy(pld);
return PARSE_ERROR;
}
case PAYLOAD_LENGTH:
{
- if (this->parse_uint16(this, rule_number, output + rule->offset) != SUCCESS)
+ if (parse_uint16(this, rule_number, output + rule->offset) != SUCCESS)
{
pld->destroy(pld);
return PARSE_ERROR;
}
case HEADER_LENGTH:
{
- if (this->parse_uint32(this, rule_number, output + rule->offset) != SUCCESS)
+ if (parse_uint32(this, rule_number, output + rule->offset) != SUCCESS)
{
pld->destroy(pld);
return PARSE_ERROR;
}
case SPI_SIZE:
{
- if (this->parse_uint8(this, rule_number, output + rule->offset) != SUCCESS)
+ if (parse_uint8(this, rule_number, output + rule->offset) != SUCCESS)
{
pld->destroy(pld);
return PARSE_ERROR;
}
case SPI:
{
- if (this->parse_chunk(this, rule_number, output + rule->offset, spi_size) != SUCCESS)
+ if (parse_chunk(this, rule_number, output + rule->offset, spi_size) != SUCCESS)
{
pld->destroy(pld);
return PARSE_ERROR;
case PROPOSALS:
{
if (payload_length < SA_PAYLOAD_HEADER_LENGTH ||
- this->parse_list(this, rule_number, output + rule->offset, PROPOSAL_SUBSTRUCTURE,
+ parse_list(this, rule_number, output + rule->offset, PROPOSAL_SUBSTRUCTURE,
payload_length - SA_PAYLOAD_HEADER_LENGTH) != SUCCESS)
{
pld->destroy(pld);
case TRANSFORMS:
{
if (payload_length < spi_size + PROPOSAL_SUBSTRUCTURE_HEADER_LENGTH ||
- this->parse_list(this, rule_number, output + rule->offset, TRANSFORM_SUBSTRUCTURE,
+ parse_list(this, rule_number, output + rule->offset, TRANSFORM_SUBSTRUCTURE,
payload_length - spi_size - PROPOSAL_SUBSTRUCTURE_HEADER_LENGTH) != SUCCESS)
{
pld->destroy(pld);
case TRANSFORM_ATTRIBUTES:
{
if (payload_length < TRANSFORM_SUBSTRUCTURE_HEADER_LENGTH ||
- this->parse_list(this, rule_number, output + rule->offset, TRANSFORM_ATTRIBUTE,
+ parse_list(this, rule_number, output + rule->offset, TRANSFORM_ATTRIBUTE,
payload_length - TRANSFORM_SUBSTRUCTURE_HEADER_LENGTH) != SUCCESS)
{
pld->destroy(pld);
case CONFIGURATION_ATTRIBUTES:
{
if (payload_length < CP_PAYLOAD_HEADER_LENGTH ||
- this->parse_list(this, rule_number, output + rule->offset, CONFIGURATION_ATTRIBUTE,
+ parse_list(this, rule_number, output + rule->offset, CONFIGURATION_ATTRIBUTE,
payload_length - CP_PAYLOAD_HEADER_LENGTH) != SUCCESS)
{
pld->destroy(pld);
}
case ATTRIBUTE_FORMAT:
{
- if (this->parse_bit(this, rule_number, output + rule->offset) != SUCCESS)
+ if (parse_bit(this, rule_number, output + rule->offset) != SUCCESS)
{
pld->destroy(pld);
return PARSE_ERROR;
}
case ATTRIBUTE_TYPE:
{
- if (this->parse_uint15(this, rule_number, output + rule->offset) != SUCCESS)
+ if (parse_uint15(this, rule_number, output + rule->offset) != SUCCESS)
{
pld->destroy(pld);
return PARSE_ERROR;
}
case CONFIGURATION_ATTRIBUTE_LENGTH:
{
- if (this->parse_uint16(this, rule_number, output + rule->offset) != SUCCESS)
+ if (parse_uint16(this, rule_number, output + rule->offset) != SUCCESS)
{
pld->destroy(pld);
return PARSE_ERROR;
}
case ATTRIBUTE_LENGTH_OR_VALUE:
{
- if (this->parse_uint16(this, rule_number, output + rule->offset) != SUCCESS)
+ if (parse_uint16(this, rule_number, output + rule->offset) != SUCCESS)
{
pld->destroy(pld);
return PARSE_ERROR;
{
if (attribute_format == FALSE)
{
- if (this->parse_chunk(this, rule_number, output + rule->offset, attribute_length) != SUCCESS)
+ if (parse_chunk(this, rule_number, output + rule->offset, attribute_length) != SUCCESS)
{
pld->destroy(pld);
return PARSE_ERROR;
case NONCE_DATA:
{
if (payload_length < NONCE_PAYLOAD_HEADER_LENGTH ||
- this->parse_chunk(this, rule_number, output + rule->offset,
+ parse_chunk(this, rule_number, output + rule->offset,
payload_length - NONCE_PAYLOAD_HEADER_LENGTH) != SUCCESS)
{
pld->destroy(pld);
case ID_DATA:
{
if (payload_length < ID_PAYLOAD_HEADER_LENGTH ||
- this->parse_chunk(this, rule_number, output + rule->offset,
+ parse_chunk(this, rule_number, output + rule->offset,
payload_length - ID_PAYLOAD_HEADER_LENGTH) != SUCCESS)
{
pld->destroy(pld);
case AUTH_DATA:
{
if (payload_length < AUTH_PAYLOAD_HEADER_LENGTH ||
- this->parse_chunk(this, rule_number, output + rule->offset,
+ parse_chunk(this, rule_number, output + rule->offset,
payload_length - AUTH_PAYLOAD_HEADER_LENGTH) != SUCCESS)
{
pld->destroy(pld);
case CERT_DATA:
{
if (payload_length < CERT_PAYLOAD_HEADER_LENGTH ||
- this->parse_chunk(this, rule_number, output + rule->offset,
+ parse_chunk(this, rule_number, output + rule->offset,
payload_length - CERT_PAYLOAD_HEADER_LENGTH) != SUCCESS)
{
pld->destroy(pld);
case CERTREQ_DATA:
{
if (payload_length < CERTREQ_PAYLOAD_HEADER_LENGTH ||
- this->parse_chunk(this, rule_number, output + rule->offset,
+ parse_chunk(this, rule_number, output + rule->offset,
payload_length - CERTREQ_PAYLOAD_HEADER_LENGTH) != SUCCESS)
{
pld->destroy(pld);
case EAP_DATA:
{
if (payload_length < EAP_PAYLOAD_HEADER_LENGTH ||
- this->parse_chunk(this, rule_number, output + rule->offset,
+ parse_chunk(this, rule_number, output + rule->offset,
payload_length - EAP_PAYLOAD_HEADER_LENGTH) != SUCCESS)
{
pld->destroy(pld);
case SPIS:
{
if (payload_length < DELETE_PAYLOAD_HEADER_LENGTH ||
- this->parse_chunk(this, rule_number, output + rule->offset,
+ parse_chunk(this, rule_number, output + rule->offset,
payload_length - DELETE_PAYLOAD_HEADER_LENGTH) != SUCCESS)
{
pld->destroy(pld);
case VID_DATA:
{
if (payload_length < VENDOR_ID_PAYLOAD_HEADER_LENGTH ||
- this->parse_chunk(this, rule_number, output + rule->offset,
+ parse_chunk(this, rule_number, output + rule->offset,
payload_length - VENDOR_ID_PAYLOAD_HEADER_LENGTH) != SUCCESS)
{
pld->destroy(pld);
case CONFIGURATION_ATTRIBUTE_VALUE:
{
size_t data_length = attribute_length;
- if (this->parse_chunk(this, rule_number, output + rule->offset, data_length) != SUCCESS)
+ if (parse_chunk(this, rule_number, output + rule->offset, data_length) != SUCCESS)
{
pld->destroy(pld);
return PARSE_ERROR;
case KEY_EXCHANGE_DATA:
{
if (payload_length < KE_PAYLOAD_HEADER_LENGTH ||
- this->parse_chunk(this, rule_number, output + rule->offset,
+ parse_chunk(this, rule_number, output + rule->offset,
payload_length - KE_PAYLOAD_HEADER_LENGTH) != SUCCESS)
{
pld->destroy(pld);
case NOTIFICATION_DATA:
{
if (payload_length < NOTIFY_PAYLOAD_HEADER_LENGTH + spi_size ||
- this->parse_chunk(this, rule_number, output + rule->offset,
+ parse_chunk(this, rule_number, output + rule->offset,
payload_length - NOTIFY_PAYLOAD_HEADER_LENGTH - spi_size) != SUCCESS)
{
pld->destroy(pld);
case ENCRYPTED_DATA:
{
if (payload_length < ENCRYPTION_PAYLOAD_HEADER_LENGTH ||
- this->parse_chunk(this, rule_number, output + rule->offset,
+ parse_chunk(this, rule_number, output + rule->offset,
payload_length - ENCRYPTION_PAYLOAD_HEADER_LENGTH) != SUCCESS)
{
pld->destroy(pld);
}
case TS_TYPE:
{
- if (this->parse_uint8(this, rule_number, output + rule->offset) != SUCCESS)
+ if (parse_uint8(this, rule_number, output + rule->offset) != SUCCESS)
{
pld->destroy(pld);
return PARSE_ERROR;
case ADDRESS:
{
size_t address_length = (ts_type == TS_IPV4_ADDR_RANGE) ? 4 : 16;
- if (this->parse_chunk(this, rule_number, output + rule->offset,address_length) != SUCCESS)
+ if (parse_chunk(this, rule_number, output + rule->offset,address_length) != SUCCESS)
{
pld->destroy(pld);
return PARSE_ERROR;
case TRAFFIC_SELECTORS:
{
if (payload_length < TS_PAYLOAD_HEADER_LENGTH ||
- this->parse_list(this, rule_number, output + rule->offset, TRAFFIC_SELECTOR_SUBSTRUCTURE,
+ parse_list(this, rule_number, output + rule->offset, TRAFFIC_SELECTOR_SUBSTRUCTURE,
payload_length - TS_PAYLOAD_HEADER_LENGTH) != SUCCESS)
{
pld->destroy(pld);
case UNKNOWN_DATA:
{
if (payload_length < UNKNOWN_PAYLOAD_HEADER_LENGTH ||
- this->parse_chunk(this, rule_number, output + rule->offset,
+ parse_chunk(this, rule_number, output + rule->offset,
payload_length - UNKNOWN_PAYLOAD_HEADER_LENGTH) != SUCCESS)
{
pld->destroy(pld);
this->public.get_remaining_byte_count = (int (*) (parser_t *))get_remaining_byte_count;
this->public.destroy = (void(*)(parser_t*)) destroy;
- this->parse_uint4 = parse_uint4;
- this->parse_uint8 = parse_uint8;
- this->parse_uint15 = parse_uint15;
- this->parse_uint16 = parse_uint16;
- this->parse_uint32 = parse_uint32;
- this->parse_uint64 = parse_uint64;
- this->parse_bytes = parse_bytes;
- this->parse_bit = parse_bit;
- this->parse_list = parse_list;
- this->parse_chunk = parse_chunk;
-
this->input = data.ptr;
this->byte_pos = data.ptr;
this->bit_pos = 0;