]>
jfr.im git - irc/quakenet/newserv.git/blob - proxyscan/proxyscanclean.c
3 * This file deals with the "clean" hosts.
9 #include "../core/error.h"
11 #define CLEANHOSTHASHSIZE 20000
13 cleanhost
*cleantable
[CLEANHOSTHASHSIZE
];
14 time_t rescaninterval
;
16 void cleanhostinit(time_t ri
) {
18 memset(cleantable
,0,sizeof(cleantable
));
21 void addcleanhost(unsigned long IP
, time_t timestamp
) {
25 hash
=(IP%CLEANHOSTHASHSIZE
);
29 chp
->lastscan
=timestamp
;
30 chp
->next
=cleantable
[hash
];
35 void delcleanhost(cleanhost
*chp
) {
39 hash
=(chp
->IP%CLEANHOSTHASHSIZE
);
41 for (chh
=&(cleantable
[hash
]);*chh
;chh
=&((*chh
)->next
)) {
54 * 0 - Host has been checked recently and is clean
55 * 1 - Host has not been checked recently, or was not clean
58 int checkcleanhost(unsigned long IP
) {
62 hash
=(IP%CLEANHOSTHASHSIZE
);
64 for (chp
=cleantable
[hash
];chp
;chp
=chp
->next
) {
67 if(chp
->lastscan
< (time(NULL
)-rescaninterval
)) {
68 /* Needs rescan; delete and return 1 */
78 /* Not found: return 1 */
84 * Dumps all clean hosts to a savefile. Expires hosts as it goes along
87 void dumpcleanhosts(void *arg
) {
92 if ((fp
=fopen("cleanhosts","w"))==NULL
) {
93 Error("proxyscan",ERR_ERROR
,"Unable to open cleanhosts file for writing!");
97 for(i
=0;i
<CLEANHOSTHASHSIZE
;i
++) {
98 for(chp
=cleantable
[i
];chp
;chp
=nchp
) {
100 if (chp
->lastscan
< (time(NULL
)-rescaninterval
)) {
101 /* Needs rescan anyway, so delete it */
104 fprintf(fp
,"%lu %lu\n",chp
->IP
,chp
->lastscan
);
114 * Loads clean hosts in from database.
117 void loadcleanhosts() {
119 unsigned long IP
,timestamp
;
122 if ((fp
=fopen("cleanhosts","r"))==NULL
) {
123 Error("proxyscan",ERR_ERROR
,"Unable to open cleanhosts file for reading!");
133 if ((sscanf(buf
,"%lu %lu",&IP
,×tamp
))==2) {
134 addcleanhost(IP
,timestamp
);
141 * Returns the number of "clean" host entries present
144 unsigned int cleancount() {
146 unsigned int total
=0;
149 for(i
=0;i
<CLEANHOSTHASHSIZE
;i
++) {
150 for (chp
=cleantable
[i
];chp
;chp
=chp
->next
) {