2 |
|
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
|
* |
4 |
|
* Copyright (C) 2003 Piotr Nizynski, Advanced IRC Services Project Team |
5 |
< |
* Copyright (C) 2005 Hybrid Development Team |
5 |
> |
* Copyright (C) 2005-2013 Hybrid Development Team |
6 |
|
* |
7 |
|
* 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 |
37 |
|
#include "send.h" |
38 |
|
#include "client.h" |
39 |
|
|
40 |
< |
static dlink_list callback_list = { NULL, NULL, 0} ; |
40 |
> |
static dlink_list callback_list; |
41 |
> |
|
42 |
|
|
43 |
|
/*! \brief Creates a new callback. |
44 |
|
* \param name name used to identify the callback |
70 |
|
} |
71 |
|
|
72 |
|
cb = MyMalloc(sizeof(struct Callback)); |
73 |
+ |
|
74 |
|
if (func != NULL) |
75 |
|
dlinkAdd(func, MyMalloc(sizeof(dlink_node)), &cb->chain); |
76 |
|
|
91 |
|
void * |
92 |
|
execute_callback(struct Callback *cb, ...) |
93 |
|
{ |
94 |
< |
void *res; |
94 |
> |
void *res = NULL; |
95 |
|
va_list args; |
96 |
|
|
97 |
|
cb->called++; |
101 |
|
return NULL; |
102 |
|
|
103 |
|
va_start(args, cb); |
104 |
< |
res = ((CBFUNC *) cb->chain.head->data)(args); |
104 |
> |
res = ((CBFUNC *)cb->chain.head->data)(args); |
105 |
|
va_end(args); |
106 |
|
|
107 |
|
return res; |
116 |
|
void * |
117 |
|
pass_callback(dlink_node *this_hook, ...) |
118 |
|
{ |
119 |
< |
void *res; |
119 |
> |
void *res = NULL; |
120 |
|
va_list args; |
121 |
|
|
122 |
|
if (this_hook->next == NULL) |
123 |
|
return NULL; /* reached the last one */ |
124 |
|
|
125 |
|
va_start(args, this_hook); |
126 |
< |
res = ((CBFUNC *) this_hook->next->data)(args); |
126 |
> |
res = ((CBFUNC *)this_hook->next->data)(args); |
127 |
|
va_end(args); |
128 |
|
|
129 |
|
return res; |
136 |
|
struct Callback * |
137 |
|
find_callback(const char *name) |
138 |
|
{ |
139 |
< |
dlink_node *ptr; |
139 |
> |
dlink_node *ptr = NULL; |
140 |
|
|
141 |
|
DLINK_FOREACH(ptr, callback_list.head) |
142 |
|
{ |
176 |
|
void |
177 |
|
uninstall_hook(struct Callback *cb, CBFUNC *hook) |
178 |
|
{ |
179 |
< |
/* let it core if not found */ |
179 |
> |
/* Let it core if not found */ |
180 |
|
dlink_node *ptr = dlinkFind(&cb->chain, hook); |
181 |
|
|
182 |
|
dlinkDelete(ptr, &cb->chain); |
190 |
|
void |
191 |
|
stats_hooks(struct Client *source_p) |
192 |
|
{ |
191 |
– |
dlink_node *ptr; |
193 |
|
char lastused[32]; |
194 |
+ |
const dlink_node *ptr = NULL; |
195 |
|
|
196 |
|
sendto_one(source_p, ":%s %d %s : %-20s %-20s Used Hooks", me.name, |
197 |
|
RPL_STATSDEBUG, source_p->name, "Callback", "Last Execution"); |
200 |
|
|
201 |
|
DLINK_FOREACH(ptr, callback_list.head) |
202 |
|
{ |
203 |
< |
struct Callback *cb = ptr->data; |
203 |
> |
const struct Callback *cb = ptr->data; |
204 |
|
|
205 |
|
if (cb->last != 0) |
206 |
|
snprintf(lastused, sizeof(lastused), "%d seconds ago", |
210 |
|
|
211 |
|
sendto_one(source_p, ":%s %d %s : %-20s %-20s %-8u %d", me.name, |
212 |
|
RPL_STATSDEBUG, source_p->name, cb->name, lastused, cb->called, |
213 |
< |
dlink_list_length(&cb->chain)); |
213 |
> |
dlink_list_length(&cb->chain)); |
214 |
|
} |
215 |
|
|
216 |
|
sendto_one(source_p, ":%s %d %s : ", me.name, RPL_STATSDEBUG, |