#endif
-// version is a simple class for holding a modules version number
+// Version is a simple class for holding a modules version number
template<>
-VersionBase<API_VERSION>::VersionBase(const std::string &modv, int flags, int, const std::string& rev)
+VersionBase<API_VERSION>::VersionBase(const std::string &modv, int flags, const std::string& rev)
: description(modv), version(rev), Flags(flags)
{
}
// These declarations define the behavours of the base class Module (which does nothing at all)
-Module::Module() { }
-bool Module::cull()
+Module::Module() : refcount(1) { }
+CullResult Module::cull()
{
- return true;
+ return classbase::cull();
+}
+Module::~Module()
+{
+ if (refcount != 1)
+ ServerInstance->Logs->Log("MODULE", DEFAULT, "References remain to destructed module " + ModuleSourceFile);
}
-Module::~Module() { }
ModResult Module::OnSendSnotice(char &snomask, std::string &type, const std::string &message) { return MOD_RES_PASSTHRU; }
void Module::OnUserConnect(User*) { }
bool ModuleManager::Load(const char* filename)
{
+ /* Don't allow people to specify paths for modules, it doesn't work as expected */
+ if (strchr(filename, '/'))
+ return false;
/* Do we have a glob pattern in the filename?
* The user wants to load multiple modules which
* match the pattern.
{
std::map<std::string, Module*>::iterator modfind = Modules.find(mod->ModuleSourceFile);
- std::vector<ExtensionItem*> items;
+ 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++)
mod->OnCleanup(TYPE_USER,u->second);
u->second->doUnhookExtensions(items);
}
+ for(char m='A'; m <= 'z'; m++)
+ {
+ ModeHandler* mh;
+ mh = ServerInstance->Modes->FindMode(m, MODETYPE_USER);
+ if (mh && mh->creator == mod)
+ ServerInstance->Modes->DelMode(mh);
+ mh = ServerInstance->Modes->FindMode(m, MODETYPE_CHANNEL);
+ if (mh && mh->creator == mod)
+ ServerInstance->Modes->DelMode(mh);
+ }
/* Tidy up any dangling resolvers */
ServerInstance->Res->CleanResolvers(mod);
/* We must load the modules AFTER initializing the socket engine, now */
void ModuleManager::LoadAll()
{
- char configToken[MAXBUF];
ModCount = 0;
printf("\nLoading core commands");
printf("\n");
}
- for(int count = 0; count < ServerInstance->Config->ConfValueEnum("module"); count++)
+ for(int count = 0;; count++)
{
- ServerInstance->Config->ConfValue("module", "name", count, configToken, MAXBUF);
- printf_c("[\033[1;32m*\033[0m] Loading module:\t\033[1;32m%s\033[0m\n",configToken);
+ ConfigTag* tag = ServerInstance->Config->ConfValue("module", count);
+ if (!tag)
+ break;
+ std::string name = tag->getString("name");
+ printf_c("[\033[1;32m*\033[0m] Loading module:\t\033[1;32m%s\033[0m\n",name.c_str());
- if (!this->Load(configToken))
+ if (!this->Load(name.c_str()))
{
ServerInstance->Logs->Log("MODULE", DEFAULT, this->LastError());
printf_c("\n[\033[1;31m*\033[0m] %s\n\n", this->LastError().c_str());
std::map<std::string, Module*>::iterator me = i++;
if (CanUnload(me->second))
{
- ServerInstance->GlobalCulls.AddItem(me->second);
+ DoSafeUnload(me->second);
}
}
ServerInstance->GlobalCulls.Apply();
this->Modes->Process(parameters, user);
}
-void InspIRCd::DumpText(User* user, const std::string &text)
-{
- if (IS_LOCAL(user))
- {
- user->Write(text);
- }
- else
- {
- PI->PushToClient(user, text);
- }
-}
-
-void InspIRCd::DumpText(User* user, const char *text, ...)
-{
- va_list argsPtr;
- char line[MAXBUF];
-
- va_start(argsPtr, text);
- vsnprintf(line, MAXBUF, text, argsPtr);
- va_end(argsPtr);
-
- DumpText(user, std::string(line));
-}
-
-void InspIRCd::DumpText(User* user, const std::string &LinePrefix, std::stringstream &TextStream)
-{
- char line[MAXBUF];
- int start_pos = LinePrefix.length();
- int pos = start_pos;
- memcpy(line, LinePrefix.data(), pos);
- std::string Word;
- while (TextStream >> Word)
- {
- int len = Word.length();
- if (pos + len + 12 > MAXBUF)
- {
- line[pos] = '\0';
- DumpText(user, std::string(line));
- pos = start_pos;
- }
- line[pos] = ' ';
- memcpy(line + pos + 1, Word.data(), len);
- pos += len + 1;
- }
- line[pos] = '\0';
- DumpText(user, std::string(line));
-}
-
bool InspIRCd::AddResolver(Resolver* r, bool cached)
{
if (!cached)
std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool allow_linefeeds)
{
/* Don't need to strlcpy() tag and name anymore, ReadConf() takes const char* */
- std::string result;
-
- if (!ServerInstance->Config->ConfValue(tag, name, default_value, index, result, allow_linefeeds))
+ std::string result = default_value;
+ if (!ServerInstance->Config->ConfValue(tag, index)->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)
{
- return ServerInstance->Config->ConfValueBool(tag, name, default_value, index);
+ bool def = (default_value == "yes");
+ return ServerInstance->Config->ConfValue(tag, index)->getBool(name, 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 result;
-
- if(!ServerInstance->Config->ConfValueInteger(tag, name, default_value, index, result))
- {
- this->error = CONF_VALUE_NOT_FOUND;
- return 0;
- }
+ int v = atoi(default_value.c_str());
+ int result = ServerInstance->Config->ConfValue(tag, index)->getInt(name, v);
if ((need_positive) && (result < 0))
{
int ConfigReader::Enumerate(const std::string &tag)
{
- return ServerInstance->Config->ConfValueEnum(tag);
-}
-
-int ConfigReader::EnumerateValues(const std::string &tag, int index)
-{
- return ServerInstance->Config->ConfVarEnum(tag, index);
+ ServerInstance->Logs->Log("MODULE", DEBUG, "Module is using ConfigReader::Enumerate on %s; this is slow!",
+ tag.c_str());
+ int i=0;
+ while (ServerInstance->Config->ConfValue(tag, i)) i++;
+ return i;
}
FileReader::FileReader(const std::string &filename)