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

Comparing ircd-hybrid-8/src/modules.c (file contents):
Revision 1436 by michael, Sun Jun 17 19:31:28 2012 UTC vs.
Revision 1437 by michael, Mon Jun 18 19:02:48 2012 UTC

# Line 64 | Line 64 | static const char *core_module_table[] =
64   static dlink_list mod_paths = { NULL, NULL, 0 };
65   static dlink_list conf_modules = { NULL, NULL, 0 };
66  
67 < static void mo_modload(struct Client *, struct Client *, int, char *[]);
68 < static void mo_modlist(struct Client *, struct Client *, int, char *[]);
69 < static void mo_modreload(struct Client *, struct Client *, int, char *[]);
70 < static void mo_modunload(struct Client *, struct Client *, int, char *[]);
71 <
72 < struct Message modload_msgtab = {
73 < "MODLOAD", 0, 0, 2, 0, MFLG_SLOW, 0,
74 <  {m_unregistered, m_not_oper, m_ignore, m_ignore, mo_modload, m_ignore}
75 < };
76 <
77 < struct Message modunload_msgtab = {
78 < "MODUNLOAD", 0, 0, 2, 0, MFLG_SLOW, 0,
79 <  {m_unregistered, m_not_oper, m_ignore, m_ignore, mo_modunload, m_ignore}
80 < };
67 > static void mo_module(struct Client *, struct Client *, int, char *[]);
68  
69 < struct Message modreload_msgtab = {
70 <  "MODRELOAD", 0, 0, 2, 0, MFLG_SLOW, 0,
71 <  {m_unregistered, m_not_oper, m_ignore, m_ignore, mo_modreload, m_ignore}
69 > struct Message module_msgtab = {
70 > "MODULE", 0, 0, 2, 0, MFLG_SLOW, 0,
71 >  {m_unregistered, m_not_oper, m_ignore, m_ignore, mo_module, m_ignore}
72   };
73  
87 – struct Message modlist_msgtab = {
88 – "MODLIST", 0, 0, 0, 0, MFLG_SLOW, 0,
89 –  {m_unregistered, m_not_oper, m_ignore, m_ignore, mo_modlist, m_ignore}
90 – };
91 –
92 –
74   int
75   modules_valid_suffix(const char *name)
76   {
# Line 203 | Line 184 | modules_init(void)
184      exit(0);
185    }
186  
187 <  mod_add_cmd(&modload_msgtab);
207 <  mod_add_cmd(&modunload_msgtab);
208 <  mod_add_cmd(&modreload_msgtab);
209 <  mod_add_cmd(&modlist_msgtab);
187 >  mod_add_cmd(&module_msgtab);
188   }
189  
190   /* mod_find_path()
# Line 429 | Line 407 | load_one_module(const char *path)
407    return -1;
408   }
409  
410 < /* load a module .. */
411 < static void
412 < mo_modload(struct Client *client_p, struct Client *source_p,
413 <           int parc, char *parv[])
414 < {
415 <  const char *m_bn = NULL;
416 <
417 <  if (!HasOFlag(source_p, OPER_FLAG_MODULE))
418 <  {
419 <    sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
420 <               me.name, source_p->name);
421 <    return;
422 <  }
423 <
446 <  m_bn = libio_basename(parv[1]);
447 <
448 <  if (findmodule_byname(m_bn) != NULL)
449 <  {
450 <    sendto_one(source_p, ":%s NOTICE %s :Module %s is already loaded",
451 <               me.name, source_p->name, m_bn);
452 <    return;
453 <  }
454 <
455 <  load_one_module(parv[1]);
456 < }
457 <
458 < /* unload a module .. */
410 > /*! \brief MODULE command handler (called by operators)
411 > *
412 > * \param client_p Pointer to allocated Client struct with physical connection
413 > *                 to this server, i.e. with an open socket connected.
414 > * \param source_p Pointer to allocated Client struct from which the message
415 > *                 originally comes from.  This can be a local or remote client.
416 > * \param parc     Integer holding the number of supplied arguments.
417 > * \param parv     Argument vector where parv[0] .. parv[parc-1] are non-NULL
418 > *                 pointers.
419 > * \note Valid arguments for this command are:
420 > *      - parv[0] = sender prefix
421 > *      - parv[1] = action [LOAD, UNLOAD, RELOAD, LIST]
422 > *      - parv[2] = module name
423 > */
424   static void
425 < mo_modunload(struct Client *client_p, struct Client *source_p,
426 <             int parc, char *parv[])
425 > mo_module(struct Client *client_p, struct Client *source_p,
426 >          int parc, char *parv[])
427   {
428    const char *m_bn = NULL;
429    struct module *modp = NULL;
430 +  int check_core;
431  
432    if (!HasOFlag(source_p, OPER_FLAG_MODULE))
433    {
# Line 470 | Line 436 | mo_modunload(struct Client *client_p, st
436      return;
437    }
438  
439 <  m_bn = libio_basename(parv[1]);
474 <
475 <  if ((modp = findmodule_byname(m_bn)) == NULL)
439 >  if (EmptyString(parv[1]))
440    {
441 <    sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded",
442 <               me.name, source_p->name, m_bn);
441 >    sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
442 >               me.name, source_p->name, "MODULE");
443      return;
444    }
445  
446 <  if (modp->flags & MODULE_FLAG_CORE)
446 >  if (!irccmp(parv[1], "LOAD"))
447    {
448 <    sendto_one(source_p,
449 <               ":%s NOTICE %s :Module %s is a core module and may not be unloaded",
450 <               me.name, source_p->name, m_bn);
448 >    if (findmodule_byname((m_bn = libio_basename(parv[2]))) != NULL)
449 >    {
450 >      sendto_one(source_p, ":%s NOTICE %s :Module %s is already loaded",
451 >                 me.name, source_p->name, m_bn);
452 >      return;
453 >    }
454 >
455 >    load_one_module(parv[2]);
456      return;
457    }
458  
459 <  if (unload_one_module(m_bn, 1) == -1)
459 >  if (!irccmp(parv[1], "UNLOAD"))
460    {
461 <    sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded",
462 <               me.name, source_p->name, m_bn);
463 <  }
464 < }
461 >    if ((modp = findmodule_byname((m_bn = libio_basename(parv[2])))) == NULL)
462 >    {
463 >      sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded",
464 >                 me.name, source_p->name, m_bn);
465 >      return;
466 >    }
467  
468 < /* unload and load in one! */
469 < static void
470 < mo_modreload(struct Client *client_p, struct Client *source_p,
471 <             int parc, char *parv[])
472 < {
473 <  const char *m_bn = NULL;
474 <  struct module *modp = NULL;
504 <  int check_core;
468 >    if (modp->flags & MODULE_FLAG_CORE)
469 >    {
470 >      sendto_one(source_p,
471 >                 ":%s NOTICE %s :Module %s is a core module and may not be unloaded",
472 >                 me.name, source_p->name, m_bn);
473 >      return;
474 >    }
475  
476 <  if (!HasOFlag(source_p, OPER_FLAG_MODULE))
477 <  {
478 <    sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
509 <               me.name, source_p->name);
476 >    if (unload_one_module(m_bn, 1) == -1)
477 >      sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded",
478 >                 me.name, source_p->name, m_bn);
479      return;
480    }
481  
482 <  if (!strcmp(parv[1], "*"))
482 >  if (!irccmp(parv[1], "RELOAD"))
483    {
484 <    unsigned int modnum = 0;
485 <    dlink_node *ptr = NULL, *ptr_next = NULL;
484 >    if (!strcmp(parv[2], "*"))
485 >    {
486 >      unsigned int modnum = 0;
487 >      dlink_node *ptr = NULL, *ptr_next = NULL;
488  
489 <    sendto_one(source_p, ":%s NOTICE %s :Reloading all modules",
490 <               me.name, source_p->name);
489 >      sendto_one(source_p, ":%s NOTICE %s :Reloading all modules",
490 >                 me.name, source_p->name);
491  
492 <    modnum = dlink_list_length(&modules_list);
492 >      modnum = dlink_list_length(&modules_list);
493  
494 <    DLINK_FOREACH_SAFE(ptr, ptr_next, modules_list.head)
494 >      DLINK_FOREACH_SAFE(ptr, ptr_next, modules_list.head)
495 >      {
496 >        modp = ptr->data;
497 >        unload_one_module(modp->name, 0);
498 >      }
499 >
500 >      load_all_modules(0);
501 >      load_conf_modules();
502 >      load_core_modules(0);
503 >
504 >      sendto_realops_flags(UMODE_ALL, L_ALL,
505 >                           "Module Restart: %u modules unloaded, %u modules loaded",
506 >                           modnum, dlink_list_length(&modules_list));
507 >      ilog(LOG_TYPE_IRCD, "Module Restart: %u modules unloaded, %u modules loaded",
508 >           modnum, dlink_list_length(&modules_list));
509 >      return;
510 >    }
511 >
512 >    if ((modp = findmodule_byname((m_bn = libio_basename(parv[2])))) == NULL)
513      {
514 <      modp = ptr->data;
515 <      unload_one_module(modp->name, 0);
514 >      sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded",
515 >               me.name, source_p->name, m_bn);
516 >      return;
517      }
518  
519 <    load_all_modules(0);
530 <    load_conf_modules();
531 <    load_core_modules(0);
519 >    check_core = (modp->flags & MODULE_FLAG_CORE) != 0;
520  
521 <    sendto_realops_flags(UMODE_ALL, L_ALL,
522 <                        "Module Restart: %u modules unloaded, %u modules loaded",
523 <                          modnum, dlink_list_length(&modules_list));
524 <    ilog(LOG_TYPE_IRCD, "Module Restart: %u modules unloaded, %u modules loaded",
525 <         modnum, dlink_list_length(&modules_list));
526 <    return;
539 <  }
521 >    if (unload_one_module(m_bn, 1) == -1)
522 >    {
523 >      sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded",
524 >                 me.name, source_p->name, m_bn);
525 >      return;
526 >    }
527  
528 <  m_bn = libio_basename(parv[1]);
528 >    if ((load_one_module(parv[2]) == -1) && check_core)
529 >    {
530 >      sendto_realops_flags(UMODE_ALL, L_ALL, "Error reloading core "
531 >                           "module: %s: terminating ircd", parv[2]);
532 >      ilog(LOG_TYPE_IRCD, "Error loading core module %s: terminating ircd", parv[2]);
533 >      exit(0);
534 >    }
535  
543 –  if ((modp = findmodule_byname(m_bn)) == NULL)
544 –  {
545 –    sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded",
546 –               me.name, source_p->name, m_bn);
536      return;
537    }
538  
539 <  check_core = (modp->flags & MODULE_FLAG_CORE) != 0;
551 <
552 <  if (unload_one_module(m_bn, 1) == -1)
539 >  if (!irccmp(parv[1], "LIST"))
540    {
541 <    sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded",
555 <               me.name, source_p->name, m_bn);
556 <    return;
557 <  }
541 >    const dlink_node *ptr = NULL;
542  
543 <  if ((load_one_module(parv[1]) == -1) && check_core)
544 <  {
545 <    sendto_realops_flags(UMODE_ALL, L_ALL, "Error reloading core "
546 <                         "module: %s: terminating ircd", parv[1]);
563 <    ilog(LOG_TYPE_IRCD, "Error loading core module %s: terminating ircd", parv[1]);
564 <    exit(0);
565 <  }
566 < }
543 >    DLINK_FOREACH(ptr, modules_list.head)
544 >    {
545 >      if (parc > 2 && !match(parv[2], modp->name))
546 >        continue;
547  
548 < /* list modules .. */
549 < static void
550 < mo_modlist(struct Client *client_p, struct Client *source_p,
551 <           int parc, char *parv[])
572 < {
573 <  const dlink_node *ptr = NULL;
548 >      sendto_one(source_p, form_str(RPL_MODLIST), me.name, source_p->name,
549 >                 modp->name, modp->handle,
550 >                 modp->version, (modp->flags & MODULE_FLAG_CORE) ?"(core)":"");
551 >    }
552  
553 <  if (!HasOFlag(source_p, OPER_FLAG_MODULE))
576 <  {
577 <    sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
553 >    sendto_one(source_p, form_str(RPL_ENDOFMODLIST),
554                 me.name, source_p->name);
555      return;
556    }
581 –
582 –  DLINK_FOREACH(ptr, modules_list.head)
583 –  {
584 –    const struct module *modp = ptr->data;
585 –
586 –    if (parc > 1 && !match(parv[1], modp->name))
587 –      continue;
588 –
589 –    sendto_one(source_p, form_str(RPL_MODLIST), me.name, source_p->name,
590 –               modp->name, modp->handle,
591 –               modp->version, (modp->flags & MODULE_FLAG_CORE) ?"(core)":"");
592 –  }
593 –
594 –  sendto_one(source_p, form_str(RPL_ENDOFMODLIST),
595 –             me.name, source_p->name);
557   }

Diff Legend

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