]>
Commit | Line | Data |
---|---|---|
905c2ba2 | 1 | |
2 | /* | |
3 | * Handle the scan queues | |
4 | */ | |
5 | ||
6 | #include "proxyscan.h" | |
92f1d9e3 | 7 | #include "../irc/irc.h" |
905c2ba2 | 8 | |
9 | pendingscan *ps_normalqueue=NULL; | |
10 | pendingscan *ps_prioqueue=NULL; | |
11 | pendingscan *ps_normalqueueend=NULL; | |
12 | ||
13 | unsigned int normalqueuedscans=0; | |
14 | unsigned int prioqueuedscans=0; | |
15 | ||
92f1d9e3 D |
16 | unsigned long countpendingscan=0; |
17 | ||
905c2ba2 | 18 | void queuescan(unsigned int IP, short scantype, unsigned short port, char class, time_t when) { |
19 | pendingscan *psp, *psp2; | |
20 | ||
21 | /* If there are scans spare, just start it immediately.. | |
22 | * provided we're not supposed to wait */ | |
23 | if (activescans < maxscans && when<=time(NULL)) { | |
24 | startscan(IP, scantype, port, class); | |
25 | return; | |
26 | } | |
27 | ||
28 | /* We have to queue it */ | |
92f1d9e3 D |
29 | psp = (struct pendingscan *) malloc(sizeof(pendingscan)); |
30 | if (!psp) | |
31 | { | |
32 | /* shutdown due to no memory */ | |
33 | irc_send("%s SQ %s 0 :Out of memory - exiting.",mynumeric->content,myserver->content); | |
34 | irc_disconnected(); | |
35 | exit(0); | |
36 | } else { | |
37 | countpendingscan++; | |
38 | } | |
905c2ba2 | 39 | psp->IP=IP; |
40 | psp->type=scantype; | |
41 | psp->port=port; | |
42 | psp->class=class; | |
43 | psp->when=when; | |
44 | psp->next=NULL; | |
45 | ||
46 | if (!when) { | |
47 | /* normal queue */ | |
48 | normalqueuedscans++; | |
49 | if (ps_normalqueueend) { | |
50 | ps_normalqueueend->next=psp; | |
51 | ps_normalqueueend=psp; | |
52 | } else { | |
53 | ps_normalqueueend=ps_normalqueue=psp; | |
54 | } | |
55 | } else { | |
56 | prioqueuedscans++; | |
57 | if (!ps_prioqueue || ps_prioqueue->when > when) { | |
58 | psp->next=ps_prioqueue; | |
59 | ps_prioqueue=psp; | |
60 | } else { | |
61 | for (psp2=ps_prioqueue; ;psp2=psp2->next) { | |
62 | if (!psp2->next || psp2->next->when > when) { | |
63 | psp->next = psp2->next; | |
64 | psp2->next = psp; | |
65 | break; | |
66 | } | |
67 | } | |
68 | } | |
69 | } | |
70 | } | |
71 | ||
72 | void startqueuedscans() { | |
73 | pendingscan *psp=NULL; | |
74 | ||
75 | while (activescans < maxscans) { | |
76 | if (ps_prioqueue && ps_prioqueue->when <= time(NULL)) { | |
77 | psp=ps_prioqueue; | |
78 | ps_prioqueue=psp->next; | |
79 | prioqueuedscans--; | |
80 | } else if (ps_normalqueue) { | |
81 | psp=ps_normalqueue; | |
82 | ps_normalqueue=psp->next; | |
83 | if (!ps_normalqueue) | |
84 | ps_normalqueueend=NULL; | |
85 | normalqueuedscans--; | |
86 | } | |
87 | ||
88 | if (psp) { | |
89 | startscan(psp->IP, psp->type, psp->port, psp->class); | |
92f1d9e3 D |
90 | free(psp); |
91 | countpendingscan--; | |
905c2ba2 | 92 | psp=NULL; |
93 | } else { | |
94 | break; | |
95 | } | |
96 | } | |
97 | } | |
98 | ||
99 |