/**
* Called just prior to destruction via cull list.
- *
- * @return true to allow the delete, or false to halt the delete
*/
virtual CullResult cull();
virtual ~classbase();
/** Base class for use count tracking. Uses reference<>, but does not
* cause object deletion when the last user is removed.
+ *
+ * Safe for use as a second parent class; will not add a second vtable.
*/
class CoreExport usecountbase
{
typedef const reference<Module> ModuleRef;
+enum ServiceType {
+ /** is a Command */
+ SERVICE_COMMAND,
+ /** is a channel ModeHandler */
+ SERVICE_CMODE,
+ /** is a user ModeHandler */
+ SERVICE_UMODE,
+ /** is a metadata descriptor */
+ SERVICE_METADATA,
+ /** is a data processing provider (MD5, SQL) */
+ SERVICE_DATA,
+ /** is an I/O hook provider (SSL) */
+ SERVICE_IOHOOK
+};
+
+/** A structure defining something that a module can provide */
+class CoreExport providerbase : public classbase
+{
+ public:
+ /** Module that is providing this service */
+ ModuleRef creator;
+ /** Name of the service being provided */
+ const std::string name;
+ /** Type of service (must match object type) */
+ const ServiceType service;
+ providerbase(Module* Creator, const std::string& Name, ServiceType Type)
+ : creator(Creator), name(Name), service(Type) {}
+ virtual ~providerbase();
+};
+
+
#endif
/** A structure that defines a command. Every command available
* in InspIRCd must be defined as derived from Command.
*/
-class CoreExport Command : public classbase
+class CoreExport Command : public providerbase
{
public:
- /** Command name
- */
- const std::string command;
-
- /** Creator module - never NULL */
- ModuleRef creator;
-
/** User flags needed to execute the command or 0
*/
char flags_needed;
* NICK, optionally PASS, and been resolved).
*/
Command(Module* me, const std::string &cmd, int minpara = 0, int maxpara = 0) :
- command(cmd), creator(me), flags_needed(0), min_params(minpara), max_params(maxpara),
+ providerbase(me, cmd, SERVICE_COMMAND), flags_needed(0), min_params(minpara), max_params(maxpara),
use_count(0), total_bytes(0), disabled(false), works_before_reg(false), Penalty(1)
{
}
/** Class represnting an extension of some object
*/
-class CoreExport ExtensionItem : public usecountbase
+class CoreExport ExtensionItem : public providerbase, public usecountbase
{
public:
- const std::string key;
- ModuleRef owner;
ExtensionItem(const std::string& key, Module* owner);
virtual ~ExtensionItem();
/** Serialize this item into a string
*/
bool AddResolver(Resolver* r, bool cached);
+ /** Register a service provided by a module */
+ void AddService(providerbase&);
+
+ inline void AddServices(providerbase** list, int count)
+ {
+ for(int i=0; i < count; i++)
+ AddService(*list[i]);
+ }
+
/** Add a command to this server's command parser
* @param f A Command command handler object to add
* @throw ModuleException Will throw ModuleExcption if the command already exists
Version GetVersion()
{
- return Version(cmd.command, VF_VENDOR|VF_CORE);
+ return Version(cmd.name, VF_VENDOR|VF_CORE);
}
};
* mode is expected to have a parameter, then this is
* equivalent to returning MODEACTION_DENY.
*/
-class CoreExport ModeHandler : public classbase
+class CoreExport ModeHandler : public providerbase
{
protected:
/**
int levelrequired;
public:
- /** Module that created this mode. NULL for core modes */
- ModuleRef creator;
- /** Long-form name
- */
- const std::string name;
-
/**
* The constructor for ModeHandler initalizes the mode handler.
* The constructor of any class you derive from ModeHandler should
(void*)this, usecount);
}
-ExtensionItem::ExtensionItem(const std::string& Key, Module* mod) : key(Key), owner(mod)
+providerbase::~providerbase()
+{
+}
+
+ExtensionItem::ExtensionItem(const std::string& Key, Module* mod) : providerbase(mod, Key, SERVICE_METADATA)
{
}
void ExtensionManager::Register(ExtensionItem* item)
{
- types.insert(std::make_pair(item->key, item));
+ types.insert(std::make_pair(item->name, item));
}
void ExtensionManager::BeginUnregister(Module* module, std::vector<reference<ExtensionItem> >& list)
{
std::map<std::string, reference<ExtensionItem> >::iterator me = i++;
ExtensionItem* item = me->second;
- if (item->owner == module)
+ if (item->creator == module)
{
list.push_back(item);
types.erase(me);
{
user->WriteNumeric(ERR_NEEDMOREPARAMS, "%s %s :Not enough parameters.", user->nick.c_str(), command.c_str());
if ((ServerInstance->Config->SyntaxHints) && (user->registered == REG_ALL) && (cm->second->syntax.length()))
- user->WriteNumeric(RPL_SYNTAX, "%s :SYNTAX %s %s", user->nick.c_str(), cm->second->command.c_str(), cm->second->syntax.c_str());
+ user->WriteNumeric(RPL_SYNTAX, "%s :SYNTAX %s %s", user->nick.c_str(), cm->second->name.c_str(), cm->second->syntax.c_str());
return do_more;
}
if ((user->registered != REG_ALL) && (!cm->second->WorksBeforeReg()))
void CommandParser::RemoveCommand(Command* x)
{
- Commandtable::iterator n = cmdlist.find(x->command);
+ Commandtable::iterator n = cmdlist.find(x->name);
if (n != cmdlist.end() && n->second == x)
cmdlist.erase(n);
}
bool CommandParser::AddCommand(Command *f)
{
/* create the command and push it onto the table */
- if (cmdlist.find(f->command) == cmdlist.end())
+ if (cmdlist.find(f->name) == cmdlist.end())
{
- cmdlist[f->command] = f;
+ cmdlist[f->name] = f;
return true;
}
return false;
Module* src = i->second->creator;
user->WriteNumeric(RPL_COMMANDS, "%s :%s %s %d %d",
user->nick.c_str(),
- i->second->command.c_str(),
+ i->second->name.c_str(),
src ? src->ModuleSourceFile.c_str() : "<core>",
i->second->min_params,
i->second->Penalty);
}
else
{
- user->WriteNumeric(ERR_NOTREGISTERED, "%s :You may not register as a server (servers have seperate ports from clients, change your config)",command.c_str());
+ user->WriteNumeric(ERR_NOTREGISTERED, "%s :You may not register as a server (servers have seperate ports from clients, change your config)",name.c_str());
}
return CMD_FAILURE;
}
match = false;
const Extensible::ExtensibleStore& list = user->GetExtList();
for(Extensible::ExtensibleStore::const_iterator i = list.begin(); i != list.end(); ++i)
- if (InspIRCd::Match(i->first->key, matchtext))
+ if (InspIRCd::Match(i->first->name, matchtext))
match = true;
}
else if (opt_realname)
/* if whowas disabled in config */
if (ServerInstance->Config->WhoWasGroupSize == 0 || ServerInstance->Config->WhoWasMaxGroups == 0)
{
- user->WriteNumeric(421, "%s %s :This command has been disabled.",user->nick.c_str(),command.c_str());
+ user->WriteNumeric(421, "%s %s :This command has been disabled.",user->nick.c_str(),name.c_str());
return CMD_FAILURE;
}
/* $Core */
-#include "inspstring.h"
+#include "inspircd.h"
/*
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
#include "modes/umode_s.h"
ModeHandler::ModeHandler(Module* Creator, const std::string& Name, char modeletter, ParamSpec Params, ModeType type)
- : m_paramtype(TR_TEXT), parameters_taken(Params), mode(modeletter), prefix(0), oper(false),
- list(false), m_type(type), count(0), levelrequired(HALFOP_VALUE), creator(Creator), name(Name)
+ : providerbase(Creator, Name, type == MODETYPE_CHANNEL ? SERVICE_CMODE : SERVICE_UMODE), m_paramtype(TR_TEXT),
+ parameters_taken(Params), mode(modeletter), prefix(0), oper(false),
+ list(false), m_type(type), count(0), levelrequired(HALFOP_VALUE)
{
}
{
if (!this->Parser->AddCommand(f))
{
- throw ModuleException("Command "+std::string(f->command)+" already exists.");
+ throw ModuleException("Command "+std::string(f->name)+" already exists.");
+ }
+}
+
+void InspIRCd::AddService(providerbase& item)
+{
+ switch (item.service)
+ {
+ case SERVICE_COMMAND:
+ if (!Parser->AddCommand(static_cast<Command*>(&item)))
+ throw ModuleException("Command "+std::string(item.name)+" already exists.");
+ return;
+ case SERVICE_CMODE:
+ case SERVICE_UMODE:
+ if (!Modes->AddMode(static_cast<ModeHandler*>(&item)))
+ throw ModuleException("Mode "+std::string(item.name)+" already exists.");
+ return;
+ case SERVICE_METADATA:
+ Extensions.Register(static_cast<ExtensionItem*>(&item));
+ return;
+ case SERVICE_DATA:
+ case SERVICE_IOHOOK:
+ default:
+ throw ModuleException("Cannot add unknown service type");
}
}
ExtensionItem* item = i->first;
std::string value = item->serialize(FORMAT_USER, ext, i->second);
if (!value.empty())
- user->SendText(checkstr + " meta:" + item->key + " " + value);
- else if (!item->key.empty())
- dumpkeys << " " << item->key;
+ user->SendText(checkstr + " meta:" + item->name + " " + value);
+ else if (!item->name.empty())
+ dumpkeys << " " << item->name;
}
if (!dumpkeys.str().empty())
user->SendText(checkstr + " metadata", dumpkeys);
ConfigReader Conf;
for (int i=0; i<Conf.Enumerate("title"); i++)
{
- std::string name = Conf.ReadValue("title", "name", "", i);
+ std::string Name = Conf.ReadValue("title", "name", "", i);
std::string pass = Conf.ReadValue("title", "password", "", i);
std::string hash = Conf.ReadValue("title", "hash", "", i);
std::string host = Conf.ReadValue("title", "host", "*@*", i);
std::string title = Conf.ReadValue("title", "title", "", i);
std::string vhost = Conf.ReadValue("title", "vhost", "", i);
- if (!strcmp(name.c_str(),parameters[0].c_str()) && !ServerInstance->PassCompare(user, pass.c_str(), parameters[1].c_str(), hash.c_str()) && OneOfMatches(TheHost,TheIP,host.c_str()) && !title.empty())
+ if (!strcmp(Name.c_str(),parameters[0].c_str()) && !ServerInstance->PassCompare(user, pass.c_str(), parameters[1].c_str(), hash.c_str()) && OneOfMatches(TheHost,TheIP,host.c_str()) && !title.empty())
{
ctitle.set(user, title);
ExtensionItem* item = i->first;
std::string value = item->serialize(FORMAT_USER, ext, i->second);
if (!value.empty())
- data << "<meta name=\"" << item->key << "\">" << Sanitize(value) << "</meta>";
- else if (!item->key.empty())
- data << "<meta name=\"" << item->key << "\"/>";
+ data << "<meta name=\"" << item->name << "\">" << Sanitize(value) << "</meta>";
+ else if (!item->name.empty())
+ data << "<meta name=\"" << item->name << "\"/>";
}
data << "</metadata>";
}
Implementation eventlist[] = { I_OnEvent, I_OnUserRegister };
ServerInstance->Modules->Attach(eventlist, this, 2);
- ServerInstance->AddCommand(&auth);
- ServerInstance->AddCommand(&sasl);
+ providerbase* providelist[] = { &auth, &sasl, &authExt };
+ ServerInstance->AddServices(providelist, 3);
- ServerInstance->Extensions.Register(&authExt);
if (!ServerInstance->Modules->Find("m_services_account.so") || !ServerInstance->Modules->Find("m_cap.so"))
ServerInstance->Logs->Log("m_sasl", DEFAULT, "WARNING: m_services_account.so and m_cap.so are not loaded! m_sasl.so will NOT function correctly until these two modules are loaded!");
}
ExtensionItem* item = i->first;
std::string value = item->serialize(FORMAT_NETWORK, user, i->second);
if (!value.empty())
- ServerInstance->PI->SendMetaData(user, item->key, value);
+ ServerInstance->PI->SendMetaData(user, item->name, value);
}
Utils->TreeRoot->SetUserCount(1); // increment by 1
ExtensionItem* item = i->first;
std::string value = item->serialize(FORMAT_NETWORK, c->second, i->second);
if (!value.empty())
- Utils->Creator->ProtoSendMetaData(this, c->second, item->key, value);
+ Utils->Creator->ProtoSendMetaData(this, c->second, item->name, value);
}
FOREACH_MOD(I_OnSyncChannel,OnSyncChannel(c->second,Utils->Creator,this));
ExtensionItem* item = i->first;
std::string value = item->serialize(FORMAT_NETWORK, u->second, i->second);
if (!value.empty())
- Utils->Creator->ProtoSendMetaData(this, u->second, item->key, value);
+ Utils->Creator->ProtoSendMetaData(this, u->second, item->name, value);
}
FOREACH_MOD(I_OnSyncUser,OnSyncUser(u->second,Utils->Creator,this));
if (i->second->use_count)
{
/* RPL_STATSCOMMANDS */
- results.push_back(sn+" 212 "+user->nick+" "+i->second->command+" "+ConvToStr(i->second->use_count)+" "+ConvToStr(i->second->total_bytes));
+ results.push_back(sn+" 212 "+user->nick+" "+i->second->name+" "+ConvToStr(i->second->use_count)+" "+ConvToStr(i->second->total_bytes));
}
}
break;