ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/whowas.c
Revision: 6719
Committed: Fri Oct 30 18:18:07 2015 UTC (9 years, 9 months ago) by michael
Content type: text/x-csrc
File size: 3567 byte(s)
Log Message:
- Make mem-usage counters use size_t and use the %zu conversion specifier accordingly

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 5347 * Copyright (c) 1997-2015 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 6654 struct Whowas *const whowas = &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 michael 6654 if (whowas->hashv != -1)
59 adx 30 {
60 michael 6654 if (whowas->online)
61     dlinkDelete(&whowas->cnode, &whowas->online->whowas);
62 michael 1358
63 michael 6654 dlinkDelete(&whowas->tnode, &WHOWASHASH[whowas->hashv]);
64 adx 30 }
65    
66 michael 6654 whowas->hashv = strhash(client_p->name);
67     whowas->shide = IsHidden(client_p->servptr) != 0;
68     whowas->logoff = CurrentTime;
69 adx 30
70 michael 6654 strlcpy(whowas->account, client_p->account, sizeof(whowas->account));
71     strlcpy(whowas->name, client_p->name, sizeof(whowas->name));
72     strlcpy(whowas->username, client_p->username, sizeof(whowas->username));
73     strlcpy(whowas->hostname, client_p->host, sizeof(whowas->hostname));
74     strlcpy(whowas->sockhost, client_p->sockhost, sizeof(whowas->sockhost));
75     strlcpy(whowas->realname, client_p->info, sizeof(whowas->realname));
76     strlcpy(whowas->servername, client_p->servptr->name, sizeof(whowas->servername));
77 adx 30
78     if (online)
79     {
80 michael 6654 whowas->online = client_p;
81     dlinkAdd(whowas, &whowas->cnode, &client_p->whowas);
82 adx 30 }
83     else
84 michael 6654 whowas->online = NULL;
85 adx 30
86 michael 6654 dlinkAdd(whowas, &whowas->tnode, &WHOWASHASH[whowas->hashv]);
87 adx 30 }
88    
89     void
90 michael 2300 whowas_off_history(struct Client *client_p)
91 adx 30 {
92 michael 4800 dlink_node *node = NULL, *node_next = NULL;
93 adx 30
94 michael 4800 DLINK_FOREACH_SAFE(node, node_next, client_p->whowas.head)
95 adx 30 {
96 michael 6654 struct Whowas *whowas = node->data;
97 michael 1358
98 michael 6654 whowas->online = NULL;
99     dlinkDelete(&whowas->cnode, &client_p->whowas);
100 adx 30 }
101     }
102    
103     struct Client *
104 michael 2300 whowas_get_history(const char *nick, time_t timelimit)
105 adx 30 {
106 michael 4800 dlink_node *node = NULL;
107 adx 30
108     timelimit = CurrentTime - timelimit;
109    
110 michael 4800 DLINK_FOREACH(node, WHOWASHASH[strhash(nick)].head)
111 adx 30 {
112 michael 6654 struct Whowas *whowas = node->data;
113 michael 1358
114 michael 6654 if (whowas->logoff < timelimit)
115 michael 1358 continue;
116 michael 6654 if (irccmp(nick, whowas->name))
117 adx 30 continue;
118 michael 6654 return whowas->online;
119 adx 30 }
120    
121 michael 1298 return NULL;
122 adx 30 }
123    
124     void
125 michael 6719 whowas_count_memory(unsigned int *const count, size_t *const bytes)
126 adx 30 {
127 michael 6654 const struct Whowas *whowas = &WHOWAS[0];
128 adx 30
129 michael 6654 for (unsigned int i = 0; i < NICKNAMEHISTORYLENGTH; ++i, ++whowas)
130 adx 30 {
131 michael 6654 if (whowas->hashv != -1)
132 adx 30 {
133 michael 2297 (*count)++;
134     (*bytes) += sizeof(struct Whowas);
135 adx 30 }
136     }
137     }

Properties

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