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
)
210 for (i
= 0; i
< num_mods
; i
++)
212 if(!irccmp(modlist
[i
]->name
, name
))
218 /* load_all_modules()
225 load_all_modules(int warn
)
227 DIR *system_module_dir
= NULL
;
228 struct dirent
*ldirent
= NULL
;
229 char module_fq_name
[PATH_MAX
+ 1];
230 size_t module_ext_len
= strlen(LT_MODULE_EXT
);
234 modlist
= (struct module **) rb_malloc(sizeof(struct module *) * (MODS_INCREMENT
));
236 max_mods
= MODS_INCREMENT
;
238 system_module_dir
= opendir(AUTOMODPATH
);
240 if(system_module_dir
== NULL
)
242 ilog(L_MAIN
, "Could not load modules from %s: %s", AUTOMODPATH
, strerror(errno
));
246 while ((ldirent
= readdir(system_module_dir
)) != NULL
)
251 len
= strlen(ldirent
->d_name
);
252 if(len
> module_ext_len
&& !strcasecmp(ldirent
->d_name
+ (len
- module_ext_len
), LT_MODULE_EXT
))
254 (void) snprintf(module_fq_name
, sizeof(module_fq_name
), "%s/%s", AUTOMODPATH
, ldirent
->d_name
);
255 (void) load_a_module(module_fq_name
, warn
, MAPI_ORIGIN_CORE
, 0);
259 (void) closedir(system_module_dir
);
262 /* load_core_modules()
266 * side effects - core modules are loaded, if any fail, kill ircd
269 load_core_modules(int warn
)
271 char module_name
[PATH_MAX
];
275 for (i
= 0; core_module_table
[i
]; i
++)
277 snprintf(module_name
, sizeof(module_name
), "%s/%s", MODPATH
,
278 core_module_table
[i
]);
280 if(load_a_module(module_name
, warn
, MAPI_ORIGIN_CORE
, 1) == -1)
283 "Error loading core module %s: terminating ircd",
284 core_module_table
[i
]);
297 load_one_module(const char *path
, int origin
, int coremodule
)
299 char modpath
[PATH_MAX
];
300 rb_dlink_node
*pathst
;
305 if (server_state_foreground
)
306 inotice("loading module %s ...", path
);
311 origin
= MAPI_ORIGIN_CORE
;
314 RB_DLINK_FOREACH(pathst
, mod_paths
.head
)
316 mpath
= pathst
->data
;
318 snprintf(modpath
, sizeof(modpath
), "%s/%s", mpath
, path
);
319 if((strstr(modpath
, "../") == NULL
) && (strstr(modpath
, "/..") == NULL
))
321 if(stat(modpath
, &statbuf
) == 0)
323 if(S_ISREG(statbuf
.st_mode
))
325 /* Regular files only please */
326 return load_a_module(modpath
, 1, origin
, coremodule
);
333 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Cannot locate module %s", path
);
338 /* load a module .. */
340 mo_modload(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
342 if(!IsOperAdmin(source_p
))
344 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
345 me
.name
, source_p
->name
, "admin");
351 sendto_match_servs(source_p
, parv
[2], CAP_ENCAP
, NOCAPS
,
352 "ENCAP %s MODLOAD %s", parv
[2], parv
[1]);
353 if (match(parv
[2], me
.name
) == 0)
357 do_modload(source_p
, parv
[1]);
361 me_modload(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
363 if(!find_shared_conf(source_p
->username
, source_p
->host
, source_p
->servptr
->name
, SHARED_MODULE
))
365 sendto_one_notice(source_p
, ":*** You do not have an appropriate shared block "
366 "to load modules on this server.");
370 do_modload(source_p
, parv
[1]);
374 /* unload a module .. */
376 mo_modunload(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
378 if(!IsOperAdmin(source_p
))
380 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
381 me
.name
, source_p
->name
, "admin");
387 sendto_match_servs(source_p
, parv
[2], CAP_ENCAP
, NOCAPS
,
388 "ENCAP %s MODUNLOAD %s", parv
[2], parv
[1]);
389 if (match(parv
[2], me
.name
) == 0)
393 do_modunload(source_p
, parv
[1]);
397 me_modunload(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
399 if(!find_shared_conf(source_p
->username
, source_p
->host
, source_p
->servptr
->name
, SHARED_MODULE
))
401 sendto_one_notice(source_p
, ":*** You do not have an appropriate shared block "
402 "to load modules on this server.");
406 do_modunload(source_p
, parv
[1]);
409 /* unload and load in one! */
411 mo_modreload(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
413 if(!IsOperAdmin(source_p
))
415 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
416 me
.name
, source_p
->name
, "admin");
422 sendto_match_servs(source_p
, parv
[2], CAP_ENCAP
, NOCAPS
,
423 "ENCAP %s MODRELOAD %s", parv
[2], parv
[1]);
424 if (match(parv
[2], me
.name
) == 0)
428 do_modreload(source_p
, parv
[1]);
432 me_modreload(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
434 if(!find_shared_conf(source_p
->username
, source_p
->host
, source_p
->servptr
->name
, SHARED_MODULE
))
436 sendto_one_notice(source_p
, ":*** You do not have an appropriate shared block "
437 "to load modules on this server.");
441 do_modreload(source_p
, parv
[1]);
444 /* list modules .. */
446 mo_modlist(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
448 if(!IsOperAdmin(source_p
))
450 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
451 me
.name
, source_p
->name
, "admin");
457 sendto_match_servs(source_p
, parv
[2], CAP_ENCAP
, NOCAPS
,
458 "ENCAP %s MODLIST %s", parv
[2], parv
[1]);
459 if (match(parv
[2], me
.name
) == 0)
463 do_modlist(source_p
, parc
> 1 ? parv
[1] : 0);
467 me_modlist(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
469 if(!find_shared_conf(source_p
->username
, source_p
->host
, source_p
->servptr
->name
, SHARED_MODULE
))
471 sendto_one_notice(source_p
, ":*** You do not have an appropriate shared block "
472 "to load modules on this server.");
476 do_modlist(source_p
, parv
[1]);
479 /* unload and reload all modules */
481 mo_modrestart(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
483 if(!IsOperAdmin(source_p
))
485 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
486 me
.name
, source_p
->name
, "admin");
492 sendto_match_servs(source_p
, parv
[1], CAP_ENCAP
, NOCAPS
,
493 "ENCAP %s MODRESTART", parv
[1]);
494 if (match(parv
[1], me
.name
) == 0)
498 do_modrestart(source_p
);
502 me_modrestart(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
504 if(!find_shared_conf(source_p
->username
, source_p
->host
, source_p
->servptr
->name
, SHARED_MODULE
))
506 sendto_one_notice(source_p
, ":*** You do not have an appropriate shared block "
507 "to load modules on this server.");
511 do_modrestart(source_p
);
515 do_modload(struct Client
*source_p
, const char *module)
517 char *m_bn
= rb_basename(module);
520 if(findmodule_byname(m_bn
) != -1)
522 sendto_one_notice(source_p
, ":Module %s is already loaded", m_bn
);
527 origin
= strcmp(module, m_bn
) == 0 ? MAPI_ORIGIN_CORE
: MAPI_ORIGIN_EXTENSION
;
528 load_one_module(module, origin
, 0);
534 do_modunload(struct Client
*source_p
, const char *module)
537 char *m_bn
= rb_basename(module);
539 if((modindex
= findmodule_byname(m_bn
)) == -1)
541 sendto_one_notice(source_p
, ":Module %s is not loaded", m_bn
);
546 if(modlist
[modindex
]->core
== 1)
548 sendto_one_notice(source_p
, ":Module %s is a core module and may not be unloaded", m_bn
);
553 if(unload_one_module(m_bn
, 1) == -1)
555 sendto_one_notice(source_p
, ":Module %s is not loaded", m_bn
);
562 do_modreload(struct Client
*source_p
, const char *module)
566 char *m_bn
= rb_basename(module);
568 if((modindex
= findmodule_byname(m_bn
)) == -1)
570 sendto_one_notice(source_p
, ":Module %s is not loaded", m_bn
);
575 check_core
= modlist
[modindex
]->core
;
577 if(unload_one_module(m_bn
, 1) == -1)
579 sendto_one_notice(source_p
, ":Module %s is not loaded", m_bn
);
584 if((load_one_module(m_bn
, modlist
[modindex
]->origin
, check_core
) == -1) && check_core
)
586 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
587 "Error reloading core module: %s: terminating ircd", m_bn
);
588 ilog(L_MAIN
, "Error loading core module %s: terminating ircd", m_bn
);
596 do_modrestart(struct Client
*source_p
)
600 sendto_one_notice(source_p
, ":Reloading all modules");
604 unload_one_module(modlist
[0]->name
, 0);
607 load_core_modules(0);
610 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
611 "Module Restart: %d modules unloaded, %d modules loaded",
613 ilog(L_MAIN
, "Module Restart: %d modules unloaded, %d modules loaded", modnum
, num_mods
);
617 do_modlist(struct Client
*source_p
, const char *pattern
)
621 for (i
= 0; i
< num_mods
; i
++)
624 switch (modlist
[i
]->origin
)
626 case MAPI_ORIGIN_EXTENSION
:
627 origin
= "extension";
629 case MAPI_ORIGIN_CORE
:
639 if(match(pattern
, modlist
[i
]->name
))
641 sendto_one(source_p
, form_str(RPL_MODLIST
),
642 me
.name
, source_p
->name
,
644 (unsigned long)(uintptr_t)modlist
[i
]->address
, origin
,
645 modlist
[i
]->core
? " (core)" : "", modlist
[i
]->version
, modlist
[i
]->description
);
650 sendto_one(source_p
, form_str(RPL_MODLIST
),
651 me
.name
, source_p
->name
, modlist
[i
]->name
,
652 (unsigned long)(uintptr_t)modlist
[i
]->address
, origin
,
653 modlist
[i
]->core
? " (core)" : "", modlist
[i
]->version
, modlist
[i
]->description
);
657 sendto_one(source_p
, form_str(RPL_ENDOFMODLIST
), me
.name
, source_p
->name
);
660 static void increase_modlist(void);
662 #define MODS_INCREMENT 10
664 static char unknown_ver
[] = "<unknown>";
665 static char unknown_description
[] = "<none>";
667 /* unload_one_module()
669 * inputs - name of module to unload
670 * - 1 to say modules unloaded, 0 to not
671 * output - 0 if successful, -1 if error
672 * side effects - module is unloaded
675 unload_one_module(const char *name
, int warn
)
679 if((modindex
= findmodule_byname(name
)) == -1)
683 ** XXX - The type system in C does not allow direct conversion between
684 ** data and function pointers, but as it happens, most C compilers will
685 ** safely do this, however it is a theoretical overlow to cast as we
686 ** must do here. I have library functions to take care of this, but
687 ** despite being more "correct" for the C language, this is more
688 ** practical. Removing the abuse of the ability to cast ANY pointer
689 ** to and from an integer value here will break some compilers.
692 /* Left the comment in but the code isn't here any more -larne */
693 switch (modlist
[modindex
]->mapi_version
)
697 struct mapi_mheader_av1
*mheader
= modlist
[modindex
]->mapi_header
;
698 if(mheader
->mapi_command_list
)
701 for (m
= mheader
->mapi_command_list
; *m
; ++m
)
705 /* hook events are never removed, we simply lose the
706 * ability to call them --fl
708 if(mheader
->mapi_hfn_list
)
710 mapi_hfn_list_av1
*m
;
711 for (m
= mheader
->mapi_hfn_list
; m
->hapi_name
; ++m
)
712 remove_hook(m
->hapi_name
, m
->fn
);
715 if(mheader
->mapi_unregister
)
716 mheader
->mapi_unregister();
721 struct mapi_mheader_av2
*mheader
= modlist
[modindex
]->mapi_header
;
723 /* XXX duplicate code :( */
724 if(mheader
->mapi_command_list
)
727 for (m
= mheader
->mapi_command_list
; *m
; ++m
)
731 /* hook events are never removed, we simply lose the
732 * ability to call them --fl
734 if(mheader
->mapi_hfn_list
)
736 mapi_hfn_list_av1
*m
;
737 for (m
= mheader
->mapi_hfn_list
; m
->hapi_name
; ++m
)
738 remove_hook(m
->hapi_name
, m
->fn
);
741 if(mheader
->mapi_unregister
)
742 mheader
->mapi_unregister();
744 if(mheader
->mapi_cap_list
)
746 mapi_cap_list_av2
*m
;
747 for (m
= mheader
->mapi_cap_list
; m
->cap_name
; ++m
)
749 struct CapabilityIndex
*idx
;
751 switch (m
->cap_index
)
753 case MAPI_CAP_CLIENT
:
756 case MAPI_CAP_SERVER
:
760 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
761 "Unknown/unsupported CAP index found of type %d on capability %s when unloading %s",
762 m
->cap_index
, m
->cap_name
, modlist
[modindex
]->name
);
764 "Unknown/unsupported CAP index found of type %d on capability %s when unloading %s",
765 m
->cap_index
, m
->cap_name
, modlist
[modindex
]->name
);
769 capability_orphan(idx
, m
->cap_name
);
774 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
775 "Unknown/unsupported MAPI version %d when unloading %s!",
776 modlist
[modindex
]->mapi_version
, modlist
[modindex
]->name
);
777 ilog(L_MAIN
, "Unknown/unsupported MAPI version %d when unloading %s!",
778 modlist
[modindex
]->mapi_version
, modlist
[modindex
]->name
);
782 lt_dlclose(modlist
[modindex
]->address
);
784 rb_free(modlist
[modindex
]->name
);
785 rb_free(modlist
[modindex
]);
786 memmove(&modlist
[modindex
], &modlist
[modindex
+ 1],
787 sizeof(struct module *) * ((num_mods
- 1) - modindex
));
794 ilog(L_MAIN
, "Module %s unloaded", name
);
795 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Module %s unloaded", name
);
804 * inputs - path name of module, int to notice, int of origin, int of core
805 * output - -1 if error 0 if success
806 * side effects - loads a module if successful
809 load_a_module(const char *path
, int warn
, int origin
, int core
)
813 const char *ver
, *description
= NULL
;
817 mod_basename
= rb_basename(path
);
819 tmpptr
= lt_dlopenext(path
);
823 const char *err
= lt_dlerror();
825 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
826 "Error loading module %s: %s", mod_basename
, err
);
827 ilog(L_MAIN
, "Error loading module %s: %s", mod_basename
, err
);
828 rb_free(mod_basename
);
833 * _mheader is actually a struct mapi_mheader_*, but mapi_version
834 * is always the first member of this structure, so we treate it
835 * as a single int in order to determine the API version.
838 mapi_version
= (int *) (uintptr_t) lt_dlsym(tmpptr
, "_mheader");
839 if((mapi_version
== NULL
840 && (mapi_version
= (int *) (uintptr_t) lt_dlsym(tmpptr
, "__mheader")) == NULL
)
841 || MAPI_MAGIC(*mapi_version
) != MAPI_MAGIC_HDR
)
843 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
844 "Data format error: module %s has no MAPI header.",
846 ilog(L_MAIN
, "Data format error: module %s has no MAPI header.", mod_basename
);
847 (void) lt_dlclose(tmpptr
);
848 rb_free(mod_basename
);
852 switch (MAPI_VERSION(*mapi_version
))
856 struct mapi_mheader_av1
*mheader
= (struct mapi_mheader_av1
*)(void *)mapi_version
; /* see above */
857 if(mheader
->mapi_register
&& (mheader
->mapi_register() == -1))
859 ilog(L_MAIN
, "Module %s indicated failure during load.",
861 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
862 "Module %s indicated failure during load.",
865 rb_free(mod_basename
);
868 if(mheader
->mapi_command_list
)
871 for (m
= mheader
->mapi_command_list
; *m
; ++m
)
875 if(mheader
->mapi_hook_list
)
878 for (m
= mheader
->mapi_hook_list
; m
->hapi_name
; ++m
)
879 *m
->hapi_id
= register_hook(m
->hapi_name
);
882 if(mheader
->mapi_hfn_list
)
884 mapi_hfn_list_av1
*m
;
885 for (m
= mheader
->mapi_hfn_list
; m
->hapi_name
; ++m
)
886 add_hook(m
->hapi_name
, m
->fn
);
889 ver
= mheader
->mapi_module_version
;
894 struct mapi_mheader_av2
*mheader
= (struct mapi_mheader_av2
*)(void *)mapi_version
; /* see above */
896 /* XXX duplicated code :( */
897 if(mheader
->mapi_register
&& (mheader
->mapi_register() == -1))
899 ilog(L_MAIN
, "Module %s indicated failure during load.",
901 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
902 "Module %s indicated failure during load.",
905 rb_free(mod_basename
);
909 /* Basic date code checks
911 * Don't make them fatal, but do complain about differences within a certain time frame.
912 * Later on if there are major API changes we can add fatal checks.
915 if(mheader
->mapi_datecode
!= datecode
&& mheader
->mapi_datecode
> 0)
917 long int delta
= datecode
- mheader
->mapi_datecode
;
918 if (delta
> MOD_WARN_DELTA
)
921 iwarn("Module %s build date is out of sync with ircd build date by %ld days, expect problems",
922 mod_basename
, delta
);
923 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
924 "Module %s build date is out of sync with ircd build date by %ld days, expect problems",
925 mod_basename
, delta
);
929 if(mheader
->mapi_command_list
)
932 for (m
= mheader
->mapi_command_list
; *m
; ++m
)
936 if(mheader
->mapi_hook_list
)
939 for (m
= mheader
->mapi_hook_list
; m
->hapi_name
; ++m
)
940 *m
->hapi_id
= register_hook(m
->hapi_name
);
943 if(mheader
->mapi_hfn_list
)
945 mapi_hfn_list_av1
*m
;
946 for (m
= mheader
->mapi_hfn_list
; m
->hapi_name
; ++m
)
947 add_hook(m
->hapi_name
, m
->fn
);
950 /* New in MAPI v2 - version replacement */
951 ver
= mheader
->mapi_module_version
? mheader
->mapi_module_version
: ircd_version
;
952 description
= mheader
->mapi_module_description
;
954 if(mheader
->mapi_cap_list
)
956 mapi_cap_list_av2
*m
;
957 for (m
= mheader
->mapi_cap_list
; m
->cap_name
; ++m
)
959 struct CapabilityIndex
*idx
;
962 switch (m
->cap_index
)
964 case MAPI_CAP_CLIENT
:
967 case MAPI_CAP_SERVER
:
971 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
972 "Unknown/unsupported CAP index found of type %d on capability %s when loading %s",
973 m
->cap_index
, m
->cap_name
, mod_basename
);
975 "Unknown/unsupported CAP index found of type %d on capability %s when loading %s",
976 m
->cap_index
, m
->cap_name
, mod_basename
);
980 result
= capability_put(idx
, m
->cap_name
, m
->cap_ownerdata
);
981 if (m
->cap_id
!= NULL
)
982 *(m
->cap_id
) = result
;
989 ilog(L_MAIN
, "Module %s has unknown/unsupported MAPI version %d.",
990 mod_basename
, MAPI_VERSION(*mapi_version
));
991 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
992 "Module %s has unknown/unsupported MAPI version %d.",
993 mod_basename
, *mapi_version
);
995 rb_free(mod_basename
);
1002 if(description
== NULL
)
1003 description
= unknown_description
;
1007 modlist
[num_mods
] = rb_malloc(sizeof(struct module));
1008 modlist
[num_mods
]->address
= tmpptr
;
1009 modlist
[num_mods
]->version
= ver
;
1010 modlist
[num_mods
]->description
= description
;
1011 modlist
[num_mods
]->core
= core
;
1012 modlist
[num_mods
]->name
= rb_strdup(mod_basename
);
1013 modlist
[num_mods
]->mapi_header
= mapi_version
;
1014 modlist
[num_mods
]->mapi_version
= MAPI_VERSION(*mapi_version
);
1015 modlist
[num_mods
]->origin
= origin
;
1024 case MAPI_ORIGIN_EXTENSION
:
1027 case MAPI_ORIGIN_CORE
:
1035 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1036 "Module %s [version: %s; MAPI version: %d; origin: %s; description: \"%s\"] loaded at 0x%lx",
1037 mod_basename
, ver
, MAPI_VERSION(*mapi_version
), o
, description
,
1038 (unsigned long) tmpptr
);
1039 ilog(L_MAIN
, "Module %s [version: %s; MAPI version: %d; origin: %s; description: \"%s\"] loaded at 0x%lx",
1040 mod_basename
, ver
, MAPI_VERSION(*mapi_version
), o
, description
, (unsigned long) tmpptr
);
1042 rb_free(mod_basename
);
1051 * side effects - expand the size of modlist if necessary
1054 increase_modlist(void)
1056 struct module **new_modlist
= NULL
;
1058 if((num_mods
+ 1) < max_mods
)
1061 new_modlist
= (struct module **) rb_malloc(sizeof(struct module *) *
1062 (max_mods
+ MODS_INCREMENT
));
1063 memcpy((void *) new_modlist
, (void *) modlist
, sizeof(struct module *) * num_mods
);
1066 modlist
= new_modlist
;
1067 max_mods
+= MODS_INCREMENT
;