]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/configreader.cpp
Remove Command and ModeHandler objects in their destructors; fixes possible pointer...
[user/henk/code/inspircd.git] / src / configreader.cpp
index 21e4c2321603eb59c14739013795753384659605..70c99e8ae4f7257a7a28a6b315b336d91bc43dfb 100644 (file)
@@ -382,14 +382,6 @@ static bool ValidateModeLists(ServerConfig* conf, const char*, const char*, Valu
        return true;
 }
 
-static bool ValidateExemptChanOps(ServerConfig* conf, const char*, const char*, ValueItem &data)
-{
-       memset(conf->ExemptChanOps, 0, sizeof(conf->ExemptChanOps));
-       for (const unsigned char* x = (const unsigned char*)data.GetString(); *x; ++x)
-               conf->ExemptChanOps[*x] = true;
-       return true;
-}
-
 static bool ValidateInvite(ServerConfig* conf, const char*, const char*, ValueItem &data)
 {
        const std::string& v = data.GetValue();
@@ -410,11 +402,11 @@ static bool ValidateSID(ServerConfig* conf, const char*, const char*, ValueItem
 {
        ServerInstance->Logs->Log("CONFIG",DEFAULT,"Validating server id");
 
-       const char *sid = data.GetString();
+       const std::string& sid = data.GetValue();
 
-       if (*sid && !ServerInstance->IsSID(sid))
+       if (!sid.empty() && !ServerInstance->IsSID(sid))
        {
-               throw CoreException(std::string(sid) + " is not a valid server ID. A server ID must be 3 characters long, with the first character a digit and the next two characters a digit or letter.");
+               throw CoreException(sid + " is not a valid server ID. A server ID must be 3 characters long, with the first character a digit and the next two characters a digit or letter.");
        }
 
        conf->sid = sid;
@@ -801,7 +793,6 @@ static const InitialConfig Values[] = {
        {"security",    "announceinvites", "1",                 NULL, DT_NOTHING,  ValidateInvite},
        {"options",     "hostintopic",  "1",                    new ValueContainerBool (&ServerConfig::FullHostInTopic),        DT_BOOLEAN,  NULL},
        {"security",    "hidemodes",    "",                     NULL, DT_NOTHING,  ValidateModeLists},
-       {"options",     "exemptchanops","",                     NULL, DT_NOTHING,  ValidateExemptChanOps},
        {"security",    "maxtargets",   "20",                   new ValueContainerUInt (&ServerConfig::MaxTargets),             DT_INTEGER,  ValidateMaxTargets},
        {"options",     "defaultmodes", "nt",                   new ValueContainerString (&ServerConfig::DefaultModes),         DT_CHARPTR,  NULL},
        {"pid",         "file",         "",                     new ValueContainerString (&ServerConfig::PID),                  DT_CHARPTR,  NULL},
@@ -1230,19 +1221,19 @@ void ServerConfig::ApplyModules(User* user)
                        continue;
                if (ServerInstance->Modules->Unload(removing->c_str()))
                {
-                       ServerInstance->SNO->WriteToSnoMask('a', "*** REHASH UNLOADED MODULE: %s",removing->c_str());
+                       ServerInstance->SNO->WriteGlobalSno('a', "*** REHASH UNLOADED MODULE: %s",removing->c_str());
 
                        if (user)
                                user->WriteNumeric(RPL_UNLOADEDMODULE, "%s %s :Module %s successfully unloaded.",user->nick.c_str(), removing->c_str(), removing->c_str());
                        else
-                               ServerInstance->SNO->WriteToSnoMask('a', "Module %s successfully unloaded.", removing->c_str());
+                               ServerInstance->SNO->WriteGlobalSno('a', "Module %s successfully unloaded.", removing->c_str());
                }
                else
                {
                        if (user)
                                user->WriteNumeric(ERR_CANTUNLOADMODULE, "%s %s :Failed to unload module %s: %s",user->nick.c_str(), removing->c_str(), removing->c_str(), ServerInstance->Modules->LastError().c_str());
                        else
-                                ServerInstance->SNO->WriteToSnoMask('a', "Failed to unload module %s: %s", removing->c_str(), ServerInstance->Modules->LastError().c_str());
+                                ServerInstance->SNO->WriteGlobalSno('a', "Failed to unload module %s: %s", removing->c_str(), ServerInstance->Modules->LastError().c_str());
                }
        }
 
@@ -1250,25 +1241,25 @@ void ServerConfig::ApplyModules(User* user)
        {
                if (ServerInstance->Modules->Load(adding->c_str()))
                {
-                       ServerInstance->SNO->WriteToSnoMask('a', "*** REHASH LOADED MODULE: %s",adding->c_str());
+                       ServerInstance->SNO->WriteGlobalSno('a', "*** REHASH LOADED MODULE: %s",adding->c_str());
                        if (user)
                                user->WriteNumeric(RPL_LOADEDMODULE, "%s %s :Module %s successfully loaded.",user->nick.c_str(), adding->c_str(), adding->c_str());
                        else
-                               ServerInstance->SNO->WriteToSnoMask('a', "Module %s successfully loaded.", adding->c_str());
+                               ServerInstance->SNO->WriteGlobalSno('a', "Module %s successfully loaded.", adding->c_str());
                }
                else
                {
                        if (user)
                                user->WriteNumeric(ERR_CANTLOADMODULE, "%s %s :Failed to load module %s: %s",user->nick.c_str(), adding->c_str(), adding->c_str(), ServerInstance->Modules->LastError().c_str());
                        else
-                               ServerInstance->SNO->WriteToSnoMask('a', "Failed to load module %s: %s", adding->c_str(), ServerInstance->Modules->LastError().c_str());
+                               ServerInstance->SNO->WriteGlobalSno('a', "Failed to load module %s: %s", adding->c_str(), ServerInstance->Modules->LastError().c_str());
                }
        }
 
        if (user)
                user->WriteServ("NOTICE %s :*** Successfully rehashed server.", user->nick.c_str());
        else
-               ServerInstance->SNO->WriteToSnoMask('a', "*** Successfully rehashed server.");
+               ServerInstance->SNO->WriteGlobalSno('a', "*** Successfully rehashed server.");
 }
 
 bool ServerConfig::LoadConf(FILE* &conf, const char* filename, bool allowexeinc)
@@ -1670,36 +1661,12 @@ bool ServerConfig::StartsWithWindowsDriveLetter(const std::string &path)
 
 bool ServerConfig::DoInclude(const std::string &file, bool allowexeinc)
 {
-       std::string confpath;
-       std::string newfile;
-       std::string::size_type pos;
-
-       confpath = ServerInstance->ConfigFileName;
-       newfile = file;
-
-       std::replace(newfile.begin(),newfile.end(),'\\','/');
-       std::replace(confpath.begin(),confpath.end(),'\\','/');
-
-       if ((newfile[0] != '/') && (!StartsWithWindowsDriveLetter(newfile)))
-       {
-               if((pos = confpath.rfind("/")) != std::string::npos)
-               {
-                       /* Leaves us with just the path */
-                       newfile = confpath.substr(0, pos) + std::string("/") + newfile;
-               }
-               else
-               {
-                       errstr << "Couldn't get config path from: " << ServerInstance->ConfigFileName << std::endl;
-                       return false;
-               }
-       }
-
-       FILE* conf = fopen(newfile.c_str(), "r");
+       FILE* conf = fopen(file.c_str(), "r");
        bool ret = false;
 
        if (conf)
        {
-               ret = LoadConf(conf, newfile, allowexeinc);
+               ret = LoadConf(conf, file, allowexeinc);
                fclose(conf);
        }
        else
@@ -1902,29 +1869,9 @@ bool ServerConfig::ReadFile(file_cache &F, const char* fname)
 
        F.clear();
 
-       if ((*fname != '/') && (*fname != '\\') && (!StartsWithWindowsDriveLetter(fname)))
-       {
-               std::string::size_type pos;
-               std::string confpath = ServerInstance->ConfigFileName;
-               std::string newfile = fname;
-
-               if (((pos = confpath.rfind("/"))) != std::string::npos)
-                       newfile = confpath.substr(0, pos) + std::string("/") + fname;
-               else if (((pos = confpath.rfind("\\"))) != std::string::npos)
-                       newfile = confpath.substr(0, pos) + std::string("\\") + fname;
-
-               ServerInstance->Logs->Log("config", DEBUG, "Filename: %s", newfile.c_str());
-
-               if (!FileExists(newfile.c_str()))
-                       return false;
-               file =  fopen(newfile.c_str(), "r");
-       }
-       else
-       {
-               if (!FileExists(fname))
-                       return false;
-               file =  fopen(fname, "r");
-       }
+       if (!FileExists(fname))
+               return false;
+       file = fopen(fname, "r");
 
        if (file)
        {
@@ -1955,8 +1902,8 @@ bool ServerConfig::FileExists(const char* file)
        if ((sb.st_mode & S_IFDIR) > 0)
                return false;
 
-       FILE *input;
-       if ((input = fopen (file, "r")) == NULL)
+       FILE *input = fopen(file, "r");
+       if (input == NULL)
                return false;
        else
        {
@@ -1973,41 +1920,6 @@ const char* ServerConfig::CleanFilename(const char* name)
 }
 
 
-std::string ServerConfig::GetFullProgDir()
-{
-       char buffer[PATH_MAX];
-#ifdef WINDOWS
-       /* Windows has specific api calls to get the exe path that never fail.
-        * For once, windows has something of use, compared to the POSIX code
-        * for this, this is positively neato.
-        */
-       if (GetModuleFileName(NULL, buffer, MAX_PATH))
-       {
-               std::string fullpath = buffer;
-               std::string::size_type n = fullpath.rfind("\\inspircd.exe");
-               return std::string(fullpath, 0, n);
-       }
-#else
-       // Get the current working directory
-       if (getcwd(buffer, PATH_MAX))
-       {
-               std::string remainder = this->argv[0];
-
-               /* Does argv[0] start with /? its a full path, use it */
-               if (remainder[0] == '/')
-               {
-                       std::string::size_type n = remainder.rfind("/inspircd");
-                       return std::string(remainder, 0, n);
-               }
-
-               std::string fullpath = std::string(buffer) + "/" + remainder;
-               std::string::size_type n = fullpath.rfind("/inspircd");
-               return std::string(fullpath, 0, n);
-       }
-#endif
-       return "/";
-}
-
 std::string ServerConfig::GetSID()
 {
        return sid;
@@ -2102,9 +2014,3 @@ void ConfigReaderThread::Finish()
                delete this->Config;
        }
 }
-
-template<>
-void ValueContainer<char[MAXBUF]>::Set(ServerConfig* conf, ValueItem const& item)
-{
-       strlcpy(conf->*vptr, item.GetString(), MAXBUF);
-}