ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/whowas.c
Revision: 1358
Committed: Sun Apr 22 13:49:23 2012 UTC (13 years, 4 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/src/whowas.c
File size: 3523 byte(s)
Log Message:
- cleanup and rewrite whowas.c to use the dlink list manipulation routines
- increase NICKNAMEHISTORYLENGTH to 16384

File Contents

# User Rev Content
1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * whowas.c: WHOWAS user cache.
4     *
5     * Copyright (C) 2005 by the past and present ircd coders, and others.
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
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     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20     * USA
21     *
22 knight 31 * $Id$
23 adx 30 */
24    
25     #include "stdinc.h"
26 michael 1358 #include "list.h"
27 adx 30 #include "whowas.h"
28     #include "client.h"
29     #include "hash.h"
30     #include "irc_string.h"
31     #include "ircd.h"
32     #include "ircd_defs.h"
33     #include "numeric.h"
34     #include "s_serv.h"
35     #include "s_user.h"
36     #include "send.h"
37 michael 1309 #include "conf.h"
38 adx 30 #include "memory.h"
39    
40    
41 michael 1358 static struct Whowas WHOWAS[NICKNAMEHISTORYLENGTH];
42     dlink_list WHOWASHASH[HASHSIZE];
43 adx 30
44    
45     void
46     add_history(struct Client *client_p, int online)
47     {
48 michael 1358 static unsigned int whowas_next = 0;
49 adx 30 struct Whowas *who = &WHOWAS[whowas_next];
50    
51 michael 507 assert(client_p && client_p->servptr);
52 adx 30
53 michael 1358 if (++whowas_next == NICKNAMEHISTORYLENGTH)
54     whowas_next = 0;
55    
56 adx 30 if (who->hashv != -1)
57     {
58     if (who->online)
59 michael 1358 dlinkDelete(&who->cnode, &who->online->whowas);
60    
61     dlinkDelete(&who->tnode, &WHOWASHASH[who->hashv]);
62 adx 30 }
63    
64 michael 507 who->hashv = strhash(client_p->name);
65 adx 30 who->logoff = CurrentTime;
66    
67     strlcpy(who->name, client_p->name, sizeof(who->name));
68 michael 1358 strlcpy(who->username, client_p->username, sizeof(who->username));
69     strlcpy(who->hostname, client_p->host, sizeof(who->hostname));
70     strlcpy(who->realname, client_p->info, sizeof(who->realname));
71 adx 30 strlcpy(who->servername, client_p->servptr->name, sizeof(who->servername));
72    
73     if (online)
74     {
75     who->online = client_p;
76 michael 1358 dlinkAdd(who, &who->cnode, &client_p->whowas);
77 adx 30 }
78     else
79     who->online = NULL;
80    
81 michael 1358 dlinkAdd(who, &who->tnode, &WHOWASHASH[who->hashv]);
82 adx 30 }
83    
84     void
85     off_history(struct Client *client_p)
86     {
87 michael 1358 dlink_node *ptr = NULL, *ptr_next = NULL;
88 adx 30
89 michael 1358 DLINK_FOREACH_SAFE(ptr, ptr_next, client_p->whowas.head)
90 adx 30 {
91 michael 1358 struct Whowas *temp = ptr->data;
92    
93 adx 30 temp->online = NULL;
94 michael 1358 dlinkDelete(&temp->cnode, &client_p->whowas);
95 adx 30 }
96     }
97    
98     struct Client *
99     get_history(const char *nick, time_t timelimit)
100     {
101 michael 1358 dlink_node *ptr = NULL;
102 adx 30
103     timelimit = CurrentTime - timelimit;
104    
105 michael 1358 DLINK_FOREACH(ptr, WHOWASHASH[strhash(nick)].head)
106 adx 30 {
107 michael 1358 struct Whowas *temp = ptr->data;
108    
109     if (temp->logoff < timelimit)
110     continue;
111 adx 30 if (irccmp(nick, temp->name))
112     continue;
113 michael 1298 return temp->online;
114 adx 30 }
115    
116 michael 1298 return NULL;
117 adx 30 }
118    
119     void
120 michael 948 count_whowas_memory(unsigned int *wwu, uint64_t *wwum)
121 adx 30 {
122 michael 948 const struct Whowas *tmp;
123 adx 30 int i;
124 michael 948 unsigned int u = 0;
125     uint64_t um = 0;
126 adx 30
127     /* count the number of used whowas structs in 'u' */
128     /* count up the memory used of whowas structs in um */
129 michael 948 for (i = 0, tmp = &WHOWAS[0]; i < NICKNAMEHISTORYLENGTH; ++i, ++tmp)
130 adx 30 {
131     if (tmp->hashv != -1)
132     {
133 michael 948 ++u;
134 adx 30 um += sizeof(struct Whowas);
135     }
136     }
137    
138     *wwu = u;
139     *wwum = um;
140     }
141    
142     void
143 michael 1358 whowas_init(void)
144 adx 30 {
145 michael 1358 unsigned int idx;
146 adx 30
147 michael 1358 for (idx = 0; idx < NICKNAMEHISTORYLENGTH; ++idx)
148     WHOWAS[idx].hashv = -1;
149 adx 30 }

Properties

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