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 1997 by michael, Sat May 11 17:35:07 2013 UTC vs.
Revision 4977 by michael, Thu Dec 4 15:12:24 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 dlink_list mod_paths = { NULL, NULL, 0 };
49 < static dlink_list conf_modules = { NULL, NULL, 0 };
46 <
47 < static const char *unknown_ver = "<unknown>";
48 < static const char *core_module_table[] =
48 > static const char *const unknown_ver = "<unknown>";
49 > static const char *const core_module_table[] =
50   {
51 +  "m_bmask.la",
52    "m_die.la",
53    "m_error.la",
54    "m_join.la",
# Line 60 | 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 +
70 + dlink_list *
71 + modules_get_list(void)
72 + {
73 +  return &modules_list;
74 + }
75 +
76   int
77   modules_valid_suffix(const char *name)
78   {
# 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, SEND_NOTICE,
# Line 191 | 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 *node = NULL;
206  
207 <  DLINK_FOREACH(ptr, mod_paths.head)
207 >  DLINK_FOREACH(node, modules_path.head)
208    {
209 <    struct module_path *mpath = ptr->data;
209 >    struct module_path *mpath = node->data;
210  
211      if (!strcmp(path, mpath->path))
212        return mpath;
# Line 218 | 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 235 | 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 250 | 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 *node = NULL, *node_next = NULL;
265  
266 <  DLINK_FOREACH_SAFE(ptr, next_ptr, mod_paths.head)
266 >  DLINK_FOREACH_SAFE(node, node_next, modules_path.head)
267    {
268 <    dlinkDelete(ptr, &mod_paths);
269 <    MyFree(ptr->data);
268 >    dlinkDelete(node, &modules_path);
269 >    MyFree(node->data);
270    }
271  
272 <  DLINK_FOREACH_SAFE(ptr, next_ptr, conf_modules.head)
272 >  DLINK_FOREACH_SAFE(node, node_next, modules_conf.head)
273    {
274 <    dlinkDelete(ptr, &conf_modules);
275 <    MyFree(ptr->data);
274 >    dlinkDelete(node, &modules_conf);
275 >    MyFree(node->data);
276    }
277   }
278  
# Line 274 | Line 285 | mod_clear_paths(void)
285   struct module *
286   findmodule_byname(const char *name)
287   {
288 <  dlink_node *ptr = NULL;
288 >  dlink_node *node = NULL;
289  
290 <  DLINK_FOREACH(ptr, modules_list.head)
290 >  DLINK_FOREACH(node, modules_list.head)
291    {
292 <    struct module *modp = ptr->data;
292 >    struct module *modp = node->data;
293  
294 <    if (strcmp(modp->name, name) == 0)
294 >    if (!strcmp(modp->name, name))
295        return modp;
296    }
297  
# Line 307 | 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 340 | load_all_modules(int warn)
340   void
341   load_conf_modules(void)
342   {
343 <  dlink_node *ptr = NULL;
343 >  dlink_node *node = NULL;
344  
345 <  DLINK_FOREACH(ptr, conf_modules.head)
345 >  DLINK_FOREACH(node, modules_conf.head)
346    {
347 <    struct module_path *mpath = ptr->data;
347 >    struct module_path *mpath = node->data;
348  
349      if (findmodule_byname(mpath->path) == NULL)
350        load_one_module(mpath->path);
# Line 350 | Line 361 | void
361   load_core_modules(int warn)
362   {
363    char module_name[HYB_PATH_MAX + 1];
353  int i = 0;
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 370 | 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[HYB_PATH_MAX + 1];
389 >  dlink_node *node = NULL;
390 >  char path[HYB_PATH_MAX + 1];
391    struct stat statbuf;
392  
393 <  DLINK_FOREACH(ptr, mod_paths.head)
393 >  DLINK_FOREACH(node, modules_path.head)
394    {
395 <    const struct module_path *mpath = ptr->data;
395 >    const struct module_path *mpath = node->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, SEND_NOTICE,
410 <                       "Cannot locate module %s", path);
411 <  ilog(LOG_TYPE_IRCD, "Cannot locate module %s", path);
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)