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-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.
|
|
|
|
//
|
2003-03-15 21:20:41 +01:00
|
|
|
class ParsedPath {
|
|
|
|
Firebird::string * PathElem;
|
|
|
|
int nElem;
|
|
|
|
Firebird::string SubPath(int n) const;
|
|
|
|
public:
|
|
|
|
ParsedPath(void);
|
2003-03-23 17:50:54 +01:00
|
|
|
ParsedPath(const Firebird::string& path);
|
2003-03-15 21:20:41 +01:00
|
|
|
~ParsedPath();
|
2003-03-17 19:01:17 +01:00
|
|
|
// Take new path inside
|
2003-03-23 17:50:54 +01:00
|
|
|
void Parse(const Firebird::string& path);
|
2003-03-17 19:01:17 +01:00
|
|
|
// Convert internal representation to traditional one
|
2003-03-23 17:50:54 +01:00
|
|
|
operator Firebird::string() const;
|
2003-03-17 19:01:17 +01:00
|
|
|
// Compare with path given by constant
|
2003-03-23 17:50:54 +01:00
|
|
|
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.
|
2003-03-23 17:50:54 +01:00
|
|
|
bool Contains(const ParsedPath& pPath) const;
|
2003-03-15 21:20:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class DirectoryList {
|
|
|
|
private:
|
2003-04-06 17:01:30 +02:00
|
|
|
// ListMode must be changed together with ListKeys in dir_list.cpp
|
|
|
|
enum ListMode {NotInitialized = -1,
|
|
|
|
None = 0, Restrict = 1, Full = 2};
|
|
|
|
ListMode Mode;
|
2003-03-15 21:20:41 +01:00
|
|
|
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.
|
2003-03-15 21:20:41 +01:00
|
|
|
void Initialize(void);
|
2003-04-06 17:01:30 +02:00
|
|
|
// 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);
|
2003-03-15 21:20:41 +01:00
|
|
|
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;
|
2003-03-15 21:20:41 +01:00
|
|
|
public:
|
|
|
|
DirectoryList();
|
2003-04-07 17:48:55 +02:00
|
|
|
virtual ~DirectoryList();
|
2003-03-23 17:50:54 +01:00
|
|
|
|
|
|
|
// TODO
|
|
|
|
// All functions, checking DirectoryList contents,
|
|
|
|
// should be const. But with today's implementation
|
|
|
|
// of Config manager, thay have to call Initialize.
|
|
|
|
|
2003-03-15 21:20:41 +01:00
|
|
|
// Check, whether Path inside this DirectoryList
|
|
|
|
bool IsPathInList(const Firebird::string & Path);
|
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().
|
|
|
|
void ExpandFileName(Firebird::string & Path,
|
|
|
|
const Firebird::string & Name,
|
|
|
|
int Access);
|
2003-03-15 21:20:41 +01:00
|
|
|
};
|
2003-03-23 17:50:54 +01:00
|
|
|
#endif // DIR_LIST_H
|