Commit 8679767b authored by 's avatar
Browse files

nits


git-svn-id: file:///home/svn/mapi/trunk@548 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 5445871e
......@@ -36,7 +36,7 @@ WITH_GLOBAL_OPT=0
WITH_ANONYMIZATION=0
#Support for application-level filtering (mostly P2P traffic identification)
WITH_TRACKING=0
WITH_TRACKING=1
#Ipfix flow record generation
WITH_IPFIX=0
......
#include "stdlib.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "flist.h"
int
flist_append(flist_t *list,int id,void *data)
int flist_default_free_data=0;
int flist_append(flist_t *list,int id,void *data)
{
flist_node_t *node;
if(!list) {
fprintf(stderr,"flist_append in NULL List\n");
return -1;
}
if ( (node = malloc(sizeof(flist_node_t))) == NULL )
if ( (node = (flist_node_t *) malloc(sizeof(flist_node_t))) == NULL )
return -1;
node->id=id;
......@@ -16,39 +24,48 @@ flist_append(flist_t *list,int id,void *data)
if ( flist_head(list) == NULL )
flist_head(list) = node;
else
flist_next(flist_tail(list)) = node;
(flist_tail(list))->next = node;
flist_tail(list) = node;
++flist_size(list);
list->size++;
return 0;
}
int
flist_prepend(flist_t *list,int id,void *data)
int flist_prepend(flist_t *list,int id,void *data)
{
flist_node_t *node;
if(!list) {
fprintf(stderr,"flist_prepend in NULL list\n");
return -1;
}
if ( (node = malloc(sizeof(flist_node_t))) == NULL )
return -1;
node->id=id;
flist_data(node) = data;
flist_next(node) = flist_head(list);
node->data = data;
node->next = list->head;
flist_head(list) = node;
if ( flist_tail(list) == NULL )
flist_tail(list) = node;
++flist_size(list);
list->size++;
return 0;
}
void *
flist_pop_first(flist_t *list)
void *flist_pop_first(flist_t *list)
{
void *d;
flist_node_t *node;
if(!list) {
fprintf(stderr,"flist_pop_first in NULL list\n");
return NULL;
}
if ( flist_head(list) == NULL )
return NULL;
......@@ -61,24 +78,31 @@ flist_pop_first(flist_t *list)
return d;
}
void
flist_init(flist_t *list)
void flist_init(flist_t *list)
{
if(!list) {
fprintf(stderr,"flist_init in NULL list\n");
return;
}
flist_head(list) = flist_tail(list) = NULL;
flist_size(list) = 0;
}
void
flist_destroy(flist_t *list,flist_destroy_t dealloc)
void flist_destroy(flist_t *list,flist_destroy_t dealloc)
{
flist_node_t *node;
if(!list) {
fprintf(stderr,"flist_destroy in NULL list\n");
return;
}
while( (node = flist_head(list)) )
{
flist_head(list) = flist_next(node);
if ( dealloc == FLIST_FREE_DATA )
free(flist_data(node));
free(node->data);
free(node);
}
flist_tail(list) = NULL;
......@@ -87,32 +111,45 @@ flist_destroy(flist_t *list,flist_destroy_t dealloc)
void* flist_get(flist_t *list, int id)
{
flist_node_t *node=flist_head(list);
flist_node_t *node;
if(!list) {
fprintf(stderr,"flist_get in NULL list\n");
return NULL;
}
node=flist_head(list);
while(node!=NULL) {
if(node->id==id)
return node->data;
else
node=flist_next(node);
}
while(node!=NULL) {
if(node->id==id)
return node->data;
node=node->next;
}
return NULL;
}
int flist_get_next_id(flist_t *list, int id)
{
flist_node_t *node=flist_head(list);
flist_node_t *node;
if(!list) {
fprintf(stderr,"flist_get_next_id in NULL List\n");
return 0;
}
node=flist_head(list);
while(node!=NULL) {
if(node->id==id) {
node=flist_next(node);
node=node->next;
if(node==NULL)
return 0;
return 0;
else
return node->id;
return node->id;
}
else
node=flist_next(node);
node=flist_next(node);
}
return 0;
......@@ -120,34 +157,56 @@ int flist_get_next_id(flist_t *list, int id)
void flist_move_before(flist_t *list,int before,int id) {
void *data=flist_remove(list,id,FLIST_LEAVE_DATA);
if(data==NULL) {
fprintf(stderr,"flist:: Cannot move not existent content!\n");
return;
}
flist_insert(list,id,data,before);
}
void* flist_remove(flist_t *list,int id,flist_destroy_t dealloc)
{
flist_node_t *node=flist_head(list);
flist_node_t *node;
flist_node_t *p=NULL;
void *data;
while(node!=NULL) {
if(node->id==id) {
--flist_size(list);
data=node->data;
if(p==NULL)
flist_head(list)=node->next;
else
p->next=node->next;
if(flist_tail(list)==node)
flist_tail(list)=p;
if(dealloc==FLIST_FREE_DATA)
free(flist_data(node));
free(node);
return data;
}
else {
p=node;
node=flist_next(node);
}
if(!list) {
fprintf(stderr,"flist:: flist_remove in NULL list\n");
return NULL;
}
node=flist_head(list);
while(node!=NULL) {
if(node->id==id) {
--flist_size(list);
data=node->data;
if(p==NULL)
flist_head(list)=node->next;
else
p->next=node->next;
if(flist_tail(list)==node)
flist_tail(list)=p;
if(dealloc==FLIST_FREE_DATA) {
free(node->data);
}
free(node);
if(dealloc==FLIST_FREE_DATA)
return FLIST_FREE_DATA_ADDR;
else
return data;
}
else {
p=node;
node=flist_next(node);
}
}
return NULL;
......@@ -157,9 +216,16 @@ int
flist_insert(flist_t *list, int id, void* data, int index)
{
int i;
flist_node_t* head = flist_head(list);
flist_node_t* head;
flist_node_t* prev=NULL;
flist_node_t* node;
if(!list) {
printf("flist:: flist_insert in NULL list\n");
return -1;
}
head = flist_head(list);
if (index == 0)
return flist_prepend(list, id, data);
......@@ -177,7 +243,7 @@ flist_insert(flist_t *list, int id, void* data, int index)
if (i == index)
{
node->next = head;
flist_next(prev) = node;
prev->next = node;
}
prev = head;
}
......@@ -192,6 +258,11 @@ void flist_reverse(flist_t* list)
flist_node_t* prev=NULL;
flist_node_t* next=NULL;
if(!list) {
printf("flist_reverse in NULL list\n");
return;
}
if (flist_head(list) == NULL)
return;
......
......@@ -118,6 +118,9 @@ extern inline void* flist_get(flist_t *list,int id);
*/
extern inline int flist_get_next_id(flist_t *list,int id);
extern int flist_default_free_data;
#define FLIST_FREE_DATA_ADDR ((void *)&flist_default_free_data)
#ifdef DIMAPI
/** \brief Searches for a mathcing node and returns it
Returns only the first matching node.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment