]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - docs/man/man3/ConfigReader.3
Added manpages
[user/henk/code/inspircd.git] / docs / man / man3 / ConfigReader.3
1 .TH "ConfigReader" 3 "2 May 2004" "InspIRCd" \" -*- nroff -*-
2 .ad l
3 .nh
4 .SH NAME
5 ConfigReader \- Allows reading of values from configuration files This class allows a module to read from either the main configuration file (inspircd.conf) or from a module-specified configuration file. 
6
7 .PP
8 .SH SYNOPSIS
9 .br
10 .PP
11 \fC#include <modules.h>\fP
12 .PP
13 Inherits \fBclassbase\fP.
14 .PP
15 .SS "Public Member Functions"
16
17 .in +1c
18 .ti -1c
19 .RI "\fBConfigReader\fP ()"
20 .br
21 .RI "\fIDefault constructor.\fP"
22 .ti -1c
23 .RI "\fBConfigReader\fP (std::string filename)"
24 .br
25 .RI "\fIOverloaded constructor.\fP"
26 .ti -1c
27 .RI "\fB~ConfigReader\fP ()"
28 .br
29 .RI "\fIDefault destructor.\fP"
30 .ti -1c
31 .RI "std::string \fBReadValue\fP (std::string tag, std::string name, int index)"
32 .br
33 .RI "\fIRetrieves a value from the config file.\fP"
34 .ti -1c
35 .RI "bool \fBReadFlag\fP (std::string tag, std::string name, int index)"
36 .br
37 .RI "\fIRetrieves a boolean value from the config file.\fP"
38 .ti -1c
39 .RI "long \fBReadInteger\fP (std::string tag, std::string name, int index, bool needs_unsigned)"
40 .br
41 .RI "\fIRetrieves an integer value from the config file.\fP"
42 .ti -1c
43 .RI "long \fBGetError\fP ()"
44 .br
45 .RI "\fIReturns the last error to occur.\fP"
46 .ti -1c
47 .RI "int \fBEnumerate\fP (std::string tag)"
48 .br
49 .RI "\fICounts the number of times a given tag appears in the config file.\fP"
50 .ti -1c
51 .RI "bool \fBVerify\fP ()"
52 .br
53 .RI "\fIReturns true if a config file is valid.\fP"
54 .ti -1c
55 .RI "int \fBEnumerateValues\fP (std::string tag, int index)"
56 .br
57 .RI "\fIReturns the number of items within a tag.\fP"
58 .in -1c
59 .SS "Protected Attributes"
60
61 .in +1c
62 .ti -1c
63 .RI "std::stringstream * \fBcache\fP"
64 .br
65 .RI "\fIThe contents of the configuration file This protected member should never be accessed by a module (and cannot be accessed unless the core is changed).\fP"
66 .ti -1c
67 .RI "bool \fBreaderror\fP"
68 .br
69 .RI "\fIUsed to store errors.\fP"
70 .ti -1c
71 .RI "long \fBerror\fP"
72 .br
73 .in -1c
74 .SH "Detailed Description"
75 .PP 
76 Allows reading of values from configuration files This class allows a module to read from either the main configuration file (inspircd.conf) or from a module-specified configuration file.
77
78 It may either be instantiated with one parameter or none. Constructing the class using one parameter allows you to specify a path to your own configuration file, otherwise, inspircd.conf is read. 
79 .PP
80 Definition at line 618 of file modules.h.
81 .SH "Constructor & Destructor Documentation"
82 .PP 
83 .SS "ConfigReader::ConfigReader ()"
84 .PP
85 Default constructor.This constructor initialises the ConfigReader class to read the inspircd.conf file as specified when running ./configure.Definition at line 553 of file modules.cpp.
86 .PP
87 References cache, CONF_FILE_NOT_FOUND, error, and readerror.
88 .PP
89 .nf
90 554 {
91 555         this->cache = new std::stringstream(std::stringstream::in | std::stringstream::out);
92 556         this->readerror = LoadConf(CONFIG_FILE,this->cache);
93 557         if (!this->readerror)
94 558                 this->error = CONF_FILE_NOT_FOUND;
95 559 }
96 .fi
97 .SS "ConfigReader::ConfigReader (std::string filename)"
98 .PP
99 Overloaded constructor.This constructor initialises the ConfigReader class to read a user-specified config fileDefinition at line 569 of file modules.cpp.
100 .PP
101 References cache, CONF_FILE_NOT_FOUND, error, and readerror.
102 .PP
103 .nf
104 570 {
105 571         this->cache = new std::stringstream(std::stringstream::in | std::stringstream::out);
106 572         this->readerror = LoadConf(filename.c_str(),this->cache);
107 573         if (!this->readerror)
108 574                 this->error = CONF_FILE_NOT_FOUND;
109 575 };
110 .fi
111 .SS "ConfigReader::~ConfigReader ()"
112 .PP
113 Default destructor.This method destroys the ConfigReader class.Definition at line 562 of file modules.cpp.
114 .PP
115 References cache.
116 .PP
117 .nf
118 563 {
119 564         if (this->cache)
120 565                 delete this->cache;
121 566 }
122 .fi
123 .SH "Member Function Documentation"
124 .PP 
125 .SS "int ConfigReader::Enumerate (std::string tag)"
126 .PP
127 Counts the number of times a given tag appears in the config file.This method counts the number of times a tag appears in a config file, for use where there are several tags of the same kind, e.g. with opers and connect types. It can be used with the index value of \fBConfigReader::ReadValue\fP to loop through all copies of a multiple instance tag.Definition at line 647 of file modules.cpp.
128 .PP
129 .nf
130 648 {
131 649         return EnumConf(cache,tag.c_str());
132 650 }
133 .fi
134 .SS "int ConfigReader::EnumerateValues (std::string tag, int index)"
135 .PP
136 Returns the number of items within a tag.For example if the tag was <test tag='blah' data='foo'> then this function would return 2. Spaces and newlines both qualify as valid seperators between values.Definition at line 652 of file modules.cpp.
137 .PP
138 .nf
139 653 {
140 654         return EnumValues(cache, tag.c_str(), index);
141 655 }
142 .fi
143 .SS "long ConfigReader::GetError ()"
144 .PP
145 Returns the last error to occur.Valid errors can be found by looking in \fBmodules.h\fP. Any nonzero value indicates an error condition. A call to \fBGetError()\fP resets the error flag back to 0.Definition at line 639 of file modules.cpp.
146 .PP
147 References error.
148 .PP
149 .nf
150 640 {
151 641         long olderr = this->error;
152 642         this->error = 0;
153 643         return olderr;
154 644 }
155 .fi
156 .SS "bool ConfigReader::ReadFlag (std::string tag, std::string name, int index)"
157 .PP
158 Retrieves a boolean value from the config file.This method retrieves a boolean value from the config file. Where multiple copies of the tag exist in the config file, index indicates which of the values to retrieve. The values '1', 'yes' and 'true' in the config file count as true to ReadFlag, and any other value counts as false.Definition at line 593 of file modules.cpp.
159 .PP
160 References CONF_VALUE_NOT_FOUND, and error.
161 .PP
162 .nf
163 594 {
164 595         char val[MAXBUF];
165 596         char t[MAXBUF];
166 597         char n[MAXBUF];
167 598         strncpy(t,tag.c_str(),MAXBUF);
168 599         strncpy(n,name.c_str(),MAXBUF);
169 600         int res = ReadConf(cache,t,n,index,val);
170 601         if (!res)
171 602         {
172 603                 this->error = CONF_VALUE_NOT_FOUND;
173 604                 return false;
174 605         }
175 606         std::string s = val;
176 607         return ((s == 'yes') || (s == 'YES') || (s == 'true') || (s == 'TRUE') || (s == '1'));
177 608 }
178 .fi
179 .SS "long ConfigReader::ReadInteger (std::string tag, std::string name, int index, bool needs_unsigned)"
180 .PP
181 Retrieves an integer value from the config file.This method retrieves an integer value from the config file. Where multiple copies of the tag exist in the config file, index indicates which of the values to retrieve. Any invalid integer values in the tag will cause the objects error value to be set, and any call to \fBGetError()\fP will return CONF_INVALID_NUMBER to be returned. needs_unsigned is set if the number must be unsigned. If a signed number is placed into a tag which is specified unsigned, 0 will be returned and \fBGetError()\fP will return CONF_NOT_UNSIGNEDDefinition at line 610 of file modules.cpp.
182 .PP
183 References CONF_NOT_A_NUMBER, CONF_NOT_UNSIGNED, CONF_VALUE_NOT_FOUND, and error.
184 .PP
185 .nf
186 611 {
187 612         char val[MAXBUF];
188 613         char t[MAXBUF];
189 614         char n[MAXBUF];
190 615         strncpy(t,tag.c_str(),MAXBUF);
191 616         strncpy(n,name.c_str(),MAXBUF);
192 617         int res = ReadConf(cache,t,n,index,val);
193 618         if (!res)
194 619         {
195 620                 this->error = CONF_VALUE_NOT_FOUND;
196 621                 return 0;
197 622         }
198 623         for (int i = 0; i < strlen(val); i++)
199 624         {
200 625                 if (!isdigit(val[i]))
201 626                 {
202 627                         this->error = CONF_NOT_A_NUMBER;
203 628                         return 0;
204 629                 }
205 630         }
206 631         if ((needs_unsigned) && (atoi(val)<0))
207 632         {
208 633                 this->error = CONF_NOT_UNSIGNED;
209 634                 return 0;
210 635         }
211 636         return atoi(val);
212 637 }
213 .fi
214 .SS "std::string ConfigReader::ReadValue (std::string tag, std::string name, int index)"
215 .PP
216 Retrieves a value from the config file.This method retrieves a value from the config file. Where multiple copies of the tag exist in the config file, index indicates which of the values to retrieve.Definition at line 577 of file modules.cpp.
217 .PP
218 References CONF_VALUE_NOT_FOUND, and error.
219 .PP
220 .nf
221 578 {
222 579         char val[MAXBUF];
223 580         char t[MAXBUF];
224 581         char n[MAXBUF];
225 582         strncpy(t,tag.c_str(),MAXBUF);
226 583         strncpy(n,name.c_str(),MAXBUF);
227 584         int res = ReadConf(cache,t,n,index,val);
228 585         if (!res)
229 586         {
230 587                 this->error = CONF_VALUE_NOT_FOUND;
231 588                 return '';
232 589         }
233 590         return std::string(val);
234 591 }
235 .fi
236 .SS "bool ConfigReader::Verify ()"
237 .PP
238 Returns true if a config file is valid.This method is partially implemented and will only return false if the config file does not exist or could not be opened.Definition at line 657 of file modules.cpp.
239 .PP
240 References readerror.
241 .PP
242 .nf
243 658 {
244 659         return this->readerror;
245 660 }
246 .fi
247 .SH "Member Data Documentation"
248 .PP 
249 .SS "std::stringstream* ConfigReader::cache\fC [protected]\fP"
250 .PP
251 The contents of the configuration file This protected member should never be accessed by a module (and cannot be accessed unless the core is changed).It will contain a pointer to the configuration file data with unneeded data (such as comments) stripped from it.Definition at line 626 of file modules.h.
252 .PP
253 Referenced by ConfigReader(), and ~ConfigReader().
254 .SS "long ConfigReader::error\fC [protected]\fP"
255 .PP
256 Definition at line 630 of file modules.h.
257 .PP
258 Referenced by ConfigReader(), GetError(), ReadFlag(), ReadInteger(), and ReadValue().
259 .SS "bool ConfigReader::readerror\fC [protected]\fP"
260 .PP
261 Used to store errors.Definition at line 629 of file modules.h.
262 .PP
263 Referenced by ConfigReader(), and Verify().
264
265 .SH "Author"
266 .PP 
267 Generated automatically by Doxygen for InspIRCd from the source code.