1 | /* |
2 | * The contents of this file are subject to the Initial |
3 | * Developer's Public License Version 1.0 (the "License"); |
4 | * you may not use this file except in compliance with the |
5 | * License. You may obtain a copy of the License at |
6 | * http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl. |
7 | * |
8 | * Software distributed under the License is distributed AS IS, |
9 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. |
10 | * See the License for the specific language governing rights |
11 | * and limitations under the License. |
12 | * |
13 | * The Original Code was created by Dmitry Yemanov |
14 | * for the Firebird Open Source RDBMS project. |
15 | * |
16 | * Copyright (c) 2002 Dmitry Yemanov <dimitr@users.sf.net> |
17 | * and all contributors signed below. |
18 | * |
19 | * All Rights Reserved. |
20 | * Contributor(s): ______________________________________. |
21 | */ |
22 | |
23 | #ifndef COMMON_CONFIG_H |
24 | #define COMMON_CONFIG_H |
25 | |
26 | #include "../common/classes/alloc.h" |
27 | #include "../common/classes/fb_string.h" |
28 | #include "../common/classes/RefCounted.h" |
29 | #include "../common/config/config_file.h" |
30 | #include "../common/classes/ImplementHelper.h" |
31 | |
32 | /** |
33 | Since the original (isc.cpp) code wasn't able to provide powerful and |
34 | easy-to-use abilities to work with complex configurations, a decision |
35 | has been made to create a completely new one. |
36 | |
37 | This class is a public interface for our generic configuration manager |
38 | and allows to access all configuration values by its getXXX() member |
39 | functions. Each of these functions corresponds to one and only one key |
40 | and has one input argument - default value, which is used when the |
41 | requested key is missing or the configuration file is not found. Supported |
42 | value datatypes are "const char*", "int" and "bool". Usual default values for |
43 | these datatypes are empty string, zero and false respectively. There are |
44 | two types of member functions - scalar and vector. The former ones return |
45 | single value of the given type. The latter ones return vector which |
46 | contains an ordered array of values. |
47 | |
48 | There's one exception - getRootDirectory() member function, which returns |
49 | root pathname of the current installation. This value isn't stored in the |
50 | configuration file, but is managed by the code itself. But there's a way |
51 | to override this value via the configuration file as well. |
52 | |
53 | To add new configuration item, you have to take the following steps: |
54 | |
55 | 1. Add key description to ConfigImpl::entries[] array (config.cpp) |
56 | 2. Add logical key to Config::ConfigKey enumeration (config.h) |
57 | (note: both physical and logical keys MUST have the same ordinal |
58 | position within appropriate structures) |
59 | 3. Add member function to Config class (config.h) and implement it |
60 | in config.cpp module. |
61 | 4. For per-database configurable parameters, please use |
62 | type getParameterName() const; |
63 | form, for world-wide parameters: |
64 | static type getParameterName(); |
65 | should be used. |
66 | **/ |
67 | |
68 | extern const char* GCPolicyCooperative; |
69 | extern const char* GCPolicyBackground; |
70 | extern const char* GCPolicyCombined; |
71 | |
72 | const int WIRE_CRYPT_DISABLED = 0; |
73 | const int WIRE_CRYPT_ENABLED = 1; |
74 | const int WIRE_CRYPT_REQUIRED = 2; |
75 | |
76 | enum WireCryptMode {WC_CLIENT, WC_SERVER}; // Have different defaults |
77 | |
78 | const char* const CONFIG_FILE = "firebird.conf" ; |
79 | |
80 | class Config : public Firebird::RefCounted, public Firebird::GlobalStorage |
81 | { |
82 | public: |
83 | typedef IPTR ConfigValue; |
84 | |
85 | enum ConfigKey |
86 | { |
87 | KEY_TEMP_BLOCK_SIZE, |
88 | KEY_TEMP_CACHE_LIMIT, |
89 | KEY_REMOTE_FILE_OPEN_ABILITY, |
90 | KEY_GUARDIAN_OPTION, |
91 | KEY_CPU_AFFINITY_MASK, |
92 | KEY_TCP_REMOTE_BUFFER_SIZE, |
93 | KEY_TCP_NO_NAGLE, |
94 | KEY_DEFAULT_DB_CACHE_PAGES, |
95 | KEY_CONNECTION_TIMEOUT, |
96 | KEY_DUMMY_PACKET_INTERVAL, |
97 | KEY_LOCK_MEM_SIZE, |
98 | KEY_LOCK_HASH_SLOTS, |
99 | KEY_LOCK_ACQUIRE_SPINS, |
100 | KEY_EVENT_MEM_SIZE, |
101 | KEY_DEADLOCK_TIMEOUT, |
102 | KEY_REMOTE_SERVICE_NAME, |
103 | KEY_REMOTE_SERVICE_PORT, |
104 | KEY_REMOTE_PIPE_NAME, |
105 | KEY_IPC_NAME, |
106 | KEY_MAX_UNFLUSHED_WRITES, |
107 | KEY_MAX_UNFLUSHED_WRITE_TIME, |
108 | KEY_PROCESS_PRIORITY_LEVEL, |
109 | KEY_REMOTE_AUX_PORT, |
110 | KEY_REMOTE_BIND_ADDRESS, |
111 | KEY_EXTERNAL_FILE_ACCESS, |
112 | KEY_DATABASE_ACCESS, |
113 | KEY_UDF_ACCESS, |
114 | KEY_TEMP_DIRECTORIES, |
115 | KEY_BUGCHECK_ABORT, |
116 | KEY_TRACE_DSQL, |
117 | KEY_LEGACY_HASH, |
118 | KEY_GC_POLICY, |
119 | KEY_REDIRECTION, |
120 | KEY_DATABASE_GROWTH_INCREMENT, |
121 | KEY_FILESYSTEM_CACHE_THRESHOLD, |
122 | KEY_RELAXED_ALIAS_CHECKING, |
123 | KEY_TRACE_CONFIG, |
124 | KEY_MAX_TRACELOG_SIZE, |
125 | KEY_FILESYSTEM_CACHE_SIZE, |
126 | KEY_PLUG_PROVIDERS, |
127 | KEY_PLUG_AUTH_SERVER, |
128 | KEY_PLUG_AUTH_CLIENT, |
129 | KEY_PLUG_AUTH_MANAGE, |
130 | KEY_PLUG_TRACE, |
131 | KEY_SECURITY_DATABASE, |
132 | KEY_SHARED_CACHE, |
133 | KEY_SHARED_DATABASE, |
134 | KEY_WIRE_CRYPT, |
135 | KEY_PLUG_WIRE_CRYPT, |
136 | KEY_PLUG_KEY_HOLDER, |
137 | KEY_REMOTE_ACCESS, |
138 | MAX_CONFIG_KEY // keep it last |
139 | }; |
140 | |
141 | |
142 | private: |
143 | enum ConfigType |
144 | { |
145 | TYPE_BOOLEAN, |
146 | TYPE_INTEGER, |
147 | TYPE_STRING |
148 | //TYPE_STRING_VECTOR // CVC: Unused |
149 | }; |
150 | |
151 | typedef const char* ConfigName; |
152 | |
153 | struct ConfigEntry |
154 | { |
155 | ConfigType data_type; |
156 | ConfigName key; |
157 | ConfigValue default_value; |
158 | }; |
159 | |
160 | void loadValues(const ConfigFile& file); |
161 | |
162 | template <typename T> T get(Config::ConfigKey key) const |
163 | { |
164 | return (T) values[key]; |
165 | } |
166 | |
167 | static const ConfigEntry entries[MAX_CONFIG_KEY]; |
168 | |
169 | ConfigValue values[MAX_CONFIG_KEY]; |
170 | |
171 | public: |
172 | explicit Config(const ConfigFile& file); // use to build default config |
173 | Config(const ConfigFile& file, const Config& base); // use to build db-specific config |
174 | ~Config(); |
175 | |
176 | // Check for missing firebird.conf |
177 | |
178 | static bool missFirebirdConf(); |
179 | |
180 | // Interface to support command line root specification. |
181 | // This ugly solution was required to make it possible to specify root |
182 | // in command line to load firebird.conf from that root, though in other |
183 | // cases firebird.conf may be also used to specify root. |
184 | |
185 | static void setRootDirectoryFromCommandLine(const Firebird::PathName& newRoot); |
186 | static const Firebird::PathName* getCommandLineRootDirectory(); |
187 | |
188 | // Master config - needed to provide per-database config |
189 | static const Firebird::RefPtr<Config>& getDefaultConfig(); |
190 | |
191 | // Merge config entries from DPB into existing config |
192 | static void merge(Firebird::RefPtr<Config>& config, const Firebird::string* dpbConfig); |
193 | |
194 | // reports key to be used by the following functions |
195 | static unsigned int getKeyByName(ConfigName name); |
196 | // helpers to build interface for firebird.conf file |
197 | SINT64 getInt(unsigned int key) const; |
198 | const char* getString(unsigned int key) const; |
199 | bool getBoolean(unsigned int key) const; |
200 | |
201 | // Static functions apply to instance-wide values, |
202 | // non-static may be specified per database. |
203 | |
204 | // Installation directory |
205 | static const char* getInstallDirectory(); |
206 | |
207 | // Root directory of current installation |
208 | static const char* getRootDirectory(); |
209 | |
210 | // Allocation chunk for the temporary spaces |
211 | static int getTempBlockSize(); |
212 | |
213 | // Caching limit for the temporary data |
214 | static FB_UINT64 getTempCacheLimit(); |
215 | |
216 | // Whether remote (NFS) files can be opened |
217 | static bool getRemoteFileOpenAbility(); |
218 | |
219 | // Startup option for the guardian |
220 | static int getGuardianOption(); |
221 | |
222 | // CPU affinity mask |
223 | static int getCpuAffinityMask(); |
224 | |
225 | // XDR buffer size |
226 | static int getTcpRemoteBufferSize(); |
227 | |
228 | // Disable Nagle algorithm |
229 | bool getTcpNoNagle() const; |
230 | |
231 | // Default database cache size |
232 | int getDefaultDbCachePages() const; |
233 | |
234 | // Connection timeout |
235 | int getConnectionTimeout() const; |
236 | |
237 | // Dummy packet interval |
238 | int getDummyPacketInterval() const; |
239 | |
240 | // Lock manager memory size |
241 | int getLockMemSize() const; |
242 | |
243 | // Lock manager hash slots |
244 | int getLockHashSlots() const; |
245 | |
246 | // Lock manager acquire spins |
247 | int getLockAcquireSpins() const; |
248 | |
249 | // Event manager memory size |
250 | int getEventMemSize() const; |
251 | |
252 | // Deadlock timeout |
253 | int getDeadlockTimeout() const; |
254 | |
255 | // Service name for remote protocols |
256 | const char* getRemoteServiceName() const; |
257 | |
258 | // Service port for INET |
259 | unsigned short getRemoteServicePort() const; |
260 | |
261 | // Pipe name for WNET |
262 | const char* getRemotePipeName() const; |
263 | |
264 | // Name for IPC-related objects |
265 | const char* getIpcName() const; |
266 | |
267 | // Unflushed writes number |
268 | int getMaxUnflushedWrites() const; |
269 | |
270 | // Unflushed write time |
271 | int getMaxUnflushedWriteTime() const; |
272 | |
273 | // Process priority level |
274 | static int getProcessPriorityLevel(); |
275 | |
276 | // Port for event processing |
277 | int getRemoteAuxPort() const; |
278 | |
279 | // Server binding NIC address |
280 | static const char* getRemoteBindAddress(); |
281 | |
282 | // Directory list for external tables |
283 | const char* getExternalFileAccess() const; |
284 | |
285 | // Directory list for databases |
286 | static const char* getDatabaseAccess(); |
287 | |
288 | // Directory list for UDF libraries |
289 | static const char* getUdfAccess(); |
290 | |
291 | // Temporary directories list |
292 | static const char* getTempDirectories(); |
293 | |
294 | // DSQL trace bitmask |
295 | static int getTraceDSQL(); |
296 | |
297 | // Abort on BUGCHECK and structured exceptions |
298 | static bool getBugcheckAbort(); |
299 | |
300 | // Let use of des hash to verify passwords |
301 | static bool getLegacyHash(); |
302 | |
303 | // GC policy |
304 | const char* getGCPolicy() const; |
305 | |
306 | // Redirection |
307 | static bool getRedirection(); |
308 | |
309 | int getDatabaseGrowthIncrement() const; |
310 | |
311 | int getFileSystemCacheThreshold() const; |
312 | |
313 | static FB_UINT64 getFileSystemCacheSize(); |
314 | |
315 | static bool getRelaxedAliasChecking(); |
316 | |
317 | static const char* getAuditTraceConfigFile(); |
318 | |
319 | static FB_UINT64 getMaxUserTraceLogSize(); |
320 | |
321 | static bool getSharedCache(); |
322 | |
323 | static bool getSharedDatabase(); |
324 | |
325 | const char* getPlugins(unsigned int type) const; |
326 | |
327 | const char* getSecurityDatabase() const; |
328 | |
329 | int getWireCrypt(WireCryptMode wcMode) const; |
330 | |
331 | bool getRemoteAccess() const; |
332 | }; |
333 | |
334 | // Implementation of interface to access master configuration file |
335 | class FirebirdConf FB_FINAL : public Firebird::RefCntIface<Firebird::IFirebirdConf, FB_FIREBIRD_CONF_VERSION> |
336 | { |
337 | public: |
338 | FirebirdConf(Config* existingConfig) |
339 | : config(existingConfig) |
340 | { } |
341 | |
342 | // IFirebirdConf implementation |
343 | unsigned int FB_CARG getKey(const char* name); |
344 | ISC_INT64 FB_CARG asInteger(unsigned int key); |
345 | const char* FB_CARG asString(unsigned int key); |
346 | FB_BOOLEAN FB_CARG asBoolean(unsigned int key); |
347 | |
348 | int FB_CARG release(); |
349 | |
350 | private: |
351 | Firebird::RefPtr<Config> config; |
352 | }; |
353 | |
354 | // Create default instance of IFirebirdConf interface |
355 | Firebird::IFirebirdConf* getFirebirdConfig(); |
356 | |
357 | #endif // COMMON_CONFIG_H |
358 | |