[2.4 nnrpd] nntpext patch

greg andruk supersede at india.com
Sat Jul 1 06:29:15 UTC 2000



This brings nnrpd a bit closer to the nntpext draft.

 - Add PAT to command table ; merge CMDxhdr() and CMDxpat() into
   CMDpat().  Put a wee bit of trace info to responses.
 - Add OVER to command table (a synonym for XOVER).
 - Add LIST EXTENSIONS command.


--- article.c.orig	Sat Jul  1 00:29:49 2000
+++ article.c	Sat Jul  1 01:48:42 2000
@@ -908,110 +908,6 @@
     return buff;
 }
 
-/*
-**  XHDR, a common extension.  Retrieve specified header from a
-**  Message-ID or article range.
-*/
-FUNCTYPE CMDxhdr(int ac, char *av[])
-{
-    int		        i;
-    char	        *p;
-    int			Overview;
-    BOOL		IsLines;
-    BOOL		DidReply;
-    ARTRANGE		range;
-    char		buff[SPOOLNAMEBUFF];
-    ARTNUM 		artnum;
-    void                *handle;
-    char                *data;
-    int                 len;
-    TOKEN               token;
-    
-
-    if (!PERMcanread) {
-	Reply("%s\r\n", NOACCESS);
-	return;
-    }
-    IsLines = caseEQ(av[1], "lines");
-
-    /* Message-ID specified? */
-    if (ac == 3 && av[2][0] == '<') {
-	if (!ARTopenbyid(av[2], &artnum)) {
-	    Reply("%d No such article\r\n", NNTP_DONTHAVEIT_VAL);
-	    return;
-	}
-	Reply("%d %ld %s header of article %s.\r\n",
-	   NNTP_HEAD_FOLLOWS_VAL, artnum, av[1], av[2]);
-	p = GetHeader(av[1], IsLines);
-	Printf("%s %s\r\n", av[2], p ? p : "(none)");
-	ARTclose();
-	Printf(".\r\n");
-	return;
-    }
-    
-    if (GRPcount == 0) {
-	Reply("%s\r\n", ARTnotingroup);
-	return;
-    }
-
-    /* Range specified. */
-    if (!CMDgetrange(ac - 1, av + 1, &range, &DidReply)) {
-	if (!DidReply) {
-	    Reply("%d %s fields follow\r\n", NNTP_HEAD_FOLLOWS_VAL,
-		av[1] ? av[1] : "\"\"");
-	    Printf(".\r\n");
-	    return;
-	}
-    }
-
-    /* Is this a header in our overview? */
-    for (Overview = -1, i = 0; i < ARTfieldsize; i++)
-	if (caseEQ(ARTfields[i].Header, av[1])) {
-	    Overview = i;
-	    break;
-	}
-
-    if (Overview < 0 ) {
-        Reply("%d %s fields follow\r\n", NNTP_HEAD_FOLLOWS_VAL, av[1]);
-        for (i = range.Low; i <= range.High && range.High > 0; i++) {
-            if (!ARTopen(i))
-                continue;
-            p = GetHeader(av[1], IsLines);
-            if (!p)
-                continue;
-            (void)sprintf(buff, "%d ", i);
-            SendIOb(buff, strlen(buff));
-            SendIOb(p, strlen(p));
-            SendIOb("\r\n", 2);
-            ARTclose();
-        }
-        SendIOb(".\r\n", 3);
-        PushIOb();
-	return;
-    }
-
-    if ((handle = (void *)OVopensearch(GRPcur, range.Low, range.High)) == NULL) {
-	Reply("%d %s fields follow\r\n.\r\n", NNTP_HEAD_FOLLOWS_VAL, av[1]);
-	return;
-    }
-
-    Reply("%d %s fields follow\r\n", NNTP_HEAD_FOLLOWS_VAL, av[1]);
-    while (OVsearch(handle, &artnum, &data, &len, &token, NULL)) {
-	if (len == 0 || PERMaccessconf->nnrpdcheckart && !ARTinstorebytoken(token))
-	    continue;
-	p = OVERGetHeader(data, Overview);
-	if (!p)
-	    continue;
-	sprintf(buff, "%lu ", artnum);
-	SendIOb(buff, strlen(buff));
-	SendIOb(p, strlen(p));
-	SendIOb("\r\n", 2);	
-    }
-    SendIOb(".\r\n", 3);
-    PushIOb();
-    OVclosesearch(handle);
-}
-
 
 /*
 **  XOVER another extension.  Dump parts of the overview database.
@@ -1154,14 +1050,15 @@
 
 
 /*
-**  XPAT, an uncommon extension.  Print only headers that match the pattern.
+**  XHDR, XPAT and PAT extensions.
 */
 /* ARGSUSED */
