ServerConfig::ServerConfig(InspIRCd* Instance) : ServerInstance(Instance)
{
this->ClearStack();
- *TempDir = *ServerName = *Network = *ServerDesc = *AdminName = '\0';
+ *ServerName = *Network = *ServerDesc = *AdminName = '\0';
*HideWhoisServer = *AdminEmail = *AdminNick = *diepass = *restartpass = '\0';
*CustomVersion = *motd = *rules = *PrefixQuit = *DieValue = *DNSServer = '\0';
*UserStats = *ModPath = *MyExecutable = *DisabledCommands = *PID = '\0';
return true;
}
-bool ValidateTempDir(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
-{
- if (!*(data.GetString()))
- data.Set("/tmp");
- return true;
-}
-
bool ValidateMaxTargets(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
{
if ((data.GetInteger() < 0) || (data.GetInteger() > 31))
return true;
}
+bool ValidateDie(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
+{
+ if (!*data.GetString())
+ {
+ conf->GetInstance()->Log(DEFAULT,"Die value is set: \"%s\", terminating.", data.GetString());
+ printf("\n\nERROR: %s\n\n", data.GetString());
+ exit(ERROR);
+ }
+ return true;
+}
+
bool ValidateWhoWas(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
{
conf->WhoWasMaxKeep = conf->GetInstance()->Duration(data.GetString());
static char* Once[] = { "server", "admin", "files", "power", "options", NULL };
/* These tags can occur ONCE or not at all */
- static InitialConfig Values[] = {
+ InitialConfig Values[] = {
{"options", "softlimit", new ValueContainerUInt (&this->SoftLimit), DT_INTEGER, ValidateSoftLimit},
{"options", "somaxconn", new ValueContainerInt (&this->MaxConn), DT_INTEGER, ValidateMaxConn},
{"server", "name", new ValueContainerChar (this->ServerName), DT_CHARPTR, ValidateServerName},
{"options", "hidebans", new ValueContainerBool (&this->HideBans), DT_BOOLEAN, NoValidation},
{"options", "hidewhois", new ValueContainerChar (this->HideWhoisServer), DT_CHARPTR, NoValidation},
{"options", "operspywhois", new ValueContainerBool (&this->OperSpyWhois), DT_BOOLEAN, NoValidation},
- {"options", "tempdir", new ValueContainerChar (this->TempDir), DT_CHARPTR, ValidateTempDir},
{"options", "nouserdns", new ValueContainerBool (&this->NoUserDns), DT_BOOLEAN, NoValidation},
{"options", "syntaxhints", new ValueContainerBool (&this->SyntaxHints), DT_BOOLEAN, NoValidation},
{"options", "cyclehosts", new ValueContainerBool (&this->CycleHosts), DT_BOOLEAN, NoValidation},
{"whowas", "groupsize", new ValueContainerInt (&this->WhoWasGroupSize), DT_INTEGER, NoValidation},
{"whowas", "maxgroups", new ValueContainerInt (&this->WhoWasMaxGroups), DT_INTEGER, NoValidation},
{"whowas", "maxkeep", new ValueContainerChar (maxkeep), DT_CHARPTR, ValidateWhoWas},
+ {"die", "value", new ValueContainerChar (this->DieValue), DT_CHARPTR, ValidateDie},
{NULL}
};
/* These tags can occur multiple times, and therefore they have special code to read them
* which is different to the code for reading the singular tags listed above.
*/
- static MultiConfig MultiValues[] = {
+ MultiConfig MultiValues[] = {
{"connect",
{"allow", "deny", "password", "timeout", "pingfreq", "flood",
*/
bool ServerConfig::ReadFile(file_cache &F, const char* fname)
{
- FILE* file;
+ FILE* file = NULL;
char linebuf[MAXBUF];
F.clear();
{
while (!feof(file))
{
- fgets(linebuf, sizeof(linebuf), file);
- linebuf[strlen(linebuf)-1] = 0;
+ if (fgets(linebuf, sizeof(linebuf), file))
+ linebuf[strlen(linebuf)-1] = 0;
+ else
+ *linebuf = 0;
if (!feof(file))
{
if (getcwd(buffer, MAXBUF ) == NULL )
return false;
- chdir(work);
+ if (chdir(work) == -1)
+ return false;
if (getcwd(otherdir, MAXBUF ) == NULL )
return false;
- chdir(buffer);
+ if (chdir(buffer) == -1)
+ return false;
size_t t = strlen(work);
if (getcwd(buffer, MAXBUF) == NULL)
return "";
- chdir(work);
+ if (chdir(work) == -1)
+ return "";
if (getcwd(otherdir, MAXBUF) == NULL)
return "";
- chdir(buffer);
+ if (chdir(buffer) == -1)
+ return "";
+
return otherdir;
}
return ServerInstance;
}
+
+ValueItem::ValueItem(int value)
+{
+ std::stringstream n;
+ n << value;
+ v = n.str();
+}
+
+ValueItem::ValueItem(bool value)
+{
+ std::stringstream n;
+ n << value;
+ v = n.str();
+}
+
+ValueItem::ValueItem(char* value)
+{
+ v = value;
+}
+
+void ValueItem::Set(char* value)
+{
+ v = value;
+}
+
+void ValueItem::Set(const char* value)
+{
+ v = value;
+}
+
+void ValueItem::Set(int value)
+{
+ std::stringstream n;
+ n << value;
+ v = n.str();
+}
+
+int ValueItem::GetInteger()
+{
+ return atoi(v.c_str());
+}
+
+char* ValueItem::GetString()
+{
+ return (char*)v.c_str();
+}
+
+bool ValueItem::GetBool()
+{
+ return (GetInteger() || v == "yes" || v == "true");
+}
+