]> jfr.im git - irc/quakenet/newserv.git/blobdiff - proxyscan/proxyscancache.c
Update documentation.
[irc/quakenet/newserv.git] / proxyscan / proxyscancache.c
index 80a7e792af5f65f81364351ae516d6f164695534..df2a432ec5ef6569dda3b1ba40d3e8e4a50bb00a 100644 (file)
@@ -19,18 +19,17 @@ void cachehostinit(time_t ri) {
 
 cachehost *addcleanhost(time_t timestamp) {
   cachehost *chp;
-  int hash;
 
   chp=getcachehost();
   chp->lastscan=timestamp;
   chp->proxies=NULL;
   chp->glineid=0;
+  chp->lastgline=0;  
   
   return chp;
 }
 
 void delcachehost(cachehost *chp) {
-  cachehost **chh;
   foundproxy *fpp, *nfpp;
 
   for (fpp=chp->proxies;fpp;fpp=nfpp) {
@@ -45,16 +44,15 @@ void delcachehost(cachehost *chp) {
  */
 
 cachehost *findcachehost(patricia_node_t *node) {
-  int hash;
   cachehost *chp;
 
-  if( (cachehost *)node->slots[ps_cache_ext] ) {
-    chp = (cachehost *)node->slots[ps_cache_ext];
+  if( (cachehost *)node->exts[ps_cache_ext] ) {
+    chp = (cachehost *)node->exts[ps_cache_ext];
     if(chp->lastscan < (time(NULL)-(chp->proxies ? dirtyscaninterval : cleanscaninterval))) {
       /* Needs rescan; delete and return 1 */
       delcachehost(chp);
-      patricia_deref_prefix(node->prefix);
-      node->slots[ps_cache_ext] = NULL;
+      derefnode(iptree,node);
+      node->exts[ps_cache_ext] = NULL;
       return NULL;
     } else {
       /* valid: return it */
@@ -72,42 +70,44 @@ cachehost *findcachehost(patricia_node_t *node) {
  */
 
 void dumpcachehosts(void *arg) {
-  int i;
   FILE *fp;
   cachehost *chp;
   time_t now=time(NULL);
   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) {
-    if ( node->slots[ps_cache_ext] ) {
-      chp = (cachehost *) node->slots[ps_cache_ext];
-      if (chp->proxies) {
-        if (chp->lastscan < (now-dirtyscaninterval)) {
-          patricia_deref_prefix(node->prefix);
-         delcachehost(chp);
-          continue;
-        }
+  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;
+          } 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);
-      } else {
-        if (chp->lastscan < (now-cleanscaninterval)) {
-          /* Needs rescan anyway, so delete it */
-         patricia_deref_prefix(node->prefix);
-         delcachehost(chp);
-         continue;
+          for (fpp=chp->proxies;fpp;fpp=fpp->next) 
+            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;          
+          } else
+          fprintf(fp,"%s %lu\n",IPtostr(node->prefix->sin),chp->lastscan);
         }
-        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 IP,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->slots[ps_cache_ext] = chp;
+        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); 
 }
 
 /*
@@ -174,14 +178,13 @@ void loadcachehosts() {
  */
 
 unsigned int cleancount() {
-  int i;
   unsigned int total=0;
   cachehost *chp;
-  patricia_node_t *node;
-
-  PATRICIA_WALK (iptree->head, node) {
-    if ( node->slots[ps_cache_ext] ) {
-      chp = (cachehost *) node->slots[ps_cache_ext];
+  patricia_node_t *head, *node;
+  head = iptree->head;
+  PATRICIA_WALK (head, node) {
+    if ( node->exts[ps_cache_ext] ) {
+      chp = (cachehost *) node->exts[ps_cache_ext];
 
       if (!chp->proxies)
         total++;
@@ -192,14 +195,13 @@ unsigned int cleancount() {
 }
 
 unsigned int dirtycount() {
-  int i;
   unsigned int total=0;
   cachehost *chp;
   patricia_node_t *node;
 
   PATRICIA_WALK (iptree->head, node) {
-    if ( node->slots[ps_cache_ext] ) {
-      chp = (cachehost *) node->slots[ps_cache_ext];
+    if ( node->exts[ps_cache_ext] ) {
+      chp = (cachehost *) node->exts[ps_cache_ext];
       if (chp->proxies)
         total++;
     }
@@ -215,7 +217,7 @@ unsigned int dirtycount() {
 
 void scanall(int type, int port) {
   int i;
-  cachehost *chp, *nchp;
+  cachehost *chp;
   nick *np;
   unsigned int hostmarker;
   patricia_node_t *node;
@@ -223,8 +225,8 @@ void scanall(int type, int port) {
   hostmarker=nexthostmarker();
 
   PATRICIA_WALK (iptree->head, node) {
-    if ( node->slots[ps_cache_ext] ) {
-      chp = (cachehost *) node->slots[ps_cache_ext];
+    if ( node->exts[ps_cache_ext] ) {
+      chp = (cachehost *) node->exts[ps_cache_ext];
       chp->marker=0;
     }
   } PATRICIA_WALK_END; 
@@ -236,9 +238,6 @@ void scanall(int type, int port) {
 
       np->host->marker=hostmarker;
 
-      if (!irc_in_addr_is_ipv4(&np->p_ipaddr))
-        continue;
-
       if ((chp=findcachehost(np->ipnode)))
        chp->marker=1;