2 * Unix SMB/CIFS implementation.
3 * Virtual Windows Registry Layer
4 * Copyright (C) Gerald Carter 2002.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 /* Implementation of registry hook cache tree */
26 #define DBGC_CLASS DBGC_REGISTRY
28 static SORTED_TREE *cache_tree = NULL;
29 extern REGISTRY_OPS regdb_ops; /* these are the default */
31 /**********************************************************************
32 Initialize the cache tree if it has not been initialized yet.
33 *********************************************************************/
35 bool reghook_cache_init( void )
37 if (cache_tree == NULL) {
38 cache_tree = pathtree_init(®db_ops, NULL);
40 DEBUG(10, ("reghook_cache_init: new tree with default "
41 "ops %p for key [%s]\n", (void *)®db_ops,
46 return (cache_tree != NULL);
49 /**********************************************************************
50 Add a new registry hook to the cache. Note that the keyname
51 is not in the exact format that a SORTED_TREE expects.
52 *********************************************************************/
54 bool reghook_cache_add(const char *keyname, REGISTRY_OPS *ops)
56 TALLOC_CTX *ctx = talloc_tos();
59 if ((keyname == NULL) || (ops == NULL)) {
63 key = talloc_asprintf(ctx, "\\%s", keyname);
67 key = talloc_string_sub(ctx, key, "\\", "/");
72 DEBUG(10, ("reghook_cache_add: Adding ops %p for key [%s]\n",
75 return pathtree_add(cache_tree, key, ops);
78 /**********************************************************************
79 Find a key in the cache.
80 *********************************************************************/
82 REGISTRY_OPS *reghook_cache_find(const char *keyname)
91 /* prepend the string with a '\' character */
93 len = strlen( keyname );
94 if ( !(key = (char *)SMB_MALLOC( len + 2 )) ) {
95 DEBUG(0,("reghook_cache_find: malloc failed for string [%s] !?!?!\n",
101 strncpy( key+1, keyname, len+1);
103 /* swap to a form understood by the SORTED_TREE */
105 string_sub( key, "\\", "/", 0 );
107 DEBUG(10,("reghook_cache_find: Searching for keyname [%s]\n", key));
109 ops = (REGISTRY_OPS *)pathtree_find(cache_tree, key);
111 DEBUG(10, ("reghook_cache_find: found ops %p for key [%s]\n",
112 ops ? (void *)ops : 0, key));
119 /**********************************************************************
120 Print out the cache tree structure for debugging.
121 *********************************************************************/
123 void reghook_dump_cache( int debuglevel )
125 DEBUG(debuglevel,("reghook_dump_cache: Starting cache dump now...\n"));
127 pathtree_print_keys( cache_tree, debuglevel );