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(MODPATH
);
133 mod_add_path(AUTOMODPATH
);
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(AUTOMODPATH
);
248 if(system_module_dir
== NULL
)
250 ilog(L_MAIN
, "Could not load modules from %s: %s", AUTOMODPATH
, strerror(errno
));
254 while ((ldirent
= readdir(system_module_dir
)) != NULL
)
259 len
= strlen(ldirent
->d_name
);
260 if(len
> module_ext_len
&& !strcasecmp(ldirent
->d_name
+ (len
- module_ext_len
), LT_MODULE_EXT
))
262 (void) snprintf(module_fq_name
, sizeof(module_fq_name
), "%s/%s", AUTOMODPATH
, ldirent
->d_name
);
263 (void) load_a_module(module_fq_name
, warn
, MAPI_ORIGIN_CORE
, 0);
267 (void) closedir(system_module_dir
);
270 /* load_core_modules()
274 * side effects - core modules are loaded, if any fail, kill ircd
277 load_core_modules(int warn
)
279 char module_name
[PATH_MAX
];
283 for (i
= 0; core_module_table
[i
]; i
++)
285 snprintf(module_name
, sizeof(module_name
), "%s/%s%s", MODPATH
,
286 core_module_table
[i
], LT_MODULE_EXT
);
288 if(load_a_module(module_name
, warn
, MAPI_ORIGIN_CORE
, 1) == -1)
291 "Error loading core module %s: terminating ircd",
292 core_module_table
[i
]);
305 load_one_module(const char *path
, int origin
, int coremodule
)
307 char modpath
[PATH_MAX
];
308 rb_dlink_node
*pathst
;
312 if (server_state_foreground
)
313 inotice("loading module %s ...", path
);
318 origin
= MAPI_ORIGIN_CORE
;
321 RB_DLINK_FOREACH(pathst
, mod_paths
.head
)
323 mpath
= pathst
->data
;
325 snprintf(modpath
, sizeof(modpath
), "%s/%s%s", mpath
, path
, LT_MODULE_EXT
);
326 if((strstr(modpath
, "../") == NULL
) && (strstr(modpath
, "/..") == NULL
))
328 if(stat(modpath
, &statbuf
) == 0)
330 if(S_ISREG(statbuf
.st_mode
))
332 /* Regular files only please */
333 return load_a_module(modpath
, 1, origin
, coremodule
);
340 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Cannot locate module %s", path
);
345 /* load a module .. */
347 mo_modload(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
349 if(!IsOperAdmin(source_p
))
351 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
352 me
.name
, source_p
->name
, "admin");
358 sendto_match_servs(source_p
, parv
[2], CAP_ENCAP
, NOCAPS
,
359 "ENCAP %s MODLOAD %s", parv
[2], parv
[1]);
360 if (match(parv
[2], me
.name
) == 0)
364 do_modload(source_p
, parv
[1]);
368 me_modload(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
370 if(!find_shared_conf(source_p
->username
, source_p
->host
, source_p
->servptr
->name
, SHARED_MODULE
))
372 sendto_one_notice(source_p
, ":*** You do not have an appropriate shared block "
373 "to load modules on this server.");
377 do_modload(source_p
, parv
[1]);
381 /* unload a module .. */
383 mo_modunload(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
385 if(!IsOperAdmin(source_p
))
387 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
388 me
.name
, source_p
->name
, "admin");
394 sendto_match_servs(source_p
, parv
[2], CAP_ENCAP
, NOCAPS
,
395 "ENCAP %s MODUNLOAD %s", parv
[2], parv
[1]);
396 if (match(parv
[2], me
.name
) == 0)
400 do_modunload(source_p
, parv
[1]);
404 me_modunload(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
406 if(!find_shared_conf(source_p
->username
, source_p
->host
, source_p
->servptr
->name
, SHARED_MODULE
))
408 sendto_one_notice(source_p
, ":*** You do not have an appropriate shared block "
409 "to load modules on this server.");
413 do_modunload(source_p
, parv
[1]);
416 /* unload and load in one! */
418 mo_modreload(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
420 if(!IsOperAdmin(source_p
))
422 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
423 me
.name
, source_p
->name
, "admin");
429 sendto_match_servs(source_p
, parv
[2], CAP_ENCAP
, NOCAPS
,
430 "ENCAP %s MODRELOAD %s", parv
[2], parv
[1]);
431 if (match(parv
[2], me
.name
) == 0)
435 do_modreload(source_p
, parv
[1]);
439 me_modreload(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
441 if(!find_shared_conf(source_p
->username
, source_p
->host
, source_p
->servptr
->name
, SHARED_MODULE
))
443 sendto_one_notice(source_p
, ":*** You do not have an appropriate shared block "
444 "to load modules on this server.");
448 do_modreload(source_p
, parv
[1]);
451 /* list modules .. */
453 mo_modlist(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
455 if(!IsOperAdmin(source_p
))
457 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
458 me
.name
, source_p
->name
, "admin");
464 sendto_match_servs(source_p
, parv
[2], CAP_ENCAP
, NOCAPS
,
465 "ENCAP %s MODLIST %s", parv
[2], parv
[1]);
466 if (match(parv
[2], me
.name
) == 0)
470 do_modlist(source_p
, parc
> 1 ? parv
[1] : 0);
474 me_modlist(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
476 if(!find_shared_conf(source_p
->username
, source_p
->host
, source_p
->servptr
->name
, SHARED_MODULE
))
478 sendto_one_notice(source_p
, ":*** You do not have an appropriate shared block "
479 "to load modules on this server.");
483 do_modlist(source_p
, parv
[1]);
486 /* unload and reload all modules */
488 mo_modrestart(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
490 if(!IsOperAdmin(source_p
))
492 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
493 me
.name
, source_p
->name
, "admin");
499 sendto_match_servs(source_p
, parv
[1], CAP_ENCAP
, NOCAPS
,
500 "ENCAP %s MODRESTART", parv
[1]);
501 if (match(parv
[1], me
.name
) == 0)
505 do_modrestart(source_p
);
509 me_modrestart(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
511 if(!find_shared_conf(source_p
->username
, source_p
->host
, source_p
->servptr
->name
, SHARED_MODULE
))
513 sendto_one_notice(source_p
, ":*** You do not have an appropriate shared block "
514 "to load modules on this server.");
518 do_modrestart(source_p
);
522 do_modload(struct Client
*source_p
, const char *module)
524 char *m_bn
= rb_basename(module);
527 if(findmodule_byname(m_bn
) != -1)
529 sendto_one_notice(source_p
, ":Module %s is already loaded", m_bn
);
534 origin
= strcmp(module, m_bn
) == 0 ? MAPI_ORIGIN_CORE
: MAPI_ORIGIN_EXTENSION
;
535 load_one_module(module, origin
, 0);
541 do_modunload(struct Client
*source_p
, const char *module)
544 char *m_bn
= rb_basename(module);
546 if((modindex
= findmodule_byname(m_bn
)) == -1)
548 sendto_one_notice(source_p
, ":Module %s is not loaded", m_bn
);
553 if(modlist
[modindex
]->core
== 1)
555 sendto_one_notice(source_p
, ":Module %s is a core module and may not be unloaded", m_bn
);
560 if(unload_one_module(m_bn
, 1) == -1)
562 sendto_one_notice(source_p
, ":Module %s is not loaded", m_bn
);
569 do_modreload(struct Client
*source_p
, const char *module)
573 char *m_bn
= rb_basename(module);
575 if((modindex
= findmodule_byname(m_bn
)) == -1)
577 sendto_one_notice(source_p
, ":Module %s is not loaded", m_bn
);
582 check_core
= modlist
[modindex
]->core
;
584 if(unload_one_module(m_bn
, 1) == -1)
586 sendto_one_notice(source_p
, ":Module %s is not loaded", m_bn
);
591 if((load_one_module(m_bn
, modlist
[modindex
]->origin
, check_core
) == -1) && check_core
)
593 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
594 "Error reloading core module: %s: terminating ircd", m_bn
);
595 ilog(L_MAIN
, "Error loading core module %s: terminating ircd", m_bn
);
603 do_modrestart(struct Client
*source_p
)
607 sendto_one_notice(source_p
, ":Reloading all modules");
611 unload_one_module(modlist
[0]->name
, 0);
614 load_core_modules(0);
617 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
618 "Module Restart: %d modules unloaded, %d modules loaded",
620 ilog(L_MAIN
, "Module Restart: %d modules unloaded, %d modules loaded", modnum
, num_mods
);
624 do_modlist(struct Client
*source_p
, const char *pattern
)
628 for (i
= 0; i
< num_mods
; i
++)
631 switch (modlist
[i
]->origin
)
633 case MAPI_ORIGIN_EXTENSION
:
634 origin
= "extension";
636 case MAPI_ORIGIN_CORE
:
646 if(match(pattern
, modlist
[i
]->name
))
648 sendto_one(source_p
, form_str(RPL_MODLIST
),
649 me
.name
, source_p
->name
,
651 (unsigned long)(uintptr_t)modlist
[i
]->address
, origin
,
652 modlist
[i
]->core
? " (core)" : "", modlist
[i
]->version
, modlist
[i
]->description
);
657 sendto_one(source_p
, form_str(RPL_MODLIST
),
658 me
.name
, source_p
->name
, modlist
[i
]->name
,
659 (unsigned long)(uintptr_t)modlist
[i
]->address
, origin
,
660 modlist
[i
]->core
? " (core)" : "", modlist
[i
]->version
, modlist
[i
]->description
);
664 sendto_one(source_p
, form_str(RPL_ENDOFMODLIST
), me
.name
, source_p
->name
);
667 static void increase_modlist(void);
669 #define MODS_INCREMENT 10
671 static char unknown_ver
[] = "<unknown>";
672 static char unknown_description
[] = "<none>";
674 /* unload_one_module()
676 * inputs - name of module to unload
677 * - 1 to say modules unloaded, 0 to not
678 * output - 0 if successful, -1 if error
679 * side effects - module is unloaded
682 unload_one_module(const char *name
, int warn
)
686 if((modindex
= findmodule_byname(name
)) == -1)
690 ** XXX - The type system in C does not allow direct conversion between
691 ** data and function pointers, but as it happens, most C compilers will
692 ** safely do this, however it is a theoretical overlow to cast as we
693 ** must do here. I have library functions to take care of this, but
694 ** despite being more "correct" for the C language, this is more
695 ** practical. Removing the abuse of the ability to cast ANY pointer
696 ** to and from an integer value here will break some compilers.
699 /* Left the comment in but the code isn't here any more -larne */
700 switch (modlist
[modindex
]->mapi_version
)
704 struct mapi_mheader_av1
*mheader
= modlist
[modindex
]->mapi_header
;
705 if(mheader
->mapi_command_list
)
708 for (m
= mheader
->mapi_command_list
; *m
; ++m
)
712 /* hook events are never removed, we simply lose the
713 * ability to call them --fl
715 if(mheader
->mapi_hfn_list
)
717 mapi_hfn_list_av1
*m
;
718 for (m
= mheader
->mapi_hfn_list
; m
->hapi_name
; ++m
)
719 remove_hook(m
->hapi_name
, m
->fn
);
722 if(mheader
->mapi_unregister
)
723 mheader
->mapi_unregister();
728 struct mapi_mheader_av2
*mheader
= modlist
[modindex
]->mapi_header
;
730 /* XXX duplicate code :( */
731 if(mheader
->mapi_command_list
)
734 for (m
= mheader
->mapi_command_list
; *m
; ++m
)
738 /* hook events are never removed, we simply lose the
739 * ability to call them --fl
741 if(mheader
->mapi_hfn_list
)
743 mapi_hfn_list_av1
*m
;
744 for (m
= mheader
->mapi_hfn_list
; m
->hapi_name
; ++m
)
745 remove_hook(m
->hapi_name
, m
->fn
);
748 if(mheader
->mapi_unregister
)
749 mheader
->mapi_unregister();
751 if(mheader
->mapi_cap_list
)
753 mapi_cap_list_av2
*m
;
754 for (m
= mheader
->mapi_cap_list
; m
->cap_name
; ++m
)
756 struct CapabilityIndex
*idx
;
758 switch (m
->cap_index
)
760 case MAPI_CAP_CLIENT
:
763 case MAPI_CAP_SERVER
:
767 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
768 "Unknown/unsupported CAP index found of type %d on capability %s when unloading %s",
769 m
->cap_index
, m
->cap_name
, modlist
[modindex
]->name
);
771 "Unknown/unsupported CAP index found of type %d on capability %s when unloading %s",
772 m
->cap_index
, m
->cap_name
, modlist
[modindex
]->name
);
776 capability_orphan(idx
, m
->cap_name
);
781 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
782 "Unknown/unsupported MAPI version %d when unloading %s!",
783 modlist
[modindex
]->mapi_version
, modlist
[modindex
]->name
);
784 ilog(L_MAIN
, "Unknown/unsupported MAPI version %d when unloading %s!",
785 modlist
[modindex
]->mapi_version
, modlist
[modindex
]->name
);
789 lt_dlclose(modlist
[modindex
]->address
);
791 rb_free(modlist
[modindex
]->name
);
792 rb_free(modlist
[modindex
]);
793 memmove(&modlist
[modindex
], &modlist
[modindex
+ 1],
794 sizeof(struct module *) * ((num_mods
- 1) - modindex
));
801 ilog(L_MAIN
, "Module %s unloaded", name
);
802 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Module %s unloaded", name
);
811 * inputs - path name of module, int to notice, int of origin, int of core
812 * output - -1 if error 0 if success
813 * side effects - loads a module if successful
816 load_a_module(const char *path
, int warn
, int origin
, int core
)
820 const char *ver
, *description
= NULL
;
824 mod_basename
= rb_basename(path
);
826 tmpptr
= lt_dlopenext(path
);
830 const char *err
= lt_dlerror();
832 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
833 "Error loading module %s: %s", mod_basename
, err
);
834 ilog(L_MAIN
, "Error loading module %s: %s", mod_basename
, err
);
835 rb_free(mod_basename
);
840 * _mheader is actually a struct mapi_mheader_*, but mapi_version
841 * is always the first member of this structure, so we treate it
842 * as a single int in order to determine the API version.
845 mapi_version
= (int *) (uintptr_t) lt_dlsym(tmpptr
, "_mheader");
846 if((mapi_version
== NULL
847 && (mapi_version
= (int *) (uintptr_t) lt_dlsym(tmpptr
, "__mheader")) == NULL
)
848 || MAPI_MAGIC(*mapi_version
) != MAPI_MAGIC_HDR
)
850 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
851 "Data format error: module %s has no MAPI header.",
853 ilog(L_MAIN
, "Data format error: module %s has no MAPI header.", mod_basename
);
854 (void) lt_dlclose(tmpptr
);
855 rb_free(mod_basename
);
859 switch (MAPI_VERSION(*mapi_version
))
863 struct mapi_mheader_av1
*mheader
= (struct mapi_mheader_av1
*)(void *)mapi_version
; /* see above */
864 if(mheader
->mapi_register
&& (mheader
->mapi_register() == -1))
866 ilog(L_MAIN
, "Module %s indicated failure during load.",
868 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
869 "Module %s indicated failure during load.",
872 rb_free(mod_basename
);
875 if(mheader
->mapi_command_list
)
878 for (m
= mheader
->mapi_command_list
; *m
; ++m
)
882 if(mheader
->mapi_hook_list
)
885 for (m
= mheader
->mapi_hook_list
; m
->hapi_name
; ++m
)
886 *m
->hapi_id
= register_hook(m
->hapi_name
);
889 if(mheader
->mapi_hfn_list
)
891 mapi_hfn_list_av1
*m
;
892 for (m
= mheader
->mapi_hfn_list
; m
->hapi_name
; ++m
)
893 add_hook(m
->hapi_name
, m
->fn
);
896 ver
= mheader
->mapi_module_version
;
901 struct mapi_mheader_av2
*mheader
= (struct mapi_mheader_av2
*)(void *)mapi_version
; /* see above */
903 /* XXX duplicated code :( */
904 if(mheader
->mapi_register
&& (mheader
->mapi_register() == -1))
906 ilog(L_MAIN
, "Module %s indicated failure during load.",
908 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
909 "Module %s indicated failure during load.",
912 rb_free(mod_basename
);
916 /* Basic date code checks
918 * Don't make them fatal, but do complain about differences within a certain time frame.
919 * Later on if there are major API changes we can add fatal checks.
922 if(mheader
->mapi_datecode
!= datecode
&& mheader
->mapi_datecode
> 0)
924 long int delta
= datecode
- mheader
->mapi_datecode
;
925 if (delta
> MOD_WARN_DELTA
)
928 iwarn("Module %s build date is out of sync with ircd build date by %ld days, expect problems",
929 mod_basename
, delta
);
930 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
931 "Module %s build date is out of sync with ircd build date by %ld days, expect problems",
932 mod_basename
, delta
);
936 if(mheader
->mapi_command_list
)
939 for (m
= mheader
->mapi_command_list
; *m
; ++m
)
943 if(mheader
->mapi_hook_list
)
946 for (m
= mheader
->mapi_hook_list
; m
->hapi_name
; ++m
)
947 *m
->hapi_id
= register_hook(m
->hapi_name
);
950 if(mheader
->mapi_hfn_list
)
952 mapi_hfn_list_av1
*m
;
953 for (m
= mheader
->mapi_hfn_list
; m
->hapi_name
; ++m
)
954 add_hook(m
->hapi_name
, m
->fn
);
957 /* New in MAPI v2 - version replacement */
958 ver
= mheader
->mapi_module_version
? mheader
->mapi_module_version
: ircd_version
;
959 description
= mheader
->mapi_module_description
;
961 if(mheader
->mapi_cap_list
)
963 mapi_cap_list_av2
*m
;
964 for (m
= mheader
->mapi_cap_list
; m
->cap_name
; ++m
)
966 struct CapabilityIndex
*idx
;
969 switch (m
->cap_index
)
971 case MAPI_CAP_CLIENT
:
974 case MAPI_CAP_SERVER
:
978 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
979 "Unknown/unsupported CAP index found of type %d on capability %s when loading %s",
980 m
->cap_index
, m
->cap_name
, mod_basename
);
982 "Unknown/unsupported CAP index found of type %d on capability %s when loading %s",
983 m
->cap_index
, m
->cap_name
, mod_basename
);
987 result
= capability_put(idx
, m
->cap_name
, m
->cap_ownerdata
);
988 if (m
->cap_id
!= NULL
)
989 *(m
->cap_id
) = result
;
996 ilog(L_MAIN
, "Module %s has unknown/unsupported MAPI version %d.",
997 mod_basename
, MAPI_VERSION(*mapi_version
));
998 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
999 "Module %s has unknown/unsupported MAPI version %d.",
1000 mod_basename
, *mapi_version
);
1002 rb_free(mod_basename
);
1009 if(description
== NULL
)
1010 description
= unknown_description
;
1014 modlist
[num_mods
] = rb_malloc(sizeof(struct module));
1015 modlist
[num_mods
]->address
= tmpptr
;
1016 modlist
[num_mods
]->version
= ver
;
1017 modlist
[num_mods
]->description
= description
;
1018 modlist
[num_mods
]->core
= core
;
1019 modlist
[num_mods
]->name
= rb_strdup(mod_basename
);
1020 modlist
[num_mods
]->mapi_header
= mapi_version
;
1021 modlist
[num_mods
]->mapi_version
= MAPI_VERSION(*mapi_version
);
1022 modlist
[num_mods
]->origin
= origin
;
1031 case MAPI_ORIGIN_EXTENSION
:
1034 case MAPI_ORIGIN_CORE
:
1042 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1043 "Module %s [version: %s; MAPI version: %d; origin: %s; description: \"%s\"] loaded at %p",
1044 mod_basename
, ver
, MAPI_VERSION(*mapi_version
), o
, description
,
1046 ilog(L_MAIN
, "Module %s [version: %s; MAPI version: %d; origin: %s; description: \"%s\"] loaded at %p",
1047 mod_basename
, ver
, MAPI_VERSION(*mapi_version
), o
, description
, (void *) tmpptr
);
1049 rb_free(mod_basename
);
1058 * side effects - expand the size of modlist if necessary
1061 increase_modlist(void)
1063 struct module **new_modlist
= NULL
;
1065 if((num_mods
+ 1) < max_mods
)
1068 new_modlist
= (struct module **) rb_malloc(sizeof(struct module *) *
1069 (max_mods
+ MODS_INCREMENT
));
1070 memcpy((void *) new_modlist
, (void *) modlist
, sizeof(struct module *) * num_mods
);
1073 modlist
= new_modlist
;
1074 max_mods
+= MODS_INCREMENT
;