NNTPC: default overview format - solved

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

 



Hello,

in a previous post I've explained a problem with nntpcache and
newsserver which provide the XOVER command but no LIST overview.fmt.
I've checked the source and found out, that there's no code in
getListServer (LIST.C) to use a default overview format.

Additionally, the code which writes the overview.fmt to a file in the
newsserver dir, is (IMO) buggy. Currently, it writes the overview.fmt
to the file as (notice that there are no ':' between the fields and
that all fields are in the same line):

SubjectFromDateMessage-IDReferencesBytesLines

It should be (to get the code working which reads the overview.fmt
file from disk cache in getListServer):

Subject:
From:
Date:
Message-ID:
References:
Bytes:
Lines:

(note, that every field is in a separate line and has a ':' appended).

If you look at the appended code from getListServer/LIST.C, it will
crash with a SIGSEGV, when it reads from overview.fmt (f_server_good
== FALSE). The complete overview.fmt is read by one fgets (there is
only one line) and there are _no_ colons, p is nil and list2 will
never contain a element. scfg->overview_fmt = list2->head will cause
the SIGSEGV.

		while (f_server_good? (Cfget(scfg, buf, sizeof buf) &&
		!EL(buf)): (fgets(buf, sizeof(buf), fp)!=NULL))
		{
			char *p = strchr (buf, ':');
			if (!p)
				continue;
			bytes += strlen(buf);
			*p = '\0';
			hash = strHash (hash, buf);
			list2 = strListAdd (list2, buf);
			if (f_server_good)
				fputs(buf, fp);
		}
[...]
		scfg->overview_fmt = list2->head;

My patch applies the default overview format defined in the config
file for servers which don't supply the "LIST overview.fmt" and
corrects the problem with the overview.fmt files. I hope, that this
patch is useful for someone out there (hi, Isabella). Comments are
welcome.

regards
ralph

--- list.c.orig	Tue Feb 18 16:05:04 1997
+++ list.c	Tue Feb 18 16:04:38 1997
@@ -269,6 +269,7 @@
 	FILE *fp=NULL;
 
 	time_t tim=time(NULL);
+	bool f_default_overview_fmt_used = FALSE;
 
 	log (("checking server %s for '%s'", scfg->host, list->name));
 	if (list->type == l_active)
@@ -278,7 +279,40 @@
 	Cfflush(scfg);
 	if (!Cfget (scfg, buf, sizeof buf))
 		goto dropped;
-	if (strToi(buf) != NNTP_LIST_FOLLOWS_VAL)
+	if (strToi(buf) != NNTP_LIST_FOLLOWS_VAL && list->type == l_overview_fmt) 
+	{
+		if(overviewFmtDef == NULL) 
+		{
+			logw (("no default overview format defined!"));
+			chdir (con.cacheDir);
+			return 0;
+		}
+		else 
+		{
+			struct strList *list_tmp=overviewFmtDef;
+			
+			setGroupDir(NULL, scfg);
+			if ((fp = fopen(list->name, "w")) == NULL)
+			{
+				loge(("couldn't write %s/%s (default) to disk cache", scfg->host, list->name));
+				chdir (con.cacheDir);
+				return 0;
+			}
+
+			while(list_tmp != NULL) {
+				fputs(list_tmp->data, fp);
+				fputs(":\r\n", fp);
+				list_tmp = list_tmp->next;
+			}
+
+			fclose (fp);
+
+			logw (("default overview format used!"));
+			f_default_overview_fmt_used = TRUE;
+		}
+	}
+
+	if (strToi(buf) != NNTP_LIST_FOLLOWS_VAL && list->type != l_overview_fmt)
 	{
 		buf[MAX_SYSLOG]='\0';
 		logw (("list %s on %s error: %s", list->name, scfg->host, buf));
@@ -291,7 +325,7 @@
 		struct strList *list2=NULL;
 		U32 hash=0;
 		bool f_server_good;
-		if (!(scfg=attachServer(scfg)))
+		if (f_default_overview_fmt_used || !(scfg=attachServer(scfg)))
 		{
 		retry_disk:
 			if ((fp = fopen(list->name, "r")) == NULL)
@@ -319,8 +353,10 @@
 			*p = '\0';
 			hash = strHash (hash, buf);
 			list2 = strListAdd (list2, buf);
-			if (f_server_good)
+			if (f_server_good) {
 				fputs(buf, fp);
+				fputs(":\r\n", fp);
+			}
 		}
 		if (fp)
 			fclose (fp);

[Index of Archives]     [Yosemite]     [Yosemite Campsites]     [Bugtraq]     [Linux]     [Trn]

Powered by Linux