46#define _DEFAULT_SOURCE
60#include <libtrap/trap.h>
65#define MAX(A, B) ((A >= B) ? (A) : (B))
240 for (i = 0; i < field_specs_static.
ur_last_id; i++) {
245 for (j = 0; j < i; j++) {
259 char *str = NULL, *strmove = NULL, *str_new = NULL;
266 str = (
char *) calloc(
sizeof(
char), len);
271 for (
int i = 0; i < tmplt->
count; i++) {
273 if (act_len >= len) {
275 str_new = (
char *) realloc(str,
sizeof(
char) * len);
276 if (str_new == NULL) {
280 strmove = str_new + (strmove - str);
284 strmove += strlen(strmove);
286 if (tmplt->
count != 0) {
294 ur_field_id_linked_list_t * first;
298 if (init_val !=
UR_OK) {
320 char **ur_field_names_new;
321 short *ur_field_sizes_new;
328 if (ur_field_types_new == NULL) {
334 if (ur_field_sizes_new == NULL) {
335 free(ur_field_types_new);
341 if (ur_field_names_new == NULL) {
342 free(ur_field_types_new);
343 free(ur_field_sizes_new);
374 int length_type_2 = 0, length_name_2 = 0;
375 const char *source_cpy;
377 while (*source != 0 && isspace(*source)) {
382 while (*source != 0 && !isspace(*source)) {
389 if (length_type_2 >= *length_type) {
393 *type = (
char *) malloc(
sizeof(
char) * (length_type_2 + 1));
397 *length_type = length_type_2 + 1;
399 memcpy(*type, source_cpy, length_type_2);
400 (*type)[length_type_2] = 0;
403 while (*source != 0 && isspace(*source)) {
408 while (*source != 0 && !isspace(*source) && *source !=
',') {
415 if (length_name_2 >= *length_name) {
419 *name = (
char *) malloc(
sizeof(
char) * (length_name_2 + 1));
423 *length_name = length_name_2 + 1;
425 memcpy(*name, source_cpy, length_name_2);
426 (*name)[length_name_2] = 0;
428 while (*source != 0 && isspace(*source)) {
432 if (*source ==
',') {
440 const char *source_cpy = NULL, *p = ifc_data_fmt;
442 int name_len = 0, act_len = 0, str_len;
443 str_len = strlen(ifc_data_fmt);
444 out_str = (
char *) calloc(str_len + 1,
sizeof(
char));
445 if (out_str == NULL) {
450 while (*p != 0 && isspace(*p)) {
454 while (*p != 0 && *p !=
' ') {
458 while (*p != 0 && isspace(*p)) {
465 while (*p != 0 && *p !=
',' && !isspace(*p)) {
469 assert(name_len + act_len + 1 <= str_len);
470 memcpy(out_str + act_len, source_cpy, name_len);
473 while (*p != 0 && isspace(*p)) {
478 }
else if (*p == 0) {
484 out_str[act_len] =
',';
492 int name_len = 0, act_len = 0, concat_str_len = strlen(ifc_data_fmt);
494 const char *source_cpy, *p = ifc_data_fmt;
496 uint32_t ifc_out = 0;
497 concat_str = (
char *) malloc(
sizeof(
char) * concat_str_len);
498 if (concat_str == NULL) {
502 while (*p != 0 && !isspace(*p)) {
509 while (*p != 0 && *p !=
',') {
513 if (name_len + act_len + 1 > concat_str_len) {
515 size_t req_size =
MAX(name_len + act_len + 1, (concat_str_len * 2));
516 str_new = (
char *) realloc(concat_str,
sizeof(
char) * req_size);
517 if (str_new == NULL) {
521 concat_str_len = req_size;
522 concat_str = str_new;
524 memcpy(concat_str + act_len, source_cpy, name_len);
526 concat_str[act_len] =
',';
532 for (
int i = 0; i < tmplt->
count; i++) {
534 name_len = strlen(f_name);
535 if (name_len + act_len + 1 > concat_str_len) {
537 size_t req_size =
MAX(name_len + act_len + 1, (concat_str_len * 2));
538 str_new = (
char *) realloc(concat_str,
sizeof(
char) * req_size);
539 if (str_new == NULL) {
543 concat_str_len = req_size;
544 concat_str = str_new;
546 memcpy(concat_str + act_len, f_name, name_len);
548 *(concat_str + act_len) =
',';
555 concat_str[act_len] = 0;
566 const char *new_fields_move;
567 new_fields_move = ifc_data_fmt;
568 char *field_name, *field_type;
570 int field_id = 0, field_type_id = 0;
571 field_name = (
char *) malloc(
sizeof(
char) * field_name_length);
572 if (field_name == NULL) {
575 field_type = (
char *) malloc(
sizeof(
char) * field_type_length);
576 if (field_type == NULL) {
580 while (*new_fields_move != 0) {
582 if (new_fields_move == NULL) {
583 if (field_name != NULL) {
586 if (field_type != NULL) {
593 if (field_type_id < 0) {
594 if (field_name != NULL) {
598 return field_type_id;
602 if (field_name != NULL) {
609 if (field_name != NULL) {
623 if (new_tmplt != NULL && tmplt != NULL) {
634 if (field_names == NULL) {
651 name_len = strlen(name);
655 if (!((name[0] >=
'A' && name[0] <=
'Z') || (name[0] >=
'a' && name[0] <=
'z'))) {
658 for (
int i = 1; i < name_len; i++) {
659 if (!((name[i] >=
'A' && name[i] <=
'Z') || (name[i] >=
'a' && name[i] <=
'z') || (name[i] >=
'0' && name[i] <=
'9') || name[i] ==
'_')) {
683 name_copy = (
char *) calloc(
sizeof(
char), strlen(name) + 1);
684 if (name_copy == NULL) {
688 strcpy(name_copy, name);
711 ur_field_id_linked_list_t *undefined_item;
712 undefined_item = (ur_field_id_linked_list_t *) calloc(
sizeof(ur_field_id_linked_list_t), 1);
713 if (undefined_item == NULL) {
719 undefined_item->id = field_id;
755 ur_field_id_linked_list_t *next, * act_del;
757 while (act_del != NULL) {
758 next = act_del->next;
811 if (errstr != NULL) {
813 if (*errstr != NULL) {
830 if (errstr != NULL) {
832 if (*errstr != NULL) {
854 if (tmplt_str == NULL) {
857 trap_ctx_set_data_fmt(ctx, ifc, TRAP_FMT_UNIREC, tmplt_str);
873 if (tmplt_str == NULL) {
876 trap_ctx_set_required_fmt(ctx, ifc, TRAP_FMT_UNIREC, tmplt_str);
890 if (tmplt_str == NULL) {
891 if (errstr != NULL) {
893 if (*errstr != NULL) {
900 trap_ctx_set_required_fmt(ctx, ifc_in, TRAP_FMT_UNIREC, tmplt_str);
901 trap_ctx_set_data_fmt(ctx, ifc_out, TRAP_FMT_UNIREC, tmplt_str);
909 int n_fields = 0, written_fields = 0;
912 while (*fields !=
'\0' && isspace(*fields)) {
916 if (*fields !=
'\0') {
918 const char *tmp = fields;
919 while (*tmp !=
'\0') {
920 if (*(tmp++) ==
',') {
928 if (fields_spec == NULL && n_fields > 0) {
929 if (errstr != NULL) {
931 if (*errstr != NULL) {
938 const char *start_ptr = fields;
940 for (
int i = 0; i < n_fields; i++) {
944 while (!isspace(*end_ptr) && *end_ptr !=
',' && *end_ptr !=
'\0') {
947 int len = end_ptr - start_ptr;
948 fields_spec[written_fields].
name = malloc(len + 1);
949 if (fields_spec[written_fields].name == NULL) {
950 if (errstr != NULL) {
952 if (*errstr != NULL) {
956 for (
int j = 0; j < i; j++) {
957 free(fields_spec[j].name);
962 memcpy(fields_spec[written_fields].name, start_ptr, len);
963 fields_spec[written_fields].
name[len] = 0;
965 while ((isspace(*start_ptr) || *start_ptr ==
',') && *start_ptr !=
'\0') {
972 if (errstr != NULL) {
973 *errstr = (
char *) malloc(100);
974 if (*errstr != NULL) {
976 n = snprintf(*errstr, 100,
"field: %s is not defined.", fields_spec[written_fields].name);
978 strcpy(*errstr,
"given field is not defined");
982 for (
int j = 0; j <= written_fields; j++) {
983 free(fields_spec[j].name);
989 int in_the_template = 0;
990 for (
int j = 0; j < written_fields; j++) {
991 if (fields_spec[j].
id == id_by_name) {
997 if (in_the_template == 0) {
998 fields_spec[written_fields].
id = id_by_name;
1000 fields_spec[written_fields].
size =
ur_get_size(fields_spec[written_fields].
id);
1003 free(fields_spec[written_fields].name);
1004 fields_spec[written_fields].
name = NULL;
1013 if (tmplt == NULL) {
1014 for (
int i = 0; i < written_fields; i++) {
1015 free(fields_spec[i].name);
1018 if (errstr != NULL) {
1020 if (*errstr != NULL) {
1031 if (tmplt->
offset == NULL) {
1032 for (
int i = 0; i < written_fields; i++) {
1033 free(fields_spec[i].name);
1037 if (errstr != NULL) {
1039 if (*errstr != NULL) {
1048 uint16_t offset = 0;
1050 for (
int i = 0; i < written_fields; i++) {
1052 if (fields_spec[i].size < 0) {
1053 tmplt->
offset[fields_spec[i].
id] = offset;
1059 tmplt->
offset[fields_spec[i].
id] = offset;
1060 offset += fields_spec[i].
size;
1068 if (tmplt->
ids == NULL) {
1069 for (
int i = 0; i < written_fields; i++) {
1070 free(fields_spec[i].name);
1074 if (errstr != NULL) {
1076 if (*errstr != NULL) {
1082 tmplt->
count = written_fields;
1083 for (
int i = 0; i < written_fields; i++) {
1084 tmplt->
ids[i] = fields_spec[i].
id;
1087 for (
int i = 0; i < written_fields; i++) {
1088 free(fields_spec[i].name);
1095 if (tmplt == NULL) {
1099 if (tmplt->
offset != NULL) {
1103 if (tmplt->
ids != NULL) {
1113 return memcmp(tmpltA->
ids, tmpltB->
ids,
sizeof(uint16_t) * tmpltA->
count) == 0;
1123 printf(
"static_size: %hu, first_dynamic: ", tmplt->
static_size);
1125 printf(
", offsets:\n"
1126 "ID\t%-30s\toffset\n",
"name");
1127 for (
int i = 0; i < tmplt->
count; i++) {
1136 int old_size_of_field =
ur_get_len(tmplt, rec, field_id);
1138 if (old_size_of_field != new_val_len) {
1139 uint16_t size = new_val_len;
1143 for (
int i = 0; i< tmplt->
count; i++) {
1144 if (field_id == tmplt->
ids[i]) {
1149 for (
int i = index + 1; i < tmplt->
count; i++) {
1153 memmove(out_ptr + new_val_len, out_ptr + old_size_of_field, size - new_val_len);
1172 memcpy(out_ptr, val_ptr, val_len);
1195 return (
char *)
ur_get_ptr_by_id(tmplt, rec, field_id) + elem_cnt * elem_size;
1222 unsigned int size = (
unsigned int)tmplt->
static_size + max_var_size;
1225 return (
void *) calloc(size, 1);
1238 char *str = malloc(size + 1);
1243 memcpy(str, p, size);
1261 int size_of_field = 0;
1262 void * ptr_dst = NULL;
1263 void * ptr_src = NULL;
1266 if (src_tmplt == dst_tmplt) {
1272 for (
int i = 0; i < size; i++) {
1276 if (size_of_field > 0) {
1280 memcpy(ptr_dst, ptr_src, size_of_field);
1285 ur_set_var(dst_tmplt, dst, i, ptr_src, size_of_field);
1301 while (id < tmplt->offset_size) {
1315 if (index >= tmplt->
count || index < 0) {
1318 return tmplt->
ids[index];
1328 int elems_parsed = 0;
1330 const char *scan_format = NULL;
1344 scan_format =
"%" SCNu8;
1347 scan_format =
"%" SCNu16;
1350 scan_format =
"%" SCNu32;
1353 scan_format =
"%" SCNu64;
1356 scan_format =
"%" SCNi8;
1359 scan_format =
"%" SCNi16;
1362 scan_format =
"%" SCNi32;
1365 scan_format =
"%" SCNi64;
1371 scan_format =
"%lf";
1377 const char *ip = tmp;
1386 memcpy(tmp, v, end - v);
1394 ((
ip_addr_t *) ptr)[elems_parsed] = addr;
1396 if (elems_parsed >= elems_allocated) {
1414 ((
mac_addr_t *) ptr)[elems_parsed] = macaddr;
1416 if (elems_parsed >= elems_allocated) {
1432 const char *time = tmp;
1441 memcpy(tmp, v, end - v);
1448 ((
ur_time_t *) ptr)[elems_parsed] = urtime;
1450 if (elems_parsed >= elems_allocated) {
1463 fprintf(stderr,
"Unsupported UniRec field type, skipping.\n");
1468 if (scan_format != NULL) {
1470 if (sscanf(v, scan_format, (
void *) ((
char*) ptr + elems_parsed * element_size)) != 1) {
1475 if (elems_parsed >= elems_allocated) {
1488 if (elems_allocated > elems_parsed) {
1506 if (sscanf(v,
"%" SCNu8, (uint8_t *) ptr) != 1) {
1511 if (sscanf(v,
"%" SCNu16 , (uint16_t *) ptr) != 1) {
1516 if (sscanf(v,
"%" SCNu32, (uint32_t *) ptr) != 1) {
1521 if (sscanf(v,
"%" SCNu64, (uint64_t *) ptr) != 1) {
1526 if (sscanf(v,
"%" SCNi8, (int8_t *) ptr) != 1) {
1531 if (sscanf(v,
"%" SCNi16, (int16_t *) ptr) != 1) {
1536 if (sscanf(v,
"%" SCNi32, (int32_t *) ptr) != 1) {
1541 if (sscanf(v,
"%" SCNi64, (int64_t *) ptr) != 1) {
1546 if (sscanf(v,
"%c", (
char *) ptr) != 1) {
1551 if (sscanf(v,
"%f", (
float *) ptr) != 1) {
1556 if (sscanf(v,
"%lf", (
double *) ptr) != 1) {
1576 (*macaddr_p) = macaddr;
1581 fprintf(stderr,
"Failed to parse time.\n");
1592 int size = strlen(v)/2;
1595 for ( ; size > 0; --size, v += 2, ++data_ptr) {
1596 if (sscanf(v,
"%2hhx", data_ptr) != 1) {
1606 fprintf(stderr,
"Unsupported UniRec field type, skipping.\n");
1619 if (ur == NULL || str == NULL) {
1623 res = strptime(str,
"%Y-%m-%dT%T", &t);
1625 if ((res != NULL) && ((*res ==
'.') || (*res == 0) || (*res ==
'z') || (*res ==
'Z'))) {
1628 if (*res != 0 && *++res != 0) {
1629 char frac_buffer[10];
1630 memset(frac_buffer,
'0', 9);
1637 size_t frac_len = strlen(res);
1638 if (frac_len > 0 && (res[frac_len - 1] ==
'z' || res[frac_len - 1] ==
'Z')) {
1644 memcpy(frac_buffer, res, frac_len);
1645 nsec = strtoul(frac_buffer, NULL, 10);
1649 goto failed_time_parsing;
1663 int str_len = strlen(str) + 1;
1664 char *new_str = malloc(
sizeof(
char) * str_len);
1665 if (new_str == NULL) {
1668 memcpy(new_str, str, str_len);
1674 for (
int i = start; i < end; i++) {
1684 for (
int i = start; i < end; i++) {
1698 unsigned int indexer;
1708 if (sscanf(mask,
"%"SCNx64, &lm->
link_mask) < 1) {
1749 if (links != NULL) {
INLINE_IMPL char * ip_get_v4_as_bytes(const ip_addr_t *addr)
INLINE_IMPL ip_addr_t ip_from_16_bytes_be(const char b[16])
INLINE_IMPL void ip_to_str(const ip_addr_t *addr, char *str)
INLINE_IMPL ip_addr_t ip_from_4_bytes_le(const char b[4])
INLINE_IMPL int ip_cmp(const ip_addr_t *addr1, const ip_addr_t *addr2)
INLINE_IMPL ip_addr_t ip_from_16_bytes_le(const char b[16])
INLINE_IMPL int ip_is4(const ip_addr_t *addr)
INLINE_IMPL ip_addr_t ip_from_int(uint32_t i)
INLINE_IMPL int ip_from_str(const char *str, ip_addr_t *addr)
INLINE_IMPL int ip_is6(const ip_addr_t *addr)
INLINE_IMPL uint32_t ip_get_v4_as_int(const ip_addr_t *addr)
INLINE_IMPL ip_addr_t ip_from_4_bytes_be(const char b[4])
INLINE_IMPL int ur_get_link_index(ur_links_t *links, uint64_t link_bit_field)
Get index of link (0 - (n-1)) Function gets search link_indexes array for value corresponding to pass...
INLINE_IMPL uint64_t ur_get_link_bit_field_position(ur_links_t *links, unsigned int index)
Get position in link_bit_field of link. Get position in link_bit_field of link specified by index of ...
ur_links_t * ur_create_links(const char *mask)
Create and initialize links structure. Create new links structure and initialize it from link mask in...
void ur_free_links(ur_links_t *links)
Destroy links structure. Free all memory allocated for a links structure created previously by ur_cre...
INLINE_IMPL unsigned int ur_get_link_count(ur_links_t *links)
Get link count.
INLINE_IMPL uint64_t ur_get_link_mask(ur_links_t *links)
Get link mask.
Links structure. It contains a link count, link mask and link indexes. Array link_indexes stores posi...
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_templ...
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...
void ur_print_template(ur_template_t *tmplt)
Print UniRec template Print static_size, first_dynamic and table of offsets to stdout (for debugging)...
#define ur_rec_fixlen_size(tmplt)
Get size of fixed-length part of UniRec record Get total size of UniRec record except variable-length...
#define ur_set_var_offset(tmplt, rec, field_id, offset_val)
Set offset of variable-length field in the record. Set offset of specified variable-length field in t...
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 ...
int ur_init(ur_static_field_specs_t field_specs_static)
Initialize UniRec structures Initialize UniRec structures. Function is called during defining first o...
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)...
const char * ur_field_type_str[]
UniRec data types.
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 ...
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 recor...
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_descriptio...
int ur_undefine_field(const char *name)
Undefine UniRec field by its name Undefine UniRec field created at run-time. It erases given field fr...
char * ur_template_string_delimiter(const ur_template_t *tmplt, int delimiter)
Get UniRec specifier of the tmplt template with delimiter between fields.
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 U...
#define ur_array_allocate(tmplt, rec, field_id, elem_cnt)
Preallocates UniRec array field to have requested number of elements.
int ur_array_resize(const ur_template_t *tmplt, void *rec, int field_id, int len)
Change length of a array field.
#define ur_is_array(field_id)
#define ur_get_var_offset(tmplt, rec, field_id)
Get offset of variable-length field in the record. Get offset of a specified variable-length field in...
ur_static_field_specs_t UR_FIELD_SPECS_STATIC
Structure that lists staticaly defined UniRec field specifications such as names, types,...
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.
void ur_free_template(ur_template_t *tmplt)
Destroy UniRec template Free all memory allocated for a template created previously by ur_create_temp...
#define ur_rec_size(tmplt, rec)
Get size of UniRec record (static and variable length) Get total size of whole UniRec record.
#define ur_get_size(field_id)
Get size of UniRec field Get size of a fixed-length UniRec field. When variable-length field is passe...
void ur_finalize()
Deallocate UniRec structures Deallocate UniRec structures at the end of a program....
#define ur_template_string(tmplt)
Get string of a template Get names and sizes of fields separated by comma. Return string has to be fr...
const int ur_field_type_size[]
Sizes of UniRec data types.
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 tem...
ur_field_specs_t ur_field_specs
Structure that lists UniRec field specifications such as names, types, id.
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 t...
int ur_get_empty_id()
Return first empty id for new UniRec field Return first empty id for new UniRec field....
void * ur_create_record(const ur_template_t *tmplt, uint16_t max_var_size)
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.
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.
#define ur_size_of(type)
Get size of UniRec type Get size of fixed-length UniRec type. For variable-length type return value <...
#define ur_get_var_len(tmplt, rec, field_id)
Get size of a variable sized field in the record. Get size of a variable-length field in the record....
#define ur_is_static(field_id)
Alias for ur_is_fixlen (for backwards compatibility only)
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 no...
int ur_field_array_elem_type[]
UniRec array element data types.
#define ur_array_get_elem_cnt(tmplt, rec, field_id)
Get number of elements stored in an UniRec array.
#define ur_array_get_elem_size(field_id)
Get size of a single element of UniRec field.
#define ur_set_var_len(tmplt, rec, field_id, len)
Set size of variable-length field in the record. Set size of specified variable-length field in the r...
#define ur_get_len(tmplt, rec, field)
Get length of UniRec field Get actual length of fixed or variable-length UniRec field.
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...
#define ur_get_name(field_id)
Get name of UniRec field Get name of any UniRec defined 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 ...
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,...
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 existin...
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 ...
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,...
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.
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.
#define ur_get_type(field_id)
Get type of UniRec field Get type of any UniRec defined field.
int ur_get_field_type_from_str(const char *type)
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.
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 structur...
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,...
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....
void ur_free_record(void *record)
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....
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 field...
#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_ge...
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 ...
char * ur_cpy_string(const char *str)
Duplicates given string. Helper function which returns pointer to duplicated string....
#define ur_is_present(tmplt, field_id)
Is given field present in given template? Return true (non-zero value) if given template contains fie...
uint64_t ur_time_t
Type of timestamps used in UniRec Timestamps in UniRec are stored as number of seconds from Unix epoc...
uint8_t ur_time_from_string(ur_time_t *ur, const char *str)
#define ur_time_from_sec_nsec(sec, nsec)
Convert seconds and nanoseconds to ur_time_t.
INLINE_IMPL void mac_to_str(const mac_addr_t *addr, char *str)
INLINE_IMPL void mac_to_bytes(const mac_addr_t *addr, uint8_t *array)
INLINE_IMPL int mac_cmp(const mac_addr_t *addr1, const mac_addr_t *addr2)
void ur_var_change_size(const ur_template_t *tmplt, void *rec, int field_id, int new_val_len)
INLINE_IMPL int mac_from_str(const char *str, mac_addr_t *addr)
const char * ur_get_type_and_name_from_string(const char *source, char **name, char **type, int *length_name, int *length_type)
const char UR_MEMORY_ERROR[]
INLINE_IMPL mac_addr_t mac_from_bytes(const uint8_t *array)
Definition of UniRec structures and functions.
@ UR_TYPE_A_UINT32
unsigned int (32b) array
@ UR_TYPE_UINT64
unsigned int (64b)
@ UR_TYPE_A_UINT16
unsigned int (16b) array
@ UR_TYPE_A_INT64
int (64b) array
@ UR_TYPE_A_DOUBLE
double (64b) array
@ UR_TYPE_A_IP
IP address (128b) array.
@ UR_TYPE_A_INT32
int (32b) array
@ UR_TYPE_A_INT8
int (8b) array
@ UR_TYPE_A_INT16
int (8b) array
@ UR_TYPE_IP
IP address (128b)
@ UR_TYPE_A_UINT8
unsigned int (8b) array
@ UR_TYPE_DOUBLE
double (64b)
@ UR_TYPE_A_FLOAT
float (32b) array
@ UR_TYPE_A_UINT64
unsigned int (64b) array
@ UR_TYPE_A_MAC
MAC address (48b) array.
@ UR_TYPE_UINT8
unsigned int (8b)
@ UR_TYPE_STRING
var-len fields (string where only printable characters are expected; '\0' at the end should NOT be in...
@ UR_TYPE_A_TIME
time (64b) array
@ UR_TYPE_UINT16
unsigned int (16b)
@ UR_TYPE_UINT32
unsigned int (32b)
@ UR_TYPE_MAC
MAC address (48b)
@ UR_TYPE_BYTES
var-len fields (generic string of bytes)
@ UR_TYPE_FLOAT
float (32b)
ur_field_id_t ur_last_id
The highest ID of a field + 1.
#define UR_UNINITIALIZED
Indicator if the UniRec has not been initialized by calling function ur_init.
ur_tmplt_direction direction
Direction of data input, output, bidirection, no direction.
ur_field_id_t ur_iter_t
Type for identifying iteration id through all fields.
#define UR_E_MEMORY
Problem during allocating memory.
int16_t ur_field_id_t
Type of UniRec field identifiers.
#define UR_ITER_BEGIN
First value in iterating through the fields.
#define UR_DEFAULT_LENGTH_OF_FIELD_TYPE
#define UR_INITIALIZED
Indicator if the UniRec has been initialized by calling function ur_init.
uint8_t intialized
If the UniRec is initialized by function ur_init variable is set to UR_INITIALIZED,...
ur_field_id_linked_list_t * ur_undefine_fields
linked list of free (undefined) IDs
#define UR_ARRAY_DELIMITER
Delimiter of array elements in string.
#define UR_E_TYPE_MISMATCH
The type of a field is different.
ur_field_id_t ur_last_statically_defined_id
Last statically defined field by UR_FIELDS(...)
#define UR_E_INVALID_NAME
The given name is not present in a template.
uint16_t count
Count of fields in template.
ur_field_type_t * ur_field_types
Array of types of fields.
char * name
Name of a field.
uint16_t first_dynamic
First dynamic (variable-length) field. Index to the ids array.
#define UR_DEFAULT_LENGTH_OF_FIELD_NAME
uint16_t * offset
Table of offsets.
uint32_t ifc_out
output interface number (stored only if the direction == UR_TMPLT_DIRECTION_BI)
uint16_t static_size
Size of static part.
#define UR_DEFAULT_LENGTH_OF_TEMPLATE
#define UR_ARRAY_ALLOC
Default alloc size increment for ur_set_array_from_string.
ur_field_id_t id
ID of a field.
short * ur_field_sizes
Array of sizes of fields.
#define UR_INVALID_OFFSET
Default value of all offsets (value is not in the record)
ur_field_id_t ur_last_id
Last specified ID.
@ UR_TMPLT_DIRECTION_IN
input direction
@ UR_TMPLT_DIRECTION_NO
template is not used for sending data
@ UR_TMPLT_DIRECTION_OUT
ouput direction
@ UR_TMPLT_DIRECTION_BI
bidirection
#define UR_NO_DYNAMIC_VALUES
Value of variable "first_dynamic" if no dynamic values are present.
short * ur_field_sizes
Array of sizes of fields.
char ** ur_field_names
Array of names of fields.
#define UR_COUNT_OF_TYPES
Constants for all possible types of UniRec fields.
char ** ur_field_names
Array of names of fields.
#define UR_INITIAL_SIZE_FIELDS_TABLE
Initial size of free space in fields tables.
#define UR_FIELD_ID_MAX
Max ID of a field.
#define UR_E_INVALID_PARAMETER
The given parameter is wrong.
#define UR_E_INVALID_TYPE
The type of a field is not defined.
ur_field_id_t ur_allocated_fields
#define UR_ITER_END
Last value in iterating through the fields.
int16_t * ids
Array of ids in template.
ur_field_type_t * ur_field_types
Array of types of fields.
uint16_t offset_size
size of offset table.
#define UR_E_INVALID_FIELD_ID
The field ID is not present in a template.
Sorting fields structure This structure is used to sort fields by their size and name....
UniRec fields structure It contains all fields which are statically defined by UR_FIELDS(....
UniRec default field list It contains all fields which are specified statically in source code of a m...
UniRec template. It contains a table mapping a field to its position in an UniRec record.
const ur_values_t ur_values[]
char * name
Name of Value.
char * description
Description of Value.