| 1 |
|
/* |
| 2 |
< |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
| 2 |
> |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
|
* |
| 4 |
< |
* Copyright (C) 1997 Jukka Santala (Donwulff) |
| 5 |
< |
* Copyright (C) 2005 by the Hybrid Development Team. |
| 4 |
> |
* Copyright (c) 1997 Jukka Santala (Donwulff) |
| 5 |
> |
* Copyright (c) 2005-2014 ircd-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 |
| 16 |
|
* |
| 17 |
|
* You should have received a copy of the GNU General Public License |
| 18 |
|
* along with this program; if not, write to the Free Software |
| 19 |
< |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 19 |
> |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 20 |
|
* USA |
| 21 |
|
*/ |
| 22 |
|
|
| 27 |
|
|
| 28 |
|
#include "stdinc.h" |
| 29 |
|
#include "list.h" |
| 30 |
– |
#include "balloc.h" |
| 31 |
– |
#include "s_user.h" |
| 32 |
– |
#include "s_misc.h" |
| 30 |
|
#include "client.h" |
| 31 |
|
#include "hash.h" |
| 32 |
|
#include "irc_string.h" |
| 36 |
– |
#include "sprintf_irc.h" |
| 33 |
|
#include "ircd.h" |
| 34 |
|
#include "numeric.h" |
| 35 |
< |
#include "s_conf.h" |
| 40 |
< |
#include "s_serv.h" |
| 35 |
> |
#include "conf.h" |
| 36 |
|
#include "send.h" |
| 37 |
< |
#include "supported.h" |
| 43 |
< |
#include "whowas.h" |
| 44 |
< |
#include "memory.h" |
| 45 |
< |
#include "packet.h" |
| 46 |
< |
#include "s_misc.h" |
| 37 |
> |
#include "mempool.h" |
| 38 |
|
#include "watch.h" |
| 39 |
|
|
| 49 |
– |
#define WATCH_HEAP_SIZE 32 |
| 40 |
|
|
| 41 |
|
static dlink_list watchTable[HASHSIZE]; |
| 42 |
< |
|
| 53 |
< |
static BlockHeap *watch_heap = NULL; |
| 42 |
> |
static mp_pool_t *watch_pool; |
| 43 |
|
|
| 44 |
|
/*! \brief Initializes the watch table |
| 45 |
|
*/ |
| 46 |
|
void |
| 47 |
|
watch_init(void) |
| 48 |
|
{ |
| 49 |
< |
memset(watchTable, 0, sizeof(watchTable)); |
| 61 |
< |
|
| 62 |
< |
watch_heap = BlockHeapCreate("watch", sizeof(struct Watch), WATCH_HEAP_SIZE); |
| 49 |
> |
watch_pool = mp_pool_new(sizeof(struct Watch), MP_CHUNK_SIZE_WATCH); |
| 50 |
|
} |
| 51 |
|
|
| 52 |
|
/* |
| 65 |
|
/*! \brief Counts up memory used by watch list headers |
| 66 |
|
*/ |
| 67 |
|
void |
| 68 |
< |
watch_count_memory(unsigned int *const count, uint64_t *const memory) |
| 68 |
> |
watch_count_memory(unsigned int *const count, uint64_t *const bytes) |
| 69 |
|
{ |
| 70 |
< |
unsigned int idx; |
| 71 |
< |
|
| 85 |
< |
for (idx = 0; idx < HASHSIZE; ++idx) |
| 86 |
< |
*count += dlink_list_length(&watchTable[idx]); |
| 70 |
> |
for (unsigned int i = 0; i < HASHSIZE; ++i) |
| 71 |
> |
(*count) += dlink_list_length(&watchTable[i]); |
| 72 |
|
|
| 73 |
< |
*memory = *count * sizeof(struct Watch); |
| 73 |
> |
(*bytes) = *count * sizeof(struct Watch); |
| 74 |
|
} |
| 75 |
|
|
| 76 |
|
/*! \brief Notifies all clients that have client_p's nick name on |
| 77 |
|
* their watch list. |
| 78 |
< |
* \param client_p pointer to Client struct |
| 79 |
< |
* \param reply numeric to send. Either RPL_LOGON or RPL_LOGOFF |
| 78 |
> |
* \param client_p Pointer to Client struct |
| 79 |
> |
* \param reply Numeric to send. Either RPL_LOGON or RPL_LOGOFF |
| 80 |
|
*/ |
| 81 |
|
void |
| 82 |
< |
watch_check_hash(struct Client *client_p, int reply) |
| 82 |
> |
watch_check_hash(struct Client *client_p, const enum irc_numerics reply) |
| 83 |
|
{ |
| 84 |
|
struct Watch *anptr = NULL; |
| 85 |
|
dlink_node *ptr = NULL; |
| 86 |
+ |
|
| 87 |
|
assert(IsClient(client_p)); |
| 88 |
+ |
|
| 89 |
|
if ((anptr = watch_find_hash(client_p->name)) == NULL) |
| 90 |
< |
return; // This nick isn't on watch |
| 90 |
> |
return; /* This nick isn't on watch */ |
| 91 |
|
|
| 92 |
< |
// Update the time of last change to item |
| 92 |
> |
/* Update the time of last change to item */ |
| 93 |
|
anptr->lasttime = CurrentTime; |
| 94 |
|
|
| 95 |
< |
// Send notifies out to everybody on the list in header |
| 95 |
> |
/* Send notifies out to everybody on the list in header */ |
| 96 |
|
DLINK_FOREACH(ptr, anptr->watched_by.head) |
| 97 |
< |
{ |
| 98 |
< |
struct Client *target_p = ptr->data; |
| 99 |
< |
|
| 113 |
< |
sendto_one(target_p, form_str(reply), |
| 114 |
< |
me.name, target_p->name, client_p->name, |
| 115 |
< |
client_p->username, client_p->host, |
| 116 |
< |
anptr->lasttime, client_p->info); |
| 117 |
< |
} |
| 97 |
> |
sendto_one_numeric(ptr->data, &me, reply, client_p->name, |
| 98 |
> |
client_p->username, client_p->host, |
| 99 |
> |
anptr->lasttime, client_p->info); |
| 100 |
|
} |
| 101 |
|
|
| 102 |
|
/*! \brief Looks up the watch table for a given nick |
| 103 |
< |
* \param name nick name to look up |
| 103 |
> |
* \param name Nick name to look up |
| 104 |
|
*/ |
| 105 |
|
struct Watch * |
| 106 |
|
watch_find_hash(const char *name) |
| 119 |
|
} |
| 120 |
|
|
| 121 |
|
/*! \brief Adds a watch entry to client_p's watch list |
| 122 |
< |
* \param nick nick name to add |
| 122 |
> |
* \param nick Nick name to add |
| 123 |
|
* \param client_p Pointer to Client struct |
| 124 |
|
*/ |
| 125 |
|
void |
| 128 |
|
struct Watch *anptr = NULL; |
| 129 |
|
dlink_node *ptr = NULL; |
| 130 |
|
|
| 131 |
< |
// If found NULL (no header for this nick), make one... |
| 131 |
> |
/* If found NULL (no header for this nick), make one... */ |
| 132 |
|
if ((anptr = watch_find_hash(nick)) == NULL) |
| 133 |
|
{ |
| 134 |
< |
anptr = BlockHeapAlloc(watch_heap); |
| 134 |
> |
anptr = mp_pool_get(watch_pool); |
| 135 |
> |
|
| 136 |
|
anptr->lasttime = CurrentTime; |
| 137 |
|
strlcpy(anptr->nick, nick, sizeof(anptr->nick)); |
| 138 |
|
|
| 139 |
< |
dlinkAdd(anptr, &anptr->node, &watchTable[strhash(nick)]); |
| 139 |
> |
dlinkAdd(anptr, &anptr->node, &watchTable[strhash(anptr->nick)]); |
| 140 |
|
} |
| 141 |
|
else |
| 142 |
|
{ |
| 143 |
< |
// Is this client already on the watch-list? |
| 143 |
> |
/* Is this client already on the watch-list? */ |
| 144 |
|
ptr = dlinkFind(&anptr->watched_by, client_p); |
| 145 |
|
} |
| 146 |
|
|
| 147 |
|
if (ptr == NULL) |
| 148 |
|
{ |
| 149 |
< |
// No it isn't, so add it in the bucket and client addint it |
| 149 |
> |
/* No it isn't, so add it in the bucket and client adding it */ |
| 150 |
|
dlinkAdd(client_p, make_dlink_node(), &anptr->watched_by); |
| 151 |
< |
dlinkAdd(anptr, make_dlink_node(), &client_p->localClient->watches); |
| 151 |
> |
dlinkAdd(anptr, make_dlink_node(), &client_p->connection->watches); |
| 152 |
|
} |
| 153 |
|
} |
| 154 |
|
|
| 155 |
|
/*! \brief Removes a single entry from client_p's watch list |
| 156 |
< |
* \param nick nick name to remove |
| 156 |
> |
* \param nick Nick name to remove |
| 157 |
|
* \param client_p Pointer to Client struct |
| 158 |
|
*/ |
| 159 |
|
void |
| 163 |
|
dlink_node *ptr = NULL; |
| 164 |
|
|
| 165 |
|
if ((anptr = watch_find_hash(nick)) == NULL) |
| 166 |
< |
return; // No header found for that nick. i.e. it's not being watched |
| 166 |
> |
return; /* No header found for that nick. i.e. it's not being watched */ |
| 167 |
|
|
| 168 |
|
if ((ptr = dlinkFind(&anptr->watched_by, client_p)) == NULL) |
| 169 |
< |
return; // This nick isn't being watched by client_p |
| 169 |
> |
return; /* This nick isn't being watched by client_p */ |
| 170 |
|
|
| 171 |
|
dlinkDelete(ptr, &anptr->watched_by); |
| 172 |
|
free_dlink_node(ptr); |
| 173 |
|
|
| 174 |
< |
if ((ptr = dlinkFindDelete(&client_p->localClient->watches, anptr))) |
| 174 |
> |
if ((ptr = dlinkFindDelete(&client_p->connection->watches, anptr))) |
| 175 |
|
free_dlink_node(ptr); |
| 176 |
|
|
| 177 |
< |
// In case this header is now empty of notices, remove it |
| 177 |
> |
/* In case this header is now empty of notices, remove it */ |
| 178 |
|
if (anptr->watched_by.head == NULL) |
| 179 |
|
{ |
| 180 |
< |
assert(dlinkFind(&watchTable[strhash(nick)], anptr) != NULL); |
| 181 |
< |
dlinkDelete(&anptr->node, &watchTable[strhash(nick)]); |
| 182 |
< |
BlockHeapFree(watch_heap, anptr); |
| 180 |
> |
assert(dlinkFind(&watchTable[strhash(anptr->nick)], anptr)); |
| 181 |
> |
dlinkDelete(&anptr->node, &watchTable[strhash(anptr->nick)]); |
| 182 |
> |
mp_pool_release(anptr); |
| 183 |
|
} |
| 184 |
|
} |
| 185 |
|
|
| 193 |
|
dlink_node *ptr = NULL, *ptr_next = NULL; |
| 194 |
|
dlink_node *tmp = NULL; |
| 195 |
|
|
| 196 |
< |
DLINK_FOREACH_SAFE(ptr, ptr_next, client_p->localClient->watches.head) |
| 196 |
> |
DLINK_FOREACH_SAFE(ptr, ptr_next, client_p->connection->watches.head) |
| 197 |
|
{ |
| 198 |
|
struct Watch *anptr = ptr->data; |
| 199 |
|
|
| 200 |
< |
assert(anptr); |
| 200 |
> |
assert(dlinkFind(&anptr->watched_by, client_p)); |
| 201 |
|
|
| 219 |
– |
assert(dlinkFind(&anptr->watched_by, client_p) != NULL); |
| 202 |
|
if ((tmp = dlinkFindDelete(&anptr->watched_by, client_p))) |
| 203 |
|
free_dlink_node(tmp); |
| 204 |
|
|
| 205 |
< |
// If this leaves a header without notifies, remove it. |
| 205 |
> |
/* If this leaves a header without notifies, remove it. */ |
| 206 |
|
if (anptr->watched_by.head == NULL) |
| 207 |
|
{ |
| 208 |
< |
assert(dlinkFind(&watchTable[strhash(anptr->nick)], anptr) != NULL); |
| 208 |
> |
assert(dlinkFind(&watchTable[strhash(anptr->nick)], anptr)); |
| 209 |
|
dlinkDelete(&anptr->node, &watchTable[strhash(anptr->nick)]); |
| 210 |
|
|
| 211 |
< |
BlockHeapFree(watch_heap, anptr); |
| 211 |
> |
mp_pool_release(anptr); |
| 212 |
|
} |
| 213 |
|
|
| 214 |
< |
dlinkDelete(ptr, &client_p->localClient->watches); |
| 214 |
> |
dlinkDelete(ptr, &client_p->connection->watches); |
| 215 |
|
free_dlink_node(ptr); |
| 216 |
|
} |
| 217 |
|
|
| 218 |
< |
assert(client_p->localClient->watches.head == NULL); |
| 219 |
< |
assert(client_p->localClient->watches.tail == NULL); |
| 218 |
> |
assert(client_p->connection->watches.head == NULL); |
| 219 |
> |
assert(client_p->connection->watches.tail == NULL); |
| 220 |
|
} |