]> jfr.im git - irc/quakenet/newserv.git/blobdiff - proxyscan/proxyscancache.c
merge
[irc/quakenet/newserv.git] / proxyscan / proxyscancache.c
index 81dd5f2f5e61ab415a840fabd8da099bc9f68f91..f14fbd2b5090e4d97145c5491a8dedf7ae50b46f 100644 (file)
@@ -24,6 +24,7 @@ cachehost *addcleanhost(time_t timestamp) {
   chp->lastscan=timestamp;
   chp->proxies=NULL;
   chp->glineid=0;
+  chp->lastgline=0;  
   
   return chp;
 }
@@ -75,39 +76,38 @@ void dumpcachehosts(void *arg) {
   foundproxy *fpp;
   patricia_node_t *node;
 
-  if ((fp=fopen("cleanhosts","w"))==NULL) {
+  if ((fp=fopen("data/cleanhosts","w"))==NULL) {
     Error("proxyscan",ERR_ERROR,"Unable to open cleanhosts file for writing!");
     return;
   }
 
-  PATRICIA_WALK (iptree->head, node) {
+  PATRICIA_WALK_CLEAR (iptree->head, node) {
     if (node->exts[ps_cache_ext] ) {
       chp = (cachehost *) node->exts[ps_cache_ext];
       if (chp) { 
         if (chp->proxies) {
           if (chp->lastscan < (now-dirtyscaninterval)) {
-            //derefnode(iptree,node); 
-           //delcachehost(chp);
-           //node->exts[ps_cache_ext] = NULL;
-            //continue;
+            derefnode(iptree,node); 
+           delcachehost(chp);
+           node->exts[ps_cache_ext] = NULL;
           } else
         
           for (fpp=chp->proxies;fpp;fpp=fpp->next) 
-            fprintf(fp, "%s %lu %u %i %u\n",IPtostr(node->prefix->sin),chp->lastscan,chp->glineid,fpp->type,fpp->port);
+            fprintf(fp, "%s %lu %u %i %u %lu\n",IPtostr(node->prefix->sin),chp->lastscan,chp->glineid,fpp->type,fpp->port,chp->lastgline);
         } else {
           if (chp->lastscan < (now-cleanscaninterval)) {
             /* Needs rescan anyway, so delete it */
-           //derefnode(iptree,node); 
-           //delcachehost(chp);
-            //node->exts[ps_cache_ext] = NULL;          
-            //continue;
+           derefnode(iptree,node); 
+           delcachehost(chp);
+            node->exts[ps_cache_ext] = NULL;          
           } else
           fprintf(fp,"%s %lu\n",IPtostr(node->prefix->sin),chp->lastscan);
         }
       }
     }
-  } PATRICIA_WALK_END;
-  
+  } PATRICIA_WALK_CLEAR_END;
+
+//  patricia_tidy_tree(iptree); 
 
   fclose(fp);
 }
@@ -119,7 +119,7 @@ void dumpcachehosts(void *arg) {
 
 void loadcachehosts() {
   FILE *fp;
-  unsigned long timestamp,glineid,ptype,pport;
+  unsigned long timestamp,glineid,ptype,pport,lastgline;
   char buf[512];
   cachehost *chp=NULL;
   foundproxy *fpp;
@@ -128,8 +128,9 @@ void loadcachehosts() {
   struct irc_in_addr sin;
   unsigned char bits;
   patricia_node_t *node;
+  int i=0;
 
-  if ((fp=fopen("cleanhosts","r"))==NULL) {
+  if ((fp=fopen("data/cleanhosts","r"))==NULL) {
     Error("proxyscan",ERR_ERROR,"Unable to open cleanhosts file for reading!");
     return;
   }
@@ -141,7 +142,7 @@ void loadcachehosts() {
       break;
     }
 
-    res=sscanf(buf,"%s %lu %lu %lu %lu",ip,&timestamp,&glineid,&ptype,&pport);
+    res=sscanf(buf,"%s %lu %lu %lu %lu %lu",ip,&timestamp,&glineid,&ptype,&pport,&lastgline);
 
     if (res<2)
       continue;
@@ -151,11 +152,13 @@ void loadcachehosts() {
     } else {
       node = refnode(iptree, &sin, bits);
       if( node ) {
+        i++;
         chp=addcleanhost(timestamp);
         node->exts[ps_cache_ext] = chp;
       
-        if (res==5) {
+        if (res==6) {
           chp->glineid=glineid;
+          chp->lastgline=lastgline;
           fpp=getfoundproxy();
           fpp->type=ptype;
           fpp->port=pport;
@@ -165,7 +168,8 @@ void loadcachehosts() {
       }
     }
   }
-  
+  Error("proxyscan",ERR_INFO, "Loaded %d entries from cache", i); 
 }
 
 /*