* | Inspire Internet Relay Chat Daemon |
* +------------------------------------+
*
- * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
- * E-mail:
- * <brain@chatspike.net>
- * <Craig@chatspike.net>
- *
- * Written by Craig Edwards, Craig McLure, and others.
+ * InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ * See: http://www.inspircd.org/wiki/index.php/Credits
+ *
* This program is free but copyrighted software; see
- * the file COPYING for details.
+ * the file COPYING for details.
*
* ---------------------------------------------------
*/
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 (x != IOHookModule.end() ? x->second : NULL);
}
+Module* ServerConfig::GetIOHook(InspSocket* is)
+{
+ std::map<InspSocket*,Module*>::iterator x = SocketIOHookModule.find(is);
+ return (x != SocketIOHookModule.end() ? x->second : NULL);
+}
+
bool ServerConfig::AddIOHook(int port, Module* iomod)
{
if (!GetIOHook(port))
}
else
{
- ModuleException err("Port already hooked by another module");
- throw(err);
+ throw ModuleException("Port already hooked by another module");
+ return false;
+ }
+}
+
+bool ServerConfig::AddIOHook(Module* iomod, InspSocket* is)
+{
+ if (!GetIOHook(is))
+ {
+ ServerInstance->Log(DEBUG,"Hooked inspsocket %08x", is);
+ SocketIOHookModule[is] = iomod;
+ is->IsIOHooked = true;
+ return true;
+ }
+ else
+ {
+ throw ModuleException("InspSocket derived class already hooked by another module");
return false;
}
}
return false;
}
+bool ServerConfig::DelIOHook(InspSocket* is)
+{
+ std::map<InspSocket*,Module*>::iterator x = SocketIOHookModule.find(is);
+ if (x != SocketIOHookModule.end())
+ {
+ SocketIOHookModule.erase(x);
+ return true;
+ }
+ return false;
+}
+
+void ServerConfig::Update005()
+{
+ std::stringstream out(data005);
+ std::string token;
+ std::string line5;
+ int token_counter = 0;
+ isupport.clear();
+ while (out >> token)
+ {
+ line5 = line5 + token + " ";
+ token_counter++;
+ if (token_counter >= 13)
+ {
+ char buf[MAXBUF];
+ snprintf(buf, MAXBUF, "%s:are supported by this server", line5.c_str());
+ isupport.push_back(buf);
+ line5 = "";
+ token_counter = 0;
+ }
+ }
+ char buf[MAXBUF];
+ snprintf(buf, MAXBUF, "%s:are supported by this server", line5.c_str());
+ isupport.push_back(buf);
+}
+
+void ServerConfig::Send005(userrec* user)
+{
+ for (std::vector<std::string>::iterator line = ServerInstance->Config->isupport.begin(); line != ServerInstance->Config->isupport.end(); line++)
+ user->WriteServ("005 %s %s", user->nick, line->c_str());
+}
+
bool ServerConfig::CheckOnce(char* tag, bool bail, userrec* user)
{
int count = ConfValueEnum(this->config_data, tag);
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))
{"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, NoValidation},
{NULL}
};
if((ch == '#') && !in_quote)
in_comment = true;
- if(((ch == '\n') || (ch == '\r')) && in_quote)
+ /*if(((ch == '\n') || (ch == '\r')) && in_quote)
{
errorstream << "Got a newline within a quoted section, this is probably a typo: " << filename << ":" << linenumber << std::endl;
return false;
- }
+ }*/
switch(ch)
{
case '\n':
+ if (in_quote)
+ {
+ ServerInstance->Log(DEBUG, "Got \\n inside value");
+ line += '\n';
+ }
linenumber++;
case '\r':
- in_comment = false;
+ if (!in_quote)
+ in_comment = false;
case '\0':
continue;
case '\t':
}
}
- line += ch;
+ if (ch != '\r')
+ line += ch;
if(ch == '<')
{
bool in_quote;
got_name = got_key = in_quote = false;
-
- // std::cout << "ParseLine(data, '" << line << "', " << linenumber << ", stream)" << std::endl;
+
+ //std::cout << "ParseLine(data, '" << line << "', " << linenumber << ", stream)" << std::endl;
for(std::string::iterator c = line.begin(); c != line.end(); c++)
{
current_value += *c;
continue;
}
+ else if ((*c == '\n') && (in_quote))
+ {
+ /* Got a 'real' \n, treat it as part of the value */
+ current_value += '\n';
+ continue;
+ }
+ else if ((*c == '\r') && (in_quote))
+ /* Got a \r, drop it */
+ continue;
+
if (*c == '"')
{
if (!in_quote)
{
/* Leaving quotes, we have the value */
results.push_back(KeyVal(current_key, current_value));
-
+
// std::cout << "<" << tagname << ":" << current_key << "> " << current_value << std::endl;
in_quote = false;
*/
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");
+}
+