🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #3790

Re: Force user to read certain groups

#3790
From: Alan Barrett
Date: Fri, 02 Apr 1993 17:09
298 lines
8621 bytes
In article <1pd5fa$956@lucy.ee.und.ac.za>, I wrote:
> Here's a patch for strn-0.8.4 to do some enforcement.

Here's an improved version.  You can set the FORCEGROUPS variable in
the site-wide STRNRC file or in the user's .strnrc file, or let it
default to the "news.announce.newusers,news.announce.important"
value in the source code.  I would be interested to hear from anybody
who tries this.

--apb
Alan Barrett, Dept. of Electronic Eng., Univ. of Natal, Durban, South Africa
RFC822: barrett@ee.und.ac.za

--- init.c.084	Wed Mar 31 22:01:32 1993
+++ init.c	Fri Apr  2 17:17:15 1993
@@ -170,6 +170,25 @@
     thread_init();
     util_init();
 
+#ifdef ENFORCE
+    /* Add some groups to the enforcement list.
+     * Set FORCEGROUPS to an empty string or to "," to disable enforcement.
+     */
+    {
+	char *s, *p, *q;
+
+	s = savestr(getval("FORCEGROUPS",
+			"news.announce.newusers,news.announce.important"));
+	/* walk the comma-list, calling setngtoforce() on each group */
+	for (p=s; p; p=q) {
+	    q = index(p, ',');
+	    if (q) { *q++ = '\0'; }
+	    if (*p) { setngtoforce(p); }
+	}
+	free(s);
+    }
+#endif
+
 #ifdef NEWSFILTER
     if (!strEQ(getval("NCLIP","///"),"///")) {
 #ifdef SCORE
--- only.c.084	Wed Mar 31 22:01:58 1993
+++ only.c	Fri Apr  2 18:16:51 1993
@@ -16,6 +16,7 @@
 #include "EXTERN.h"
 #include "common.h"
 #include "search.h"
+#include "rcstuff.h"
 #include "util.h"
 #include "final.h"
 #include "ngsrch.h"
@@ -28,6 +29,91 @@
     ;
 }
 
+#ifdef ENFORCE
+/* Subscribe to a group and move it to near the head of the list.
+ * Returns bool pass/fail status. */
+
+static bool
+force_early_subscription(ngnam,loc)
+char *ngnam;
+NG_NUM loc;
+{
+    NG_NUM ng;
+    enum {nothing, add, subscribe, move} what = nothing;
+    bool bogus;
+
+    /* add or subscribe, if necessary */
+    ng = find_ng(ngnam);
+    if (ng == nextrcline) {			/* not in .newsrc? */
+	ng = add_newsgroup(ngnam, ':');
+	what = add;
+    } else if (RCCHAR(rcchar[ng]) != ':') {	/* not subscribed? */
+	register char *cp = rcline[ng] + rcnums[ng];
+	rcchar[ng] = (*cp && cp[1] == '0' ? '0' : ':');
+	what = subscribe;
+    } else if (ng != loc) {			/* in wrong place? */
+	what = move;
+    } else {					/* nothing to do */
+	return TRUE;
+    }
+
+    /* check if it is bogus, and either undo earlier work or press on */
+    bogus = (getngsize(ng) < TR_NONE);
+    if (bogus) {
+	switch (what) {
+	case subscribe:
+	    rcchar[ng] = '!';
+	    break;
+	case add:
+	    nextrcline--;
+	    break;
+	}
+    } else {
+	set_toread(ng);
+	checkexpired(ng);
+	ng = relocate_newsgroup(ng, loc);
+    }
+
+#ifdef VERBOSE
+    if (verbose) {
+	if (bogus) {
+	    printf("Did not force subscription to bogus group %s\n", ngnam);
+	} else {
+	    switch (what) {
+	    case add:
+		printf("Forced addition of %s to .newsrc\n", ngnam);
+		break;
+	    case subscribe:
+		printf("Forced subscription to %s\n", ngnam);
+		break;
+	    case move:
+		printf("Forced %s to start of .newsrc\n", ngnam);
+		break;
+	    }
+	}
+    }
+#endif
+
+    return !bogus;
+}
+
+/* add a group to the enforcement list */
+
+void
+setngtoforce(ngnam)
+char *ngnam;
+{
+    if (maxngtoforce < NGMAX) {
+	ngtoforce[maxngtoforce] = savestr(ngnam);
+	if (force_early_subscription(ngnam, (NG_NUM)maxngtoforce)) {
+	    maxngtoforce++;
+	}
+    }
+}
+#endif /* ENFORCE */
+
+/* add a group pattern to the restriction list */
+
 void
 setngtodo(pat)
 char *pat;
