ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/whowas.c
Revision: 1997
Committed: Sat May 11 17:35:07 2013 UTC (12 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 3389 byte(s)
Log Message:
- Mostly style cleanups & whitespace changes

File Contents

# Content
1 /*
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 * $Id$
23 */
24
25 #include "stdinc.h"
26 #include "list.h"
27 #include "whowas.h"
28 #include "client.h"
29 #include "hash.h"
30 #include "irc_string.h"
31 #include "ircd.h"
32
33
34 static struct Whowas WHOWAS[NICKNAMEHISTORYLENGTH];
35 dlink_list WHOWASHASH[HASHSIZE];
36
37
38 void
39 whowas_init(void)
40 {
41 unsigned int idx;
42
43 for (idx = 0; idx < NICKNAMEHISTORYLENGTH; ++idx)
44 WHOWAS[idx].hashv = -1;
45 }
46
47 void
48 add_history(struct Client *client_p, const int online)
49 {
50 static unsigned int whowas_next = 0;
51 struct Whowas *who = &WHOWAS[whowas_next];
52
53 assert(client_p && client_p->servptr);
54
55 if (++whowas_next == NICKNAMEHISTORYLENGTH)
56 whowas_next = 0;
57
58 if (who->hashv != -1)
59 {
60 if (who->online)
61 dlinkDelete(&who->cnode, &who->online->whowas);
62
63 dlinkDelete(&who->tnode, &WHOWASHASH[who->hashv]);
64 }
65
66 who->hashv = strhash(client_p->name);
67 who->logoff = CurrentTime;
68
69 strlcpy(who->name, client_p->name, sizeof(who->name));
70 strlcpy(who->username, client_p->username, sizeof(who->username));
71 strlcpy(who->hostname, client_p->host, sizeof(who->hostname));
72 strlcpy(who->realname, client_p->info, sizeof(who->realname));
73 strlcpy(who->servername, client_p->servptr->name, sizeof(who->servername));
74
75 if (online)
76 {
77 who->online = client_p;
78 dlinkAdd(who, &who->cnode, &client_p->whowas);
79 }
80 else
81 who->online = NULL;
82
83 dlinkAdd(who, &who->tnode, &WHOWASHASH[who->hashv]);
84 }
85
86 void
87 off_history(struct Client *client_p)
88 {
89 dlink_node *ptr = NULL, *ptr_next = NULL;
90
91 DLINK_FOREACH_SAFE(ptr, ptr_next, client_p->whowas.head)
92 {
93 struct Whowas *temp = ptr->data;
94
95 temp->online = NULL;
96 dlinkDelete(&temp->cnode, &client_p->whowas);
97 }
98 }
99
100 struct Client *
101 get_history(const char *nick, time_t timelimit)
102 {
103 dlink_node *ptr = NULL;
104
105 timelimit = CurrentTime - timelimit;
106
107 DLINK_FOREACH(ptr, WHOWASHASH[strhash(nick)].head)
108 {
109 struct Whowas *temp = ptr->data;
110
111 if (temp->logoff < timelimit)
112 continue;
113 if (irccmp(nick, temp->name))
114 continue;
115 return temp->online;
116 }
117
118 return NULL;
119 }
120
121 void
122 count_whowas_memory(unsigned int *wwu, uint64_t *wwum)
123 {
124 const struct Whowas *tmp;
125 int i;
126 unsigned int u = 0;
127 uint64_t um = 0;
128
129 /* count the number of used whowas structs in 'u' */
130 /* count up the memory used of whowas structs in um */
131 for (i = 0, tmp = &WHOWAS[0]; i < NICKNAMEHISTORYLENGTH; ++i, ++tmp)
132 {
133 if (tmp->hashv != -1)
134 {
135 ++u;
136 um += sizeof(struct Whowas);
137 }
138 }
139
140 *wwu = u;
141 *wwum = um;
142 }

Properties

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