From 95cf2209fe50c127e88d0021ac93b36c73a407c5 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 20 Sep 2010 10:18:23 -0400 Subject: [PATCH] freetdm: make conf nodes to be stored in FIFO order --- libs/freetdm/src/ftdm_config.c | 25 +++++++++++++------ libs/freetdm/src/include/private/ftdm_types.h | 6 +++++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/libs/freetdm/src/ftdm_config.c b/libs/freetdm/src/ftdm_config.c index 4ba2e19c67..f6d9c1ae30 100644 --- a/libs/freetdm/src/ftdm_config.c +++ b/libs/freetdm/src/ftdm_config.c @@ -268,13 +268,24 @@ FT_DECLARE(ftdm_status_t) ftdm_conf_node_create(const char *name, ftdm_conf_node if (parent) { /* store who my parent is */ newnode->parent = parent; - /* save any siblings */ - sibling = parent->child; - /* as a newborn I am first */ - parent->child = newnode; - if (sibling) { - /* store a pointer to my next sibling */ - newnode->next = sibling; + + /* arrange them in FIFO order (newnode should be last) */ + if (!parent->child) { + /* we're the first node being added */ + parent->child = newnode; + } else { + if (!parent->last) { + /* we're the second node being added */ + parent->last = newnode; + parent->child->next = newnode; + newnode->prev = parent->child; + } else { + /* we're the third or Nth node to be added */ + sibling = parent->last; + sibling->next = newnode; + parent->last = newnode; + newnode->prev = sibling; + } } } diff --git a/libs/freetdm/src/include/private/ftdm_types.h b/libs/freetdm/src/include/private/ftdm_types.h index ba6956344d..d0d19e5a55 100644 --- a/libs/freetdm/src/include/private/ftdm_types.h +++ b/libs/freetdm/src/include/private/ftdm_types.h @@ -322,9 +322,15 @@ struct ftdm_conf_node { /* first node child */ struct ftdm_conf_node *child; + /* last node child */ + struct ftdm_conf_node *last; + /* next node sibling */ struct ftdm_conf_node *next; + /* prev node sibling */ + struct ftdm_conf_node *prev; + /* my parent if any */ struct ftdm_conf_node *parent; };