2003-03-15 21:20:41 +01:00
|
|
|
/*
|
|
|
|
* PROGRAM: Client/Server Common Code
|
|
|
|
* MODULE: dir_list.h
|
|
|
|
* DESCRIPTION: Directory listing config file operation
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Created by: Alex Peshkov <AlexPeshkov@users.sourceforge.net>
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
* Contributor(s): ______________________________________.
|
|
|
|
*/
|
|
|
|
|
2003-03-23 17:50:54 +01:00
|
|
|
#ifndef DIR_LIST_H
|
|
|
|
#define DIR_LIST_H
|
2003-03-15 21:20:41 +01:00
|
|
|
|
2003-05-01 14:20:40 +02:00
|
|
|
#include "fb_types.h"
|
|
|
|
#include "fb_string.h"
|
2003-05-05 14:26:37 +02:00
|
|
|
#include "../common/config/config_file.h"
|
2003-05-01 14:20:40 +02:00
|
|
|
|
2004-03-14 14:14:58 +01:00
|
|
|
namespace Firebird {
|
|
|
|
|
2003-03-17 19:01:17 +01:00
|
|
|
//
|
|
|
|
// This class is used internally by DirectoryList
|
|
|
|
// to store single path in format of pre-parsed
|
|
|
|
// elements of that path & perform basic operations
|
|
|
|
// with this path representation.
|
|
|
|
// Because of it's internal nature it has only
|
|
|
|
// internally required subset of possible operators.
|
|
|
|
//
|
2004-03-14 14:14:58 +01:00
|
|
|
class ParsedPath : public ObjectsArray<PathName>
|
|
|
|
{
|
|
|
|
typedef ObjectsArray<PathName> inherited;
|
2003-03-15 21:20:41 +01:00
|
|
|
public:
|
2004-03-14 14:14:58 +01:00
|
|
|
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);
|
2003-03-17 19:01:17 +01:00
|
|
|
// Convert internal representation to traditional one
|
2004-03-14 14:14:58 +01:00
|
|
|
operator PathName() const;
|
2003-03-17 19:01:17 +01:00
|
|
|
// Compare with path given by constant
|
2004-03-14 14:14:58 +01:00
|
|
|
bool operator==(const char* path) const
|
|
|
|
{
|
|
|
|
return PathName(*this) == path;
|
|
|
|
}
|
2003-03-17 19:01:17 +01:00
|
|
|
// Check, whether pPath lies inside directory tree,
|
|
|
|
// specified by *this ParsedPath. Also checks against
|
|
|
|
// possible symbolic links.
|
2004-03-14 14:14:58 +01:00
|
|
|
bool contains(const ParsedPath& pPath) const;
|
|
|
|
// Returns path, containing elements from 0 to n-1
|
|
|
|
PathName subPath(int n) const;
|
2003-03-15 21:20:41 +01:00
|
|
|
};
|
|
|
|
|
2004-03-14 14:14:58 +01:00
|
|
|
|
|
|
|
class DirectoryList : public ObjectsArray<ParsedPath> {
|
2003-03-15 21:20:41 +01:00
|
|
|
private:
|
2004-03-14 14:14:58 +01:00
|
|
|
typedef ObjectsArray<ParsedPath> inherited;
|
2003-04-06 17:01:30 +02:00
|
|
|
// ListMode must be changed together with ListKeys in dir_list.cpp
|
|
|
|
enum ListMode {NotInitialized = -1,
|
2003-05-01 14:20:40 +02:00
|
|
|
None = 0, Restrict = 1, Full = 2, SimpleList = 3};
|
2004-03-14 14:14:58 +01:00
|
|
|
ListMode mode;
|
2003-04-06 17:01:30 +02:00
|
|
|
// 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.
|
2004-03-14 14:14:58 +01:00
|
|
|
bool keyword(const ListMode keyMode, PathName& value,
|
|
|
|
PathName key, PathName next);
|
2003-03-15 21:20:41 +01:00
|
|
|
protected:
|
2004-03-14 14:14:58 +01:00
|
|
|
// Clear allocated memory and reinitialize
|
|
|
|
void clear(void) {
|
|
|
|
((inherited*)this)->clear();
|
|
|
|
mode = NotInitialized;
|
|
|
|
}
|
2003-03-17 19:01:17 +01:00
|
|
|
// Used for various configuration parameters -
|
2003-05-30 14:17:47 +02:00
|
|
|
// returns parameter PathName from Config Manager.
|
2004-03-14 14:14:58 +01:00
|
|
|
virtual const PathName getConfigString(void) const = 0;
|
2003-05-01 14:20:40 +02:00
|
|
|
// 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.
|
2004-03-14 14:14:58 +01:00
|
|
|
void initialize(bool simple_mode = false);
|
2003-03-15 21:20:41 +01:00
|
|
|
public:
|
2004-03-14 14:14:58 +01:00
|
|
|
explicit DirectoryList(MemoryPool& p)
|
|
|
|
: ObjectsArray<ParsedPath>(p), mode(NotInitialized) { }
|
|
|
|
DirectoryList()
|
|
|
|
: ObjectsArray<ParsedPath>(), mode(NotInitialized) { }
|
|
|
|
virtual ~DirectoryList() {clear();}
|
2003-03-23 17:50:54 +01:00
|
|
|
|
2003-03-15 21:20:41 +01:00
|
|
|
// Check, whether Path inside this DirectoryList
|
2004-03-14 14:14:58 +01:00
|
|
|
bool isPathInList(const PathName& path) const;
|
|
|
|
|
2003-03-23 17:50:54 +01:00
|
|
|
// 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().
|
2004-03-14 14:14:58 +01:00
|
|
|
void expandFileName(PathName& path,
|
|
|
|
const PathName& name,
|
|
|
|
int access) const;
|
2003-03-15 21:20:41 +01:00
|
|
|
};
|
2003-05-01 14:20:40 +02:00
|
|
|
|
2004-03-14 14:14:58 +01:00
|
|
|
class TempDirectoryList : protected DirectoryList {
|
|
|
|
typedef DirectoryList inherited;
|
2003-05-01 14:20:40 +02:00
|
|
|
public:
|
2004-03-14 14:14:58 +01:00
|
|
|
// directory list item(s)
|
|
|
|
typedef Pair<Left<PathName, size_t> > Item;
|
|
|
|
typedef ObjectsArray<Item> Items;
|
2003-05-01 14:20:40 +02:00
|
|
|
|
|
|
|
// public functions
|
2004-03-14 14:14:58 +01:00
|
|
|
const Item& operator[](size_t i) const
|
|
|
|
{
|
|
|
|
return items[i];
|
|
|
|
}
|
|
|
|
int Count() const
|
|
|
|
{
|
|
|
|
return items.getCount();
|
|
|
|
}
|
2003-05-01 14:20:40 +02:00
|
|
|
|
2004-03-14 14:14:58 +01:00
|
|
|
explicit TempDirectoryList(MemoryPool& p)
|
|
|
|
: DirectoryList(p), items(p)
|
|
|
|
{
|
|
|
|
initTemp();
|
|
|
|
}
|
|
|
|
TempDirectoryList()
|
|
|
|
{
|
|
|
|
initTemp();
|
|
|
|
}
|
|
|
|
~TempDirectoryList() {
|
|
|
|
items.clear();
|
|
|
|
DirectoryList::~DirectoryList();
|
|
|
|
}
|
2003-05-01 14:20:40 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
// implementation of the inherited function
|
2004-03-14 14:14:58 +01:00
|
|
|
const PathName getConfigString() const;
|
2003-05-01 14:20:40 +02:00
|
|
|
|
|
|
|
// private data
|
2004-03-14 14:14:58 +01:00
|
|
|
Items items;
|
|
|
|
|
|
|
|
// load items from DirectoryList
|
|
|
|
initTemp();
|
2003-05-01 14:20:40 +02:00
|
|
|
};
|
|
|
|
|
2004-03-14 14:14:58 +01:00
|
|
|
} //namespace Firebird
|
|
|
|
|
2003-03-23 17:50:54 +01:00
|
|
|
#endif // DIR_LIST_H
|