s3:registry: untangle assignment from check in reg_enumvalue()
[samba.git] / source3 / registry / reg_import.h
1 /*
2  * Samba Unix/Linux SMB client library
3  *
4  * Copyright (C) Gregor Beck 2010
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 /**
21  * @brief  Adapter to use reg_parse with the registry api
22  * @file   reg_import.h
23  * @author Gregor Beck <gb@sernet.de>
24  * @date   Jun 2010
25  */
26
27
28 #ifndef REG_IMPORT_H
29 #define REG_IMPORT_H
30
31 #include "reg_parse.h"
32
33 struct registry_value;
34 struct regval_blob;
35
36 /**
37  * Protoype for function called to open a key.
38  *
39  * @param private_data
40  * @param[in] parent    the parent of the key to open, may be NULL
41  * @param[in] name      the name of the key relative to parent.
42  * @param[out] key      the opened key
43  *
44  * @return WERR_OK on success
45  */
46 typedef WERROR (*reg_import_callback_openkey_t) (void* private_data,
47                                                 void* parent,
48                                                 const char* name,
49                                                 void** key);
50
51 /**
52  * Protoype for function called to close a key.
53  *
54  * @param private_data
55  * @param key the key to close
56  *
57  * @return WERR_OK on success
58  */
59 typedef WERROR (*reg_import_callback_closekey_t) (void* private_data,
60                                                   void* key);
61
62 /**
63  * Protoype for function called to create (or open an existing) key.
64  *
65  * @param private_data
66  * @param[in] parent    the parent of the key to create, may be NULL
67  * @param[in] name      the name of the key relative to parent.
68  * @param[out] key      the opened key
69  * @param[out] existing whether we opened an existing key
70  *
71  * @return WERR_OK on success
72  */
73 typedef WERROR (*reg_import_callback_createkey_t)(void* private_data,
74                                                 void* parent,
75                                                 const char* name,
76                                                 void** key,
77                                                 bool* existing);
78
79 /**
80  * Protoype for function called to delete a key.
81  *
82  * @param private_data
83  * @param parent    the parent of the key to delete, may be NULL
84  * @param[in] name  the name of the key relative to parent.
85  *
86  * @return WERR_OK on success
87  */
88 typedef WERROR (*reg_import_callback_deletekey_t)(void* private_data,
89                                                   void* parent,
90                                                   const char* name);
91
92 /**
93  * Protoype for function called to delete a value.
94  *
95  * @param private_data
96  * @param parent    the key of the value to delete
97  * @param[in] name  the name of the value to delete.
98  *
99  * @return WERR_OK on success
100  */
101 typedef WERROR (*reg_import_callback_deleteval_t)(void* private_data,
102                                                 void* parent,
103                                                 const char* name);
104
105 /**
106  * Protoype for function called to set a value.
107  *
108  * @param private_data
109  * @param parent the key of the value to set
110  * @param name   the name of the value
111  * @param type   the type of the value
112  * @param data   the value of the value
113  * @param size   the number of bytes of data
114  *
115  * @return WERR_OK on success
116  */
117 typedef WERROR (*reg_import_callback_setval_blob_t)(void* private_data,
118                                                   void* parent,
119                                                   const char* name,
120                                                   uint32_t type,
121                                                   const uint8_t* data,
122                                                   uint32_t size);
123
124 /**
125  * Protoype for function called to set a value given as struct registry_value.
126  *
127  * @param private_data
128  * @param parent the key of the value to set
129  * @param name   the name of the value
130  * @param val    the value of the value
131  *
132  * @return WERR_OK on success
133  */
134 typedef WERROR (*reg_import_callback_setval_registry_value_t) (
135         void* private_data,
136         void* parent,
137         const char* name,
138         const struct registry_value* val);
139
140 /**
141  * Protoype for function called to set a value given as struct struct regval_blob.
142  *
143  * @param private_data
144  * @param parent the key of the value to set
145  * @param val    the value
146  *
147  * @return WERR_OK on success
148  */
149 typedef WERROR (*reg_import_callback_setval_regval_blob_t)(
150         void* private_data,
151         void* parent,
152         const struct regval_blob* val);
153
154 /**
155  * Type handling the output of a reg_import object.
156  * It containes the functions to call and an opaque data pointer.
157  */
158 struct reg_import_callback {
159         /** Function called to open key */
160         reg_import_callback_openkey_t   openkey;
161         /** Function called to close key */
162         reg_import_callback_closekey_t  closekey;
163         /** Function called to create or open key */
164         reg_import_callback_createkey_t createkey;
165         /** Function called to delete key */
166         reg_import_callback_deletekey_t deletekey;
167         /** Function called to delete value */
168         reg_import_callback_deleteval_t deleteval;
169
170         /** Function called to set value */
171         union {
172                 reg_import_callback_setval_blob_t           blob;
173                 reg_import_callback_setval_registry_value_t registry_value;
174                 reg_import_callback_setval_regval_blob_t    regval_blob;
175         } setval;
176         /** Which function is called to set a value */
177         enum {
178                 NONE=0,         /**< no setval function used */
179                 BLOB,           /**< @ref reg_import_callback_setval_blob_t blob */
180                 REGISTRY_VALUE, /**< @ref reg_import_callback_setval_registry_value_t registry_value */
181                 REGVAL_BLOB,    /**< @ref reg_import_callback_setval_regval_blob_t regval_blob */
182         } setval_type;
183         void* data; /**< Private data passed to callback function */
184 };
185
186
187 /**
188  * Create a new reg_import object.
189  * Because its only purpose is to act as an reg_parse_callback the return type
190  * is accordingly.
191  *
192  * @param talloc_ctx the talloc parent
193  * @param cb         the output handler
194  *
195  * @return a talloc'ed reg_import object, NULL on error
196  */
197 struct reg_parse_callback* reg_import_adapter(TALLOC_CTX *talloc_ctx,
198                                               struct reg_import_callback cb);
199 #endif