2007-01-25 07:40:21 +01:00
|
|
|
/*
|
|
|
|
* ircd-ratbox: A slightly useful ircd.
|
|
|
|
* modules.c: A module loader.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
|
|
|
|
* Copyright (C) 1996-2002 Hybrid Development Team
|
|
|
|
* Copyright (C) 2002-2005 ircd-ratbox development team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA
|
|
|
|
*/
|
|
|
|
|
2016-07-01 05:04:00 +02:00
|
|
|
#include <ircd/stdinc.h>
|
|
|
|
#include <ircd/modules.h>
|
|
|
|
#include <ircd/logger.h>
|
|
|
|
#include <ircd/ircd.h>
|
|
|
|
#include <ircd/client.h>
|
|
|
|
#include <ircd/send.h>
|
|
|
|
#include <ircd/s_conf.h>
|
|
|
|
#include <ircd/s_newconf.h>
|
|
|
|
#include <ircd/numeric.h>
|
|
|
|
#include <ircd/parse.h>
|
|
|
|
#include <ircd/match.h>
|
|
|
|
#include <ircd/s_serv.h>
|
|
|
|
#include <ircd/capability.h>
|
2016-01-06 04:39:09 +01:00
|
|
|
#include <ltdl.h>
|
|
|
|
|
2016-03-13 03:10:46 +01:00
|
|
|
#ifndef LT_MODULE_EXT
|
|
|
|
# error "Charybdis requires loadable module support."
|
|
|
|
#endif
|
|
|
|
|
2016-06-18 07:52:16 +02:00
|
|
|
rb_dlink_list module_list;
|
|
|
|
rb_dlink_list mod_paths;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
static const char *core_module_table[] = {
|
2010-03-05 18:36:44 +01:00
|
|
|
"m_ban",
|
2007-01-25 07:40:21 +01:00
|
|
|
"m_die",
|
|
|
|
"m_error",
|
|
|
|
"m_join",
|
|
|
|
"m_kick",
|
|
|
|
"m_kill",
|
|
|
|
"m_message",
|
|
|
|
"m_mode",
|
2016-04-07 11:00:25 +02:00
|
|
|
"m_modules",
|
2007-01-25 07:40:21 +01:00
|
|
|
"m_nick",
|
|
|
|
"m_part",
|
|
|
|
"m_quit",
|
|
|
|
"m_server",
|
|
|
|
"m_squit",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2016-03-08 01:10:22 +01:00
|
|
|
#define MOD_WARN_DELTA (90 * 86400) /* time in seconds, 86400 seconds in a day */
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
void
|
2016-06-18 07:38:40 +02:00
|
|
|
init_modules(void)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-01-06 04:39:09 +01:00
|
|
|
if(lt_dlinit())
|
|
|
|
{
|
|
|
|
ilog(L_MAIN, "lt_dlinit failed");
|
2016-04-25 23:27:57 +02:00
|
|
|
exit(EXIT_FAILURE);
|
2016-01-06 04:39:09 +01:00
|
|
|
}
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
/* Add the default paths we look in to the module system --nenolod */
|
2016-03-25 00:45:28 +01:00
|
|
|
mod_add_path(ircd_paths[IRCD_PATH_MODULES]);
|
|
|
|
mod_add_path(ircd_paths[IRCD_PATH_AUTOLOAD_MODULES]);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* mod_find_path()
|
|
|
|
*
|
|
|
|
* input - path
|
|
|
|
* output - none
|
|
|
|
* side effects - returns a module path from path
|
|
|
|
*/
|
2014-02-23 23:47:27 +01:00
|
|
|
static char *
|
2007-01-25 07:40:21 +01:00
|
|
|
mod_find_path(const char *path)
|
|
|
|
{
|
2008-04-01 22:41:52 +02:00
|
|
|
rb_dlink_node *ptr;
|
2014-02-23 23:47:27 +01:00
|
|
|
char *mpath;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2008-04-01 22:43:10 +02:00
|
|
|
RB_DLINK_FOREACH(ptr, mod_paths.head)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-07-13 07:17:21 +02:00
|
|
|
mpath = (char *)ptr->data;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2014-02-23 23:47:27 +01:00
|
|
|
if(!strcmp(path, mpath))
|
2007-01-25 07:40:21 +01:00
|
|
|
return mpath;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* mod_add_path
|
|
|
|
*
|
|
|
|
* input - path
|
2014-03-03 05:25:47 +01:00
|
|
|
* ouput -
|
2007-01-25 07:40:21 +01:00
|
|
|
* side effects - adds path to list
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
mod_add_path(const char *path)
|
|
|
|
{
|
2014-02-23 23:47:27 +01:00
|
|
|
char *pathst;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
if(mod_find_path(path))
|
|
|
|
return;
|
|
|
|
|
2014-02-23 23:47:27 +01:00
|
|
|
pathst = rb_strdup(path);
|
2008-04-01 22:41:52 +02:00
|
|
|
rb_dlinkAddAlloc(pathst, &mod_paths);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* mod_clear_paths()
|
|
|
|
*
|
|
|
|
* input -
|
|
|
|
* output -
|
|
|
|
* side effects - clear the lists of paths
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
mod_clear_paths(void)
|
|
|
|
{
|
2008-04-02 00:47:17 +02:00
|
|
|
rb_dlink_node *ptr, *next_ptr;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2008-04-02 00:47:17 +02:00
|
|
|
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, mod_paths.head)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2008-04-02 00:47:17 +02:00
|
|
|
rb_free(ptr->data);
|
2008-04-02 03:03:13 +02:00
|
|
|
rb_free_rb_dlink_node(ptr);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
mod_paths.head = mod_paths.tail = NULL;
|
|
|
|
mod_paths.length = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* findmodule_byname
|
|
|
|
*
|
2016-04-03 08:51:26 +02:00
|
|
|
* input - module to load
|
|
|
|
* output - index of module on success, -1 on failure
|
|
|
|
* side effects - none
|
2007-01-25 07:40:21 +01:00
|
|
|
*/
|
2016-06-18 07:52:16 +02:00
|
|
|
struct module *
|
2007-01-25 07:40:21 +01:00
|
|
|
findmodule_byname(const char *name)
|
|
|
|
{
|
2016-06-18 07:52:16 +02:00
|
|
|
rb_dlink_node *ptr;
|
2016-03-20 12:00:20 +01:00
|
|
|
char name_ext[PATH_MAX + 1];
|
|
|
|
|
2016-03-20 12:01:12 +01:00
|
|
|
rb_strlcpy(name_ext, name, sizeof name_ext);
|
|
|
|
rb_strlcat(name_ext, LT_MODULE_EXT, sizeof name_ext);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-06-18 07:52:16 +02:00
|
|
|
RB_DLINK_FOREACH(ptr, module_list.head)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-07-13 07:17:21 +02:00
|
|
|
struct module *mod = (struct module *)ptr->data;
|
2016-06-18 07:52:16 +02:00
|
|
|
|
|
|
|
if(!irccmp(mod->name, name))
|
|
|
|
return mod;
|
2016-03-20 12:00:20 +01:00
|
|
|
|
2016-06-18 07:52:16 +02:00
|
|
|
if(!irccmp(mod->name, name_ext))
|
|
|
|
return mod;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
2016-03-20 12:00:20 +01:00
|
|
|
|
2016-06-18 07:52:16 +02:00
|
|
|
return NULL;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* load_all_modules()
|
|
|
|
*
|
|
|
|
* input -
|
|
|
|
* output -
|
|
|
|
* side effects -
|
|
|
|
*/
|
|
|
|
void
|
2016-04-03 08:51:26 +02:00
|
|
|
load_all_modules(bool warn)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
DIR *system_module_dir = NULL;
|
|
|
|
struct dirent *ldirent = NULL;
|
|
|
|
char module_fq_name[PATH_MAX + 1];
|
2016-03-18 21:32:33 +01:00
|
|
|
size_t module_ext_len = strlen(LT_MODULE_EXT);
|
|
|
|
|
2016-03-25 00:45:28 +01:00
|
|
|
system_module_dir = opendir(ircd_paths[IRCD_PATH_AUTOLOAD_MODULES]);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
if(system_module_dir == NULL)
|
|
|
|
{
|
2016-03-25 00:45:28 +01:00
|
|
|
ilog(L_MAIN, "Could not load modules from %s: %s", ircd_paths[IRCD_PATH_AUTOLOAD_MODULES], strerror(errno));
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((ldirent = readdir(system_module_dir)) != NULL)
|
|
|
|
{
|
2016-04-03 08:21:06 +02:00
|
|
|
size_t len = strlen(ldirent->d_name);
|
2016-03-13 03:10:46 +01:00
|
|
|
|
2016-04-03 08:21:06 +02:00
|
|
|
if(len > module_ext_len &&
|
2016-04-05 12:39:59 +02:00
|
|
|
rb_strncasecmp(ldirent->d_name + (len - module_ext_len), LT_MODULE_EXT, module_ext_len) == 0)
|
2016-02-10 02:25:32 +01:00
|
|
|
{
|
2016-04-03 08:21:06 +02:00
|
|
|
(void) snprintf(module_fq_name, sizeof(module_fq_name), "%s%c%s",
|
|
|
|
ircd_paths[IRCD_PATH_AUTOLOAD_MODULES], RB_PATH_SEPARATOR, ldirent->d_name);
|
2016-04-03 08:51:26 +02:00
|
|
|
(void) load_a_module(module_fq_name, warn, MAPI_ORIGIN_CORE, false);
|
2016-02-10 02:25:32 +01:00
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
(void) closedir(system_module_dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* load_core_modules()
|
|
|
|
*
|
|
|
|
* input -
|
|
|
|
* output -
|
|
|
|
* side effects - core modules are loaded, if any fail, kill ircd
|
|
|
|
*/
|
|
|
|
void
|
2016-04-03 08:51:26 +02:00
|
|
|
load_core_modules(bool warn)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2011-10-28 16:45:18 +02:00
|
|
|
char module_name[PATH_MAX];
|
2007-01-25 07:40:21 +01:00
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; core_module_table[i]; i++)
|
|
|
|
{
|
2016-04-03 08:51:26 +02:00
|
|
|
snprintf(module_name, sizeof(module_name), "%s%c%s", ircd_paths[IRCD_PATH_MODULES], RB_PATH_SEPARATOR,
|
|
|
|
core_module_table[i]);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-04-03 08:51:26 +02:00
|
|
|
if(load_a_module(module_name, warn, MAPI_ORIGIN_CORE, true) == false)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
ilog(L_MAIN,
|
2016-03-13 03:10:46 +01:00
|
|
|
"Error loading core module %s: terminating ircd",
|
|
|
|
core_module_table[i]);
|
2016-07-13 07:17:21 +02:00
|
|
|
|
|
|
|
fprintf(stderr,
|
|
|
|
"Error loading core module %s (%s): terminating ircd\n",
|
|
|
|
core_module_table[i],
|
|
|
|
module_name);
|
|
|
|
|
2016-04-25 23:27:57 +02:00
|
|
|
exit(EXIT_FAILURE);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* load_one_module()
|
|
|
|
*
|
|
|
|
* input -
|
|
|
|
* output -
|
|
|
|
* side effects -
|
|
|
|
*/
|
2016-04-03 08:51:26 +02:00
|
|
|
bool
|
|
|
|
load_one_module(const char *path, int origin, bool coremodule)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2011-10-28 16:45:18 +02:00
|
|
|
char modpath[PATH_MAX];
|
2008-04-01 22:41:52 +02:00
|
|
|
rb_dlink_node *pathst;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-03-09 09:19:31 +01:00
|
|
|
if (server_state_foreground)
|
2014-03-03 05:25:47 +01:00
|
|
|
inotice("loading module %s ...", path);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-04-03 08:51:26 +02:00
|
|
|
if(coremodule)
|
2016-03-07 01:56:45 +01:00
|
|
|
origin = MAPI_ORIGIN_CORE;
|
|
|
|
|
2008-04-01 22:43:10 +02:00
|
|
|
RB_DLINK_FOREACH(pathst, mod_paths.head)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-04-03 08:51:26 +02:00
|
|
|
struct stat statbuf;
|
2016-07-13 07:17:21 +02:00
|
|
|
const char *mpath = (const char *)pathst->data;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-04-03 08:51:26 +02:00
|
|
|
snprintf(modpath, sizeof(modpath), "%s%c%s%s", mpath, RB_PATH_SEPARATOR, path, LT_MODULE_EXT);
|
2007-01-25 07:40:21 +01:00
|
|
|
if((strstr(modpath, "../") == NULL) && (strstr(modpath, "/..") == NULL))
|
|
|
|
{
|
2016-04-03 08:51:26 +02:00
|
|
|
if(stat(modpath, &statbuf) == 0 && S_ISREG(statbuf.st_mode))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-04-03 08:51:26 +02:00
|
|
|
/* Regular files only please */
|
|
|
|
return load_a_module(modpath, true, origin, coremodule);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_ALL, "Cannot locate module %s", path);
|
2016-04-03 08:51:26 +02:00
|
|
|
return false;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
void module_log(struct module *const mod,
|
|
|
|
const char *const fmt,
|
|
|
|
...)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
char buf[BUFSIZE];
|
|
|
|
vsnprintf(buf, sizeof(buf), fmt, ap),
|
|
|
|
slog(L_MAIN, SNO_GENERAL, "Module %s: %s", mod->name, buf);
|
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ******************************************************************************
|
|
|
|
// INTERNAL API STACK
|
|
|
|
// driven by load_a_module() / unload_one_module() (bottom)
|
|
|
|
|
|
|
|
static
|
|
|
|
bool init_module_v1(struct module *const mod)
|
|
|
|
{
|
|
|
|
struct mapi_mheader_av1 *mheader = (struct mapi_mheader_av1 *)mod->mapi_header;
|
|
|
|
if(mheader->mapi_register && (mheader->mapi_register() == -1))
|
2016-04-03 08:51:26 +02:00
|
|
|
return false;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
mod->version = mheader->mapi_module_version;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
void fini_module_v1(struct module *const mod)
|
|
|
|
{
|
2016-07-13 07:17:21 +02:00
|
|
|
struct mapi_mheader_av1 *mheader = (mapi_mheader_av1 *)mod->mapi_header;
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
bool init_module__cap(struct module *const mod,
|
|
|
|
mapi_cap_list_av2 *const 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:
|
|
|
|
slog(L_MAIN, SNO_GENERAL,
|
|
|
|
"Unknown/unsupported CAP index found of type %d on capability %s when loading %s",
|
|
|
|
m->cap_index,
|
|
|
|
m->cap_name,
|
|
|
|
mod->name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(m->cap_id)
|
|
|
|
{
|
|
|
|
*(m->cap_id) = capability_put(idx, m->cap_name, m->cap_ownerdata);
|
|
|
|
sendto_local_clients_with_capability(CLICAP_CAP_NOTIFY, ":%s CAP * ADD :%s", me.name, m->cap_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
void fini_module__cap(struct module *const mod,
|
|
|
|
mapi_cap_list_av2 *const 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:
|
|
|
|
slog(L_MAIN, SNO_GENERAL,
|
|
|
|
"Unknown/unsupported CAP index found of type %d on capability %s when unloading %s",
|
|
|
|
m->cap_index,
|
|
|
|
m->cap_name,
|
|
|
|
mod->name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(m->cap_id)
|
|
|
|
{
|
|
|
|
capability_orphan(idx, m->cap_name);
|
|
|
|
sendto_local_clients_with_capability(CLICAP_CAP_NOTIFY, ":%s CAP * DEL :%s", me.name, m->cap_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
bool init_module_v2(struct module *const mod)
|
|
|
|
{
|
|
|
|
struct mapi_mheader_av2 *mheader = (struct mapi_mheader_av2 *)mod->mapi_header;
|
|
|
|
if(mheader->mapi_register && (mheader->mapi_register() == -1))
|
2016-06-22 02:39:44 +02:00
|
|
|
return false;
|
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
/* Basic date code checks
|
|
|
|
*
|
|
|
|
* Don't make them fatal, but do complain about differences within a certain time frame.
|
|
|
|
* Later on if there are major API changes we can add fatal checks.
|
|
|
|
* -- Elizafox
|
2007-01-25 07:40:21 +01:00
|
|
|
*/
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
if(mheader->mapi_datecode != datecode && mheader->mapi_datecode > 0)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
long int delta = datecode - mheader->mapi_datecode;
|
|
|
|
if (delta > MOD_WARN_DELTA)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
delta /= 86400;
|
|
|
|
iwarn("Module %s build date is out of sync with ircd build date by %ld days, expect problems",
|
|
|
|
mod->name, delta);
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
|
|
|
"Module %s build date is out of sync with ircd build date by %ld days, expect problems",
|
|
|
|
mod->name, delta);
|
|
|
|
}
|
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
if(mheader->mapi_command_list)
|
|
|
|
{
|
|
|
|
struct Message **m;
|
|
|
|
for (m = mheader->mapi_command_list; *m; ++m)
|
|
|
|
mod_add_cmd(*m);
|
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
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);
|
|
|
|
}
|
2016-03-06 23:53:03 +01:00
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
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);
|
|
|
|
}
|
2016-03-06 23:53:03 +01:00
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
/* New in MAPI v2 - version replacement */
|
|
|
|
mod->version = mheader->mapi_module_version? mheader->mapi_module_version : ircd_version;
|
|
|
|
mod->description = mheader->mapi_module_description;
|
2016-03-06 23:53:03 +01:00
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
if(mheader->mapi_cap_list)
|
|
|
|
{
|
|
|
|
mapi_cap_list_av2 *m;
|
|
|
|
for (m = mheader->mapi_cap_list; m->cap_name; ++m)
|
|
|
|
if(!init_module__cap(mod, m))
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-06 23:53:03 +01:00
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
void fini_module_v2(struct module *const mod)
|
|
|
|
{
|
|
|
|
struct mapi_mheader_av2 *mheader = (struct mapi_mheader_av2 *)mod->mapi_header;
|
|
|
|
|
|
|
|
if(mheader->mapi_command_list)
|
|
|
|
{
|
|
|
|
struct Message **m;
|
|
|
|
for (m = mheader->mapi_command_list; *m; ++m)
|
|
|
|
mod_del_cmd(*m);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
/* 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);
|
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
if(mheader->mapi_unregister)
|
|
|
|
mheader->mapi_unregister();
|
2007-01-25 07:40:21 +01:00
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
if(mheader->mapi_cap_list)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
mapi_cap_list_av2 *m;
|
|
|
|
for (m = mheader->mapi_cap_list; m->cap_name; ++m)
|
|
|
|
fini_module__cap(mod, m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
bool require_value(struct module *const mod,
|
|
|
|
struct mapi_av3_attr *const attr)
|
|
|
|
{
|
|
|
|
if(!attr->value)
|
|
|
|
{
|
|
|
|
module_log(mod, "key[%s] requires non-null value", attr->key);
|
|
|
|
return false;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2016-04-03 08:51:26 +02:00
|
|
|
return true;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
static
|
|
|
|
bool init_v3_module_attr(struct module *const mod,
|
|
|
|
struct mapi_mheader_av3 *const h,
|
|
|
|
struct mapi_av3_attr *const attr)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
if(EmptyString(attr->key))
|
|
|
|
{
|
|
|
|
module_log(mod, "Skipping a NULL or empty key (ignoring)");
|
|
|
|
return true;
|
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
if(strncmp(attr->key, "time", MAPI_V3_KEY_MAXLEN) == 0)
|
|
|
|
{
|
|
|
|
//TODO: elizafox's warning
|
|
|
|
return true;
|
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
if(strncmp(attr->key, "name", MAPI_V3_KEY_MAXLEN) == 0)
|
|
|
|
{
|
|
|
|
module_log(mod, "Changing the display unsupported (ignoring)");
|
|
|
|
return true;
|
|
|
|
}
|
2016-04-07 11:15:12 +02:00
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
if(strncmp(attr->key, "mtab", MAPI_V3_KEY_MAXLEN) == 0)
|
|
|
|
{
|
|
|
|
if(!require_value(mod, attr))
|
|
|
|
return false;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-07-13 07:17:21 +02:00
|
|
|
struct Message *const v = (Message *)attr->value;
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
mod_add_cmd(v);
|
|
|
|
return true;
|
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
if(strncmp(attr->key, "hook", MAPI_V3_KEY_MAXLEN) == 0)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
if(!require_value(mod, attr))
|
|
|
|
return false;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-07-13 07:17:21 +02:00
|
|
|
mapi_hlist_av1 *const v = (mapi_hlist_av1 *)attr->value;
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
*v->hapi_id = register_hook(v->hapi_name);
|
|
|
|
return true;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
if(strncmp(attr->key, "hookfn", MAPI_V3_KEY_MAXLEN) == 0)
|
|
|
|
{
|
|
|
|
if(!require_value(mod, attr))
|
|
|
|
return false;
|
|
|
|
|
2016-07-13 07:17:21 +02:00
|
|
|
mapi_hfn_list_av1 *const v = (mapi_hfn_list_av1 *)attr->value;
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
add_hook(v->hapi_name, v->fn);
|
|
|
|
return true;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
if(strncmp(attr->key, "cap", MAPI_V3_KEY_MAXLEN) == 0)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
if(!require_value(mod, attr))
|
|
|
|
return false;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-07-13 07:17:21 +02:00
|
|
|
mapi_cap_list_av2 *const v = (mapi_cap_list_av2 *)attr->value;
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
return init_module__cap(mod, v);
|
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
if(strncmp(attr->key, "description", MAPI_V3_KEY_MAXLEN) == 0)
|
|
|
|
{
|
|
|
|
mod->description = (const char *)attr->value;
|
|
|
|
return true;
|
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
if(strncmp(attr->key, "version", MAPI_V3_KEY_MAXLEN) == 0)
|
|
|
|
{
|
|
|
|
mod->version = (const char *)attr->value;
|
|
|
|
return true;
|
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
if(strncmp(attr->key, "init", MAPI_V3_KEY_MAXLEN) == 0)
|
|
|
|
return attr->init();
|
2016-03-08 01:10:22 +01:00
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
// Ignore fini on load
|
|
|
|
if(strncmp(attr->key, "fini", MAPI_V3_KEY_MAXLEN) == 0)
|
|
|
|
return true;
|
2016-03-08 01:10:22 +01:00
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
// TODO: analysis.
|
|
|
|
module_log(mod, "Unknown key [%s]. Host version does not yet support unknown keys.", attr->key);
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-06 23:53:03 +01:00
|
|
|
|
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
static
|
|
|
|
void fini_v3_module_attr(struct module *const mod,
|
|
|
|
struct mapi_mheader_av3 *const h,
|
|
|
|
struct mapi_av3_attr *const attr)
|
|
|
|
{
|
|
|
|
if(EmptyString(attr->key))
|
|
|
|
{
|
|
|
|
module_log(mod, "Skipping a NULL or empty key (ignoring)");
|
|
|
|
return;
|
|
|
|
}
|
2016-03-06 23:53:03 +01:00
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
if(strncmp(attr->key, "mtab", MAPI_V3_KEY_MAXLEN) == 0)
|
|
|
|
{
|
|
|
|
if(attr->value)
|
2016-07-13 07:17:21 +02:00
|
|
|
mod_del_cmd((Message *)attr->value);
|
2016-03-06 23:53:03 +01:00
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(strncmp(attr->key, "hook", MAPI_V3_KEY_MAXLEN) == 0)
|
|
|
|
{
|
|
|
|
// ???
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(strncmp(attr->key, "hookfn", MAPI_V3_KEY_MAXLEN) == 0)
|
|
|
|
{
|
|
|
|
if(!attr->value)
|
|
|
|
return;
|
|
|
|
|
2016-07-13 07:17:21 +02:00
|
|
|
mapi_hfn_list_av1 *const v = (mapi_hfn_list_av1 *)attr->value;
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
remove_hook(v->hapi_name, v->fn);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(strncmp(attr->key, "cap", MAPI_V3_KEY_MAXLEN) == 0)
|
|
|
|
{
|
|
|
|
if(attr->value)
|
2016-07-13 07:17:21 +02:00
|
|
|
fini_module__cap(mod, (mapi_cap_list_av2 *)attr->value);
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(strncmp(attr->key, "fini", MAPI_V3_KEY_MAXLEN) == 0)
|
|
|
|
{
|
|
|
|
if(attr->value)
|
|
|
|
attr->fini();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
void fini_module_v3(struct module *const mod)
|
|
|
|
{
|
|
|
|
struct mapi_mheader_av3 *const h = (struct mapi_mheader_av3 *)mod->mapi_header;
|
|
|
|
if(!h->attrs)
|
|
|
|
{
|
|
|
|
module_log(mod, "(unload) has no attribute vector!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t i = -1;
|
|
|
|
struct mapi_av3_attr *attr;
|
|
|
|
for(attr = h->attrs[++i]; attr; attr = h->attrs[++i]);
|
|
|
|
for(attr = h->attrs[--i]; i > -1; attr = h->attrs[--i])
|
|
|
|
fini_v3_module_attr(mod, h, attr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
bool init_module_v3(struct module *const mod)
|
|
|
|
{
|
|
|
|
struct mapi_mheader_av3 *const h = (struct mapi_mheader_av3 *)mod->mapi_header;
|
|
|
|
if(!h->attrs)
|
|
|
|
{
|
|
|
|
module_log(mod, "has no attribute vector!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t i = 0;
|
|
|
|
for(struct mapi_av3_attr *attr = h->attrs[i]; attr; attr = h->attrs[++i])
|
|
|
|
{
|
|
|
|
if(!init_v3_module_attr(mod, h, attr))
|
|
|
|
{
|
|
|
|
h->attrs[i] = NULL;
|
|
|
|
fini_module_v3(mod);
|
|
|
|
return false;
|
2016-03-06 23:53:03 +01:00
|
|
|
}
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
}
|
2016-03-07 00:08:44 +01:00
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
bool init_module(struct module *const mod)
|
|
|
|
{
|
|
|
|
mod->mapi_header = lt_dlsym(mod->address, "_mheader");
|
|
|
|
if(!mod->mapi_header)
|
|
|
|
{
|
|
|
|
module_log(mod, "has no MAPI header. (%s)", lt_dlerror());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int version_magic = *(const int *)mod->mapi_header;
|
|
|
|
if(MAPI_MAGIC(version_magic) != MAPI_MAGIC_HDR)
|
|
|
|
{
|
|
|
|
module_log(mod, "has an invalid header (magic is [%x] mismatches [%x]).",
|
|
|
|
MAPI_MAGIC(version_magic),
|
|
|
|
MAPI_MAGIC_HDR);
|
2016-04-03 08:51:26 +02:00
|
|
|
return false;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
mod->mapi_version = MAPI_VERSION(version_magic);
|
|
|
|
switch(mod->mapi_version)
|
|
|
|
{
|
|
|
|
case 1: return init_module_v1(mod);
|
|
|
|
case 2: return init_module_v2(mod);
|
|
|
|
case 3: return init_module_v3(mod);
|
|
|
|
default:
|
|
|
|
module_log(mod, "has unknown/unsupported MAPI version %d.", mod->mapi_version);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
const char *reflect_origin(const int origin)
|
|
|
|
{
|
|
|
|
switch(origin)
|
|
|
|
{
|
|
|
|
case MAPI_ORIGIN_EXTENSION: return "extension";
|
|
|
|
case MAPI_ORIGIN_CORE: return "core";
|
|
|
|
default: return "unknown";
|
|
|
|
}
|
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-03-06 23:53:03 +01:00
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
static
|
|
|
|
void free_module(struct module **ptr)
|
|
|
|
{
|
|
|
|
if(!ptr || !*ptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
struct module *mod = *ptr;
|
|
|
|
if(mod->name)
|
|
|
|
rb_free(mod->name);
|
|
|
|
|
|
|
|
if(mod->path)
|
|
|
|
rb_free(mod->path);
|
|
|
|
|
|
|
|
rb_free(mod);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
void close_handle(lt_dlhandle *handle)
|
|
|
|
{
|
|
|
|
if(handle && *handle)
|
|
|
|
lt_dlclose(*handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* load_a_module()
|
|
|
|
*
|
|
|
|
* inputs - path name of module, bool to notice, int of origin, bool if core
|
|
|
|
* output - false if error true if success
|
|
|
|
* side effects - loads a module if successful
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
load_a_module(const char *path, bool warn, int origin, bool core)
|
|
|
|
{
|
|
|
|
char *const name RB_AUTO_PTR = rb_basename(path);
|
|
|
|
|
|
|
|
/* Trim off the ending for the display name if we have to */
|
|
|
|
char *c;
|
|
|
|
if((c = rb_strcasestr(name, LT_MODULE_EXT)) != NULL)
|
|
|
|
*c = '\0';
|
|
|
|
|
|
|
|
lt_dlhandle handle RB_UNIQUE_PTR(close_handle) = lt_dlopenext(path);
|
|
|
|
if(handle == NULL)
|
|
|
|
{
|
|
|
|
slog(L_MAIN, SNO_GENERAL, "Error loading module %s: %s", name, lt_dlerror());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-13 07:17:21 +02:00
|
|
|
struct module *mod RB_UNIQUE_PTR(free_module) = (module *)rb_malloc(sizeof(struct module));
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
mod->name = rb_strdup(name);
|
|
|
|
mod->path = rb_strdup(path);
|
|
|
|
mod->address = handle;
|
2016-06-18 07:52:16 +02:00
|
|
|
mod->origin = origin;
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
mod->core = core;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
if(!init_module(mod))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
slog(L_MAIN, SNO_GENERAL, "Loading module %s aborted.", name);
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-07 00:52:49 +01:00
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
if(!mod->version)
|
|
|
|
mod->version = "<unknown>";
|
|
|
|
|
|
|
|
if(!mod->description)
|
|
|
|
mod->description = "<no description>";
|
|
|
|
|
|
|
|
if(warn)
|
|
|
|
slog(L_MAIN, SNO_GENERAL,
|
|
|
|
"Module %s [version: %s; MAPI version: %d; origin: %s; description: \"%s\"] loaded from [%s] to %p",
|
|
|
|
name,
|
|
|
|
mod->version,
|
|
|
|
mod->mapi_version,
|
|
|
|
reflect_origin(mod->origin),
|
|
|
|
mod->description,
|
|
|
|
mod->path,
|
|
|
|
(const void *)mod->address);
|
|
|
|
|
|
|
|
// NULL the acquired resources after commitment to list ownership
|
|
|
|
rb_dlinkAdd(mod, &mod->node, &module_list);
|
|
|
|
mod = NULL;
|
|
|
|
handle = NULL;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* unload_one_module()
|
|
|
|
*
|
|
|
|
* inputs - name of module to unload
|
|
|
|
* - true to say modules unloaded, false to not
|
|
|
|
* output - true if successful, false if error
|
|
|
|
* side effects - module is unloaded
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
unload_one_module(const char *name, bool warn)
|
|
|
|
{
|
|
|
|
struct module *mod;
|
|
|
|
if((mod = findmodule_byname(name)) == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(mod->core)
|
|
|
|
return false;
|
2016-03-07 00:52:49 +01:00
|
|
|
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
/*
|
|
|
|
** XXX - The type system in C does not allow direct conversion between
|
|
|
|
** data and function pointers, but as it happens, most C compilers will
|
|
|
|
** safely do this, however it is a theoretical overlow to cast as we
|
|
|
|
** must do here. I have library functions to take care of this, but
|
|
|
|
** despite being more "correct" for the C language, this is more
|
|
|
|
** practical. Removing the abuse of the ability to cast ANY pointer
|
|
|
|
** to and from an integer value here will break some compilers.
|
|
|
|
** -jmallett
|
|
|
|
*/
|
|
|
|
/* Left the comment in but the code isn't here any more -larne */
|
|
|
|
switch (mod->mapi_version)
|
|
|
|
{
|
|
|
|
case 1: fini_module_v1(mod); break;
|
|
|
|
case 2: fini_module_v2(mod); break;
|
|
|
|
case 3: fini_module_v3(mod); break;
|
|
|
|
default:
|
|
|
|
slog(L_MAIN, SNO_GENERAL,
|
|
|
|
"Unknown/unsupported MAPI version %d when unloading %s!",
|
|
|
|
mod->mapi_version,
|
|
|
|
mod->name);
|
|
|
|
break;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
MAPI Version 3
This version leverages a flexible, cleaner key-value strategy
reducing the need to design entire new headers for every feature
addition, change, etc.
* A friendly declaration for the module authors, with minimal
requirements to fill in, and explicit labels of what the fields are.
* Repetition of keys, removing references to (and the requirement to
build) a clist, hlist and hfnlist and caplist and whatever the future
holds.
* Safe deterministic loading and unloading. Keys are evaluated in
order, errors can be recognized, and unloading occurs in reverse
order.
ircd: Refactor internal half of modules.c, with some V3 additions.
Provides better delegation for versions, a cleaner stack with better
error handling, and some functionality deduping. V1 and V2 handlers
are still somewhat unaltered, just factored in.
2016-06-23 03:30:05 +02:00
|
|
|
|
|
|
|
rb_dlinkDelete(&mod->node, &module_list);
|
|
|
|
close_handle(&mod->address);
|
|
|
|
|
|
|
|
if(warn)
|
|
|
|
slog(L_MAIN, SNO_GENERAL, "Module %s unloaded", name);
|
|
|
|
|
|
|
|
// free after the unload message in case *name came from the mod struct.
|
|
|
|
free_module(&mod);
|
2016-04-03 08:51:26 +02:00
|
|
|
return true;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|