ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/src/whowas.c
Revision: 194
Committed: Thu Oct 27 18:56:46 2005 UTC (19 years, 10 months ago) by michael
Content type: text/x-csrc
File size: 3439 byte(s)
Log Message:
- Fixed several compiletime warnings

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 if (++whowas_next == NICKNAMEHISTORYLENGTH)
48 whowas_next = 0;
49
50 assert(client_p != NULL);
51
52 /* XXX when is this possible? Looks like it could happen
53 * (with a half registered client.)
54 * and what is the correct action here? - Dianora
55 */
56 if (client_p->servptr == NULL)
57 return;
58
59 if (who->hashv != -1)
60 {
61 if (who->online)
62 dlinkDelete(&who->cnode, &who->online->whowas);
63
64 dlinkDelete(&who->tnode, &WHOWASHASH[who->hashv]);
65 }
66
67 who->hashv = strhash(client_p->name);
68 who->logoff = CurrentTime;
69
70 /* NOTE: strcpy ok here, the sizes in the client struct MUST
71 * match the sizes in the whowas struct
72 */
73 strlcpy(who->name, client_p->name, sizeof(who->name));
74 strcpy(who->username, client_p->username);
75 strcpy(who->hostname, client_p->host);
76 strcpy(who->realname, client_p->info);
77
78 strlcpy(who->servername, client_p->servptr->name, sizeof(who->servername));
79
80 if (online)
81 {
82 who->online = client_p;
83 dlinkAdd(who, &who->cnode, &client_p->whowas);
84 }
85 else
86 who->online = NULL;
87
88 dlinkAdd(who, &who->tnode, &WHOWASHASH[who->hashv]);
89 }
90
91 void
92 off_history(struct Client *client_p)
93 {
94 dlink_node *ptr = NULL, *ptr_next = NULL;
95
96 DLINK_FOREACH_SAFE(ptr, ptr_next, client_p->whowas.head)
97 {
98 struct Whowas *temp = ptr->data;
99 temp->online = NULL;
100 dlinkDelete(&temp->cnode, &client_p->whowas);
101 }
102 }
103
104 struct Client *
105 get_history(const char *nick, time_t timelimit)
106 {
107 dlink_node *ptr = NULL;
108
109 timelimit = CurrentTime - timelimit;
110
111 DLINK_FOREACH(ptr, WHOWASHASH[strhash(nick)].head) {
112 struct Whowas *temp = ptr->data;
113
114 if (irccmp(nick, temp->name))
115 continue;
116 if (temp->logoff < timelimit)
117 continue;
118 return temp->online;
119 }
120
121 return NULL;
122 }
123
124 void
125 init_whowas(void)
126 {
127 unsigned int i;
128
129 for (i = 0; i < NICKNAMEHISTORYLENGTH; ++i)
130 {
131 memset(&WHOWAS[i], 0, sizeof(struct Whowas));
132 WHOWAS[i].hashv = -1;
133 }
134
135 /*
136 * Global variables are always 0 initialized,
137 * but we do this anyway.
138 */
139 memset(WHOWASHASH, 0, sizeof(WHOWASHASH));
140 }

Properties

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