[news.software.b] More sys file flags for C News.

ross@contact.uucp (Ross Ridge) (05/11/91)

Yes, just what you haven't asked for, more sys file flags for C News.
I decided that having two news flags, 'o' and 'x', would be really handy,
and so hacked them into C News's relaynews.  Would others find them
useful?  I dunno, but I figured it wouldn't hurt (much) if I posted
the patches to net.

The flags basically correspond to the -o and -x options to relaynews.

The 'o' flag limits the age of articles sent to the site, it takes
a numeric argument, like the 'L' flag, but allowing decimal fractions,
being the age limit in days.  Note: the -o option will reject articles
before relaynews even looks at the sys file.

The 'x' flags makes the site of the sys line the current excluded
site (meaning articles will not be sent to that site), if the sys
line matches (site, newsgroups, distributions, and other flags).
Only one site can be excluded at a time, if another site's sys
line matches and has the 'x' flag then that site replaces the current
exclusion.  If the -x option is supplied to relaynews then any
'x' flags are ignored.

Why?

Well lets show you a site that has four lines in our sys file and uses
both these flags:

# send them regional groups regardless of source
torag:\
	tor,ont,can,to.torag\
	/all,!local,!camelot,!contact\
	:xf:
# feed them rec groups, but not the ones from nttor, 'cause they
# can be flaky at times and send a weeks news in one day
torag/nttor:\
	rec\
	/all,!local,!camelot,!contact\
	:xf:
# but any rec article not over two days old from nttor is ok
torag:\
	rec\
	/all,!local,!camelot,!contact\
	:xfo2.0:
# We get comp and news from them, so we need to send them our
# comp and news articles and those of our "downstream" sites.
# (geac, nttor, tsltor and utdoe being "upstream")
torag/geac,nttor,tsltor,utdoe:\
	comp,news,\
	/all,!local,!camelot,!contact\
	:f:

When one of the first three lines matches, none of the rest are
considered because of the 'x' flags.  This prevents the
same article being sent three times when it's crossposted locally
to, say, ont.sf-lovers and rec.arts.sf-lovers.

Since this patch modifies some of C News headers you should
probably clean out all the object files and rebuild all of 
C news.  You may be able to get away with cleaning out
the libbig, libsmall and relay subdirs, but I'm not sure.
This patch is relative to C News patch date 24-Mar-1991,
it won't likely work with any other.

Remember, applying this patch voids your warranty, so if
you have any problems with C news thereafter, flame me,
not Henry or Geoff, as it's probably my fault.

*** relay/save/article.h	Sat May  4 22:21:46 1991
--- relay/article.h	Sat May  4 22:46:59 1991
***************
*** 24,29 ****
--- 24,30 ----
  	long a_unread;		/* bytes of article input yet unread */
  	long a_id;		/* article id #, unique within this batch */
  	boolean a_badhdr;	/* true iff non-header is before blank line */
+ 	time_t a_age;		/* age of article (from headers) */
  };
  
  /* return name of at least one link, for printing in error messages, etc. */
*** relay/save/procart.c	Sat May  4 22:21:46 1991
--- relay/procart.c	Sat May  4 22:50:58 1991
***************
*** 369,376 ****
  	} else if (alreadyseen(hdrs->h_msgid)) {
  		prefuse(art);
  		(void) fputs("duplicate\n", stdout);
! 	} else
! 		return;			/* art was accepted */
  	decline(art);
  }
  
--- 369,378 ----
  	} else if (alreadyseen(hdrs->h_msgid)) {
  		prefuse(art);
  		(void) fputs("duplicate\n", stdout);
! 	} else {
! 		art->a_age = now - date; /* save age of article */
! 		return;			 /* art was accepted */
! 	}
  	decline(art);
  }
  
*** relay/save/sys.c	Sat May  4 21:53:44 1991
--- relay/sys.c	Sat May  4 23:49:21 1991
***************
*** 15,20 ****
--- 15,22 ----
  #include "config.h"
  #include "system.h"
  
+ #define DAY	(24L*60L*60L)
+ 
  #define BTCHDIR "out.going/"	/* prefix of relative batch file name */
  #define BTCHPFX BTCHDIR		/* prefix of default batch file name */
  #define BTCHSFX "/togo"		/* suffix of same */
***************
*** 323,328 ****
--- 325,352 ----
  			sysp->sy_flags |= FLG_UNMOD;
  			break;
  		case 'U':		/* mostly harmless */
