#include "dns.h"
#include "exitcodes.h"
-#ifndef WIN32
+#ifndef _WIN32
#include <dirent.h>
#endif
void Module::OnHookIO(StreamSocket*, ListenSocket*) { }
ModResult Module::OnAcceptConnection(int, ListenSocket*, irc::sockets::sockaddrs*, irc::sockets::sockaddrs*) { return MOD_RES_PASSTHRU; }
void Module::OnSendWhoLine(User*, const std::vector<std::string>&, User*, std::string&) { }
-void Module::OnSetClientIP(User *) { }
+void Module::OnSetUserIP(LocalUser*) { }
ModuleManager::ModuleManager() : ModCount(0)
{
{
std::map<std::string, Module*>::iterator modfind = Modules.find(mod->ModuleSourceFile);
- if (modfind == Modules.end() || modfind->second != mod)
+ if ((modfind == Modules.end()) || (modfind->second != mod) || (mod->dying))
{
LastModuleError = "Module " + mod->ModuleSourceFile + " is not loaded, cannot unload it!";
ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
return false;
}
+
+ mod->dying = true;
return true;
}
std::vector<reference<ExtensionItem> > items;
ServerInstance->Extensions.BeginUnregister(modfind->second, items);
/* Give the module a chance to tidy out all its metadata */
- for (chan_hash::iterator c = ServerInstance->chanlist->begin(); c != ServerInstance->chanlist->end(); c++)
+ for (chan_hash::iterator c = ServerInstance->chanlist->begin(); c != ServerInstance->chanlist->end(); )
{
- mod->OnCleanup(TYPE_CHANNEL,c->second);
- c->second->doUnhookExtensions(items);
- const UserMembList* users = c->second->GetUsers();
+ Channel* chan = c->second;
+ ++c;
+ mod->OnCleanup(TYPE_CHANNEL, chan);
+ chan->doUnhookExtensions(items);
+ const UserMembList* users = chan->GetUsers();
for(UserMembCIter mi = users->begin(); mi != users->end(); mi++)
mi->second->doUnhookExtensions(items);
}
- for (user_hash::iterator u = ServerInstance->Users->clientlist->begin(); u != ServerInstance->Users->clientlist->end(); u++)
+ for (user_hash::iterator u = ServerInstance->Users->clientlist->begin(); u != ServerInstance->Users->clientlist->end(); )
{
- mod->OnCleanup(TYPE_USER,u->second);
- u->second->doUnhookExtensions(items);
+ User* user = u->second;
+ // The module may quit the user (e.g. SSL mod unloading) and that will remove it from the container
+ ++u;
+ mod->OnCleanup(TYPE_USER, user);
+ user->doUnhookExtensions(items);
}
for(char m='A'; m <= 'z'; m++)
{
throw ModuleException("Mode "+std::string(item.name)+" already exists.");
return;
case SERVICE_METADATA:
- ServerInstance->Extensions.Register(static_cast<ExtensionItem*>(&item));
+ if (!ServerInstance->Extensions.Register(static_cast<ExtensionItem*>(&item)))
+ throw ModuleException("Extension " + std::string(item.name) + " already exists.");
return;
case SERVICE_DATA:
case SERVICE_IOHOOK:
if (i != ServerInstance->Modules->DataProviders.end())
value = static_cast<DataProvider*>(i->second);
}
- return value;
+ return (value != NULL);
}
void InspIRCd::SendMode(const std::vector<std::string>& parameters, User *user)
std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool allow_linefeeds)
{
std::string result = default_value;
- if (!SlowGetTag(tag, index)->readString(name, result, allow_linefeeds))
+ ConfigTag* conftag = SlowGetTag(tag, index);
+ if (!conftag || !conftag->readString(name, result, allow_linefeeds))
{
this->error = CONF_VALUE_NOT_FOUND;
}
bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, const std::string &default_value, int index)
{
bool def = (default_value == "yes");
- return SlowGetTag(tag, index)->getBool(name, def);
+ ConfigTag* conftag = SlowGetTag(tag, index);
+ return conftag ? conftag->getBool(name, def) : def;
}
bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, int index)
int ConfigReader::ReadInteger(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool need_positive)
{
int v = atoi(default_value.c_str());
- int result = SlowGetTag(tag, index)->getInt(name, v);
+ ConfigTag* conftag = SlowGetTag(tag, index);
+ int result = conftag ? conftag->getInt(name, v) : v;
if ((need_positive) && (result < 0))
{
std::string FileReader::GetLine(int x)
{
- if ((x<0) || ((unsigned)x>fc.size()))
+ if ((x<0) || ((unsigned)x>=fc.size()))
return "";
return fc[x];
}