diff options
-rw-r--r-- | include/configreader.h | 47 | ||||
-rw-r--r-- | include/users.h | 5 | ||||
-rw-r--r-- | include/xline.h | 8 | ||||
-rw-r--r-- | src/configreader.cpp | 105 | ||||
-rw-r--r-- | src/users.cpp | 12 | ||||
-rw-r--r-- | src/xline.cpp | 24 |
6 files changed, 117 insertions, 84 deletions
diff --git a/include/configreader.h b/include/configreader.h index 516c6a6ed..023121ffc 100644 --- a/include/configreader.h +++ b/include/configreader.h @@ -31,19 +31,52 @@ class ServerConfig; class InspIRCd; +/** Types of data in the core config + */ +enum ConfigDataType { DT_NOTHING, DT_INTEGER, DT_CHARPTR, DT_BOOLEAN }; + +class ValueItem +{ + std::string v; + public: + ValueItem(int value) + { + std::stringstream n; + n << value; + v = n.str(); + } + + ValueItem(bool value) + { + std::stringstream n; + n << value; + v = n.str(); + } + + ValueItem(char* value) + { + v = value; + } + + int GetInteger() { return atoi(v.c_str()); }; + + const char* GetString() { return v.c_str(); }; + + bool GetBool() { return GetInteger(); }; +}; + +typedef std::deque<ValueItem> ValueList; + /** A callback for validating a single value */ typedef bool (*Validator)(ServerConfig* conf, const char*, const char*, void*); /** A callback for validating multiple value entries */ -typedef bool (*MultiValidator)(ServerConfig* conf, const char*, char**, void**, int*); +typedef bool (*MultiValidator)(ServerConfig* conf, const char*, char**, ValueList&, int*); /** A callback indicating the end of a group of entries */ typedef bool (*MultiNotify)(ServerConfig* conf, const char*); -/** Types of data in the core config - */ -enum ConfigDataType { DT_NOTHING, DT_INTEGER, DT_CHARPTR, DT_BOOLEAN }; /** Holds a core configuration item and its callbacks */ @@ -498,4 +531,10 @@ class ServerConfig : public Extensible bool InitializeDisabledCommands(const char* data, InspIRCd* ServerInstance); +bool InitTypes(ServerConfig* conf, const char* tag); +bool InitClasses(ServerConfig* conf, const char* tag); +bool DoType(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types); +bool DoClass(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types); +bool DoneClassesAndTypes(ServerConfig* conf, const char* tag); + #endif diff --git a/include/users.h b/include/users.h index d94511660..d82b3d2cc 100644 --- a/include/users.h +++ b/include/users.h @@ -845,10 +845,5 @@ namespace irc /* Configuration callbacks */ class ServerConfig; -bool InitTypes(ServerConfig* conf, const char* tag); -bool InitClasses(ServerConfig* conf, const char* tag); -bool DoType(ServerConfig* conf, const char* tag, char** entries, void** values, int* types); -bool DoClass(ServerConfig* conf, const char* tag, char** entries, void** values, int* types); -bool DoneClassesAndTypes(ServerConfig* conf, const char* tag); #endif diff --git a/include/xline.h b/include/xline.h index daefe8a1e..3e8739a7e 100644 --- a/include/xline.h +++ b/include/xline.h @@ -191,10 +191,10 @@ class InspIRCd; bool InitXLine(ServerConfig* conf, const char* tag); bool DoneXLine(ServerConfig* conf, const char* tag); -bool DoZLine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types); -bool DoQLine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types); -bool DoKLine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types); -bool DoELine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types); +bool DoZLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types); +bool DoQLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types); +bool DoKLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types); +bool DoELine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types); typedef std::pair<std::string, std::string> IdentHostPair; diff --git a/src/configreader.cpp b/src/configreader.cpp index d71a504eb..15feacd37 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -324,7 +324,7 @@ bool ValidateRules(ServerConfig* conf, const char* tag, const char* value, void* bool ValidateWhoWas(ServerConfig* conf, const char* tag, const char* value, void* data) { - const char* max = (const char*)data; + char* max = (char*)data; conf->WhoWasMaxKeep = conf->GetInstance()->Duration(max); if (conf->WhoWasGroupSize < 0) @@ -354,34 +354,34 @@ bool InitConnect(ServerConfig* conf, const char* tag) /* Callback called to process a single <connect> tag */ -bool DoConnect(ServerConfig* conf, const char* tag, char** entries, void** values, int* types) +bool DoConnect(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types) { ConnectClass c; - char* allow = (char*)values[0]; /* Yeah, there are a lot of values. Live with it. */ - char* deny = (char*)values[1]; - char* password = (char*)values[2]; - int* timeout = (int*)values[3]; - int* pingfreq = (int*)values[4]; - int* flood = (int*)values[5]; - int* threshold = (int*)values[6]; - int* sendq = (int*)values[7]; - int* recvq = (int*)values[8]; - int* localmax = (int*)values[9]; - int* globalmax = (int*)values[10]; + const char* allow = values[0].GetString(); /* Yeah, there are a lot of values. Live with it. */ + const char* deny = values[1].GetString(); + const char* password = values[2].GetString(); + int timeout = values[3].GetInteger(); + int pingfreq = values[4].GetInteger(); + int flood = values[5].GetInteger(); + int threshold = values[6].GetInteger(); + int sendq = values[7].GetInteger(); + int recvq = values[8].GetInteger(); + int localmax = values[9].GetInteger(); + int globalmax = values[10].GetInteger(); if (*allow) { c.host = allow; c.type = CC_ALLOW; c.pass = password; - c.registration_timeout = *timeout; - c.pingtime = *pingfreq; - c.flood = *flood; - c.threshold = *threshold; - c.sendqmax = *sendq; - c.recvqmax = *recvq; - c.maxlocal = *localmax; - c.maxglobal = *globalmax; + c.registration_timeout = timeout; + c.pingtime = pingfreq; + c.flood = flood; + c.threshold = threshold; + c.sendqmax = sendq; + c.recvqmax = recvq; + c.maxlocal = localmax; + c.maxglobal = globalmax; if (c.maxlocal == 0) @@ -433,9 +433,9 @@ bool InitULine(ServerConfig* conf, const char* tag) /* Callback called to process a single <uline> tag */ -bool DoULine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types) +bool DoULine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types) { - char* server = (char*)values[0]; + const char* server = values[0].GetString(); conf->GetInstance()->Log(DEBUG,"Read ULINE '%s'",server); conf->ulines.push_back(server); return true; @@ -465,9 +465,9 @@ bool InitModule(ServerConfig* conf, const char* tag) /* Callback called to process a single <module> tag */ -bool DoModule(ServerConfig* conf, const char* tag, char** entries, void** values, int* types) +bool DoModule(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types) { - char* modname = (char*)values[0]; + const char* modname = values[0].GetString(); new_module_names.push_back(modname); return true; } @@ -517,11 +517,11 @@ bool InitMaxBans(ServerConfig* conf, const char* tag) /* Callback called to process a single <banlist> tag */ -bool DoMaxBans(ServerConfig* conf, const char* tag, char** entries, void** values, int* types) +bool DoMaxBans(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types) { - char* channel = (char*)values[0]; - int* limit = (int*)values[1]; - conf->maxbans[channel] = *limit; + const char* channel = values[0].GetString(); + int limit = values[1].GetInteger(); + conf->maxbans[channel] = limit; return true; } @@ -534,11 +534,8 @@ bool DoneMaxBans(ServerConfig* conf, const char* tag) void ServerConfig::Read(bool bail, userrec* user) { - static char debug[MAXBUF]; /* Temporary buffer for debugging value */ + static char debug[MAXBUF]; /* Temporary buffer for debugging value */ static char maxkeep[MAXBUF]; /* Temporary buffer for WhoWasMaxKeep value */ - char* data[12]; /* Temporary buffers for reading multiple occurance tags into */ - void* ptr[12]; /* Temporary pointers for passing to callbacks */ - int r_i[12]; /* Temporary array for casting */ int rem = 0, add = 0; /* Number of modules added, number of modules removed */ std::ostringstream errstr; /* String stream containing the error output */ @@ -724,12 +721,12 @@ void ServerConfig::Read(bool bail, userrec* user) case DT_INTEGER: ConfValueInteger(this->config_data, Values[Index].tag, Values[Index].value, 0, *((int*)Values[Index].val)); - ServerInstance->Log(DEBUG,"Data type DT_CHARPTR item <%s:%s> = '%d'", Values[Index].tag, Values[Index].value, *((int*)Values[Index].val)); + ServerInstance->Log(DEBUG,"Data type DT_INTEGER item <%s:%s> = '%d'", Values[Index].tag, Values[Index].value, *((int*)Values[Index].val)); break; case DT_BOOLEAN: *((bool*)(Values[Index].val)) = (ConfValueBool(this->config_data, Values[Index].tag, Values[Index].value, 0)); - ServerInstance->Log(DEBUG,"Data type DT_CHARPTR item <%s:%s> = '%d'", Values[Index].tag, Values[Index].value, *((bool*)(Values[Index].val))); + ServerInstance->Log(DEBUG,"Data type DT_BOOLEAN item <%s:%s> = '%d'", Values[Index].tag, Values[Index].value, *((bool*)(Values[Index].val))); break; case DT_NOTHING: @@ -739,11 +736,6 @@ void ServerConfig::Read(bool bail, userrec* user) Values[Index].validation_function(this, Values[Index].tag, Values[Index].value, Values[Index].val); } - /* Claim memory for use when reading multiple tags - */ - for (int n = 0; n < 12; n++) - data[n] = new char[MAXBUF]; - /* Read the multiple-tag items (class tags, connect tags, etc) * and call the callbacks associated with them. We have three * callbacks for these, a 'start', 'item' and 'end' callback. @@ -758,38 +750,45 @@ void ServerConfig::Read(bool bail, userrec* user) for (int tagnum = 0; tagnum < number_of_tags; tagnum++) { + ValueList vl; for (int valuenum = 0; MultiValues[Index].items[valuenum]; valuenum++) { - ConfValue(this->config_data, MultiValues[Index].tag, MultiValues[Index].items[valuenum], tagnum, data[valuenum], MAXBUF); - switch (MultiValues[Index].datatype[valuenum]) { case DT_CHARPTR: - ptr[valuenum] = data[valuenum]; + { + char item[MAXBUF]; + ConfValue(this->config_data, MultiValues[Index].tag, MultiValues[Index].items[valuenum], tagnum, item, MAXBUF); + ServerInstance->Log(DEBUG,"Data type DT_CHARPTR multi-item <%s:%s>[%d] = '%s'", MultiValues[Index].tag, MultiValues[Index].items[valuenum],tagnum, item); + vl.push_back(ValueItem(item)); + } break; case DT_INTEGER: - r_i[valuenum] = atoi(data[valuenum]); - ptr[valuenum] = &r_i[valuenum]; + { + int item; + ConfValueInteger(this->config_data, MultiValues[Index].tag, MultiValues[Index].items[valuenum], tagnum, item); + ServerInstance->Log(DEBUG,"Data type DT_INTEGER multi-item <%s:%s>[%d] = '%d'", MultiValues[Index].tag, MultiValues[Index].items[valuenum],tagnum, item); + vl.push_back(ValueItem(item)); + } break; case DT_BOOLEAN: - r_i[valuenum] = ((*data[valuenum] == tolower('y')) || (*data[valuenum] == tolower('t')) || (*data[valuenum] == '1')); - ptr[valuenum] = &r_i[valuenum]; + { + bool item = ConfValueBool(this->config_data, MultiValues[Index].tag, MultiValues[Index].items[valuenum], tagnum); + ServerInstance->Log(DEBUG,"Data type DT_BOOLEAN multi-item <%s:%s>[%d] = '%d'", MultiValues[Index].tag, MultiValues[Index].items[valuenum],tagnum, item); + vl.push_back(ValueItem(item)); + } break; default: break; } } - MultiValues[Index].validation_function(this, MultiValues[Index].tag, (char**)MultiValues[Index].items, ptr, MultiValues[Index].datatype); + ServerInstance->Log(DEBUG,"Call validation function for multi-value <%s>", MultiValues[Index].tag); + MultiValues[Index].validation_function(this, MultiValues[Index].tag, (char**)MultiValues[Index].items, vl, MultiValues[Index].datatype); } MultiValues[Index].finish_function(this, MultiValues[Index].tag); } - /* Free any memory we claimed - */ - for (int n = 0; n < 12; n++) - delete[] data[n]; - // write once here, to try it out and make sure its ok ServerInstance->WritePID(this->PID); diff --git a/src/users.cpp b/src/users.cpp index 31264570f..9eb0ba509 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -61,20 +61,20 @@ bool InitClasses(ServerConfig* conf, const char* tag) return true; } -bool DoType(ServerConfig* conf, const char* tag, char** entries, void** values, int* types) +bool DoType(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types) { - char* TypeName = (char*)values[0]; - char* Classes = (char*)values[1]; + const char* TypeName = values[0].GetString(); + const char* Classes = values[1].GetString(); conf->opertypes[TypeName] = strdup(Classes); conf->GetInstance()->Log(DEBUG,"Read oper TYPE '%s' with classes '%s'",TypeName,Classes); return true; } -bool DoClass(ServerConfig* conf, const char* tag, char** entries, void** values, int* types) +bool DoClass(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types) { - char* ClassName = (char*)values[0]; - char* CommandList = (char*)values[1]; + const char* ClassName = values[0].GetString(); + const char* CommandList = values[1].GetString(); conf->operclass[ClassName] = strdup(CommandList); conf->GetInstance()->Log(DEBUG,"Read oper CLASS '%s' with commands '%s'",ClassName,CommandList); diff --git a/src/xline.cpp b/src/xline.cpp index ce80f7880..746ad6388 100644 --- a/src/xline.cpp +++ b/src/xline.cpp @@ -52,40 +52,40 @@ bool DoneXLine(ServerConfig* conf, const char* tag) return true; } -bool DoZLine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types) +bool DoZLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types) { - char* reason = (char*)values[0]; - char* ipmask = (char*)values[1]; + const char* reason = values[0].GetString(); + const char* ipmask = values[1].GetString(); conf->GetInstance()->XLines->add_zline(0,"<Config>",reason,ipmask); conf->GetInstance()->Log(DEBUG,"Read Z line (badip tag): ipmask=%s reason=%s",ipmask,reason); return true; } -bool DoQLine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types) +bool DoQLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types) { - char* reason = (char*)values[0]; - char* nick = (char*)values[1]; + const char* reason = values[0].GetString(); + const char* nick = values[1].GetString(); conf->GetInstance()->XLines->add_qline(0,"<Config>",reason,nick); conf->GetInstance()->Log(DEBUG,"Read Q line (badnick tag): nick=%s reason=%s",nick,reason); return true; } -bool DoKLine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types) +bool DoKLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types) { - char* reason = (char*)values[0]; - char* host = (char*)values[1]; + const char* reason = values[0].GetString(); + const char* host = values[1].GetString(); conf->GetInstance()->XLines->add_kline(0,"<Config>",reason,host); conf->GetInstance()->Log(DEBUG,"Read K line (badhost tag): host=%s reason=%s",host,reason); return true; } -bool DoELine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types) +bool DoELine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types) { - char* reason = (char*)values[0]; - char* host = (char*)values[1]; + const char* reason = values[0].GetString(); + const char* host = values[1].GetString(); conf->GetInstance()->XLines->add_eline(0,"<Config>",reason,host); conf->GetInstance()->Log(DEBUG,"Read E line (exception tag): host=%s reason=%s",host,reason); |