summaryrefslogtreecommitdiff
path: root/src/modules.cpp
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2004-05-01 19:58:59 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2004-05-01 19:58:59 +0000
commit0f2cf28d39404881b9719330ca86757c51b87bad (patch)
tree0a4ae8cedfbe3a2e60ebc140be8d06c38a687a8a /src/modules.cpp
parentdfd170b1798c2515a446dc957172972da56e715b (diff)
Added documentation of new ConfigReader methods suggested by Azhrarn for sanity
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@772 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules.cpp')
-rw-r--r--src/modules.cpp70
1 files changed, 66 insertions, 4 deletions
diff --git a/src/modules.cpp b/src/modules.cpp
index e05ab4566..23b45e8aa 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -553,7 +553,9 @@ int Server::CountUsers(chanrec* c)
ConfigReader::ConfigReader()
{
this->cache = new std::stringstream(std::stringstream::in | std::stringstream::out);
- this->error = LoadConf(CONFIG_FILE,this->cache);
+ this->readerror = LoadConf(CONFIG_FILE,this->cache);
+ if (!this->readerror)
+ this->error = CONF_FILE_NOT_FOUND;
}
@@ -567,7 +569,9 @@ ConfigReader::~ConfigReader()
ConfigReader::ConfigReader(std::string filename)
{
this->cache = new std::stringstream(std::stringstream::in | std::stringstream::out);
- this->error = LoadConf(filename.c_str(),this->cache);
+ this->readerror = LoadConf(filename.c_str(),this->cache);
+ if (!this->readerror)
+ this->error = CONF_FILE_NOT_FOUND;
};
std::string ConfigReader::ReadValue(std::string tag, std::string name, int index)
@@ -577,10 +581,68 @@ std::string ConfigReader::ReadValue(std::string tag, std::string name, int index
char n[MAXBUF];
strncpy(t,tag.c_str(),MAXBUF);
strncpy(n,name.c_str(),MAXBUF);
- ReadConf(cache,t,n,index,val);
+ int res = ReadConf(cache,t,n,index,val);
+ if (!res)
+ {
+ this->error = CONF_VALUE_NOT_FOUND;
+ return "";
+ }
return std::string(val);
}
+bool ConfigReader::ReadFlag(std::string tag, std::string name, int index)
+{
+ char val[MAXBUF];
+ char t[MAXBUF];
+ char n[MAXBUF];
+ strncpy(t,tag.c_str(),MAXBUF);
+ strncpy(n,name.c_str(),MAXBUF);
+ int res = ReadConf(cache,t,n,index,val);
+ if (!res)
+ {
+ this->error = CONF_VALUE_NOT_FOUND;
+ return false;
+ }
+ std::string s = val;
+ return ((s == "yes") || (s == "YES") || (s == "true") || (s == "TRUE") || (s == "1"));
+}
+
+long ConfigReader::ReadInteger(std::string tag, std::string name, int index, bool needs_unsigned)
+{
+ char val[MAXBUF];
+ char t[MAXBUF];
+ char n[MAXBUF];
+ strncpy(t,tag.c_str(),MAXBUF);
+ strncpy(n,name.c_str(),MAXBUF);
+ int res = ReadConf(cache,t,n,index,val);
+ if (!res)
+ {
+ this->error = CONF_VALUE_NOT_FOUND;
+ return 0;
+ }
+ for (int i = 0; i < strlen(val); i++)
+ {
+ if (!isdigit(val[i]))
+ {
+ this->error = CONF_NOT_A_NUMBER;
+ return 0;
+ }
+ }
+ if ((needs_unsigned) && (atoi(val)<0))
+ {
+ this->error = CONF_NOT_UNSIGNED;
+ return 0;
+ }
+ return atoi(val);
+}
+
+long ConfigReader::GetError()
+{
+ long olderr = this->error;
+ this->error = 0;
+ return olderr;
+}
+
int ConfigReader::Enumerate(std::string tag)
{
@@ -594,7 +656,7 @@ int ConfigReader::EnumerateValues(std::string tag, int index)
bool ConfigReader::Verify()
{
- return this->error;
+ return this->readerror;
}