ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/monitor.c
Revision: 7473
Committed: Sun Mar 13 12:32:13 2016 UTC (10 years, 6 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/src/watch.c
File size: 6202 byte(s)
Log Message:
- watch.c: remove unused header include

File Contents

# User Rev Content
1 michael 876 /*
2 michael 2855 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 michael 876 *
4 michael 2855 * Copyright (c) 1997 Jukka Santala (Donwulff)
5 michael 7006 * Copyright (c) 2005-2016 ircd-hybrid development team
6 michael 876 *
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
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * This program is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
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 michael 4565 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
20 michael 876 * USA
21     */
22    
23     /*! \file watch.c
24     * \brief File including functions for WATCH support
25 michael 879 * \version $Id$
26 michael 876 */
27    
28     #include "stdinc.h"
29 michael 1011 #include "list.h"
30 michael 876 #include "client.h"
31     #include "hash.h"
32     #include "irc_string.h"
33     #include "ircd.h"
34     #include "numeric.h"
35     #include "send.h"
36 michael 1654 #include "mempool.h"
37 michael 876 #include "watch.h"
38    
39    
40 michael 7473 static mp_pool_t *watch_pool;
41 michael 876 static dlink_list watchTable[HASHSIZE];
42    
43     /*! \brief Initializes the watch table
44     */
45     void
46     watch_init(void)
47     {
48 michael 1654 watch_pool = mp_pool_new(sizeof(struct Watch), MP_CHUNK_SIZE_WATCH);
49 michael 876 }
50    
51     /*
52     * Rough figure of the datastructures for watch:
53     *
54     * NOTIFY HASH client_p1
55     * | |- nick1
56     * nick1-|- client_p1 |- nick2
57     * | |- client_p2 client_p3
58     * | |- client_p3 client_p2 |- nick1
59     * | |- nick1
60     * nick2-|- client_p2 |- nick2
61     * |- client_p1
62     */
63    
64     /*! \brief Counts up memory used by watch list headers
65     */
66     void
67 michael 6719 watch_count_memory(unsigned int *const count, size_t *const bytes)
68 michael 876 {
69 michael 3250 for (unsigned int i = 0; i < HASHSIZE; ++i)
70     (*count) += dlink_list_length(&watchTable[i]);
71 michael 876
72 michael 2297 (*bytes) = *count * sizeof(struct Watch);
73 michael 876 }
74    
75 michael 7084 /*! \brief Notifies all clients that have client_p's name on
76 michael 876 * their watch list.
77 michael 2855 * \param client_p Pointer to Client struct
78     * \param reply Numeric to send. Either RPL_LOGON or RPL_LOGOFF
79 michael 876 */
80     void
81 michael 4785 watch_check_hash(const struct Client *client_p, const enum irc_numerics reply)
82 michael 876 {
83 michael 4815 struct Watch *watch = NULL;
84 michael 4800 dlink_node *node = NULL;
85 michael 3250
86 michael 876 assert(IsClient(client_p));
87 michael 3250
88 michael 4815 if ((watch = watch_find_hash(client_p->name)) == NULL)
89 michael 7084 return; /* This name isn't on watch */
90 michael 876
91 michael 1359 /* Update the time of last change to item */
92 michael 4815 watch->lasttime = CurrentTime;
93 michael 876
94 michael 1359 /* Send notifies out to everybody on the list in header */
95 michael 4815 DLINK_FOREACH(node, watch->watched_by.head)
96 michael 4800 sendto_one_numeric(node->data, &me, reply, client_p->name,
97 michael 3109 client_p->username, client_p->host,
98 michael 4815 watch->lasttime, client_p->info);
99 michael 876 }
100    
101 michael 7084 /*! \brief Looks up the watch table for a given name
102 michael 2855 * \param name Nick name to look up
103 michael 876 */
104     struct Watch *
105     watch_find_hash(const char *name)
106     {
107 michael 4800 dlink_node *node = NULL;
108 michael 876
109 michael 4800 DLINK_FOREACH(node, watchTable[strhash(name)].head)
110 michael 876 {
111 michael 4815 struct Watch *watch = node->data;
112 michael 876
113 michael 7084 if (!irccmp(watch->name, name))
114 michael 4815 return watch;
115 michael 876 }
116    
117     return NULL;
118     }
119    
120     /*! \brief Adds a watch entry to client_p's watch list
121 michael 7084 * \param name Nick name to add
122 michael 876 * \param client_p Pointer to Client struct
123     */
124     void
125 michael 7084 watch_add_to_hash_table(const char *name, struct Client *client_p)
126 michael 876 {
127 michael 4815 struct Watch *watch = NULL;
128 michael 4800 dlink_node *node = NULL;
129 michael 876
130 michael 7084 /* If found NULL (no header for this name), make one... */
131     if ((watch = watch_find_hash(name)) == NULL)
132 michael 876 {
133 michael 4815 watch = mp_pool_get(watch_pool);
134 michael 3250
135 michael 4815 watch->lasttime = CurrentTime;
136 michael 7084 strlcpy(watch->name, name, sizeof(watch->name));
137 michael 876
138 michael 7084 dlinkAdd(watch, &watch->node, &watchTable[strhash(watch->name)]);
139 michael 876 }
140     else
141     {
142 michael 1359 /* Is this client already on the watch-list? */
143 michael 4815 node = dlinkFind(&watch->watched_by, client_p);
144 michael 876 }
145    
146 michael 4800 if (node == NULL)
147 michael 876 {
148 michael 4728 /* No it isn't, so add it in the bucket and client adding it */
149 michael 4815 dlinkAdd(client_p, make_dlink_node(), &watch->watched_by);
150     dlinkAdd(watch, make_dlink_node(), &client_p->connection->watches);
151 michael 876 }
152     }
153    
154     /*! \brief Removes a single entry from client_p's watch list
155 michael 7084 * \param name Name to remove
156 michael 876 * \param client_p Pointer to Client struct
157     */
158     void
159 michael 7084 watch_del_from_hash_table(const char *name, struct Client *client_p)
160 michael 876 {
161 michael 4815 struct Watch *watch = NULL;
162 michael 4800 dlink_node *node = NULL;
163 michael 876
164 michael 7084 if ((watch = watch_find_hash(name)) == NULL)
165     return; /* No header found for that name. i.e. it's not being watched */
166 michael 876
167 michael 4815 if ((node = dlinkFind(&watch->watched_by, client_p)) == NULL)
168 michael 7084 return; /* This name isn't being watched by client_p */
169 michael 876
170 michael 4815 dlinkDelete(node, &watch->watched_by);
171 michael 4800 free_dlink_node(node);
172 michael 876
173 michael 4815 if ((node = dlinkFindDelete(&client_p->connection->watches, watch)))
174 michael 4800 free_dlink_node(node);
175 michael 876
176 michael 1359 /* In case this header is now empty of notices, remove it */
177 michael 4815 if (watch->watched_by.head == NULL)
178 michael 876 {
179 michael 7084 assert(dlinkFind(&watchTable[strhash(watch->name)], watch));
180     dlinkDelete(&watch->node, &watchTable[strhash(watch->name)]);
181 michael 4815 mp_pool_release(watch);
182 michael 876 }
183     }
184    
185     /*! \brief Removes all entries from client_p's watch list
186     * and deletes headers that are no longer being watched.
187     * \param client_p Pointer to Client struct
188     */
189     void
190     watch_del_watch_list(struct Client *client_p)
191     {
192 michael 4800 dlink_node *node = NULL, *node_next = NULL;
193     dlink_node *temp = NULL;
194 michael 876
195 michael 4800 DLINK_FOREACH_SAFE(node, node_next, client_p->connection->watches.head)
196 michael 876 {
197 michael 4815 struct Watch *watch = node->data;
198 michael 876
199 michael 4815 assert(dlinkFind(&watch->watched_by, client_p));
200 michael 876
201 michael 4815 if ((temp = dlinkFindDelete(&watch->watched_by, client_p)))
202 michael 4800 free_dlink_node(temp);
203 michael 876
204 michael 1359 /* If this leaves a header without notifies, remove it. */
205 michael 4815 if (watch->watched_by.head == NULL)
206 michael 876 {
207 michael 7084 assert(dlinkFind(&watchTable[strhash(watch->name)], watch));
208     dlinkDelete(&watch->node, &watchTable[strhash(watch->name)]);
209 michael 876
210 michael 4815 mp_pool_release(watch);
211 michael 876 }
212    
213 michael 4800 dlinkDelete(node, &client_p->connection->watches);
214     free_dlink_node(node);
215 michael 876 }
216    
217 michael 4588 assert(client_p->connection->watches.head == NULL);
218     assert(client_p->connection->watches.tail == NULL);
219 michael 876 }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision