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"
42 struct module **modlist
= NULL
;
44 static const char *core_module_table
[] = {
61 #define MOD_WARN_DELTA (90 * 86400) /* time in seconds, 86400 seconds in a day */
63 #define MODS_INCREMENT 10
65 int max_mods
= MODS_INCREMENT
;
67 static rb_dlink_list mod_paths
;
69 static int mo_modload(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
70 static int mo_modlist(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
71 static int mo_modreload(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
72 static int mo_modunload(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
73 static int mo_modrestart(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
75 static int me_modload(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
76 static int me_modlist(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
77 static int me_modreload(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
78 static int me_modunload(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
79 static int me_modrestart(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
81 static int do_modload(struct Client
*, const char *);
82 static int do_modunload(struct Client
*, const char *);
83 static int do_modreload(struct Client
*, const char *);
84 static int do_modlist(struct Client
*, const char *);
85 static int do_modrestart(struct Client
*);
87 struct Message modload_msgtab
= {
88 "MODLOAD", 0, 0, 0, 0,
89 {mg_unreg
, mg_not_oper
, mg_ignore
, mg_ignore
, {me_modload
, 2}, {mo_modload
, 2}}
92 struct Message modunload_msgtab
= {
93 "MODUNLOAD", 0, 0, 0, 0,
94 {mg_unreg
, mg_not_oper
, mg_ignore
, mg_ignore
, {me_modunload
, 2}, {mo_modunload
, 2}}
97 struct Message modreload_msgtab
= {
98 "MODRELOAD", 0, 0, 0, 0,
99 {mg_unreg
, mg_not_oper
, mg_ignore
, mg_ignore
, {me_modreload
, 2}, {mo_modreload
, 2}}
102 struct Message modlist_msgtab
= {
103 "MODLIST", 0, 0, 0, 0,
104 {mg_unreg
, mg_not_oper
, mg_ignore
, mg_ignore
, {me_modlist
, 0}, {mo_modlist
, 0}}
107 struct Message modrestart_msgtab
= {
108 "MODRESTART", 0, 0, 0, 0,
109 {mg_unreg
, mg_not_oper
, mg_ignore
, mg_ignore
, {me_modrestart
, 0}, {mo_modrestart
, 0}}
117 ilog(L_MAIN
, "lt_dlinit failed");
121 mod_add_cmd(&modload_msgtab
);
122 mod_add_cmd(&modunload_msgtab
);
123 mod_add_cmd(&modreload_msgtab
);
124 mod_add_cmd(&modlist_msgtab
);
125 mod_add_cmd(&modrestart_msgtab
);
127 /* Add the default paths we look in to the module system --nenolod */
128 mod_add_path(MODPATH
);
129 mod_add_path(AUTOMODPATH
);
136 * side effects - returns a module path from path
139 mod_find_path(const char *path
)
144 RB_DLINK_FOREACH(ptr
, mod_paths
.head
)
148 if(!strcmp(path
, mpath
))
159 * side effects - adds path to list
162 mod_add_path(const char *path
)
166 if(mod_find_path(path
))
169 pathst
= rb_strdup(path
);
170 rb_dlinkAddAlloc(pathst
, &mod_paths
);
177 * side effects - clear the lists of paths
180 mod_clear_paths(void)
182 rb_dlink_node
*ptr
, *next_ptr
;
184 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, mod_paths
.head
)
187 rb_free_rb_dlink_node(ptr
);
190 mod_paths
.head
= mod_paths
.tail
= NULL
;
191 mod_paths
.length
= 0;
202 findmodule_byname(const char *name
)
206 for (i
= 0; i
< num_mods
; i
++)
208 if(!irccmp(modlist
[i
]->name
, name
))
214 /* load_all_modules()
221 load_all_modules(int warn
)
223 DIR *system_module_dir
= NULL
;
224 struct dirent
*ldirent
= NULL
;
225 char module_fq_name
[PATH_MAX
+ 1];
230 modlist
= (struct module **) rb_malloc(sizeof(struct module *) * (MODS_INCREMENT
));
232 max_mods
= MODS_INCREMENT
;
234 system_module_dir
= opendir(AUTOMODPATH
);
236 if(system_module_dir
== NULL
)
238 ilog(L_MAIN
, "Could not load modules from %s: %s", AUTOMODPATH
, strerror(errno
));
242 while ((ldirent
= readdir(system_module_dir
)) != NULL
)
244 len
= strlen(ldirent
->d_name
);
245 if((len
> 3) && !strcmp(ldirent
->d_name
+len
-3, ".la"))
247 (void) snprintf(module_fq_name
, sizeof(module_fq_name
), "%s/%s", AUTOMODPATH
, ldirent
->d_name
);
248 (void) load_a_module(module_fq_name
, warn
, MAPI_ORIGIN_CORE
, 0);
252 (void) closedir(system_module_dir
);
255 /* load_core_modules()
259 * side effects - core modules are loaded, if any fail, kill ircd
262 load_core_modules(int warn
)
264 char module_name
[PATH_MAX
];
268 for (i
= 0; core_module_table
[i
]; i
++)
270 snprintf(module_name
, sizeof(module_name
), "%s/%s%s", MODPATH
,
271 core_module_table
[i
], ".la");
273 if(load_a_module(module_name
, warn
, MAPI_ORIGIN_CORE
, 1) == -1)
276 "Error loading core module %s%s: terminating ircd",
277 core_module_table
[i
], ".la");
290 load_one_module(const char *path
, int origin
, int coremodule
)
292 char modpath
[PATH_MAX
];
293 rb_dlink_node
*pathst
;
298 if (server_state_foreground
== 1)
299 inotice("loading module %s ...", path
);
304 origin
= MAPI_ORIGIN_CORE
;
307 RB_DLINK_FOREACH(pathst
, mod_paths
.head
)
309 mpath
= pathst
->data
;
311 snprintf(modpath
, sizeof(modpath
), "%s/%s", mpath
, path
);
312 if((strstr(modpath
, "../") == NULL
) && (strstr(modpath
, "/..") == NULL
))
314 if(stat(modpath
, &statbuf
) == 0)
316 if(S_ISREG(statbuf
.st_mode
))
318 /* Regular files only please */
319 return load_a_module(modpath
, 1, origin
, coremodule
);
326 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Cannot locate module %s", path
);
331 /* load a module .. */
333 mo_modload(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
335 if(!IsOperAdmin(source_p
))
337 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
338 me
.name
, source_p
->name
, "admin");
344 sendto_match_servs(source_p
, parv
[2], CAP_ENCAP
, NOCAPS
,
345 "ENCAP %s MODLOAD %s", parv
[2], parv
[1]);
346 if (match(parv
[2], me
.name
) == 0)
350 return do_modload(source_p
, parv
[1]);
354 me_modload(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
356 if(!find_shared_conf(source_p
->username
, source_p
->host
, source_p
->servptr
->name
, SHARED_MODULE
))
358 sendto_one_notice(source_p
, ":*** You do not have an appropriate shared block "
359 "to load modules on this server.");
363 return do_modload(source_p
, parv
[1]);
367 do_modload(struct Client
*source_p
, const char *module)
369 char *m_bn
= rb_basename(module);
372 if(findmodule_byname(m_bn
) != -1)
374 sendto_one_notice(source_p
, ":Module %s is already loaded", m_bn
);
379 origin
= strcmp(module, m_bn
) == 0 ? MAPI_ORIGIN_CORE
: MAPI_ORIGIN_EXTENSION
;
380 load_one_module(module, origin
, 0);
388 /* unload a module .. */
390 mo_modunload(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
392 if(!IsOperAdmin(source_p
))
394 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
395 me
.name
, source_p
->name
, "admin");
401 sendto_match_servs(source_p
, parv
[2], CAP_ENCAP
, NOCAPS
,
402 "ENCAP %s MODUNLOAD %s", parv
[2], parv
[1]);
403 if (match(parv
[2], me
.name
) == 0)
407 return do_modunload(source_p
, parv
[1]);
411 me_modunload(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
413 if(!find_shared_conf(source_p
->username
, source_p
->host
, source_p
->servptr
->name
, SHARED_MODULE
))
415 sendto_one_notice(source_p
, ":*** You do not have an appropriate shared block "
416 "to load modules on this server.");
420 return do_modunload(source_p
, parv
[1]);
424 do_modunload(struct Client
*source_p
, const char *module)
427 char *m_bn
= rb_basename(module);
429 if((modindex
= findmodule_byname(m_bn
)) == -1)
431 sendto_one_notice(source_p
, ":Module %s is not loaded", m_bn
);
436 if(modlist
[modindex
]->core
== 1)
438 sendto_one_notice(source_p
, ":Module %s is a core module and may not be unloaded", m_bn
);
443 if(unload_one_module(m_bn
, 1) == -1)
445 sendto_one_notice(source_p
, ":Module %s is not loaded", m_bn
);
452 /* unload and load in one! */
454 mo_modreload(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
456 if(!IsOperAdmin(source_p
))
458 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
459 me
.name
, source_p
->name
, "admin");
465 sendto_match_servs(source_p
, parv
[2], CAP_ENCAP
, NOCAPS
,
466 "ENCAP %s MODRELOAD %s", parv
[2], parv
[1]);
467 if (match(parv
[2], me
.name
) == 0)
471 return do_modreload(source_p
, parv
[1]);
475 me_modreload(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
477 if(!find_shared_conf(source_p
->username
, source_p
->host
, source_p
->servptr
->name
, SHARED_MODULE
))
479 sendto_one_notice(source_p
, ":*** You do not have an appropriate shared block "
480 "to load modules on this server.");
484 return do_modreload(source_p
, parv
[1]);
488 do_modreload(struct Client
*source_p
, const char *module)
492 char *m_bn
= rb_basename(module);
494 if((modindex
= findmodule_byname(m_bn
)) == -1)
496 sendto_one_notice(source_p
, ":Module %s is not loaded", m_bn
);
501 check_core
= modlist
[modindex
]->core
;
503 if(unload_one_module(m_bn
, 1) == -1)
505 sendto_one_notice(source_p
, ":Module %s is not loaded", m_bn
);
510 if((load_one_module(m_bn
, modlist
[modindex
]->origin
, check_core
) == -1) && check_core
)
512 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
513 "Error reloading core module: %s: terminating ircd", m_bn
);
514 ilog(L_MAIN
, "Error loading core module %s: terminating ircd", m_bn
);
522 /* list modules .. */
524 mo_modlist(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
526 if(!IsOperAdmin(source_p
))
528 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
529 me
.name
, source_p
->name
, "admin");
535 sendto_match_servs(source_p
, parv
[2], CAP_ENCAP
, NOCAPS
,
536 "ENCAP %s MODLIST %s", parv
[2], parv
[1]);
537 if (match(parv
[2], me
.name
) == 0)
541 return do_modlist(source_p
, parc
> 1 ? parv
[1] : 0);
545 me_modlist(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
547 if(!find_shared_conf(source_p
->username
, source_p
->host
, source_p
->servptr
->name
, SHARED_MODULE
))
549 sendto_one_notice(source_p
, ":*** You do not have an appropriate shared block "
550 "to load modules on this server.");
554 return do_modlist(source_p
, parv
[1]);
558 do_modlist(struct Client
*source_p
, const char *pattern
)
562 for (i
= 0; i
< num_mods
; i
++)
565 switch (modlist
[i
]->origin
)
567 case MAPI_ORIGIN_EXTENSION
:
568 origin
= "extension";
570 case MAPI_ORIGIN_CORE
:
580 if(match(pattern
, modlist
[i
]->name
))
582 sendto_one(source_p
, form_str(RPL_MODLIST
),
583 me
.name
, source_p
->name
,
585 (unsigned long)(uintptr_t)modlist
[i
]->address
, origin
,
586 modlist
[i
]->core
? " (core)" : "", modlist
[i
]->version
, modlist
[i
]->description
);
591 sendto_one(source_p
, form_str(RPL_MODLIST
),
592 me
.name
, source_p
->name
, modlist
[i
]->name
,
593 (unsigned long)(uintptr_t)modlist
[i
]->address
, origin
,
594 modlist
[i
]->core
? " (core)" : "", modlist
[i
]->version
, modlist
[i
]->description
);
598 sendto_one(source_p
, form_str(RPL_ENDOFMODLIST
), me
.name
, source_p
->name
);
602 /* unload and reload all modules */
604 mo_modrestart(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
606 if(!IsOperAdmin(source_p
))
608 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
609 me
.name
, source_p
->name
, "admin");
615 sendto_match_servs(source_p
, parv
[1], CAP_ENCAP
, NOCAPS
,
616 "ENCAP %s MODRESTART", parv
[1]);
617 if (match(parv
[1], me
.name
) == 0)
621 return do_modrestart(source_p
);
625 me_modrestart(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
627 if(!find_shared_conf(source_p
->username
, source_p
->host
, source_p
->servptr
->name
, SHARED_MODULE
))
629 sendto_one_notice(source_p
, ":*** You do not have an appropriate shared block "
630 "to load modules on this server.");
634 return do_modrestart(source_p
);
638 do_modrestart(struct Client
*source_p
)
642 sendto_one_notice(source_p
, ":Reloading all modules");
646 unload_one_module(modlist
[0]->name
, 0);
649 load_core_modules(0);
652 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
653 "Module Restart: %d modules unloaded, %d modules loaded",
655 ilog(L_MAIN
, "Module Restart: %d modules unloaded, %d modules loaded", modnum
, num_mods
);
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_dlopen(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
);
834 * _mheader is actually a struct mapi_mheader_*, but mapi_version
835 * is always the first member of this structure, so we treate it
836 * as a single int in order to determine the API version.
839 mapi_version
= (int *) (uintptr_t) lt_dlsym(tmpptr
, "_mheader");
840 if((mapi_version
== NULL
841 && (mapi_version
= (int *) (uintptr_t) lt_dlsym(tmpptr
, "__mheader")) == NULL
)
842 || MAPI_MAGIC(*mapi_version
) != MAPI_MAGIC_HDR
)
844 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
845 "Data format error: module %s has no MAPI header.",
847 ilog(L_MAIN
, "Data format error: module %s has no MAPI header.", mod_basename
);
848 (void) lt_dlclose(tmpptr
);
849 rb_free(mod_basename
);
853 switch (MAPI_VERSION(*mapi_version
))
857 struct mapi_mheader_av1
*mheader
= (struct mapi_mheader_av1
*)(void *)mapi_version
; /* see above */
858 if(mheader
->mapi_register
&& (mheader
->mapi_register() == -1))
860 ilog(L_MAIN
, "Module %s indicated failure during load.",
862 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
863 "Module %s indicated failure during load.",
866 rb_free(mod_basename
);
869 if(mheader
->mapi_command_list
)
872 for (m
= mheader
->mapi_command_list
; *m
; ++m
)
876 if(mheader
->mapi_hook_list
)
879 for (m
= mheader
->mapi_hook_list
; m
->hapi_name
; ++m
)
880 *m
->hapi_id
= register_hook(m
->hapi_name
);
883 if(mheader
->mapi_hfn_list
)
885 mapi_hfn_list_av1
*m
;
886 for (m
= mheader
->mapi_hfn_list
; m
->hapi_name
; ++m
)
887 add_hook(m
->hapi_name
, m
->fn
);
890 ver
= mheader
->mapi_module_version
;
895 struct mapi_mheader_av2
*mheader
= (struct mapi_mheader_av2
*)(void *)mapi_version
; /* see above */
897 /* XXX duplicated code :( */
898 if(mheader
->mapi_register
&& (mheader
->mapi_register() == -1))
900 ilog(L_MAIN
, "Module %s indicated failure during load.",
902 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
903 "Module %s indicated failure during load.",
906 rb_free(mod_basename
);
910 /* Basic date code checks
912 * Don't make them fatal, but do complain about differences within a certain time frame.
913 * Later on if there are major API changes we can add fatal checks.
916 if(mheader
->mapi_datecode
!= datecode
&& mheader
->mapi_datecode
> 0)
918 long int delta
= labs(datecode
- mheader
->mapi_datecode
);
919 if (delta
> MOD_WARN_DELTA
)
923 "Module %s build date is out of sync with ircd build date by %ld days, expect problems",
924 mod_basename
, delta
);
925 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
926 "Module %s build date is out of sync with ircd build date by %ld days, expect problems",
927 mod_basename
, delta
);
931 if(mheader
->mapi_command_list
)
934 for (m
= mheader
->mapi_command_list
; *m
; ++m
)
938 if(mheader
->mapi_hook_list
)
941 for (m
= mheader
->mapi_hook_list
; m
->hapi_name
; ++m
)
942 *m
->hapi_id
= register_hook(m
->hapi_name
);
945 if(mheader
->mapi_hfn_list
)
947 mapi_hfn_list_av1
*m
;
948 for (m
= mheader
->mapi_hfn_list
; m
->hapi_name
; ++m
)
949 add_hook(m
->hapi_name
, m
->fn
);
952 /* New in MAPI v2 - version replacement */
953 ver
= mheader
->mapi_module_version
? mheader
->mapi_module_version
: ircd_version
;
954 description
= mheader
->mapi_module_description
;
956 if(mheader
->mapi_cap_list
)
958 mapi_cap_list_av2
*m
;
959 for (m
= mheader
->mapi_cap_list
; m
->cap_name
; ++m
)
961 struct CapabilityIndex
*idx
;
964 switch (m
->cap_index
)
966 case MAPI_CAP_CLIENT
:
969 case MAPI_CAP_SERVER
:
973 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
974 "Unknown/unsupported CAP index found of type %d on capability %s when loading %s",
975 m
->cap_index
, m
->cap_name
, mod_basename
);
977 "Unknown/unsupported CAP index found of type %d on capability %s when loading %s",
978 m
->cap_index
, m
->cap_name
, mod_basename
);
982 result
= capability_put(idx
, m
->cap_name
, m
->cap_ownerdata
);
983 if (m
->cap_id
!= NULL
)
984 *(m
->cap_id
) = result
;
991 ilog(L_MAIN
, "Module %s has unknown/unsupported MAPI version %d.",
992 mod_basename
, MAPI_VERSION(*mapi_version
));
993 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
994 "Module %s has unknown/unsupported MAPI version %d.",
995 mod_basename
, *mapi_version
);
997 rb_free(mod_basename
);
1004 if(description
== NULL
)
1005 description
= unknown_description
;
1009 modlist
[num_mods
] = rb_malloc(sizeof(struct module));
1010 modlist
[num_mods
]->address
= tmpptr
;
1011 modlist
[num_mods
]->version
= ver
;
1012 modlist
[num_mods
]->description
= description
;
1013 modlist
[num_mods
]->core
= core
;
1014 modlist
[num_mods
]->name
= rb_strdup(mod_basename
);
1015 modlist
[num_mods
]->mapi_header
= mapi_version
;
1016 modlist
[num_mods
]->mapi_version
= MAPI_VERSION(*mapi_version
);
1017 modlist
[num_mods
]->origin
= origin
;
1026 case MAPI_ORIGIN_EXTENSION
:
1029 case MAPI_ORIGIN_CORE
:
1037 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1038 "Module %s [version: %s; MAPI version: %d; origin: %s; description: \"%s\"] loaded at 0x%lx",
1039 mod_basename
, ver
, MAPI_VERSION(*mapi_version
), o
, description
,
1040 (unsigned long) tmpptr
);
1041 ilog(L_MAIN
, "Module %s [version: %s; MAPI version: %d; origin: %s; description: \"%s\"] loaded at 0x%lx",
1042 mod_basename
, ver
, MAPI_VERSION(*mapi_version
), o
, description
, (unsigned long) tmpptr
);
1044 rb_free(mod_basename
);
1053 * side effects - expand the size of modlist if necessary
1056 increase_modlist(void)
1058 struct module **new_modlist
= NULL
;
1060 if((num_mods
+ 1) < max_mods
)
1063 new_modlist
= (struct module **) rb_malloc(sizeof(struct module *) *
1064 (max_mods
+ MODS_INCREMENT
));
1065 memcpy((void *) new_modlist
, (void *) modlist
, sizeof(struct module *) * num_mods
);
1068 modlist
= new_modlist
;
1069 max_mods
+= MODS_INCREMENT
;