+ 			break;
+ 		case 'o':		/* on */
+ 			sysp->sy_flags |= FLG_AGE;
+ 			sysp->sy_age = 0L;
+ 			while (isascii(flags[1]) && isdigit(flags[1])) {
+ 				sysp->sy_age *= 10L;
+ 				sysp->sy_age += *++flags - '0';
+ 			}
+ 			sysp->sy_age *= DAY;
+ 			if (flags[1] == '.') {
+ 				long t = DAY;
+ 				flags++;
+ 				while (isascii(flags[1]) && isdigit(flags[1])) {
+ 					t /= 10L;
+ 					sysp->sy_age += (*++flags - '0') * t;
+ 				}
+ 			}
+ 			if (sysp->sy_age == 0)		/* supply a default */
+ 				sysp->sy_age = DAY;
+ 			break;
+ 		case 'x':
+ 			sysp->sy_flags |= FLG_EXCLUDE;
  			break;
  		case 'H':		/* bugger off */
  		case 'S':		/* bugger off */
*** relay/save/system.h	Sat May  4 21:53:44 1991
--- relay/system.h	Sat May  4 22:40:43 1991
***************
*** 9,16 ****
  	char *sy_ngs;		/* newsgroup subscription list */
  	char *sy_distr;		/* distribution list */
  	char *sy_cmd;		/* command to transmit articles */
  	unsigned sy_lochops;	/* flags Ln value: local hops */
! 	char sy_flags;		/* ornaments, encoded as bits */
  	struct system *sy_next;	/* link to next system */
  };
  
--- 9,17 ----
  	char *sy_ngs;		/* newsgroup subscription list */
  	char *sy_distr;		/* distribution list */
  	char *sy_cmd;		/* command to transmit articles */
+ 	time_t sy_age;		/* flags on value: max age */
  	unsigned sy_lochops;	/* flags Ln value: local hops */
! 	short sy_flags;		/* ornaments, encoded as bits */
  	struct system *sy_next;	/* link to next system */
  };
  
***************
*** 22,27 ****
--- 23,30 ----
  #define FLG_MOD		(1<<4)		/* m: send moderated groups only */
  #define FLG_UNMOD	(1<<5)		/* u: send unmoderated groups only */
  #define FLG_NBATCH	(1<<6)		/* n: NNTP batch: filename & msg-id */
+ #define FLG_AGE		(1<<7)		/* o: send recent articles only */
+ #define FLG_EXCLUDE	(1<<8)		/* x: exclude this system */
  
  /* imports from system.c */
  extern struct system *oursys(), *nextsys();
*** relay/save/transmit.c	Sat May  4 21:53:44 1991
--- relay/transmit.c	Sat May  4 23:48:21 1991
***************
*** 41,47 ****
--- 41,52 ----
  {
  	register struct system *sys;
  	register int bsysno = 0;	/* ordinal # of batch sys entry */
+ 	register int real_exclude = 0;
  
+ 	if (exclude != NULL) {
+ 		real_exclude = 1;
+ 	}
+ 
  	rewndsys();
  	if (debug)
  		(void) fprintf(stderr, "just rewound sys file\n");
***************
*** 50,60 ****
  			(void) fprintf(stderr,
  				"sy_name=%s sy_ngs=%s sy_distr=%s\n",
  				sys->sy_name, sys->sy_ngs, sys->sy_distr);
! 		if (oktransmit(art, sys, exclude))
  			ejaculate(art, sys, bsysno);
  		if (sys->sy_flags&FLG_BATCH)
  			++bsysno;
  	}
  	if (debug)
  		(void) fprintf(stderr, "just finished reading sys file\n");
  }
--- 55,73 ----
  			(void) fprintf(stderr,
  				"sy_name=%s sy_ngs=%s sy_distr=%s\n",
  				sys->sy_name, sys->sy_ngs, sys->sy_distr);
! 		if (oktransmit(art, sys, exclude)) {
  			ejaculate(art, sys, bsysno);
+ 			if ((sys->sy_flags&FLG_EXCLUDE) && !real_exclude) {
+ 				if (exclude != NULL)
+ 					free(exclude);
+ 				exclude = strsave(sys->sy_name);
+ 			}
+ 		}
  		if (sys->sy_flags&FLG_BATCH)
  			++bsysno;
  	}
+ 	if (exclude != NULL && !real_exclude) 
+ 		free(exclude);
  	if (debug)
  		(void) fprintf(stderr, "just finished reading sys file\n");
  }
***************
*** 101,106 ****
--- 114,120 ----
  	    STREQ(hostname(), site) ||
  	    exclude != NULL && STREQ(exclude, site) || hostin(site, path) ||
  	    sys->sy_excl != NULL && anyhostin(sys->sy_excl, path) ||
+ 	    flags&FLG_AGE && art->a_age > sys->sy_age ||
  	    !ngmatch(sys->sy_ngs, art->h.h_ngs) ||
  	    !ngmatch(sys->sy_distr, art->h.h_distr))
  		result = NO;
-- 
Ross Ridge								 //
"The Great HTMU"							[oo]
ross@contact.uucp							-()-
ross@watcsc.uwaterloo.ca						 //