#include "match.h"
#include "s_serv.h"
#include "capability.h"
+#include "hash.h"
#include <ltdl.h>
mod_add_path(ircd_paths[IRCD_PATH_AUTOLOAD_MODULES]);
}
+static unsigned int prev_caps;
+
+void
+mod_remember_clicaps(void)
+{
+ prev_caps = capability_index_mask(cli_capindex);
+}
+
+void
+mod_notify_clicaps(void)
+{
+ unsigned int cur_caps = capability_index_mask(cli_capindex);
+ unsigned int del = prev_caps & ~cur_caps;
+ unsigned int new = cur_caps & ~prev_caps;
+
+ if (del)
+ sendto_local_clients_with_capability(CLICAP_CAP_NOTIFY, ":%s CAP * DEL :%s",
+ me.name, capability_index_list(cli_capindex, del));
+ if (new)
+ sendto_local_clients_with_capability(CLICAP_CAP_NOTIFY, ":%s CAP * NEW :%s",
+ me.name, capability_index_list(cli_capindex, new));
+}
+
/* mod_find_path()
*
* input - path
}
sendto_realops_snomask(SNO_GENERAL, L_ALL, "Cannot locate module %s", path);
+
+ if (server_state_foreground)
+ ierror("cannot locate module %s", path);
+
return false;
}
continue;
}
- if (m->cap_id != NULL)
- {
- capability_orphan(idx, m->cap_name);
- sendto_local_clients_with_capability(CLICAP_CAP_NOTIFY, ":%s CAP * DEL :%s", me.name, m->cap_name);
- }
+ capability_orphan(idx, m->cap_name);
}
}
break;
rb_dlinkDelete(&mod->node, &module_list);
rb_free(mod->name);
+ rb_free(mod->path);
rb_free(mod);
if(warn)
{
struct mapi_mheader_av2 *mheader = (struct mapi_mheader_av2 *)(void *)mapi_version; /* see above */
+ 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_displayname);
+ ilog(L_MAIN,
+ "Unknown/unsupported CAP index found of type %d on capability %s when loading %s",
+ m->cap_index, m->cap_name, mod_displayname);
+ continue;
+ }
+
+ result = capability_put(idx, m->cap_name, m->cap_ownerdata);
+ if (m->cap_id != NULL)
+ *(m->cap_id) = result;
+ }
+ }
+
/* XXX duplicated code :( */
if(mheader->mapi_register && (mheader->mapi_register() == -1))
{
sendto_realops_snomask(SNO_GENERAL, L_ALL,
"Module %s indicated failure during load.",
mod_displayname);
+ 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:
+ continue;
+ }
+ capability_orphan(idx, m->cap_name);
+ }
+ }
lt_dlclose(tmpptr);
rb_free(mod_displayname);
return false;
{
mapi_hfn_list_av1 *m;
for (m = mheader->mapi_hfn_list; m->hapi_name; ++m)
- add_hook(m->hapi_name, m->fn);
+ {
+ int priority = m->priority;
+ if (priority == 0)
+ priority = HOOK_NORMAL;
+ add_hook_prio(m->hapi_name, m->fn, priority);
+ }
}
/* New in MAPI v2 - version replacement */
ver = mheader->mapi_module_version ? mheader->mapi_module_version : ircd_version;
description = mheader->mapi_module_description;
-
- 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_displayname);
- ilog(L_MAIN,
- "Unknown/unsupported CAP index found of type %d on capability %s when loading %s",
- m->cap_index, m->cap_name, mod_displayname);
- continue;
- }
-
- result = capability_put(idx, m->cap_name, m->cap_ownerdata);
- if (m->cap_id != NULL)
- {
- *(m->cap_id) = result;
- sendto_local_clients_with_capability(CLICAP_CAP_NOTIFY, ":%s CAP * ADD :%s", me.name, m->cap_name);
- }
- }
- }
}
break;
mod->mapi_header = mapi_version;
mod->mapi_version = MAPI_VERSION(*mapi_version);
mod->origin = origin;
+ mod->path = rb_strdup(path);
rb_dlinkAdd(mod, &mod->node, &module_list);
if(warn)
return true;
}
+void
+modules_do_reload(void *info_)
+{
+ struct modreload *info = info_;
+ struct module *mod;
+ int check_core;
+ int origin;
+ char *m_bn = rb_basename(info->module);
+ char *path;
+ struct Client *source_p = find_id(info->id);
+
+ if((mod = findmodule_byname(m_bn)) == NULL)
+ {
+ if (source_p) sendto_one_notice(source_p, ":Module %s is not loaded", m_bn);
+ rb_free(info);
+ rb_free(m_bn);
+ return;
+ }
+
+ origin = mod->origin;
+ check_core = mod->core;
+ path = rb_strdup(mod->path);
+
+ mod_remember_clicaps();
+
+ if(unload_one_module(m_bn, true) == false)
+ {
+ if (source_p) sendto_one_notice(source_p, ":Module %s is not loaded", m_bn);
+ rb_free(info);
+ rb_free(m_bn);
+ rb_free(path);
+ return;
+ }
+
+ if((load_a_module(path, true, origin, check_core) == false) && check_core)
+ {
+ sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
+ "Error reloading core module: %s: terminating ircd", m_bn);
+ ilog(L_MAIN, "Error loading core module %s: terminating ircd", m_bn);
+ exit(0);
+ }
+
+ mod_notify_clicaps();
+
+ rb_free(info);
+ rb_free(m_bn);
+ rb_free(path);
+}
+
void
modules_do_restart(void *unused)
{
unsigned int modnum = 0;
rb_dlink_node *ptr, *nptr;
+ mod_remember_clicaps();
+
RB_DLINK_FOREACH_SAFE(ptr, nptr, module_list.head)
{
struct module *mod = ptr->data;
load_core_modules(false);
rehash(false);
+ mod_notify_clicaps();
+
sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
"Module Restart: %u modules unloaded, %lu modules loaded",
modnum, rb_dlink_list_length(&module_list));