diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2004-04-07 13:22:17 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2004-04-07 13:22:17 +0000 |
commit | 6ec52cab73c5e77337ddd364617d8c4ad4065d80 (patch) | |
tree | 91ada68c6f7780a202133a4402b7e013af33e679 /src | |
parent | 3717c045aabf40d8280d1f8a7a0f33383ecafae4 (diff) |
Fixed config reader to cache its files instead of re-reading them for each access
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@413 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r-- | src/InspIRCd.dev | 12 | ||||
-rw-r--r-- | src/InspIRCd.layout | 43 | ||||
-rw-r--r-- | src/inspircd.cpp | 118 | ||||
-rw-r--r-- | src/inspircd_io.cpp | 297 | ||||
-rw-r--r-- | src/modules.cpp | 13 |
5 files changed, 263 insertions, 220 deletions
diff --git a/src/InspIRCd.dev b/src/InspIRCd.dev index 2848d0ba7..fa1a770ac 100644 --- a/src/InspIRCd.dev +++ b/src/InspIRCd.dev @@ -1,7 +1,7 @@ [Project] FileName=InspIRCd.dev Name=InspIRCd -UnitCount=34 +UnitCount=35 Type=1 Ver=1 ObjFiles= @@ -383,3 +383,13 @@ Priority=1000 OverrideBuildCmd=0 BuildCmd= +[Unit35] +FileName=modules\m_filter.cpp +CompileCpp=1 +Folder=Modules +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + diff --git a/src/InspIRCd.layout b/src/InspIRCd.layout index b6c14fd5f..229be3357 100644 --- a/src/InspIRCd.layout +++ b/src/InspIRCd.layout @@ -1,5 +1,5 @@ [Editors] -Focused=1 +Focused=2 Order=7,3,2,6,25,24,4,5,0,-1,1 [Editor_0] @@ -12,18 +12,18 @@ LeftChar=1 [Editor_1] Open=1 -Top=1 -CursorCol=7 -CursorRow=5232 -TopLine=5208 +Top=0 +CursorCol=2 +CursorRow=4535 +TopLine=4481 LeftChar=1 [Editor_2] Open=1 -Top=0 -CursorCol=1 -CursorRow=43 -TopLine=7 +Top=1 +CursorCol=28 +CursorRow=246 +TopLine=219 LeftChar=1 [Editor_3] @@ -37,9 +37,9 @@ LeftChar=1 [Editor_4] Open=1 Top=0 -CursorCol=77 -CursorRow=124 -TopLine=90 +CursorCol=29 +CursorRow=299 +TopLine=280 LeftChar=1 [Editor_5] @@ -70,7 +70,7 @@ LeftChar=1 Open=1 Top=0 CursorCol=1 -CursorRow=1 +CursorRow=33 TopLine=1 LeftChar=1 @@ -149,8 +149,8 @@ LeftChar=1 [Editor_18] Open=1 Top=0 -CursorCol=1 -CursorRow=1 +CursorCol=81 +CursorRow=27 TopLine=1 LeftChar=1 @@ -165,9 +165,9 @@ LeftChar=1 [Editor_20] Open=1 Top=0 -CursorCol=2 -CursorRow=494 -TopLine=506 +CursorCol=26 +CursorRow=482 +TopLine=436 LeftChar=1 [Editor_21] @@ -256,3 +256,10 @@ Top=0 [Editor_33] Open=0 Top=0 +[Editor_34] +Open=1 +Top=0 +CursorCol=2 +CursorRow=45 +TopLine=1 +LeftChar=1 diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 786cbe4f2..3b11f8d16 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -16,6 +16,8 @@ /* Now with added unF! ;) */ +using namespace std; + #include "inspircd.h" #include "inspircd_io.h" #include "inspircd_util.h" @@ -47,8 +49,6 @@ #include "dynamic.h" #include "wildcard.h" -using namespace std; - #ifdef GCC3 #define nspace __gnu_cxx #else @@ -180,6 +180,7 @@ char* Passwd(userrec *user); bool IsDenied(userrec *user); void AddWhoWas(userrec* u); +std::stringstream config_f(stringstream::in | stringstream::out); void safedelete(userrec *p) { @@ -375,20 +376,22 @@ void ReadConfig(void) char dbg[MAXBUF],pauseval[MAXBUF],Value[MAXBUF],timeout[MAXBUF]; ConnectClass c; - ConfValue("server","name",0,ServerName); - ConfValue("server","description",0,ServerDesc); - ConfValue("server","network",0,Network); - ConfValue("admin","name",0,AdminName); - ConfValue("admin","email",0,AdminEmail); - ConfValue("admin","nick",0,AdminNick); - ConfValue("files","motd",0,motd); - ConfValue("files","rules",0,rules); - ConfValue("power","diepass",0,diepass); - ConfValue("power","pause",0,pauseval); - ConfValue("power","restartpass",0,restartpass); - ConfValue("options","prefixquit",0,PrefixQuit); - ConfValue("die","value",0,DieValue); - ConfValue("options","loglevel",0,dbg); + LoadConf(CONFIG_FILE,&config_f); + + ConfValue("server","name",0,ServerName,&config_f); + ConfValue("server","description",0,ServerDesc,&config_f); + ConfValue("server","network",0,Network,&config_f); + ConfValue("admin","name",0,AdminName,&config_f); + ConfValue("admin","email",0,AdminEmail,&config_f); + ConfValue("admin","nick",0,AdminNick,&config_f); + ConfValue("files","motd",0,motd,&config_f); + ConfValue("files","rules",0,rules,&config_f); + ConfValue("power","diepass",0,diepass,&config_f); + ConfValue("power","pause",0,pauseval,&config_f); + ConfValue("power","restartpass",0,restartpass,&config_f); + ConfValue("options","prefixquit",0,PrefixQuit,&config_f); + ConfValue("die","value",0,DieValue,&config_f); + ConfValue("options","loglevel",0,dbg,&config_f); if (!strcmp(dbg,"debug")) LogLevel = DEBUG; if (!strcmp(dbg,"verbose")) @@ -404,17 +407,17 @@ void ReadConfig(void) readfile(RULES,rules); log(DEBUG,"Reading connect classes"); Classes.clear(); - for (int i = 0; i < ConfValueEnum("connect"); i++) + for (int i = 0; i < ConfValueEnum("connect",&config_f); i++) { strcpy(Value,""); - ConfValue("connect","allow",i,Value); - ConfValue("connect","timeout",i,timeout); + ConfValue("connect","allow",i,Value,&config_f); + ConfValue("connect","timeout",i,timeout,&config_f); if (strcmp(Value,"")) { strcpy(c.host,Value); c.type = CC_ALLOW; strcpy(Value,""); - ConfValue("connect","password",i,Value); + ConfValue("connect","password",i,Value,&config_f); strcpy(c.pass,Value); c.registration_timeout = 90; // default is 2 minutes if (atoi(timeout)>0) @@ -426,7 +429,7 @@ void ReadConfig(void) } else { - ConfValue("connect","deny",i,Value); + ConfValue("connect","deny",i,Value,&config_f); strcpy(c.host,Value); c.type = CC_DENY; Classes.push_back(c); @@ -3955,7 +3958,6 @@ void handle_who(char **parameters, int pcnt, userrec *user) if ((!strcmp(parameters[0],"0")) || (!strcmp(parameters[0],"*")) && (!strcmp(parameters[1],"o"))) { Ptr = user->chans[0].channel; - printf(user->chans[0].channel->name); for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++) { if ((common_channels(user,i->second)) && (isnick(i->second->nick))) @@ -4345,14 +4347,14 @@ void handle_stats(char **parameters, int pcnt, userrec *user) /* stats o */ if (!strcasecmp(parameters[0],"o")) { - for (int i = 0; i < ConfValueEnum("oper"); i++) + for (int i = 0; i < ConfValueEnum("oper",&config_f); i++) { char LoginName[MAXBUF]; char HostName[MAXBUF]; char OperType[MAXBUF]; - ConfValue("oper","name",i,LoginName); - ConfValue("oper","host",i,HostName); - ConfValue("oper","type",i,OperType); + ConfValue("oper","name",i,LoginName,&config_f); + ConfValue("oper","host",i,HostName,&config_f); + ConfValue("oper","type",i,OperType,&config_f); WriteServ(user->fd,"243 %s O %s * %s %s 0",user->nick,HostName,LoginName,OperType); } } @@ -4409,12 +4411,12 @@ void handle_connect(char **parameters, int pcnt, userrec *user) int LinkPort; bool found = false; - for (int i = 0; i < ConfValueEnum("link"); i++) + for (int i = 0; i < ConfValueEnum("link",&config_f); i++) { - ConfValue("link","name",i,Link_ServerName); - ConfValue("link","ipaddr",i,Link_IPAddr); - ConfValue("link","port",i,Link_Port); - ConfValue("link","sendpass",i,Link_Pass); + ConfValue("link","name",i,Link_ServerName,&config_f); + ConfValue("link","ipaddr",i,Link_IPAddr,&config_f); + ConfValue("link","port",i,Link_Port,&config_f); + ConfValue("link","sendpass",i,Link_Pass,&config_f); log(DEBUG,"(%d) Comparing against name='%s', ipaddr='%s', port='%s', recvpass='%s'",i,Link_ServerName,Link_IPAddr,Link_Port,Link_Pass); LinkPort = atoi(Link_Port); if (match(Link_ServerName,parameters[0])) { @@ -4471,24 +4473,24 @@ void handle_oper(char **parameters, int pcnt, userrec *user) char Hostname[MAXBUF]; int i,j; - for (i = 0; i < ConfValueEnum("oper"); i++) + for (i = 0; i < ConfValueEnum("oper",&config_f); i++) { - ConfValue("oper","name",i,LoginName); - ConfValue("oper","password",i,Password); + ConfValue("oper","name",i,LoginName,&config_f); + ConfValue("oper","password",i,Password,&config_f); if ((!strcmp(LoginName,parameters[0])) && (!strcmp(Password,parameters[1]))) { /* correct oper credentials */ - ConfValue("oper","type",i,OperType); + ConfValue("oper","type",i,OperType,&config_f); WriteOpers("*** %s (%s@%s) is now an IRC operator of type %s",user->nick,user->ident,user->host,OperType); WriteServ(user->fd,"381 %s :You are now an IRC operator of type %s",user->nick,OperType); WriteServ(user->fd,"MODE %s :+o",user->nick); - for (j =0; j < ConfValueEnum("type"); j++) + for (j =0; j < ConfValueEnum("type",&config_f); j++) { - ConfValue("type","name",j,TypeName); + ConfValue("type","name",j,TypeName,&config_f); if (!strcmp(TypeName,OperType)) { /* found this oper's opertype */ - ConfValue("type","host",j,Hostname); + ConfValue("type","host",j,Hostname,&config_f); strncpy(user->dhost,Hostname,256); } } @@ -5012,13 +5014,13 @@ void handle_link_packet(long theirkey, char* udp_msg, char* udp_host, int udp_po int LinkPort = 0; // search for a corresponding <link> block in the config files - for (int i = 0; i < ConfValueEnum("link"); i++) + for (int i = 0; i < ConfValueEnum("link",&config_f); i++) { - ConfValue("link","name",i,Link_ServerName); - ConfValue("link","ipaddr",i,Link_IPAddr); - ConfValue("link","port",i,Link_Port); - ConfValue("link","recvpass",i,Link_Pass); - ConfValue("link","sendpass",i,Link_SendPass); + ConfValue("link","name",i,Link_ServerName,&config_f); + ConfValue("link","ipaddr",i,Link_IPAddr,&config_f); + ConfValue("link","port",i,Link_Port,&config_f); + ConfValue("link","recvpass",i,Link_Pass,&config_f); + ConfValue("link","sendpass",i,Link_SendPass,&config_f); log(DEBUG,"(%d) Comparing against name='%s', ipaddr='%s', port='%s', recvpass='%s'",i,Link_ServerName,Link_IPAddr,Link_Port,Link_Pass); LinkPort = atoi(Link_Port); if (!strcasecmp(Link_ServerName,servername)) { @@ -5102,13 +5104,13 @@ void handle_link_packet(long theirkey, char* udp_msg, char* udp_host, int udp_po int LinkPort = 0; // search for a corresponding <link> block in the config files - for (int i = 0; i < ConfValueEnum("link"); i++) + for (int i = 0; i < ConfValueEnum("link",&config_f); i++) { - ConfValue("link","name",i,Link_ServerName); - ConfValue("link","ipaddr",i,Link_IPAddr); - ConfValue("link","port",i,Link_Port); - ConfValue("link","recvpass",i,Link_Pass); - ConfValue("link","sendpass",i,Link_SendPass); + ConfValue("link","name",i,Link_ServerName,&config_f); + ConfValue("link","ipaddr",i,Link_IPAddr,&config_f); + ConfValue("link","port",i,Link_Port,&config_f); + ConfValue("link","recvpass",i,Link_Pass,&config_f); + ConfValue("link","sendpass",i,Link_SendPass,&config_f); log(DEBUG,"(%d) Comparing against name='%s', ipaddr='%s', port='%s', recvpass='%s'",i,Link_ServerName,Link_IPAddr,Link_Port,Link_Pass); LinkPort = atoi(Link_Port); if (!strcasecmp(Link_ServerName,servername)) { @@ -5226,16 +5228,16 @@ int InspIRCd(void) int count2 = 0, count3 = 0; - for (count = 0; count < ConfValueEnum("bind"); count++) + for (count = 0; count < ConfValueEnum("bind",&config_f); count++) { - ConfValue("bind","port",count,configToken); - ConfValue("bind","address",count,Addr); - ConfValue("bind","type",count,Type); + ConfValue("bind","port",count,configToken,&config_f); + ConfValue("bind","address",count,Addr,&config_f); + ConfValue("bind","type",count,Type,&config_f); if (!strcmp(Type,"servers")) { char Default[MAXBUF]; strcpy(Default,"no"); - ConfValue("bind","default",count,Default); + ConfValue("bind","default",count,Default,&config_f); if (strchr(Default,'y')) { defaultRoute = count3; @@ -5264,11 +5266,11 @@ int InspIRCd(void) /* BugFix By Craig! :p */ count2 = 0; - for (count = 0; count2 < ConfValueEnum("module"); count2++) + for (count = 0; count2 < ConfValueEnum("module",&config_f); count2++) { char modfile[MAXBUF]; - ConfValue("module","name",count,configToken); - sprintf(modfile,"%s/%s",MOD_PATH,configToken); + ConfValue("module","name",count,configToken,&config_f); + sprintf(modfile,"%s/%s",MOD_PATH,configToken,&config_f); printf("Loading module... \033[1;37m%s\033[0;37m\n",modfile); log(DEBUG,"InspIRCd: startup: Loading module: %s",modfile); /* If The File Doesnt exist, Trying to load it diff --git a/src/inspircd_io.cpp b/src/inspircd_io.cpp index 11471538d..65597704f 100644 --- a/src/inspircd_io.cpp +++ b/src/inspircd_io.cpp @@ -19,11 +19,17 @@ #endif #include <sys/types.h> +#include <string> #include <unistd.h> +#include <sstream> +#include <iostream> +#include <fstream> #include "inspircd.h" #include "inspircd_io.h" #include "inspircd_util.h" +using namespace std; + extern FILE *log_file; void WriteOpers(char* text, ...); @@ -109,87 +115,107 @@ int FileExists (char* file) } +void LoadConf(const char* filename, std::stringstream *target) +{ + FILE* conf = fopen(filename,"r"); + char buffer[MAXBUF]; + if (conf) + { + target->clear(); + while (!feof(conf)) + { + if (fgets(buffer, MAXBUF, conf)) + { + if ((!feof(conf)) && (buffer) && (strlen(buffer))) + { + if (buffer[0] != '#') + { + *target << std::string(buffer); + } + } + } + } + fclose(conf); + } + target->seekg(0); +} + /* Counts the number of tags of a certain type within the config file, e.g. to enumerate opers */ -int EnumConf(const char* filename, const char* tag) +int EnumConf(std::stringstream *config, const char* tag) { - FILE *config; int ptr = 0; char buffer[MAXBUF], c_tag[MAXBUF], c, lastc; int in_token, in_quotes, tptr, j, idx = 0; char* key; - if ((config = fopen (filename, "r")) == NULL) + const char* buf = config->str().c_str(); + long bptr = 0; + long len = strlen(buf); + + ptr = 0; + in_token = 0; + in_quotes = 0; + lastc = '\0'; + while (bptr<len) { - return 0; - } - else - { - ptr = 0; - in_token = 0; - in_quotes = 0; - lastc = '\0'; - while (!feof(config)) + lastc = c; + c = buf[bptr++]; + if ((c == '#') && (lastc == '\n')) { - lastc = c; - c = fgetc(config); - if ((c == '#') && (lastc == '\n')) + while ((c != '\n') && (bptr<len)) { - while ((c != '\n') && (!feof(config))) + lastc = c; + c = buf[bptr++]; + } + } + if ((c == '<') && (!in_quotes)) + { + tptr = 0; + in_token = 1; + do { + c = buf[bptr++]; + if (c != ' ') { - lastc = c; - c = fgetc(config); + c_tag[tptr++] = c; + c_tag[tptr] = '\0'; } - } - if ((c == '<') && (!in_quotes)) - { - tptr = 0; - in_token = 1; - do { - c = fgetc(config); - if (c != ' ') - { - c_tag[tptr++] = c; - c_tag[tptr] = '\0'; - } - } while (c != ' '); - } - if (c == '"') + } while (c != ' '); + } + if (c == '"') + { + in_quotes = (!in_quotes); + } + if ((c == '>') && (!in_quotes)) + { + in_token = 0; + if (!strcmp(c_tag,tag)) { - in_quotes = (!in_quotes); + /* correct tag, but wrong index */ + idx++; } - if ((c == '>') && (!in_quotes)) + c_tag[0] = '\0'; + buffer[0] = '\0'; + ptr = 0; + tptr = 0; + } + if (c != '>') + { + if ((in_token) && (c != '\n') && (c != '\r')) { - in_token = 0; - if (!strcmp(c_tag,tag)) - { - /* correct tag, but wrong index */ - idx++; - } - c_tag[0] = '\0'; - buffer[0] = '\0'; - ptr = 0; - tptr = 0; - } - if (c != '>') - { - if ((in_token) && (c != '\n') && (c != '\r')) - { - buffer[ptr++] = c; - buffer[ptr] = '\0'; - } + buffer[ptr++] = c; + buffer[ptr] = '\0'; } } } - fclose(config); return idx; } -int ConfValueEnum(char* tag) +int ConfValueEnum(char* tag, std::stringstream* config) { - EnumConf(CONFIG_FILE,tag); + EnumConf(config,tag); } @@ -200,125 +226,118 @@ int ConfValueEnum(char* tag) * ConfValue("oper","name",2,result); */ -int ReadConf(const char* filename, const char* tag, const char* var, int index, char *result) +int ReadConf(std::stringstream *config, const char* tag, const char* var, int index, char *result) { - FILE *config; int ptr = 0; char buffer[MAXBUF], c_tag[MAXBUF], c, lastc; int in_token, in_quotes, tptr, j, idx = 0; char* key; - if ((config = fopen (filename, "r")) == NULL) + const char* buf = config->str().c_str(); + long bptr = 0; + long len = strlen(buf); + + ptr = 0; + in_token = 0; + in_quotes = 0; + lastc = '\0'; + while (bptr<len) { - return 0; - } - else - { - ptr = 0; - in_token = 0; - in_quotes = 0; - lastc = '\0'; - while (!feof(config)) + lastc = c; + c = buf[bptr++]; + if ((c == '#') && (lastc == '\n')) { - lastc = c; - c = fgetc(config); - if ((c == '#') && (lastc == '\n')) + while ((c != '\n') && (bptr<len)) { - while ((c != '\n') && (!feof(config))) + lastc = c; + c = buf[bptr++]; + } + } + if ((c == '<') && (!in_quotes)) + { + tptr = 0; + in_token = 1; + do { + c = buf[bptr++]; + if (c != ' ') { - lastc = c; - c = fgetc(config); + c_tag[tptr++] = c; + c_tag[tptr] = '\0'; } - } - if ((c == '<') && (!in_quotes)) - { - tptr = 0; - in_token = 1; - do { - c = fgetc(config); - if (c != ' ') - { - c_tag[tptr++] = c; - c_tag[tptr] = '\0'; - } - } while (c != ' '); - } - if (c == '"') - { - in_quotes = (!in_quotes); - } - if ((c == '>') && (!in_quotes)) + } while (c != ' '); + } + if (c == '"') + { + in_quotes = (!in_quotes); + } + if ((c == '>') && (!in_quotes)) + { + in_token = 0; + if (idx == index) { - in_token = 0; - if (idx == index) + if (!strcmp(c_tag,tag)) { - if (!strcmp(c_tag,tag)) + if ((buffer) && (c_tag) && (var)) { - if ((buffer) && (c_tag) && (var)) + key = strstr(buffer,var); + if (!key) { - key = strstr(buffer,var); - if (!key) - { - /* value not found in tag */ - fclose(config); - return 0; - } - else + /* value not found in tag */ + return 0; + } + else + { + key+=strlen(var); + while (key[0] !='"') { - key+=strlen(var); - while (key[0] !='"') + if (!strlen(key)) { - if (!strlen(key)) - { - /* missing quote */ - return 0; - } - key++; + /* missing quote */ + return 0; } key++; - for (j = 0; j < strlen(key); j++) + } + key++; + for (j = 0; j < strlen(key); j++) + { + if (key[j] == '"') { - if (key[j] == '"') - { - key[j] = '\0'; - } + key[j] = '\0'; } - fclose(config); - strcpy(result,key); - return 1; } + strcpy(result,key); + return 1; } } } - if (!strcmp(c_tag,tag)) - { - /* correct tag, but wrong index */ - idx++; - } - c_tag[0] = '\0'; - buffer[0] = '\0'; - ptr = 0; - tptr = 0; } - if (c != '>') + if (!strcmp(c_tag,tag)) { - if ((in_token) && (c != '\n') && (c != '\r')) - { - buffer[ptr++] = c; - buffer[ptr] = '\0'; - } + /* correct tag, but wrong index */ + idx++; + } + c_tag[0] = '\0'; + buffer[0] = '\0'; + ptr = 0; + tptr = 0; + } + if (c != '>') + { + if ((in_token) && (c != '\n') && (c != '\r')) + { + buffer[ptr++] = c; + buffer[ptr] = '\0'; } } } - fclose(config); return 0; } -int ConfValue(char* tag, char* var, int index, char *result) +int ConfValue(char* tag, char* var, int index, char *result,std::stringstream *config) { - ReadConf(CONFIG_FILE, tag, var, index, result); + ReadConf(config, tag, var, index, result); } diff --git a/src/modules.cpp b/src/modules.cpp index c1a912eca..b2424639a 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -295,7 +295,8 @@ bool Server::AddExtendedMode(char modechar, int type, bool requires_oper, int pa ConfigReader::ConfigReader() { - fname = CONFIG_FILE; + this->cache = new std::stringstream(stringstream::in | stringstream::out); + LoadConf(CONFIG_FILE,this->cache); } @@ -304,19 +305,23 @@ ConfigReader::~ConfigReader() } -ConfigReader::ConfigReader(std::string filename) : fname(filename) { }; +ConfigReader::ConfigReader(std::string filename) +{ + this->cache = new std::stringstream(stringstream::in | stringstream::out); + LoadConf(filename.c_str(),this->cache); +}; std::string ConfigReader::ReadValue(std::string tag, std::string name, int index) { char val[MAXBUF]; - ReadConf(fname.c_str(),tag.c_str(),name.c_str(),index,val); + ReadConf(cache,tag.c_str(),name.c_str(),index,val); return val; } int ConfigReader::Enumerate(std::string tag) { - return EnumConf(fname.c_str(),tag.c_str()); + return EnumConf(cache,tag.c_str()); } |