1 | |
---|
2 | |
---|
3 | |
---|
4 | #ifndef DOTCONFPP_H |
---|
5 | #define DOTCONFPP_H |
---|
6 | |
---|
7 | #include <list> |
---|
8 | |
---|
9 | #include <stdarg.h> |
---|
10 | #include <stdio.h> |
---|
11 | #include <string.h> |
---|
12 | #include <ctype.h> |
---|
13 | #include <errno.h> |
---|
14 | |
---|
15 | #include <sys/types.h> |
---|
16 | #include <sys/stat.h> |
---|
17 | |
---|
18 | #ifdef WIN32 |
---|
19 | #define PATH_MAX _MAX_PATH |
---|
20 | #define snprintf _snprintf |
---|
21 | #define strcasecmp stricmp |
---|
22 | #define realpath(path,resolved_path) _fullpath(resolved_path, path, _MAX_PATH) |
---|
23 | #include <io.h> |
---|
24 | #else |
---|
25 | #include <unistd.h> |
---|
26 | #include <limits.h> |
---|
27 | #include <stdint.h> |
---|
28 | #include <strings.h> |
---|
29 | #endif |
---|
30 | |
---|
31 | #include "mempool.h" |
---|
32 | |
---|
33 | class DOTCONFDocument; |
---|
34 | |
---|
35 | class DOTCONFDocumentNode |
---|
36 | { |
---|
37 | friend class DOTCONFDocument; |
---|
38 | private: |
---|
39 | DOTCONFDocumentNode * previousNode; |
---|
40 | DOTCONFDocumentNode * nextNode; |
---|
41 | DOTCONFDocumentNode * parentNode; |
---|
42 | DOTCONFDocumentNode * childNode; |
---|
43 | char ** values; |
---|
44 | int valuesCount; |
---|
45 | char * name; |
---|
46 | const DOTCONFDocument * document; |
---|
47 | int lineNum; |
---|
48 | char * fileName; |
---|
49 | bool closed; |
---|
50 | |
---|
51 | void pushValue(char * _value); |
---|
52 | |
---|
53 | public: |
---|
54 | DOTCONFDocumentNode(); |
---|
55 | ~DOTCONFDocumentNode(); |
---|
56 | |
---|
57 | const char * getConfigurationFileName()const { return fileName; } |
---|
58 | int getConfigurationLineNumber() const { return lineNum; } |
---|
59 | |
---|
60 | const DOTCONFDocumentNode * getNextNode() const { return nextNode; } |
---|
61 | const DOTCONFDocumentNode * getPreviuosNode() const { return previousNode; } |
---|
62 | const DOTCONFDocumentNode * getParentNode() const { return parentNode; } |
---|
63 | const DOTCONFDocumentNode * getChildNode() const { return childNode; } |
---|
64 | const char* getValue(int index = 0) const; |
---|
65 | const char * getName() const { return name; } |
---|
66 | const DOTCONFDocument * getDocument() const { return document; } |
---|
67 | }; |
---|
68 | |
---|
69 | class DOTCONFDocument |
---|
70 | { |
---|
71 | public: |
---|
72 | enum CaseSensitive { CASESENSETIVE, CASEINSENSETIVE }; |
---|
73 | protected: |
---|
74 | AsyncDNSMemPool * mempool; |
---|
75 | private: |
---|
76 | DOTCONFDocumentNode * curParent; |
---|
77 | DOTCONFDocumentNode * curPrev; |
---|
78 | int curLine; |
---|
79 | bool quoted; |
---|
80 | std::list<DOTCONFDocumentNode*> nodeTree; |
---|
81 | std::list<char*> requiredOptions; |
---|
82 | std::list<char*> processedFiles; |
---|
83 | FILE * file; |
---|
84 | char * fileName; |
---|
85 | std::list<char*> words; |
---|
86 | int (*cmp_func)(const char *, const char *); |
---|
87 | |
---|
88 | int checkRequiredOptions(); |
---|
89 | int parseLine(); |
---|
90 | int parseFile(DOTCONFDocumentNode * _parent = NULL); |
---|
91 | int checkConfig(const std::list<DOTCONFDocumentNode*>::iterator & from); |
---|
92 | int cleanupLine(char * line); |
---|
93 | char * getSubstitution(char * macro, int lineNum); |
---|
94 | int macroSubstitute(DOTCONFDocumentNode * tagNode, int valueIndex); |
---|
95 | |
---|
96 | protected: |
---|
97 | virtual void error(int lineNum, const char * fileName, const char * fmt, ...) ATTR_PRINTF(4,5); |
---|
98 | |
---|
99 | public: |
---|
100 | DOTCONFDocument(CaseSensitive caseSensitivity = CASESENSETIVE); |
---|
101 | virtual ~DOTCONFDocument(); |
---|
102 | |
---|
103 | int setContent(const char * _fileName); |
---|
104 | |
---|
105 | void setRequiredOptionNames(const char ** requiredOptionNames); |
---|
106 | const DOTCONFDocumentNode * getFirstNode() const; |
---|
107 | const DOTCONFDocumentNode * findNode(const char * nodeName, const DOTCONFDocumentNode * parentNode = NULL, const DOTCONFDocumentNode * startNode = NULL) const; |
---|
108 | }; |
---|
109 | |
---|
110 | #endif |
---|