X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fconfigreader.cpp;h=905eb786af84b0646b6ae4eca423e172cb903935;hb=bbeb5ea38686dfeb9537860770bbdb3bd2f9cd3f;hp=1b565c7f739aaa34d7aaf5f6b47bf59015e55e59;hpb=370e899d8a53ecfd3ec3a49a5fbb81212fa154e3;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/configreader.cpp b/src/configreader.cpp index 1b565c7f7..905eb786a 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -23,7 +23,6 @@ #include "inspircd.h" -#include #include "xline.h" #include "listmode.h" #include "exitcodes.h" @@ -50,8 +49,7 @@ static void range(T& value, V min, V max, V def, const char* msg) { if (value >= (T)min && value <= (T)max) return; - ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, - "WARNING: %s value of %ld is not between %ld and %ld; set to %ld.", + ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "WARNING: %s value of %ld is not between %ld and %ld; set to %ld.", msg, (long)value, (long)min, (long)max, (long)def); value = def; } @@ -135,8 +133,6 @@ void ServerConfig::CrossCheckOperClassType() std::string name = tag->getString("name"); if (name.empty()) throw CoreException(" is missing from tag at " + tag->getTagLocation()); - if (!ServerInstance->IsNick(name, Limits.NickMax)) - throw CoreException(" is invalid (value '" + name + "')"); if (oper_blocks.find(" " + name) != oper_blocks.end()) throw CoreException("Duplicate type block with name " + name + " at " + tag->getTagLocation()); @@ -335,13 +331,13 @@ struct DeprecatedConfig { /** Tag name. */ std::string tag; - + /** Attribute key. */ std::string key; - + /** Attribute value. */ std::string value; - + /** Reason for deprecation. */ std::string reason; }; @@ -371,10 +367,15 @@ void ServerConfig::Fill() else { if (ServerName != ConfValue("server")->getString("name")) - throw CoreException("You must restart to change the server name or SID"); + throw CoreException("You must restart to change the server name"); + std::string nsid = ConfValue("server")->getString("id"); if (!nsid.empty() && nsid != sid) - throw CoreException("You must restart to change the server name or SID"); + throw CoreException("You must restart to change the server id"); + + if (Limits.MaxLine != static_cast(ConfValue("limits")->getInt("maxline", 512))) + throw CoreException("You must restart to change the maximum line length"); + } diepass = ConfValue("power")->getString("diepass"); restartpass = ConfValue("power")->getString("restartpass"); @@ -427,11 +428,13 @@ void ServerConfig::Fill() Limits.MaxKick = ConfValue("limits")->getInt("maxkick", 255); Limits.MaxGecos = ConfValue("limits")->getInt("maxgecos", 128); Limits.MaxAway = ConfValue("limits")->getInt("maxaway", 200); + Limits.MaxLine = ConfValue("limits")->getInt("maxline", 512); InvBypassModes = options->getBool("invitebypassmodes", true); NoSnoticeStack = options->getBool("nosnoticestack", false); range(SoftLimit, 10, ServerInstance->SE->GetMaxFds(), ServerInstance->SE->GetMaxFds(), ""); - range(MaxConn, 0, SOMAXCONN, SOMAXCONN, ""); + if (ConfValue("performance")->getBool("limitsomaxconn", true)) + range(MaxConn, 0, SOMAXCONN, SOMAXCONN, ""); range(MaxTargets, 1, 31, 20, ""); range(NetBufferSize, 1024, 65534, 10240, ""); @@ -594,14 +597,14 @@ void ServerConfig::Apply(ServerConfig* old, const std::string &useruid) ServerInstance->BindPorts(pl); if (pl.size()) { - errstr << "Not all your client ports could be bound.\nThe following port(s) failed to bind:\n"; + errstr << "Not all your client ports could be bound." << std::endl + << "The following port(s) failed to bind:" << std::endl; int j = 1; for (FailedPortList::iterator i = pl.begin(); i != pl.end(); i++, j++) { - char buf[MAXBUF]; - snprintf(buf, MAXBUF, "%d. Address: %s Reason: %s\n", j, i->first.empty() ? "" : i->first.c_str(), i->second.c_str()); - errstr << buf; + errstr << j << ".\tAddress: " << (i->first.empty() ? "" : i->first.c_str()) << "\tReason: " + << i->second << std::endl; } } } @@ -609,7 +612,7 @@ void ServerConfig::Apply(ServerConfig* old, const std::string &useruid) User* user = useruid.empty() ? NULL : ServerInstance->FindNick(useruid); if (!valid) - ServerInstance->Logs->Log("CONFIG",LOG_DEFAULT, "There were errors in your configuration file:"); + ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "There were errors in your configuration file:"); while (errstr.good()) { @@ -751,7 +754,7 @@ ConfigTag* ServerConfig::ConfValue(const std::string &tag) ConfigTag* rv = found.first->second; found.first++; if (found.first != found.second) - ServerInstance->Logs->Log("CONFIG",LOG_DEFAULT, "Multiple <" + tag + "> tags found; only first will be used " + ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "Multiple <" + tag + "> tags found; only first will be used " "(first at " + rv->getTagLocation() + "; second at " + found.first->second->getTagLocation() + ")"); return rv; } @@ -770,14 +773,31 @@ bool ServerConfig::FileExists(const char* file) if ((sb.st_mode & S_IFDIR) > 0) return false; - FILE *input = fopen(file, "r"); - if (input == NULL) - return false; - else + return !access(file, F_OK); +} + +std::string ServerConfig::Escape(const std::string& str, bool xml) +{ + std::string escaped; + for (std::string::const_iterator it = str.begin(); it != str.end(); ++it) { - fclose(input); - return true; + switch (*it) + { + case '"': + escaped += xml ? """ : "\""; + break; + case '&': + escaped += xml ? "&" : "&"; + break; + case '\\': + escaped += xml ? "\\" : "\\\\"; + break; + default: + escaped += *it; + break; + } } + return escaped; } const char* ServerConfig::CleanFilename(const char* name) @@ -787,11 +807,6 @@ const char* ServerConfig::CleanFilename(const char* name) return (p != name ? ++p : p); } -const std::string& ServerConfig::GetSID() -{ - return sid; -} - void ConfigReaderThread::Run() { Config->Read(); @@ -801,7 +816,7 @@ void ConfigReaderThread::Run() void ConfigReaderThread::Finish() { ServerConfig* old = ServerInstance->Config; - ServerInstance->Logs->Log("CONFIG",LOG_DEBUG,"Switching to new configuration..."); + ServerInstance->Logs->Log("CONFIG", LOG_DEBUG, "Switching to new configuration..."); ServerInstance->Config = this->Config; Config->Apply(old, TheUserUID);