| 26 |
|
*/ |
| 27 |
|
|
| 28 |
|
#include "stdinc.h" |
| 29 |
< |
#include "tools.h" |
| 30 |
< |
#include "s_user.h" |
| 31 |
< |
#include "s_misc.h" |
| 29 |
> |
#include "list.h" |
| 30 |
|
#include "client.h" |
| 33 |
– |
#include "common.h" |
| 31 |
|
#include "hash.h" |
| 32 |
|
#include "irc_string.h" |
| 36 |
– |
#include "sprintf_irc.h" |
| 33 |
|
#include "ircd.h" |
| 38 |
– |
#include "list.h" |
| 39 |
– |
#include "listener.h" |
| 40 |
– |
#include "motd.h" |
| 34 |
|
#include "numeric.h" |
| 35 |
< |
#include "s_conf.h" |
| 43 |
< |
#include "s_log.h" |
| 44 |
< |
#include "s_serv.h" |
| 45 |
< |
#include "s_stats.h" |
| 35 |
> |
#include "conf.h" |
| 36 |
|
#include "send.h" |
| 37 |
< |
#include "supported.h" |
| 48 |
< |
#include "whowas.h" |
| 49 |
< |
#include "memory.h" |
| 50 |
< |
#include "packet.h" |
| 51 |
< |
#include "s_misc.h" |
| 52 |
< |
#include "msg.h" |
| 37 |
> |
#include "mempool.h" |
| 38 |
|
#include "watch.h" |
| 39 |
|
|
| 55 |
– |
#define WATCH_HEAP_SIZE 32 |
| 40 |
|
|
| 41 |
|
static dlink_list watchTable[HASHSIZE]; |
| 42 |
|
|
| 43 |
< |
static BlockHeap *watch_heap = NULL; |
| 43 |
> |
static mp_pool_t *watch_pool = NULL; |
| 44 |
|
|
| 45 |
|
/*! \brief Initializes the watch table |
| 46 |
|
*/ |
| 47 |
|
void |
| 48 |
|
watch_init(void) |
| 49 |
|
{ |
| 50 |
< |
memset(watchTable, 0, sizeof(watchTable)); |
| 67 |
< |
|
| 68 |
< |
watch_heap = BlockHeapCreate("watch", sizeof(struct Watch), WATCH_HEAP_SIZE); |
| 50 |
> |
watch_pool = mp_pool_new(sizeof(struct Watch), MP_CHUNK_SIZE_WATCH); |
| 51 |
|
} |
| 52 |
|
|
| 53 |
|
/* |
| 66 |
|
/*! \brief Counts up memory used by watch list headers |
| 67 |
|
*/ |
| 68 |
|
void |
| 69 |
< |
watch_count_memory(unsigned int *const count, size_t *const memory) |
| 69 |
> |
watch_count_memory(unsigned int *const count, uint64_t *const memory) |
| 70 |
|
{ |
| 71 |
|
unsigned int idx; |
| 72 |
|
|
| 82 |
|
* \param reply numeric to send. Either RPL_LOGON or RPL_LOGOFF |
| 83 |
|
*/ |
| 84 |
|
void |
| 85 |
< |
watch_check_hash(struct Client *client_p, int reply) |
| 85 |
> |
watch_check_hash(struct Client *client_p, unsigned int reply) |
| 86 |
|
{ |
| 87 |
|
struct Watch *anptr = NULL; |
| 88 |
|
dlink_node *ptr = NULL; |
| 89 |
|
assert(IsClient(client_p)); |
| 90 |
|
if ((anptr = watch_find_hash(client_p->name)) == NULL) |
| 91 |
< |
return; // This nick isn't on watch |
| 91 |
> |
return; /* This nick isn't on watch */ |
| 92 |
|
|
| 93 |
< |
// Update the time of last change to item |
| 93 |
> |
/* Update the time of last change to item */ |
| 94 |
|
anptr->lasttime = CurrentTime; |
| 95 |
|
|
| 96 |
< |
// Send notifies out to everybody on the list in header |
| 96 |
> |
/* Send notifies out to everybody on the list in header */ |
| 97 |
|
DLINK_FOREACH(ptr, anptr->watched_by.head) |
| 98 |
|
{ |
| 99 |
|
struct Client *target_p = ptr->data; |
| 134 |
|
struct Watch *anptr = NULL; |
| 135 |
|
dlink_node *ptr = NULL; |
| 136 |
|
|
| 137 |
< |
// If found NULL (no header for this nick), make one... |
| 137 |
> |
/* If found NULL (no header for this nick), make one... */ |
| 138 |
|
if ((anptr = watch_find_hash(nick)) == NULL) |
| 139 |
|
{ |
| 140 |
< |
anptr = BlockHeapAlloc(watch_heap); |
| 140 |
> |
anptr = mp_pool_get(watch_pool); |
| 141 |
> |
memset(anptr, 0, sizeof(*anptr)); |
| 142 |
|
anptr->lasttime = CurrentTime; |
| 143 |
|
strlcpy(anptr->nick, nick, sizeof(anptr->nick)); |
| 144 |
|
|
| 146 |
|
} |
| 147 |
|
else |
| 148 |
|
{ |
| 149 |
< |
// Is this client already on the watch-list? |
| 149 |
> |
/* Is this client already on the watch-list? */ |
| 150 |
|
ptr = dlinkFind(&anptr->watched_by, client_p); |
| 151 |
|
} |
| 152 |
|
|
| 153 |
|
if (ptr == NULL) |
| 154 |
|
{ |
| 155 |
< |
// No it isn't, so add it in the bucket and client addint it |
| 155 |
> |
/* No it isn't, so add it in the bucket and client addint it */ |
| 156 |
|
dlinkAdd(client_p, make_dlink_node(), &anptr->watched_by); |
| 157 |
|
dlinkAdd(anptr, make_dlink_node(), &client_p->localClient->watches); |
| 158 |
|
} |
| 169 |
|
dlink_node *ptr = NULL; |
| 170 |
|
|
| 171 |
|
if ((anptr = watch_find_hash(nick)) == NULL) |
| 172 |
< |
return; // No header found for that nick. i.e. it's not being watched |
| 172 |
> |
return; /* No header found for that nick. i.e. it's not being watched */ |
| 173 |
|
|
| 174 |
|
if ((ptr = dlinkFind(&anptr->watched_by, client_p)) == NULL) |
| 175 |
< |
return; // This nick isn't being watched by client_p |
| 175 |
> |
return; /* This nick isn't being watched by client_p */ |
| 176 |
|
|
| 177 |
|
dlinkDelete(ptr, &anptr->watched_by); |
| 178 |
|
free_dlink_node(ptr); |
| 180 |
|
if ((ptr = dlinkFindDelete(&client_p->localClient->watches, anptr))) |
| 181 |
|
free_dlink_node(ptr); |
| 182 |
|
|
| 183 |
< |
// In case this header is now empty of notices, remove it |
| 183 |
> |
/* In case this header is now empty of notices, remove it */ |
| 184 |
|
if (anptr->watched_by.head == NULL) |
| 185 |
|
{ |
| 186 |
|
assert(dlinkFind(&watchTable[strhash(nick)], anptr) != NULL); |
| 187 |
|
dlinkDelete(&anptr->node, &watchTable[strhash(nick)]); |
| 188 |
< |
BlockHeapFree(watch_heap, anptr); |
| 188 |
> |
mp_pool_release(anptr); |
| 189 |
|
} |
| 190 |
|
} |
| 191 |
|
|
| 209 |
|
if ((tmp = dlinkFindDelete(&anptr->watched_by, client_p))) |
| 210 |
|
free_dlink_node(tmp); |
| 211 |
|
|
| 212 |
< |
// If this leaves a header without notifies, remove it. |
| 212 |
> |
/* If this leaves a header without notifies, remove it. */ |
| 213 |
|
if (anptr->watched_by.head == NULL) |
| 214 |
|
{ |
| 215 |
|
assert(dlinkFind(&watchTable[strhash(anptr->nick)], anptr) != NULL); |
| 216 |
|
dlinkDelete(&anptr->node, &watchTable[strhash(anptr->nick)]); |
| 217 |
|
|
| 218 |
< |
BlockHeapFree(watch_heap, anptr); |
| 218 |
> |
mp_pool_release(anptr); |
| 219 |
|
} |
| 220 |
|
|
| 221 |
|
dlinkDelete(ptr, &client_p->localClient->watches); |