UniRec
2.9.3
|
Macros | |
#define | ur_template_string(tmplt) ur_template_string_delimiter(tmplt, ',') |
Get string of a template Get names and sizes of fields separated by comma. Return string has to be freed by user. More... | |
#define | ur_size_of(type) ur_field_type_size[type] |
Get size of UniRec type Get size of fixed-length UniRec type. For variable-length type return value < 0. More... | |
#define | ur_get_name(field_id) ur_field_specs.ur_field_names[field_id] |
Get name of UniRec field Get name of any UniRec defined field. More... | |
#define | ur_get_type(field_id) ur_field_specs.ur_field_types[field_id] |
Get type of UniRec field Get type of any UniRec defined field. More... | |
#define | ur_get_size(field_id) ur_field_specs.ur_field_sizes[field_id] |
Get size of UniRec field Get size of a fixed-length UniRec field. When variable-length field is passed, return value < 0. To get real length of a variable-length field use ur_get_var_len. More... | |
#define | ur_get(tmplt, data, field_id) (*(field_id ## _T*)((char *)(data) + (tmplt)->offset[field_id])) |
Get value of UniRec field Get value of a fixed-length UniRec field. For variable-length fields, use ur_get_ptr or ur_get_ptr_by_id. More... | |
#define | ur_get_ptr(tmplt, data, field_id) |
Get pointer to UniRec field Get pointer to fixed or varible length statically defined UniRec field. For dynamically defined fields, use ur_get_ptr_by_id. More... | |
#define | ur_get_ptr_by_id(tmplt, data, field_id) |
Get pointer to UniRec field Get pointer to fixed or varible length UniRec field. In contrast to ur_get_ptr, field_id may be a variable (not only F_ token). Returned pointer is always void *. More... | |
#define | ur_set(tmplt, data, field_id, value) (*(field_id ## _T*)((char *)(data) + (tmplt)->offset[field_id]) = (value)) |
Set value of UniRec (static) field Set value of a fixed-length UniRec field. For variable-length fields, use ur_set_var. More... | |
#define | ur_get_var_offset(tmplt, rec, field_id) *((uint16_t *)((char *) rec + tmplt->offset[field_id])) |
Get offset of variable-length field in the record. Get offset of a specified variable-length field in the record. Given field has to be part of the record. More... | |
#define | ur_get_var_len(tmplt, rec, field_id) *((uint16_t *)((char *) rec + tmplt->offset[field_id] + 2)) |
Get size of a variable sized field in the record. Get size of a variable-length field in the record. Given field has to be part of the record. More... | |
#define | ur_set_var_len(tmplt, rec, field_id, len) *((uint16_t *)((char *) rec + tmplt->offset[field_id] + 2)) = (uint16_t) len |
Set size of variable-length field in the record. Set size of specified variable-length field in the record. Field has to be part of the record. It does not move other variable sized records. It just sets given value to the right position in the record. More... | |
#define | ur_set_var_offset(tmplt, rec, field_id, offset_val) *((uint16_t *)((char *) rec + tmplt->offset[field_id])) = (uint16_t) offset_val |
Set offset of variable-length field in the record. Set offset of specified variable-length field in the record. Field has to be part of the record. It does not move other variable sized records. It just sets given value to the right position in the record. More... | |
#define | ur_get_len(tmplt, rec, field) ur_is_static(field) ? ur_get_size(field) : ur_get_var_len(tmplt, rec, field) |
Get length of UniRec field Get actual length of fixed or variable-length UniRec field. More... | |
#define | ur_set_string(tmplt, rec, field_id, str) ur_set_var(tmplt, rec, field_id, str, strlen(str)) |
Set variable-length field to given string. Set contents of a variable-length field in the record. Field has to be part of the record. It copies string terminated with \0 and safely moves other variable-length records. More... | |
#define | ur_is_array(field_id) (ur_field_type_size[ur_get_type(field_id)] < 0 ? 1 : 0) |
#define | ur_array_get_elem_size(field_id) (ur_field_type_size[ur_get_type(field_id)] < 0 ? -ur_field_type_size[ur_get_type(field_id)] : ur_field_type_size[ur_get_type(field_id)]) |
Get size of a single element of UniRec field. More... | |
#define | ur_array_get_elem_cnt(tmplt, rec, field_id) (ur_get_var_len(tmplt, rec, field_id) / ur_array_get_elem_size(field_id)) |
Get number of elements stored in an UniRec array. More... | |
#define | ur_array_get_elem_type(field_id) ur_field_array_elem_type[ur_get_type(field_id)] |
Get type of an element stored in an UniRec array. More... | |
#define | ur_array_set(tmplt, rec, field_id, index, element) |
Set element to array at given index. Automatically resizes array when index is out of array bounds. Set contents of a variable-length field in the record. Field has to be part of the record. More... | |
#define | ur_array_append(tmplt, rec, field_id, element) |
Set element to array at last position. Automatically resizes array. More... | |
#define | ur_array_clear(tmplt, rec, field_id) ur_array_resize(tmplt, rec, field_id, 0) |
Clear contents of an UniRec array. Array is resized to 0 elements. More... | |
#define | ur_array_get(tmplt, rec, field_id, index) ((field_id ## _T)((char *)(ur_get_ptr_by_id(tmplt, rec, field_id))))[index] |
Get element of an array field at given index. More... | |
#define | ur_array_allocate(tmplt, rec, field_id, elem_cnt) ur_array_resize(tmplt, rec, field_id, (elem_cnt) * ur_array_get_elem_size(field_id)) |
Preallocates UniRec array field to have requested number of elements. More... | |
#define | ur_is_present(tmplt, field_id) ((tmplt)->offset_size > (field_id) && (tmplt)->offset[(field_id)] != UR_INVALID_OFFSET) |
Is given field present in given template? Return true (non-zero value) if given template contains field with given ID. More... | |
#define | ur_is_varlen(field_id) (ur_field_specs.ur_field_sizes[field_id] < 0) |
Is given field variable-length? Return true (non-zero value) if given ID refers to a field with variable length. More... | |
#define | ur_is_dynamic(field_id) ur_is_varlen(field_id) |
Alias for ur_is_varlen (for backwards compatibility only) More... | |
#define | ur_is_fixlen(field_id) (ur_field_specs.ur_field_sizes[field_id] >= 0) |
Is given field fixed-length? Return true (non-zero value) if given ID refers to a field with fixed length. More... | |
#define | ur_is_static(field_id) ur_is_fixlen(field_id) |
Alias for ur_is_fixlen (for backwards compatibility only) More... | |
#define | ur_rec_fixlen_size(tmplt) ((tmplt)->static_size) |
Get size of fixed-length part of UniRec record Get total size of UniRec record except variable-length fields. More... | |
#define | ur_rec_size(tmplt, rec) (ur_rec_fixlen_size(tmplt) + ur_rec_varlen_size(tmplt, rec)) |
Get size of UniRec record (static and variable length) Get total size of whole UniRec record. More... | |
#define | ur_create_input_template(ifc, fields, errstr) ur_ctx_create_input_template(trap_get_global_ctx(), ifc, fields, errstr); |
Create UniRec template and set it to input interface Creates UniRec template (same like ur_create_template) and set this template to input interface of a module. More... | |
#define | ur_create_output_template(ifc, fields, errstr) ur_ctx_create_output_template(trap_get_global_ctx(), ifc, fields, errstr); |
Create UniRec template and set it to output interface Creates UniRec template (same like ur_create_template) and set this template to ouput interface of a module. More... | |
#define | ur_set_output_template(ifc, tmplt) ur_ctx_set_output_template(trap_get_global_ctx(), ifc, tmplt) |
Set UniRec template to ouput interface. More... | |
#define | ur_set_input_template(ifc, tmplt) ur_ctx_set_input_template(trap_get_global_ctx(), ifc, tmplt) |
Set UniRec template to input interface. More... | |
#define | ur_create_bidirectional_template(ifc_in, ifc_out, fields, errstr) ur_ctx_create_bidirectional_template(trap_get_global_ctx(), ifc_in, ifc_out, fields, errstr); |
Create UniRec template and set it to input and output interface Creates UniRec template (same like ur_create_template) and set this template to input and ouput interface of a module. More... | |
#define | UR_MAX_SIZE 0xffff |
#define | ur_cpy(tmplt, src, dst) (memcpy(dst,src,ur_rec_size(tmplt,src))) |
Copy data from one UniRec to another. Procedure gets template and void pointer of source and destination. Then it copies the data defined by the given template. The destination pointer must have required space allocated. More... | |
#define | ur_values_get_name(field, value) ur_values_get_name_start_end(UR_TYPE_START_ ## field, UR_TYPE_END_ ## field, value) |
Returns name of specified value This function returns name of specified value and field, which is defined in values file. More... | |
#define | ur_values_get_description(field, value) ur_values_get_description_start_end(UR_TYPE_START_ ## field, UR_TYPE_END_ ## field, value) |
Returns description of specified value This function returns description of specified value and field, which is defined in values file. More... | |
Functions | |
char * | ur_template_string_delimiter (const ur_template_t *tmplt, int delimiter) |
Get UniRec specifier of the tmplt template with delimiter between fields. More... | |
int | ur_get_field_type_from_str (const char *type) |
char * | ur_array_append_get_ptr (const ur_template_t *tmplt, void *rec, int field_id) |
Allocate new element at the end of array and return its pointer. More... | |
int | ur_init (ur_static_field_specs_t field_specs_static) |
Initialize UniRec structures Initialize UniRec structures. Function is called during defining first own field. More... | |
int | ur_get_empty_id () |
Return first empty id for new UniRec field Return first empty id for new UniRec field. If there is no space in the UniRec structures, it will increase space in the existing structures. More... | |
int | ur_define_field (const char *name, ur_field_type_t type) |
Define new UniRec field Define new UniRec field at run-time. It adds new field into existing structures. If the field already exists (name and type are equal) it only returns its ID. More... | |
int | ur_define_set_of_fields (const char *ifc_data_fmt) |
Define set of new UniRec fields Define new UniRec fields at run-time. It adds new fields into existing structures. If the field already exists and type is equal nothing will happen. If the type is not equal an error will be returned. Example ifc_data_fmt: "uint32 FOO,uint8 BAR,float FOO2". More... | |
int | ur_undefine_field_by_id (ur_field_id_t field_id) |
Undefine UniRec field by its id Undefine UniRec field created at run-time. It erases given field from UniRec structures and the field ID can be used for another field. By undefining field, all templates which were using the undefined field, has to be recreated. More... | |
int | ur_undefine_field (const char *name) |
Undefine UniRec field by its name Undefine UniRec field created at run-time. It erases given field from UniRec structures and the field ID can be used for another field. By undefining field, all templates which were using the undefined field, has to be recreated. More... | |
void | ur_finalize () |
Deallocate UniRec structures Deallocate UniRec structures at the end of a program. This function SHOULD be called after all UniRec functions and macros invocations, typically during a cleanup phase before the program's end. This function has to be called if some fields are defined during run-time, otherwise this function is needless. More... | |
int | ur_get_id_by_name (const char *name) |
Get ID of a field by its name Get ID of a field by its name. More... | |
int | compare_fields (const void *field1, const void *field2) |
Compare fields Compare two fields. This function is for sorting the fields in the right order. First by sizes (larger first) and then by names. More... | |
ur_template_t * | ur_create_template (const char *fields, char **errstr) |
Create UniRec template Create new UniRec template specified by a string containing names of its fields separated by commas. Example spec-string: "SRC_IP,DST_IP,SRC_PORT,DST_PORT,PROTOCOL,PACKETS" Order of fields is not important (templates with the same set of fields are equivalent). Template created by this function should be destroyed by ur_free_template. More... | |
ur_template_t * | ur_ctx_create_output_template (trap_ctx_t *ctx, int ifc, const char *fields, char **errstr) |
Create UniRec template and set it to output interface on specified context Creates UniRec template, same like ur_create_output_template, but context is specified. More... | |
ur_template_t * | ur_ctx_create_input_template (trap_ctx_t *ctx, int ifc, const char *fields, char **errstr) |
Create UniRec template and set it to input interface on specified context Creates UniRec template, same like ur_create_input_template, but context is specified. More... | |
int | ur_ctx_set_output_template (trap_ctx_t *ctx, int ifc, ur_template_t *tmplt) |
Set UniRec template to ouput interface on specified context. More... | |
int | ur_ctx_set_input_template (trap_ctx_t *ctx, int ifc, ur_template_t *tmplt) |
Set UniRec template to input interface on specified context. More... | |
ur_template_t * | ur_ctx_create_bidirectional_template (trap_ctx_t *ctx, int ifc_in, int ifc_out, const char *fields, char **errstr) |
Create UniRec template and set it to input and output interface on specified context Creates UniRec template, same like ur_create_bidirectional_template, but context is specified. More... | |
ur_template_t * | ur_expand_template (const char *ifc_data_fmt, ur_template_t *tmplt) |
Expand UniRec template Expand existing UniRec template by a string containing types and names of its fields separated by commas. Example ifc_data_fmt: "uint32 FOO,uint8 BAR,float FOO2" Order of fields is not important (templates with the same set of fields are equivalent). In case of success the given template will be destroyed and new template will be returned. More... | |
ur_template_t * | ur_define_fields_and_update_template (const char *ifc_data_fmt, ur_template_t *tmplt) |
Defined new fields and expand an UniRec template Define new fields (function ur_define_set_of_fields) and create new UniRec template (function ur_create_template_from_ifc_spec). The string describing fields contain types and names of fields separated by commas. Example ifc_data_fmt: "uint32 FOO,uint8 BAR,float FOO2" Order of fields is not important (templates with the same set of fields are equivalent). In case of success the given template will be destroyed and new template will be returned. More... | |
ur_template_t * | ur_create_template_from_ifc_spec (const char *ifc_data_fmt) |
Create UniRec template from data format string. Creates new UniRec template (function ur_create_template_from_ifc_spec). The string describing fields contain types and names of fields separated by commas. Example ifc_data_fmt: "uint32 FOO,uint8 BAR,float FOO2" Order of fields is not important (templates with the same set of fields are equivalent).. More... | |
void | ur_free_template (ur_template_t *tmplt) |
Destroy UniRec template Free all memory allocated for a template created previously by ur_create_template. More... | |
int | ur_template_compare (const ur_template_t *tmpltA, const ur_template_t *tmpltB) |
Compares fields of two UniRec templates Function compares only sets of UniRec fields (direction is not compared). More... | |
void | ur_print_template (ur_template_t *tmplt) |
Print UniRec template Print static_size, first_dynamic and table of offsets to stdout (for debugging). If template does not contain any dynamic fields, print '-' instead. param[in] tmplt pointer to the template. More... | |
int | ur_set_var (const ur_template_t *tmplt, void *rec, int field_id, const void *val_ptr, int val_len) |
Set content of variable-length UniRec field Copy given data into variable-length UniRec field, set its offset and length in a record and move data which are behind this field. For better performance use function ur_clear_varlen, before setting all variable fields in record. More... | |
int | ur_array_resize (const ur_template_t *tmplt, void *rec, int field_id, int len) |
Change length of a array field. More... | |
void | ur_clear_varlen (const ur_template_t *tmplt, void *rec) |
Clear variable-length part of a record. For better performance of setting content to variable-length fields, use this function before setting of all the variable-length fields. This function will clear all the variable-length fields, so they don't have to be moved in memory during setting of them. More... | |
uint16_t | ur_rec_varlen_size (const ur_template_t *tmplt, const void *rec) |
Get size of variable sized part of UniRec record Get total size of all variable-length fields in an UniRec record. More... | |
void * | ur_create_record (const ur_template_t *tmplt, uint16_t max_var_size) |
void | ur_free_record (void *record) |
char * | ur_get_var_as_str (const ur_template_t *tmplt, const void *rec, ur_field_id_t field_id) |
Get variable-length UniRec field as a C string Copy data of a variable-length field from UniRec record and append '\0' character. The function allocates new memory space for the string, it must be freed using free()! More... | |
void | ur_copy_fields (const ur_template_t *dst_tmplt, void *dst, const ur_template_t *src_tmplt, const void *src) |
Copy data from one UniRec record to another. Copies all fields present in both templates from src to dst. The function compares src_tmplt and dst_tmplt and for each field present in both templates it sets the value of field in dst to a corresponding value in src. "dst" must point to a memory of enough size. More... | |
void * | ur_clone_record (const ur_template_t *tmplt, const void *src) |
Create new UniRec and copy the source UniRec into it. Function creates new UniRec record and fills it with the data given by parameter. More... | |
ur_iter_t | ur_iter_fields (const ur_template_t *tmplt, ur_iter_t id) |
Iterate over fields of a template in order of a record This function can be used to iterate over all fields of a given template. It returns ID of the next field present in the template after a given ID. If ID is set to UR_ITER_BEGIN, it returns the first fields. If no more fields are present, UR_ITER_END is returned. Example usage: ur_field_id_t id = UR_ITER_BEGIN while ((id = ur_iter_fields(&tmplt, id)) != UR_ITER_END) { ... } The order of fields is given by the order in which they are defined. More... | |
ur_iter_t | ur_iter_fields_record_order (const ur_template_t *tmplt, int index) |
Iterate over fields of a template This function can be used to iterate over all fields of a given template. It returns n-th ID of a record specified by index. If the return value is UR_ITER_END. The index is higher than count of fields in the template. Example usage: int i = 0; while ((id = ur_iter_fields(&tmplt, i++)) != UR_ITER_END) { ... } The order of fields is given by the order in the record. More... | |
int | ur_set_array_from_string (const ur_template_t *tmpl, void *data, ur_field_id_t f_id, const char *v) |
Set value of a UniRec array field. More... | |
int | ur_set_from_string (const ur_template_t *tmpl, void *data, ur_field_id_t f_id, const char *v) |
Set value of a UniRec field. More... | |
char * | ur_ifc_data_fmt_to_field_names (const char *ifc_data_fmt) |
Parses field names from data format Function parses field names from data format and returns pointer to new allocated string. Example: "type1 name1,type2 name2" => "name1,name2" New string has to be freed by user. More... | |
char * | ur_cpy_string (const char *str) |
Duplicates given string. Helper function which returns pointer to duplicated string. New string has to be freed by user. More... | |
const char * | ur_values_get_name_start_end (uint32_t start, uint32_t end, int32_t value) |
Returns name of specified value (Helper function) Helper function for ur_values_get_name. This function returns name of specified value and field, which is defined in values file. Function needs start and end index of a field. More... | |
const char * | ur_values_get_description_start_end (uint32_t start, uint32_t end, int32_t value) |
Returns description of specified value (Helper function) Helper function for ur_values_get_description. This function returns description of specified value and field, which is defined in values file. Function needs start and end index of a field. More... | |
Variables | |
const int | ur_field_type_size [] |
Sizes of UniRec data types. More... | |
const char * | ur_field_type_str [] |
UniRec data types. More... | |
int | ur_field_array_elem_type [] |
UniRec array element types. More... | |
ur_field_specs_t | ur_field_specs |
Structure that lists UniRec field specifications such as names, types, id. More... | |
ur_static_field_specs_t | UR_FIELD_SPECS_STATIC |
Structure that lists staticaly defined UniRec field specifications such as names, types, id (using UR_FIELDS()). More... | |
#define ur_array_allocate | ( | tmplt, | |
rec, | |||
field_id, | |||
elem_cnt | |||
) | ur_array_resize(tmplt, rec, field_id, (elem_cnt) * ur_array_get_elem_size(field_id)) |
Preallocates UniRec array field to have requested number of elements.
[in] | tmplt | Pointer to UniRec template |
[in] | rec | Pointer to the beginning of a record |
[in] | field_id | Identifier of a field. |
[in] | elem_cnt | Number of elements to be in resized array. |
#define ur_array_append | ( | tmplt, | |
rec, | |||
field_id, | |||
element | |||
) |
Set element to array at last position. Automatically resizes array.
[in] | tmplt | Pointer to UniRec template |
[in] | rec | Pointer to the beginning of a record |
[in] | field_id | Identifier of a field. |
[in] | element | Array element. |
#define ur_array_clear | ( | tmplt, | |
rec, | |||
field_id | |||
) | ur_array_resize(tmplt, rec, field_id, 0) |
Clear contents of an UniRec array. Array is resized to 0 elements.
[in] | tmplt | Pointer to UniRec template |
[in] | rec | Pointer to the beginning of a record |
[in] | field_id | Identifier of a field. |
#define ur_array_get | ( | tmplt, | |
rec, | |||
field_id, | |||
index | |||
) | ((field_id ## _T)((char *)(ur_get_ptr_by_id(tmplt, rec, field_id))))[index] |
Get element of an array field at given index.
[in] | tmplt | Pointer to UniRec template |
[in] | rec | Pointer to the beginning of a record |
[in] | field_id | Identifier of a field. |
[in] | index | Element index in array. |
[in] | element | Array element. |
#define ur_array_get_elem_cnt | ( | tmplt, | |
rec, | |||
field_id | |||
) | (ur_get_var_len(tmplt, rec, field_id) / ur_array_get_elem_size(field_id)) |
#define ur_array_get_elem_size | ( | field_id | ) | (ur_field_type_size[ur_get_type(field_id)] < 0 ? -ur_field_type_size[ur_get_type(field_id)] : ur_field_type_size[ur_get_type(field_id)]) |
#define ur_array_get_elem_type | ( | field_id | ) | ur_field_array_elem_type[ur_get_type(field_id)] |
#define ur_array_set | ( | tmplt, | |
rec, | |||
field_id, | |||
index, | |||
element | |||
) |
Set element to array at given index. Automatically resizes array when index is out of array bounds. Set contents of a variable-length field in the record. Field has to be part of the record.
[in] | tmplt | Pointer to UniRec template |
[in] | rec | Pointer to the beginning of a record |
[in] | field_id | Identifier of a field. |
[in] | index | Element index in array. |
[in] | element | Array element. |
#define ur_cpy | ( | tmplt, | |
src, | |||
dst | |||
) | (memcpy(dst,src,ur_rec_size(tmplt,src))) |
Copy data from one UniRec to another. Procedure gets template and void pointer of source and destination. Then it copies the data defined by the given template. The destination pointer must have required space allocated.
[in] | tmplt | Pointer to UniRec template |
[in] | src | Pointer to source data |
[out] | dst | Pointer to destination of copy |
#define ur_create_bidirectional_template | ( | ifc_in, | |
ifc_out, | |||
fields, | |||
errstr | |||
) | ur_ctx_create_bidirectional_template(trap_get_global_ctx(), ifc_in, ifc_out, fields, errstr); |
Create UniRec template and set it to input and output interface Creates UniRec template (same like ur_create_template) and set this template to input and ouput interface of a module.
[in] | ifc_in | input interface number |
[in] | ifc_out | output interface number |
[in] | fields | String with names of fields delimited by comma |
[in] | errstr | Pointer to char * string where the error message will be allocated and written in case of error. NULL if you don't need error message. In case of error, function will allocate string, which has to be freed by user. |
#define ur_create_input_template | ( | ifc, | |
fields, | |||
errstr | |||
) | ur_ctx_create_input_template(trap_get_global_ctx(), ifc, fields, errstr); |
Create UniRec template and set it to input interface Creates UniRec template (same like ur_create_template) and set this template to input interface of a module.
[in] | ifc | interface number |
[in] | fields | String with names of fields delimited by comma |
[in] | errstr | Pointer to char * string where the error message will be allocated and written in case of error. NULL if you don't need error message. In case of error, function will allocate string, which has to be freed by user. |
#define ur_create_output_template | ( | ifc, | |
fields, | |||
errstr | |||
) | ur_ctx_create_output_template(trap_get_global_ctx(), ifc, fields, errstr); |
Create UniRec template and set it to output interface Creates UniRec template (same like ur_create_template) and set this template to ouput interface of a module.
[in] | ifc | interface number |
[in] | fields | String with names of fields delimited by comma |
[in] | errstr | Pointer to char * string where the error message will be allocated and written in case of error. NULL if you don't need error message. In case of error, function will allocate string, which has to be freed by user. |
#define ur_get | ( | tmplt, | |
data, | |||
field_id | |||
) | (*(field_id ## _T*)((char *)(data) + (tmplt)->offset[field_id])) |
Get value of UniRec field Get value of a fixed-length UniRec field. For variable-length fields, use ur_get_ptr or ur_get_ptr_by_id.
[in] | tmplt | Pointer to UniRec template |
[in] | data | Pointer to the beginning of a record |
[in] | field_id | Identifier of a field. It must be a token beginning with F_, not a numeric ID (e.g. F_SRC_IP for source IP defined in UR_FIELDS as SRC_IP). |
#define ur_get_len | ( | tmplt, | |
rec, | |||
field | |||
) | ur_is_static(field) ? ur_get_size(field) : ur_get_var_len(tmplt, rec, field) |
Get length of UniRec field Get actual length of fixed or variable-length UniRec field.
[in] | tmplt | Pointer to UniRec template |
[in] | rec | Pointer to the beginning of a record |
[in] | field | Identifier of a field - e.g. F_SRC_IP for source IP defined in UR_FIELDS as SRC_IP. |
#define ur_get_name | ( | field_id | ) | ur_field_specs.ur_field_names[field_id] |
#define ur_get_ptr | ( | tmplt, | |
data, | |||
field_id | |||
) |
Get pointer to UniRec field Get pointer to fixed or varible length statically defined UniRec field. For dynamically defined fields, use ur_get_ptr_by_id.
[in] | tmplt | Pointer to UniRec template |
[in] | data | Pointer to the beginning of a record |
[in] | field_id | Identifier of a field. It must be a token beginning with F_, not a numeric ID. |
#define ur_get_ptr_by_id | ( | tmplt, | |
data, | |||
field_id | |||
) |
Get pointer to UniRec field Get pointer to fixed or varible length UniRec field. In contrast to ur_get_ptr, field_id may be a variable (not only F_ token). Returned pointer is always void *.
[in] | tmplt | Pointer to UniRec template |
[in] | data | Pointer to the beginning of a record |
[in] | field_id | Identifier of a field. Token beginning with F_ or a numeric ID. |
#define ur_get_size | ( | field_id | ) | ur_field_specs.ur_field_sizes[field_id] |
Get size of UniRec field Get size of a fixed-length UniRec field. When variable-length field is passed, return value < 0. To get real length of a variable-length field use ur_get_var_len.
[in] | field_id | ID of a field. |
#define ur_get_type | ( | field_id | ) | ur_field_specs.ur_field_types[field_id] |
#define ur_get_var_len | ( | tmplt, | |
rec, | |||
field_id | |||
) | *((uint16_t *)((char *) rec + tmplt->offset[field_id] + 2)) |
Get size of a variable sized field in the record. Get size of a variable-length field in the record. Given field has to be part of the record.
[in] | tmplt | Pointer to UniRec template |
[in] | rec | Pointer to the beginning of a record |
[in] | field_id | Identifier of a field. |
#define ur_get_var_offset | ( | tmplt, | |
rec, | |||
field_id | |||
) | *((uint16_t *)((char *) rec + tmplt->offset[field_id])) |
Get offset of variable-length field in the record. Get offset of a specified variable-length field in the record. Given field has to be part of the record.
[in] | tmplt | Pointer to UniRec template |
[in] | rec | Pointer to the beginning of a record |
[in] | field_id | Identifier of a field. |
#define ur_is_array | ( | field_id | ) | (ur_field_type_size[ur_get_type(field_id)] < 0 ? 1 : 0) |
#define ur_is_dynamic | ( | field_id | ) | ur_is_varlen(field_id) |
#define ur_is_fixlen | ( | field_id | ) | (ur_field_specs.ur_field_sizes[field_id] >= 0) |
#define ur_is_present | ( | tmplt, | |
field_id | |||
) | ((tmplt)->offset_size > (field_id) && (tmplt)->offset[(field_id)] != UR_INVALID_OFFSET) |
#define ur_is_static | ( | field_id | ) | ur_is_fixlen(field_id) |
#define ur_is_varlen | ( | field_id | ) | (ur_field_specs.ur_field_sizes[field_id] < 0) |
#define ur_rec_fixlen_size | ( | tmplt | ) | ((tmplt)->static_size) |
#define ur_rec_size | ( | tmplt, | |
rec | |||
) | (ur_rec_fixlen_size(tmplt) + ur_rec_varlen_size(tmplt, rec)) |
#define ur_set | ( | tmplt, | |
data, | |||
field_id, | |||
value | |||
) | (*(field_id ## _T*)((char *)(data) + (tmplt)->offset[field_id]) = (value)) |
Set value of UniRec (static) field Set value of a fixed-length UniRec field. For variable-length fields, use ur_set_var.
[in] | tmplt | Pointer to UniRec template |
[in] | data | Pointer to the beginning of a record |
[in] | field_id | Identifier of a field. It must be a token beginning with F_, not a numeric ID. |
[in] | value | The value the field should be set to. |
#define ur_set_input_template | ( | ifc, | |
tmplt | |||
) | ur_ctx_set_input_template(trap_get_global_ctx(), ifc, tmplt) |
#define ur_set_output_template | ( | ifc, | |
tmplt | |||
) | ur_ctx_set_output_template(trap_get_global_ctx(), ifc, tmplt) |
#define ur_set_string | ( | tmplt, | |
rec, | |||
field_id, | |||
str | |||
) | ur_set_var(tmplt, rec, field_id, str, strlen(str)) |
Set variable-length field to given string. Set contents of a variable-length field in the record. Field has to be part of the record. It copies string terminated with \0 and safely moves other variable-length records.
[in] | tmplt | Pointer to UniRec template |
[in] | rec | Pointer to the beginning of a record |
[in] | field_id | Identifier of a field. |
[in] | str | String terminated with \0, which will be copied |
#define ur_set_var_len | ( | tmplt, | |
rec, | |||
field_id, | |||
len | |||
) | *((uint16_t *)((char *) rec + tmplt->offset[field_id] + 2)) = (uint16_t) len |
Set size of variable-length field in the record. Set size of specified variable-length field in the record. Field has to be part of the record. It does not move other variable sized records. It just sets given value to the right position in the record.
[in] | tmplt | Pointer to UniRec template |
[in] | rec | Pointer to the beginning of a record |
[in] | field_id | Identifier of a field. |
[in] | len | The value the length should be set to. |
#define ur_set_var_offset | ( | tmplt, | |
rec, | |||
field_id, | |||
offset_val | |||
) | *((uint16_t *)((char *) rec + tmplt->offset[field_id])) = (uint16_t) offset_val |
Set offset of variable-length field in the record. Set offset of specified variable-length field in the record. Field has to be part of the record. It does not move other variable sized records. It just sets given value to the right position in the record.
[in] | tmplt | Pointer to UniRec template |
[in] | rec | Pointer to the beginning of a record |
[in] | field_id | Identifier of a field. |
[in] | offset_val | The value the offset should be set to. |
#define ur_size_of | ( | type | ) | ur_field_type_size[type] |
#define ur_template_string | ( | tmplt | ) | ur_template_string_delimiter(tmplt, ',') |
Get string of a template Get names and sizes of fields separated by comma. Return string has to be freed by user.
[in] | tmplt | Pointer to UniRec template |
#define ur_values_get_description | ( | field, | |
value | |||
) | ur_values_get_description_start_end(UR_TYPE_START_ ## field, UR_TYPE_END_ ## field, value) |
Returns description of specified value This function returns description of specified value and field, which is defined in values file.
[in] | field | Name of field to search value in |
[in] | value | Value of an item to find |
#define ur_values_get_name | ( | field, | |
value | |||
) | ur_values_get_name_start_end(UR_TYPE_START_ ## field, UR_TYPE_END_ ## field, value) |
Returns name of specified value This function returns name of specified value and field, which is defined in values file.
[in] | field | Name of field to search value in |
[in] | value | Value of an item to find |
int compare_fields | ( | const void * | field1, |
const void * | field2 | ||
) |
Compare fields Compare two fields. This function is for sorting the fields in the right order. First by sizes (larger first) and then by names.
[in] | field1 | Pointer to first field (field_spec_t) |
[in] | field2 | Pointer to second field (field_spec_t) |
char* ur_array_append_get_ptr | ( | const ur_template_t * | tmplt, |
void * | rec, | ||
int | field_id | ||
) |
Allocate new element at the end of array and return its pointer.
[in] | tmplt | Pointer to UniRec template |
[in] | rec | Pointer to the beginning of a record |
[in] | field_id | Identifier of a field. |
int ur_array_resize | ( | const ur_template_t * | tmplt, |
void * | rec, | ||
int | field_id, | ||
int | len | ||
) |
Change length of a array field.
[in] | tmplt | Pointer to UniRec template |
[in] | rec | Pointer to the beginning of a record. |
[in] | field_id | Identifier of a field. |
[in] | len | Length of the copied data in bytes. |
void ur_clear_varlen | ( | const ur_template_t * | tmplt, |
void * | rec | ||
) |
Clear variable-length part of a record. For better performance of setting content to variable-length fields, use this function before setting of all the variable-length fields. This function will clear all the variable-length fields, so they don't have to be moved in memory during setting of them.
[in] | tmplt | Pointer to UniRec template. |
[in] | rec | Pointer to the beginning of a record. |
|
inline |
Create new UniRec and copy the source UniRec into it. Function creates new UniRec record and fills it with the data given by parameter.
[in] | tmplt | Pointer to UniRec template |
[in] | src | Pointer to source data (UniRec record of the same template) |
void ur_copy_fields | ( | const ur_template_t * | dst_tmplt, |
void * | dst, | ||
const ur_template_t * | src_tmplt, | ||
const void * | src | ||
) |
Copy data from one UniRec record to another. Copies all fields present in both templates from src to dst. The function compares src_tmplt and dst_tmplt and for each field present in both templates it sets the value of field in dst to a corresponding value in src. "dst" must point to a memory of enough size.
[in] | dst_tmplt | Pointer to destination UniRec template |
[in] | dst | Pointer to destination record |
[in] | src_tmplt | Pointer to source UniRec template |
[in] | src | Pointer to source record |
char* ur_cpy_string | ( | const char * | str | ) |
void* ur_create_record | ( | const ur_template_t * | tmplt, |
uint16_t | max_var_size | ||
) |
Create UniRec record. Allocate and zero memory for a record with given template. It allocates N+M bytes, where N is the size of static part of the record (inferred from template), and M is the size of variable part (variable-length fields), which must be provided by caller. No more than 65535 bytes is allocated (even if N+M is greater), since this is the maximal possible size of UniRec record.
[in] | tmplt | Pointer to UniRec template. |
[in] | max_var_size | Size of variable-length part, i.e. sum of lengths of all variable-length fields. If it is not known at the time of record creation, use UR_MAX_SIZE, which allocates enough memory to hold the largest possible UniRec record (65535 bytes). Set to 0 if there are no variable-length fields in the template. |
ur_template_t* ur_create_template | ( | const char * | fields, |
char ** | errstr | ||
) |
Create UniRec template Create new UniRec template specified by a string containing names of its fields separated by commas. Example spec-string: "SRC_IP,DST_IP,SRC_PORT,DST_PORT,PROTOCOL,PACKETS" Order of fields is not important (templates with the same set of fields are equivalent). Template created by this function should be destroyed by ur_free_template.
[in] | fields | String with names of fields delimited by comma |
[in] | errstr | Pointer to char * string where the error message will be allocated and written in case of error. NULL if you don't need error message. In case of error, function will allocate string, which has to be freed by user. |
ur_template_t* ur_create_template_from_ifc_spec | ( | const char * | ifc_data_fmt | ) |
Create UniRec template from data format string. Creates new UniRec template (function ur_create_template_from_ifc_spec). The string describing fields contain types and names of fields separated by commas. Example ifc_data_fmt: "uint32 FOO,uint8 BAR,float FOO2" Order of fields is not important (templates with the same set of fields are equivalent)..
[in] | ifc_data_fmt | String with types and names of fields delimited by commas |
ur_template_t* ur_ctx_create_bidirectional_template | ( | trap_ctx_t * | ctx, |
int | ifc_in, | ||
int | ifc_out, | ||
const char * | fields, | ||
char ** | errstr | ||
) |
Create UniRec template and set it to input and output interface on specified context Creates UniRec template, same like ur_create_bidirectional_template, but context is specified.
[in] | ctx | specified context |
[in] | ifc_in | input interface number |
[in] | ifc_out | output interface number |
[in] | fields | String with names of fields delimited by comma |
[in] | errstr | Pointer to char * string where the error message will be allocated and written in case of error. NULL if you don't need error message. In case of error, function will allocate string, which has to be freed by user. |
ur_template_t* ur_ctx_create_input_template | ( | trap_ctx_t * | ctx, |
int | ifc, | ||
const char * | fields, | ||
char ** | errstr | ||
) |
Create UniRec template and set it to input interface on specified context Creates UniRec template, same like ur_create_input_template, but context is specified.
[in] | ctx | specified context |
[in] | ifc | interface number |
[in] | fields | String with names of fields delimited by comma |
[in] | errstr | Pointer to char * string where the error message will be allocated and written in case of error. NULL if you don't need error message. In case of error, function will allocate string, which has to be freed by user. |
ur_template_t* ur_ctx_create_output_template | ( | trap_ctx_t * | ctx, |
int | ifc, | ||
const char * | fields, | ||
char ** | errstr | ||
) |
Create UniRec template and set it to output interface on specified context Creates UniRec template, same like ur_create_output_template, but context is specified.
[in] | ctx | specified context |
[in] | ifc | interface number |
[in] | fields | String with names of fields delimited by comma |
[in] | errstr | Pointer to char * string where the error message will be allocated and written in case of error. NULL if you don't need error message. In case of error, function will allocate string, which has to be freed by user. |
int ur_ctx_set_input_template | ( | trap_ctx_t * | ctx, |
int | ifc, | ||
ur_template_t * | tmplt | ||
) |
int ur_ctx_set_output_template | ( | trap_ctx_t * | ctx, |
int | ifc, | ||
ur_template_t * | tmplt | ||
) |
int ur_define_field | ( | const char * | name, |
ur_field_type_t | type | ||
) |
Define new UniRec field Define new UniRec field at run-time. It adds new field into existing structures. If the field already exists (name and type are equal) it only returns its ID.
[in] | name | String with name of field. |
[in] | type | Type of field (specified by UR_TYPE_*). |
ur_template_t* ur_define_fields_and_update_template | ( | const char * | ifc_data_fmt, |
ur_template_t * | tmplt | ||
) |
Defined new fields and expand an UniRec template Define new fields (function ur_define_set_of_fields) and create new UniRec template (function ur_create_template_from_ifc_spec). The string describing fields contain types and names of fields separated by commas. Example ifc_data_fmt: "uint32 FOO,uint8 BAR,float FOO2" Order of fields is not important (templates with the same set of fields are equivalent). In case of success the given template will be destroyed and new template will be returned.
[in] | ifc_data_fmt | String with types and names of fields delimited by commas |
[in] | tmplt | Pointer to an existing template. |
int ur_define_set_of_fields | ( | const char * | ifc_data_fmt | ) |
Define set of new UniRec fields Define new UniRec fields at run-time. It adds new fields into existing structures. If the field already exists and type is equal nothing will happen. If the type is not equal an error will be returned. Example ifc_data_fmt: "uint32 FOO,uint8 BAR,float FOO2".
[in] | ifc_data_fmt | String containing types and names of fields delimited by comma. |
ur_template_t* ur_expand_template | ( | const char * | ifc_data_fmt, |
ur_template_t * | tmplt | ||
) |
Expand UniRec template Expand existing UniRec template by a string containing types and names of its fields separated by commas. Example ifc_data_fmt: "uint32 FOO,uint8 BAR,float FOO2" Order of fields is not important (templates with the same set of fields are equivalent). In case of success the given template will be destroyed and new template will be returned.
[in] | ifc_data_fmt | String with types and names of fields delimited by commas |
[in] | tmplt | Pointer to an existing template. |
void ur_finalize | ( | ) |
Deallocate UniRec structures Deallocate UniRec structures at the end of a program. This function SHOULD be called after all UniRec functions and macros invocations, typically during a cleanup phase before the program's end. This function has to be called if some fields are defined during run-time, otherwise this function is needless.
void ur_free_record | ( | void * | record | ) |
void ur_free_template | ( | ur_template_t * | tmplt | ) |
int ur_get_empty_id | ( | ) |
Return first empty id for new UniRec field Return first empty id for new UniRec field. If there is no space in the UniRec structures, it will increase space in the existing structures.
int ur_get_field_type_from_str | ( | const char * | type | ) |
int ur_get_id_by_name | ( | const char * | name | ) |
char* ur_get_var_as_str | ( | const ur_template_t * | tmplt, |
const void * | rec, | ||
ur_field_id_t | field_id | ||
) |
Get variable-length UniRec field as a C string Copy data of a variable-length field from UniRec record and append '\0' character. The function allocates new memory space for the string, it must be freed using free()!
[in] | tmplt | Pointer to UniRec template |
[in] | rec | Pointer to the beginning of a record |
[in] | field_id | Identifier of a field. |
char* ur_ifc_data_fmt_to_field_names | ( | const char * | ifc_data_fmt | ) |
Parses field names from data format Function parses field names from data format and returns pointer to new allocated string. Example: "type1 name1,type2 name2" => "name1,name2" New string has to be freed by user.
[in] | ifc_data_fmt | Pointer to the string containing data format |
int ur_init | ( | ur_static_field_specs_t | field_specs_static | ) |
Initialize UniRec structures Initialize UniRec structures. Function is called during defining first own field.
[in] | field_specs_static | Structure of statically-known UniRec fields. |
ur_iter_t ur_iter_fields | ( | const ur_template_t * | tmplt, |
ur_iter_t | id | ||
) |
Iterate over fields of a template in order of a record This function can be used to iterate over all fields of a given template. It returns ID of the next field present in the template after a given ID. If ID is set to UR_ITER_BEGIN, it returns the first fields. If no more fields are present, UR_ITER_END is returned. Example usage: ur_field_id_t id = UR_ITER_BEGIN while ((id = ur_iter_fields(&tmplt, id)) != UR_ITER_END) { ... } The order of fields is given by the order in which they are defined.
[in] | tmplt | Template to iterate over. |
[in] | id | Field ID returned in last iteration or UR_ITER_BEGIN to get first value. |
ur_iter_t ur_iter_fields_record_order | ( | const ur_template_t * | tmplt, |
int | index | ||
) |
Iterate over fields of a template This function can be used to iterate over all fields of a given template. It returns n-th ID of a record specified by index. If the return value is UR_ITER_END. The index is higher than count of fields in the template. Example usage: int i = 0; while ((id = ur_iter_fields(&tmplt, i++)) != UR_ITER_END) { ... } The order of fields is given by the order in the record.
[in] | tmplt | Template to iterate over. |
[in] | index | Field ID returned in last iteration or UR_ITER_BEGIN to get first value. |
void ur_print_template | ( | ur_template_t * | tmplt | ) |
uint16_t ur_rec_varlen_size | ( | const ur_template_t * | tmplt, |
const void * | rec | ||
) |
int ur_set_array_from_string | ( | const ur_template_t * | tmpl, |
void * | data, | ||
ur_field_id_t | f_id, | ||
const char * | v | ||
) |
Set value of a UniRec array field.
[in] | tmpl | Pointer to UniRec template |
[out] | data | Pointer to the beginning of a record |
[in] | f_id | Identifier of a field. It must be a constant beginning with UR_, not its numeric value. |
[in] | v | The value the field should be set to, array of fields with ' ' space delimiter. |
int ur_set_from_string | ( | const ur_template_t * | tmpl, |
void * | data, | ||
ur_field_id_t | f_id, | ||
const char * | v | ||
) |
Set value of a UniRec field.
[in] | tmpl | Pointer to UniRec template |
[out] | data | Pointer to the beginning of a record |
[in] | f_id | Identifier of a field. It must be a constant beginning with UR_, not its numeric value. |
[in] | v | The value the field should be set to. |
int ur_set_var | ( | const ur_template_t * | tmplt, |
void * | rec, | ||
int | field_id, | ||
const void * | val_ptr, | ||
int | val_len | ||
) |
Set content of variable-length UniRec field Copy given data into variable-length UniRec field, set its offset and length in a record and move data which are behind this field. For better performance use function ur_clear_varlen, before setting all variable fields in record.
[in] | tmplt | Pointer to UniRec template |
[in] | rec | Pointer to the beginning of a record. |
[in] | field_id | Identifier of a field. |
[in] | val_ptr | Pointer to data which should be copied into the record. |
[in] | val_len | Length of the copied data in bytes. |
int ur_template_compare | ( | const ur_template_t * | tmpltA, |
const ur_template_t * | tmpltB | ||
) |
Compares fields of two UniRec templates Function compares only sets of UniRec fields (direction is not compared).
[in] | tmpltA | Pointer to the first template. |
[in] | tmpltB | Pointer to the second template. |
char* ur_template_string_delimiter | ( | const ur_template_t * | tmplt, |
int | delimiter | ||
) |
Get UniRec specifier of the tmplt
template with delimiter
between fields.
Get names and sizes of fields separated by given delimiter.
Example:
[in] | tmplt | Pointer to UniRec template |
[in] | delimiter | Delimiter that is placed between the UniRec fields in the template specifier. |
int ur_undefine_field | ( | const char * | name | ) |
Undefine UniRec field by its name Undefine UniRec field created at run-time. It erases given field from UniRec structures and the field ID can be used for another field. By undefining field, all templates which were using the undefined field, has to be recreated.
[in] | name | Name of a field. |
int ur_undefine_field_by_id | ( | ur_field_id_t | field_id | ) |
Undefine UniRec field by its id Undefine UniRec field created at run-time. It erases given field from UniRec structures and the field ID can be used for another field. By undefining field, all templates which were using the undefined field, has to be recreated.
[in] | field_id | Identifier of a field. |
const char* ur_values_get_description_start_end | ( | uint32_t | start, |
uint32_t | end, | ||
int32_t | value | ||
) |
Returns description of specified value (Helper function) Helper function for ur_values_get_description. This function returns description of specified value and field, which is defined in values file. Function needs start and end index of a field.
[in] | start | Index of first item to search the value in ur_values array |
[in] | end | Index of last item to search the value in ur_values array |
[in] | value | Value of an item to find |
const char* ur_values_get_name_start_end | ( | uint32_t | start, |
uint32_t | end, | ||
int32_t | value | ||
) |
Returns name of specified value (Helper function) Helper function for ur_values_get_name. This function returns name of specified value and field, which is defined in values file. Function needs start and end index of a field.
[in] | start | Index of first item to search the value in ur_values array |
[in] | end | Index of last item to search the value in ur_values array |
[in] | value | Value of an item to find. |
int ur_field_array_elem_type[] |
ur_field_specs_t ur_field_specs |
ur_static_field_specs_t UR_FIELD_SPECS_STATIC |
Structure that lists staticaly defined UniRec field specifications such as names, types, id (using UR_FIELDS()).
const int ur_field_type_size[] |
Sizes of UniRec data types.
Data types are defined in the ur_field_type_str array.
const char* ur_field_type_str[] |
UniRec data types.
Sizes of data types are defined in the ur_field_type_size array.