Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
cmake_minimum_required(VERSION 3.10)


project(apx LANGUAGES C VERSION 0.3.1)
project(apx LANGUAGES C VERSION 0.3.2)

set(apx_ALPHA_BETA_VERSION "")


set(ADT_RBFH_ENABLE ON CACHE BOOL "This must always be enabled in c-apx" FORCE)

Expand All @@ -10,7 +13,6 @@ include(adt/cmake/LeakCheck.cmake)
include(adt/cmake/UnitTest.cmake)
include(cmake/SetEnv.cmake)

option(apx_ALPHA_BUILD "Is this an alpha build?" OFF)
option(BUILD_DEFAULT_SERVER "Build default APX server?" ON)
option(APX_DEBUG "Enable debug-level printouts?" OFF)

Expand All @@ -24,12 +26,6 @@ else()
set(BUILD_SHARED_LIB_DEFAULT ON)
endif()

if (apx_ALPHA_BUILD)
set (apx_ALPHA_BUILD_STR "a")
else()
set (apx_ALPHA_BUILD_STR "")
endif()

option(BUILD_SHARED_LIBS "Build ${PROJECT_NAME} as a shared library." ${BUILD_SHARED_LIB_DEFAULT})

if(BUILD_SHARED_LIBS)
Expand Down
9 changes: 5 additions & 4 deletions app/apx_server/src/server_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,18 @@ int main(int argc, char **argv)
apx_error_t result;
dtl_hv_t *server_config = (dtl_hv_t*) 0;

m_shutdownTimer = SHUTDOWN_TIMER_INIT;
m_shutdownTimer = SHUTDOWN_TIMER_INIT;
m_runFlag = 1;

if (argc < 2u)
if ((argc < 2u) || (argv[1] == NULL))
{
printUsage(argv[0]);
return 0;
}
const char* config_path = argv[1];
printf("APX Server %s\n\n", SW_VERSION_STR);
result = load_config_file(argv[1], &server_config);
printf("Loading %s: ", argv[1]);
result = load_config_file(config_path, &server_config);
printf("Loading %s: ", config_path);
if (result != APX_NO_ERROR)
{
printf("Error %d\n", (int) result);
Expand Down
4 changes: 2 additions & 2 deletions apx/include/apx/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ typedef struct apx_vm_decoder_tag
apx_rangeCheckInt32OperationInfo_t range_check_int32_info;
apx_rangeCheckInt64OperationInfo_t range_check_int64_info;
adt_str_t field_name;
bool is_last_field;
bool is_first_field;
} apx_vm_decoder_t;

//////////////////////////////////////////////////////////////////////////////
Expand All @@ -71,6 +71,6 @@ char const* apx_vm_decoder_get_field_name(apx_vm_decoder_t* self);
void apx_vm_decoder_save_program_position(apx_vm_decoder_t* self);
void apx_vm_decoder_recall_program_position(apx_vm_decoder_t* self);
bool apx_vm_decoder_has_saved_program_position(apx_vm_decoder_t* self);
bool apx_vm_decoder_is_last_field(apx_vm_decoder_t* self);
bool apx_vm_decoder_is_first_field(apx_vm_decoder_t* self);

