-/* @(#) $Id$ */
+/* @(#) $Id: ./src/shared/dirtree_op.c, 2011/09/08 dcid Exp $
+ */
/* Copyright (C) 2009 Trend Micro Inc.
* All rights reserved.
* License details at the LICENSE file included with OSSEC or
* online at: http://www.ossec.net/en/licensing.html
*/
-
-/* Common API for dealing with directory trees */
+
+/* Common API for dealing with directory trees */
#include "shared.h"
-/* Create the tree
+/* Create the tree
* Return NULL on error
*/
OSDirTree *OSDirTree_Create()
{
return(NULL);
}
-
+
my_tree->first_node = NULL;
my_tree->last_node = NULL;
-
+
return(my_tree);
}
-/* Get first node from tree (starting from parent)
+/* Get first node from tree (starting from parent)
* Returns null on invalid tree (not initialized)
*/
OSTreeNode *OSDirTree_GetFirstNode(OSDirTree *tree)
* Internal call, looks up for an entry in the middle of the tree.
* Should not be called directly.
*/
-OSDirTree *_OSTreeNode_Add(OSDirTree *tree, char *str,
+OSDirTree *_OSTreeNode_Add(OSDirTree *tree, char *str,
void *data, char sep)
{
char *tmp_str;
tree->first_node = NULL;
tree->last_node = NULL;
}
-
+
curnode = tree->first_node;
{
os_calloc(1, sizeof(OSTreeNode), newnode);
//printf("XXXX Adding node: %s\n", str);
-
+
if(!tree->first_node && !tree->last_node)
{
{
*tmp_str = sep;
}
-
+
return(tree);
}
-
+
/** void OSDirTree_AddToTree
char *tmp_str;
OSTreeNode *newnode;
OSTreeNode *curnode;
-
-
+
+
/* First character doesn't count as a separator */
tmp_str = strchr(str +1, sep);
if(tmp_str)
{
*tmp_str = '\0';
}
-
-
+
+
curnode = tree->first_node;
while(curnode)
{
/* If we have other elements, keep going */
if(tmp_str)
{
- curnode->child = _OSTreeNode_Add(curnode->child,
+ curnode->child = _OSTreeNode_Add(curnode->child,
tmp_str +1, data, sep);
}
break;
tree->last_node->next = newnode;
tree->last_node = newnode;
}
-
+
newnode->next = NULL;
os_strdup(str, newnode->value);
/* If we have other elements, keep going */
if(tmp_str)
{
- newnode->child = _OSTreeNode_Add(newnode->child,
+ newnode->child = _OSTreeNode_Add(newnode->child,
tmp_str +1, data, sep);
newnode->data = NULL;
}
{
*tmp_str = sep;
}
-
+
return(ret);
}