/[svn]/ircd-hybrid/trunk/src/hook.c
ViewVC logotype

Diff of /ircd-hybrid/trunk/src/hook.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2357 by michael, Wed Nov 7 21:02:43 2012 UTC revision 2358 by michael, Thu Jul 4 20:16:08 2013 UTC
# Line 2  Line 2 
2   *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).   *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3   *   *
4   *  Copyright (C) 2003 Piotr Nizynski, Advanced IRC Services Project Team   *  Copyright (C) 2003 Piotr Nizynski, Advanced IRC Services Project Team
5   *  Copyright (C) 2005 Hybrid Development Team   *  Copyright (C) 2005-2013 Hybrid Development Team
6   *   *
7   *  This program is free software; you can redistribute it and/or modify   *  This program is free software; you can redistribute it and/or modify
8   *  it under the terms of the GNU General Public License as published by   *  it under the terms of the GNU General Public License as published by
# Line 37  Line 37 
37  #include "send.h"  #include "send.h"
38  #include "client.h"  #include "client.h"
39    
40  static dlink_list callback_list = { NULL, NULL, 0} ;  static dlink_list callback_list;
41    
42    
43  /*! \brief Creates a new callback.  /*! \brief Creates a new callback.
44   * \param name name used to identify the callback   * \param name name used to identify the callback
# Line 69  register_callback(const char *name, CBFU Line 70  register_callback(const char *name, CBFU
70    }    }
71    
72    cb = MyMalloc(sizeof(struct Callback));    cb = MyMalloc(sizeof(struct Callback));
73    
74    if (func != NULL)    if (func != NULL)
75      dlinkAdd(func, MyMalloc(sizeof(dlink_node)), &cb->chain);      dlinkAdd(func, MyMalloc(sizeof(dlink_node)), &cb->chain);
76    
# Line 89  register_callback(const char *name, CBFU Line 91  register_callback(const char *name, CBFU
91  void *  void *
92  execute_callback(struct Callback *cb, ...)  execute_callback(struct Callback *cb, ...)
93  {  {
94    void *res;    void *res = NULL;
95    va_list args;    va_list args;
96    
97    cb->called++;    cb->called++;
# Line 99  execute_callback(struct Callback *cb, .. Line 101  execute_callback(struct Callback *cb, ..
101      return NULL;      return NULL;
102    
103    va_start(args, cb);    va_start(args, cb);
104    res = ((CBFUNC *) cb->chain.head->data)(args);    res = ((CBFUNC *)cb->chain.head->data)(args);
105    va_end(args);    va_end(args);
106    
107    return res;    return res;
# Line 114  execute_callback(struct Callback *cb, .. Line 116  execute_callback(struct Callback *cb, ..
116  void *  void *
117  pass_callback(dlink_node *this_hook, ...)  pass_callback(dlink_node *this_hook, ...)
118  {  {
119    void *res;    void *res = NULL;
120    va_list args;    va_list args;
121    
122    if (this_hook->next == NULL)    if (this_hook->next == NULL)
123      return NULL;  /* reached the last one */      return NULL;  /* reached the last one */
124    
125    va_start(args, this_hook);    va_start(args, this_hook);
126    res = ((CBFUNC *) this_hook->next->data)(args);    res = ((CBFUNC *)this_hook->next->data)(args);
127    va_end(args);    va_end(args);
128    
129    return res;    return res;
# Line 134  pass_callback(dlink_node *this_hook, ... Line 136  pass_callback(dlink_node *this_hook, ...
136  struct Callback *  struct Callback *
137  find_callback(const char *name)  find_callback(const char *name)
138  {  {
139    dlink_node *ptr;    dlink_node *ptr = NULL;
140    
141    DLINK_FOREACH(ptr, callback_list.head)    DLINK_FOREACH(ptr, callback_list.head)
142    {    {
# Line 174  install_hook(struct Callback *cb, CBFUNC Line 176  install_hook(struct Callback *cb, CBFUNC
176  void  void
177  uninstall_hook(struct Callback *cb, CBFUNC *hook)  uninstall_hook(struct Callback *cb, CBFUNC *hook)
178  {  {
179    /* let it core if not found */    /* Let it core if not found */
180    dlink_node *ptr = dlinkFind(&cb->chain, hook);    dlink_node *ptr = dlinkFind(&cb->chain, hook);
181    
182    dlinkDelete(ptr, &cb->chain);    dlinkDelete(ptr, &cb->chain);
# Line 188  uninstall_hook(struct Callback *cb, CBFU Line 190  uninstall_hook(struct Callback *cb, CBFU
190  void  void
191  stats_hooks(struct Client *source_p)  stats_hooks(struct Client *source_p)
192  {  {
   dlink_node *ptr;  
193    char lastused[32];    char lastused[32];
194      const dlink_node *ptr = NULL;
195    
196    sendto_one(source_p, ":%s %d %s : %-20s %-20s Used     Hooks", me.name,    sendto_one(source_p, ":%s %d %s : %-20s %-20s Used     Hooks", me.name,
197               RPL_STATSDEBUG, source_p->name, "Callback", "Last Execution");               RPL_STATSDEBUG, source_p->name, "Callback", "Last Execution");
# Line 198  stats_hooks(struct Client *source_p) Line 200  stats_hooks(struct Client *source_p)
200    
201    DLINK_FOREACH(ptr, callback_list.head)    DLINK_FOREACH(ptr, callback_list.head)
202    {    {
203      struct Callback *cb = ptr->data;      const struct Callback *cb = ptr->data;
204    
205      if (cb->last != 0)      if (cb->last != 0)
206        snprintf(lastused, sizeof(lastused), "%d seconds ago",        snprintf(lastused, sizeof(lastused), "%d seconds ago",
# Line 208  stats_hooks(struct Client *source_p) Line 210  stats_hooks(struct Client *source_p)
210    
211      sendto_one(source_p, ":%s %d %s : %-20s %-20s %-8u %d", me.name,      sendto_one(source_p, ":%s %d %s : %-20s %-20s %-8u %d", me.name,
212                 RPL_STATSDEBUG, source_p->name, cb->name, lastused, cb->called,                 RPL_STATSDEBUG, source_p->name, cb->name, lastused, cb->called,
213                 dlink_list_length(&cb->chain));                 dlink_list_length(&cb->chain));
214    }    }
215    
216    sendto_one(source_p, ":%s %d %s : ", me.name, RPL_STATSDEBUG,    sendto_one(source_p, ":%s %d %s : ", me.name, RPL_STATSDEBUG,

Legend:
Removed from v.2357  
changed lines
  Added in v.2358

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28