]> jfr.im git - irc/quakenet/newserv.git/blame - proxyscan/proxyscanqueue.c
Added 'showkill' and 'spew' commands (with associated functions) - also cleaned up...
[irc/quakenet/newserv.git] / proxyscan / proxyscanqueue.c
CommitLineData
905c2ba2 1
2/*
3 * Handle the scan queues
4 */
5
6#include "proxyscan.h"
7
8pendingscan *ps_normalqueue=NULL;
9pendingscan *ps_prioqueue=NULL;
10pendingscan *ps_normalqueueend=NULL;
11
12unsigned int normalqueuedscans=0;
13unsigned int prioqueuedscans=0;
14
15void queuescan(unsigned int IP, short scantype, unsigned short port, char class, time_t when) {
16 pendingscan *psp, *psp2;
17
18 /* If there are scans spare, just start it immediately..
19 * provided we're not supposed to wait */
20 if (activescans < maxscans && when<=time(NULL)) {
21 startscan(IP, scantype, port, class);
22 return;
23 }
24
25 /* We have to queue it */
26 psp=getpendingscan();
27 psp->IP=IP;
28 psp->type=scantype;
29 psp->port=port;
30 psp->class=class;
31 psp->when=when;
32 psp->next=NULL;
33
34 if (!when) {
35 /* normal queue */
36 normalqueuedscans++;
37 if (ps_normalqueueend) {
38 ps_normalqueueend->next=psp;
39 ps_normalqueueend=psp;
40 } else {
41 ps_normalqueueend=ps_normalqueue=psp;
42 }
43 } else {
44 prioqueuedscans++;
45 if (!ps_prioqueue || ps_prioqueue->when > when) {
46 psp->next=ps_prioqueue;
47 ps_prioqueue=psp;
48 } else {
49 for (psp2=ps_prioqueue; ;psp2=psp2->next) {
50 if (!psp2->next || psp2->next->when > when) {
51 psp->next = psp2->next;
52 psp2->next = psp;
53 break;
54 }
55 }
56 }
57 }
58}
59
60void startqueuedscans() {
61 pendingscan *psp=NULL;
62
63 while (activescans < maxscans) {
64 if (ps_prioqueue && ps_prioqueue->when <= time(NULL)) {
65 psp=ps_prioqueue;
66 ps_prioqueue=psp->next;
67 prioqueuedscans--;
68 } else if (ps_normalqueue) {
69 psp=ps_normalqueue;
70 ps_normalqueue=psp->next;
71 if (!ps_normalqueue)
72 ps_normalqueueend=NULL;
73 normalqueuedscans--;
74 }
75
76 if (psp) {
77 startscan(psp->IP, psp->type, psp->port, psp->class);
78 freependingscan(psp);
79 psp=NULL;
80 } else {
81 break;
82 }
83 }
84}
85
86