23 |
|
*/ |
24 |
|
|
25 |
|
#include "stdinc.h" |
26 |
+ |
#include "list.h" |
27 |
|
#include "whowas.h" |
28 |
|
#include "client.h" |
28 |
– |
#include "common.h" |
29 |
|
#include "hash.h" |
30 |
|
#include "irc_string.h" |
31 |
|
#include "ircd.h" |
32 |
– |
#include "ircd_defs.h" |
33 |
– |
#include "numeric.h" |
34 |
– |
#include "s_serv.h" |
35 |
– |
#include "s_user.h" |
36 |
– |
#include "send.h" |
37 |
– |
#include "s_conf.h" |
38 |
– |
#include "memory.h" |
39 |
– |
|
40 |
– |
/* internally defined function */ |
41 |
– |
static void add_whowas_to_clist(struct Whowas **, struct Whowas *); |
42 |
– |
static void del_whowas_from_clist(struct Whowas **, struct Whowas *); |
43 |
– |
static void add_whowas_to_list(struct Whowas **, struct Whowas *); |
44 |
– |
static void del_whowas_from_list(struct Whowas **, struct Whowas *); |
32 |
|
|
46 |
– |
struct Whowas WHOWAS[NICKNAMEHISTORYLENGTH]; |
47 |
– |
struct Whowas *WHOWASHASH[HASHSIZE]; |
33 |
|
|
34 |
< |
static unsigned int whowas_next = 0; |
34 |
> |
static struct Whowas WHOWAS[NICKNAMEHISTORYLENGTH]; |
35 |
> |
dlink_list WHOWASHASH[HASHSIZE]; |
36 |
> |
|
37 |
|
|
38 |
|
void |
39 |
|
add_history(struct Client *client_p, int online) |
40 |
|
{ |
41 |
+ |
static unsigned int whowas_next = 0; |
42 |
|
struct Whowas *who = &WHOWAS[whowas_next]; |
43 |
|
|
44 |
< |
assert(client_p != NULL); |
57 |
< |
|
58 |
< |
if (client_p == NULL) |
59 |
< |
return; |
44 |
> |
assert(client_p && client_p->servptr); |
45 |
|
|
46 |
< |
/* XXX when is this possible? Looks like it could happen |
47 |
< |
* (with a half registered client.) |
63 |
< |
* and what is the correct action here? - Dianora |
64 |
< |
*/ |
65 |
< |
if (client_p->servptr == NULL) |
66 |
< |
return; |
46 |
> |
if (++whowas_next == NICKNAMEHISTORYLENGTH) |
47 |
> |
whowas_next = 0; |
48 |
|
|
49 |
|
if (who->hashv != -1) |
50 |
|
{ |
51 |
|
if (who->online) |
52 |
< |
del_whowas_from_clist(&(who->online->whowas),who); |
53 |
< |
del_whowas_from_list(&WHOWASHASH[who->hashv], who); |
52 |
> |
dlinkDelete(&who->cnode, &who->online->whowas); |
53 |
> |
|
54 |
> |
dlinkDelete(&who->tnode, &WHOWASHASH[who->hashv]); |
55 |
|
} |
56 |
|
|
57 |
< |
who->hashv = strhash(client_p->name); |
57 |
> |
who->hashv = strhash(client_p->name); |
58 |
|
who->logoff = CurrentTime; |
59 |
|
|
78 |
– |
/* NOTE: strcpy ok here, the sizes in the client struct MUST |
79 |
– |
* match the sizes in the whowas struct |
80 |
– |
*/ |
60 |
|
strlcpy(who->name, client_p->name, sizeof(who->name)); |
61 |
< |
strcpy(who->username, client_p->username); |
62 |
< |
strcpy(who->hostname, client_p->host); |
63 |
< |
strcpy(who->realname, client_p->info); |
85 |
< |
|
61 |
> |
strlcpy(who->username, client_p->username, sizeof(who->username)); |
62 |
> |
strlcpy(who->hostname, client_p->host, sizeof(who->hostname)); |
63 |
> |
strlcpy(who->realname, client_p->info, sizeof(who->realname)); |
64 |
|
strlcpy(who->servername, client_p->servptr->name, sizeof(who->servername)); |
65 |
|
|
66 |
|
if (online) |
67 |
|
{ |
68 |
|
who->online = client_p; |
69 |
< |
add_whowas_to_clist(&(client_p->whowas), who); |
69 |
> |
dlinkAdd(who, &who->cnode, &client_p->whowas); |
70 |
|
} |
71 |
|
else |
72 |
|
who->online = NULL; |
73 |
|
|
74 |
< |
add_whowas_to_list(&WHOWASHASH[who->hashv], who); |
97 |
< |
whowas_next++; |
98 |
< |
|
99 |
< |
if (whowas_next == NICKNAMEHISTORYLENGTH) |
100 |
< |
whowas_next = 0; |
74 |
> |
dlinkAdd(who, &who->tnode, &WHOWASHASH[who->hashv]); |
75 |
|
} |
76 |
|
|
77 |
|
void |
78 |
|
off_history(struct Client *client_p) |
79 |
|
{ |
80 |
< |
struct Whowas *temp, *next; |
80 |
> |
dlink_node *ptr = NULL, *ptr_next = NULL; |
81 |
|
|
82 |
< |
for (temp = client_p->whowas; temp; temp=next) |
82 |
> |
DLINK_FOREACH_SAFE(ptr, ptr_next, client_p->whowas.head) |
83 |
|
{ |
84 |
< |
next = temp->cnext; |
84 |
> |
struct Whowas *temp = ptr->data; |
85 |
> |
|
86 |
|
temp->online = NULL; |
87 |
< |
del_whowas_from_clist(&(client_p->whowas), temp); |
87 |
> |
dlinkDelete(&temp->cnode, &client_p->whowas); |
88 |
|
} |
89 |
|
} |
90 |
|
|
91 |
|
struct Client * |
92 |
|
get_history(const char *nick, time_t timelimit) |
93 |
|
{ |
94 |
< |
struct Whowas *temp; |
94 |
> |
dlink_node *ptr = NULL; |
95 |
|
|
96 |
|
timelimit = CurrentTime - timelimit; |
122 |
– |
temp = WHOWASHASH[strhash(nick)]; |
97 |
|
|
98 |
< |
for (; temp; temp = temp->next) |
98 |
> |
DLINK_FOREACH(ptr, WHOWASHASH[strhash(nick)].head) |
99 |
|
{ |
100 |
< |
if (irccmp(nick, temp->name)) |
101 |
< |
continue; |
100 |
> |
struct Whowas *temp = ptr->data; |
101 |
> |
|
102 |
|
if (temp->logoff < timelimit) |
103 |
|
continue; |
104 |
< |
return(temp->online); |
104 |
> |
if (irccmp(nick, temp->name)) |
105 |
> |
continue; |
106 |
> |
return temp->online; |
107 |
|
} |
108 |
|
|
109 |
< |
return(NULL); |
109 |
> |
return NULL; |
110 |
|
} |
111 |
|
|
112 |
|
void |
113 |
< |
count_whowas_memory(int *wwu, unsigned long *wwum) |
113 |
> |
count_whowas_memory(unsigned int *wwu, uint64_t *wwum) |
114 |
|
{ |
115 |
< |
struct Whowas *tmp; |
115 |
> |
const struct Whowas *tmp; |
116 |
|
int i; |
117 |
< |
int u = 0; |
118 |
< |
unsigned long um = 0; |
117 |
> |
unsigned int u = 0; |
118 |
> |
uint64_t um = 0; |
119 |
|
|
120 |
|
/* count the number of used whowas structs in 'u' */ |
121 |
|
/* count up the memory used of whowas structs in um */ |
122 |
< |
for (i = 0, tmp = &WHOWAS[0]; i < NICKNAMEHISTORYLENGTH; i++, tmp++) |
122 |
> |
for (i = 0, tmp = &WHOWAS[0]; i < NICKNAMEHISTORYLENGTH; ++i, ++tmp) |
123 |
|
{ |
124 |
|
if (tmp->hashv != -1) |
125 |
|
{ |
126 |
< |
u++; |
126 |
> |
++u; |
127 |
|
um += sizeof(struct Whowas); |
128 |
|
} |
129 |
|
} |
133 |
|
} |
134 |
|
|
135 |
|
void |
136 |
< |
init_whowas(void) |
136 |
> |
whowas_init(void) |
137 |
|
{ |
138 |
< |
int i; |
138 |
> |
unsigned int idx; |
139 |
|
|
140 |
< |
for (i = 0; i < NICKNAMEHISTORYLENGTH; i++) |
141 |
< |
{ |
166 |
< |
memset(&WHOWAS[i], 0, sizeof(struct Whowas)); |
167 |
< |
WHOWAS[i].hashv = -1; |
168 |
< |
} |
169 |
< |
|
170 |
< |
for (i = 0; i < HASHSIZE; ++i) |
171 |
< |
WHOWASHASH[i] = NULL; |
172 |
< |
} |
173 |
< |
|
174 |
< |
static void |
175 |
< |
add_whowas_to_clist(struct Whowas **bucket, struct Whowas *whowas) |
176 |
< |
{ |
177 |
< |
whowas->cprev = NULL; |
178 |
< |
|
179 |
< |
if ((whowas->cnext = *bucket) != NULL) |
180 |
< |
whowas->cnext->cprev = whowas; |
181 |
< |
*bucket = whowas; |
182 |
< |
} |
183 |
< |
|
184 |
< |
static void |
185 |
< |
del_whowas_from_clist(struct Whowas **bucket, struct Whowas *whowas) |
186 |
< |
{ |
187 |
< |
if (whowas->cprev) |
188 |
< |
whowas->cprev->cnext = whowas->cnext; |
189 |
< |
else |
190 |
< |
*bucket = whowas->cnext; |
191 |
< |
if (whowas->cnext) |
192 |
< |
whowas->cnext->cprev = whowas->cprev; |
193 |
< |
} |
194 |
< |
|
195 |
< |
static void |
196 |
< |
add_whowas_to_list(struct Whowas **bucket, struct Whowas *whowas) |
197 |
< |
{ |
198 |
< |
whowas->prev = NULL; |
199 |
< |
|
200 |
< |
if ((whowas->next = *bucket) != NULL) |
201 |
< |
whowas->next->prev = whowas; |
202 |
< |
*bucket = whowas; |
203 |
< |
} |
204 |
< |
|
205 |
< |
static void |
206 |
< |
del_whowas_from_list(struct Whowas **bucket, struct Whowas *whowas) |
207 |
< |
{ |
208 |
< |
if (whowas->prev) |
209 |
< |
whowas->prev->next = whowas->next; |
210 |
< |
else |
211 |
< |
*bucket = whowas->next; |
212 |
< |
if (whowas->next) |
213 |
< |
whowas->next->prev = whowas->prev; |
140 |
> |
for (idx = 0; idx < NICKNAMEHISTORYLENGTH; ++idx) |
141 |
> |
WHOWAS[idx].hashv = -1; |
142 |
|
} |