1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements.  See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License.  You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/**
18 * @file ap_regkey.h
19 * @brief APR-style Win32 Registry Manipulation
20 */
21
22#ifndef AP_REGKEY_H
23#define AP_REGKEY_H
24
25#if defined(WIN32) || defined(DOXYGEN)
26
27#include "apr.h"
28#include "apr_pools.h"
29#include "ap_config.h"      /* Just for AP_DECLARE */
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35typedef struct ap_regkey_t ap_regkey_t;
36
37/* Used to recover AP_REGKEY_* constants
38 */
39AP_DECLARE(const ap_regkey_t *) ap_regkey_const(int i);
40
41/**
42 * Win32 Only: Constants for ap_regkey_open()
43 */
44#define AP_REGKEY_CLASSES_ROOT         ap_regkey_const(0)
45#define AP_REGKEY_CURRENT_CONFIG       ap_regkey_const(1)
46#define AP_REGKEY_CURRENT_USER         ap_regkey_const(2)
47#define AP_REGKEY_LOCAL_MACHINE        ap_regkey_const(3)
48#define AP_REGKEY_USERS                ap_regkey_const(4)
49#define AP_REGKEY_PERFORMANCE_DATA     ap_regkey_const(5)
50#define AP_REGKEY_DYN_DATA             ap_regkey_const(6)
51
52/**
53 * Win32 Only: Flags for ap_regkey_value_set()
54 */
55#define AP_REGKEY_EXPAND               0x0001
56
57/**
58 * Win32 Only: Open the specified registry key.
59 * @param newkey The opened registry key
60 * @param parentkey The open registry key of the parent, or one of
61 * <PRE>
62 *           AP_REGKEY_CLASSES_ROOT
63 *           AP_REGKEY_CURRENT_CONFIG
64 *           AP_REGKEY_CURRENT_USER
65 *           AP_REGKEY_LOCAL_MACHINE
66 *           AP_REGKEY_USERS
67 *           AP_REGKEY_PERFORMANCE_DATA
68 *           AP_REGKEY_DYN_DATA
69 * </PRE>
70 * @param keyname The path of the key relative to the parent key
71 * @param flags Or'ed value of:
72 * <PRE>
73 *           APR_READ             open key for reading
74 *           APR_WRITE            open key for writing
75 *           APR_CREATE           create the key if it doesn't exist
76 *           APR_EXCL             return error if APR_CREATE and key exists
77 * </PRE>
78 * @param pool The pool in which newkey is allocated
79 */
80AP_DECLARE(apr_status_t) ap_regkey_open(ap_regkey_t **newkey,
81                                        const ap_regkey_t *parentkey,
82                                        const char *keyname,
83                                        apr_int32_t flags,
84                                        apr_pool_t *pool);
85
86/**
87 * Win32 Only: Close the registry key opened or created by ap_regkey_open().
88 * @param key The registry key to close
89 */
90AP_DECLARE(apr_status_t) ap_regkey_close(ap_regkey_t *key);
91
92/**
93 * Win32 Only: Remove the given registry key.
94 * @param parent The open registry key of the parent, or one of
95 * <PRE>
96 *           AP_REGKEY_CLASSES_ROOT
97 *           AP_REGKEY_CURRENT_CONFIG
98 *           AP_REGKEY_CURRENT_USER
99 *           AP_REGKEY_LOCAL_MACHINE
100 *           AP_REGKEY_USERS
101 *           AP_REGKEY_PERFORMANCE_DATA
102 *           AP_REGKEY_DYN_DATA
103 * </PRE>
104 * @param keyname The path of the key relative to the parent key
105 * @param pool The pool used for temp allocations
106 * @remark ap_regkey_remove() is not recursive, although it removes
107 * all values within the given keyname, it will not remove a key
108 * containing subkeys.
109 */
110AP_DECLARE(apr_status_t) ap_regkey_remove(const ap_regkey_t *parent,
111                                          const char *keyname,
112                                          apr_pool_t *pool);
113
114/**
115 * Win32 Only: Retrieve a registry value string from an open key.
116 * @param result The string value retrieved
117 * @param key The registry key to retrieve the value from
118 * @param valuename The named value to retrieve (pass "" for the default)
119 * @param pool The pool used to store the result
120 * @remark There is no toggle to prevent environment variable expansion
121 * if the registry value is set with AP_REG_EXPAND (REG_EXPAND_SZ), such
122 * expansions are always performed.
123 */
124AP_DECLARE(apr_status_t) ap_regkey_value_get(char **result,
125                                             ap_regkey_t *key,
126                                             const char *valuename,
127                                             apr_pool_t *pool);
128
129/**
130 * Win32 Only: Store a registry value string into an open key.
131 * @param key The registry key to store the value into
132 * @param valuename The named value to store (pass "" for the default)
133 * @param value The string to store for the named value
134 * @param flags The option AP_REGKEY_EXPAND or 0, where AP_REGKEY_EXPAND
135 * values will find all %foo% variables expanded from the environment.
136 * @param pool The pool used for temp allocations
137 */
138AP_DECLARE(apr_status_t) ap_regkey_value_set(ap_regkey_t *key,
139                                             const char *valuename,
140                                             const char *value,
141                                             apr_int32_t flags,
142                                             apr_pool_t *pool);
143
144/**
145 * Win32 Only: Retrieve a raw byte value from an open key.
146 * @param result The raw bytes value retrieved
147 * @param resultsize Pointer to a variable to store the number raw bytes retrieved
148 * @param resulttype Pointer to a variable to store the registry type of the value retrieved
149 * @param key The registry key to retrieve the value from
150 * @param valuename The named value to retrieve (pass "" for the default)
151 * @param pool The pool used to store the result
152 */
153AP_DECLARE(apr_status_t) ap_regkey_value_raw_get(void **result,
154                                                 apr_size_t *resultsize,
155                                                 apr_int32_t *resulttype,
156                                                 ap_regkey_t *key,
157                                                 const char *valuename,
158                                                 apr_pool_t *pool);
159
160/**
161 * Win32 Only: Store a raw bytes value into an open key.
162 * @param key The registry key to store the value into
163 * @param valuename The named value to store (pass "" for the default)
164 * @param value The bytes to store for the named value
165 * @param valuesize The number of bytes for value
166 * @param valuetype The
167 * values will find all %foo% variables expanded from the environment.
168 * @param pool The pool used for temp allocations
169 */
170AP_DECLARE(apr_status_t) ap_regkey_value_raw_set(ap_regkey_t *key,
171                                                 const char *valuename,
172                                                 const void *value,
173                                                 apr_size_t  valuesize,
174                                                 apr_int32_t valuetype,
175                                                 apr_pool_t *pool);
176
177/**
178 * Win32 Only: Retrieve a registry value string from an open key.
179 * @param result The string elements retrieved from a REG_MULTI_SZ string array
180 * @param key The registry key to retrieve the value from
181 * @param valuename The named value to retrieve (pass "" for the default)
182 * @param pool The pool used to store the result
183 */
184AP_DECLARE(apr_status_t) ap_regkey_value_array_get(apr_array_header_t **result,
185                                                   ap_regkey_t *key,
186                                                   const char *valuename,
187                                                   apr_pool_t *pool);
188
189/**
190 * Win32 Only: Store a registry value string array into an open key.
191 * @param key The registry key to store the value into
192 * @param valuename The named value to store (pass "" for the default)
193 * @param nelts The string elements to store in a REG_MULTI_SZ string array
194 * @param elts The number of elements in the elts string array
195 * @param pool The pool used for temp allocations
196 */
197AP_DECLARE(apr_status_t) ap_regkey_value_array_set(ap_regkey_t *key,
198                                                   const char *valuename,
199                                                   int nelts,
200                                                   const char * const * elts,
201                                                   apr_pool_t *pool);
202
203/**
204 * Win32 Only: Remove a registry value from an open key.
205 * @param key The registry key to remove the value from
206 * @param valuename The named value to remove (pass "" for the default)
207 * @param pool The pool used for temp allocations
208 */
209AP_DECLARE(apr_status_t) ap_regkey_value_remove(const ap_regkey_t *key,
210                                                const char *valuename,
211                                                apr_pool_t *pool);
212
213#ifdef __cplusplus
214}
215#endif
216
217#endif /* def WIN32 || def DOXYGEN */
218
219#endif /* AP_REGKEY_H */
220