ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/whowas.c
Revision: 4800
Committed: Tue Oct 28 13:59:43 2014 UTC (10 years, 10 months ago) by michael
Content type: text/x-csrc
File size: 3375 byte(s)
Log Message:
- Renamed variables

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2916 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 2916 * Copyright (c) 1997-2014 ircd-hybrid development team
5 adx 30 *
6     * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18 michael 4565 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 adx 30 * USA
20     */
21    
22 michael 2916 /*! \file whowas.c
23     * \brief WHOWAS user cache.
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28 michael 1358 #include "list.h"
29 adx 30 #include "whowas.h"
30     #include "client.h"
31     #include "hash.h"
32     #include "irc_string.h"
33     #include "ircd.h"
34    
35    
36 michael 1358 static struct Whowas WHOWAS[NICKNAMEHISTORYLENGTH];
37     dlink_list WHOWASHASH[HASHSIZE];
38 adx 30
39    
40     void
41 michael 1997 whowas_init(void)
42     {
43 michael 3235 for (unsigned int i = 0; i < NICKNAMEHISTORYLENGTH; ++i)
44     WHOWAS[i].hashv = -1;
45 michael 1997 }
46    
47     void
48 michael 2300 whowas_add_history(struct Client *client_p, const int online)
49 adx 30 {
50 michael 1358 static unsigned int whowas_next = 0;
51 michael 3273 struct Whowas *const who = &WHOWAS[whowas_next];
52 adx 30
53 michael 3273 assert(IsClient(client_p));
54 adx 30
55 michael 1358 if (++whowas_next == NICKNAMEHISTORYLENGTH)
56     whowas_next = 0;
57    
58 adx 30 if (who->hashv != -1)
59     {
60     if (who->online)
61 michael 1358 dlinkDelete(&who->cnode, &who->online->whowas);
62    
63     dlinkDelete(&who->tnode, &WHOWASHASH[who->hashv]);
64 adx 30 }
65    
66 michael 507 who->hashv = strhash(client_p->name);
67 michael 2748 who->shide = IsHidden(client_p->servptr) != 0;
68 adx 30 who->logoff = CurrentTime;
69    
70 michael 4767 strlcpy(who->svid, client_p->svid, sizeof(who->svid));
71 adx 30 strlcpy(who->name, client_p->name, sizeof(who->name));
72 michael 1358 strlcpy(who->username, client_p->username, sizeof(who->username));
73     strlcpy(who->hostname, client_p->host, sizeof(who->hostname));
74     strlcpy(who->realname, client_p->info, sizeof(who->realname));
75 adx 30 strlcpy(who->servername, client_p->servptr->name, sizeof(who->servername));
76    
77     if (online)
78     {
79     who->online = client_p;
80 michael 1358 dlinkAdd(who, &who->cnode, &client_p->whowas);
81 adx 30 }
82     else
83     who->online = NULL;
84    
85 michael 1358 dlinkAdd(who, &who->tnode, &WHOWASHASH[who->hashv]);
86 adx 30 }
87    
88     void
89 michael 2300 whowas_off_history(struct Client *client_p)
90 adx 30 {
91 michael 4800 dlink_node *node = NULL, *node_next = NULL;
92 adx 30
93 michael 4800 DLINK_FOREACH_SAFE(node, node_next, client_p->whowas.head)
94 adx 30 {
95 michael 4800 struct Whowas *temp = node->data;
96 michael 1358
97 adx 30 temp->online = NULL;
98 michael 1358 dlinkDelete(&temp->cnode, &client_p->whowas);
99 adx 30 }
100     }
101    
102     struct Client *
103 michael 2300 whowas_get_history(const char *nick, time_t timelimit)
104 adx 30 {
105 michael 4800 dlink_node *node = NULL;
106 adx 30
107     timelimit = CurrentTime - timelimit;
108    
109 michael 4800 DLINK_FOREACH(node, WHOWASHASH[strhash(nick)].head)
110 adx 30 {
111 michael 4800 struct Whowas *temp = node->data;
112 michael 1358
113     if (temp->logoff < timelimit)
114     continue;
115 adx 30 if (irccmp(nick, temp->name))
116     continue;
117 michael 1298 return temp->online;
118 adx 30 }
119    
120 michael 1298 return NULL;
121 adx 30 }
122    
123     void
124 michael 2297 whowas_count_memory(unsigned int *const count, uint64_t *const bytes)
125 adx 30 {
126 michael 2297 const struct Whowas *tmp = &WHOWAS[0];
127 adx 30
128 michael 3235 for (unsigned int i = 0; i < NICKNAMEHISTORYLENGTH; ++i, ++tmp)
129 adx 30 {
130     if (tmp->hashv != -1)
131     {
132 michael 2297 (*count)++;
133     (*bytes) += sizeof(struct Whowas);
134 adx 30 }
135     }
136     }

Properties

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