1 /* Copyright (C) 2003 Aleksey Krivoshey <voodoo@foss.kharkov.ua>
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include <sys/types.h>
36 typedef void (* DOTCONFCallback) (void * data, const char * buf);
38 class DOTCONFDocument;
39 class AsyncDNSMemPool;
41 class DOTCONFDocumentNode
43 friend class DOTCONFDocument;
45 DOTCONFDocumentNode * previousNode;
46 DOTCONFDocumentNode * nextNode;
47 DOTCONFDocumentNode * parentNode;
48 DOTCONFDocumentNode * childNode;
52 const DOTCONFDocument * document;
57 void pushValue(char * _value);
60 DOTCONFDocumentNode();
61 ~DOTCONFDocumentNode();
63 const char * getConfigurationFileName() const { return fileName; }
64 int getConfigurationLineNumber() const { return lineNum; }
66 const DOTCONFDocumentNode * getNextNode() const { return nextNode; }
67 const DOTCONFDocumentNode * getPreviuosNode() const { return previousNode; }
68 const DOTCONFDocumentNode * getParentNode() const { return parentNode; }
69 const DOTCONFDocumentNode * getChildNode() const { return childNode; }
70 const char * getValue(int index = 0) const;
71 const char * getName() const { return name; }
72 const DOTCONFDocument * getDocument() const { return document; }
78 enum CaseSensitive { CASESENSITIVE, CASEINSENSITIVE };
80 AsyncDNSMemPool * mempool;
82 DOTCONFDocumentNode * curParent;
83 DOTCONFDocumentNode * curPrev;
84 DOTCONFCallback errorCallback;
85 void * errorCallbackData;
88 std::list<DOTCONFDocumentNode *> nodeTree;
89 std::list<char *> requiredOptions;
90 std::list<char *> processedFiles;
93 std::list<char *> words;
94 int (* cmp_func)(const char *, const char *);
96 int checkRequiredOptions();
98 int parseFile(DOTCONFDocumentNode * _parent = NULL);
99 int checkConfig(const std::list<DOTCONFDocumentNode *>::iterator & from);
100 int cleanupLine(char * line);
101 char * getSubstitution(char * macro, int lineNum);
102 int macroSubstitute(DOTCONFDocumentNode * tagNode, int valueIndex);
105 virtual void error(int lineNum, const char * fileName, const char * fmt, ...);
108 explicit DOTCONFDocument(CaseSensitive caseSensitivity = CASESENSITIVE);
109 virtual ~DOTCONFDocument();
111 void setErrorCallback(DOTCONFCallback _callback, void * _data) { errorCallback = _callback; errorCallbackData = _data; }
113 int setContent(const char * _fileName);
115 void setRequiredOptionNames(const char ** requiredOptionNames); // !TERMINATE ARRAY WITH NULL
116 const DOTCONFDocumentNode * getFirstNode() const;
117 const DOTCONFDocumentNode * findNode(const char * nodeName, const DOTCONFDocumentNode * parentNode = NULL, const DOTCONFDocumentNode * startNode = NULL) const;