summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-08-10 18:28:37 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-08-10 18:28:37 +0000
commit6c9588419d3cfe01d04d3c870eaac712bb6745b8 (patch)
tree3fb86402535392367b1e2b42cb744de7255e610c /src
parentfd2eb26472bcc0b7b144f40523ff820cba82f574 (diff)
Move FileExists, CleanFilename, DirValid, GetFullProgDir into class ServerConfig
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4848 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/cmd_modules.cpp8
-rw-r--r--src/cmd_rehash.cpp5
-rw-r--r--src/configreader.cpp172
-rw-r--r--src/helperfuncs.cpp117
-rw-r--r--src/inspircd.cpp8
5 files changed, 152 insertions, 158 deletions
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++)