From c63aeb44e9aa55070639cba2097e7a20a5db67db Mon Sep 17 00:00:00 2001 From: Elizabeth Myers Date: Sun, 6 Mar 2016 17:52:49 -0600 Subject: [PATCH] modules: add origin field to V2 --- extensions/m_remove.c | 2 +- include/modules.h | 11 +++++++++-- ircd/modules.c | 29 +++++++++++++++++++++++++---- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/extensions/m_remove.c b/extensions/m_remove.c index 35d70edc..4d6e74d7 100644 --- a/extensions/m_remove.c +++ b/extensions/m_remove.c @@ -62,7 +62,7 @@ mapi_cap_list_av2 remove_cap_list[] = { const char description[] = "Provides the REMOVE command, an alternative to KICK"; -DECLARE_MODULE_AV2(remove, NULL, NULL, remove_clist, NULL, remove_hfnlist, remove_cap_list, NULL, description); +DECLARE_MODULE_AV2(remove, MAPI_ORIGIN_EXTENSION, NULL, NULL, remove_clist, NULL, remove_hfnlist, remove_cap_list, NULL, description); static int m_remove(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) diff --git a/include/modules.h b/include/modules.h index b4042d16..1a6e0a61 100644 --- a/include/modules.h +++ b/include/modules.h @@ -42,6 +42,7 @@ struct module const char *description; lt_dlhandle address; int core; + int origin; int mapi_version; void *mapi_header; /* actually struct mapi_mheader_av */ }; @@ -91,9 +92,15 @@ struct mapi_mheader_av1 const char *mapi_module_version; /* Module's version (freeform) */ }; +#define MAPI_ORIGIN_UNKNOWN 0 /* Unknown provenance (AV1 etc.) */ +#define MAPI_ORIGIN_EXTERNAL 1 /* Came from outside charybdis */ +#define MAPI_ORIGIN_EXTENSION 2 /* Charybdis bundled extension */ +#define MAPI_ORIGIN_CORE 3 /* Charybdis core module */ + struct mapi_mheader_av2 { int mapi_version; /* Module API version */ + int mapi_origin; /* Module provenance */ int (*mapi_register)(void); /* Register function; ret -1 = failure (unload) */ void (*mapi_unregister)(void); /* Unregister function. */ mapi_clist_av1 *mapi_command_list; /* List of commands to add. */ @@ -107,8 +114,8 @@ struct mapi_mheader_av2 #define DECLARE_MODULE_AV1(name, reg, unreg, cl, hl, hfnlist, v) \ struct mapi_mheader_av1 _mheader = { MAPI_V1, reg, unreg, cl, hl, hfnlist, v} -#define DECLARE_MODULE_AV2(name, reg, unreg, cl, hl, hfnlist, caplist, v, desc) \ - struct mapi_mheader_av2 _mheader = { MAPI_V2, reg, unreg, cl, hl, hfnlist, caplist, v, desc} +#define DECLARE_MODULE_AV2(name, origin, reg, unreg, cl, hl, hfnlist, caplist, v, desc) \ + struct mapi_mheader_av2 _mheader = { MAPI_V2, origin, reg, unreg, cl, hl, hfnlist, caplist, v, desc} /* add a path */ void mod_add_path(const char *path); diff --git a/ircd/modules.c b/ircd/modules.c index 5b00ed17..4501c1ff 100644 --- a/ircd/modules.c +++ b/ircd/modules.c @@ -791,6 +791,7 @@ load_a_module(const char *path, int warn, int core) lt_dlhandle tmpptr; char *mod_basename; const char *ver, *description = NULL; + int origin = 0; int *mapi_version; @@ -910,6 +911,7 @@ load_a_module(const char *path, int warn, int core) /* 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) { @@ -972,16 +974,35 @@ load_a_module(const char *path, int warn, int 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; description: \"%s\"] loaded at 0x%lx", - mod_basename, ver, MAPI_VERSION(*mapi_version), description, + "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; description: \"%s\"] loaded at 0x%lx", - mod_basename, ver, MAPI_VERSION(*mapi_version), description, (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;