[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[leafnode-list] Need feedback: KNode and others suffering from delaybody.



Hi,

I have an EXPERIMENTAL patch (below) for leafnode 1.9.40 that changes
the way bodies are fetched. Usually, leafnode will delete the original
article and write a new one, with the same message-ID and a higher
article number. This confuses KNode 0.7.1 and likely other versions.

Can people try if KNode works if the article header and body caches are
set to 0 KB each and leafnode's delaybody=1?


The other option is using the patch: With the patch, fetchnews will
instead update the article body in place and retain both the original
article number and message-ID. I have had some success with this patch,
delaybody=1 and KNode, I needed to reduce the KNode article cache to 0
KB. The header cache was left at its default of 2048 kB.


If this doesn't work either, then I'll have to go all the way and fake
the Message-ID of the "just-header" articles and give the real article
both a new Message-ID and a new article number. I can't yet estimate
what adverse effect this would have. This isn't yet implemented.


The status of this entire code is uncertain. I doubt it's adequate for a
"stable" release, so I guess I'll add an option that defaults to "off"
before releasing this code.


Anyways, here's the patch. To apply, unpack leafnode 1.9.40.rel, save
this mail body to a file, say patch-delaybody, within the leafnode
directory, then type:

cd leafnode-1.9.40.rel
patch <patch-delaybody -p0

Then build as usual.

Index: fetchnews.c
===================================================================
RCS file: /var/CVS/leafnode-1/fetchnews.c,v
retrieving revision 1.105
diff -u -r1.105 fetchnews.c
--- fetchnews.c	20 May 2003 16:05:37 -0000	1.105
+++ fetchnews.c	20 May 2003 19:25:42 -0000
@@ -358,38 +358,19 @@
     const char *c;
     int rc = 0;
     char *l;
-    char *p, *q;
     char *messageid;
-    char *newsgroups;		/* I hope this is enough */
-    char *xref;
-    FILE *f, *g;
+    FILE *f;
     char s[SIZE_s+1];
+    off_t pos;
 
     if (!chdirgroup(group->name, FALSE))
 	return 0;
 
-    /* extract message-id: and xref: headers */
+    /* extract message-id: header */
     xsnprintf(s, SIZE_s, "%lu", id);
-    if (!(f = fopen(s, "r"))) {
-	syslog(LOG_INFO, "%s: cannot open %s for reading -- possibly expired",
-	       group->name, s);
-	return 1;		/* pretend to have read file successfully so that
-				   it is purged from the list */
-    }
-    messageid = NULL;
-    newsgroups = NULL;
-    xref = NULL;
-    debug = 0;
-    while ((l = getaline(f)) != NULL) {
-	if (!newsgroups && !strncmp(l, "Newsgroups: ", 12))
-	    newsgroups = critstrdup(l + 12, "getbody");
-	if (!messageid && !strncmp(l, "Message-ID: ", 12))
-	    messageid = critstrdup(l + 12, "getbody");
-	if (!xref && !strncmp(l, "Xref: ", 6))
-	    xref = critstrdup(l + 6, "getbody");
-    }
-    debug = debugmode;
-    fclose(f);
+    messageid = getheader(s, "Message-ID:");
+    if (!messageid)
+	return 0;
 
     /* check whether we can retrieve the body */
     if (verbose > 2)
@@ -406,36 +387,14 @@
 
     xsnprintf(s, SIZE_s, "%lu", id);
     c = lookup(messageid);
-    unlink(c);			/* make space for new file */
-
-    if (!(f = fopen(c, "w"))) {
-	syslog(LOG_ERR, "%s: cannot open %s for writing", group->name, c);
-	link(s, c);		/* if we can't open new file restore old one */
+    if (!(f = fopen(c, "a"))) {
+	syslog(LOG_ERR, "%s: cannot open %s for appending", group->name, c);
 	rc = 0;
 	goto getbody_bail;
     }
+    pos = ftell(f);
+    fputc('\n', f); /* blank line -- separate header and body */
 
-    /* copy all headers except Xref: into new file */
-    g = fopen(s, "r");
-    if (!g) {
-	syslog(LOG_ERR, "%s: open %s failed", group->name, s);
-	rc = 0;
-	goto getbody_bail;
-    }
-    debug = 0;
-    while ((l = getaline(g)) != NULL) {
-	/* skip xref: headers */
-	if (strncasecmp(l, "Xref: ", 6) != 0)
-	    fprintf(f, "%s\n", l);
-    }
-    debug = debugmode;
-    fclose(g);
-
-    /* create a whole bunch of new hardlinks */
-    store(c, f, newsgroups, messageid);
-
-    /* retrieve body */
-    fprintf(f, "\n");		/* Empty line between header and body. */
     debug = 0;
     while (((l = getaline(nntpin)) != NULL) && strcmp(l, ".") && !ferror(f)) {
 	if (*l == '.')
@@ -444,62 +403,28 @@
 	fputc('\n', f);
     }
     debug = debugmode;
+
     if (!l) {
 	syslog(LOG_ERR, "%s: Retrieving body %s failed. "
 	       "Transmission interrupted.", group->name, messageid);
-	fprintf(f, "\n\t[ Leafnode: ]\n"
-		"\t[ An error occured while " "retrieving this message. ]\n");
+	ftruncate(fileno(f), pos);
 	fclose(f);
 	rc = 0;
 	goto getbody_bail;
     }
+
     /* abort when disk is full */
-    if (fclose(f) && errno == ENOSPC)
+    if (fclose(f) && errno == ENOSPC) {
+	truncate(s, pos);
 	raise(SIGINT);
-
-    /* Remove old article files since we don't need them anymore.
-       This is done by evaluating the old Xref: header.
-     */
-    if (!xref) {
-	/* no Xref: header --> make a fake one */
-	xref = critmalloc(50 + strlen(fqdn) + strlen(group->name), "getbody");
-	sprintf(xref, "%s %s:%lu", fqdn, group->name, id);	/* RATS: ignore */
+	return 0;
     }
 
-    if (debugmode)
-	syslog(LOG_DEBUG, "xref: %s", xref);
-    c = strchr(xref, ' ');
-#ifdef __LCLINT__
-    assert(c != NULL);		/* we know c != NULL */
-#endif				/* __LCLINT__ */
-    while ((c++) && (*c) && (q = strchr(c, ':')) != NULL) {
-	*q++ = '\0';
-	if ((p = strchr(q, ' ')) != NULL)
-	    *p = '\0';
-
-	/* c points to the newsgroup, q to the article number */
-	if (!chdirgroup(c, FALSE)) {
-	    return 0;
-	}
-	if (unlink(q))
-	    syslog(LOG_NOTICE,
-		   "retrieved body, but unlinking headers-only file %s/%s failed",
-		   c, q);
-	else if (debugmode)
-	    syslog(LOG_DEBUG,
-		   "retrieved body, now unlinking headers-only file %s/%s", c,
-		   q);
-
-	c = strchr(q, ' ');
-    }
     rc = 1;
+
   getbody_bail:
-    if (xref)
-	free(xref);
     if (messageid)
 	free(messageid);
-    if (newsgroups)
-	free(newsgroups);
     return rc;
 }
 


-- 
Matthias Andree
leafnode-1 download: http://sourceforge.net/projects/leafnode/
leafnode-1 docs/new: http://mandree.home.pages.de/leafnode/
leafnode-2 homepage: http://mandree.home.pages.de/leafnode/beta/

-- 
leafnode-list@xxxxxxxxxxxxxxxxxxxxxxxxxxxx -- mailing list for leafnode
To unsubscribe, send mail with "unsubscribe" in the subject to the list