1 .TH "ConfigReader" 3 "2 May 2004" "InspIRCd" \" -*- nroff -*-
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.
11 \fC#include <modules.h>\fP
13 Inherits \fBclassbase\fP.
15 .SS "Public Member Functions"
19 .RI "\fBConfigReader\fP ()"
21 .RI "\fIDefault constructor.\fP"
23 .RI "\fBConfigReader\fP (std::string filename)"
25 .RI "\fIOverloaded constructor.\fP"
27 .RI "\fB~ConfigReader\fP ()"
29 .RI "\fIDefault destructor.\fP"
31 .RI "std::string \fBReadValue\fP (std::string tag, std::string name, int index)"
33 .RI "\fIRetrieves a value from the config file.\fP"
35 .RI "bool \fBReadFlag\fP (std::string tag, std::string name, int index)"
37 .RI "\fIRetrieves a boolean value from the config file.\fP"
39 .RI "long \fBReadInteger\fP (std::string tag, std::string name, int index, bool needs_unsigned)"
41 .RI "\fIRetrieves an integer value from the config file.\fP"
43 .RI "long \fBGetError\fP ()"
45 .RI "\fIReturns the last error to occur.\fP"
47 .RI "int \fBEnumerate\fP (std::string tag)"
49 .RI "\fICounts the number of times a given tag appears in the config file.\fP"
51 .RI "bool \fBVerify\fP ()"
53 .RI "\fIReturns true if a config file is valid.\fP"
55 .RI "int \fBEnumerateValues\fP (std::string tag, int index)"
57 .RI "\fIReturns the number of items within a tag.\fP"
59 .SS "Protected Attributes"
63 .RI "std::stringstream * \fBcache\fP"
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"
67 .RI "bool \fBreaderror\fP"
69 .RI "\fIUsed to store errors.\fP"
71 .RI "long \fBerror\fP"
74 .SH "Detailed Description"
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.
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.
80 Definition at line 618 of file modules.h.
81 .SH "Constructor & Destructor Documentation"
83 .SS "ConfigReader::ConfigReader ()"
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.
87 References cache, CONF_FILE_NOT_FOUND, error, and readerror.
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;
97 .SS "ConfigReader::ConfigReader (std::string filename)"
99 Overloaded constructor.This constructor initialises the ConfigReader class to read a user-specified config fileDefinition at line 569 of file modules.cpp.
101 References cache, CONF_FILE_NOT_FOUND, error, and readerror.
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;
111 .SS "ConfigReader::~ConfigReader ()"
113 Default destructor.This method destroys the ConfigReader class.Definition at line 562 of file modules.cpp.
120 565 delete this->cache;
123 .SH "Member Function Documentation"
125 .SS "int ConfigReader::Enumerate (std::string tag)"
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.
131 649 return EnumConf(cache,tag.c_str());
134 .SS "int ConfigReader::EnumerateValues (std::string tag, int index)"
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.
140 654 return EnumValues(cache, tag.c_str(), index);
143 .SS "long ConfigReader::GetError ()"
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.
151 641 long olderr = this->error;
156 .SS "bool ConfigReader::ReadFlag (std::string tag, std::string name, int index)"
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.
160 References CONF_VALUE_NOT_FOUND, and error.
164 595 char val[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);
172 603 this->error = CONF_VALUE_NOT_FOUND;
175 606 std::string s = val;
176 607 return ((s == 'yes') || (s == 'YES') || (s == 'true') || (s == 'TRUE') || (s == '1'));
179 .SS "long ConfigReader::ReadInteger (std::string tag, std::string name, int index, bool needs_unsigned)"
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.
183 References CONF_NOT_A_NUMBER, CONF_NOT_UNSIGNED, CONF_VALUE_NOT_FOUND, and error.
187 612 char val[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);
195 620 this->error = CONF_VALUE_NOT_FOUND;
198 623 for (int i = 0; i < strlen(val); i++)
200 625 if (!isdigit(val[i]))
202 627 this->error = CONF_NOT_A_NUMBER;
206 631 if ((needs_unsigned) && (atoi(val)<0))
208 633 this->error = CONF_NOT_UNSIGNED;
211 636 return atoi(val);
214 .SS "std::string ConfigReader::ReadValue (std::string tag, std::string name, int index)"
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.
218 References CONF_VALUE_NOT_FOUND, and error.
222 579 char val[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);
230 587 this->error = CONF_VALUE_NOT_FOUND;
233 590 return std::string(val);
236 .SS "bool ConfigReader::Verify ()"
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.
240 References readerror.
244 659 return this->readerror;
247 .SH "Member Data Documentation"
249 .SS "std::stringstream* ConfigReader::cache\fC [protected]\fP"
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.
253 Referenced by ConfigReader(), and ~ConfigReader().
254 .SS "long ConfigReader::error\fC [protected]\fP"
256 Definition at line 630 of file modules.h.
258 Referenced by ConfigReader(), GetError(), ReadFlag(), ReadInteger(), and ReadValue().
259 .SS "bool ConfigReader::readerror\fC [protected]\fP"
261 Used to store errors.Definition at line 629 of file modules.h.
263 Referenced by ConfigReader(), and Verify().
267 Generated automatically by Doxygen for InspIRCd from the source code.