]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/configreader.cpp
Fix <die:value>, its been broken for quite some time. (whoops *hide*)
[user/henk/code/inspircd.git] / src / configreader.cpp
index 11aa026c2759b1dec6f8d0ab2066ab8989eb6639..eba798a564a38752a66692178b6c19af8afc78e5 100644 (file)
@@ -25,7 +25,7 @@ std::vector<std::string> old_module_names, new_module_names, added_modules, remo
 ServerConfig::ServerConfig(InspIRCd* Instance) : ServerInstance(Instance)
 {
        this->ClearStack();
-       *TempDir = *ServerName = *Network = *ServerDesc = *AdminName = '\0';
+       *ServerName = *Network = *ServerDesc = *AdminName = '\0';
        *HideWhoisServer = *AdminEmail = *AdminNick = *diepass = *restartpass = '\0';
        *CustomVersion = *motd = *rules = *PrefixQuit = *DieValue = *DNSServer = '\0';
        *UserStats = *ModPath = *MyExecutable = *DisabledCommands = *PID = '\0';
@@ -140,13 +140,6 @@ bool NoValidation(ServerConfig* conf, const char* tag, const char* value, ValueI
        return true;
 }
 
-bool ValidateTempDir(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
-{
-       if (!*(data.GetString()))
-               data.Set("/tmp");
-       return true;
-}
 bool ValidateMaxTargets(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
 {
        if ((data.GetInteger() < 0) || (data.GetInteger() > 31))
@@ -315,6 +308,17 @@ bool ValidateRules(ServerConfig* conf, const char* tag, const char* value, Value
        return true;
 }
 
+bool ValidateDie(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
+{
+       if (!*data.GetString())
+       {
+               conf->GetInstance()->Log(DEFAULT,"Die value is set: \"%s\", terminating.", data.GetString());
+               printf("\n\nERROR: %s\n\n", data.GetString());
+               exit(ERROR);
+       }
+       return true;
+}
+
 bool ValidateWhoWas(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
 {
        conf->WhoWasMaxKeep = conf->GetInstance()->Duration(data.GetString());
@@ -564,7 +568,6 @@ void ServerConfig::Read(bool bail, userrec* user)
                {"options",             "hidebans",                     new ValueContainerBool (&this->HideBans),               DT_BOOLEAN, NoValidation},
                {"options",             "hidewhois",                    new ValueContainerChar (this->HideWhoisServer),         DT_CHARPTR, NoValidation},
                {"options",             "operspywhois",                 new ValueContainerBool (&this->OperSpyWhois),           DT_BOOLEAN, NoValidation},
-               {"options",             "tempdir",                      new ValueContainerChar (this->TempDir),                 DT_CHARPTR, ValidateTempDir},
                {"options",             "nouserdns",                    new ValueContainerBool (&this->NoUserDns),              DT_BOOLEAN, NoValidation},
                {"options",             "syntaxhints",                  new ValueContainerBool (&this->SyntaxHints),            DT_BOOLEAN, NoValidation},
                {"options",             "cyclehosts",                   new ValueContainerBool (&this->CycleHosts),             DT_BOOLEAN, NoValidation},
@@ -572,6 +575,7 @@ void ServerConfig::Read(bool bail, userrec* user)
                {"whowas",              "groupsize",                    new ValueContainerInt  (&this->WhoWasGroupSize),        DT_INTEGER, NoValidation},
                {"whowas",              "maxgroups",                    new ValueContainerInt  (&this->WhoWasMaxGroups),        DT_INTEGER, NoValidation},
                {"whowas",              "maxkeep",                      new ValueContainerChar (maxkeep),                       DT_CHARPTR, ValidateWhoWas},
+               {"die",                 "value",                        new ValueContainerChar (this->DieValue),                DT_CHARPTR, ValidateDie},
                {NULL}
        };
 
@@ -1310,7 +1314,7 @@ int ServerConfig::ConfVarEnum(ConfigDataHash &target, const std::string &tag, in
  */
 bool ServerConfig::ReadFile(file_cache &F, const char* fname)
 {
-       FILE* file;
+       FILE* file = NULL;
        char linebuf[MAXBUF];
 
        F.clear();
@@ -1334,8 +1338,10 @@ bool ServerConfig::ReadFile(file_cache &F, const char* fname)
        {
                while (!feof(file))
                {
-                       fgets(linebuf, sizeof(linebuf), file);
-                       linebuf[strlen(linebuf)-1] = 0;
+                       if (fgets(linebuf, sizeof(linebuf), file))
+                               linebuf[strlen(linebuf)-1] = 0;
+                       else
+                               *linebuf = 0;
 
                        if (!feof(file))
                        {
@@ -1399,12 +1405,14 @@ bool ServerConfig::DirValid(const char* dirandfile)
        if (getcwd(buffer, MAXBUF ) == NULL )
                return false;
 
-       chdir(work);
+       if (chdir(work) == -1)
+               return false;
 
        if (getcwd(otherdir, MAXBUF ) == NULL )
                return false;
 
-       chdir(buffer);
+       if (chdir(buffer) == -1)
+               return false;
 
        size_t t = strlen(work);
 
@@ -1451,12 +1459,15 @@ std::string ServerConfig::GetFullProgDir(char** argv, int argc)
        if (getcwd(buffer, MAXBUF) == NULL)
                return "";
 
-       chdir(work);
+       if (chdir(work) == -1)
+               return "";
 
        if (getcwd(otherdir, MAXBUF) == NULL)
                return "";
 
-       chdir(buffer);
+       if (chdir(buffer) == -1)
+               return "";
+
        return otherdir;
 }
 
@@ -1465,3 +1476,55 @@ InspIRCd* ServerConfig::GetInstance()
        return ServerInstance;
 }
 
+
+ValueItem::ValueItem(int value)
+{
+       std::stringstream n;
+       n << value;
+       v = n.str();
+}
+
+ValueItem::ValueItem(bool value)
+{
+       std::stringstream n;
+       n << value;
+       v = n.str();
+}
+
+ValueItem::ValueItem(char* value)
+{
+       v = value;
+}
+
+void ValueItem::Set(char* value)
+{
+       v = value;
+}
+
+void ValueItem::Set(const char* value)
+{
+       v = value;
+}
+
+void ValueItem::Set(int value)
+{
+       std::stringstream n;
+       n << value;
+       v = n.str();
+}
+
+int ValueItem::GetInteger()
+{
+       return atoi(v.c_str());
+}
+
+char* ValueItem::GetString()
+{
+       return (char*)v.c_str();
+}
+
+bool ValueItem::GetBool()
+{
+       return (GetInteger() || v == "yes" || v == "true");
+}
+