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>
39 typedef void (* DOTCONFCallback) (void * data, const char * buf);
41 class DOTCONFDocument;
43 class DOTCONFDocumentNode
45 friend class DOTCONFDocument;
47 DOTCONFDocumentNode * previousNode;
48 DOTCONFDocumentNode * nextNode;
49 DOTCONFDocumentNode * parentNode;
50 DOTCONFDocumentNode * childNode;
54 const DOTCONFDocument * document;
59 void pushValue(char * _value);
62 DOTCONFDocumentNode();
63 ~DOTCONFDocumentNode();
65 const char * getConfigurationFileName() const { return fileName; }
66 int getConfigurationLineNumber() const { return lineNum; }
68 const DOTCONFDocumentNode * getNextNode() const { return nextNode; }
69 const DOTCONFDocumentNode * getPreviuosNode() const { return previousNode; }
70 const DOTCONFDocumentNode * getParentNode() const { return parentNode; }
71 const DOTCONFDocumentNode * getChildNode() const { return childNode; }
72 const char * getValue(int index = 0) const;
73 const char * getName() const { return name; }
74 const DOTCONFDocument * getDocument() const { return document; }
80 enum CaseSensitive { CASESENSITIVE, CASEINSENSITIVE };
82 AsyncDNSMemPool * mempool;
84 DOTCONFDocumentNode * curParent;
85 DOTCONFDocumentNode * curPrev;
86 DOTCONFCallback errorCallback;
87 void * errorCallbackData;
90 std::list<DOTCONFDocumentNode *> nodeTree;
91 std::list<char *> requiredOptions;
92 std::list<char *> processedFiles;
95 std::list<char *> words;
96 int (* cmp_func)(const char *, const char *);
98 int checkRequiredOptions();
100 int parseFile(DOTCONFDocumentNode * _parent = NULL);
101 int checkConfig(const std::list<DOTCONFDocumentNode *>::iterator & from);
102 int cleanupLine(char * line);
103 char * getSubstitution(char * macro, int lineNum);
104 int macroSubstitute(DOTCONFDocumentNode * tagNode, int valueIndex);
107 virtual void error(int lineNum, const char * fileName, const char * fmt, ...);
110 DOTCONFDocument(CaseSensitive caseSensitivity = CASESENSITIVE);
111 virtual ~DOTCONFDocument();
113 void setErrorCallback(DOTCONFCallback _callback, void * _data) { errorCallback = _callback; errorCallbackData = _data; };
115 int setContent(const char * _fileName);
117 void setRequiredOptionNames(const char ** requiredOptionNames); // !TERMINATE ARRAY WITH NULL
118 const DOTCONFDocumentNode * getFirstNode() const;
119 const DOTCONFDocumentNode * findNode(const char * nodeName, const DOTCONFDocumentNode * parentNode = NULL, const DOTCONFDocumentNode * startNode = NULL) const;