]>
jfr.im git - solanum.git/blob - ircd/whowas.c
2 * ircd-ratbox: A slightly useful ircd.
3 * whowas.c: WHOWAS user cache.
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 * $Id: whowas.c 1717 2006-07-04 14:41:11Z jilles $
35 #include "ircd_defs.h"
44 /* internally defined function */
45 static void add_whowas_to_clist(struct Whowas
**, struct Whowas
*);
46 static void del_whowas_from_clist(struct Whowas
**, struct Whowas
*);
47 static void add_whowas_to_list(struct Whowas
**, struct Whowas
*);
48 static void del_whowas_from_list(struct Whowas
**, struct Whowas
*);
50 struct Whowas WHOWAS
[NICKNAMEHISTORYLENGTH
];
51 struct Whowas
*WHOWASHASH
[WW_MAX
];
53 static int whowas_next
= 0;
55 unsigned int hash_whowas_name(const char *name
)
57 return fnv_hash_upper((const unsigned char *) name
, WW_MAX_BITS
);
60 void add_history(struct Client
*client_p
, int online
)
62 struct Whowas
*who
= &WHOWAS
[whowas_next
];
64 s_assert(NULL
!= client_p
);
72 del_whowas_from_clist(&(who
->online
->whowas
), who
);
73 del_whowas_from_list(&WHOWASHASH
[who
->hashv
], who
);
75 who
->hashv
= hash_whowas_name(client_p
->name
);
76 who
->logoff
= rb_current_time();
78 * NOTE: strcpy ok here, the sizes in the client struct MUST
79 * match the sizes in the whowas struct
81 rb_strlcpy(who
->name
, client_p
->name
, sizeof(who
->name
));
82 strcpy(who
->username
, client_p
->username
);
83 strcpy(who
->hostname
, client_p
->host
);
84 strcpy(who
->realname
, client_p
->info
);
85 strcpy(who
->suser
, client_p
->user
->suser
);
86 strcpy(who
->sockhost
, client_p
->sockhost
);
87 who
->flags
= (IsIPSpoof(client_p
) ? WHOWAS_IP_SPOOFING
: 0) |
88 (IsDynSpoof(client_p
) ? WHOWAS_DYNSPOOF
: 0);
90 who
->servername
= scache_get_name(client_p
->servptr
->serv
->nameinfo
);
94 who
->online
= client_p
;
95 add_whowas_to_clist(&(client_p
->whowas
), who
);
99 add_whowas_to_list(&WHOWASHASH
[who
->hashv
], who
);
101 if(whowas_next
== NICKNAMEHISTORYLENGTH
)
105 void off_history(struct Client
*client_p
)
107 struct Whowas
*temp
, *next
;
109 for (temp
= client_p
->whowas
; temp
; temp
= next
)
113 del_whowas_from_clist(&(client_p
->whowas
), temp
);
117 struct Client
*get_history(const char *nick
, time_t timelimit
)
122 timelimit
= rb_current_time() - timelimit
;
123 blah
= hash_whowas_name(nick
);
124 temp
= WHOWASHASH
[blah
];
125 for (; temp
; temp
= temp
->next
)
127 if(irccmp(nick
, temp
->name
))
129 if(temp
->logoff
< timelimit
)
136 void count_whowas_memory(size_t * wwu
, size_t * wwum
)
138 *wwu
= NICKNAMEHISTORYLENGTH
;
139 *wwum
= NICKNAMEHISTORYLENGTH
* sizeof(struct Whowas
);
147 for (i
= 0; i
< NICKNAMEHISTORYLENGTH
; i
++)
149 memset((void *) &WHOWAS
[i
], 0, sizeof(struct Whowas
));
150 WHOWAS
[i
].hashv
= -1;
152 for (i
= 0; i
< WW_MAX
; i
++)
153 WHOWASHASH
[i
] = NULL
;
158 add_whowas_to_clist(struct Whowas
**bucket
, struct Whowas
*whowas
)
160 whowas
->cprev
= NULL
;
161 if((whowas
->cnext
= *bucket
) != NULL
)
162 whowas
->cnext
->cprev
= whowas
;
167 del_whowas_from_clist(struct Whowas
**bucket
, struct Whowas
*whowas
)
170 whowas
->cprev
->cnext
= whowas
->cnext
;
172 *bucket
= whowas
->cnext
;
174 whowas
->cnext
->cprev
= whowas
->cprev
;
178 add_whowas_to_list(struct Whowas
**bucket
, struct Whowas
*whowas
)
181 if((whowas
->next
= *bucket
) != NULL
)
182 whowas
->next
->prev
= whowas
;
187 del_whowas_from_list(struct Whowas
**bucket
, struct Whowas
*whowas
)
190 whowas
->prev
->next
= whowas
->next
;
192 *bucket
= whowas
->next
;
194 whowas
->next
->prev
= whowas
->prev
;