#endif //APX_VM_DECODER_H
4 changes: 2 additions & 2 deletions apx/include/apx/deserializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ typedef struct apx_vm_readState_tag
dtl_dv_type_id value_type; //describes which part of the value union is currently active
scalar_storage_type_t scalar_storage_type; //describes which part of the scalar_value union is currently active
apx_typeCode_t type_code;
bool is_last_field;
apx_sizeType_t dynamic_size_type;
apx_rangeCheckState_t range_check_state;
} apx_vm_readState_t;
Expand Down Expand Up @@ -131,7 +130,8 @@ apx_error_t apx_vm_deserializer_unpack_char8(apx_vm_deserializer_t* self, uint32
apx_error_t apx_vm_deserializer_unpack_bool(apx_vm_deserializer_t* self, uint32_t array_length, apx_sizeType_t dynamic_size_type);
apx_error_t apx_vm_deserializer_unpack_byte(apx_vm_deserializer_t* self, uint32_t array_length, apx_sizeType_t dynamic_size_type);
apx_error_t apx_vm_deserializer_unpack_record(apx_vm_deserializer_t* self, uint32_t array_length, apx_sizeType_t dynamic_size_type);
apx_error_t apx_vm_deserializer_record_select(apx_vm_deserializer_t* self, char const* key, bool is_last_field);
apx_error_t apx_vm_deserializer_record_select(apx_vm_deserializer_t* self, char const* key, bool const is_first_field);
apx_error_t apx_vm_deserializer_record_end(apx_vm_deserializer_t* self);
apx_error_t apx_vm_deserializer_check_value_range_int32(apx_vm_deserializer_t* self, int32_t lower_limit, int32_t upper_limit);
apx_error_t apx_vm_deserializer_check_value_range_uint32(apx_vm_deserializer_t* self, uint32_t lower_limit, uint32_t upper_limit);
apx_error_t apx_vm_deserializer_check_value_range_int64(apx_vm_deserializer_t* self, int64_t lower_limit, int64_t upper_limit);
Expand Down
3 changes: 2 additions & 1 deletion apx/include/apx/program.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ typedef struct apx_programHeader_tag
apx_error_t apx_program_encode_header(apx_program_t *program, apx_programType_t program_type, uint32_t element_size, uint32_t queue_size, bool is_dynamic);
apx_error_t apx_program_decode_header(uint8_t const* begin, uint8_t const* end, uint8_t const** next, apx_programHeader_t *header);
uint8_t apx_program_encode_instruction(uint8_t opcode, uint8_t variant, bool flag);
void apx_program_decode_instruction(uint8_t instruction, uint8_t* opcode, uint8_t* variant, bool* flag);
void apx_program_decode_instruction(uint8_t const instruction, uint8_t* opcode, uint8_t* variant, bool* flag);
void apx_program_dump(apx_program_t const* program);

#define APX_PROGRAM_CREATE(p) adt_bytearray_create(p, APX_PROGRAM_GROW_SIZE)
#define APX_PROGRAM_NEW() adt_bytearray_new(APX_PROGRAM_GROW_SIZE)
Expand Down
4 changes: 2 additions & 2 deletions apx/include/apx/serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ typedef struct apx_vm_writeState_tag
dtl_dv_type_id value_type; //describes which part of the value union is currently active
scalar_storage_type_t scalar_storage_type; //describes which part of the scalar_value union is currently active
apx_typeCode_t type_code;
bool is_last_field;
apx_sizeType_t dynamic_size_type;
apx_rangeCheckState_t range_check_state;
} apx_vm_writeState_t;
Expand Down Expand Up @@ -140,7 +139,8 @@ apx_error_t apx_vm_serializer_pack_char8(apx_vm_serializer_t* self, uint32_t arr
apx_error_t apx_vm_serializer_pack_bool(apx_vm_serializer_t* self, uint32_t array_length, apx_sizeType_t dynamic_size_type);
apx_error_t apx_vm_serializer_pack_byte(apx_vm_serializer_t* self, uint32_t array_length, apx_sizeType_t dynamic_size_type);
apx_error_t apx_vm_serializer_pack_record(apx_vm_serializer_t* self, uint32_t array_length, apx_sizeType_t dynamic_size_type);
apx_error_t apx_vm_serializer_record_select(apx_vm_serializer_t* self, char const* key, bool is_last_field);
apx_error_t apx_vm_serializer_record_select(apx_vm_serializer_t* self, char const* key, bool const is_first_field);
apx_error_t apx_vm_serializer_record_end(apx_vm_serializer_t* self);
apx_error_t apx_vm_serializer_check_value_range_int32(apx_vm_serializer_t* self, int32_t lower_limit, int32_t upper_limit);
apx_error_t apx_vm_serializer_check_value_range_uint32(apx_vm_serializer_t* self, uint32_t lower_limit, uint32_t upper_limit);
apx_error_t apx_vm_serializer_check_value_range_int64(apx_vm_serializer_t* self, int64_t lower_limit, int64_t upper_limit);
Expand Down
56 changes: 30 additions & 26 deletions apx/include/apx/vm_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,14 @@
4: S8
5: S16
6: S32
7: S64
8: ARRAY
9: RECORD
10: BOOL
11: BYTE (immutable bytes object)
12: CHAR
8: BOOL
9: BYTE (immutable bytes object)
10: RECORD
11: ARRAY
12: ASCII_CHAR
13: CHAR8
14: CHAR16
15: CHAR32

2: DATA_SIZE : 6 variants
FLAG: is_dynamic_array(true, false)
Expand All @@ -130,19 +132,19 @@
10: ELEMENT_SIZE_U32_QUEUE_SIZE_U16
11: ELEMENT_SIZE_U32_QUEUE_SIZE_U32

3: DATA_CTRL : 9 variants
3: DATA_CTRL : 10 variants
0: RECORD_SELECT
1: LIMIT_CHECK_U8
2: LIMIT_CHECK_U16
3: LIMIT_CHECK_U32
4: LIMIT_CHECK_U64
5: LIMIT_CHECK_S8
6: LIMIT_CHECK_S16
7: LIMIT_CHECK_S32
8: LIMIT_CHECK_S64
FLAG(variant 0): When true: This is the last record field.
When false: More record fields to follow
FLAG (variant 1..8): When true, the limit check applies to non-scalar value (such as array of u8, u16 etc.)
1: RECORD_END
2: LIMIT_CHECK_U8
3: LIMIT_CHECK_U16
4: LIMIT_CHECK_U32
5: LIMIT_CHECK_U64
6: LIMIT_CHECK_S8
7: LIMIT_CHECK_S16
8: LIMIT_CHECK_S32
9: LIMIT_CHECK_S64
FLAG (variant 0): When true, this is the first field of the record.
FLAG (variants 1..9): When true, the limit check applies to non-scalar value (such as array of u8, u16 etc.)
4: FLOW_CTRL : 1 variant
0: ARRAY_NEXT
5: UNPACK2 (reserved for 16 additional data types)
Expand Down Expand Up @@ -204,12 +206,13 @@
#define APX_VM_OPCODE_DATA_CTRL ((uint8_t) 3u)
#define APX_VM_VARIANT_RECORD_SELECT ((uint8_t) 0u)
#define APX_VM_VARIANT_LIMIT_CHECK_NONE ((uint8_t) 0u) //Overlays with APX_VM_VARIANT_RECORD_SELECT (context-specific)
#define APX_VM_VARIANT_LIMIT_CHECK_U8 ((uint8_t) 1u)
#define APX_VM_VARIANT_LIMIT_CHECK_U16 ((uint8_t) 2u)
#define APX_VM_VARIANT_LIMIT_CHECK_U32 ((uint8_t) 3u)
#define APX_VM_VARIANT_LIMIT_CHECK_U64 ((uint8_t) 4u)
#define APX_VM_VARIANT_LIMIT_CHECK_S8 ((uint8_t) 5u)
#define APX_VM_VARIANT_LIMIT_CHECK_S16 ((uint8_t) 6u)
#define APX_VM_VARIANT_RECORD_END ((uint8_t) 1u)
#define APX_VM_VARIANT_LIMIT_CHECK_U8 ((uint8_t) 2u)
#define APX_VM_VARIANT_LIMIT_CHECK_U16 ((uint8_t) 3u)
#define APX_VM_VARIANT_LIMIT_CHECK_U32 ((uint8_t) 4u)
#define APX_VM_VARIANT_LIMIT_CHECK_U64 ((uint8_t) 5u)
#define APX_VM_VARIANT_LIMIT_CHECK_S8 ((uint8_t) 6u)
#define APX_VM_VARIANT_LIMIT_CHECK_S16 ((uint8_t) 7u)
#define APX_VM_VARIANT_LIMIT_CHECK_S32 ((uint8_t) 8u)
#define APX_VM_VARIANT_LIMIT_CHECK_S64 ((uint8_t) 9u)
#define APX_VM_VARIANT_LIMIT_CHECK_LAST APX_VM_VARIANT_LIMIT_CHECK_S64
Expand All @@ -228,7 +231,7 @@
#define APX_VM_INST_FLAG 0x80
#define APX_VM_ARRAY_FLAG APX_VM_INST_FLAG
#define APX_VM_DYN_ARRAY_FLAG APX_VM_INST_FLAG
#define APX_VM_LAST_FIELD_FLAG APX_VM_INST_FLAG
#define APX_VM_FIRST_FIELD_FLAG APX_VM_INST_FLAG

#define APX_VM_UINT8_SIZE ((uint32_t) sizeof(uint8_t))
#define APX_VM_CHAR_SIZE ((uint32_t) sizeof(char))
Expand All @@ -254,7 +257,8 @@ typedef uint8_t apx_operationType_t;
#define APX_OPERATION_TYPE_RANGE_CHECK_INT64 ((apx_operationType_t) 5u)
#define APX_OPERATION_TYPE_RANGE_CHECK_UINT64 ((apx_operationType_t) 6u)
#define APX_OPERATION_TYPE_RECORD_SELECT ((apx_operationType_t) 7u)
#define APX_OPERATION_TYPE_ARRAY_NEXT ((apx_operationType_t) 8u)
#define APX_OPERATION_TYPE_RECORD_END ((apx_operationType_t) 8u)
#define APX_OPERATION_TYPE_ARRAY_NEXT ((apx_operationType_t) 9u)

typedef struct apx_packUnpackOperationInfo_tag
{
Expand Down
24 changes: 19 additions & 5 deletions apx/src/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ static apx_error_t compile_limit_values_int64(apx_compiler_t* self, uint8_t limi
static apx_error_t compile_limit_values_uint64(apx_compiler_t* self, uint8_t limit_variant, uint64_t lower_limit, uint64_t upper_limit);
static apx_error_t compile_array_size_instruction(apx_compiler_t* self, uint32_t array_size, bool is_dynamic_array);
static apx_error_t compile_record_fields(apx_compiler_t* self, apx_dataElement_t const* data_element, apx_programType_t program_type, uint32_t* record_size);
static apx_error_t compile_record_select_instruction(apx_compiler_t* self, apx_dataElement_t const* data_element, bool is_last_field);
static apx_error_t compile_record_select_instruction(apx_compiler_t* self, apx_dataElement_t const* data_element, bool const is_first_field);
static apx_error_t compile_record_end_instruction(apx_compiler_t* self);
static apx_error_t compile_array_next_instruction(apx_compiler_t* self);


Expand Down Expand Up @@ -647,13 +648,13 @@ static apx_error_t compile_record_fields(apx_compiler_t* self, apx_dataElement_t
{
return APX_EMPTY_RECORD_ERROR;
}
apx_error_t result = APX_NO_ERROR;
for (i = 0u; i < num_children; i++)
{
apx_error_t result = APX_NO_ERROR;
uint32_t child_size = 0u;
apx_dataElement_t const* child_element = apx_dataElement_get_child_at(data_element, i);
assert(child_element != NULL);
result = compile_record_select_instruction(self, child_element, (i == (num_children - 1)) ? true : false);
result = compile_record_select_instruction(self, child_element, (i==0u) ? true : false);
if (result != APX_NO_ERROR)
{
return result;
Expand All @@ -676,10 +677,15 @@ static apx_error_t compile_record_fields(apx_compiler_t* self, apx_dataElement_t
}
*record_size += child_size;
}
result = compile_record_end_instruction(self);
if (result != APX_NO_ERROR)
{
return result;
}
return APX_NO_ERROR;
}

static apx_error_t compile_record_select_instruction(apx_compiler_t* self, apx_dataElement_t const* data_element, bool is_last_field)
static apx_error_t compile_record_select_instruction(apx_compiler_t* self, apx_dataElement_t const* data_element, bool const is_first_field)
{
assert((self != NULL) && (data_element != NULL));
char const* name = apx_dataElement_get_name(data_element);
Expand All @@ -698,7 +704,7 @@ static apx_error_t compile_record_select_instruction(apx_compiler_t* self, apx_d
{
return APX_NAME_TOO_LONG_ERROR;
}
uint8_t const instruction = apx_program_encode_instruction(APX_VM_OPCODE_DATA_CTRL, APX_VM_VARIANT_RECORD_SELECT, is_last_field);
uint8_t const instruction = apx_program_encode_instruction(APX_VM_OPCODE_DATA_CTRL, APX_VM_VARIANT_RECORD_SELECT, is_first_field);
rc = adt_bytearray_push(self->program, instruction);
if (rc == ADT_NO_ERROR)
{
Expand All @@ -711,6 +717,14 @@ static apx_error_t compile_record_select_instruction(apx_compiler_t* self, apx_d
return convert_from_adt_to_apx_error(rc);
}

static apx_error_t compile_record_end_instruction(apx_compiler_t* self)
{
assert(self != NULL);
uint8_t const instruction = apx_program_encode_instruction(APX_VM_OPCODE_DATA_CTRL, APX_VM_VARIANT_RECORD_END, false);
adt_error_t rc = adt_bytearray_push(self->program, instruction);
return convert_from_adt_to_apx_error(rc);
}

static apx_error_t compile_array_next_instruction(apx_compiler_t* self)
{
assert(self != NULL);
Expand Down
25 changes: 19 additions & 6 deletions apx/src/decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ static apx_error_t decode_range_check_uint32(apx_vm_decoder_t* self, uint8_t var
static apx_error_t decode_range_check_uint64(apx_vm_decoder_t* self, uint8_t variant);
static apx_error_t decode_range_check_int32(apx_vm_decoder_t* self, uint8_t variant);
static apx_error_t decode_range_check_int64(apx_vm_decoder_t* self, uint8_t variant);
static apx_error_t decode_record_select(apx_vm_decoder_t* self, bool is_last_field);
static apx_error_t decode_record_select(apx_vm_decoder_t* self, bool is_first_field);
static apx_error_t decode_record_end(apx_vm_decoder_t* self);

//////////////////////////////////////////////////////////////////////////////
// PUBLIC FUNCTIONS
Expand All @@ -76,7 +77,7 @@ void apx_vm_decoder_create(apx_vm_decoder_t* self)
self->range_check_int64_info.lower_limit = 0;
self->range_check_int64_info.upper_limit = 0;
adt_str_create(&self->field_name);
self->is_last_field = false;
self->is_first_field = false;
}
}

Expand Down Expand Up @@ -218,11 +219,11 @@ bool apx_vm_decoder_has_saved_program_position(apx_vm_decoder_t* self)
return false;
}

bool apx_vm_decoder_is_last_field(apx_vm_decoder_t* self)
bool apx_vm_decoder_is_first_field(apx_vm_decoder_t* self)
{
if (self != NULL)
{
return self->is_last_field;
return self->is_first_field;
}
return false;
}
Expand Down Expand Up @@ -260,6 +261,10 @@ static apx_error_t decode_next_instruction_internal(apx_vm_decoder_t* self)
{
return decode_record_select(self, flag);
}
else if (variant == APX_VM_VARIANT_RECORD_END)
{
return decode_record_end(self);
}
else if (variant <= APX_VM_VARIANT_LIMIT_CHECK_LAST)
{
switch (variant)
Expand Down Expand Up @@ -490,7 +495,7 @@ static apx_error_t decode_range_check_int64(apx_vm_decoder_t* self, uint8_t vari
return APX_UNEXPECTED_END_ERROR;
}

static apx_error_t decode_record_select(apx_vm_decoder_t* self, bool is_last_field)
static apx_error_t decode_record_select(apx_vm_decoder_t* self, bool is_first_field)
{
assert(self != NULL);
self->operation_type = APX_OPERATION_TYPE_RECORD_SELECT;
Expand All @@ -499,8 +504,16 @@ static apx_error_t decode_record_select(apx_vm_decoder_t* self, bool is_last_fie
{
adt_str_set_bstr(&self->field_name, self->program_next, result);
self->program_next = result + UINT8_SIZE; //Skip past null-terminator
self->is_last_field = is_last_field;
self->is_first_field = is_first_field;
return APX_NO_ERROR;
}
return APX_INVALID_INSTRUCTION_ERROR;
}

static apx_error_t decode_record_end(apx_vm_decoder_t* self)
{
assert(self != NULL);
self->operation_type = APX_OPERATION_TYPE_RECORD_END;
return APX_NO_ERROR;
}

Loading
Loading