Skip to content

Commit

Permalink
UniRec output: code style polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas955 committed Jul 2, 2020
1 parent afbaf0f commit b058cd3
Show file tree
Hide file tree
Showing 2 changed files with 228 additions and 213 deletions.
126 changes: 65 additions & 61 deletions extra_plugins/output/unirec/src/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,44 +291,47 @@ map_load_line_ie_defs(map_t *map, char *ur_name, int ur_type, char *ur_type_str,
char *subsave_ptr_list = NULL;
struct map_ipfix_s *ipfix = &rec.ipfix;
rec.ipfix.next = NULL;

for (char *list = subtoken; ;list = NULL) {
char *list_token = strtok_r(list, "/", &subsave_ptr_list);
if (!list_token) {
break;
}

elem_def = map_elem_get_ipfix(map->iemgr, list_token);
if (elem_def != NULL) {
if (list == NULL) {
ipfix->next = malloc(sizeof(struct map_ipfix_s));
if (!ipfix->next) {
rc = IPX_ERR_NOMEM;
elem_def = NULL;
break;
}
ipfix = ipfix->next;
}
// Store the "IPFIX element" record
ipfix->source = MAP_SRC_IPFIX;
ipfix->def = elem_def;
ipfix->id = elem_def->id;
ipfix->en = elem_def->scope->pen;
ipfix->next = NULL;

continue;
}
break;
// Test if the specifier describes basicList
char *list_token = strtok_r(list, "/", &subsave_ptr_list);
if (!list_token) {
break;
}

elem_def = map_elem_get_ipfix(map->iemgr, list_token);
if (elem_def != NULL) {
if (list == NULL) {
ipfix->next = malloc(sizeof(struct map_ipfix_s));
if (!ipfix->next) {
rc = IPX_ERR_NOMEM;
elem_def = NULL;
break;
}
ipfix = ipfix->next;
}

// Store the "IPFIX element" record
ipfix->source = MAP_SRC_IPFIX;
ipfix->def = elem_def;
ipfix->id = elem_def->id;
ipfix->en = elem_def->scope->pen;
ipfix->next = NULL;
continue;
}
break;
}

if (elem_def != NULL) {
rc = map_rec_add(map, &rec);
continue;
rc = map_rec_add(map, &rec);
continue;
}

ipfix = rec.ipfix.next;
while (ipfix) {
struct map_ipfix_s *tmp = ipfix->next;
free(ipfix);
ipfix = tmp;
struct map_ipfix_s *tmp = ipfix->next;
free(ipfix);
ipfix = tmp;
}

enum MAP_SRC fn_id = map_elem_get_internal(subtoken);
Expand Down Expand Up @@ -459,28 +462,28 @@ map_sort_fn(const void *p1, const void *p2)
const struct map_ipfix_s *ipfix2 = &(*(struct map_rec **) p2)->ipfix;

while (ipfix1 && ipfix2) {
if (ipfix1->source != ipfix2->source) {
return (ipfix1->source < ipfix2->source) ? (-1) : 1;
}

// Primary sort by PEN
if (ipfix1->en != ipfix2->en) {
return (ipfix1->en < ipfix2->en) ? (-1) : 1;
}

// Secondary sort by ID
if (ipfix1->id != ipfix2->id) {
return (ipfix1->id < ipfix2->id) ? (-1) : 1;
}

ipfix1 = ipfix1->next;
ipfix2 = ipfix2->next;
if (ipfix1->source != ipfix2->source) {
return (ipfix1->source < ipfix2->source) ? (-1) : 1;
}

// Primary sort by PEN
if (ipfix1->en != ipfix2->en) {
return (ipfix1->en < ipfix2->en) ? (-1) : 1;
}

// Secondary sort by ID
if (ipfix1->id != ipfix2->id) {
return (ipfix1->id < ipfix2->id) ? (-1) : 1;
}

ipfix1 = ipfix1->next;
ipfix2 = ipfix2->next;
}

if (ipfix1->next) {
return -1;
return -1;
} else if (ipfix2->next) {
return 1;
return 1;
}

return 0;
Expand Down Expand Up @@ -563,20 +566,21 @@ map_load(map_t *map, const char *file)
const struct map_ipfix_s *ipfix_prev = &rec_prev->ipfix;
const struct map_ipfix_s *ipfix_now = &rec_now->ipfix;
while (1) {
if (ipfix_prev->en != ipfix_now->en || ipfix_prev->id != ipfix_now->id || !ipfix_prev || !ipfix_now) {
rec_prev = rec_now;
break;
}

ipfix_prev = ipfix_prev->next;
ipfix_now = ipfix_now->next;
if (!ipfix_prev && !ipfix_now) {
collision = true;
break;
}
if (!ipfix_prev || !ipfix_now || ipfix_prev->en != ipfix_now->en
|| ipfix_prev->id != ipfix_now->id) {
rec_prev = rec_now;
break;
}

ipfix_prev = ipfix_prev->next;
ipfix_now = ipfix_now->next;
if (!ipfix_prev && !ipfix_now) {
collision = true;
break;
}
}
if (!collision) {
continue;
continue;
}

// Collision detected!
Expand Down
Loading

0 comments on commit b058cd3

Please sign in to comment.