From 06ae9ac5d98a752d8ca17686a4a3b1786fbe520d Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 18 Jul 2002 23:00:24 +0000 Subject: virtual registry framework with initial printing hooks. (This used to be commit a43d9788fa8823d678ee72470421b980165ec2b0) --- source3/lib/adt_tree.c | 414 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 414 insertions(+) create mode 100644 source3/lib/adt_tree.c (limited to 'source3/lib/adt_tree.c') diff --git a/source3/lib/adt_tree.c b/source3/lib/adt_tree.c new file mode 100644 index 0000000000..e3519c6c41 --- /dev/null +++ b/source3/lib/adt_tree.c @@ -0,0 +1,414 @@ +/* + * Unix SMB/CIFS implementation. + * Generic Abstract Data Types + * Copyright (C) Gerald Carter 2002. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "includes.h" + + +/************************************************************************** + Initialize the tree's root. The cmp_fn is a callback function used + for comparision of two children + *************************************************************************/ + +SORTED_TREE* sorted_tree_init( int (cmp_fn)(void*, void*), + void (free_fn)(void*) ) +{ + SORTED_TREE *tree = NULL; + + if ( !(tree = (SORTED_TREE*)malloc( sizeof(SORTED_TREE) )) ) + return NULL; + + ZERO_STRUCTP( tree ); + + tree->compare = cmp_fn; + tree->free = free_fn; + + if ( !(tree->root = (TREE_NODE*)malloc( sizeof(TREE_NODE) )) ) { + SAFE_FREE( tree ); + return NULL; + } + + ZERO_STRUCTP( tree->root ); + + return tree; +} + + +/************************************************************************** + Delete a tree and free all allocated memory + *************************************************************************/ + +static void sorted_tree_destroy_children( TREE_NODE *root ) +{ + int i; + + if ( !root ) + return; + + for ( i=0; inum_children; i++ ) + { + sorted_tree_destroy_children( root->children[i] ); + } + + SAFE_FREE( root->children ); + SAFE_FREE( root->key ); + + return; +} + +/************************************************************************** + Delete a tree and free all allocated memory + *************************************************************************/ + +void sorted_tree_destroy( SORTED_TREE *tree ) +{ + if ( tree->root ) + sorted_tree_destroy_children( tree->root ); + + if ( tree->free ) + tree->free( tree->root ); + + SAFE_FREE( tree ); +} + +/************************************************************************** + Find the next child given a key string + *************************************************************************/ + +static TREE_NODE* sorted_tree_birth_child( TREE_NODE *node, char* key ) +{ + TREE_NODE *infant = NULL; + TREE_NODE *child, *crib; + TREE_NODE **siblings; + int i, result; + + if ( !(infant = (TREE_NODE*)malloc( sizeof(TREE_NODE) )) ) + return NULL; + + ZERO_STRUCTP( infant ); + + infant->key = strdup( key ); + infant->parent = node; + + siblings = Realloc( node->children, sizeof(TREE_NODE*)*(node->num_children+1) ); + + if ( siblings ) + node->children = siblings; + + node->num_children++; + + /* first child */ + + if ( node->num_children == 1 ) { + DEBUG(11,("sorted_tree_birth_child: First child of node [%s]! [%s]\n", + node->key ? node->key : "NULL", infant->key )); + node->children[0] = infant; + } + else + { + /* + * multiple siblings .... (at least 2 children) + * + * work from the end of the list forward + * The last child is not set at this point + * Insert the new infanct in ascending order + * from left to right + */ + + for ( i = node->num_children-1; i>=1; i-- ) + { + crib = node->children[i]; + child = node->children[i-1]; + + DEBUG(10,("sorted_tree_birth_child: Looking for crib; infant -> [%s], child -> [%s]\n", + infant->key, child->key)); + + /* the strings should never match assuming that we + have called sorted_tree_find_child() first */ + + result = StrCaseCmp( infant->key, child->key ); + if ( result > 0 ) { + crib = infant; + break; + } + + crib = child; + } + } + + return infant; +} +/************************************************************************** + Find the next child given a key string + *************************************************************************/ + +static TREE_NODE* sorted_tree_find_child( TREE_NODE *node, char* key ) +{ + TREE_NODE *next = NULL; + int i, result; + + if ( !node ) { + DEBUG(0,("sorted_tree_find_child: NULL node passed into function!\n")); + return NULL; + } + + if ( !key ) { + DEBUG(0,("sorted_tree_find_child: NULL key string passed into function!\n")); + return NULL; + } + + for ( i=0; i<(node->num_children); i++ ) + { + result = StrCaseCmp( key, node->children[i]->key ); + + if ( result == 0 ) + next = node->children[i]; + + /* if result > 0 then we've gone to far because + the list of children is sorted by key name + If result == 0, then we have a match */ + + if ( !(result < 0) ) + break; + } + + DEBUG(11,("sorted_tree_find_child: Did %s find [%s]\n", + next ? "" : "not", key )); + + return next; +} + +/************************************************************************** + Add a new node into the tree given a key path and a blob of data + *************************************************************************/ + +BOOL sorted_tree_add( SORTED_TREE *tree, const char *path, void *data_p ) +{ + char *str, *base, *path2; + TREE_NODE *current, *next; + BOOL ret = True; + + DEBUG(8,("sorted_tree_add: Enter\n")); + + if ( !path || *path != '/' ) { + DEBUG(0,("sorted_tree_add: Attempt to add a node with a bad path [%s]\n", + path ? path : "NULL" )); + return False; + } + + if ( !tree ) { + DEBUG(0,("sorted_tree_add: Attempt to add a node to an uninitialized tree!\n")); + return False; + } + + /* move past the first '/' */ + + path++; + path2 = strdup( path ); + if ( !path2 ) { + DEBUG(0,("sorted_tree_add: strdup() failed on string [%s]!?!?!\n", path)); + return False; + } + + + /* + * this works sort of like a 'mkdir -p' call, possibly + * creating an entire path to the new node at once + * The path should be of the form ///... + */ + + base = path2; + str = path2; + current = tree->root; + + do { + /* break off the remaining part of the path */ + + str = strchr( str, '/' ); + if ( str ) + *str = '\0'; + + /* iterate to the next child--birth it if necessary */ + + next = sorted_tree_find_child( current, base ); + if ( !next ) { + next = sorted_tree_birth_child( current, base ); + if ( !next ) { + DEBUG(0,("sorted_tree_add: Failed to create new child!\n")); + ret = False; + goto done; + } + } + current = next; + + /* setup the next part of the path */ + + base = str; + if ( base ) { + *base = '/'; + base++; + str = base; + } + + } while ( base != NULL ); + + current->data_p = data_p; + + DEBUG(10,("sorted_tree_add: Successfully added node [%s] to tree\n", + path )); + + DEBUG(8,("sorted_tree_add: Exit\n")); + +done: + SAFE_FREE( path2 ); + return ret; +} + + +/************************************************************************** + Recursive routine to print out all children of a TREE_NODE + *************************************************************************/ + +static void sorted_tree_print_children( TREE_NODE *node, int debug, char *path ) +{ + int i; + int num_children; + pstring path2; + + if ( !node ) + return; + + + if ( node->key ) + DEBUG(debug,("%s: [%s] (%s)\n", path ? path : "NULL", node->key, + node->data_p ? "data" : "NULL" )); + + *path2 = '\0'; + if ( path ) + pstrcpy( path2, path ); + pstrcat( path2, node->key ? node->key : "NULL" ); + pstrcat( path2, "/" ); + + num_children = node->num_children; + for ( i=0; ichildren[i], debug, path2 ); + + +} + +/************************************************************************** + Dump the kys for a tree to the log file + *************************************************************************/ + +void sorted_tree_print_keys( SORTED_TREE *tree, int debug ) +{ + int i; + int num_children = tree->root->num_children; + + if ( tree->root->key ) + DEBUG(debug,("ROOT/: [%s] (%s)\n", tree->root->key, + tree->root->data_p ? "data" : "NULL" )); + + for ( i=0; iroot->children[i], debug, + tree->root->key ? tree->root->key : "ROOT/" ); + } + +} + +/************************************************************************** + return the data_p for for the node in tree matching the key string + The key string is the full path. We must break it apart and walk + the tree + *************************************************************************/ + +void* sorted_tree_find( SORTED_TREE *tree, char *key ) +{ + char *keystr, *base, *str; + TREE_NODE *current; + void *result = NULL; + + DEBUG(10,("sorted_tree_find: Enter [%s]\n", key ? key : "NULL" )); + + /* sanity checks first */ + + if ( !key ) { + DEBUG(0,("sorted_tree_find: Attempt to search tree using NULL search string!\n")); + return NULL; + } + + if ( !tree ) { + DEBUG(0,("sorted_tree_find: Attempt to search an uninitialized tree using string [%s]!\n", + key ? key : "NULL" )); + return NULL; + } + + if ( !tree->root ) + return NULL; + + /* make a copy to play with */ + + keystr = strdup( key ); + if ( !keystr ) { + DEBUG(0,("sorted_tree_find: strdup() failed on string [%s]!?!?!\n", key)); + return NULL; + } + + /* start breaking the path apart */ + + base = keystr; + str = keystr; + current = tree->root; + + do + { + /* break off the remaining part of the path */ + + str = strchr( str, '/' ); + if ( str ) + *str = '\0'; + + DEBUG(10,("sorted_tree_find: [loop] key => [%s]\n", base)); + + /* iterate to the next child */ + + current = sorted_tree_find_child( current, base ); + + /* setup the next part of the path */ + + base = str; + if ( base ) { + *base = '/'; + base++; + str = base; + } + + } while ( base && current ); + + if ( current ) + result = current->data_p; + + SAFE_FREE( keystr ); + + DEBUG(10,("sorted_tree_find: Exit\n")); + + return result; +} + + -- cgit From 9fe3bd1259e7bda901f7a264bd7fc88c72d2112f Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 19 Jul 2002 18:49:44 +0000 Subject: * refactored registry operations some. subkey lists and registry values are now passed around in containers (REGSUBKEY_CTR & REGVAL_CTR) which each possess a TALLOC_CTX. * removed subkey_specific_fn() from REGISTRY_OPS. Is implemented in the form of a wrapper * temporarily broke the printing registry ops. * implemented inheritence for the data_p of nodes in a SORTED_TREE * All REGISTRY_KEY instances now store a valid REGISTRY_HOOK since the default REGOSTRY_OPS structure is stored in the root of the cache_tree. * Probably some other change I forgot.... T (This used to be commit e7b55e8f017e638342d9c8c1a9259000745a0298) --- source3/lib/adt_tree.c | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) (limited to 'source3/lib/adt_tree.c') diff --git a/source3/lib/adt_tree.c b/source3/lib/adt_tree.c index e3519c6c41..3a6e722c97 100644 --- a/source3/lib/adt_tree.c +++ b/source3/lib/adt_tree.c @@ -26,7 +26,8 @@ for comparision of two children *************************************************************************/ -SORTED_TREE* sorted_tree_init( int (cmp_fn)(void*, void*), +SORTED_TREE* sorted_tree_init( void *data_p, + int (cmp_fn)(void*, void*), void (free_fn)(void*) ) { SORTED_TREE *tree = NULL; @@ -45,6 +46,7 @@ SORTED_TREE* sorted_tree_init( int (cmp_fn)(void*, void*), } ZERO_STRUCTP( tree->root ); + tree->root->data_p = data_p; return tree; } @@ -94,7 +96,6 @@ void sorted_tree_destroy( SORTED_TREE *tree ) static TREE_NODE* sorted_tree_birth_child( TREE_NODE *node, char* key ) { TREE_NODE *infant = NULL; - TREE_NODE *child, *crib; TREE_NODE **siblings; int i, result; @@ -116,7 +117,7 @@ static TREE_NODE* sorted_tree_birth_child( TREE_NODE *node, char* key ) /* first child */ if ( node->num_children == 1 ) { - DEBUG(11,("sorted_tree_birth_child: First child of node [%s]! [%s]\n", + DEBUG(10,("sorted_tree_birth_child: First child of node [%s]! [%s]\n", node->key ? node->key : "NULL", infant->key )); node->children[0] = infant; } @@ -133,23 +134,28 @@ static TREE_NODE* sorted_tree_birth_child( TREE_NODE *node, char* key ) for ( i = node->num_children-1; i>=1; i-- ) { - crib = node->children[i]; - child = node->children[i-1]; - DEBUG(10,("sorted_tree_birth_child: Looking for crib; infant -> [%s], child -> [%s]\n", - infant->key, child->key)); + infant->key, node->children[i-1]->key)); /* the strings should never match assuming that we have called sorted_tree_find_child() first */ - result = StrCaseCmp( infant->key, child->key ); + result = StrCaseCmp( infant->key, node->children[i-1]->key ); if ( result > 0 ) { - crib = infant; + node->children[i] = infant; break; } - - crib = child; + + /* bump everything towards the end on slot */ + + node->children[i] = node->children[i-1]; } + + /* if we haven't found the correct clot yet, the child + will be first in the list */ + + if ( i == 0 ) + node->children[0] = infant; } return infant; @@ -376,6 +382,9 @@ void* sorted_tree_find( SORTED_TREE *tree, char *key ) str = keystr; current = tree->root; + if ( tree->root->data_p ) + result = tree->root->data_p; + do { /* break off the remaining part of the path */ @@ -384,7 +393,7 @@ void* sorted_tree_find( SORTED_TREE *tree, char *key ) if ( str ) *str = '\0'; - DEBUG(10,("sorted_tree_find: [loop] key => [%s]\n", base)); + DEBUG(11,("sorted_tree_find: [loop] key => [%s]\n", base)); /* iterate to the next child */ @@ -399,10 +408,18 @@ void* sorted_tree_find( SORTED_TREE *tree, char *key ) str = base; } + /* + * the idea is that the data_p for a parent should + * be inherited by all children, but allow it to be + * overridden farther down + */ + + if ( current && current->data_p ) + result = current->data_p; + } while ( base && current ); - - if ( current ) - result = current->data_p; + + /* result should be the data_p from the lowest match node in the tree */ SAFE_FREE( keystr ); -- cgit From 3c0a9c46d8057b9499d7d48a67ba15f9942d558a Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 19 Jul 2002 22:16:03 +0000 Subject: fixed seg fault in registry frontend caused by trying to use a destroyed TALLOC_CTX* (This used to be commit 432b9f8d7c20fbf3b2a0906c8a93272abbe43fb6) --- source3/lib/adt_tree.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/lib/adt_tree.c') diff --git a/source3/lib/adt_tree.c b/source3/lib/adt_tree.c index 3a6e722c97..9c4ad423c1 100644 --- a/source3/lib/adt_tree.c +++ b/source3/lib/adt_tree.c @@ -420,6 +420,8 @@ void* sorted_tree_find( SORTED_TREE *tree, char *key ) } while ( base && current ); /* result should be the data_p from the lowest match node in the tree */ + if ( result ) + DEBUG(10,("sorted_tree_find: Found data_p!\n")); SAFE_FREE( keystr ); -- cgit From 39bbeff5b361ffa6a5ff9273cf7fce5f46543703 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sat, 20 Jul 2002 02:42:04 +0000 Subject: fixed a logic error in the sorted_tree_find_child() routine that caused a valid search to fail. The printing registry view now works again. (This used to be commit 2050859f03493d5135984ce1e42baf8f1f2566b9) --- source3/lib/adt_tree.c | 95 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 63 insertions(+), 32 deletions(-) (limited to 'source3/lib/adt_tree.c') diff --git a/source3/lib/adt_tree.c b/source3/lib/adt_tree.c index 9c4ad423c1..2c18bb1198 100644 --- a/source3/lib/adt_tree.c +++ b/source3/lib/adt_tree.c @@ -21,6 +21,33 @@ #include "includes.h" +/************************************************************************** + Initialize the tree's root. The cmp_fn is a callback function used + for comparision of two children + *************************************************************************/ + +static BOOL trim_tree_keypath( char *path, char **base, char **new_path ) +{ + char *p; + + *new_path = *base = NULL; + + if ( !path ) + return False; + + *base = path; + + p = strchr( path, '/' ); + + if ( p ) { + *p = '\0'; + *new_path = p+1; + } + + return True; +} + + /************************************************************************** Initialize the tree's root. The cmp_fn is a callback function used for comparision of two children @@ -97,7 +124,7 @@ static TREE_NODE* sorted_tree_birth_child( TREE_NODE *node, char* key ) { TREE_NODE *infant = NULL; TREE_NODE **siblings; - int i, result; + int i; if ( !(infant = (TREE_NODE*)malloc( sizeof(TREE_NODE) )) ) return NULL; @@ -117,7 +144,7 @@ static TREE_NODE* sorted_tree_birth_child( TREE_NODE *node, char* key ) /* first child */ if ( node->num_children == 1 ) { - DEBUG(10,("sorted_tree_birth_child: First child of node [%s]! [%s]\n", + DEBUG(11,("sorted_tree_birth_child: First child of node [%s]! [%s]\n", node->key ? node->key : "NULL", infant->key )); node->children[0] = infant; } @@ -134,14 +161,15 @@ static TREE_NODE* sorted_tree_birth_child( TREE_NODE *node, char* key ) for ( i = node->num_children-1; i>=1; i-- ) { - DEBUG(10,("sorted_tree_birth_child: Looking for crib; infant -> [%s], child -> [%s]\n", + DEBUG(11,("sorted_tree_birth_child: Looking for crib; infant -> [%s], child -> [%s]\n", infant->key, node->children[i-1]->key)); /* the strings should never match assuming that we have called sorted_tree_find_child() first */ - result = StrCaseCmp( infant->key, node->children[i-1]->key ); - if ( result > 0 ) { + if ( StrCaseCmp( infant->key, node->children[i-1]->key ) > 0 ) { + DEBUG(11,("sorted_tree_birth_child: storing infant in i == [%d]\n", + i)); node->children[i] = infant; break; } @@ -150,8 +178,10 @@ static TREE_NODE* sorted_tree_birth_child( TREE_NODE *node, char* key ) node->children[i] = node->children[i-1]; } + + DEBUG(11,("sorted_tree_birth_child: Exiting loop (i == [%d])\n", i )); - /* if we haven't found the correct clot yet, the child + /* if we haven't found the correct slot yet, the child will be first in the list */ if ( i == 0 ) @@ -160,6 +190,7 @@ static TREE_NODE* sorted_tree_birth_child( TREE_NODE *node, char* key ) return infant; } + /************************************************************************** Find the next child given a key string *************************************************************************/ @@ -179,9 +210,12 @@ static TREE_NODE* sorted_tree_find_child( TREE_NODE *node, char* key ) return NULL; } - for ( i=0; i<(node->num_children); i++ ) - { - result = StrCaseCmp( key, node->children[i]->key ); + for ( i=0; inum_children; i++ ) + { + DEBUG(11,("sorted_tree_find_child: child key => [%s]\n", + node->children[i]->key)); + + result = StrCaseCmp( node->children[i]->key, key ); if ( result == 0 ) next = node->children[i]; @@ -190,12 +224,12 @@ static TREE_NODE* sorted_tree_find_child( TREE_NODE *node, char* key ) the list of children is sorted by key name If result == 0, then we have a match */ - if ( !(result < 0) ) + if ( result > 0 ) break; } - DEBUG(11,("sorted_tree_find_child: Did %s find [%s]\n", - next ? "" : "not", key )); + DEBUG(11,("sorted_tree_find_child: %s [%s]\n", + next ? "Found" : "Did not find", key )); return next; } @@ -346,7 +380,7 @@ void sorted_tree_print_keys( SORTED_TREE *tree, int debug ) void* sorted_tree_find( SORTED_TREE *tree, char *key ) { - char *keystr, *base, *str; + char *keystr, *base, *str, *p; TREE_NODE *current; void *result = NULL; @@ -370,7 +404,11 @@ void* sorted_tree_find( SORTED_TREE *tree, char *key ) /* make a copy to play with */ - keystr = strdup( key ); + if ( *key == '/' ) + keystr = strdup( key+1 ); + else + keystr = strdup( key ); + if ( !keystr ) { DEBUG(0,("sorted_tree_find: strdup() failed on string [%s]!?!?!\n", key)); return NULL; @@ -378,8 +416,7 @@ void* sorted_tree_find( SORTED_TREE *tree, char *key ) /* start breaking the path apart */ - base = keystr; - str = keystr; + p = keystr; current = tree->root; if ( tree->root->data_p ) @@ -388,25 +425,15 @@ void* sorted_tree_find( SORTED_TREE *tree, char *key ) do { /* break off the remaining part of the path */ - - str = strchr( str, '/' ); - if ( str ) - *str = '\0'; + + trim_tree_keypath( p, &base, &str ); - DEBUG(11,("sorted_tree_find: [loop] key => [%s]\n", base)); + DEBUG(11,("sorted_tree_find: [loop] base => [%s], new_path => [%s]\n", + base, str)); /* iterate to the next child */ current = sorted_tree_find_child( current, base ); - - /* setup the next part of the path */ - - base = str; - if ( base ) { - *base = '/'; - base++; - str = base; - } /* * the idea is that the data_p for a parent should @@ -416,12 +443,16 @@ void* sorted_tree_find( SORTED_TREE *tree, char *key ) if ( current && current->data_p ) result = current->data_p; + + /* reset the path pointer 'p' to the remaining part of the key string */ + + p = str; - } while ( base && current ); + } while ( str && current ); /* result should be the data_p from the lowest match node in the tree */ if ( result ) - DEBUG(10,("sorted_tree_find: Found data_p!\n")); + DEBUG(11,("sorted_tree_find: Found data_p!\n")); SAFE_FREE( keystr ); -- cgit From 634c54310c92c48dd4eceec602e230a021bdcfc5 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 3 Jan 2003 08:28:12 +0000 Subject: Merge from HEAD - make Samba compile with -Wwrite-strings without additional warnings. (Adds a lot of const). Andrew Bartlett (This used to be commit 3a7458f9472432ef12c43008414925fd1ce8ea0c) --- source3/lib/adt_tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/adt_tree.c') diff --git a/source3/lib/adt_tree.c b/source3/lib/adt_tree.c index 2c18bb1198..0bc224ec23 100644 --- a/source3/lib/adt_tree.c +++ b/source3/lib/adt_tree.c @@ -325,7 +325,7 @@ done: Recursive routine to print out all children of a TREE_NODE *************************************************************************/ -static void sorted_tree_print_children( TREE_NODE *node, int debug, char *path ) +static void sorted_tree_print_children( TREE_NODE *node, int debug, const char *path ) { int i; int num_children; -- cgit From 79d5739893dca1272b60d6566ccb728c73c4240e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 26 Feb 2004 02:11:31 +0000 Subject: fixed compilation with --enable-dmalloc the macro redefinition of free() means we cannot have a structure element called "free" (This used to be commit d2d653a1a6db9d0407e99affb317a0045e56168a) --- source3/lib/adt_tree.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/lib/adt_tree.c') diff --git a/source3/lib/adt_tree.c b/source3/lib/adt_tree.c index 0bc224ec23..bd857e205a 100644 --- a/source3/lib/adt_tree.c +++ b/source3/lib/adt_tree.c @@ -65,7 +65,7 @@ SORTED_TREE* sorted_tree_init( void *data_p, ZERO_STRUCTP( tree ); tree->compare = cmp_fn; - tree->free = free_fn; + tree->free_func = free_fn; if ( !(tree->root = (TREE_NODE*)malloc( sizeof(TREE_NODE) )) ) { SAFE_FREE( tree ); @@ -110,8 +110,8 @@ void sorted_tree_destroy( SORTED_TREE *tree ) if ( tree->root ) sorted_tree_destroy_children( tree->root ); - if ( tree->free ) - tree->free( tree->root ); + if ( tree->free_func ) + tree->free_func( tree->root ); SAFE_FREE( tree ); } -- cgit From acf9d61421faa6c0055d57fdee7db300dc5431aa Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 7 Dec 2004 18:25:53 +0000 Subject: r4088: Get medieval on our ass about malloc.... :-). Take control of all our allocation functions so we can funnel through some well known functions. Should help greatly with malloc checking. HEAD patch to follow. Jeremy. (This used to be commit 620f2e608f70ba92f032720c031283d295c5c06a) --- source3/lib/adt_tree.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source3/lib/adt_tree.c') diff --git a/source3/lib/adt_tree.c b/source3/lib/adt_tree.c index bd857e205a..a5d6380377 100644 --- a/source3/lib/adt_tree.c +++ b/source3/lib/adt_tree.c @@ -59,7 +59,7 @@ SORTED_TREE* sorted_tree_init( void *data_p, { SORTED_TREE *tree = NULL; - if ( !(tree = (SORTED_TREE*)malloc( sizeof(SORTED_TREE) )) ) + if ( !(tree = SMB_MALLOC_P(SORTED_TREE)) ) return NULL; ZERO_STRUCTP( tree ); @@ -67,7 +67,7 @@ SORTED_TREE* sorted_tree_init( void *data_p, tree->compare = cmp_fn; tree->free_func = free_fn; - if ( !(tree->root = (TREE_NODE*)malloc( sizeof(TREE_NODE) )) ) { + if ( !(tree->root = SMB_MALLOC_P(TREE_NODE)) ) { SAFE_FREE( tree ); return NULL; } @@ -126,15 +126,15 @@ static TREE_NODE* sorted_tree_birth_child( TREE_NODE *node, char* key ) TREE_NODE **siblings; int i; - if ( !(infant = (TREE_NODE*)malloc( sizeof(TREE_NODE) )) ) + if ( !(infant = SMB_MALLOC_P(TREE_NODE)) ) return NULL; ZERO_STRUCTP( infant ); - infant->key = strdup( key ); + infant->key = SMB_STRDUP( key ); infant->parent = node; - siblings = Realloc( node->children, sizeof(TREE_NODE*)*(node->num_children+1) ); + siblings = SMB_REALLOC_ARRAY( node->children, TREE_NODE *, node->num_children+1 ); if ( siblings ) node->children = siblings; @@ -260,7 +260,7 @@ BOOL sorted_tree_add( SORTED_TREE *tree, const char *path, void *data_p ) /* move past the first '/' */ path++; - path2 = strdup( path ); + path2 = SMB_STRDUP( path ); if ( !path2 ) { DEBUG(0,("sorted_tree_add: strdup() failed on string [%s]!?!?!\n", path)); return False; @@ -405,9 +405,9 @@ void* sorted_tree_find( SORTED_TREE *tree, char *key ) /* make a copy to play with */ if ( *key == '/' ) - keystr = strdup( key+1 ); + keystr = SMB_STRDUP( key+1 ); else - keystr = strdup( key ); + keystr = SMB_STRDUP( key ); if ( !keystr ) { DEBUG(0,("sorted_tree_find: strdup() failed on string [%s]!?!?!\n", key)); -- cgit From 96a3fede405cd095e353398ff05f4b43a07c457d Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 23 Feb 2005 16:36:44 +0000 Subject: r5517: code cleanup; rename the sorted_tree to pathtree (used by registry code) I was going to use this for tracking dfs mounts in smbclient but found another way. Still the cleanup is valid so commiting it. should be minimally disruptive since it is not widely used. (This used to be commit 00738dca3b07083c91545910486a1f30f2b17281) --- source3/lib/adt_tree.c | 79 +++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 39 deletions(-) (limited to 'source3/lib/adt_tree.c') diff --git a/source3/lib/adt_tree.c b/source3/lib/adt_tree.c index a5d6380377..ad763c2be1 100644 --- a/source3/lib/adt_tree.c +++ b/source3/lib/adt_tree.c @@ -19,6 +19,7 @@ */ #include "includes.h" +#include "adt_tree.h" /************************************************************************** @@ -53,7 +54,7 @@ static BOOL trim_tree_keypath( char *path, char **base, char **new_path ) for comparision of two children *************************************************************************/ -SORTED_TREE* sorted_tree_init( void *data_p, + SORTED_TREE* pathtree_init( void *data_p, int (cmp_fn)(void*, void*), void (free_fn)(void*) ) { @@ -83,7 +84,7 @@ SORTED_TREE* sorted_tree_init( void *data_p, Delete a tree and free all allocated memory *************************************************************************/ -static void sorted_tree_destroy_children( TREE_NODE *root ) +static void pathtree_destroy_children( TREE_NODE *root ) { int i; @@ -92,7 +93,7 @@ static void sorted_tree_destroy_children( TREE_NODE *root ) for ( i=0; inum_children; i++ ) { - sorted_tree_destroy_children( root->children[i] ); + pathtree_destroy_children( root->children[i] ); } SAFE_FREE( root->children ); @@ -105,10 +106,10 @@ static void sorted_tree_destroy_children( TREE_NODE *root ) Delete a tree and free all allocated memory *************************************************************************/ -void sorted_tree_destroy( SORTED_TREE *tree ) + void pathtree_destroy( SORTED_TREE *tree ) { if ( tree->root ) - sorted_tree_destroy_children( tree->root ); + pathtree_destroy_children( tree->root ); if ( tree->free_func ) tree->free_func( tree->root ); @@ -120,7 +121,7 @@ void sorted_tree_destroy( SORTED_TREE *tree ) Find the next child given a key string *************************************************************************/ -static TREE_NODE* sorted_tree_birth_child( TREE_NODE *node, char* key ) +static TREE_NODE* pathtree_birth_child( TREE_NODE *node, char* key ) { TREE_NODE *infant = NULL; TREE_NODE **siblings; @@ -144,7 +145,7 @@ static TREE_NODE* sorted_tree_birth_child( TREE_NODE *node, char* key ) /* first child */ if ( node->num_children == 1 ) { - DEBUG(11,("sorted_tree_birth_child: First child of node [%s]! [%s]\n", + DEBUG(11,("pathtree_birth_child: First child of node [%s]! [%s]\n", node->key ? node->key : "NULL", infant->key )); node->children[0] = infant; } @@ -161,14 +162,14 @@ static TREE_NODE* sorted_tree_birth_child( TREE_NODE *node, char* key ) for ( i = node->num_children-1; i>=1; i-- ) { - DEBUG(11,("sorted_tree_birth_child: Looking for crib; infant -> [%s], child -> [%s]\n", + DEBUG(11,("pathtree_birth_child: Looking for crib; infant -> [%s], child -> [%s]\n", infant->key, node->children[i-1]->key)); /* the strings should never match assuming that we - have called sorted_tree_find_child() first */ + have called pathtree_find_child() first */ if ( StrCaseCmp( infant->key, node->children[i-1]->key ) > 0 ) { - DEBUG(11,("sorted_tree_birth_child: storing infant in i == [%d]\n", + DEBUG(11,("pathtree_birth_child: storing infant in i == [%d]\n", i)); node->children[i] = infant; break; @@ -179,7 +180,7 @@ static TREE_NODE* sorted_tree_birth_child( TREE_NODE *node, char* key ) node->children[i] = node->children[i-1]; } - DEBUG(11,("sorted_tree_birth_child: Exiting loop (i == [%d])\n", i )); + DEBUG(11,("pathtree_birth_child: Exiting loop (i == [%d])\n", i )); /* if we haven't found the correct slot yet, the child will be first in the list */ @@ -195,24 +196,24 @@ static TREE_NODE* sorted_tree_birth_child( TREE_NODE *node, char* key ) Find the next child given a key string *************************************************************************/ -static TREE_NODE* sorted_tree_find_child( TREE_NODE *node, char* key ) +static TREE_NODE* pathtree_find_child( TREE_NODE *node, char* key ) { TREE_NODE *next = NULL; int i, result; if ( !node ) { - DEBUG(0,("sorted_tree_find_child: NULL node passed into function!\n")); + DEBUG(0,("pathtree_find_child: NULL node passed into function!\n")); return NULL; } if ( !key ) { - DEBUG(0,("sorted_tree_find_child: NULL key string passed into function!\n")); + DEBUG(0,("pathtree_find_child: NULL key string passed into function!\n")); return NULL; } for ( i=0; inum_children; i++ ) { - DEBUG(11,("sorted_tree_find_child: child key => [%s]\n", + DEBUG(11,("pathtree_find_child: child key => [%s]\n", node->children[i]->key)); result = StrCaseCmp( node->children[i]->key, key ); @@ -228,7 +229,7 @@ static TREE_NODE* sorted_tree_find_child( TREE_NODE *node, char* key ) break; } - DEBUG(11,("sorted_tree_find_child: %s [%s]\n", + DEBUG(11,("pathtree_find_child: %s [%s]\n", next ? "Found" : "Did not find", key )); return next; @@ -238,22 +239,22 @@ static TREE_NODE* sorted_tree_find_child( TREE_NODE *node, char* key ) Add a new node into the tree given a key path and a blob of data *************************************************************************/ -BOOL sorted_tree_add( SORTED_TREE *tree, const char *path, void *data_p ) + BOOL pathtree_add( SORTED_TREE *tree, const char *path, void *data_p ) { char *str, *base, *path2; TREE_NODE *current, *next; BOOL ret = True; - DEBUG(8,("sorted_tree_add: Enter\n")); + DEBUG(8,("pathtree_add: Enter\n")); if ( !path || *path != '/' ) { - DEBUG(0,("sorted_tree_add: Attempt to add a node with a bad path [%s]\n", + DEBUG(0,("pathtree_add: Attempt to add a node with a bad path [%s]\n", path ? path : "NULL" )); return False; } if ( !tree ) { - DEBUG(0,("sorted_tree_add: Attempt to add a node to an uninitialized tree!\n")); + DEBUG(0,("pathtree_add: Attempt to add a node to an uninitialized tree!\n")); return False; } @@ -262,7 +263,7 @@ BOOL sorted_tree_add( SORTED_TREE *tree, const char *path, void *data_p ) path++; path2 = SMB_STRDUP( path ); if ( !path2 ) { - DEBUG(0,("sorted_tree_add: strdup() failed on string [%s]!?!?!\n", path)); + DEBUG(0,("pathtree_add: strdup() failed on string [%s]!?!?!\n", path)); return False; } @@ -286,11 +287,11 @@ BOOL sorted_tree_add( SORTED_TREE *tree, const char *path, void *data_p ) /* iterate to the next child--birth it if necessary */ - next = sorted_tree_find_child( current, base ); + next = pathtree_find_child( current, base ); if ( !next ) { - next = sorted_tree_birth_child( current, base ); + next = pathtree_birth_child( current, base ); if ( !next ) { - DEBUG(0,("sorted_tree_add: Failed to create new child!\n")); + DEBUG(0,("pathtree_add: Failed to create new child!\n")); ret = False; goto done; } @@ -310,10 +311,10 @@ BOOL sorted_tree_add( SORTED_TREE *tree, const char *path, void *data_p ) current->data_p = data_p; - DEBUG(10,("sorted_tree_add: Successfully added node [%s] to tree\n", + DEBUG(10,("pathtree_add: Successfully added node [%s] to tree\n", path )); - DEBUG(8,("sorted_tree_add: Exit\n")); + DEBUG(8,("pathtree_add: Exit\n")); done: SAFE_FREE( path2 ); @@ -325,7 +326,7 @@ done: Recursive routine to print out all children of a TREE_NODE *************************************************************************/ -static void sorted_tree_print_children( TREE_NODE *node, int debug, const char *path ) +static void pathtree_print_children( TREE_NODE *node, int debug, const char *path ) { int i; int num_children; @@ -347,7 +348,7 @@ static void sorted_tree_print_children( TREE_NODE *node, int debug, const char * num_children = node->num_children; for ( i=0; ichildren[i], debug, path2 ); + pathtree_print_children( node->children[i], debug, path2 ); } @@ -356,7 +357,7 @@ static void sorted_tree_print_children( TREE_NODE *node, int debug, const char * Dump the kys for a tree to the log file *************************************************************************/ -void sorted_tree_print_keys( SORTED_TREE *tree, int debug ) + void pathtree_print_keys( SORTED_TREE *tree, int debug ) { int i; int num_children = tree->root->num_children; @@ -366,7 +367,7 @@ void sorted_tree_print_keys( SORTED_TREE *tree, int debug ) tree->root->data_p ? "data" : "NULL" )); for ( i=0; iroot->children[i], debug, + pathtree_print_children( tree->root->children[i], debug, tree->root->key ? tree->root->key : "ROOT/" ); } @@ -378,23 +379,23 @@ void sorted_tree_print_keys( SORTED_TREE *tree, int debug ) the tree *************************************************************************/ -void* sorted_tree_find( SORTED_TREE *tree, char *key ) + void* pathtree_find( SORTED_TREE *tree, char *key ) { char *keystr, *base, *str, *p; TREE_NODE *current; void *result = NULL; - DEBUG(10,("sorted_tree_find: Enter [%s]\n", key ? key : "NULL" )); + DEBUG(10,("pathtree_find: Enter [%s]\n", key ? key : "NULL" )); /* sanity checks first */ if ( !key ) { - DEBUG(0,("sorted_tree_find: Attempt to search tree using NULL search string!\n")); + DEBUG(0,("pathtree_find: Attempt to search tree using NULL search string!\n")); return NULL; } if ( !tree ) { - DEBUG(0,("sorted_tree_find: Attempt to search an uninitialized tree using string [%s]!\n", + DEBUG(0,("pathtree_find: Attempt to search an uninitialized tree using string [%s]!\n", key ? key : "NULL" )); return NULL; } @@ -410,7 +411,7 @@ void* sorted_tree_find( SORTED_TREE *tree, char *key ) keystr = SMB_STRDUP( key ); if ( !keystr ) { - DEBUG(0,("sorted_tree_find: strdup() failed on string [%s]!?!?!\n", key)); + DEBUG(0,("pathtree_find: strdup() failed on string [%s]!?!?!\n", key)); return NULL; } @@ -428,12 +429,12 @@ void* sorted_tree_find( SORTED_TREE *tree, char *key ) trim_tree_keypath( p, &base, &str ); - DEBUG(11,("sorted_tree_find: [loop] base => [%s], new_path => [%s]\n", + DEBUG(11,("pathtree_find: [loop] base => [%s], new_path => [%s]\n", base, str)); /* iterate to the next child */ - current = sorted_tree_find_child( current, base ); + current = pathtree_find_child( current, base ); /* * the idea is that the data_p for a parent should @@ -452,11 +453,11 @@ void* sorted_tree_find( SORTED_TREE *tree, char *key ) /* result should be the data_p from the lowest match node in the tree */ if ( result ) - DEBUG(11,("sorted_tree_find: Found data_p!\n")); + DEBUG(11,("pathtree_find: Found data_p!\n")); SAFE_FREE( keystr ); - DEBUG(10,("sorted_tree_find: Exit\n")); + DEBUG(10,("pathtree_find: Exit\n")); return result; } -- cgit From 99c909c2fa2b847e6f55f6f5706d5f46014f8b86 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sat, 3 Sep 2005 16:38:51 +0000 Subject: r9998: starting content for maintainers file (This used to be commit 554c22faeefe6932a01aa7bd6e2861c5abd37510) --- source3/lib/adt_tree.c | 61 ++++++-------------------------------------------- 1 file changed, 7 insertions(+), 54 deletions(-) (limited to 'source3/lib/adt_tree.c') diff --git a/source3/lib/adt_tree.c b/source3/lib/adt_tree.c index ad763c2be1..05a470bc49 100644 --- a/source3/lib/adt_tree.c +++ b/source3/lib/adt_tree.c @@ -23,8 +23,6 @@ /************************************************************************** - Initialize the tree's root. The cmp_fn is a callback function used - for comparision of two children *************************************************************************/ static BOOL trim_tree_keypath( char *path, char **base, char **new_path ) @@ -54,69 +52,26 @@ static BOOL trim_tree_keypath( char *path, char **base, char **new_path ) for comparision of two children *************************************************************************/ - SORTED_TREE* pathtree_init( void *data_p, - int (cmp_fn)(void*, void*), - void (free_fn)(void*) ) + SORTED_TREE* pathtree_init( void *data_p, int (cmp_fn)(void*, void*) ) { SORTED_TREE *tree = NULL; - if ( !(tree = SMB_MALLOC_P(SORTED_TREE)) ) + if ( !(tree = TALLOC_ZERO_P(NULL, SORTED_TREE)) ) return NULL; - ZERO_STRUCTP( tree ); - tree->compare = cmp_fn; - tree->free_func = free_fn; - if ( !(tree->root = SMB_MALLOC_P(TREE_NODE)) ) { - SAFE_FREE( tree ); + if ( !(tree->root = TALLOC_ZERO_P(tree, TREE_NODE)) ) { + TALLOC_FREE( tree ); return NULL; } - ZERO_STRUCTP( tree->root ); tree->root->data_p = data_p; return tree; } -/************************************************************************** - Delete a tree and free all allocated memory - *************************************************************************/ - -static void pathtree_destroy_children( TREE_NODE *root ) -{ - int i; - - if ( !root ) - return; - - for ( i=0; inum_children; i++ ) - { - pathtree_destroy_children( root->children[i] ); - } - - SAFE_FREE( root->children ); - SAFE_FREE( root->key ); - - return; -} - -/************************************************************************** - Delete a tree and free all allocated memory - *************************************************************************/ - - void pathtree_destroy( SORTED_TREE *tree ) -{ - if ( tree->root ) - pathtree_destroy_children( tree->root ); - - if ( tree->free_func ) - tree->free_func( tree->root ); - - SAFE_FREE( tree ); -} - /************************************************************************** Find the next child given a key string *************************************************************************/ @@ -127,15 +82,13 @@ static TREE_NODE* pathtree_birth_child( TREE_NODE *node, char* key ) TREE_NODE **siblings; int i; - if ( !(infant = SMB_MALLOC_P(TREE_NODE)) ) + if ( !(infant = TALLOC_ZERO_P( node, TREE_NODE)) ) return NULL; - ZERO_STRUCTP( infant ); - - infant->key = SMB_STRDUP( key ); + infant->key = talloc_strdup( infant, key ); infant->parent = node; - siblings = SMB_REALLOC_ARRAY( node->children, TREE_NODE *, node->num_children+1 ); + siblings = TALLOC_REALLOC_ARRAY( node, node->children, TREE_NODE *, node->num_children+1 ); if ( siblings ) node->children = siblings; -- cgit From 2202bbf4ab179e2c67f0448bcfaec81bb27ddb04 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 16 Jan 2007 18:05:37 +0000 Subject: r20838: Small fix from Jiri.Sasek@Sun.COM to fix null pointer deref. Jeremy (This used to be commit 34d891c81ad4226bb1f0e26902c4e4afaba6d62f) --- source3/lib/adt_tree.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/lib/adt_tree.c') diff --git a/source3/lib/adt_tree.c b/source3/lib/adt_tree.c index 05a470bc49..acd61ee477 100644 --- a/source3/lib/adt_tree.c +++ b/source3/lib/adt_tree.c @@ -334,7 +334,7 @@ static void pathtree_print_children( TREE_NODE *node, int debug, const char *pat void* pathtree_find( SORTED_TREE *tree, char *key ) { - char *keystr, *base, *str, *p; + char *keystr, *base = NULL, *str = NULL, *p; TREE_NODE *current; void *result = NULL; @@ -383,7 +383,8 @@ static void pathtree_print_children( TREE_NODE *node, int debug, const char *pat trim_tree_keypath( p, &base, &str ); DEBUG(11,("pathtree_find: [loop] base => [%s], new_path => [%s]\n", - base, str)); + base ? base : "", + str ? str : "")); /* iterate to the next child */ -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/lib/adt_tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/adt_tree.c') diff --git a/source3/lib/adt_tree.c b/source3/lib/adt_tree.c index acd61ee477..950a86d0fd 100644 --- a/source3/lib/adt_tree.c +++ b/source3/lib/adt_tree.c @@ -5,7 +5,7 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, -- cgit From 153cfb9c83534b09f15cc16205d7adb19b394928 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 05:23:25 +0000 Subject: r23801: The FSF has moved around a lot. This fixes their Mass Ave address. (This used to be commit 87c91e4362c51819032bfbebbb273c52e203b227) --- source3/lib/adt_tree.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/lib/adt_tree.c') diff --git a/source3/lib/adt_tree.c b/source3/lib/adt_tree.c index 950a86d0fd..f26f924d61 100644 --- a/source3/lib/adt_tree.c +++ b/source3/lib/adt_tree.c @@ -14,8 +14,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program; if not, see . */ #include "includes.h" -- cgit From db31df8186eafabd9a997a89e33779cf10ce5a9b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 14 Sep 2007 22:14:39 +0000 Subject: r25171: More pstring removal. Jeremy. (This used to be commit 4748d2639796e8caa67fae44d1cf660d49d82663) --- source3/lib/adt_tree.c | 52 +++++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 20 deletions(-) (limited to 'source3/lib/adt_tree.c') diff --git a/source3/lib/adt_tree.c b/source3/lib/adt_tree.c index f26f924d61..cf305d7307 100644 --- a/source3/lib/adt_tree.c +++ b/source3/lib/adt_tree.c @@ -278,31 +278,41 @@ done: Recursive routine to print out all children of a TREE_NODE *************************************************************************/ -static void pathtree_print_children( TREE_NODE *node, int debug, const char *path ) +static void pathtree_print_children(TALLOC_CTX *ctx, + TREE_NODE *node, + int debug, + const char *path ) { int i; int num_children; - pstring path2; - + char *path2 = NULL; + if ( !node ) return; - - + if ( node->key ) DEBUG(debug,("%s: [%s] (%s)\n", path ? path : "NULL", node->key, node->data_p ? "data" : "NULL" )); - *path2 = '\0'; - if ( path ) - pstrcpy( path2, path ); - pstrcat( path2, node->key ? node->key : "NULL" ); - pstrcat( path2, "/" ); - - num_children = node->num_children; - for ( i=0; ichildren[i], debug, path2 ); - + if ( path ) { + path2 = talloc_strdup(ctx, path); + if (!path2) { + return; + } + } + + path2 = talloc_asprintf(ctx, + "%s%s/", + path ? path : "", + node->key ? node->key : "NULL"); + if (!path2) { + return; + } + num_children = node->num_children; + for ( i=0; ichildren[i], debug, path2 ); + } } /************************************************************************** @@ -313,21 +323,23 @@ static void pathtree_print_children( TREE_NODE *node, int debug, const char *pat { int i; int num_children = tree->root->num_children; - + if ( tree->root->key ) DEBUG(debug,("ROOT/: [%s] (%s)\n", tree->root->key, tree->root->data_p ? "data" : "NULL" )); - + for ( i=0; iroot->children[i], debug, + TALLOC_CTX *ctx = talloc_stackframe(); + pathtree_print_children(ctx, tree->root->children[i], debug, tree->root->key ? tree->root->key : "ROOT/" ); + TALLOC_FREE(ctx); } - + } /************************************************************************** return the data_p for for the node in tree matching the key string - The key string is the full path. We must break it apart and walk + The key string is the full path. We must break it apart and walk the tree *************************************************************************/ -- cgit From 30191d1a5704ad2b158386b511558972d539ce47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Oct 2007 17:40:25 -0700 Subject: RIP BOOL. Convert BOOL -> bool. I found a few interesting bugs in various places whilst doing this (places that assumed BOOL == int). I also need to fix the Samba4 pidl generation (next checkin). Jeremy. (This used to be commit f35a266b3cbb3e5fa6a86be60f34fe340a3ca71f) --- source3/lib/adt_tree.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/lib/adt_tree.c') diff --git a/source3/lib/adt_tree.c b/source3/lib/adt_tree.c index cf305d7307..ef72ba3e70 100644 --- a/source3/lib/adt_tree.c +++ b/source3/lib/adt_tree.c @@ -24,7 +24,7 @@ /************************************************************************** *************************************************************************/ -static BOOL trim_tree_keypath( char *path, char **base, char **new_path ) +static bool trim_tree_keypath( char *path, char **base, char **new_path ) { char *p; @@ -191,11 +191,11 @@ static TREE_NODE* pathtree_find_child( TREE_NODE *node, char* key ) Add a new node into the tree given a key path and a blob of data *************************************************************************/ - BOOL pathtree_add( SORTED_TREE *tree, const char *path, void *data_p ) + bool pathtree_add( SORTED_TREE *tree, const char *path, void *data_p ) { char *str, *base, *path2; TREE_NODE *current, *next; - BOOL ret = True; + bool ret = True; DEBUG(8,("pathtree_add: Enter\n")); -- cgit From 01f4bd4f4d05e195911f4787f209b2ab6e2d8ab4 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sun, 13 Apr 2008 14:41:44 +0200 Subject: adt_tree: change pathtree_add to return WERR instead of bool. Michael (This used to be commit da45fb92f69221758f36db4cbb7d871e3ce60718) --- source3/lib/adt_tree.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/lib/adt_tree.c') diff --git a/source3/lib/adt_tree.c b/source3/lib/adt_tree.c index ef72ba3e70..6ac498d9e6 100644 --- a/source3/lib/adt_tree.c +++ b/source3/lib/adt_tree.c @@ -191,23 +191,23 @@ static TREE_NODE* pathtree_find_child( TREE_NODE *node, char* key ) Add a new node into the tree given a key path and a blob of data *************************************************************************/ - bool pathtree_add( SORTED_TREE *tree, const char *path, void *data_p ) + WERROR pathtree_add( SORTED_TREE *tree, const char *path, void *data_p ) { char *str, *base, *path2; TREE_NODE *current, *next; - bool ret = True; + WERROR ret = WERR_OK; DEBUG(8,("pathtree_add: Enter\n")); if ( !path || *path != '/' ) { DEBUG(0,("pathtree_add: Attempt to add a node with a bad path [%s]\n", path ? path : "NULL" )); - return False; + return WERR_INVALID_PARAM; } if ( !tree ) { DEBUG(0,("pathtree_add: Attempt to add a node to an uninitialized tree!\n")); - return False; + return WERR_INVALID_PARAM; } /* move past the first '/' */ @@ -216,7 +216,7 @@ static TREE_NODE* pathtree_find_child( TREE_NODE *node, char* key ) path2 = SMB_STRDUP( path ); if ( !path2 ) { DEBUG(0,("pathtree_add: strdup() failed on string [%s]!?!?!\n", path)); - return False; + return WERR_NOMEM; } @@ -244,7 +244,7 @@ static TREE_NODE* pathtree_find_child( TREE_NODE *node, char* key ) next = pathtree_birth_child( current, base ); if ( !next ) { DEBUG(0,("pathtree_add: Failed to create new child!\n")); - ret = False; + ret = WERR_NOMEM; goto done; } } -- cgit