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 |
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 |
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 |
|
|
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++; |
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; |
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; |
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 |
{ |
{ |
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); |
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"); |
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", |
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, |