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