8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-02-02 04:40:39 +01:00
firebird-mirror/src/common/config/dir_list.h

104 lines
3.4 KiB
C
Raw Normal View History

/*
* 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): ______________________________________.
*/
#ifndef DIR_LIST_H
#define DIR_LIST_H
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.
//
class ParsedPath {
Firebird::string * PathElem;
int nElem;
Firebird::string SubPath(int n) const;
public:
ParsedPath(void);
ParsedPath(const Firebird::string& path);
~ParsedPath();
2003-03-17 19:01:17 +01:00
// Take new path inside
void Parse(const Firebird::string& path);
2003-03-17 19:01:17 +01:00
// Convert internal representation to traditional one
operator Firebird::string() const;
2003-03-17 19:01:17 +01:00
// Compare with path given by constant
bool operator==(const char* path) const;
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.
bool Contains(const ParsedPath& pPath) const;
};
class DirectoryList {
private:
// ListMode must be changed together with ListKeys in dir_list.cpp
enum ListMode {NotInitialized = -1,
None = 0, Restrict = 1, Full = 2};
ListMode Mode;
ParsedPath * ConfigDirs;
int nDirs;
2003-03-17 19:01:17 +01: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.
void Initialize(void);
// Clear allocated memory and reinitialize
void Clear(void) {
delete[] ConfigDirs;
ConfigDirs = 0;
nDirs = 0;
Mode = NotInitialized;
}
// 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::string& Value,
Firebird::string Key, Firebird::string Next);
protected:
2003-03-17 19:01:17 +01:00
// Used for various configuration parameters -
// returns parameter string from Config Manager.
2003-04-06 11:08:58 +02:00
virtual const Firebird::string GetConfigString(void) const = 0;
public:
DirectoryList();
2003-04-07 17:48:55 +02:00
virtual ~DirectoryList();
// TODO
// All functions, checking DirectoryList contents,
// should be const. But with today's implementation
// of Config manager, thay have to call Initialize.
// Check, whether Path inside this DirectoryList
bool IsPathInList(const Firebird::string & Path);
// 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::string & Path,
const Firebird::string & Name,
int Access);
};
#endif // DIR_LIST_H