2002-11-03 17:26:12 +01:00
|
|
|
/*
|
|
|
|
* PROGRAM: Client/Server Common Code
|
|
|
|
* MODULE: config.cpp
|
|
|
|
* DESCRIPTION: Configuration manager (generic code)
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Interbase Public
|
|
|
|
* License Version 1.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy
|
|
|
|
* of the License at http://www.Inprise.com/IPL.html
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an
|
|
|
|
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
|
|
|
|
* or implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code was created by Inprise Corporation
|
|
|
|
* and its predecessors. Portions created by Inprise Corporation are
|
|
|
|
* Copyright (C) Inprise Corporation.
|
|
|
|
*
|
|
|
|
* Created by: Dmitry Yemanov <yemanov@yandex.ru>
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
* Contributor(s): ______________________________________.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "firebird.h"
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning (disable: 4786) // debug identifier truncated
|
2002-11-30 16:08:09 +01:00
|
|
|
#pragma warning (disable: 4800) // forcing value to bool 'true' or 'false'
|
2002-11-03 17:26:12 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "../../common/config/config.h"
|
|
|
|
#include "../../common/config/config_impl.h"
|
|
|
|
#include "../../common/config/config_file.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_STDLIB_H
|
|
|
|
#include <stdlib.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "../jrd/gdsassert.h"
|
|
|
|
|
|
|
|
typedef Firebird::string string;
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
*
|
2002-11-30 16:08:09 +01:00
|
|
|
* Configuration entries
|
2002-11-03 17:26:12 +01:00
|
|
|
*/
|
|
|
|
|
2002-11-30 16:08:09 +01:00
|
|
|
const ConfigImpl::ConfigEntry ConfigImpl::entries[] =
|
|
|
|
{
|
|
|
|
{TYPE_STRING, "RootDirectory", (ConfigValue) 0},
|
|
|
|
{TYPE_INTEGER, "SortMemBlockSize", (ConfigValue) 1048576},
|
|
|
|
{TYPE_INTEGER, "SortMemUpperLimit", (ConfigValue) 268435456},
|
|
|
|
{TYPE_BOOLEAN, "RemoteFileOpenAbility", (ConfigValue) false},
|
|
|
|
{TYPE_INTEGER, "GuardianOption", (ConfigValue) 1},
|
2002-12-03 14:37:06 +01:00
|
|
|
{TYPE_INTEGER, "CpuAffinityMask", (ConfigValue) 1},
|
2002-12-06 13:34:43 +01:00
|
|
|
{TYPE_BOOLEAN, "OldParameterOrdering", (ConfigValue) false},
|
|
|
|
{TYPE_INTEGER, "TcpRemoteBufferSize", (ConfigValue) 8192},
|
|
|
|
{TYPE_BOOLEAN, "TcpNoNagle", (ConfigValue) false}
|
2002-11-03 17:26:12 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Static instance of the system configuration file
|
|
|
|
*/
|
|
|
|
|
2002-11-30 16:08:09 +01:00
|
|
|
const static ConfigImpl sysConfig;
|
2002-11-03 17:26:12 +01:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Implementation interface
|
|
|
|
*/
|
|
|
|
|
|
|
|
ConfigImpl::ConfigImpl()
|
|
|
|
{
|
2002-11-30 16:08:09 +01:00
|
|
|
/* Prepare some stuff */
|
|
|
|
|
|
|
|
ConfigFile file;
|
2002-12-06 13:04:39 +01:00
|
|
|
root_dir = getRootDirectory();
|
2002-11-30 16:08:09 +01:00
|
|
|
MemoryPool *pool = getDefaultMemoryPool();
|
2002-12-02 09:25:23 +01:00
|
|
|
int size = FB_NELEM(entries);
|
2002-11-30 16:08:09 +01:00
|
|
|
values = FB_NEW(*pool) ConfigValue[size];
|
|
|
|
|
|
|
|
string val_sep = ",";
|
2002-11-03 17:26:12 +01:00
|
|
|
file.setConfigFile(getConfigFile());
|
|
|
|
|
2002-11-30 16:08:09 +01:00
|
|
|
/* Iterate through the known configuration entries */
|
2002-11-03 17:26:12 +01:00
|
|
|
|
2002-11-30 16:08:09 +01:00
|
|
|
for (int i = 0; i < size; i++)
|
2002-11-03 17:26:12 +01:00
|
|
|
{
|
2002-11-30 16:08:09 +01:00
|
|
|
ConfigEntry entry = entries[i];
|
|
|
|
string value = getValue(file, entries[i].key);
|
2002-11-03 17:26:12 +01:00
|
|
|
|
2002-11-30 16:08:09 +01:00
|
|
|
if (!value.length())
|
|
|
|
{
|
|
|
|
/* Assign the default value */
|
|
|
|
|
|
|
|
values[i] = entries[i].default_value;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Assign the actual value */
|
|
|
|
|
|
|
|
switch (entry.data_type)
|
|
|
|
{
|
|
|
|
case TYPE_BOOLEAN:
|
|
|
|
values[i] = (ConfigValue) asBoolean(value);
|
|
|
|
break;
|
|
|
|
case TYPE_INTEGER:
|
|
|
|
values[i] = (ConfigValue) asInteger(value);
|
|
|
|
break;
|
|
|
|
case TYPE_STRING:
|
|
|
|
{
|
|
|
|
const char *src = asString(value);
|
|
|
|
char *dst = FB_NEW(*pool) char[strlen(src) + 1];
|
|
|
|
strcpy(dst, src);
|
|
|
|
values[i] = (ConfigValue) dst;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TYPE_STRING_VECTOR:
|
|
|
|
;
|
|
|
|
}
|
2002-11-03 17:26:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-30 16:08:09 +01:00
|
|
|
ConfigImpl::~ConfigImpl()
|
2002-11-03 17:26:12 +01:00
|
|
|
{
|
2002-12-02 09:25:23 +01:00
|
|
|
int size = FB_NELEM(entries);
|
|
|
|
|
2002-11-30 16:08:09 +01:00
|
|
|
/* Free allocated memory */
|
2002-11-03 17:26:12 +01:00
|
|
|
|
2002-12-02 09:25:23 +01:00
|
|
|
for (int i = 0; i < size; i++)
|
2002-11-03 17:26:12 +01:00
|
|
|
{
|
2002-11-30 16:08:09 +01:00
|
|
|
if (values[i] == entries[i].default_value)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch (entries[i].data_type)
|
|
|
|
{
|
|
|
|
case TYPE_STRING:
|
|
|
|
delete[] values[i];
|
|
|
|
break;
|
|
|
|
case TYPE_STRING_VECTOR:
|
|
|
|
;
|
|
|
|
}
|
2002-11-03 17:26:12 +01:00
|
|
|
}
|
2002-11-30 16:08:09 +01:00
|
|
|
|
|
|
|
delete[] values;
|
2002-11-03 17:26:12 +01:00
|
|
|
}
|
|
|
|
|
2002-11-30 16:08:09 +01:00
|
|
|
string ConfigImpl::getValue(ConfigFile file, ConfigKey key)
|
2002-11-03 17:26:12 +01:00
|
|
|
{
|
2002-11-30 16:08:09 +01:00
|
|
|
return file.doesKeyExist(key) ? file.getString(key) : "";
|
|
|
|
}
|
2002-11-03 17:26:12 +01:00
|
|
|
|
2002-11-30 16:08:09 +01:00
|
|
|
int ConfigImpl::asInteger(const string &value)
|
|
|
|
{
|
|
|
|
return atoi(value.data());
|
|
|
|
}
|
2002-11-03 17:26:12 +01:00
|
|
|
|
2002-11-30 16:08:09 +01:00
|
|
|
bool ConfigImpl::asBoolean(const string &value)
|
|
|
|
{
|
|
|
|
return (atoi(value.data()) != 0);
|
|
|
|
}
|
2002-11-03 17:26:12 +01:00
|
|
|
|
2002-11-30 16:08:09 +01:00
|
|
|
const char* ConfigImpl::asString(const string &value)
|
|
|
|
{
|
|
|
|
return value.c_str();
|
2002-11-03 17:26:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Public interface
|
|
|
|
*/
|
|
|
|
|
2002-11-30 16:08:09 +01:00
|
|
|
const char* Config::getRootDirectory()
|
2002-11-03 17:26:12 +01:00
|
|
|
{
|
2002-11-30 16:08:09 +01:00
|
|
|
const char* result = (char*) sysConfig.values[KEY_ROOT_DIRECTORY];
|
|
|
|
return result ? result : sysConfig.root_dir;
|
2002-11-03 17:26:12 +01:00
|
|
|
}
|
|
|
|
|
2002-11-30 16:08:09 +01:00
|
|
|
int Config::getSortMemBlockSize()
|
2002-11-03 17:26:12 +01:00
|
|
|
{
|
2002-11-30 16:08:09 +01:00
|
|
|
return (int) sysConfig.values[KEY_SORT_MEM_BLOCK_SIZE];
|
2002-11-03 17:26:12 +01:00
|
|
|
}
|
|
|
|
|
2002-11-30 16:08:09 +01:00
|
|
|
int Config::getSortMemUpperLimit()
|
2002-11-03 17:26:12 +01:00
|
|
|
{
|
2002-11-30 16:08:09 +01:00
|
|
|
return (int) sysConfig.values[KEY_SORT_MEM_UPPER_LIMIT];
|
2002-11-03 17:26:12 +01:00
|
|
|
}
|
|
|
|
|
2002-11-30 16:08:09 +01:00
|
|
|
bool Config::getRemoteFileOpenAbility()
|
2002-11-03 17:26:12 +01:00
|
|
|
{
|
2002-11-30 16:08:09 +01:00
|
|
|
return (bool) sysConfig.values[KEY_REMOTE_FILE_OPEN_ABILITY];
|
2002-11-03 17:26:12 +01:00
|
|
|
}
|
|
|
|
|
2002-11-30 16:08:09 +01:00
|
|
|
int Config::getGuardianOption()
|
2002-11-03 17:26:12 +01:00
|
|
|
{
|
2002-11-30 16:08:09 +01:00
|
|
|
return (int) sysConfig.values[KEY_GUARDIAN_OPTION];
|
2002-11-03 17:26:12 +01:00
|
|
|
}
|
2002-11-10 14:41:20 +01:00
|
|
|
|
2002-11-30 16:08:09 +01:00
|
|
|
int Config::getCpuAffinityMask()
|
2002-11-10 14:41:20 +01:00
|
|
|
{
|
2002-11-30 16:08:09 +01:00
|
|
|
return (int) sysConfig.values[KEY_CPU_AFFINITY_MASK];
|
2002-11-10 14:41:20 +01:00
|
|
|
}
|
2002-12-03 14:37:06 +01:00
|
|
|
|
|
|
|
bool Config::getOldParameterOrdering()
|
|
|
|
{
|
|
|
|
return (bool) sysConfig.values[KEY_OLD_PARAMETER_ORDERING];
|
|
|
|
}
|
2002-12-06 13:34:43 +01:00
|
|
|
|
|
|
|
int Config::getTcpRemoteBufferSize()
|
|
|
|
{
|
|
|
|
return (int) sysConfig.values[KEY_TCP_REMOTE_BUFFER_SIZE];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Config::getTcpNoNagle()
|
|
|
|
{
|
|
|
|
return (bool) sysConfig.values[KEY_TCP_NO_NAGLE];
|
|
|
|
}
|