r20: Add the registry library. Still needs a lot of work,
[ira/wip.git] / source4 / lib / registry / common / registry.h
1 /* 
2    Unix SMB/CIFS implementation.
3    Registry interface
4    This file contains the _internal_ structs for the registry 
5    subsystem. Backends and the subsystem itself are the only
6    files that need to include this file.
7    Copyright (C) Gerald Carter                        2002.
8    Copyright (C) Jelmer Vernooij                                          2003-2004.
9    
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 2 of the License, or
13    (at your option) any later version.
14    
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19    
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25 #ifndef _REGISTRY_REGISTRY_H /* _REGISTRY_REGISTRY_H */
26 #define _REGISTRY_REGISTRY_H 
27
28 #define REGISTRY_INTERFACE_VERSION 1
29
30 /* structure to store the registry handles */
31 struct reg_key_s {
32   char *name;         /* Name of the key                    */
33   char *path;             /* Full path to the key */
34   smb_ucs2_t *class_name; /* Name of key class */
35   NTTIME last_mod; /* Time last modified                 */
36   SEC_DESC *security;
37   REG_HANDLE *handle;
38   void *backend_data;
39   REG_VAL **cache_values; 
40   int cache_values_count;
41   REG_KEY **cache_subkeys; 
42   int cache_subkeys_count;
43   int ref;
44 };
45
46 struct reg_val_s {
47   char *name;
48   int has_name;
49   int data_type;
50   int data_len;
51   void *data_blk;    /* Might want a separate block */
52   REG_HANDLE *handle;
53   REG_KEY *parent;
54   void *backend_data;
55   int ref;
56 };
57
58 /* 
59  * Container for function pointers to enumeration routines
60  * for virtual registry view 
61  */ 
62  
63 struct reg_ops_s {
64         const char *name;
65         BOOL (*open_registry) (REG_HANDLE *, const char *location, BOOL try_complete_load);
66         BOOL (*sync)(REG_HANDLE *, const char *location);
67         BOOL (*close_registry) (REG_HANDLE *);
68
69         /* Either implement these */
70         REG_KEY *(*open_root_key) (REG_HANDLE *);
71         int (*num_subkeys) (REG_KEY *);
72         int (*num_values) (REG_KEY *);
73         REG_KEY *(*get_subkey_by_index) (REG_KEY *, int idx);
74         REG_KEY *(*get_subkey_by_name) (REG_KEY *, const char *name);
75         REG_VAL *(*get_value_by_index) (REG_KEY *, int idx);
76         REG_VAL *(*get_value_by_name) (REG_KEY *, const char *name);
77
78         /* Or these */
79         REG_KEY *(*open_key) (REG_HANDLE *, const char *name);
80         BOOL (*fetch_subkeys) (REG_KEY *, int *count, REG_KEY ***);
81         BOOL (*fetch_values) (REG_KEY *, int *count, REG_VAL ***);
82
83         /* Key management */
84         BOOL (*add_key)(REG_KEY *, const char *name);
85         BOOL (*del_key)(REG_KEY *);
86
87         /* Value management */
88         REG_VAL *(*add_value)(REG_KEY *, const char *name, int type, void *data, int len);
89         BOOL (*del_value)(REG_VAL *);
90         
91         /* If update is not available, value will first be deleted and then added 
92          * again */
93         BOOL (*update_value)(REG_VAL *, int type, void *data, int len); 
94
95         void (*free_key_backend_data) (REG_KEY *);
96         void (*free_val_backend_data) (REG_VAL *);
97 };
98
99 typedef struct reg_sub_tree_s {
100         char *path;
101         REG_HANDLE *handle;
102         struct reg_sub_tree_s *prev, *next;
103 } REG_SUBTREE;
104
105 struct reg_handle_s {
106         REG_OPS *functions;
107         REG_SUBTREE *subtrees;
108         char *location;
109         void *backend_data;
110 };
111
112 struct reg_init_function_entry {
113         /* Function to create a member of the pdb_methods list */
114         REG_OPS *functions;
115         struct reg_init_function_entry *prev, *next;
116 };
117
118 /* Used internally */
119 #define SMB_REG_ASSERT(a) { if(!(a)) { DEBUG(0,("%s failed! (%s:%d)", #a, __FILE__, __LINE__)); }}
120
121 #endif /* _REGISTRY_H */