[leafnode-list] LIST filtering

Matthew Parry mettw at mettw.homelinux.net
Mon Jul 24 10:43:15 CEST 2006



I'm not sure if you would want to make this patch a standard part
or leafnode2 or not, so I made it's compilation conditional on
GROUPINFO_FILTERS being defined.

My upstream server serves up over 35,000 newsgroups, most of
them foreign, which makes it very hard to find anything
usefull on USENET.  The following patch allows you to filter
the output of a LIST command by defining the environment 
variable LEAFNODE_LIST to be a space seperated list of wildmat
patterns.  If a newsgroup matches any of the patterns then it
will be printed out at a LIST command.

-- 

Matthew Parry

-
"There now, didn't I tell you to keep a good count?  Well,
there's an end of the story.  God knows there's no going on
with it now." - Sancho Panza.



--- leafnode-2.0.0.alpha20060711a/nntpd.c	2006-06-09 08:51:09.000000000 +1000
+++ nntpd.c	2006-07-24 18:35:22.444631152 +1000
@@ -797,6 +797,43 @@
 
 /* LIST ACTIVE if what==0, else LIST NEWSGROUPS */
 static void printlist(const struct newsgroup *ng, const int what) {
+
+	/* There are 35,000 groups in my groupinfo file and
+	 * this makes it very hard to find usefull groups.
+	 * This optional section will filter out any group
+	 * that matches a wildmat pattern in the env var
+	 * LEAFNODE_LIST
+	 *
+	 * Matthew Parry <mettw at yahoo.com.au>
+	 */
+	
+#ifdef GROUPINFO_FILTERING
+
+{
+	static struct stringlisthead *groups_to_filter = NULL;
+	static int filter_groups = TRUE;
+
+	if(filter_groups){
+
+		if(!groups_to_filter){
+			char *filter_patterns = getenv("LEAFNODE_LIST");
+
+			if(!filter_patterns || strlen(filter_patterns) == 0){
+				filter_groups = FALSE;
+				printlist(ng, what); /* Don't like goto */
+				return;
+			}
+
+			groups_to_filter = cmdlinetolist(filter_patterns);
+			
+		}
+
+		if(matchlist(groups_to_filter->head, ng->name) == NULL)
+			return;
+	}
+}
+#endif
+
     if (what) {
 	printf("%s\t%s", ng->name, ng->desc ? ng->desc : "-x-");
 	if (ng->status == 'm' && (!ng->desc || !strstr(ng->desc, " (Moderated)")))



More information about the leafnode-list mailing list