mirror of
https://github.com/mangosfour/server.git
synced 2025-12-20 16:37:04 +00:00
[8645] Cleanup code for config loading/store/access.
Signed-off-by: VladimirMangos <vladimir@getmangos.com>
This commit is contained in:
parent
4d3e43e814
commit
aff1a3e59f
9 changed files with 532 additions and 474 deletions
|
|
@ -1,6 +1,3 @@
|
|||
|
||||
|
||||
|
||||
#ifndef DOTCONFPP_H
|
||||
#define DOTCONFPP_H
|
||||
|
||||
|
|
@ -21,77 +18,94 @@ class DOTCONFDocument;
|
|||
|
||||
class DOTCONFDocumentNode
|
||||
{
|
||||
friend class DOTCONFDocument;
|
||||
private:
|
||||
DOTCONFDocumentNode * previousNode;
|
||||
DOTCONFDocumentNode * nextNode;
|
||||
DOTCONFDocumentNode * parentNode;
|
||||
DOTCONFDocumentNode * childNode;
|
||||
char ** values;
|
||||
int valuesCount;
|
||||
char * name;
|
||||
const DOTCONFDocument * document;
|
||||
int lineNum;
|
||||
char * fileName;
|
||||
bool closed;
|
||||
friend class DOTCONFDocument;
|
||||
|
||||
void pushValue(char * _value);
|
||||
private:
|
||||
|
||||
public:
|
||||
DOTCONFDocumentNode();
|
||||
~DOTCONFDocumentNode();
|
||||
DOTCONFDocumentNode* previousNode;
|
||||
DOTCONFDocumentNode* nextNode;
|
||||
DOTCONFDocumentNode* parentNode;
|
||||
DOTCONFDocumentNode* childNode;
|
||||
char** values;
|
||||
int valuesCount;
|
||||
char* name;
|
||||
const DOTCONFDocument* document;
|
||||
int lineNum;
|
||||
char* fileName;
|
||||
bool closed;
|
||||
|
||||
const char * getConfigurationFileName()const { return fileName; }
|
||||
int getConfigurationLineNumber() const { return lineNum; }
|
||||
void pushValue(char* _value);
|
||||
|
||||
const DOTCONFDocumentNode * getNextNode() const { return nextNode; }
|
||||
const DOTCONFDocumentNode * getPreviuosNode() const { return previousNode; }
|
||||
const DOTCONFDocumentNode * getParentNode() const { return parentNode; }
|
||||
const DOTCONFDocumentNode * getChildNode() const { return childNode; }
|
||||
const char* getValue(int index = 0) const;
|
||||
const char * getName() const { return name; }
|
||||
const DOTCONFDocument * getDocument() const { return document; }
|
||||
public:
|
||||
|
||||
DOTCONFDocumentNode();
|
||||
~DOTCONFDocumentNode();
|
||||
|
||||
const char* getConfigurationFileName() const { return fileName; }
|
||||
int getConfigurationLineNumber() const { return lineNum; }
|
||||
|
||||
const DOTCONFDocumentNode* getNextNode() const { return nextNode; }
|
||||
const DOTCONFDocumentNode* getPreviuosNode() const { return previousNode; }
|
||||
const DOTCONFDocumentNode* getParentNode() const { return parentNode; }
|
||||
const DOTCONFDocumentNode* getChildNode() const { return childNode; }
|
||||
const char* getValue(int index = 0) const;
|
||||
const char* getName() const { return name; }
|
||||
const DOTCONFDocument * getDocument() const { return document; }
|
||||
};
|
||||
|
||||
class DOTCONFDocument
|
||||
{
|
||||
public:
|
||||
enum CaseSensitive { CASESENSETIVE, CASEINSENSETIVE };
|
||||
protected:
|
||||
AsyncDNSMemPool * mempool;
|
||||
private:
|
||||
DOTCONFDocumentNode * curParent;
|
||||
DOTCONFDocumentNode * curPrev;
|
||||
int curLine;
|
||||
bool quoted;
|
||||
std::list<DOTCONFDocumentNode*> nodeTree;
|
||||
std::list<char*> requiredOptions;
|
||||
std::list<char*> processedFiles;
|
||||
FILE * file;
|
||||
char * fileName;
|
||||
std::list<char*> words;
|
||||
int (*cmp_func)(const char *, const char *);
|
||||
public:
|
||||
|
||||
int checkRequiredOptions();
|
||||
int parseLine();
|
||||
int parseFile(DOTCONFDocumentNode * _parent = NULL);
|
||||
int checkConfig(const std::list<DOTCONFDocumentNode*>::iterator & from);
|
||||
int cleanupLine(char * line);
|
||||
char * getSubstitution(char * macro, int lineNum);
|
||||
int macroSubstitute(DOTCONFDocumentNode * tagNode, int valueIndex);
|
||||
enum CaseSensitive
|
||||
{
|
||||
CASESENSITIVE,
|
||||
CASEINSENSETIVE
|
||||
};
|
||||
|
||||
protected:
|
||||
virtual void error(int lineNum, const char * fileName, const char * fmt, ...) ATTR_PRINTF(4,5);
|
||||
protected:
|
||||
|
||||
public:
|
||||
DOTCONFDocument(CaseSensitive caseSensitivity = CASESENSETIVE);
|
||||
virtual ~DOTCONFDocument();
|
||||
AsyncDNSMemPool* mempool;
|
||||
|
||||
int setContent(const char * _fileName);
|
||||
private:
|
||||
|
||||
void setRequiredOptionNames(const char ** requiredOptionNames);
|
||||
const DOTCONFDocumentNode * getFirstNode() const;
|
||||
const DOTCONFDocumentNode * findNode(const char * nodeName, const DOTCONFDocumentNode * parentNode = NULL, const DOTCONFDocumentNode * startNode = NULL) const;
|
||||
typedef std::list<char*> CharList;
|
||||
typedef std::list<DOTCONFDocumentNode*> NodeList;
|
||||
|
||||
DOTCONFDocumentNode* curParent;
|
||||
DOTCONFDocumentNode* curPrev;
|
||||
int curLine;
|
||||
bool quoted;
|
||||
NodeList nodeTree;
|
||||
CharList requiredOptions;
|
||||
CharList processedFiles;
|
||||
FILE* file;
|
||||
char* fileName;
|
||||
CharList words;
|
||||
int (*cmp_func)(const char*, const char*);
|
||||
|
||||
int checkRequiredOptions();
|
||||
int parseLine();
|
||||
int parseFile(DOTCONFDocumentNode* _parent = NULL);
|
||||
int checkConfig(const NodeList::iterator& from);
|
||||
int cleanupLine(char* line);
|
||||
char* getSubstitution(char* macro, int lineNum);
|
||||
int macroSubstitute(DOTCONFDocumentNode* tagNode, int valueIndex);
|
||||
|
||||
protected:
|
||||
|
||||
virtual void error(int lineNum, const char* fileName, const char* fmt, ...) ATTR_PRINTF(4,5);
|
||||
|
||||
public:
|
||||
|
||||
DOTCONFDocument(CaseSensitive caseSensitivity = CASESENSITIVE);
|
||||
virtual ~DOTCONFDocument();
|
||||
|
||||
int setContent(const char* _fileName);
|
||||
|
||||
void setRequiredOptionNames(const char** requiredOptionNames);
|
||||
const DOTCONFDocumentNode * getFirstNode() const;
|
||||
const DOTCONFDocumentNode * findNode(const char* nodeName, const DOTCONFDocumentNode* parentNode = NULL, const DOTCONFDocumentNode* startNode = NULL) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue