]> jfr.im git - irc/quakenet/newserv.git/blobdiff - proxyscan/proxyscanqueue.c
CHANSERV: remove E type escapes
[irc/quakenet/newserv.git] / proxyscan / proxyscanqueue.c
index f4ba2423b5a31841259ff601f816da31f99dc5f7..fae99c5e1cdf7dfd9d3450a66e0a6e64e334424e 100644 (file)
@@ -4,6 +4,9 @@
  */
 
 #include "proxyscan.h"
+#include "../irc/irc.h"
+#include "../core/error.h"
+#include <assert.h>
 
 pendingscan *ps_normalqueue=NULL;
 pendingscan *ps_prioqueue=NULL;
@@ -12,19 +15,37 @@ pendingscan *ps_normalqueueend=NULL;
 unsigned int normalqueuedscans=0;
 unsigned int prioqueuedscans=0;
 
-void queuescan(unsigned int IP, short scantype, unsigned short port, char class, time_t when) {
+unsigned long countpendingscan=0;
+
+void queuescan(patricia_node_t *node, short scantype, unsigned short port, char class, time_t when) {
   pendingscan *psp, *psp2;
+
+  /* we can just blindly queue the scans as node extension cleanhost cache blocks duplicate scans normally.
+   * Scans may come from:
+   * a) scan <node> (from an oper)
+   * b) newnick handler - which ignores clean hosts, only scans new hosts or dirty hosts
+   * c) adding a new scan type (rare) 
+   */
+
+  /* we should never have an internal node */
+  assert(node->prefix);
+  /* reference the node - we either start a or queue a single scan */
+  patricia_ref_prefix(node->prefix);
   
   /* If there are scans spare, just start it immediately.. 
    * provided we're not supposed to wait */
-  if (activescans < maxscans && when<=time(NULL)) {
-    startscan(IP, scantype, port, class);
+  if (activescans < maxscans && when<=time(NULL) && ps_ready) {
+    startscan(node, scantype, port, class);
     return;
   }
 
   /* We have to queue it */
-  psp=getpendingscan();
-  psp->IP=IP;
+  if (!(psp=getpendingscan()))
+    Error("proxyscan",ERR_STOP,"Unable to allocate memory");
+
+  countpendingscan++;
+
+  psp->node=node;
   psp->type=scantype;
   psp->port=port;
   psp->class=class;
@@ -61,7 +82,7 @@ void startqueuedscans() {
   pendingscan *psp=NULL;
 
   while (activescans < maxscans) {
-    if (ps_prioqueue && ps_prioqueue->when <= time(NULL)) {
+    if (ps_prioqueue && (ps_prioqueue->when <= time(NULL))) {
       psp=ps_prioqueue;
       ps_prioqueue=psp->next;
       prioqueuedscans--;
@@ -74,8 +95,9 @@ void startqueuedscans() {
     }
     
     if (psp) {
-      startscan(psp->IP, psp->type, psp->port, psp->class);
+      startscan(psp->node, psp->type, psp->port, psp->class);
       freependingscan(psp);
+      countpendingscan--;
       psp=NULL;
     } else {
       break;