ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/modules.c
(Generate patch)

Comparing ircd-hybrid/trunk/src/modules.c (file contents):
Revision 1592 by michael, Sat Oct 27 21:02:32 2012 UTC vs.
Revision 4565 by michael, Sun Aug 24 10:27:40 2014 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  modules.c: A module loader.
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
4 > *  Copyright (c) 2000-2014 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 16 | Line 15
15   *
16   *  You should have received a copy of the GNU General Public License
17   *  along with this program; if not, write to the Free Software
18 < *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18 > *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19   *  USA
20 < *
21 < *  $Id$
20 > */
21 >
22 > /*! \file modules.c
23 > * \brief A module loader.
24 > * \version $Id$
25   */
26  
27   #include "ltdl.h"
# Line 39 | Line 41
41   #include "memory.h"
42  
43  
44 < dlink_list modules_list = { NULL, NULL, 0 };
44 > static dlink_list modules_list;
45 > static dlink_list modules_path;
46 > static dlink_list modules_conf;
47  
48   static const char *unknown_ver = "<unknown>";
45
49   static const char *core_module_table[] =
50   {
51 +  "m_bmask.la",
52    "m_die.la",
53    "m_error.la",
54    "m_join.la",
# Line 58 | Line 62 | static const char *core_module_table[] =
62    "m_server.la",
63    "m_sjoin.la",
64    "m_squit.la",
65 +  "m_tmode.la",
66    NULL
67   };
68  
69 < static dlink_list mod_paths = { NULL, NULL, 0 };
70 < static dlink_list conf_modules = { NULL, NULL, 0 };
69 >
70 > dlink_list *
71 > modules_get_list(void)
72 > {
73 >  return &modules_list;
74 > }
75  
76   int
77   modules_valid_suffix(const char *name)
# Line 97 | Line 106 | unload_one_module(const char *name, int
106    if (warn == 1)
107    {
108      ilog(LOG_TYPE_IRCD, "Module %s unloaded", name);
109 <    sendto_realops_flags(UMODE_ALL, L_ALL, "Module %s unloaded", name);
109 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
110 >                         "Module %s unloaded", name);
111    }
112  
113    return 0;
# Line 119 | Line 129 | load_a_module(const char *path, int warn
129    if (findmodule_byname((mod_basename = libio_basename(path))))
130      return 1;
131  
132 <  if (!(tmpptr = lt_dlopen(path))) {
132 >  if (!(tmpptr = lt_dlopen(path)))
133 >  {
134      const char *err = ((err = lt_dlerror())) ? err : "<unknown>";
135  
136 <    sendto_realops_flags(UMODE_ALL, L_ALL, "Error loading module %s: %s",
136 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
137 >                         "Error loading module %s: %s",
138                           mod_basename, err);
139      ilog(LOG_TYPE_IRCD, "Error loading module %s: %s", mod_basename, err);
140      return -1;
# Line 132 | Line 144 | load_a_module(const char *path, int warn
144    {
145      const char *err = ((err = lt_dlerror())) ? err : "<unknown>";
146  
147 <    sendto_realops_flags(UMODE_ALL, L_ALL, "Error loading module %s: %s",
147 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
148 >                         "Error loading module %s: %s",
149                           mod_basename, err);
150      ilog(LOG_TYPE_IRCD, "Error loading module %s: %s", mod_basename, err);
151      lt_dlclose(tmpptr);
# Line 144 | Line 157 | load_a_module(const char *path, int warn
157    if (EmptyString(modp->version))
158      modp->version = unknown_ver;
159  
160 <  DupString(modp->name, mod_basename);
160 >  modp->name = xstrdup(mod_basename);
161    dlinkAdd(modp, &modp->node, &modules_list);
162  
163    if (modp->modinit)
# Line 152 | Line 165 | load_a_module(const char *path, int warn
165  
166    if (warn == 1)
167    {
168 <    sendto_realops_flags(UMODE_ALL, L_ALL,
168 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
169                           "Module %s [version: %s handle: %p] loaded.",
170                           modp->name, modp->version, tmpptr);
171      ilog(LOG_TYPE_IRCD, "Module %s [version: %s handle: %p] loaded.",
# Line 189 | Line 202 | modules_init(void)
202   static struct module_path *
203   mod_find_path(const char *path)
204   {
205 <  dlink_node *ptr;
205 >  dlink_node *ptr = NULL;
206  
207 <  DLINK_FOREACH(ptr, mod_paths.head)
207 >  DLINK_FOREACH(ptr, modules_path.head)
208    {
209      struct module_path *mpath = ptr->data;
210  
# Line 216 | Line 229 | mod_add_path(const char *path)
229    if (mod_find_path(path))
230      return;
231  
232 <  pathst = MyMalloc(sizeof(struct module_path));
232 >  pathst = MyCalloc(sizeof(struct module_path));
233  
234    strlcpy(pathst->path, path, sizeof(pathst->path));
235 <  dlinkAdd(pathst, &pathst->node, &mod_paths);
235 >  dlinkAdd(pathst, &pathst->node, &modules_path);
236   }
237  
238   /* add_conf_module
# Line 233 | Line 246 | add_conf_module(const char *name)
246   {
247    struct module_path *pathst;
248  
249 <  pathst = MyMalloc(sizeof(struct module_path));
249 >  pathst = MyCalloc(sizeof(struct module_path));
250  
251    strlcpy(pathst->path, name, sizeof(pathst->path));
252 <  dlinkAdd(pathst, &pathst->node, &conf_modules);
252 >  dlinkAdd(pathst, &pathst->node, &modules_conf);
253   }
254  
255   /* mod_clear_paths()
# Line 248 | Line 261 | add_conf_module(const char *name)
261   void
262   mod_clear_paths(void)
263   {
264 <  dlink_node *ptr = NULL, *next_ptr = NULL;
264 >  dlink_node *ptr = NULL, *ptr_next = NULL;
265  
266 <  DLINK_FOREACH_SAFE(ptr, next_ptr, mod_paths.head)
266 >  DLINK_FOREACH_SAFE(ptr, ptr_next, modules_path.head)
267    {
268 <    dlinkDelete(ptr, &mod_paths);
268 >    dlinkDelete(ptr, &modules_path);
269      MyFree(ptr->data);
270    }
271  
272 <  DLINK_FOREACH_SAFE(ptr, next_ptr, conf_modules.head)
272 >  DLINK_FOREACH_SAFE(ptr, ptr_next, modules_conf.head)
273    {
274 <    dlinkDelete(ptr, &conf_modules);
274 >    dlinkDelete(ptr, &modules_conf);
275      MyFree(ptr->data);
276    }
277   }
# Line 278 | Line 291 | findmodule_byname(const char *name)
291    {
292      struct module *modp = ptr->data;
293  
294 <    if (strcmp(modp->name, name) == 0)
294 >    if (!strcmp(modp->name, name))
295        return modp;
296    }
297  
# Line 296 | Line 309 | load_all_modules(int warn)
309   {
310    DIR *system_module_dir = NULL;
311    struct dirent *ldirent = NULL;
312 <  char module_fq_name[PATH_MAX + 1];
312 >  char module_fq_name[HYB_PATH_MAX + 1];
313  
314    if ((system_module_dir = opendir(AUTOMODPATH)) == NULL)
315    {
# Line 305 | Line 318 | load_all_modules(int warn)
318      return;
319    }
320  
321 <  while ((ldirent = readdir(system_module_dir)) != NULL)
321 >  while ((ldirent = readdir(system_module_dir)))
322    {
323      if (modules_valid_suffix(ldirent->d_name))
324      {
# Line 329 | Line 342 | load_conf_modules(void)
342   {
343    dlink_node *ptr = NULL;
344  
345 <  DLINK_FOREACH(ptr, conf_modules.head)
345 >  DLINK_FOREACH(ptr, modules_conf.head)
346    {
347      struct module_path *mpath = ptr->data;
348  
# Line 347 | Line 360 | load_conf_modules(void)
360   void
361   load_core_modules(int warn)
362   {
363 <  char module_name[PATH_MAX + 1];
351 <  int i = 0;
363 >  char module_name[HYB_PATH_MAX + 1];
364  
365 <  for (; core_module_table[i]; ++i)
365 >  for (unsigned int i = 0; core_module_table[i]; ++i)
366    {
367      snprintf(module_name, sizeof(module_name), "%s%s",
368               MODPATH, core_module_table[i]);
# Line 368 | Line 380 | load_core_modules(int warn)
380   *
381   * input        - pointer to path
382   *              - flagged as core module or not
383 < * output       - -1 if error
383 > * output       - -1 if error
384   * side effects - module is loaded if found.
385   */
386   int
387 < load_one_module(const char *path)
387 > load_one_module(const char *name)
388   {
389    dlink_node *ptr = NULL;
390 <  char modpath[PATH_MAX + 1];
390 >  char path[HYB_PATH_MAX + 1];
391    struct stat statbuf;
392  
393 <  DLINK_FOREACH(ptr, mod_paths.head)
393 >  DLINK_FOREACH(ptr, modules_path.head)
394    {
395      const struct module_path *mpath = ptr->data;
396  
397 <    snprintf(modpath, sizeof(modpath), "%s/%s", mpath->path, path);
397 >    snprintf(path, sizeof(path), "%s/%s", mpath->path, name);
398  
399 <    if (!modules_valid_suffix(path))
399 >    if (!modules_valid_suffix(name))
400        continue;
401  
402 <    if (strstr(modpath, "../") == NULL &&
403 <        strstr(modpath, "/..") == NULL)
404 <      if (!stat(modpath, &statbuf))
402 >    if (strstr(path, "../") == NULL &&
403 >        strstr(path, "/..") == NULL)
404 >      if (!stat(path, &statbuf))
405          if (S_ISREG(statbuf.st_mode))  /* Regular files only please */
406 <          return load_a_module(modpath, 1);
406 >          return load_a_module(path, 1);
407    }
408  
409 <  sendto_realops_flags(UMODE_ALL, L_ALL,
410 <                       "Cannot locate module %s", path);
411 <  ilog(LOG_TYPE_IRCD, "Cannot locate module %s", path);
409 >  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
410 >                       "Cannot locate module %s", name);
411 >  ilog(LOG_TYPE_IRCD, "Cannot locate module %s", name);
412    return -1;
413   }

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)