@@ -60,10 +146,36 @@
 #endif
 }
 
-/* if command line list is non-null, is this newsgroup wanted? */
+/* is group wanted? */
 
 bool
 inlist(ngnam)
+char *ngnam;
+{
+    return (inforcelist(ngnam) || indolist(ngnam));
+}
+
+/* is group wanted by the enforcement list */
+
+bool
+inforcelist(ngnam)
+char *ngnam;
+{
+#ifdef ENFORCE
+    register int i;
+
+    for (i=0; i<maxngtoforce; i++) {
+	if (strEQ(ngtoforce[i],ngnam))
+	    return TRUE;
+    }
+#endif
+    return FALSE;
+}
+
+/* is group wanted by the restriction list */
+
+bool
+indolist(ngnam)
 char *ngnam;
 {
 #ifdef ONLY
--- only.h.084	Wed Mar 31 22:03:16 1993
+++ only.h	Thu Apr  1 14:39:45 1993
@@ -24,13 +24,24 @@
 #   endif
 #endif
 
-EXT int maxngtodo INIT(0);			/*  0 => no restrictions */
+EXT int maxngtodo INIT(0);		/*  0 => no restrictions */
 					/* >0 => # of entries in ngtodo */
 
+#ifdef ENFORCE
+    EXT char *ngtoforce[NGMAX];		/* enforcements in effect */
+    EXT int maxngtoforce INIT(0);	/*  0 => no enforcements */
+					/* >0 => # of entries in ngtoforce */
+#endif
+
 void	only_init _((void));
-bool	inlist _((char*));	/* return TRUE if ngname is in command line list */
+bool	inlist _((char*));	/* return TRUE if ngname is in enforcement or restriction list */
+bool	indolist _((char*));	/* return TRUE if ngname is in restriction list */
+bool	inforcelist _((char*));	/* return TRUE if ngname is in enforcement list */
 			/* or if there was no list */
-void	setngtodo _((char*));
+void	setngtodo _((char*));		/* add pattern to restriction list */
+#ifdef ENFORCE
+void	setngtoforce _((char*));	/* add group to enforcement list */
+#endif
 #ifdef ONLY
-void	end_only _((void));
+void	end_only _((void));		/* remove restrictions */
 #endif
--- rcstuff.c.084	Thu Mar 18 23:58:49 1993
+++ rcstuff.c	Fri Apr  2 18:22:01 1993
@@ -134,6 +134,7 @@
 	    toread[newng] = TR_UNSUB;
 	    continue;
 	}
+	/* XXX: should be able to detect duplicate lines */
 
 	/* now find out how much there is to read */
 
@@ -505,6 +506,8 @@
     ART_NUM tmpngmax;
     ART_NUM tmpabs1st;
     
+    if (ngx == newng)
+	return newng;			/* simple optimisation */
 #ifdef SCAN
     sg_changed_newsrc = TRUE;
 #endif
@@ -883,7 +886,7 @@
 {
     if (data->dat_len == nextrcline-1)
 	data->dat_len = ngnum;
-    else if (data->dat_len > ngnum)
+    else if (data->dat_len >= ngnum)
 	data->dat_len++;
 }
 #endif