-FUNCTYPE CMDxpat(int ac, char *av[])
+FUNCTYPE CMDpat(int ac, char *av[])
 {
     char	        *p;
     int	        	i;
     ARTRANGE		range;
+    BOOL		IsLines;
     BOOL		DidReply;
     char		*header;
     char		*pattern;
@@ -1180,31 +1077,41 @@
     }
 
     header = av[1];
+    IsLines = caseEQ(header, "lines");
+
+    if (ac > 3)
+	pattern = Glom(&av[3]);
+    else
+	pattern = NULL;
 
     /* Message-ID specified? */
-    if (av[2][0] == '<') {
+    if (ac > 2 && av[2][0] == '<') {
 	p = av[2];
 	if (!ARTopenbyid(p, &artnum)) {
 	    Printf("%d No such article.\r\n", NNTP_DONTHAVEIT_VAL);
 	    return;
 	}
-
-	Printf("%d %s matches follow.\r\n", NNTP_HEAD_FOLLOWS_VAL, header);
-	pattern = Glom(&av[3]);
+	Printf("%d %s matches follow (ID)\r\n", NNTP_HEAD_FOLLOWS_VAL, header);
 	if ((text = GetHeader(header, FALSE)) != NULL
-	 && wildmat(text, pattern))
+	    && (!pattern || wildmat(text, pattern)))
 	    Printf("%s %s\r\n", p, text);
 
 	ARTclose();
 	Printf(".\r\n");
-	DISPOSE(pattern);
+	if (pattern)
+	    DISPOSE(pattern);
+	return;
+    }
+
+    if (GRPcount == 0) {
+	Reply("%s\r\n", ARTnotingroup);
 	return;
     }
 
     /* Range specified. */
     if (!CMDgetrange(ac - 1, av + 1, &range, &DidReply)) {
 	if (!DidReply) {
-	    Reply("%d %s matches follow\r\n", NNTP_HEAD_FOLLOWS_VAL,
+	    Reply("%d %s no matches follow (range)\r\n", NNTP_HEAD_FOLLOWS_VAL,
 		av[1] ? av[1] : "\"\"");
 	    Printf(".\r\n");
 	    return;
@@ -1220,13 +1127,12 @@
 
     /* Not in overview, we have to fish headers out from the articles */
     if (Overview < 0 ) {
-        Reply("%d %s matches follow\r\n", NNTP_HEAD_FOLLOWS_VAL, av[1]);
-	pattern = Glom(&av[3]);
+        Reply("%d %s matches follow (art)\r\n", NNTP_HEAD_FOLLOWS_VAL, av[1]);
         for (i = range.Low; i <= range.High && range.High > 0; i++) {
             if (!ARTopen(i))
                 continue;
             p = GetHeader(header, FALSE);
-	    if (p && wildmat(p, pattern)) {
+	    if (p && (!pattern || wildmat(p, pattern))) {
 		sprintf(buff, "%lu ", i);
 		SendIOb(buff, strlen(buff));
 		SendIOb(p, strlen(p));
@@ -1236,23 +1142,23 @@
         }
         SendIOb(".\r\n", 3);
         PushIOb();
-        DISPOSE(pattern);
+	if (pattern)
+	    DISPOSE(pattern);
 	return;
     }
 
     /* Okay then, we can grab values from overview. */
     if ((handle = (void *)OVopensearch(GRPcur, range.Low, range.High)) == NULL) {
-	Reply("%d %s fields follow\r\n.\r\n", NNTP_HEAD_FOLLOWS_VAL, av[1]);
+	Reply("%d %s no matches follow (NOV)\r\n.\r\n", NNTP_HEAD_FOLLOWS_VAL, av[1]);
 	return;
     }	
 	
-    Printf("%d %s matches follow.\r\n", NNTP_HEAD_FOLLOWS_VAL, header);
-    pattern = Glom(&av[3]);
+    Printf("%d %s matches follow (NOV)\r\n", NNTP_HEAD_FOLLOWS_VAL, header);
     while (OVsearch(handle, &artnum, &data, &len, &token, NULL)) {
 	if (len == 0 || PERMaccessconf->nnrpdcheckart && !ARTinstorebytoken(token))
 	    continue;
 	if ((p = OVERGetHeader(data, Overview)) != NULL) {
-	    if (wildmat(p, pattern)) {
+	    if (!pattern || wildmat(p, pattern)) {
 		sprintf(buff, "%lu ", artnum);
 		SendIOb(buff, strlen(buff));
 		SendIOb(p, strlen(p));
@@ -1263,5 +1169,6 @@
     SendIOb(".\r\n", 3);
     PushIOb();
     OVclosesearch(handle);
-    DISPOSE(pattern);
+    if (pattern)
+	DISPOSE(pattern);
 }
--- commands.c.orig	Sun Jun 11 21:26:28 2000
+++ commands.c	Sat Jul  1 01:33:59 2000
@@ -48,6 +48,10 @@
     NULL, _PATH_DISTPATS, FALSE, "distribution patterns",
     "Default distributions in form \"weight:pattern:value\""
 };
+STATIC LISTINFO		INFOextensions = {
+    NULL, NULL, FALSE, "supported extensions",
+    "Supported NNTP extensions"
+};
 STATIC LISTINFO		INFOgroups = {
     NULL, _PATH_NEWSGROUPS, FALSE, "newsgroup descriptions",
     "Descriptions in form \"group description\""
@@ -438,6 +442,12 @@
 	lp = &INFOsubs;
     else if (caseEQ(p, "distrib.pats"))
 	lp = &INFOdistribpats;
+    else if (caseEQ(p, "extensions")) {
+	lp = &INFOextensions;
+	    Reply("%d %s.\r\n", NNTP_LIST_FOLLOWS_VAL, lp->Format);
+	    Printf(" LISTGROUP\r\n OVER\r\n PAT\r\n.\r\n");
+	    return;
+    }
     else if (caseEQ(p, "moderators"))
 	lp = &INFOmoderators;
     else if (caseEQ(p,"motd"))
--- nnrpd.c.orig	Sat Jul  1 00:25:59 2000
+++ nnrpd.c	Sat Jul  1 01:54:36 2000
@@ -99,9 +99,8 @@
 extern FUNCTYPE	CMDnextlast();
 extern FUNCTYPE	CMDpost();
 extern FUNCTYPE	CMDxgtitle();
-extern FUNCTYPE	CMDxhdr();
 extern FUNCTYPE	CMDxover();
-extern FUNCTYPE	CMDxpat();
+extern FUNCTYPE	CMDpat();
 extern FUNCTYPE	CMDxpath();
 extern FUNCTYPE	CMD_unimp();
 #ifdef HAVE_SSL
@@ -148,6 +147,10 @@
 	"newsgroups [YY]yymmdd hhmmss [\"GMT\"|\"UTC\"] [<distributions>]" },
     {	"next",		CMDnextlast,	TRUE,	1,	1,
 	NULL },
+    {	"over",		CMDxover,	TRUE,	1,	2,
+	"[range]" },
+    {	"pat",		CMDpat,		TRUE,	3,	CMDany,
+	"header range|MessageID [pat [morepat...]]" },
     {	"post",		CMDpost,	TRUE,	1,	1,
 	NULL },
     {	"slave",	CMD_unimp,	FALSE,	1,	1,
@@ -156,11 +159,11 @@
 	CMDfetchhelp },
     {	"xgtitle",	CMDxgtitle,	TRUE,	1,	2,
 	"[group_pattern]" },
-    {	"xhdr",		CMDxhdr,	TRUE,	2,	3,
+    {	"xhdr",		CMDpat,		TRUE,	2,	3,
 	"header [range|MessageID]" },
     {	"xover",	CMDxover,	TRUE,	1,	2,
 	"[range]" },
-    {	"xpat",		CMDxpat,	TRUE,	4,	CMDany,
+    {	"xpat",		CMDpat,		TRUE,	4,	CMDany,
 	"header range|MessageID pat [morepat...]" },
     {	"xpath",	CMDxpath,	TRUE,	2,	2,
 	"MessageID" },



More information about the inn-patches mailing list