ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/src/whowas.c
Revision: 69
Committed: Tue Oct 4 16:09:51 2005 UTC (20 years, 10 months ago) by adx
Content type: text/x-csrc
File size: 4997 byte(s)
Log Message:
- splitted ircd/libio, all headers connected with libio sources have been
  moved for internal use only. To use libio interface, include "libio.h"
  (which is already done in "stdinc.h")


File Contents

# User Rev Content
1 adx 30 /*
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 knight 31 * $Id$
23 adx 30 */
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     /* internally defined function */
39     static void add_whowas_to_clist(struct Whowas **, struct Whowas *);
40     static void del_whowas_from_clist(struct Whowas **, struct Whowas *);
41     static void add_whowas_to_list(struct Whowas **, struct Whowas *);
42     static void del_whowas_from_list(struct Whowas **, struct Whowas *);
43    
44     struct Whowas WHOWAS[NICKNAMEHISTORYLENGTH];
45     struct Whowas *WHOWASHASH[HASHSIZE];
46    
47     static unsigned int whowas_next = 0;
48    
49     void
50     add_history(struct Client *client_p, int online)
51     {
52     struct Whowas *who = &WHOWAS[whowas_next];
53    
54     assert(client_p != NULL);
55    
56     if (client_p == NULL)
57     return;
58    
59     /* XXX when is this possible? Looks like it could happen
60     * (with a half registered client.)
61     * and what is the correct action here? - Dianora
62     */
63     if (client_p->servptr == NULL)
64     return;
65    
66     if (who->hashv != -1)
67     {
68     if (who->online)
69     del_whowas_from_clist(&(who->online->whowas),who);
70     del_whowas_from_list(&WHOWASHASH[who->hashv], who);
71     }
72    
73     who->hashv = strhash(client_p->name);
74     who->logoff = CurrentTime;
75    
76     /* NOTE: strcpy ok here, the sizes in the client struct MUST
77     * match the sizes in the whowas struct
78     */
79     strlcpy(who->name, client_p->name, sizeof(who->name));
80     strcpy(who->username, client_p->username);
81     strcpy(who->hostname, client_p->host);
82     strcpy(who->realname, client_p->info);
83    
84     strlcpy(who->servername, client_p->servptr->name, sizeof(who->servername));
85    
86     if (online)
87     {
88     who->online = client_p;
89     add_whowas_to_clist(&(client_p->whowas), who);
90     }
91     else
92     who->online = NULL;
93    
94     add_whowas_to_list(&WHOWASHASH[who->hashv], who);
95     whowas_next++;
96    
97     if (whowas_next == NICKNAMEHISTORYLENGTH)
98     whowas_next = 0;
99     }
100    
101     void
102     off_history(struct Client *client_p)
103     {
104     struct Whowas *temp, *next;
105    
106     for (temp = client_p->whowas; temp; temp=next)
107     {
108     next = temp->cnext;
109     temp->online = NULL;
110     del_whowas_from_clist(&(client_p->whowas), temp);
111     }
112     }
113    
114     struct Client *
115     get_history(const char *nick, time_t timelimit)
116     {
117     struct Whowas *temp;
118    
119     timelimit = CurrentTime - timelimit;
120     temp = WHOWASHASH[strhash(nick)];
121    
122     for (; temp; temp = temp->next)
123     {
124     if (irccmp(nick, temp->name))
125     continue;
126     if (temp->logoff < timelimit)
127     continue;
128     return(temp->online);
129     }
130    
131     return(NULL);
132     }
133    
134     void
135     count_whowas_memory(int *wwu, unsigned long *wwum)
136     {
137     struct Whowas *tmp;
138     int i;
139     int u = 0;
140     unsigned long um = 0;
141    
142     /* count the number of used whowas structs in 'u' */
143     /* count up the memory used of whowas structs in um */
144     for (i = 0, tmp = &WHOWAS[0]; i < NICKNAMEHISTORYLENGTH; i++, tmp++)
145     {
146     if (tmp->hashv != -1)
147     {
148     u++;
149     um += sizeof(struct Whowas);
150     }
151     }
152    
153     *wwu = u;
154     *wwum = um;
155     }
156    
157     void
158     init_whowas(void)
159     {
160     int i;
161    
162     for (i = 0; i < NICKNAMEHISTORYLENGTH; i++)
163     {
164     memset(&WHOWAS[i], 0, sizeof(struct Whowas));
165     WHOWAS[i].hashv = -1;
166     }
167    
168     for (i = 0; i < HASHSIZE; ++i)
169     WHOWASHASH[i] = NULL;
170     }
171    
172     static void
173     add_whowas_to_clist(struct Whowas **bucket, struct Whowas *whowas)
174     {
175     whowas->cprev = NULL;
176    
177     if ((whowas->cnext = *bucket) != NULL)
178     whowas->cnext->cprev = whowas;
179     *bucket = whowas;
180     }
181    
182     static void
183     del_whowas_from_clist(struct Whowas **bucket, struct Whowas *whowas)
184     {
185     if (whowas->cprev)
186     whowas->cprev->cnext = whowas->cnext;
187     else
188     *bucket = whowas->cnext;
189     if (whowas->cnext)
190     whowas->cnext->cprev = whowas->cprev;
191     }
192    
193     static void
194     add_whowas_to_list(struct Whowas **bucket, struct Whowas *whowas)
195     {
196     whowas->prev = NULL;
197    
198     if ((whowas->next = *bucket) != NULL)
199     whowas->next->prev = whowas;
200     *bucket = whowas;
201     }
202    
203     static void
204     del_whowas_from_list(struct Whowas **bucket, struct Whowas *whowas)
205     {
206     if (whowas->prev)
207     whowas->prev->next = whowas->next;
208     else
209     *bucket = whowas->next;
210     if (whowas->next)
211     whowas->next->prev = whowas->prev;
212     }

Properties

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