* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
- *
- * $Id: modules.c 3161 2007-01-25 07:23:01Z nenolod $
*/
#include "stdinc.h"
#include "ircd_defs.h"
#include "match.h"
#include "s_serv.h"
+#include "capability.h"
#include <ltdl.h>
static rb_dlink_list mod_paths;
-static int mo_modload(struct Client *, struct Client *, int, const char **);
-static int mo_modlist(struct Client *, struct Client *, int, const char **);
-static int mo_modreload(struct Client *, struct Client *, int, const char **);
-static int mo_modunload(struct Client *, struct Client *, int, const char **);
-static int mo_modrestart(struct Client *, struct Client *, int, const char **);
+static int mo_modload(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static int mo_modlist(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static int mo_modreload(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static int mo_modunload(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static int mo_modrestart(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
-static int me_modload(struct Client *, struct Client *, int, const char **);
-static int me_modlist(struct Client *, struct Client *, int, const char **);
-static int me_modreload(struct Client *, struct Client *, int, const char **);
-static int me_modunload(struct Client *, struct Client *, int, const char **);
-static int me_modrestart(struct Client *, struct Client *, int, const char **);
+static int me_modload(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static int me_modlist(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static int me_modreload(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static int me_modunload(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static int me_modrestart(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
static int do_modload(struct Client *, const char *);
static int do_modunload(struct Client *, const char *);
static int do_modrestart(struct Client *);
struct Message modload_msgtab = {
- "MODLOAD", 0, 0, 0, MFLG_SLOW,
+ "MODLOAD", 0, 0, 0, 0,
{mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_modload, 2}, {mo_modload, 2}}
};
struct Message modunload_msgtab = {
- "MODUNLOAD", 0, 0, 0, MFLG_SLOW,
+ "MODUNLOAD", 0, 0, 0, 0,
{mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_modunload, 2}, {mo_modunload, 2}}
};
struct Message modreload_msgtab = {
- "MODRELOAD", 0, 0, 0, MFLG_SLOW,
+ "MODRELOAD", 0, 0, 0, 0,
{mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_modreload, 2}, {mo_modreload, 2}}
};
struct Message modlist_msgtab = {
- "MODLIST", 0, 0, 0, MFLG_SLOW,
+ "MODLIST", 0, 0, 0, 0,
{mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_modlist, 0}, {mo_modlist, 0}}
};
struct Message modrestart_msgtab = {
- "MODRESTART", 0, 0, 0, MFLG_SLOW,
+ "MODRESTART", 0, 0, 0, 0,
{mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_modrestart, 0}, {mo_modrestart, 0}}
};
/* load a module .. */
static int
-mo_modload(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
+mo_modload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
{
if(!IsOperAdmin(source_p))
{
}
static int
-me_modload(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
+me_modload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
{
if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE))
{
/* unload a module .. */
static int
-mo_modunload(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
+mo_modunload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
{
if(!IsOperAdmin(source_p))
{
}
static int
-me_modunload(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
+me_modunload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
{
if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE))
{
/* unload and load in one! */
static int
-mo_modreload(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
+mo_modreload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
{
if(!IsOperAdmin(source_p))
{
}
static int
-me_modreload(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
+me_modreload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
{
if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE))
{
/* list modules .. */
static int
-mo_modlist(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
+mo_modlist(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
{
if(!IsOperAdmin(source_p))
{
}
static int
-me_modlist(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
+me_modlist(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
{
if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE))
{
me.name, source_p->name,
modlist[i]->name,
(unsigned long)(uintptr_t)modlist[i]->address,
- modlist[i]->version, modlist[i]->core ? "(core)" : "");
+ modlist[i]->version, modlist[i]->description, modlist[i]->core ? " (core)" : "");
}
}
else
{
sendto_one(source_p, form_str(RPL_MODLIST),
me.name, source_p->name, modlist[i]->name,
- (unsigned long)(uintptr_t)modlist[i]->address, modlist[i]->version,
- modlist[i]->core ? "(core)" : "");
+ (unsigned long)(uintptr_t)modlist[i]->address,
+ modlist[i]->version, modlist[i]->description, modlist[i]->core ? " (core)" : "");
}
}
/* unload and reload all modules */
static int
-mo_modrestart(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
+mo_modrestart(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
{
if(!IsOperAdmin(source_p))
{
}
static int
-me_modrestart(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
+me_modrestart(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
{
if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE))
{
#define MODS_INCREMENT 10
static char unknown_ver[] = "<unknown>";
+static char unknown_description[] = "<none>";
/* unload_one_module()
*
mheader->mapi_unregister();
break;
}
+ case 2:
+ {
+ struct mapi_mheader_av2 *mheader = modlist[modindex]->mapi_header;
+
+ /* XXX duplicate code :( */
+ if(mheader->mapi_command_list)
+ {
+ struct Message **m;
+ for (m = mheader->mapi_command_list; *m; ++m)
+ mod_del_cmd(*m);
+ }
+
+ /* hook events are never removed, we simply lose the
+ * ability to call them --fl
+ */
+ if(mheader->mapi_hfn_list)
+ {
+ mapi_hfn_list_av1 *m;
+ for (m = mheader->mapi_hfn_list; m->hapi_name; ++m)
+ remove_hook(m->hapi_name, m->fn);
+ }
+
+ if(mheader->mapi_unregister)
+ mheader->mapi_unregister();
+
+ if(mheader->mapi_cap_list)
+ {
+ mapi_cap_list_av2 *m;
+ for (m = mheader->mapi_cap_list; m->cap_name; ++m)
+ {
+ struct CapabilityIndex *idx;
+
+ switch(m->cap_index)
+ {
+ case MAPI_CAP_CLIENT:
+ idx = cli_capindex;
+ break;
+ case MAPI_CAP_SERVER:
+ idx = serv_capindex;
+ break;
+ default:
+ sendto_realops_snomask(SNO_GENERAL, L_ALL,
+ "Unknown/unsupported CAP index found of type %d on capability %s when unloading %s",
+ m->cap_index, m->cap_name, modlist[modindex]->name);
+ ilog(L_MAIN,
+ "Unknown/unsupported CAP index found of type %d on capability %s when unloading %s",
+ m->cap_index, m->cap_name, modlist[modindex]->name);
+ continue;
+ }
+
+ capability_orphan(idx, m->cap_name);
+ }
+ }
+ }
default:
sendto_realops_snomask(SNO_GENERAL, L_ALL,
"Unknown/unsupported MAPI version %d when unloading %s!",
{
lt_dlhandle tmpptr;
char *mod_basename;
- const char *ver;
+ const char *ver, *description = NULL;
+ int origin = 0;
int *mapi_version;
ver = mheader->mapi_module_version;
break;
}
+ case 2:
+ {
+ struct mapi_mheader_av2 *mheader = (struct mapi_mheader_av2 *)(void *)mapi_version; /* see above */
+
+ /* XXX duplicated code :( */
+ if(mheader->mapi_register && (mheader->mapi_register() == -1))
+ {
+ ilog(L_MAIN, "Module %s indicated failure during load.",
+ mod_basename);
+ sendto_realops_snomask(SNO_GENERAL, L_ALL,
+ "Module %s indicated failure during load.",
+ mod_basename);
+ lt_dlclose(tmpptr);
+ rb_free(mod_basename);
+ return -1;
+ }
+ if(mheader->mapi_command_list)
+ {
+ struct Message **m;
+ for (m = mheader->mapi_command_list; *m; ++m)
+ mod_add_cmd(*m);
+ }
+
+ if(mheader->mapi_hook_list)
+ {
+ mapi_hlist_av1 *m;
+ for (m = mheader->mapi_hook_list; m->hapi_name; ++m)
+ *m->hapi_id = register_hook(m->hapi_name);
+ }
+
+ if(mheader->mapi_hfn_list)
+ {
+ mapi_hfn_list_av1 *m;
+ for (m = mheader->mapi_hfn_list; m->hapi_name; ++m)
+ add_hook(m->hapi_name, m->fn);
+ }
+
+ /* New in MAPI v2 - version replacement */
+ ver = mheader->mapi_module_version ? mheader->mapi_module_version : ircd_version;
+ description = mheader->mapi_module_description;
+ origin = mheader->mapi_origin;
+
+ if(mheader->mapi_cap_list)
+ {
+ mapi_cap_list_av2 *m;
+ for (m = mheader->mapi_cap_list; m->cap_name; ++m)
+ {
+ struct CapabilityIndex *idx;
+ int result;
+
+ switch(m->cap_index)
+ {
+ case MAPI_CAP_CLIENT:
+ idx = cli_capindex;
+ break;
+ case MAPI_CAP_SERVER:
+ idx = serv_capindex;
+ break;
+ default:
+ sendto_realops_snomask(SNO_GENERAL, L_ALL,
+ "Unknown/unsupported CAP index found of type %d on capability %s when loading %s",
+ m->cap_index, m->cap_name, mod_basename);
+ ilog(L_MAIN,
+ "Unknown/unsupported CAP index found of type %d on capability %s when loading %s",
+ m->cap_index, m->cap_name, mod_basename);
+ continue;
+ }
+
+ result = capability_put(idx, m->cap_name, m->cap_ownerdata);
+ if (m->cap_id != NULL)
+ *(m->cap_id) = result;
+ }
+ }
+ }
+ break;
default:
ilog(L_MAIN, "Module %s has unknown/unsupported MAPI version %d.",
mod_basename, MAPI_VERSION(*mapi_version));
if(ver == NULL)
ver = unknown_ver;
+ if(description == NULL)
+ description = unknown_description;
+
increase_modlist();
modlist[num_mods] = rb_malloc(sizeof(struct module));
modlist[num_mods]->address = tmpptr;
modlist[num_mods]->version = ver;
+ modlist[num_mods]->description = description;
modlist[num_mods]->core = core;
modlist[num_mods]->name = rb_strdup(mod_basename);
modlist[num_mods]->mapi_header = mapi_version;
modlist[num_mods]->mapi_version = MAPI_VERSION(*mapi_version);
+ modlist[num_mods]->origin = origin;
num_mods++;
if(warn == 1)
{
+ const char *o;
+
+ switch(origin)
+ {
+ case MAPI_ORIGIN_EXTERNAL:
+ o = "external";
+ break;
+ case MAPI_ORIGIN_EXTENSION:
+ o = "extension";
+ break;
+ case MAPI_ORIGIN_CORE:
+ o = "core";
+ break;
+ default:
+ o = "unknown";
+ break;
+ }
+
sendto_realops_snomask(SNO_GENERAL, L_ALL,
- "Module %s [version: %s; MAPI version: %d] loaded at 0x%lx",
- mod_basename, ver, MAPI_VERSION(*mapi_version),
+ "Module %s [version: %s; MAPI version: %d; origin: %s; description: \"%s\"] loaded at 0x%lx",
+ mod_basename, ver, MAPI_VERSION(*mapi_version), o, description,
(unsigned long) tmpptr);
- ilog(L_MAIN, "Module %s [version: %s; MAPI version: %d] loaded at 0x%lx",
- mod_basename, ver, MAPI_VERSION(*mapi_version), (unsigned long) tmpptr);
+ ilog(L_MAIN, "Module %s [version: %s; MAPI version: %d; origin: %s; description: \"%s\"] loaded at 0x%lx",
+ mod_basename, ver, MAPI_VERSION(*mapi_version), o, description, (unsigned long) tmpptr);
}
rb_free(mod_basename);
return 0;