new ovdb release, plus a bunch of other patches

Heath Kehoe hakehoe at norand.com
Thu Jan 13 23:07:07 UTC 2000


Ok, so it wasn't as hard as I thought it would be.
This patch against ovdb.c makes it compatible with nnrpd/article.c
without the SendIOv -> SendIOb change.

-h


*** ovdb.c.dist	Thu Jan 13 17:00:21 2000
--- ovdb.c	Thu Jan 13 17:06:25 2000
***************
*** 2,7 ****
--- 2,8 ----
   * ovdb.c
   * Overview storage using BerkeleyDB 2.x/3.x
   *
+  * 2000-01-13 : Fix to make compatible with unmodified nnrpd/article.c
   * 2000-01-04 : Added data versioning
   * 1999-12-20 : Added BerkeleyDB 3.x compatibility
   * 1999-12-06 : First Release -- H. Kehoe <hakehoe at avalon.net>
***************
*** 12,17 ****
--- 13,21 ----
  #ifdef HAVE_UNISTD_H
  #include <unistd.h>
  #endif
+ #ifdef HAVE_LIMITS_H
+ # include <limits.h>
+ #endif
  #include <fcntl.h>
  #include <stdlib.h>
  #include <string.h>
***************
*** 139,144 ****
--- 143,150 ----
      time_t expires;
  };
  
+ #define SEARCHQUEUELEN  (IOV_MAX+5)
+ 
  struct ovdbsearch {
      DB *db;
      DBC *cursor;
***************
*** 145,150 ****
--- 151,159 ----
      struct datakey lokey;
      struct datakey hikey;
      int state;
+     void *queue[SEARCHQUEUELEN];
+     int queuelen;
+     int queuehead;
  };
  
  
***************
*** 1151,1156 ****
--- 1160,1167 ----
      s->hikey.groupnum = gno;
      s->hikey.artnum = htonl(high);
      s->state = 0;
+     s->queuelen = 0;
+     s->queuehead = 0;
  
      return (void *)s;
  }
***************
*** 1166,1171 ****
--- 1177,1183 ----
  
      memset(&key, 0, sizeof key);
      memset(&val, 0, sizeof val);
+     val.flags = DB_DBT_MALLOC;
  
      switch(s->state) {
      case 0:
***************
*** 1184,1190 ****
  
      if(!data && !len) {
  	/* caller doesn't need data, so we don't have to retrieve it all */
! 	val.flags = DB_DBT_PARTIAL;
  
  	if(token || arrived)
  	    val.dlen = sizeof(struct ovdata);
--- 1196,1202 ----
  
      if(!data && !len) {
  	/* caller doesn't need data, so we don't have to retrieve it all */
! 	val.flags |= DB_DBT_PARTIAL;
  
  	if(token || arrived)
  	    val.dlen = sizeof(struct ovdata);
***************
*** 1204,1214 ****
--- 1216,1228 ----
  
      if(key.size != sizeof(struct datakey)) {
  	s->state = 2;
+ 	free(val.data);
  	return FALSE;
      }
  
      if(memcmp(key.data, &(s->hikey), sizeof(struct datakey)) > 0) {
  	s->state = 2;
+ 	free(val.data);
  	return FALSE;
      }
  
***************
*** 1216,1221 ****
--- 1230,1236 ----
  	|| ((token || arrived) && val.size < sizeof(struct ovdata)) ) {
  	syslog(L_ERROR, "OVDB: search: bad value length");
  	s->state = 2;
+ 	free(val.data);
  	return FALSE;
      }
  
***************
*** 1223,1232 ****
  	memcpy(&dk, key.data, sizeof(struct datakey));
  	*artnum = ntohl(dk.artnum);
      }
-     if(len)
- 	*len = val.size - sizeof(struct ovdata);
-     if(data)
- 	*data = (char *)val.data + sizeof(struct ovdata);
  
      memcpy(&ovd, val.data, sizeof(struct ovdata));
      if(token)
--- 1238,1243 ----
***************
*** 1234,1247 ****
--- 1245,1276 ----
      if(arrived)
  	*arrived = ovd.arrived;
  
+     if(len)
+ 	*len = val.size - sizeof(struct ovdata);
+     if(data) {
+ 	*data = (char *)val.data + sizeof(struct ovdata);
+ 	if(s->queuelen < SEARCHQUEUELEN) {
+ 	    s->queuelen++;
+ 	} else {
+ 	    free(s->queue[s->queuehead]);
+ 	}
+ 	s->queue[s->queuehead] = val.data;
+ 	s->queuehead = (1 + s->queuehead) % SEARCHQUEUELEN;
+     } else {
+ 	free(val.data);
+     }
      return TRUE;
  }
  
  void ovdb_closesearch(void *handle)
  {
+     int i;
      struct ovdbsearch *s = (struct ovdbsearch *)handle;
  
      s->cursor->c_close(s->cursor);
+    
+     for(i = 0; i < s->queuelen; i++)
+ 	free(s->queue[i]);
  
      DISPOSE(s);
  }




More information about the inn-workers mailing list