Hold reference to the associated ConfigTag inside ConnectClass

git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11880 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
danieldg 2009-10-17 02:40:16 +00:00
parent bf6724c049
commit 548eacee47
5 changed files with 37 additions and 69 deletions

View File

@ -59,11 +59,13 @@ enum RegistrationState {
/* Required forward declaration */
class Channel;
class UserResolver;
class ConfigTag;
/** Holds information relevent to <connect allow> and <connect deny> tags in the config file.
*/
struct CoreExport ConnectClass : public refcountbase
{
reference<ConfigTag> config;
/** Type of line, either CC_ALLOW or CC_DENY
*/
char type;
@ -129,10 +131,10 @@ struct CoreExport ConnectClass : public refcountbase
/** Create a new connect class with no settings.
*/
ConnectClass(char type, const std::string& mask);
ConnectClass(ConfigTag* tag, char type, const std::string& mask);
/** Create a new connect class with inherited settings.
*/
ConnectClass(char type, const std::string& mask, const ConnectClass& parent);
ConnectClass(ConfigTag* tag, char type, const std::string& mask, const ConnectClass& parent);
/** Update the settings in this block to match the given block */
void Update(const ConnectClass* newSettings);

View File

@ -389,8 +389,8 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current)
throw CoreException("Two connect classes cannot have the same mask (" + mask + ")");
ConnectClass* me = parent ?
new ConnectClass(type, mask, *parent) :
new ConnectClass(type, mask);
new ConnectClass(tag, type, mask, *parent) :
new ConnectClass(tag, type, mask);
if (!name.empty())
me->name = name;

View File

@ -17,14 +17,8 @@
class ModuleModesOnConnect : public Module
{
private:
ConfigReader *Conf;
public:
ModuleModesOnConnect() {
Conf = new ConfigReader;
Implementation eventlist[] = { I_OnUserConnect, I_OnRehash };
ServerInstance->Modules->Attach(eventlist, this, 2);
// for things like +x on connect, important, otherwise we have to resort to config order (bleh) -- w00t
@ -32,15 +26,8 @@ class ModuleModesOnConnect : public Module
}
virtual void OnRehash(User* user)
{
delete Conf;
Conf = new ConfigReader;
}
virtual ~ModuleModesOnConnect()
{
delete Conf;
}
virtual Version GetVersion()
@ -59,41 +46,33 @@ class ModuleModesOnConnect : public Module
sizeof(ServerInstance->Config->DisabledUModes));
memset(ServerInstance->Config->DisabledUModes, 0, 64);
for (int j = 0; j < Conf->Enumerate("connect"); j++)
ConfigTag* tag = user->MyClass->config;
std::string ThisModes = tag->getString("modes");
if (!ThisModes.empty())
{
std::string hostn = Conf->ReadValue("connect","allow",j);
/* XXX: Fixme: does not respect port, limit, etc */
if ((InspIRCd::MatchCIDR(user->GetIPString(),hostn, ascii_case_insensitive_map)) || (InspIRCd::Match(user->host,hostn, ascii_case_insensitive_map)))
std::string buf;
std::stringstream ss(ThisModes);
std::vector<std::string> tokens;
// split ThisUserModes into modes and mode params
while (ss >> buf)
tokens.push_back(buf);
std::vector<std::string> modes;
modes.push_back(user->nick);
modes.push_back(tokens[0]);
if (tokens.size() > 1)
{
std::string ThisModes = Conf->ReadValue("connect","modes",j);
if (!ThisModes.empty())
// process mode params
for (unsigned int k = 1; k < tokens.size(); k++)
{
std::string buf;
std::stringstream ss(ThisModes);
std::vector<std::string> tokens;
// split ThisUserModes into modes and mode params
while (ss >> buf)
tokens.push_back(buf);
std::vector<std::string> modes;
modes.push_back(user->nick);
modes.push_back(tokens[0]);
if (tokens.size() > 1)
{
// process mode params
for (unsigned int k = 1; k < tokens.size(); k++)
{
modes.push_back(tokens[k]);
}
}
ServerInstance->Parser->CallHandler("MODE", modes, user);
modes.push_back(tokens[k]);
}
break;
}
ServerInstance->Parser->CallHandler("MODE", modes, user);
}
memcpy(ServerInstance->Config->DisabledUModes, save, 64);

View File

@ -276,12 +276,10 @@ class IdentRequestSocket : public EventHandler
class ModuleIdent : public Module
{
int RequestTimeout;
ConfigReader *Conf;
SimpleExtItem<IdentRequestSocket> ext;
public:
ModuleIdent() : ext("ident_socket", this)
{
Conf = new ConfigReader;
OnRehash(NULL);
Implementation eventlist[] = { I_OnRehash, I_OnUserRegister, I_OnCheckReady, I_OnUserDisconnect };
ServerInstance->Modules->Attach(eventlist, this, 4);
@ -289,7 +287,6 @@ class ModuleIdent : public Module
~ModuleIdent()
{
delete Conf;
}
virtual Version GetVersion()
@ -299,28 +296,18 @@ class ModuleIdent : public Module
virtual void OnRehash(User *user)
{
delete Conf;
Conf = new ConfigReader;
ConfigReader Conf;
RequestTimeout = Conf->ReadInteger("ident", "timeout", 0, true);
RequestTimeout = Conf.ReadInteger("ident", "timeout", 0, true);
if (!RequestTimeout)
RequestTimeout = 5;
}
virtual ModResult OnUserRegister(User *user)
{
for (int j = 0; j < Conf->Enumerate("connect"); j++)
{
std::string hostn = Conf->ReadValue("connect","allow",j);
/* XXX: Fixme: does not respect port, limit, etc */
if ((InspIRCd::MatchCIDR(user->GetIPString(),hostn, ascii_case_insensitive_map)) || (InspIRCd::Match(user->host,hostn, ascii_case_insensitive_map)))
{
bool useident = Conf->ReadFlag("connect", "useident", "yes", j);
if (!useident)
return MOD_RES_PASSTHRU;
}
}
ConfigTag* tag = user->MyClass->config;
if (!tag->getBool("useident", true))
return MOD_RES_PASSTHRU;
/* User::ident is currently the username field from USER; with m_ident loaded, that
* should be preceded by a ~. The field is actually IdentMax+2 characters wide. */

View File

@ -1801,15 +1801,15 @@ const std::string FakeUser::GetFullRealHost()
return nick;
}
ConnectClass::ConnectClass(char t, const std::string& mask)
: type(t), name("unnamed"), registration_timeout(0), host(mask),
ConnectClass::ConnectClass(ConfigTag* tag, char t, const std::string& mask)
: config(tag), type(t), name("unnamed"), registration_timeout(0), host(mask),
pingtime(0), pass(""), hash(""), softsendqmax(0), hardsendqmax(0),
recvqmax(0), maxlocal(0), maxglobal(0), maxchans(0), port(0), limit(0)
{
}
ConnectClass::ConnectClass(char t, const std::string& mask, const ConnectClass& parent)
: type(t), name("unnamed"),
ConnectClass::ConnectClass(ConfigTag* tag, char t, const std::string& mask, const ConnectClass& parent)
: config(tag), type(t), name("unnamed"),
registration_timeout(parent.registration_timeout), host(mask),
pingtime(parent.pingtime), pass(parent.pass), hash(parent.hash),
softsendqmax(parent.softsendqmax), hardsendqmax(parent.hardsendqmax),