ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/src/whowas.c
Revision: 1362
Committed: Sun Apr 22 19:05:08 2012 UTC (11 years, 11 months ago) by michael
Content type: text/x-csrc
File size: 3383 byte(s)
Log Message:
- whowas.c: sort out header includes

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

Properties

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