]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/configreader.cpp
Move all of the xline stuff into class XLineManager, make an instance of it in class...
[user/henk/code/inspircd.git] / src / configreader.cpp
index 726192cc629bcca9bd8979cf02e4c67a44e4c144..b57de169214fb9d2ad672b30ed6bc5925cba07f7 100644 (file)
@@ -3,13 +3,13 @@
  *       +------------------------------------+
  *
  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
- *                       E-mail:
- *                <brain@chatspike.net>
- *                <Craig@chatspike.net>
+ *                    E-mail:
+ *             <brain@chatspike.net>
+ *             <Craig@chatspike.net>
  *     
  * Written by Craig Edwards, Craig McLure, and others.
  * This program is free but copyrighted software; see
- *            the file COPYING for details.
+ *         the file COPYING for details.
  *
  * ---------------------------------------------------
  */
 #include "userprocess.h"
 #include "xline.h"
 
-extern time_t TIME;
-
-extern int MODCOUNT;
-extern std::vector<Module*> modules;
-extern std::vector<ircd_module*> factory;
-
-using irc::sockets::BindPorts;
-
 std::vector<std::string> old_module_names, new_module_names, added_modules, removed_modules;
 
 ServerConfig::ServerConfig(InspIRCd* Instance) : ServerInstance(Instance)
@@ -103,7 +95,7 @@ bool ServerConfig::CheckOnce(char* tag, bool bail, userrec* user)
                if (bail)
                {
                        printf("There were errors in your configuration:\nYou have more than one <%s> tag, this is not permitted.\n",tag);
-                       Exit(0);
+                       InspIRCd::Exit(ERROR);
                }
                else
                {
@@ -125,7 +117,7 @@ bool ServerConfig::CheckOnce(char* tag, bool bail, userrec* user)
                if (bail)
                {
                        printf("There were errors in your configuration:\nYou have not defined a <%s> tag, this is required.\n",tag);
-                       Exit(0);
+                       InspIRCd::Exit(ERROR);
                }
                else
                {
@@ -668,7 +660,7 @@ void ServerConfig::Read(bool bail, userrec* user)
                {
                        /* Unneeded because of the log() aboive? */
                        printf("There were errors in your configuration:\n%s",errstr.str().c_str());
-                       Exit(0);
+                       InspIRCd::Exit(ERROR);
                }
                else
                {
@@ -800,7 +792,7 @@ void ServerConfig::Read(bool bail, userrec* user)
         */
        if (!bail)
        {
-               ServerInstance->stats->BoundPortCount = BindPorts(false);
+               ServerInstance->stats->BoundPortCount = ServerInstance->BindPorts(false);
 
                if (!removed_modules.empty())
                        for (std::vector<std::string>::iterator removing = removed_modules.begin(); removing != removed_modules.end(); removing++)
@@ -1291,35 +1283,149 @@ int ServerConfig::ConfVarEnum(ConfigDataHash &target, const std::string &tag, in
  */
 bool ServerConfig::ReadFile(file_cache &F, const char* fname)
 {
-        FILE* file;
-        char linebuf[MAXBUF];
-
-        F.clear();
-        file =  fopen(fname,"r");
-
-        if (file)
-        {
-                while (!feof(file))
-                {
-                        fgets(linebuf,sizeof(linebuf),file);
-                        linebuf[strlen(linebuf)-1]='\0';
-
-                        if (!*linebuf)
-                        {
-                                strcpy(linebuf," ");
-                        }
-
-                        if (!feof(file))
-                        {
-                                F.push_back(linebuf);
-                        }
-                }
-
-                fclose(file);
-        }
-        else
+       FILE* file;
+       char linebuf[MAXBUF];
+
+       F.clear();
+       file =  fopen(fname,"r");
+
+       if (file)
+       {
+               while (!feof(file))
+               {
+                       fgets(linebuf,sizeof(linebuf),file);
+                       linebuf[strlen(linebuf)-1]='\0';
+
+                       if (!*linebuf)
+                       {
+                               strcpy(linebuf," ");
+                       }
+
+                       if (!feof(file))
+                       {
+                               F.push_back(linebuf);
+                       }
+               }
+
+               fclose(file);
+       }
+       else
                return false;
 
        return true;
 }
 
+bool ServerConfig::FileExists(const char* file)
+{
+       FILE *input;
+       if ((input = fopen (file, "r")) == NULL)
+       {
+               return false;
+       }
+       else
+       {
+               fclose(input);
+               return true;
+       }
+}
+
+char* ServerConfig::CleanFilename(char* name)
+{
+       char* p = name + strlen(name);
+       while ((p != name) && (*p != '/')) p--;
+       return (p != name ? ++p : p);
+}
+
+
+bool ServerConfig::DirValid(const char* dirandfile)
+{
+       char work[MAXBUF];
+       char buffer[MAXBUF];
+       char otherdir[MAXBUF];
+       int p;
+
+       strlcpy(work, dirandfile, MAXBUF);
+       p = strlen(work);
+
+       // we just want the dir
+       while (*work)
+       {
+               if (work[p] == '/')
+               {
+                       work[p] = '\0';
+                       break;
+               }
+
+               work[p--] = '\0';
+       }
+
+       // Get the current working directory
+       if (getcwd(buffer, MAXBUF ) == NULL )
+               return false;
+
+       chdir(work);
+
+       if (getcwd(otherdir, MAXBUF ) == NULL )
+               return false;
+
+       chdir(buffer);
+
+       size_t t = strlen(work);
+
+       if (strlen(otherdir) >= t)
+       {
+               otherdir[t] = '\0';
+
+               if (!strcmp(otherdir,work))
+               {
+                       return true;
+               }
+
+               return false;
+       }
+       else
+       {
+               return false;
+       }
+}
+
+std::string ServerConfig::GetFullProgDir(char** argv, int argc)
+{
+       char work[MAXBUF];
+       char buffer[MAXBUF];
+       char otherdir[MAXBUF];
+       int p;
+
+       strlcpy(work,argv[0],MAXBUF);
+       p = strlen(work);
+
+       // we just want the dir
+       while (*work)
+       {
+               if (work[p] == '/')
+               {
+                       work[p] = '\0';
+                       break;
+               }
+
+               work[p--] = '\0';
+       }
+
+       // Get the current working directory
+       if (getcwd(buffer, MAXBUF) == NULL)
+               return "";
+
+       chdir(work);
+
+       if (getcwd(otherdir, MAXBUF) == NULL)
+               return "";
+
+       chdir(buffer);
+       return otherdir;
+}
+
+InspIRCd* ServerConfig::GetInstance()
+{
+       return ServerInstance;
+}
+