mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-23 19:23:03 +01:00
Pools support
This commit is contained in:
parent
84e17c41cf
commit
221ae2fa2a
@ -129,7 +129,7 @@ const ConfigImpl& ConfigImpl::instance()
|
||||
config_init_lock.enter();
|
||||
if (!sys_config) {
|
||||
#endif
|
||||
sys_config = FB_NEW(*getDefaultMemoryPool()) ConfigImpl;
|
||||
sys_config = FB_NEW(*getDefaultMemoryPool()) ConfigImpl(*getDefaultMemoryPool());
|
||||
#ifdef MULTI_THREAD
|
||||
}
|
||||
} catch(const std::exception&) {
|
||||
@ -149,15 +149,14 @@ const ConfigImpl& ConfigImpl::instance()
|
||||
* Implementation interface
|
||||
*/
|
||||
|
||||
ConfigImpl::ConfigImpl()
|
||||
ConfigImpl::ConfigImpl(MemoryPool& p) : ConfigRoot(p)
|
||||
{
|
||||
/* Prepare some stuff */
|
||||
|
||||
ConfigFile file(true);
|
||||
root_dir = getRootDirectory();
|
||||
MemoryPool *pool = getDefaultMemoryPool();
|
||||
int size = FB_NELEM(entries);
|
||||
values = FB_NEW(*pool) ConfigValue[size];
|
||||
values = FB_NEW(p) ConfigValue[size];
|
||||
|
||||
string val_sep = ",";
|
||||
file.setConfigFile(getConfigFile());
|
||||
@ -190,7 +189,7 @@ ConfigImpl::ConfigImpl()
|
||||
case TYPE_STRING:
|
||||
{
|
||||
const char *src = asString(value);
|
||||
char *dst = FB_NEW(*pool) char[strlen(src) + 1];
|
||||
char *dst = FB_NEW(p) char[strlen(src) + 1];
|
||||
strcpy(dst, src);
|
||||
values[i] = (ConfigValue) dst;
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include "fb_string.h"
|
||||
#include "fb_vector.h"
|
||||
#include "../jrd/os/path_utils.h"
|
||||
|
||||
/**
|
||||
Since the original (isc.cpp) code wasn't able to provide powerful and
|
||||
@ -318,4 +319,14 @@ public:
|
||||
static int getTraceDSQL();
|
||||
};
|
||||
|
||||
namespace Firebird {
|
||||
|
||||
// Add appropriate file prefix.
|
||||
inline void Prefix(PathName& result, const PathName& file)
|
||||
{
|
||||
PathUtils::concatPath(result, Config::getRootDirectory(), file);
|
||||
}
|
||||
|
||||
} //namespace Firebird
|
||||
|
||||
#endif // CONFIG_H
|
||||
|
@ -30,15 +30,17 @@
|
||||
|
||||
#include "firebird.h"
|
||||
|
||||
#include "../../common/classes/auto.h"
|
||||
#include "../../common/config/config_file.h"
|
||||
#include "../jrd/os/fbsyslog.h"
|
||||
#include "../jrd/ib_stdio.h"
|
||||
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
//#include <fstream>
|
||||
//#include <iostream>
|
||||
|
||||
// Invalid or missing CONF_FILE may lead to severe errors
|
||||
// in applications. That's why for regular SERVER builds
|
||||
@ -55,61 +57,6 @@
|
||||
// config_file works with OS case-sensitivity
|
||||
typedef Firebird::PathName string;
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Allow case-insensitive comparison
|
||||
*/
|
||||
|
||||
bool ConfigFile::key_compare::operator()(const string& x, const string& y) const
|
||||
{
|
||||
return x < y;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Strip leading spaces
|
||||
*/
|
||||
|
||||
void ConfigFile::stripLeadingWhiteSpace(string& s)
|
||||
{
|
||||
if (!s.size())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const string::size_type startPos = s.find_first_not_of(" \t\r");
|
||||
if (startPos == string::npos)
|
||||
{
|
||||
s.erase(); // nothing but air
|
||||
}
|
||||
else if (startPos)
|
||||
{
|
||||
s = s.substr(startPos);
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Strip trailing spaces
|
||||
*/
|
||||
|
||||
void ConfigFile::stripTrailingWhiteSpace(string& s)
|
||||
{
|
||||
if (!s.size())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string::size_type endPos = s.find_last_not_of(" \t\r");
|
||||
if (endPos != string::npos)
|
||||
{
|
||||
// Note that endPos is the index to the last non-ws char
|
||||
// why we have to inc. it
|
||||
++endPos;
|
||||
s = s.substr(0, endPos);
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Strip any comments
|
||||
@ -150,16 +97,8 @@ string ConfigFile::getString(const string& key)
|
||||
{
|
||||
checkLoadConfig();
|
||||
|
||||
mymap_t::iterator lookup;
|
||||
|
||||
lookup = parameters.find(key);
|
||||
|
||||
if (lookup != parameters.end())
|
||||
{
|
||||
return lookup->second;
|
||||
}
|
||||
|
||||
return string();
|
||||
int pos;
|
||||
return parameters.find(key, pos) ? parameters[pos].second : string();
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -169,7 +108,7 @@ string ConfigFile::getString(const string& key)
|
||||
|
||||
string ConfigFile::parseKeyFrom(const string& inputLine, string::size_type& endPos)
|
||||
{
|
||||
endPos = inputLine.find_first_of("=\t");
|
||||
endPos = inputLine.find_first_of("=");
|
||||
if (endPos == string::npos)
|
||||
{
|
||||
return inputLine;
|
||||
@ -197,7 +136,7 @@ string ConfigFile::parseValueFrom(string inputLine, string::size_type initialPos
|
||||
return string();
|
||||
}
|
||||
|
||||
stripTrailingWhiteSpace(inputLine);
|
||||
inputLine.rtrim(" \t\r");
|
||||
return inputLine.substr(startPos);
|
||||
}
|
||||
|
||||
@ -219,13 +158,27 @@ void ConfigFile::checkLoadConfig()
|
||||
* Load file immediately
|
||||
*/
|
||||
|
||||
namespace {
|
||||
class FileClose
|
||||
{
|
||||
public:
|
||||
static void clear(IB_FILE *f)
|
||||
{
|
||||
if (f) {
|
||||
ib_fclose(f);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void ConfigFile::loadConfig()
|
||||
{
|
||||
isLoadedFlg = true;
|
||||
|
||||
parameters.clear();
|
||||
|
||||
FILE* ifile = fopen(configFile.c_str(), "rt");
|
||||
Firebird::AutoPtr<IB_FILE, FileClose> ifile =
|
||||
fopen(configFile.c_str(), "rt");
|
||||
|
||||
#ifdef EXIT_ON_NO_CONF
|
||||
int BadLinesCount = 0;
|
||||
@ -256,7 +209,7 @@ void ConfigFile::loadConfig()
|
||||
inputLine.LoadFromFile(ifile);
|
||||
|
||||
stripComments(inputLine);
|
||||
stripLeadingWhiteSpace(inputLine);
|
||||
inputLine.ltrim(" \t\r");
|
||||
|
||||
if (!inputLine.size())
|
||||
{
|
||||
@ -279,13 +232,11 @@ void ConfigFile::loadConfig()
|
||||
string::size_type endPos;
|
||||
|
||||
string key = parseKeyFrom(inputLine, endPos);
|
||||
stripTrailingWhiteSpace(key);
|
||||
key.rtrim(" \t\r");
|
||||
// TODO: here we must check for correct parameter spelling !
|
||||
string value = parseValueFrom(inputLine, endPos);
|
||||
|
||||
// parameters.insert(pair<string, string>(key, value));
|
||||
// Just to display yet another template function
|
||||
parameters.insert(std::make_pair(key, value));
|
||||
parameters.add(Parameter(getPool(), key, value));
|
||||
}
|
||||
#ifdef EXIT_ON_NO_CONF
|
||||
if (BadLinesCount && fExitOnError) {
|
||||
|
@ -35,6 +35,8 @@
|
||||
#include <map>
|
||||
|
||||
#include "../../common/classes/alloc.h"
|
||||
#include "../../common/classes/fb_pair.h"
|
||||
#include "../../common/classes/objects_array.h"
|
||||
#include "fb_string.h"
|
||||
|
||||
/**
|
||||
@ -54,25 +56,23 @@
|
||||
(common/config/config.cpp) and server-side alias manager (jrd/db_alias.cpp).
|
||||
**/
|
||||
|
||||
class ConfigFile
|
||||
class ConfigFile : public Firebird::AutoStorage
|
||||
{
|
||||
// config_file works with OS case-sensitivity
|
||||
typedef Firebird::PathName string;
|
||||
|
||||
// used to provide proper filename handling in various OS
|
||||
class key_compare : public std::binary_function<const string&, const string&, bool>
|
||||
{
|
||||
public:
|
||||
key_compare() {}
|
||||
bool operator()(const string&, const string&) const;
|
||||
};
|
||||
|
||||
typedef std::map <string, string, key_compare,
|
||||
Firebird::allocator <std::pair <const string, string> > > mymap_t;
|
||||
typedef Firebird::Pair<Firebird::Full<string, string> > Parameter;
|
||||
typedef Firebird::SortedObjectsArray <Parameter,
|
||||
Firebird::InlineStorage<Parameter *, 100>,
|
||||
string, Firebird::FirstObjectKey<Parameter> > mymap_t;
|
||||
|
||||
public:
|
||||
ConfigFile(bool ExitOnError)
|
||||
: isLoadedFlg(false), fExitOnError(ExitOnError) {}
|
||||
explicit ConfigFile(MemoryPool& p, bool ExitOnError)
|
||||
: AutoStorage(p), isLoadedFlg(false),
|
||||
fExitOnError(ExitOnError), parameters(getPool()) {}
|
||||
explicit ConfigFile(bool ExitOnError)
|
||||
: AutoStorage(), isLoadedFlg(false),
|
||||
fExitOnError(ExitOnError), parameters(getPool()) {}
|
||||
|
||||
// configuration file management
|
||||
const string getConfigFile() { return configFile; }
|
||||
@ -88,8 +88,6 @@ public:
|
||||
string getString(const string&);
|
||||
|
||||
// utilities
|
||||
static void stripLeadingWhiteSpace(string&);
|
||||
static void stripTrailingWhiteSpace(string&);
|
||||
static void stripComments(string&);
|
||||
static string parseKeyFrom(const string&, string::size_type&);
|
||||
static string parseValueFrom(string, string::size_type);
|
||||
|
@ -72,7 +72,7 @@ public:
|
||||
inline static const ConfigImpl& instance();
|
||||
|
||||
private:
|
||||
ConfigImpl();
|
||||
explicit ConfigImpl(MemoryPool& p);
|
||||
|
||||
static const ConfigEntry entries[];
|
||||
const char *root_dir;
|
||||
|
@ -25,88 +25,59 @@
|
||||
#include "../jrd/os/path_utils.h"
|
||||
#include "../jrd/gds_proto.h"
|
||||
|
||||
#define New FB_NEW(*getDefaultMemoryPool())
|
||||
namespace Firebird {
|
||||
|
||||
ParsedPath::ParsedPath(void) {
|
||||
PathElem = 0;
|
||||
nElem = 0;
|
||||
}
|
||||
|
||||
ParsedPath::ParsedPath(const Firebird::PathName& path) {
|
||||
PathElem = 0;
|
||||
Parse(path);
|
||||
}
|
||||
|
||||
ParsedPath::~ParsedPath() {
|
||||
delete[] PathElem;
|
||||
}
|
||||
|
||||
void ParsedPath::Parse(const Firebird::PathName& path) {
|
||||
delete[] PathElem;
|
||||
void ParsedPath::parse(const PathName& path) {
|
||||
clear();
|
||||
|
||||
if (path.length() == 1) {
|
||||
nElem = 1;
|
||||
PathElem = New Firebird::PathName[1];
|
||||
PathElem[0] = path;
|
||||
add(path);
|
||||
return;
|
||||
}
|
||||
|
||||
nElem = 0;
|
||||
Firebird::PathName oldpath = path;
|
||||
PathName oldpath = path;
|
||||
do {
|
||||
Firebird::PathName newpath, elem;
|
||||
PathName newpath, elem;
|
||||
PathUtils::splitLastComponent(newpath, elem, oldpath);
|
||||
oldpath = newpath;
|
||||
nElem++;
|
||||
insert(0, elem);
|
||||
} while (oldpath.length() > 0);
|
||||
|
||||
PathElem = New Firebird::PathName[nElem];
|
||||
oldpath = path;
|
||||
for (int i = nElem; i--; ) {
|
||||
Firebird::PathName newpath;
|
||||
PathUtils::splitLastComponent(newpath, PathElem[i], oldpath);
|
||||
oldpath = newpath;
|
||||
}
|
||||
}
|
||||
|
||||
bool ParsedPath::operator==(const char* path) const {
|
||||
return (Firebird::PathName(*this) == Firebird::PathName(path));
|
||||
}
|
||||
|
||||
Firebird::PathName ParsedPath::SubPath(int n) const {
|
||||
Firebird::PathName rc = PathElem[0];
|
||||
PathName ParsedPath::subPath(int n) const {
|
||||
PathName rc = (*this)[0];
|
||||
if (PathUtils::isRelative(rc + PathUtils::dir_sep))
|
||||
rc = PathUtils::dir_sep + rc;
|
||||
for (int i = 1; i < n; i++) {
|
||||
Firebird::PathName newpath;
|
||||
PathUtils::concatPath(newpath, rc, PathElem[i]);
|
||||
PathName newpath;
|
||||
PathUtils::concatPath(newpath, rc, (*this)[i]);
|
||||
rc = newpath;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
ParsedPath::operator Firebird::PathName() const {
|
||||
if (!PathElem)
|
||||
ParsedPath::operator PathName() const {
|
||||
if (!getCount())
|
||||
return "";
|
||||
return SubPath(nElem);
|
||||
return subPath(getCount());
|
||||
}
|
||||
|
||||
bool ParsedPath::Contains(const ParsedPath& pPath) const {
|
||||
int nFullElem = nElem;
|
||||
if (nFullElem > 1 && PathElem[nFullElem - 1].length() == 0)
|
||||
bool ParsedPath::contains(const ParsedPath& pPath) const {
|
||||
int nFullElem = getCount();
|
||||
if (nFullElem > 1 && (*this)[nFullElem - 1].length() == 0)
|
||||
nFullElem--;
|
||||
|
||||
if (pPath.nElem < nFullElem) {
|
||||
if (pPath.getCount() < nFullElem) {
|
||||
return false;
|
||||
}
|
||||
int i;
|
||||
for (i = 0; i < nFullElem; i++) {
|
||||
if (!PathUtils::comparePaths(pPath.PathElem[i], PathElem[i])) {
|
||||
if (pPath[i] != (*this)[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (i = nFullElem + 1; i <= pPath.nElem; i++) {
|
||||
Firebird::PathName x = pPath.SubPath(i);
|
||||
for (i = nFullElem + 1; i <= pPath.getCount(); i++) {
|
||||
PathName x = pPath.subPath(i);
|
||||
if (PathUtils::isSymLink(x)) {
|
||||
return false;
|
||||
}
|
||||
@ -114,127 +85,106 @@ bool ParsedPath::Contains(const ParsedPath& pPath) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
DirectoryList::DirectoryList() {
|
||||
ConfigDirs = 0;
|
||||
nDirs = 0;
|
||||
Mode = NotInitialized;
|
||||
}
|
||||
|
||||
DirectoryList::~DirectoryList() {
|
||||
Clear();
|
||||
}
|
||||
|
||||
bool DirectoryList::KeyWord(
|
||||
const ListMode KeyMode,
|
||||
Firebird::PathName& Value,
|
||||
Firebird::PathName Key,
|
||||
Firebird::PathName Next
|
||||
bool DirectoryList::keyword(
|
||||
const ListMode keyMode,
|
||||
PathName& value,
|
||||
PathName key,
|
||||
PathName next
|
||||
) {
|
||||
if (Value.length() < Key.length()) {
|
||||
if (value.length() < key.length()) {
|
||||
return false;
|
||||
}
|
||||
Firebird::PathName KeyValue = Value.substr(0, Key.length());
|
||||
if (KeyValue != Key) {
|
||||
PathName keyValue = value.substr(0, key.length());
|
||||
if (keyValue != key) {
|
||||
return false;
|
||||
}
|
||||
if (Next.length() > 0) {
|
||||
if (Value.length() == Key.length()) {
|
||||
if (next.length() > 0) {
|
||||
if (value.length() == key.length()) {
|
||||
return false;
|
||||
}
|
||||
KeyValue = Value.substr(Key.length());
|
||||
if (Next.find(KeyValue[0]) == Firebird::PathName::npos) {
|
||||
keyValue = value.substr(key.length());
|
||||
if (next.find(keyValue[0]) == PathName::npos) {
|
||||
return false;
|
||||
}
|
||||
Firebird::PathName::size_type startPos =
|
||||
KeyValue.find_first_not_of(Next);
|
||||
if (startPos == Firebird::PathName::npos) {
|
||||
PathName::size_type startPos = keyValue.find_first_not_of(next);
|
||||
if (startPos == PathName::npos) {
|
||||
return false;
|
||||
}
|
||||
Value = KeyValue.substr(startPos);
|
||||
value = keyValue.substr(startPos);
|
||||
}
|
||||
else {
|
||||
if (Value.length() > Key.length()) {
|
||||
if (value.length() > key.length()) {
|
||||
return false;
|
||||
}
|
||||
Value.erase();
|
||||
value.erase();
|
||||
}
|
||||
Mode = KeyMode;
|
||||
mode = keyMode;
|
||||
return true;
|
||||
}
|
||||
|
||||
void DirectoryList::Initialize(bool simple_mode) {
|
||||
if (Mode != NotInitialized)
|
||||
void DirectoryList::initialize(bool simple_mode) {
|
||||
if (mode != NotInitialized)
|
||||
return;
|
||||
|
||||
Clear();
|
||||
clear();
|
||||
|
||||
Firebird::PathName val = GetConfigString();
|
||||
PathName val = getConfigString();
|
||||
|
||||
if (simple_mode) {
|
||||
Mode = SimpleList;
|
||||
mode = SimpleList;
|
||||
}
|
||||
else {
|
||||
if (KeyWord(None, val, "None", "") ||
|
||||
KeyWord(Full, val, "Full", "")) {
|
||||
if (keyword(None, val, "None", "") ||
|
||||
keyword(Full, val, "Full", "")) {
|
||||
return;
|
||||
}
|
||||
if (! KeyWord(Restrict, val, "Restrict", " \t")) {
|
||||
if (! keyword(Restrict, val, "Restrict", " \t")) {
|
||||
gds__log("DirectoryList: unknown parameter '%s', "
|
||||
"defaulting to None", val.c_str());
|
||||
Mode = None;
|
||||
mode = None;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
nDirs = 1;
|
||||
unsigned int i;
|
||||
for (i = 0; i < val.length(); i++) {
|
||||
unsigned int last = 0;
|
||||
PathName root = Config::getRootDirectory();
|
||||
for (int i = 0; i < val.length(); i++) {
|
||||
if (val[i] == ';') {
|
||||
nDirs++;
|
||||
}
|
||||
}
|
||||
ConfigDirs = New ParsedPath[nDirs];
|
||||
unsigned int Last = 0;
|
||||
nDirs = 0;
|
||||
Firebird::PathName Root = Config::getRootDirectory();
|
||||
for (i = 0; i < val.length(); i++) {
|
||||
if (val[i] == ';') {
|
||||
Firebird::PathName dir = "";
|
||||
if (i > Last) {
|
||||
dir = val.substr(Last, i-Last);
|
||||
Trim(dir);
|
||||
PathName dir = "";
|
||||
if (i > last) {
|
||||
dir = val.substr(last, i - last);
|
||||
dir.trim();
|
||||
}
|
||||
if (PathUtils::isRelative(dir)) {
|
||||
Firebird::PathName newdir;
|
||||
PathUtils::concatPath(newdir, Root, dir);
|
||||
PathName newdir;
|
||||
PathUtils::concatPath(newdir, root, dir);
|
||||
dir = newdir;
|
||||
}
|
||||
ConfigDirs[nDirs++].Parse(dir);
|
||||
Last = i + 1;
|
||||
add(ParsedPath(dir));
|
||||
last = i + 1;
|
||||
}
|
||||
}
|
||||
Firebird::PathName dir = "";
|
||||
if (i > Last) {
|
||||
dir = val.substr(Last, i - Last);
|
||||
Trim(dir);
|
||||
PathName dir = "";
|
||||
if (i > last) {
|
||||
dir = val.substr(last, i - last);
|
||||
dir.trim();
|
||||
}
|
||||
if (PathUtils::isRelative(dir)) {
|
||||
Firebird::PathName newdir;
|
||||
PathUtils::concatPath(newdir, Root, dir);
|
||||
PathName newdir;
|
||||
PathUtils::concatPath(newdir, root, dir);
|
||||
dir = newdir;
|
||||
}
|
||||
ConfigDirs[nDirs++].Parse(dir);
|
||||
add(ParsedPath(dir));
|
||||
}
|
||||
|
||||
bool DirectoryList::IsPathInList(const Firebird::PathName& path) {
|
||||
bool DirectoryList::isPathInList(const PathName& path) const {
|
||||
#ifdef BOOT_BUILD
|
||||
return true;
|
||||
#else //BOOT_BUILD
|
||||
Initialize();
|
||||
fb_assert(mode != NotInitialized);
|
||||
|
||||
// Handle special cases
|
||||
switch(Mode) {
|
||||
case NotInitialized:
|
||||
switch(mode) {
|
||||
case None:
|
||||
return false;
|
||||
case Full:
|
||||
@ -247,19 +197,19 @@ bool DirectoryList::IsPathInList(const Firebird::PathName& path) {
|
||||
// Example of IIS attack attempt:
|
||||
// "GET /scripts/..%252f../winnt/system32/cmd.exe?/c+dir HTTP/1.0"
|
||||
// (live from apache access.log :)
|
||||
if (path.find(PathUtils::up_dir_link) != Firebird::PathName::npos)
|
||||
if (path.find(PathUtils::up_dir_link) != PathName::npos)
|
||||
return false;
|
||||
|
||||
Firebird::PathName varpath = path;
|
||||
PathName varpath(path);
|
||||
if (PathUtils::isRelative(path)) {
|
||||
PathUtils::concatPath(varpath,
|
||||
Firebird::PathName(Config::getRootDirectory()), path);
|
||||
PathName(Config::getRootDirectory()), path);
|
||||
}
|
||||
|
||||
ParsedPath pPath = path;
|
||||
ParsedPath pPath(path);
|
||||
bool rc = 0;
|
||||
for (int i = 0; i < nDirs; i++) {
|
||||
if (ConfigDirs[i].Contains(pPath)) {
|
||||
for (int i = 0; i < getCount(); i++) {
|
||||
if ((*this)[i].contains(pPath)) {
|
||||
rc = true;
|
||||
break;
|
||||
}
|
||||
@ -268,49 +218,42 @@ bool DirectoryList::IsPathInList(const Firebird::PathName& path) {
|
||||
#endif //BOOT_BUILD
|
||||
}
|
||||
|
||||
void DirectoryList::ExpandFileName (
|
||||
Firebird::PathName & Path,
|
||||
const Firebird::PathName & Name,
|
||||
int Access
|
||||
) {
|
||||
if (Mode == NotInitialized)
|
||||
Initialize();
|
||||
for (int i = 0; i < nDirs; i++) {
|
||||
PathUtils::concatPath(Path, ConfigDirs[i], Name);
|
||||
if (PathUtils::canAccess(Path, Access)) {
|
||||
void DirectoryList::expandFileName (
|
||||
PathName& path,
|
||||
const PathName& name,
|
||||
int access
|
||||
) const {
|
||||
fb_assert(mode != NotInitialized);
|
||||
for (int i = 0; i < getCount(); i++) {
|
||||
PathUtils::concatPath(path, (*this)[i], name);
|
||||
if (PathUtils::canAccess(path, access)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
Path = Name;
|
||||
path = name;
|
||||
}
|
||||
|
||||
TempDirectoryList::TempDirectoryList() : items(0)
|
||||
TempDirectoryList::initTemp()
|
||||
{
|
||||
Initialize(true);
|
||||
|
||||
// Get directory list
|
||||
const ParsedPath* dir_list = DirList();
|
||||
initialize(true);
|
||||
|
||||
// Iterate through directories to parse them
|
||||
// and fill the "items" vector
|
||||
for (size_t i = 0; i < DirCount(); i++) {
|
||||
Item item;
|
||||
Firebird::PathName dir = dir_list[i];
|
||||
for (size_t i = 0; i < getCount(); i++) {
|
||||
PathName dir = (*(inherited*)this)[i];
|
||||
size_t pos = dir.rfind(" ");
|
||||
long size = atol(dir.substr(pos + 1, Firebird::PathName::npos).c_str());
|
||||
if (pos != Firebird::PathName::npos && !size) {
|
||||
pos = Firebird::PathName::npos;
|
||||
long size = atol(dir.substr(pos + 1, PathName::npos).c_str());
|
||||
if (pos != PathName::npos && !size) {
|
||||
pos = PathName::npos;
|
||||
}
|
||||
if (size <= 0) {
|
||||
size = ALLROOM;
|
||||
}
|
||||
item.dir = dir.substr(0, pos);
|
||||
item.size = size;
|
||||
items.push_back(item);
|
||||
items.add(Item(dir.substr(0, pos), size));
|
||||
}
|
||||
}
|
||||
|
||||
const Firebird::PathName TempDirectoryList::GetConfigString() const
|
||||
const PathName TempDirectoryList::getConfigString() const
|
||||
{
|
||||
const char* value;
|
||||
char tmp_buf[MAXPATHLEN];
|
||||
@ -320,15 +263,7 @@ const Firebird::PathName TempDirectoryList::GetConfigString() const
|
||||
gds__temp_dir(tmp_buf);
|
||||
value = tmp_buf;
|
||||
}
|
||||
return Firebird::PathName(value);
|
||||
return PathName(value);
|
||||
}
|
||||
|
||||
size_t TempDirectoryList::Count() const
|
||||
{
|
||||
return items.size();
|
||||
}
|
||||
|
||||
const TempDirectoryList::Item& TempDirectoryList::operator[](size_t i) const
|
||||
{
|
||||
return items[i];
|
||||
}
|
||||
} //namespace Firebird
|
@ -24,9 +24,10 @@
|
||||
|
||||
#include "fb_types.h"
|
||||
#include "fb_string.h"
|
||||
#include "fb_vector.h"
|
||||
#include "../common/config/config_file.h"
|
||||
|
||||
namespace Firebird {
|
||||
|
||||
//
|
||||
// This class is used internally by DirectoryList
|
||||
// to store single path in format of pre-parsed
|
||||
@ -35,107 +36,129 @@
|
||||
// Because of it's internal nature it has only
|
||||
// internally required subset of possible operators.
|
||||
//
|
||||
class ParsedPath {
|
||||
Firebird::PathName * PathElem;
|
||||
int nElem;
|
||||
Firebird::PathName SubPath(int n) const;
|
||||
class ParsedPath : public ObjectsArray<PathName>
|
||||
{
|
||||
typedef ObjectsArray<PathName> inherited;
|
||||
public:
|
||||
ParsedPath(void);
|
||||
ParsedPath(const Firebird::PathName& path);
|
||||
~ParsedPath();
|
||||
// Take new path inside
|
||||
void Parse(const Firebird::PathName& path);
|
||||
explicit ParsedPath(MemoryPool& p) : ObjectsArray<PathName>(p) { }
|
||||
explicit ParsedPath(MemoryPool& p, const PathName& path)
|
||||
: ObjectsArray<PathName>(p)
|
||||
{
|
||||
parse(path);
|
||||
}
|
||||
explicit ParsedPath() : ObjectsArray<PathName>() { }
|
||||
explicit ParsedPath(const PathName& path)
|
||||
: ObjectsArray<PathName>()
|
||||
{
|
||||
parse(path);
|
||||
}
|
||||
// Take new path inside
|
||||
void parse(const PathName& path);
|
||||
// Convert internal representation to traditional one
|
||||
operator Firebird::PathName() const;
|
||||
operator PathName() const;
|
||||
// Compare with path given by constant
|
||||
bool operator==(const char* path) const;
|
||||
bool operator==(const char* path) const
|
||||
{
|
||||
return PathName(*this) == path;
|
||||
}
|
||||
// Check, whether pPath lies inside directory tree,
|
||||
// specified by *this ParsedPath. Also checks against
|
||||
// possible symbolic links.
|
||||
bool Contains(const ParsedPath& pPath) const;
|
||||
bool contains(const ParsedPath& pPath) const;
|
||||
// Returns path, containing elements from 0 to n-1
|
||||
PathName subPath(int n) const;
|
||||
};
|
||||
|
||||
class DirectoryList {
|
||||
|
||||
class DirectoryList : public ObjectsArray<ParsedPath> {
|
||||
private:
|
||||
typedef ObjectsArray<ParsedPath> inherited;
|
||||
// ListMode must be changed together with ListKeys in dir_list.cpp
|
||||
enum ListMode {NotInitialized = -1,
|
||||
None = 0, Restrict = 1, Full = 2, SimpleList = 3};
|
||||
ListMode Mode;
|
||||
ParsedPath * ConfigDirs;
|
||||
int nDirs;
|
||||
// Clear allocated memory and reinitialize
|
||||
void Clear(void) {
|
||||
delete[] ConfigDirs;
|
||||
ConfigDirs = 0;
|
||||
nDirs = 0;
|
||||
Mode = NotInitialized;
|
||||
}
|
||||
ListMode mode;
|
||||
// Check, whether Value begins with Key,
|
||||
// followed by any character from Next.
|
||||
// If Next is empty, Value shoult exactly match Key.
|
||||
// If Key found, sets Mode to KeyMode and returns true.
|
||||
bool KeyWord(const ListMode KeyMode, Firebird::PathName& Value,
|
||||
Firebird::PathName Key, Firebird::PathName Next);
|
||||
bool keyword(const ListMode keyMode, PathName& value,
|
||||
PathName key, PathName next);
|
||||
protected:
|
||||
// Clear allocated memory and reinitialize
|
||||
void clear(void) {
|
||||
((inherited*)this)->clear();
|
||||
mode = NotInitialized;
|
||||
}
|
||||
// Used for various configuration parameters -
|
||||
// returns parameter PathName from Config Manager.
|
||||
virtual const Firebird::PathName GetConfigString(void) const = 0;
|
||||
virtual const PathName getConfigString(void) const = 0;
|
||||
// Initialize loads data from Config Manager.
|
||||
// With simple mutex add-on may be easily used to
|
||||
// load them dynamically. Now called locally
|
||||
// when IsPathInList() invoked first time.
|
||||
void Initialize(bool simple_mode = false);
|
||||
// May be used in derived classes for custom behaviour
|
||||
size_t DirCount() { return nDirs; }
|
||||
const ParsedPath* DirList() { return ConfigDirs; }
|
||||
void initialize(bool simple_mode = false);
|
||||
public:
|
||||
DirectoryList();
|
||||
virtual ~DirectoryList();
|
||||
|
||||
// TODO
|
||||
// All functions, checking DirectoryList contents,
|
||||
// should be const. But with today's implementation
|
||||
// of Config manager, thay have to call Initialize.
|
||||
explicit DirectoryList(MemoryPool& p)
|
||||
: ObjectsArray<ParsedPath>(p), mode(NotInitialized) { }
|
||||
DirectoryList()
|
||||
: ObjectsArray<ParsedPath>(), mode(NotInitialized) { }
|
||||
virtual ~DirectoryList() {clear();}
|
||||
|
||||
// Check, whether Path inside this DirectoryList
|
||||
bool IsPathInList(const Firebird::PathName & Path);
|
||||
bool isPathInList(const PathName& path) const;
|
||||
|
||||
// Search for file Name in all direcories of DirectoryList.
|
||||
// If found, return full path to it in Path.
|
||||
// Otherwise Path = Name.
|
||||
// Last parameter defines required access rights
|
||||
// to the file - like access().
|
||||
void ExpandFileName(Firebird::PathName & Path,
|
||||
const Firebird::PathName & Name,
|
||||
int Access);
|
||||
|
||||
// Temporary - while we use STL basic_string
|
||||
// for PathName representation we don't have this
|
||||
static void Trim(Firebird::PathName & s) {
|
||||
ConfigFile::stripLeadingWhiteSpace(s);
|
||||
ConfigFile::stripTrailingWhiteSpace(s);
|
||||
}
|
||||
void expandFileName(PathName& path,
|
||||
const PathName& name,
|
||||
int access) const;
|
||||
};
|
||||
|
||||
class TempDirectoryList : private DirectoryList {
|
||||
class TempDirectoryList : protected DirectoryList {
|
||||
typedef DirectoryList inherited;
|
||||
public:
|
||||
// directory list item
|
||||
struct Item {
|
||||
Firebird::PathName dir;
|
||||
size_t size;
|
||||
};
|
||||
// directory list item(s)
|
||||
typedef Pair<Left<PathName, size_t> > Item;
|
||||
typedef ObjectsArray<Item> Items;
|
||||
|
||||
// public functions
|
||||
size_t Count() const;
|
||||
const Item& operator[](size_t) const;
|
||||
const Item& operator[](size_t i) const
|
||||
{
|
||||
return items[i];
|
||||
}
|
||||
int Count() const
|
||||
{
|
||||
return items.getCount();
|
||||
}
|
||||
|
||||
TempDirectoryList();
|
||||
explicit TempDirectoryList(MemoryPool& p)
|
||||
: DirectoryList(p), items(p)
|
||||
{
|
||||
initTemp();
|
||||
}
|
||||
TempDirectoryList()
|
||||
{
|
||||
initTemp();
|
||||
}
|
||||
~TempDirectoryList() {
|
||||
items.clear();
|
||||
DirectoryList::~DirectoryList();
|
||||
}
|
||||
|
||||
private:
|
||||
// implementation of the inherited function
|
||||
const Firebird::PathName GetConfigString() const;
|
||||
const PathName getConfigString() const;
|
||||
|
||||
// private data
|
||||
Firebird::vector<Item> items;
|
||||
Items items;
|
||||
|
||||
// load items from DirectoryList
|
||||
initTemp();
|
||||
};
|
||||
|
||||
} //namespace Firebird
|
||||
|
||||
#endif // DIR_LIST_H
|
||||
|
@ -51,7 +51,7 @@
|
||||
getConfigFile() member function.
|
||||
**/
|
||||
|
||||
class ConfigRoot
|
||||
class ConfigRoot : public Firebird::PermanentStorage
|
||||
{
|
||||
// config_file works with OS case-sensitivity
|
||||
typedef Firebird::PathName string;
|
||||
@ -70,7 +70,9 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
ConfigRoot() {
|
||||
ConfigRoot(MemoryPool& p) : PermanentStorage(p),
|
||||
root_dir(getPool()), config_file(getPool())
|
||||
{
|
||||
GetRoot();
|
||||
config_file = root_dir + string(CONFIG_FILE);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user