INN commit: trunk/expire (makehistory.c)

INN Commit Russ_Allbery at isc.org
Sun Jul 22 17:13:05 UTC 2007


    Date: Sunday, July 22, 2007 @ 10:13:04
  Author: eagle
Revision: 7610

Revert a change that wasn't fully tested yet.

Modified:
  trunk/expire/makehistory.c

---------------+
 makehistory.c |  229 +++++++++++++++++++++-----------------------------------
 1 file changed, 86 insertions(+), 143 deletions(-)

Modified: makehistory.c
===================================================================
--- makehistory.c	2007-07-22 16:35:51 UTC (rev 7609)
+++ makehistory.c	2007-07-22 17:13:04 UTC (rev 7610)
@@ -16,10 +16,10 @@
 #include "inn/history.h"
 #include "inn/innconf.h"
 #include "inn/messages.h"
-#include "inn/overview.h"
 #include "inn/qio.h"
 #include "inn/wire.h"
 #include "inn/libinn.h"
+#include "inn/ov.h"
 #include "inn/paths.h"
 #include "inn/storage.h"
 
@@ -67,7 +67,7 @@
 FILE *OverTmpFile;
 char *OverTmpPath = NULL;
 bool NoHistory;
-bool SortOverview = false;
+OVSORTTYPE sorttype;
 int RetrMode;
 bool WriteStdout = false;
 
@@ -87,7 +87,7 @@
 					(e.g. message-id */
 static size_t		Missfieldsize = 0;
 
-static void OverAddAllNewsgroups(struct overview *overview);
+static void OverAddAllNewsgroups(void);
 
 /*
 **  Check and parse a Message-ID header line.  Return private space.
@@ -116,45 +116,24 @@
  * The sorting/batching helps improve efficiency.
  */
 
-
 /*
-**  Given a pointer to an overview data struct, find the start of the Xref
-**  information in its overview entry and return a pointer to it or NULL if it
-**  couldn't be found.
-*/
-static const char *
-find_xref(struct overview_data *data)
-{
-    const char *p;
-    const char *xref = NULL;
+ * Flush the unwritten OverTempFile data to disk, sort the file, read it 
+ * back in, and add it to overview. 
+ */
 
-    for (p = data->overview + data->overlen - 1; p > data->overview + 5; p--)
-        if (*p == ':' && strncasecmp(p - 5, "\tXref", 5) == 0) {
-            xref = p + 2;
-            break;
-        }
-    return xref;
-}
-
-
-/*
-**  Flush the unwritten OverTempFile data to disk, sort the file, read it back
-**  in, and add it to overview.
-*/
 static void
-FlushOverTmpFile(struct overview *overview)
+FlushOverTmpFile(void)
 {
     char temp[SMBUF];
     char *SortedTmpPath;
     int i, pid, fd;
+    TOKEN token;
     QIOSTATE *qp;
     int count;
     char *line, *p;
     char *q = NULL;
     char *r = NULL;
-    const char *xref;
-    struct overview_data data;
-    struct overview_config config;
+    time_t arrived, expires;
     static int first = 1;
 
     if (OverTmpFile == NULL)
@@ -183,19 +162,20 @@
 
 	/* child */
 	/* init the overview setup. */
-        overview = overview_open(OV_WRITE);
-        if (overview == NULL) {
+	if (!OVopen(OV_WRITE)) {
             warn("cannot open overview");
 	    _exit(1);
 	}
-        overview_config_get(overview, &config);
-        SortOverview = config.sorted;
-        config.cutoff = Cutofflow;
-        if (!overview_config_set(overview, &config)) {
-            warn("cannot set overview cutoff configuration");
-            overview_close(overview);
-            _exit(1);
-        }
+	if (!OVctl(OVSORT, (void *)&sorttype)) {
+            warn("cannot obtain overview sorting information");
+	    OVclose();
+	    _exit(1);
+	}
+	if (!OVctl(OVCUTOFFLOW, (void *)&Cutofflow)) {
+            warn("cannot obtain overview cutoff information");
+	    OVclose();
+	    _exit(1);
+	}
     }
 
     /* This is a bit odd, but as long as other user's files can't be deleted
@@ -206,7 +186,7 @@
     fd = mkstemp(SortedTmpPath);
     if (fd < 0) {
         syswarn("cannot create temporary file");
-        overview_close(overview);
+        OVclose();
         Fork ? _exit(1) : exit(1);
     }
     close(fd);
@@ -217,7 +197,7 @@
     if (i != 0) {
         syswarn("cannot sort temporary overview file (%s exited %d)",
                 INN_PATH_SORT, i);
-        overview_close(overview);
+	OVclose();
 	Fork ? _exit(1) : exit(1);
     }
 
@@ -229,7 +209,7 @@
     /* read sorted lines. */
     if ((qp = QIOopen(SortedTmpPath)) == NULL) {
         syswarn("cannot open sorted overview file %s", SortedTmpPath);
-        overview_close(overview);
+	OVclose();
 	Fork ? _exit(1) : exit(1);
     }
 
@@ -249,17 +229,13 @@
                  SortedTmpPath, count);
 	    continue;
 	}
