2 * ircd-ratbox: A slightly useful ircd.
3 * modules.c: A module loader.
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
32 #include "s_newconf.h"
35 #include "ircd_defs.h"
38 #include "capability.h"
43 # error "Charybdis requires loadable module support."
46 struct module **modlist
= NULL
;
48 static const char *core_module_table
[] = {
65 #define MOD_WARN_DELTA (90 * 86400) /* time in seconds, 86400 seconds in a day */
67 #define MODS_INCREMENT 10
69 int max_mods
= MODS_INCREMENT
;
71 static rb_dlink_list mod_paths
;
73 static void mo_modload(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
74 static void mo_modlist(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
75 static void mo_modreload(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
76 static void mo_modunload(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
77 static void mo_modrestart(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
79 static void me_modload(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
80 static void me_modlist(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
81 static void me_modreload(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
82 static void me_modunload(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
83 static void me_modrestart(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
85 static void do_modload(struct Client
*, const char *);
86 static void do_modunload(struct Client
*, const char *);
87 static void do_modreload(struct Client
*, const char *);
88 static void do_modlist(struct Client
*, const char *);
89 static void do_modrestart(struct Client
*);
91 struct Message modload_msgtab
= {
92 "MODLOAD", 0, 0, 0, 0,
93 {mg_unreg
, mg_not_oper
, mg_ignore
, mg_ignore
, {me_modload
, 2}, {mo_modload
, 2}}
96 struct Message modunload_msgtab
= {
97 "MODUNLOAD", 0, 0, 0, 0,
98 {mg_unreg
, mg_not_oper
, mg_ignore
, mg_ignore
, {me_modunload
, 2}, {mo_modunload
, 2}}
101 struct Message modreload_msgtab
= {
102 "MODRELOAD", 0, 0, 0, 0,
103 {mg_unreg
, mg_not_oper
, mg_ignore
, mg_ignore
, {me_modreload
, 2}, {mo_modreload
, 2}}
106 struct Message modlist_msgtab
= {
107 "MODLIST", 0, 0, 0, 0,
108 {mg_unreg
, mg_not_oper
, mg_ignore
, mg_ignore
, {me_modlist
, 0}, {mo_modlist
, 0}}
111 struct Message modrestart_msgtab
= {
112 "MODRESTART", 0, 0, 0, 0,
113 {mg_unreg
, mg_not_oper
, mg_ignore
, mg_ignore
, {me_modrestart
, 0}, {mo_modrestart
, 0}}
121 ilog(L_MAIN
, "lt_dlinit failed");
125 mod_add_cmd(&modload_msgtab
);
126 mod_add_cmd(&modunload_msgtab
);
127 mod_add_cmd(&modreload_msgtab
);
128 mod_add_cmd(&modlist_msgtab
);
129 mod_add_cmd(&modrestart_msgtab
);
131 /* Add the default paths we look in to the module system --nenolod */
132 mod_add_path(ircd_paths
[IRCD_PATH_MODULES
]);
133 mod_add_path(ircd_paths
[IRCD_PATH_AUTOLOAD_MODULES
]);
140 * side effects - returns a module path from path
143 mod_find_path(const char *path
)
148 RB_DLINK_FOREACH(ptr
, mod_paths
.head
)
152 if(!strcmp(path
, mpath
))
163 * side effects - adds path to list
166 mod_add_path(const char *path
)
170 if(mod_find_path(path
))
173 pathst
= rb_strdup(path
);
174 rb_dlinkAddAlloc(pathst
, &mod_paths
);
181 * side effects - clear the lists of paths
184 mod_clear_paths(void)
186 rb_dlink_node
*ptr
, *next_ptr
;
188 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, mod_paths
.head
)
191 rb_free_rb_dlink_node(ptr
);
194 mod_paths
.head
= mod_paths
.tail
= NULL
;
195 mod_paths
.length
= 0;
206 findmodule_byname(const char *name
)
209 char name_ext
[PATH_MAX
+ 1];
211 rb_strlcpy(name_ext
, name
, sizeof name_ext
);
212 rb_strlcat(name_ext
, LT_MODULE_EXT
, sizeof name_ext
);
214 for (i
= 0; i
< num_mods
; i
++)
216 if(!irccmp(modlist
[i
]->name
, name
))
219 if(!irccmp(modlist
[i
]->name
, name_ext
))
226 /* load_all_modules()
233 load_all_modules(int warn
)
235 DIR *system_module_dir
= NULL
;
236 struct dirent
*ldirent
= NULL
;
237 char module_fq_name
[PATH_MAX
+ 1];
238 size_t module_ext_len
= strlen(LT_MODULE_EXT
);
242 modlist
= (struct module **) rb_malloc(sizeof(struct module *) * (MODS_INCREMENT
));
244 max_mods
= MODS_INCREMENT
;
246 system_module_dir
= opendir(ircd_paths
[IRCD_PATH_AUTOLOAD_MODULES
]);
248 if(system_module_dir
== NULL
)
250 ilog(L_MAIN
, "Could not load modules from %s: %s", ircd_paths
[IRCD_PATH_AUTOLOAD_MODULES
], strerror(errno
));
254 while ((ldirent
= readdir(system_module_dir
)) != NULL
)
258 len
= strlen(ldirent
->d_name
);
259 if(len
> module_ext_len
&& !strcasecmp(ldirent
->d_name
+ (len
- module_ext_len
), LT_MODULE_EXT
))
261 (void) snprintf(module_fq_name
, sizeof(module_fq_name
), "%s%c%s", ircd_paths
[IRCD_PATH_AUTOLOAD_MODULES
], RB_PATH_SEPARATOR
, ldirent
->d_name
);
262 (void) load_a_module(module_fq_name
, warn
, MAPI_ORIGIN_CORE
, 0);
266 (void) closedir(system_module_dir
);
269 /* load_core_modules()
273 * side effects - core modules are loaded, if any fail, kill ircd
276 load_core_modules(int warn
)
278 char module_name
[PATH_MAX
];
282 for (i
= 0; core_module_table
[i
]; i
++)
284 snprintf(module_name
, sizeof(module_name
), "%s%c%s%s", ircd_paths
[IRCD_PATH_MODULES
], RB_PATH_SEPARATOR
,
285 core_module_table
[i
], LT_MODULE_EXT
);
287 if(load_a_module(module_name
, warn
, MAPI_ORIGIN_CORE
, 1) == -1)
290 "Error loading core module %s: terminating ircd",
291 core_module_table
[i
]);
304 load_one_module(const char *path
, int origin
, int coremodule
)
306 char modpath
[PATH_MAX
];
307 rb_dlink_node
*pathst
;
311 if (server_state_foreground
)
312 inotice("loading module %s ...", path
);
317 origin
= MAPI_ORIGIN_CORE
;
320 RB_DLINK_FOREACH(pathst
, mod_paths
.head
)
322 mpath
= pathst
->data
;
324 snprintf(modpath
, sizeof(modpath
), "%s/%s%s", mpath
, path
, LT_MODULE_EXT
);
325 if((strstr(modpath
, "../") == NULL
) && (strstr(modpath
, "/..") == NULL
))
327 if(stat(modpath
, &statbuf
) == 0)
329 if(S_ISREG(statbuf
.st_mode
))
331 /* Regular files only please */
332 return load_a_module(modpath
, 1, origin
, coremodule
);
339 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Cannot locate module %s", path
);
344 /* load a module .. */
346 mo_modload(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
348 if(!IsOperAdmin(source_p
))
350 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
351 me
.name
, source_p
->name
, "admin");
357 sendto_match_servs(source_p
, parv
[2], CAP_ENCAP
, NOCAPS
,
358 "ENCAP %s MODLOAD %s", parv
[2], parv
[1]);
359 if (match(parv
[2], me
.name
) == 0)
363 do_modload(source_p
, parv
[1]);
367 me_modload(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
369 if(!find_shared_conf(source_p
->username
, source_p
->host
, source_p
->servptr
->name
, SHARED_MODULE
))
371 sendto_one_notice(source_p
, ":*** You do not have an appropriate shared block "
372 "to load modules on this server.");
376 do_modload(source_p
, parv
[1]);
380 /* unload a module .. */
382 mo_modunload(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
384 if(!IsOperAdmin(source_p
))
386 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
387 me
.name
, source_p
->name
, "admin");
393 sendto_match_servs(source_p
, parv
[2], CAP_ENCAP
, NOCAPS
,
394 "ENCAP %s MODUNLOAD %s", parv
[2], parv
[1]);
395 if (match(parv
[2], me
.name
) == 0)
399 do_modunload(source_p
, parv
[1]);
403 me_modunload(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
405 if(!find_shared_conf(source_p
->username
, source_p
->host
, source_p
->servptr
->name
, SHARED_MODULE
))
407 sendto_one_notice(source_p
, ":*** You do not have an appropriate shared block "
408 "to load modules on this server.");
412 do_modunload(source_p
, parv
[1]);
415 /* unload and load in one! */
417 mo_modreload(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
419 if(!IsOperAdmin(source_p
))
421 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
422 me
.name
, source_p
->name
, "admin");
428 sendto_match_servs(source_p
, parv
[2], CAP_ENCAP
, NOCAPS
,
429 "ENCAP %s MODRELOAD %s", parv
[2], parv
[1]);
430 if (match(parv
[2], me
.name
) == 0)
434 do_modreload(source_p
, parv
[1]);
438 me_modreload(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
440 if(!find_shared_conf(source_p
->username
, source_p
->host
, source_p
->servptr
->name
, SHARED_MODULE
))
442 sendto_one_notice(source_p
, ":*** You do not have an appropriate shared block "
443 "to load modules on this server.");
447 do_modreload(source_p
, parv
[1]);
450 /* list modules .. */
452 mo_modlist(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
454 if(!IsOperAdmin(source_p
))
456 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
457 me
.name
, source_p
->name
, "admin");
463 sendto_match_servs(source_p
, parv
[2], CAP_ENCAP
, NOCAPS
,
464 "ENCAP %s MODLIST %s", parv
[2], parv
[1]);
465 if (match(parv
[2], me
.name
) == 0)
469 do_modlist(source_p
, parc
> 1 ? parv
[1] : 0);
473 me_modlist(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
475 if(!find_shared_conf(source_p
->username
, source_p
->host
, source_p
->servptr
->name
, SHARED_MODULE
))
477 sendto_one_notice(source_p
, ":*** You do not have an appropriate shared block "
478 "to load modules on this server.");
482 do_modlist(source_p
, parv
[1]);
485 /* unload and reload all modules */
487 mo_modrestart(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
489 if(!IsOperAdmin(source_p
))
491 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
492 me
.name
, source_p
->name
, "admin");
498 sendto_match_servs(source_p
, parv
[1], CAP_ENCAP
, NOCAPS
,
499 "ENCAP %s MODRESTART", parv
[1]);
500 if (match(parv
[1], me
.name
) == 0)
504 do_modrestart(source_p
);
508 me_modrestart(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
510 if(!find_shared_conf(source_p
->username
, source_p
->host
, source_p
->servptr
->name
, SHARED_MODULE
))
512 sendto_one_notice(source_p
, ":*** You do not have an appropriate shared block "
513 "to load modules on this server.");
517 do_modrestart(source_p
);
521 do_modload(struct Client
*source_p
, const char *module)
523 char *m_bn
= rb_basename(module);
526 if(findmodule_byname(m_bn
) != -1)
528 sendto_one_notice(source_p
, ":Module %s is already loaded", m_bn
);
533 origin
= strcmp(module, m_bn
) == 0 ? MAPI_ORIGIN_CORE
: MAPI_ORIGIN_EXTENSION
;
534 load_one_module(module, origin
, 0);
540 do_modunload(struct Client
*source_p
, const char *module)
543 char *m_bn
= rb_basename(module);
545 if((modindex
= findmodule_byname(m_bn
)) == -1)
547 sendto_one_notice(source_p
, ":Module %s is not loaded", m_bn
);
552 if(modlist
[modindex
]->core
== 1)
554 sendto_one_notice(source_p
, ":Module %s is a core module and may not be unloaded", m_bn
);
559 if(unload_one_module(m_bn
, 1) == -1)
561 sendto_one_notice(source_p
, ":Module %s is not loaded", m_bn
);
568 do_modreload(struct Client
*source_p
, const char *module)
572 char *m_bn
= rb_basename(module);
574 if((modindex
= findmodule_byname(m_bn
)) == -1)
576 sendto_one_notice(source_p
, ":Module %s is not loaded", m_bn
);
581 check_core
= modlist
[modindex
]->core
;
583 if(unload_one_module(m_bn
, 1) == -1)
585 sendto_one_notice(source_p
, ":Module %s is not loaded", m_bn
);
590 if((load_one_module(m_bn
, modlist
[modindex
]->origin
, check_core
) == -1) && check_core
)
592 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
593 "Error reloading core module: %s: terminating ircd", m_bn
);
594 ilog(L_MAIN
, "Error loading core module %s: terminating ircd", m_bn
);
602 do_modrestart(struct Client
*source_p
)
606 sendto_one_notice(source_p
, ":Reloading all modules");
610 unload_one_module(modlist
[0]->name
, 0);
613 load_core_modules(0);
616 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
617 "Module Restart: %d modules unloaded, %d modules loaded",
619 ilog(L_MAIN
, "Module Restart: %d modules unloaded, %d modules loaded", modnum
, num_mods
);
623 do_modlist(struct Client
*source_p
, const char *pattern
)
627 for (i
= 0; i
< num_mods
; i
++)
630 switch (modlist
[i
]->origin
)
632 case MAPI_ORIGIN_EXTENSION
:
633 origin
= "extension";
635 case MAPI_ORIGIN_CORE
:
645 if(match(pattern
, modlist
[i
]->name
))
647 sendto_one(source_p
, form_str(RPL_MODLIST
),
648 me
.name
, source_p
->name
,
650 (unsigned long)(uintptr_t)modlist
[i
]->address
, origin
,
651 modlist
[i
]->core
? " (core)" : "", modlist
[i
]->version
, modlist
[i
]->description
);
656 sendto_one(source_p
, form_str(RPL_MODLIST
),
657 me
.name
, source_p
->name
, modlist
[i
]->name
,
658 (unsigned long)(uintptr_t)modlist
[i
]->address
, origin
,
659 modlist
[i
]->core
? " (core)" : "", modlist
[i
]->version
, modlist
[i
]->description
);
663 sendto_one(source_p
, form_str(RPL_ENDOFMODLIST
), me
.name
, source_p
->name
);
666 static void increase_modlist(void);
668 #define MODS_INCREMENT 10
670 static char unknown_ver
[] = "<unknown>";
671 static char unknown_description
[] = "<none>";
673 /* unload_one_module()
675 * inputs - name of module to unload
676 * - 1 to say modules unloaded, 0 to not
677 * output - 0 if successful, -1 if error
678 * side effects - module is unloaded
681 unload_one_module(const char *name
, int warn
)
685 if((modindex
= findmodule_byname(name
)) == -1)
689 ** XXX - The type system in C does not allow direct conversion between
690 ** data and function pointers, but as it happens, most C compilers will
691 ** safely do this, however it is a theoretical overlow to cast as we
692 ** must do here. I have library functions to take care of this, but
693 ** despite being more "correct" for the C language, this is more
694 ** practical. Removing the abuse of the ability to cast ANY pointer
695 ** to and from an integer value here will break some compilers.
698 /* Left the comment in but the code isn't here any more -larne */
699 switch (modlist
[modindex
]->mapi_version
)
703 struct mapi_mheader_av1
*mheader
= modlist
[modindex
]->mapi_header
;
704 if(mheader
->mapi_command_list
)
707 for (m
= mheader
->mapi_command_list
; *m
; ++m
)
711 /* hook events are never removed, we simply lose the
712 * ability to call them --fl
714 if(mheader
->mapi_hfn_list
)
716 mapi_hfn_list_av1
*m
;
717 for (m
= mheader
->mapi_hfn_list
; m
->hapi_name
; ++m
)
718 remove_hook(m
->hapi_name
, m
->fn
);
721 if(mheader
->mapi_unregister
)
722 mheader
->mapi_unregister();
727 struct mapi_mheader_av2
*mheader
= modlist
[modindex
]->mapi_header
;
729 /* XXX duplicate code :( */
730 if(mheader
->mapi_command_list
)
733 for (m
= mheader
->mapi_command_list
; *m
; ++m
)
737 /* hook events are never removed, we simply lose the
738 * ability to call them --fl
740 if(mheader
->mapi_hfn_list
)
742 mapi_hfn_list_av1
*m
;
743 for (m
= mheader
->mapi_hfn_list
; m
->hapi_name
; ++m
)
744 remove_hook(m
->hapi_name
, m
->fn
);
747 if(mheader
->mapi_unregister
)
748 mheader
->mapi_unregister();
750 if(mheader
->mapi_cap_list
)
752 mapi_cap_list_av2
*m
;
753 for (m
= mheader
->mapi_cap_list
; m
->cap_name
; ++m
)
755 struct CapabilityIndex
*idx
;
757 switch (m
->cap_index
)
759 case MAPI_CAP_CLIENT
:
762 case MAPI_CAP_SERVER
:
766 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
767 "Unknown/unsupported CAP index found of type %d on capability %s when unloading %s",
768 m
->cap_index
, m
->cap_name
, modlist
[modindex
]->name
);
770 "Unknown/unsupported CAP index found of type %d on capability %s when unloading %s",
771 m
->cap_index
, m
->cap_name
, modlist
[modindex
]->name
);
775 capability_orphan(idx
, m
->cap_name
);
780 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
781 "Unknown/unsupported MAPI version %d when unloading %s!",
782 modlist
[modindex
]->mapi_version
, modlist
[modindex
]->name
);
783 ilog(L_MAIN
, "Unknown/unsupported MAPI version %d when unloading %s!",
784 modlist
[modindex
]->mapi_version
, modlist
[modindex
]->name
);
788 lt_dlclose(modlist
[modindex
]->address
);
790 rb_free(modlist
[modindex
]->name
);
791 rb_free(modlist
[modindex
]);
792 memmove(&modlist
[modindex
], &modlist
[modindex
+ 1],
793 sizeof(struct module *) * ((num_mods
- 1) - modindex
));
800 ilog(L_MAIN
, "Module %s unloaded", name
);
801 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Module %s unloaded", name
);
810 * inputs - path name of module, int to notice, int of origin, int of core
811 * output - -1 if error 0 if success
812 * side effects - loads a module if successful
815 load_a_module(const char *path
, int warn
, int origin
, int core
)
819 const char *ver
, *description
= NULL
;
823 mod_basename
= rb_basename(path
);
825 tmpptr
= lt_dlopenext(path
);
829 const char *err
= lt_dlerror();
831 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
832 "Error loading module %s: %s", mod_basename
, err
);
833 ilog(L_MAIN
, "Error loading module %s: %s", mod_basename
, err
);
834 rb_free(mod_basename
);
839 * _mheader is actually a struct mapi_mheader_*, but mapi_version
840 * is always the first member of this structure, so we treate it
841 * as a single int in order to determine the API version.
844 mapi_version
= (int *) (uintptr_t) lt_dlsym(tmpptr
, "_mheader");
845 if((mapi_version
== NULL
846 && (mapi_version
= (int *) (uintptr_t) lt_dlsym(tmpptr
, "__mheader")) == NULL
)
847 || MAPI_MAGIC(*mapi_version
) != MAPI_MAGIC_HDR
)
849 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
850 "Data format error: module %s has no MAPI header.",
852 ilog(L_MAIN
, "Data format error: module %s has no MAPI header.", mod_basename
);
853 (void) lt_dlclose(tmpptr
);
854 rb_free(mod_basename
);
858 switch (MAPI_VERSION(*mapi_version
))
862 struct mapi_mheader_av1
*mheader
= (struct mapi_mheader_av1
*)(void *)mapi_version
; /* see above */
863 if(mheader
->mapi_register
&& (mheader
->mapi_register() == -1))
865 ilog(L_MAIN
, "Module %s indicated failure during load.",
867 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
868 "Module %s indicated failure during load.",
871 rb_free(mod_basename
);
874 if(mheader
->mapi_command_list
)
877 for (m
= mheader
->mapi_command_list
; *m
; ++m
)
881 if(mheader
->mapi_hook_list
)
884 for (m
= mheader
->mapi_hook_list
; m
->hapi_name
; ++m
)
885 *m
->hapi_id
= register_hook(m
->hapi_name
);
888 if(mheader
->mapi_hfn_list
)
890 mapi_hfn_list_av1
*m
;
891 for (m
= mheader
->mapi_hfn_list
; m
->hapi_name
; ++m
)
892 add_hook(m
->hapi_name
, m
->fn
);
895 ver
= mheader
->mapi_module_version
;
900 struct mapi_mheader_av2
*mheader
= (struct mapi_mheader_av2
*)(void *)mapi_version
; /* see above */
902 /* XXX duplicated code :( */
903 if(mheader
->mapi_register
&& (mheader
->mapi_register() == -1))
905 ilog(L_MAIN
, "Module %s indicated failure during load.",
907 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
908 "Module %s indicated failure during load.",
911 rb_free(mod_basename
);
915 /* Basic date code checks
917 * Don't make them fatal, but do complain about differences within a certain time frame.
918 * Later on if there are major API changes we can add fatal checks.
921 if(mheader
->mapi_datecode
!= datecode
&& mheader
->mapi_datecode
> 0)
923 long int delta
= datecode
- mheader
->mapi_datecode
;
924 if (delta
> MOD_WARN_DELTA
)
927 iwarn("Module %s build date is out of sync with ircd build date by %ld days, expect problems",
928 mod_basename
, delta
);
929 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
930 "Module %s build date is out of sync with ircd build date by %ld days, expect problems",
931 mod_basename
, delta
);
935 if(mheader
->mapi_command_list
)
938 for (m
= mheader
->mapi_command_list
; *m
; ++m
)
942 if(mheader
->mapi_hook_list
)
945 for (m
= mheader
->mapi_hook_list
; m
->hapi_name
; ++m
)
946 *m
->hapi_id
= register_hook(m
->hapi_name
);
949 if(mheader
->mapi_hfn_list
)
951 mapi_hfn_list_av1
*m
;
952 for (m
= mheader
->mapi_hfn_list
; m
->hapi_name
; ++m
)
953 add_hook(m
->hapi_name
, m
->fn
);
956 /* New in MAPI v2 - version replacement */
957 ver
= mheader
->mapi_module_version
? mheader
->mapi_module_version
: ircd_version
;
958 description
= mheader
->mapi_module_description
;
960 if(mheader
->mapi_cap_list
)
962 mapi_cap_list_av2
*m
;
963 for (m
= mheader
->mapi_cap_list
; m
->cap_name
; ++m
)
965 struct CapabilityIndex
*idx
;
968 switch (m
->cap_index
)
970 case MAPI_CAP_CLIENT
:
973 case MAPI_CAP_SERVER
:
977 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
978 "Unknown/unsupported CAP index found of type %d on capability %s when loading %s",
979 m
->cap_index
, m
->cap_name
, mod_basename
);
981 "Unknown/unsupported CAP index found of type %d on capability %s when loading %s",
982 m
->cap_index
, m
->cap_name
, mod_basename
);
986 result
= capability_put(idx
, m
->cap_name
, m
->cap_ownerdata
);
987 if (m
->cap_id
!= NULL
)
988 *(m
->cap_id
) = result
;
995 ilog(L_MAIN
, "Module %s has unknown/unsupported MAPI version %d.",
996 mod_basename
, MAPI_VERSION(*mapi_version
));
997 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
998 "Module %s has unknown/unsupported MAPI version %d.",
999 mod_basename
, *mapi_version
);
1001 rb_free(mod_basename
);
1008 if(description
== NULL
)
1009 description
= unknown_description
;
1013 modlist
[num_mods
] = rb_malloc(sizeof(struct module));
1014 modlist
[num_mods
]->address
= tmpptr
;
1015 modlist
[num_mods
]->version
= ver
;
1016 modlist
[num_mods
]->description
= description
;
1017 modlist
[num_mods
]->core
= core
;
1018 modlist
[num_mods
]->name
= rb_strdup(mod_basename
);
1019 modlist
[num_mods
]->mapi_header
= mapi_version
;
1020 modlist
[num_mods
]->mapi_version
= MAPI_VERSION(*mapi_version
);
1021 modlist
[num_mods
]->origin
= origin
;
1030 case MAPI_ORIGIN_EXTENSION
:
1033 case MAPI_ORIGIN_CORE
:
1041 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1042 "Module %s [version: %s; MAPI version: %d; origin: %s; description: \"%s\"] loaded at %p",
1043 mod_basename
, ver
, MAPI_VERSION(*mapi_version
), o
, description
,
1045 ilog(L_MAIN
, "Module %s [version: %s; MAPI version: %d; origin: %s; description: \"%s\"] loaded at %p",
1046 mod_basename
, ver
, MAPI_VERSION(*mapi_version
), o
, description
, (void *) tmpptr
);
1048 rb_free(mod_basename
);
1057 * side effects - expand the size of modlist if necessary
1060 increase_modlist(void)
1062 struct module **new_modlist
= NULL
;
1064 if((num_mods
+ 1) < max_mods
)
1067 new_modlist
= (struct module **) rb_malloc(sizeof(struct module *) *
1068 (max_mods
+ MODS_INCREMENT
));
1069 memcpy((void *) new_modlist
, (void *) modlist
, sizeof(struct module *) * num_mods
);
1072 modlist
= new_modlist
;
1073 max_mods
+= MODS_INCREMENT
;