]>
Commit | Line | Data |
---|---|---|
905c2ba2 | 1 | |
2 | /* | |
3 | * Handle the scan queues | |
4 | */ | |
5 | ||
6 | #include "proxyscan.h" | |
92f1d9e3 | 7 | #include "../irc/irc.h" |
b8dc4a0e | 8 | #include "../core/error.h" |
905c2ba2 | 9 | |
10 | pendingscan *ps_normalqueue=NULL; | |
11 | pendingscan *ps_prioqueue=NULL; | |
12 | pendingscan *ps_normalqueueend=NULL; | |
13 | ||
14 | unsigned int normalqueuedscans=0; | |
15 | unsigned int prioqueuedscans=0; | |
16 | ||
92f1d9e3 D |
17 | unsigned long countpendingscan=0; |
18 | ||
557c8cb2 | 19 | void queuescan(patricia_node_t *node, short scantype, unsigned short port, char class, time_t when) { |
905c2ba2 | 20 | pendingscan *psp, *psp2; |
761a4596 P |
21 | |
22 | /* check if the IP/port combo is already queued - don't queue up | |
23 | * multiple identical scans | |
24 | */ | |
25 | psp = ps_prioqueue; | |
26 | while (psp != NULL) | |
27 | { | |
557c8cb2 | 28 | if (psp->node == node && psp->type == scantype && |
761a4596 P |
29 | psp->port == port && psp->class == class) |
30 | { | |
31 | /* found it, ignore */ | |
32 | return; | |
33 | } | |
34 | psp = psp->next; | |
35 | } | |
36 | ||
37 | psp = ps_normalqueue; | |
38 | while (psp != NULL) | |
39 | { | |
557c8cb2 | 40 | if (psp->node == node && psp->type == scantype && |
761a4596 P |
41 | psp->port == port && psp->class == class) |
42 | { | |
43 | /* found it, ignore */ | |
44 | return; | |
45 | } | |
46 | psp = psp->next; | |
47 | } | |
905c2ba2 | 48 | |
49 | /* If there are scans spare, just start it immediately.. | |
50 | * provided we're not supposed to wait */ | |
761a4596 | 51 | if (activescans < maxscans && when<=time(NULL) && (ps_start_ts+120 <= time(NULL))) { |
557c8cb2 | 52 | startscan(node, scantype, port, class); |
905c2ba2 | 53 | return; |
54 | } | |
55 | ||
56 | /* We have to queue it */ | |
b8dc4a0e | 57 | if (!(psp=(struct pendingscan *)malloc(sizeof(pendingscan)))) |
58 | Error("proxyscan",ERR_STOP,"Unable to allocate memory"); | |
59 | ||
60 | countpendingscan++; | |
61 | ||
557c8cb2 | 62 | psp->node=node; |
905c2ba2 | 63 | psp->type=scantype; |
64 | psp->port=port; | |
65 | psp->class=class; | |
66 | psp->when=when; | |
67 | psp->next=NULL; | |
68 | ||
69 | if (!when) { | |
70 | /* normal queue */ | |
71 | normalqueuedscans++; | |
72 | if (ps_normalqueueend) { | |
73 | ps_normalqueueend->next=psp; | |
74 | ps_normalqueueend=psp; | |
75 | } else { | |
76 | ps_normalqueueend=ps_normalqueue=psp; | |
77 | } | |
78 | } else { | |
79 | prioqueuedscans++; | |
80 | if (!ps_prioqueue || ps_prioqueue->when > when) { | |
81 | psp->next=ps_prioqueue; | |
82 | ps_prioqueue=psp; | |
83 | } else { | |
84 | for (psp2=ps_prioqueue; ;psp2=psp2->next) { | |
85 | if (!psp2->next || psp2->next->when > when) { | |
86 | psp->next = psp2->next; | |
87 | psp2->next = psp; | |
88 | break; | |
89 | } | |
90 | } | |
91 | } | |
92 | } | |
93 | } | |
94 | ||
95 | void startqueuedscans() { | |
96 | pendingscan *psp=NULL; | |
97 | ||
761a4596 P |
98 | if (ps_start_ts+120 > time(NULL)) |
99 | return; | |
100 | ||
905c2ba2 | 101 | while (activescans < maxscans) { |
761a4596 | 102 | if (ps_prioqueue && (ps_prioqueue->when <= time(NULL))) { |
905c2ba2 | 103 | psp=ps_prioqueue; |
104 | ps_prioqueue=psp->next; | |
105 | prioqueuedscans--; | |
106 | } else if (ps_normalqueue) { | |
107 | psp=ps_normalqueue; | |
108 | ps_normalqueue=psp->next; | |
109 | if (!ps_normalqueue) | |
110 | ps_normalqueueend=NULL; | |
111 | normalqueuedscans--; | |
112 | } | |
113 | ||
114 | if (psp) { | |
557c8cb2 | 115 | startscan(psp->node, psp->type, psp->port, psp->class); |
92f1d9e3 D |
116 | free(psp); |
117 | countpendingscan--; | |
905c2ba2 | 118 | psp=NULL; |
119 | } else { | |
120 | break; | |
121 | } | |
122 | } | |
123 | } | |
124 | ||
125 |