--- sgfile.c.084	Wed Mar 31 23:43:22 1993
+++ sgfile.c	Thu Apr  1 00:01:48 1993
@@ -7,6 +7,7 @@
 /* trim the list */
 #include "EXTERN.h"
 #include "common.h"
+#include "only.h"
 #include "intrp.h"
 #include "search.h"
 #include "sgroup.h"
@@ -177,6 +178,19 @@
     (void)sg_new_context();
     sg_contexts[sg_num_contexts-1].title = savestr(title);
     sg_contexts[sg_num_contexts-1].filename = savestr(s);
+
+#ifdef ENFORCE
+    /* If this file is the top-level menu, start with the enforcement list */
+    if (sg_num_contexts == 1) {
+	int i, j;
+	NG_NUM ng;
+	for (i=0; i<maxngtoforce; i++) {
+	    ng = find_ng(ngtoforce[i]);
+	    j = sg_add_ent(1,ngtoforce[i]);
+	    sg_ents[j].groupnum = ng;
+	}
+    }
+#endif /* ENFORCE */
 
 /* Later considerations:
  * 1. Long lines
--- trn.c.084	Thu Apr  1 14:35:46 1993
+++ trn.c	Thu Apr  1 14:47:25 1993
@@ -165,12 +165,14 @@
 		    }
 #endif
 		} else {
-		    bool shoe_fits;	/* newsgroup matches restriction? */
+		    bool shoe_fits;		/* newsgroup wanted or forced? */
+		    bool shoe_really_fits;	/* newsgroup matches restriction? */
 
 		    mode = 'n';
 		    if (toread[ng] >= TR_NONE) {	/* recalc toread? */
 			set_ngname(rcline[ng]);
-			shoe_fits = inlist(ngname);
+			shoe_really_fits = indolist(ngname);
+			shoe_fits = (shoe_really_fits || inforcelist(ngname));
 			if (shoe_fits)
 			    set_toread(ng);
 			if (paranoid) {
@@ -183,7 +185,7 @@
 			}
 		    }
 		    if (toread[ng] < (maxngtodo||special ? TR_NONE : TR_ONE)
-		     || !shoe_fits) {		/* unwanted newsgroup? */
+		     || !shoe_really_fits) {	/* unwanted newsgroup? */
 			ng += direction;	/* then skip it */
 			if (ng < 0) {
 			   ng = 1;
Technical Details
Message-ID: <1phs0i$ih3@lucy.ee.und.ac.za>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!archive!mbox2nntp-news.software.readers.mbox.zip!gmd.de!newsserver.jvnc.net!darwin.sura.net!zaphod.mps.ohio-state.edu!cs.utexas.edu!uunet!psgrain!ee.und.ac.za!tplinfm
References: <1p56qs$pkg@sdl.Warren.MENTORG.COM> <1pakha$35k@genesis.ait.psu.edu> <1pbca3$5b4@lucy.ee.und.ac.za> <1pd5fa$956@lucy.ee.und.ac.za>

Show Full Headers
Complete Article Headers
Message-ID: <1phs0i$ih3@lucy.ee.und.ac.za>
Subject: Re: Force user to read certain groups
Date: Fri, 02 Apr 1993 17:09:38 +0000
From: barrett@lucy.ee.und.ac.za (Alan Barrett)
References: <1p56qs$pkg@sdl.Warren.MENTORG.COM> <1pakha$35k@genesis.ait.psu.edu> <1pbca3$5b4@lucy.ee.und.ac.za> <1pd5fa$956@lucy.ee.und.ac.za>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!archive!mbox2nntp-news.software.readers.mbox.zip!gmd.de!newsserver.jvnc.net!darwin.sura.net!zaphod.mps.ohio-state.edu!cs.utexas.edu!uunet!psgrain!ee.und.ac.za!tplinfm
Newsgroups: news.software.readers
Organization: Elec. Eng., Univ. Natal, Durban, S. Africa
Lines: 298
Distribution: world
NNTP-Posting-Host: lucy.ee.und.ac.za