X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=blobdiff_plain;f=src%2Fshared%2Fdirtree_op.c;h=47adbb44ee674d01b1b2faf68213560b6dfdc3b4;hb=6ef2f786c6c8ead94841b5f93baf9f43421f08c8;hp=5d469b53207ca2f0106f429cedc6a65764d0f6e8;hpb=914feba5d54f979cd5d7e69c349c3d01f630042a;p=ossec-hids.git diff --git a/src/shared/dirtree_op.c b/src/shared/dirtree_op.c index 5d469b5..47adbb4 100755 --- a/src/shared/dirtree_op.c +++ b/src/shared/dirtree_op.c @@ -1,25 +1,26 @@ -/* @(#) $Id: dirtree_op.c,v 1.4 2009/06/24 18:53:08 dcid Exp $ */ +/* @(#) $Id: ./src/shared/dirtree_op.c, 2011/09/08 dcid Exp $ + */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * 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() @@ -31,16 +32,16 @@ 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) @@ -54,7 +55,7 @@ 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; @@ -82,7 +83,7 @@ OSDirTree *_OSTreeNode_Add(OSDirTree *tree, char *str, tree->first_node = NULL; tree->last_node = NULL; } - + curnode = tree->first_node; @@ -108,7 +109,7 @@ OSDirTree *_OSTreeNode_Add(OSDirTree *tree, char *str, { os_calloc(1, sizeof(OSTreeNode), newnode); //printf("XXXX Adding node: %s\n", str); - + if(!tree->first_node && !tree->last_node) { @@ -146,11 +147,11 @@ OSDirTree *_OSTreeNode_Add(OSDirTree *tree, char *str, { *tmp_str = sep; } - + return(tree); } - + /** void OSDirTree_AddToTree @@ -168,16 +169,16 @@ void OSDirTree_AddToTree(OSDirTree *tree, char *str, void *data, char sep) 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) { @@ -186,7 +187,7 @@ void OSDirTree_AddToTree(OSDirTree *tree, char *str, void *data, char sep) /* 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; @@ -213,7 +214,7 @@ void OSDirTree_AddToTree(OSDirTree *tree, char *str, void *data, char sep) tree->last_node->next = newnode; tree->last_node = newnode; } - + newnode->next = NULL; os_strdup(str, newnode->value); @@ -221,7 +222,7 @@ void OSDirTree_AddToTree(OSDirTree *tree, char *str, void *data, char sep) /* 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; } @@ -290,7 +291,7 @@ void *OSDirTree_SearchTree(OSDirTree *tree, char *str, char sep) { *tmp_str = sep; } - + return(ret); }