ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/whowas.c
Revision: 5631
Committed: Sun Mar 1 12:20:27 2015 UTC (9 years ago) by michael
Content type: text/x-csrc
File size: 3453 byte(s)
Log Message:
- WHOWAS now shows IP addresses to irc operators
- Changed RPL_WHOISACTUALLY numeric string. In the future it will also show the
  *real* hostname once we distinguish between spoofs/vhosts and real hosts

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2015 ircd-hybrid development team
5 *
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 * USA
20 */
21
22 /*! \file whowas.c
23 * \brief WHOWAS user cache.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "list.h"
29 #include "whowas.h"
30 #include "client.h"
31 #include "hash.h"
32 #include "irc_string.h"
33 #include "ircd.h"
34
35
36 static struct Whowas WHOWAS[NICKNAMEHISTORYLENGTH];
37 dlink_list WHOWASHASH[HASHSIZE];
38
39
40 void
41 whowas_init(void)
42 {
43 for (unsigned int i = 0; i < NICKNAMEHISTORYLENGTH; ++i)
44 WHOWAS[i].hashv = -1;
45 }
46
47 void
48 whowas_add_history(struct Client *client_p, const int online)
49 {
50 static unsigned int whowas_next = 0;
51 struct Whowas *const who = &WHOWAS[whowas_next];
52
53 assert(IsClient(client_p));
54
55 if (++whowas_next == NICKNAMEHISTORYLENGTH)
56 whowas_next = 0;
57
58 if (who->hashv != -1)
59 {
60 if (who->online)
61 dlinkDelete(&who->cnode, &who->online->whowas);
62
63 dlinkDelete(&who->tnode, &WHOWASHASH[who->hashv]);
64 }
65
66 who->hashv = strhash(client_p->name);
67 who->shide = IsHidden(client_p->servptr) != 0;
68 who->logoff = CurrentTime;
69
70 strlcpy(who->account, client_p->account, sizeof(who->account));
71 strlcpy(who->name, client_p->name, sizeof(who->name));
72 strlcpy(who->username, client_p->username, sizeof(who->username));
73 strlcpy(who->hostname, client_p->host, sizeof(who->hostname));
74 strlcpy(who->sockhost, client_p->sockhost, sizeof(who->sockhost));
75 strlcpy(who->realname, client_p->info, sizeof(who->realname));
76 strlcpy(who->servername, client_p->servptr->name, sizeof(who->servername));
77
78 if (online)
79 {
80 who->online = client_p;
81 dlinkAdd(who, &who->cnode, &client_p->whowas);
82 }
83 else
84 who->online = NULL;
85
86 dlinkAdd(who, &who->tnode, &WHOWASHASH[who->hashv]);
87 }
88
89 void
90 whowas_off_history(struct Client *client_p)
91 {
92 dlink_node *node = NULL, *node_next = NULL;
93
94 DLINK_FOREACH_SAFE(node, node_next, client_p->whowas.head)
95 {
96 struct Whowas *temp = node->data;
97
98 temp->online = NULL;
99 dlinkDelete(&temp->cnode, &client_p->whowas);
100 }
101 }
102
103 struct Client *
104 whowas_get_history(const char *nick, time_t timelimit)
105 {
106 dlink_node *node = NULL;
107
108 timelimit = CurrentTime - timelimit;
109
110 DLINK_FOREACH(node, WHOWASHASH[strhash(nick)].head)
111 {
112 struct Whowas *temp = node->data;
113
114 if (temp->logoff < timelimit)
115 continue;
116 if (irccmp(nick, temp->name))
117 continue;
118 return temp->online;
119 }
120
121 return NULL;
122 }
123
124 void
125 whowas_count_memory(unsigned int *const count, uint64_t *const bytes)
126 {
127 const struct Whowas *tmp = &WHOWAS[0];
128
129 for (unsigned int i = 0; i < NICKNAMEHISTORYLENGTH; ++i, ++tmp)
130 {
131 if (tmp->hashv != -1)
132 {
133 (*count)++;
134 (*bytes) += sizeof(struct Whowas);
135 }
136 }
137 }

Properties

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