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

Re: [leafnode-list] Fetchnews Problem



Colin Brough wrote:

[slrn 0.9.5.7 seems to be Y2K-compliant]

> Would my understanding of the NEWGROUPS situation be that it is the
> news-readers responsibility to keep track of the last time a user read
> news, and from that send an appropriate NEWGROUPS command to the
> server?

Exactly.

You can see which NEWGROUPS command is sent to the server by switching
on the debugging mode of Leafnode.

> So slrn notes somewhere the last time I read news, so it can
> work out what is new. Likewise, fetchnews will note the last time it
> read news from the upstream server, and send an appropriate NEWGROUPS
> command to it...

That's the way how it should work, yes.

> (Poking around, the .jnewsrc.time file in my home directory, which is
>  used by slrn, contains:
> 	NEWGROUPS 000824 083307 GMT
>  This at Thu Aug 24 10:16:55 BST 2000.)

Maybe the GMT is the cause of the problem. Please try the following patch
(most of which comes straight from 2.0a):

--- nntpd.c.orig	Thu Aug 24 12:10:31 2000
+++ nntpd.c	Thu Aug 24 12:18:12 2000
@@ -97,12 +97,45 @@
 
 static jmp_buf timeout;
 
+time_t gmt_off;                 /* offset between localtime and GMT in sec */
+
 static void timer(int sig) {
     longjmp(timeout, 1);
     exit(sig);			/* not reached */
 }
 
 /*
+ * calculate offset in seconds between GMT and localtime.
+ * Code by Joerg Dietrich <joerg@xxxxxxxxxxxx>.
+ */
+static time_t gmtoff( void ) {
+    time_t localsec, gmtsec;
+    time_t now;
+    struct tm * ltime;
+    char *zone, *oldzone;
+    int  len;
+
+    now = time( NULL );		/* returns UTC */
+    ltime = localtime( &now );
+    localsec = mktime( ltime );
+
+    zone = getenv( "TZ" );	/* save current timezone */
+    len = 4 + ( zone ? strlen(zone) : 0 );
+    oldzone = (char *)calloc( len, sizeof(char) );
+    if ( !oldzone ) {
+	syslog( LOG_NOTICE, "Unable to allocate %d chars, using GMT", len );
+	return(0);
+    }
+    snprintf( oldzone, len, "TZ=%s", zone ? zone : "" );
+    putenv( "TZ=GMT" );		/* use mktime to create UTC */
+    gmtsec = mktime( ltime );
+    putenv( oldzone );
+    free( oldzone );
+
+    return( gmtsec - localsec );
+}
+
+/*
  * call getaline with 15 min timeout (not configurable)
  */
 static char * mgetaline( FILE *f ) {
@@ -753,21 +786,23 @@
 void donewgroups(const char *arg) {
     struct tm timearray;
     struct tm * ltime;
-    struct newsgroup *g;
     time_t age;
     time_t now;
     int year, century;
     char * l;
     int a, b;
+    struct newsgroup * ng;
 
     now = time( 0 );
     ltime = localtime( &now );
     year    = ltime->tm_year % 100;
-    century = ltime->tm_year / 100;
+    century = ltime->tm_year / 100;  /* 0 for 1900-1999, 1 for 2000-2099 etc */
 
     memset( &timearray, 0, sizeof(timearray) );
     l = NULL;
     a = strtol( arg, &l, 10 );
+    /* NEWGROUPS may have the form YYMMDD or YYYYMMDD.
+       Distinguish between the two */
     b = a / 10000;
     if ( b < 100 ) {
 	/* YYMMDD */
@@ -776,10 +811,11 @@
 	else
 	    timearray.tm_year = b + (century-1)*100 ;
     } else if ( b < 1000 ) {
-    	/* YYYMMDD - this should not happen, but leafnode will parse it */
+    	/* YYYMMDD - happens with buggy newsreaders */
+	/* In these readers, YYY=100 is equivalent to YY=00 or YYYY=2000 */
 	syslog( LOG_NOTICE,
 		"NEWGROUPS year is %d: please update your newsreader", b );
-	timearray.tm_year = b;
+	timearray.tm_year = b ;
     } else {
 	/* YYYYMMDD */
 	timearray.tm_year = b - 1900 ;
@@ -792,20 +828,22 @@
     timearray.tm_hour = a / 10000;
     timearray.tm_min  = a % 10000 / 100;
     timearray.tm_sec  = a % 100;
-#ifdef HAVE_GMTOFF
-    age = mktime( &timearray ) + (strstr( arg, "GMT" ) ? 0 : ltime->tm_gmtoff );
-#else
-    age = mktime( &timearray ) - (strstr( arg, "GMT" ) ? 0 : timezone);
-#endif
+    /* mktime() shall guess correct value of tm_isdst (0 or 1) */
+    timearray.tm_isdst = -1;
+    /* mktime() assumes local time -> correct according to timezone
+       (global variable set by last call to localtime() ) if GMT is not
+       requested */
+    age = mktime( &timearray ) - (strstr( arg, "GMT" ) ? gmt_off : 0 );
 
-    printf( "231 List of new newsgroups follows\r\n" );
+    printf( "231 List of new newsgroups since %ld follows\r\n", age );
     if ( debugmode )
-	syslog( LOG_DEBUG, ">231 List of new newsgroups follows" );
-    g = active;
-    while ( g->name ) {
-	if ( g->age >= age )
-	    printf( "%s %lu %lu y\r\n", g->name, g->first, g->last );
-	g++;
+	syslog( LOG_DEBUG, "231 List of new newsgroups since %ld follows", age );
+
+    ng = active;
+    while ( ng->name ) {
+	if ( ng->age >= age )
+	    printf( "%s %lu %lu y\r\n", ng->name, ng->first, ng->last );
+	ng++;
     }
     printf( ".\r\n" );
 }
@@ -1435,6 +1473,8 @@
     pseudogroup = FALSE;
 
     rereadactive();
+
+    gmt_off = gmtoff(); /* get difference between local time and GMT */
 
     parser();
     fflush(stdout);

--Cornelius.

-- 
/* Cornelius Krasel, U Wuerzburg, Dept. of Pharmacology, Versbacher Str. 9 */
/* D-97078 Wuerzburg, Germany   email: phak004@xxxxxxxxxxxxxxxxxxxxxx  SP4 */
/* "Science is the game we play with God to find out what His rules are."  */

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