| 20 |
|
* USA |
| 21 |
|
*/ |
| 22 |
|
|
| 23 |
< |
/*! \file watch.c |
| 24 |
< |
* \brief File including functions for WATCH support |
| 23 |
> |
/*! \file monitor.c |
| 24 |
> |
* \brief File including functions for MONITOR support |
| 25 |
|
* \version $Id$ |
| 26 |
|
*/ |
| 27 |
|
|
| 34 |
|
#include "ircd.h" |
| 35 |
|
#include "numeric.h" |
| 36 |
|
#include "send.h" |
| 37 |
< |
#include "watch.h" |
| 37 |
> |
#include "monitor.h" |
| 38 |
|
|
| 39 |
|
|
| 40 |
< |
static dlink_list watchTable[HASHSIZE]; |
| 40 |
> |
static dlink_list monitor_table[HASHSIZE]; |
| 41 |
|
|
| 42 |
|
|
| 43 |
|
/* |
| 44 |
< |
* Rough figure of the datastructures for watch: |
| 44 |
> |
* Rough figure of the datastructures for monitor: |
| 45 |
|
* |
| 46 |
< |
* NOTIFY HASH client1 |
| 46 |
> |
* MONITOR HASH client1 |
| 47 |
|
* | |- nick1 |
| 48 |
|
* nick1-|- client1 |- nick2 |
| 49 |
|
* | |- client2 client3 |
| 53 |
|
* |- client1 |
| 54 |
|
*/ |
| 55 |
|
|
| 56 |
< |
/*! \brief Counts up memory used by watch list headers |
| 56 |
> |
/*! \brief Counts up memory used by monitor list headers |
| 57 |
|
*/ |
| 58 |
|
void |
| 59 |
< |
watch_count_memory(unsigned int *const count, size_t *const bytes) |
| 59 |
> |
monitor_count_memory(unsigned int *const count, size_t *const bytes) |
| 60 |
|
{ |
| 61 |
|
for (unsigned int i = 0; i < HASHSIZE; ++i) |
| 62 |
< |
(*count) += dlink_list_length(&watchTable[i]); |
| 62 |
> |
(*count) += dlink_list_length(&monitor_table[i]); |
| 63 |
|
|
| 64 |
< |
(*bytes) = *count * sizeof(struct Watch); |
| 64 |
> |
(*bytes) = *count * sizeof(struct Monitor); |
| 65 |
|
} |
| 66 |
|
|
| 67 |
|
/*! \brief Notifies all clients that have client's name on |
| 68 |
< |
* their watch list. |
| 68 |
> |
* their monitor list. |
| 69 |
|
* \param client Pointer to Client struct |
| 70 |
– |
* \param reply Numeric to send. Either RPL_LOGON or RPL_LOGOFF |
| 70 |
|
*/ |
| 71 |
|
void |
| 72 |
< |
watch_check_hash(const struct Client *client, const enum irc_numerics reply) |
| 72 |
> |
monitor_signon(const struct Client *client) |
| 73 |
|
{ |
| 74 |
< |
struct Watch *watch = NULL; |
| 75 |
< |
dlink_node *node = NULL; |
| 74 |
> |
char buf[NICKLEN + USERLEN + HOSTLEN + 3]; /* +3 for !, @, \0 */ |
| 75 |
> |
dlink_node *node; |
| 76 |
|
|
| 77 |
|
assert(IsClient(client)); |
| 78 |
|
|
| 79 |
< |
if ((watch = watch_find_hash(client->name)) == NULL) |
| 80 |
< |
return; /* This name isn't on watch */ |
| 79 |
> |
struct Monitor *monitor = monitor_find_hash(client->name); |
| 80 |
> |
if (monitor == NULL) |
| 81 |
> |
return; /* This name isn't on monitor */ |
| 82 |
|
|
| 83 |
< |
/* Update the time of last change to item */ |
| 84 |
< |
watch->lasttime = event_base->time.sec_real; |
| 83 |
> |
snprintf(buf, sizeof(buf), "%s!%s@%s", client->name, |
| 84 |
> |
client->username, client->host); |
| 85 |
|
|
| 86 |
|
/* Send notifies out to everybody on the list in header */ |
| 87 |
< |
DLINK_FOREACH(node, watch->watched_by.head) |
| 88 |
< |
sendto_one_numeric(node->data, &me, reply, client->name, |
| 89 |
< |
client->username, client->host, |
| 90 |
< |
watch->lasttime, client->info); |
| 87 |
> |
DLINK_FOREACH(node, monitor->monitored_by.head) |
| 88 |
> |
sendto_one_numeric(node->data, &me, RPL_MONONLINE, buf); |
| 89 |
|
} |
| 90 |
|
|
| 91 |
< |
/*! \brief Looks up the watch table for a given name |
| 91 |
> |
/*! \brief Notifies all clients that have client's name on |
| 92 |
> |
* their monitor list. |
| 93 |
> |
* \param client Pointer to Client struct |
| 94 |
> |
*/ |
| 95 |
> |
void |
| 96 |
> |
monitor_signoff(const struct Client *client) |
| 97 |
> |
{ |
| 98 |
> |
dlink_node *node; |
| 99 |
> |
|
| 100 |
> |
assert(IsClient(client)); |
| 101 |
> |
|
| 102 |
> |
struct Monitor *monitor = monitor_find_hash(client->name); |
| 103 |
> |
if (monitor == NULL) |
| 104 |
> |
return; /* This name isn't on monitor */ |
| 105 |
> |
|
| 106 |
> |
/* Send notifies out to everybody on the list in header */ |
| 107 |
> |
DLINK_FOREACH(node, monitor->monitored_by.head) |
| 108 |
> |
sendto_one_numeric(node->data, &me, RPL_MONOFFLINE, client->name); |
| 109 |
> |
} |
| 110 |
> |
|
| 111 |
> |
/*! \brief Looks up the monitor table for a given name |
| 112 |
|
* \param name Nick name to look up |
| 113 |
|
*/ |
| 114 |
< |
struct Watch * |
| 115 |
< |
watch_find_hash(const char *name) |
| 114 |
> |
struct Monitor * |
| 115 |
> |
monitor_find_hash(const char *name) |
| 116 |
|
{ |
| 117 |
< |
dlink_node *node = NULL; |
| 117 |
> |
dlink_node *node; |
| 118 |
|
|
| 119 |
< |
DLINK_FOREACH(node, watchTable[strhash(name)].head) |
| 119 |
> |
DLINK_FOREACH(node, monitor_table[strhash(name)].head) |
| 120 |
|
{ |
| 121 |
< |
struct Watch *watch = node->data; |
| 121 |
> |
struct Monitor *monitor = node->data; |
| 122 |
|
|
| 123 |
< |
if (irccmp(watch->name, name) == 0) |
| 124 |
< |
return watch; |
| 123 |
> |
if (irccmp(monitor->name, name) == 0) |
| 124 |
> |
return monitor; |
| 125 |
|
} |
| 126 |
|
|
| 127 |
|
return NULL; |
| 128 |
|
} |
| 129 |
|
|
| 130 |
< |
/*! \brief Adds a watch entry to client's watch list |
| 130 |
> |
/*! \brief Adds a monitor entry to client's monitor list |
| 131 |
|
* \param name Nick name to add |
| 132 |
|
* \param client Pointer to Client struct |
| 133 |
+ |
* \return false if the target is already being watched, true otherwise |
| 134 |
|
*/ |
| 135 |
< |
void |
| 136 |
< |
watch_add_to_hash_table(const char *name, struct Client *client) |
| 135 |
> |
bool |
| 136 |
> |
monitor_add_to_hash_table(const char *name, struct Client *client) |
| 137 |
|
{ |
| 119 |
– |
struct Watch *watch = NULL; |
| 138 |
|
dlink_node *node = NULL; |
| 139 |
|
|
| 140 |
|
/* If found NULL (no header for this name), make one... */ |
| 141 |
< |
if ((watch = watch_find_hash(name)) == NULL) |
| 141 |
> |
struct Monitor *monitor = monitor_find_hash(name); |
| 142 |
> |
if (monitor == NULL) |
| 143 |
|
{ |
| 144 |
< |
watch = xcalloc(sizeof(*watch)); |
| 144 |
> |
monitor = xcalloc(sizeof(*monitor)); |
| 145 |
|
|
| 146 |
< |
strlcpy(watch->name, name, sizeof(watch->name)); |
| 147 |
< |
watch->hash_value = strhash(watch->name); |
| 129 |
< |
watch->lasttime = event_base->time.sec_real; |
| 146 |
> |
strlcpy(monitor->name, name, sizeof(monitor->name)); |
| 147 |
> |
monitor->hash_value = strhash(monitor->name); |
| 148 |
|
|
| 149 |
< |
dlinkAdd(watch, &watch->node, &watchTable[watch->hash_value]); |
| 149 |
> |
dlinkAdd(monitor, &monitor->node, &monitor_table[monitor->hash_value]); |
| 150 |
|
} |
| 151 |
|
else |
| 152 |
|
{ |
| 153 |
< |
/* Is this client already on the watch-list? */ |
| 154 |
< |
node = dlinkFind(&watch->watched_by, client); |
| 153 |
> |
/* Is this client already on the monitor-list? */ |
| 154 |
> |
node = dlinkFind(&monitor->monitored_by, client); |
| 155 |
|
} |
| 156 |
|
|
| 157 |
|
if (node == NULL) |
| 158 |
|
{ |
| 159 |
|
/* No it isn't, so add it in the bucket and client adding it */ |
| 160 |
< |
dlinkAdd(client, make_dlink_node(), &watch->watched_by); |
| 161 |
< |
dlinkAdd(watch, make_dlink_node(), &client->connection->watches); |
| 160 |
> |
dlinkAdd(client, make_dlink_node(), &monitor->monitored_by); |
| 161 |
> |
dlinkAdd(monitor, make_dlink_node(), &client->connection->monitors); |
| 162 |
> |
return true; |
| 163 |
|
} |
| 164 |
+ |
|
| 165 |
+ |
return false; |
| 166 |
|
} |
| 167 |
|
|
| 168 |
< |
/*! \brief Removes a single entry from client's watch list |
| 168 |
> |
/*! \brief Removes a single entry from client's monitor list |
| 169 |
|
* \param name Name to remove |
| 170 |
|
* \param client Pointer to Client struct |
| 171 |
|
*/ |
| 172 |
|
void |
| 173 |
< |
watch_del_from_hash_table(const char *name, struct Client *client) |
| 173 |
> |
monitor_del_from_hash_table(const char *name, struct Client *client) |
| 174 |
|
{ |
| 175 |
< |
struct Watch *watch = NULL; |
| 176 |
< |
dlink_node *node = NULL; |
| 175 |
> |
struct Monitor *monitor = monitor_find_hash(name); |
| 176 |
> |
if (monitor == NULL) |
| 177 |
> |
return; /* No header found for that name. i.e. it's not being monitored */ |
| 178 |
|
|
| 179 |
< |
if ((watch = watch_find_hash(name)) == NULL) |
| 180 |
< |
return; /* No header found for that name. i.e. it's not being watched */ |
| 181 |
< |
|
| 160 |
< |
if ((node = dlinkFind(&watch->watched_by, client)) == NULL) |
| 161 |
< |
return; /* This name isn't being watched by client */ |
| 179 |
> |
dlink_node *node = dlinkFind(&monitor->monitored_by, client); |
| 180 |
> |
if (node == NULL) |
| 181 |
> |
return; /* This name isn't being monitored by client */ |
| 182 |
|
|
| 183 |
< |
dlinkDelete(node, &watch->watched_by); |
| 183 |
> |
dlinkDelete(node, &monitor->monitored_by); |
| 184 |
|
free_dlink_node(node); |
| 185 |
|
|
| 186 |
< |
if ((node = dlinkFindDelete(&client->connection->watches, watch))) |
| 186 |
> |
node = dlinkFindDelete(&client->connection->monitors, monitor); |
| 187 |
> |
if (node) |
| 188 |
|
free_dlink_node(node); |
| 189 |
|
|
| 190 |
|
/* In case this header is now empty of notices, remove it */ |
| 191 |
< |
if (watch->watched_by.head == NULL) |
| 191 |
> |
if (monitor->monitored_by.head == NULL) |
| 192 |
|
{ |
| 193 |
< |
assert(dlinkFind(&watchTable[watch->hash_value], watch)); |
| 194 |
< |
dlinkDelete(&watch->node, &watchTable[watch->hash_value]); |
| 195 |
< |
xfree(watch); |
| 193 |
> |
assert(dlinkFind(&monitor_table[monitor->hash_value], monitor)); |
| 194 |
> |
dlinkDelete(&monitor->node, &monitor_table[monitor->hash_value]); |
| 195 |
> |
xfree(monitor); |
| 196 |
|
} |
| 197 |
|
} |
| 198 |
|
|
| 199 |
< |
/*! \brief Removes all entries from client's watch list |
| 200 |
< |
* and deletes headers that are no longer being watched. |
| 199 |
> |
/*! \brief Removes all entries from client's monitor list |
| 200 |
> |
* and deletes headers that are no longer being monitored. |
| 201 |
|
* \param client Pointer to Client struct |
| 202 |
|
*/ |
| 203 |
|
void |
| 204 |
< |
watch_del_watch_list(struct Client *client) |
| 204 |
> |
monitor_clear_list(struct Client *client) |
| 205 |
|
{ |
| 206 |
< |
dlink_node *node = NULL, *node_next = NULL; |
| 186 |
< |
dlink_node *temp = NULL; |
| 206 |
> |
dlink_node *node, *node_next; |
| 207 |
|
|
| 208 |
< |
DLINK_FOREACH_SAFE(node, node_next, client->connection->watches.head) |
| 208 |
> |
DLINK_FOREACH_SAFE(node, node_next, client->connection->monitors.head) |
| 209 |
|
{ |
| 210 |
< |
struct Watch *watch = node->data; |
| 210 |
> |
struct Monitor *monitor = node->data; |
| 211 |
|
|
| 212 |
< |
assert(dlinkFind(&watch->watched_by, client)); |
| 212 |
> |
assert(dlinkFind(&monitor->monitored_by, client)); |
| 213 |
|
|
| 214 |
< |
if ((temp = dlinkFindDelete(&watch->watched_by, client))) |
| 214 |
> |
dlink_node *temp = dlinkFindDelete(&monitor->monitored_by, client); |
| 215 |
> |
if (temp) |
| 216 |
|
free_dlink_node(temp); |
| 217 |
|
|
| 218 |
|
/* If this leaves a header without notifies, remove it. */ |
| 219 |
< |
if (watch->watched_by.head == NULL) |
| 219 |
> |
if (monitor->monitored_by.head == NULL) |
| 220 |
|
{ |
| 221 |
< |
assert(dlinkFind(&watchTable[watch->hash_value], watch)); |
| 222 |
< |
dlinkDelete(&watch->node, &watchTable[watch->hash_value]); |
| 221 |
> |
assert(dlinkFind(&monitor_table[monitor->hash_value], monitor)); |
| 222 |
> |
dlinkDelete(&monitor->node, &monitor_table[monitor->hash_value]); |
| 223 |
|
|
| 224 |
< |
xfree(watch); |
| 224 |
> |
xfree(monitor); |
| 225 |
|
} |
| 226 |
|
|
| 227 |
< |
dlinkDelete(node, &client->connection->watches); |
| 227 |
> |
dlinkDelete(node, &client->connection->monitors); |
| 228 |
|
free_dlink_node(node); |
| 229 |
|
} |
| 230 |
|
|
| 231 |
< |
assert(client->connection->watches.head == NULL); |
| 232 |
< |
assert(client->connection->watches.tail == NULL); |
| 231 |
> |
assert(client->connection->monitors.head == NULL); |
| 232 |
> |
assert(client->connection->monitors.tail == NULL); |
| 233 |
|
} |