-
-	/* If SortOverview is false, line points to the arrival date, p+1 to
-           the expiration date, q+1 to the token, and r+1 to the overview
-           data.  If it's true, there's a group name prepended, which is used
-           for sorting and which we have to strip off first. */
-        *p++ = '\0';
-        *q++ = '\0';
-        *r++ = '\0';
-	if (SortOverview) {
-            data.arrived = (time_t) atol(p);
-            data.expires = (time_t) atol(q);
+	/* p+1 now points to start of token, q+1 points to start of overline. */
+	if (sorttype == OVNEWSGROUP) {
+	    *p++ = '\0';
+	    *q++ = '\0';
+	    *r++ = '\0';
+	    arrived = (time_t)atol(p);
+	    expires = (time_t)atol(q);
 	    q = r;
 	    if ((r = strchr(r, '\t')) == NULL) {
                 warn("sorted overview file %s has a bad line at %d",
@@ -268,45 +244,34 @@
 	    }
 	    *r++ = '\0';
 	} else {
-            data.arrived = (time_t) atol(line);
-            data.expires = (time_t) atol(p);
+	    *p++ = '\0';
+	    *q++ = '\0';
+	    *r++ = '\0';
+	    arrived = (time_t)atol(line);
+	    expires = (time_t)atol(p);
 	}
-        data.token = TextToToken(q);
-        data.overview = r;
-        data.overlen = strlen(r);
-        xref = find_xref(&data);
-        if (xref == NULL) {
-            warn("no Xref found in overview data for %s", q);
-            continue;
-        }
-
-        /* Okay, we can finally add the data. */
-        if (!overview_add_xref(overview, xref, &data)) {
-            float space;
-
-            space = overview_free_space(overview);
-            if (space >= 0 && space <= 0.1) {
+	token = TextToToken(q);
+	if (OVadd(token, r, strlen(r), arrived, expires) == OVADDFAILED) {
+	    if (OVctl(OVSPACE, (void *)&i) && i == OV_NOSPACE) {
                 warn("no space left for overview");
-                overview_close(overview);
-                Fork ? _exit(1) : exit(1);
-            }
-            warn("cannot write overview data for %s", q);
-        }
+		OVclose();
+		Fork ? _exit(1) : exit(1);
+	    }
+            warn("cannot write overview data \"%.40s\"", q);
+	}
     }
-
     /* Check for errors and close. */
     if (QIOerror(qp)) {
         syswarn("cannot read sorted overview file %s", SortedTmpPath);
-	overview_close(overview);
+	OVclose();
 	Fork ? _exit(1) : exit(1);
     }
     QIOclose(qp);
-
     /* unlink sorted tmp file */
     unlink(SortedTmpPath);
     free(SortedTmpPath);
-    if (Fork) {
-	overview_close(overview);
+    if(Fork) {
+	OVclose();
 	_exit(0);
     }
 }
@@ -318,14 +283,12 @@
 **  appropriate.
 */
 static void
-WriteOverLine(struct overview *overview, TOKEN *token, const char *xrefs,
-              int xrefslen, char *overdata, int overlen, time_t arrived,
-              time_t expires)
+WriteOverLine(TOKEN *token, const char *xrefs, int xrefslen, 
+	      char *overdata, int overlen, time_t arrived, time_t expires)
 {
     char temp[SMBUF];
-    const char *p, *q, *r, *xref;
-    int fd;
-    struct overview_data data;
+    const char *p, *q, *r;
+    int i, fd;
 
     /* If WriteStdout is set, just print the overview information to standard
        output and return. */
@@ -340,35 +303,21 @@
     /* If the overview method doesn't care about sorted data, don't bother
        with the temporary file and just write the data out to our child
        process or to the overview database directly. */
-    if (!SortOverview) {
+    if (sorttype == OVNOSORT) {
 	if (Fork) {
 	    fprintf(Overchan, "%s %ld %ld ", TokenToText(*token), (long)arrived, (long)expires);
 	    if (fwrite(overdata, 1, overlen, Overchan) != (size_t) overlen)
                 sysdie("writing overview failed");
 	    fputc('\n', Overchan);
-	} else {
-            data.token = *token;
-            data.overview = overdata;
-            data.overlen = overlen;
-            data.arrived = arrived;
-            data.expires = expires;
-            xref = find_xref(&data);
-            if (xref == NULL) {
-                warn("no Xref in overview data for %s", TokenToText(*token));
-                return;
-            }
-            if (!overview_add_xref(overview, xref, &data)) {
-                float space;
-
-                space = overview_free_space(overview);
-                if (space >= 0 && space <= 0.1) {
-                    warn("no space left for overview");
-                    overview_close(overview);
-                    exit(1);
-                }
-            }
-            warn("cannot write overview data for %s", TokenToText(*token));
-        }
+	} else if (OVadd(*token, overdata, overlen, arrived, expires) == OVADDFAILED) {
+	    if (OVctl(OVSPACE, (void *)&i) && i == OV_NOSPACE) {
+                warn("no space left for overview");
+		OVclose();
+		exit(1);
+	    }
+            warn("cannot write overview data for article %s",
+                 TokenToText(*token));
+	}
 	return;
     }
 
@@ -388,7 +337,7 @@
 
     /* Print out the data to the teporary file with the appropriate keys for
        sorting. */
-    if (SortOverview) {
+    if (sorttype == OVNEWSGROUP) {
 	/* find first ng name in xref. */
 	for (p = xrefs, q=NULL ; p < xrefs+xrefslen ; ++p) {
 	    if (*p == ' ') {
@@ -430,7 +379,7 @@
     OverTmpSegCount++;
 
     if (OverTmpSegSize != 0 && OverTmpSegCount >= OverTmpSegSize) {
-	FlushOverTmpFile(overview);
+	FlushOverTmpFile();
     }
 }
 
@@ -546,7 +495,7 @@
  * Handle a single article.  This routine's fairly complicated. 
  */
 static void
-DoArt(ARTHANDLE *art, struct overview *overview)
+DoArt(ARTHANDLE *art)
 {
     ARTOVERFIELD		*fp;
     const char                  *p, *end;
@@ -734,7 +683,7 @@
                 buffer.left++;
             }
 	}
-	WriteOverLine(overview, art->token, Xrefp->Header, Xrefp->HeaderLength,
+	WriteOverLine(art->token, Xrefp->Header, Xrefp->HeaderLength,
 		      buffer.data, buffer.left, Arrived, Expires);
     }
 
@@ -753,13 +702,13 @@
 ** Add all groups to overview group.index. --rmt
 */
 static void
-OverAddAllNewsgroups(struct overview *overview)
+OverAddAllNewsgroups(void)
 {
     QIOSTATE *qp;
     int count;
-    char *q, *p;
+    char *q,*p;
     char *line;
-    struct overview_group data;
+    ARTNUM hi, lo;
 
     if ((qp = QIOopen(ActivePath)) == NULL)
         sysdie("cannot open %s", ActivePath);
@@ -769,19 +718,19 @@
 	    continue;
 	}
 	*p++ = '\0';
-        data.high = (ARTNUM) atol(p);
+	hi = (ARTNUM)atol(p);
 	if ((p = strchr(p, ' ')) == NULL) {
             warn("bad active line %d: %.40s", count, line);
 	    continue;
 	}
 	*p++ = '\0';
-        data.low = (ARTNUM) atol(p);
+	lo = (ARTNUM)atol(p);
 	if ((q = strrchr(p, ' ')) == NULL) {
             warn("bad active line %d: %.40s", count, line);
 	    continue;
 	}
-        data.flag = q[1];
-        if (!overview_group_add(overview, line, &data))
+	/* q+1 points to NG flag */
+	if (!OVgroupadd(line, lo, hi, q+1))
             die("cannot add %s to overview group index", line);
     }
     /* Test error conditions; QIOtoolong shouldn't happen. */
@@ -827,7 +776,6 @@
     char *buff;
     size_t npairs = 0;
     FILE *F;
-    struct overview *overview = NULL;
 
     /* First thing, set up logging and our identity. */
     openlog("makehistory", L_OPENLOG_FLAGS | LOG_PID, LOG_INN_PROG);
@@ -924,30 +872,25 @@
     /* Read in the overview schema */
     ARTreadschema(DoOverview);
     
-    /* If we're writing to the overview database directly, open it and prepare
-       to write to it later. */
     if (DoOverview && !WriteStdout) {
-        struct overview_config config;
-
-        overview = overview_open(OV_WRITE);
-        if (overview == NULL)
+	/* init the overview setup. */
+	if (!OVopen(OV_WRITE))
             sysdie("cannot open overview");
-        overview_config_get(overview, &config);
-        SortOverview = config.sorted;
+	if (!OVctl(OVSORT, (void *)&sorttype))
+            die("cannot obtain overview sort information");
 	if (!Fork) {
-            config.cutoff = Cutofflow;
-            if (!overview_config_set(overview, &config))
-                die("cannot set overview cutoff configuration");
-	    OverAddAllNewsgroups(overview);
+	    if (!OVctl(OVCUTOFFLOW, (void *)&Cutofflow))
+                die("cannot obtain overview cutoff information");
+	    OverAddAllNewsgroups();
 	} else {
-	    OverAddAllNewsgroups(overview);
-	    if (!SortOverview) {
+	    OverAddAllNewsgroups();
+	    if (sorttype == OVNOSORT) {
 		buff = concat(innconf->pathbin, "/", "overchan", NULL);
 		if ((Overchan = popen(buff, "w")) == NULL)
                     sysdie("cannot fork overchan process");
 		free(buff);
 	    }
-            overview_close(overview);
+	    OVclose();
 	}
     }
 
@@ -983,7 +926,7 @@
 		SMcancel(*art->token);
 	    continue;
 	}
-	DoArt(art, overview);
+	DoArt(art);
     }
 
     if (!NoHistory) {
@@ -993,12 +936,12 @@
     }
 
     if (DoOverview) {
-	if (!SortOverview && Fork)
+	if (sorttype == OVNOSORT && Fork)
 	    if (fflush(Overchan) == EOF || ferror(Overchan) || pclose(Overchan) == EOF)
                 sysdie("cannot flush overview data");
-	if (SortOverview && !WriteStdout) {
+	if (sorttype != OVNOSORT && !WriteStdout) {
 	    int status;
-	    FlushOverTmpFile(overview);
+	    FlushOverTmpFile();
 	    if(Fork)
 		wait(&status);
 	}
@@ -1011,6 +954,6 @@
         }
     }
     if (!Fork && !WriteStdout)
-        overview_close(overview);
+	OVclose();
     exit(0);
 }



More information about the inn-committers mailing list