ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/src/whowas.c
Revision: 607
Committed: Tue May 16 08:12:00 2006 UTC (20 years, 2 months ago) by michael
Content type: text/x-csrc
File size: 3289 byte(s)
Log Message:
- Only fully registered clients are added into the whowas history,
  so let's remove those pointles IsClient tests.

File Contents

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

Properties

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