diff options
-rw-r--r-- | include/configreader.h | 6 | ||||
-rw-r--r-- | include/globals.h | 3 | ||||
-rw-r--r-- | include/helperfuncs.h | 4 | ||||
-rw-r--r-- | src/cmd_modules.cpp | 8 | ||||
-rw-r--r-- | src/cmd_rehash.cpp | 5 | ||||
-rw-r--r-- | src/configreader.cpp | 172 | ||||
-rw-r--r-- | src/helperfuncs.cpp | 117 | ||||
-rw-r--r-- | src/inspircd.cpp | 8 |
8 files changed, 158 insertions, 165 deletions
diff --git a/include/configreader.h b/include/configreader.h index 5bf26e695..b95cdede5 100644 --- a/include/configreader.h +++ b/include/configreader.h @@ -405,6 +405,12 @@ class ServerConfig : public Extensible Module* GetIOHook(int port); bool AddIOHook(int port, Module* iomod); bool DelIOHook(int port); + + static std::string GetFullProgDir(char** argv, int argc); + static bool DirValid(const char* dirandfile); + static char* CleanFilename(char* name); + static bool FileExists(const char* file); + }; bool InitializeDisabledCommands(const char* data, InspIRCd* ServerInstance); diff --git a/include/globals.h b/include/globals.h index 4a5c1e1e4..253ca923b 100644 --- a/include/globals.h +++ b/include/globals.h @@ -19,12 +19,9 @@ // include the common header files -#include <typeinfo> -#include <iostream> #include <string> #include <deque> #include "users.h" -#include "channels.h" typedef std::deque<std::string> file_cache; typedef std::pair< std::string, std::string > KeyVal; diff --git a/include/helperfuncs.h b/include/helperfuncs.h index 9c3207a9e..ff43c4abe 100644 --- a/include/helperfuncs.h +++ b/include/helperfuncs.h @@ -53,10 +53,6 @@ void Error(int status); void ShowMOTD(userrec *user); void ShowRULES(userrec *user); bool AllModulesReportReady(userrec* user); -bool DirValid(char* dirandfile); -bool FileExists(const char* file); -char* CleanFilename(char* name); -std::string GetFullProgDir(char** argv, int argc); int InsertMode(std::string &output, const char* modes, unsigned short section); bool IsValidChannelName(const char *); diff --git a/src/cmd_modules.cpp b/src/cmd_modules.cpp index 7948c0fb9..650f2c587 100644 --- a/src/cmd_modules.cpp +++ b/src/cmd_modules.cpp @@ -76,7 +76,7 @@ void cmd_modules::Handle (const char** parameters, int pcnt, userrec *user) { if (match(ServerInstance->Config->module_names[i].c_str(),parameters[1])) { - user->WriteServ("900 %s :0x%08lx %d.%d.%d.%d %s (%s)",user->nick,modules[i],V.Major,V.Minor,V.Revision,V.Build,CleanFilename(modulename),flagstate+2); + user->WriteServ("900 %s :0x%08lx %d.%d.%d.%d %s (%s)",user->nick,modules[i],V.Major,V.Minor,V.Revision,V.Build,ServerConfig::CleanFilename(modulename),flagstate+2); for (int it = 0; itab[it];) { char data[MAXBUF]; @@ -95,7 +95,7 @@ void cmd_modules::Handle (const char** parameters, int pcnt, userrec *user) } } if (*dlist) - user->WriteServ("900 %s :%s [ %s]",user->nick,CleanFilename(modulename),dlist); + user->WriteServ("900 %s :%s [ %s]",user->nick,ServerConfig::CleanFilename(modulename),dlist); } user->WriteServ("900 %s :=== DEBUG: Implementation counts ===",user->nick); for (int it = 0; itab[it]; it++) @@ -107,12 +107,12 @@ void cmd_modules::Handle (const char** parameters, int pcnt, userrec *user) } else { - user->WriteServ("900 %s :0x%08lx %d.%d.%d.%d %s (%s)",user->nick,modules[i],V.Major,V.Minor,V.Revision,V.Build,CleanFilename(modulename),flagstate+2); + user->WriteServ("900 %s :0x%08lx %d.%d.%d.%d %s (%s)",user->nick,modules[i],V.Major,V.Minor,V.Revision,V.Build,ServerConfig::CleanFilename(modulename),flagstate+2); } } else { - user->WriteServ("900 %s :%s",user->nick,CleanFilename(modulename)); + user->WriteServ("900 %s :%s",user->nick,ServerConfig::CleanFilename(modulename)); } } user->WriteServ("901 %s :End of MODULES list",user->nick); diff --git a/src/cmd_rehash.cpp b/src/cmd_rehash.cpp index eeb8958f9..3f6657943 100644 --- a/src/cmd_rehash.cpp +++ b/src/cmd_rehash.cpp @@ -19,7 +19,6 @@ #include "users.h" #include "modules.h" #include "commands.h" -#include "helperfuncs.h" #include "commands/cmd_rehash.h" extern InspIRCd* ServerInstance; @@ -29,7 +28,7 @@ extern FactoryList factory; void cmd_rehash::Handle (const char** parameters, int pcnt, userrec *user) { - user->WriteServ("382 %s %s :Rehashing",user->nick,CleanFilename(CONFIG_FILE)); + user->WriteServ("382 %s %s :Rehashing",user->nick,ServerConfig::CleanFilename(CONFIG_FILE)); std::string parameter = ""; if (pcnt) { @@ -37,7 +36,7 @@ void cmd_rehash::Handle (const char** parameters, int pcnt, userrec *user) } else { - ServerInstance->WriteOpers("%s is rehashing config file %s",user->nick,CleanFilename(CONFIG_FILE)); + ServerInstance->WriteOpers("%s is rehashing config file %s",user->nick,ServerConfig::CleanFilename(CONFIG_FILE)); ServerInstance->Config->Read(false,user); } FOREACH_MOD(I_OnRehash,OnRehash(parameter)); diff --git a/src/configreader.cpp b/src/configreader.cpp index 726192cc6..85745c63e 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -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. * * --------------------------------------------------- */ @@ -1291,35 +1291,145 @@ 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; +} + + diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index a1b1b8bc2..689b1c409 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -507,121 +507,6 @@ bool AllModulesReportReady(userrec* user) return true; } -/* Make Sure Modules Are Avaliable! - * (BugFix By Craig.. See? I do work! :p) - * Modified by brain, requires const char* - * to work with other API functions - */ - -/* XXX - Needed? */ -bool FileExists (const char* file) -{ - FILE *input; - if ((input = fopen (file, "r")) == NULL) - { - return(false); - } - else - { - fclose (input); - return(true); - } -} - -char* CleanFilename(char* name) -{ - char* p = name + strlen(name); - while ((p != name) && (*p != '/')) p--; - return (p != name ? ++p : p); -} - -bool DirValid(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 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; -} - int InsertMode(std::string &output, const char* mode, unsigned short section) { unsigned short currsection = 1; @@ -685,7 +570,7 @@ void OpenLog(char** argv, int argc) { if (ServerInstance->Config->logpath == "") { - ServerInstance->Config->logpath = GetFullProgDir(argv,argc) + "/ircd.log"; + ServerInstance->Config->logpath = ServerConfig::GetFullProgDir(argv,argc) + "/ircd.log"; } } else diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 14f88e0a3..6dad70a51 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -141,7 +141,7 @@ void Killed(int status) void Rehash(int status) { - ServerInstance->WriteOpers("Rehashing config file %s due to SIGHUP",CleanFilename(CONFIG_FILE)); + ServerInstance->WriteOpers("Rehashing config file %s due to SIGHUP",ServerConfig::CleanFilename(CONFIG_FILE)); fclose(ServerInstance->Config->log_file); OpenLog(NULL,0); ServerInstance->Config->Read(false,NULL); @@ -234,7 +234,7 @@ InspIRCd::InspIRCd(int argc, char** argv) this->startup_time = time(NULL); srand(time(NULL)); log(DEBUG,"*** InspIRCd starting up!"); - if (!FileExists(CONFIG_FILE)) + if (!ServerConfig::FileExists(CONFIG_FILE)) { printf("ERROR: Cannot open config file: %s\nExiting...\n",CONFIG_FILE); log(DEFAULT,"main: no config"); @@ -559,7 +559,7 @@ bool InspIRCd::LoadModule(const char* filename) std::string filename_str = filename; #ifndef STATIC_LINK #ifndef IS_CYGWIN - if (!DirValid(modfile)) + if (!ServerConfig::DirValid(modfile)) { log(DEFAULT,"Module %s is not within the modules directory.",modfile); snprintf(MODERR,MAXBUF,"Module %s is not within the modules directory.",modfile); @@ -569,7 +569,7 @@ bool InspIRCd::LoadModule(const char* filename) #endif log(DEBUG,"Loading module: %s",modfile); #ifndef STATIC_LINK - if (FileExists(modfile)) + if (ServerConfig::FileExists(modfile)) { #endif for (unsigned int j = 0; j < Config->module_names.size(); j++) |