ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/whowas.c
Revision: 2916
Committed: Sat Jan 25 21:09:18 2014 UTC (12 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 3331 byte(s)
Log Message:
- Clean up all files in include/ (fixed indentation, removed whitespaces/tabs)
- Fixed copyright years

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     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19     * 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     unsigned int idx;
44    
45     for (idx = 0; idx < NICKNAMEHISTORYLENGTH; ++idx)
46     WHOWAS[idx].hashv = -1;
47     }
48    
49     void
50 michael 2300 whowas_add_history(struct Client *client_p, const int online)
51 adx 30 {
52 michael 1358 static unsigned int whowas_next = 0;
53 adx 30 struct Whowas *who = &WHOWAS[whowas_next];
54    
55 michael 507 assert(client_p && client_p->servptr);
56 adx 30
57 michael 1358 if (++whowas_next == NICKNAMEHISTORYLENGTH)
58     whowas_next = 0;
59    
60 adx 30 if (who->hashv != -1)
61     {
62     if (who->online)
63 michael 1358 dlinkDelete(&who->cnode, &who->online->whowas);
64    
65     dlinkDelete(&who->tnode, &WHOWASHASH[who->hashv]);
66 adx 30 }
67    
68 michael 507 who->hashv = strhash(client_p->name);
69 michael 2748 who->shide = IsHidden(client_p->servptr) != 0;
70 adx 30 who->logoff = CurrentTime;
71    
72     strlcpy(who->name, client_p->name, sizeof(who->name));
73 michael 1358 strlcpy(who->username, client_p->username, sizeof(who->username));
74     strlcpy(who->hostname, client_p->host, sizeof(who->hostname));
75     strlcpy(who->realname, client_p->info, sizeof(who->realname));
76 adx 30 strlcpy(who->servername, client_p->servptr->name, sizeof(who->servername));
77    
78     if (online)
79     {
80     who->online = client_p;
81 michael 1358 dlinkAdd(who, &who->cnode, &client_p->whowas);
82 adx 30 }
83     else
84     who->online = NULL;
85    
86 michael 1358 dlinkAdd(who, &who->tnode, &WHOWASHASH[who->hashv]);
87 adx 30 }
88    
89     void
90 michael 2300 whowas_off_history(struct Client *client_p)
91 adx 30 {
92 michael 1358 dlink_node *ptr = NULL, *ptr_next = NULL;
93 adx 30
94 michael 1358 DLINK_FOREACH_SAFE(ptr, ptr_next, client_p->whowas.head)
95 adx 30 {
96 michael 1358 struct Whowas *temp = ptr->data;
97    
98 adx 30 temp->online = NULL;
99 michael 1358 dlinkDelete(&temp->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 1358 dlink_node *ptr = NULL;
107 adx 30
108     timelimit = CurrentTime - timelimit;
109    
110 michael 1358 DLINK_FOREACH(ptr, WHOWASHASH[strhash(nick)].head)
111 adx 30 {
112 michael 1358 struct Whowas *temp = ptr->data;
113    
114     if (temp->logoff < timelimit)
115     continue;
116 adx 30 if (irccmp(nick, temp->name))
117     continue;
118 michael 1298 return temp->online;
119 adx 30 }
120    
121 michael 1298 return NULL;
122 adx 30 }
123    
124     void
125 michael 2297 whowas_count_memory(unsigned int *const count, uint64_t *const bytes)
126 adx 30 {
127 michael 2297 const struct Whowas *tmp = &WHOWAS[0];
128     unsigned int i = 0;
129 adx 30
130 michael 2297 for (; i < NICKNAMEHISTORYLENGTH; ++i, ++tmp)
131 adx 30 {
132     if (tmp->hashv != -1)
133     {
134 michael 2297 (*count)++;
135     (*bytes) += sizeof(struct Whowas);
136 adx 30 }
137     }
138     }

Properties

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