nntpext update for -current

an unspecified meowbot meowbot at meowing.net
Fri Mar 9 07:38:16 UTC 2001



An ugly, puke-inducing attempt to keep up with nntpext in -current.

lib/wildmat.c: Add wildmat_classic, wildmat without the magic comma and
bang.  This lets XPAT regain its traditional behavior, which seems like the
right thing to do seeing that PAT is dead.

nnrpd/article.c: That do{...}while(0); loop is there to make sure
Glom() garbage gets freed, and returning instead of breaking out of
the loop kinda defeats it.  [had returns there locally, not sure how I
managed to mangle the earlier patch.] I'm not touching the Argify/Glom
whitespace weirdness, it's not helpful to change behavior that's been
there forever, esp. where nnrpd is the de facto standard for this
command.

nnrpd/nnrpd.c: Lose the PAT command and add HDR.

nnrpd/commands.c: Replace the PAT extension with HDR.  The current draft
doesn't fully reflect this change, but the next one will. 

doc/pod/wildmat.pod: Make appropriate disdainful noises about
wildmat_classic.



--- nnrpd/article.c.orig	Thu Mar  8 23:35:47 2001
+++ nnrpd/article.c	Fri Mar  9 00:56:54 2001
@@ -1058,7 +1058,7 @@
 
 
 /*
-**  XHDR, XPAT and PAT extensions.
+**  [X]HDR and XPAT extensions.
 */
 /* ARGSUSED */
 void CMDpat(int ac, char *av[])
@@ -1087,7 +1087,7 @@
     header = av[1];
     IsLines = caseEQ(header, "lines");
 
-    if (ac > 3)
+    if (ac > 3) /* XPAT */
 	pattern = Glom(&av[3]);
     else
 	pattern = NULL;
@@ -1098,22 +1098,22 @@
 	    p = av[2];
 	    if (!ARTopenbyid(p, &artnum)) {
 		Printf("%d No such article.\r\n", NNTP_DONTHAVEIT_VAL);
-		return;
+		break;
 	    }
 	    Printf("%d %s matches follow (ID)\r\n", NNTP_HEAD_FOLLOWS_VAL,
 		   header);
 	    if ((text = GetHeader(header, FALSE)) != NULL
-		&& (!pattern || wildmat(text, pattern)))
+		&& (!pattern || wildmat_classic(text, pattern)))
 		Printf("%s %s\r\n", p, text);
 
 	    ARTclose();
 	    Printf(".\r\n");
-	    return;
+	    break;
 	}
 
 	if (GRPcount == 0) {
 	    Reply("%s\r\n", ARTnotingroup);
-	    return;
+	    break;
 	}
 
 	/* Range specified. */
@@ -1122,7 +1122,7 @@
 		Reply("%d %s no matches follow (range)\r\n",
 		      NNTP_HEAD_FOLLOWS_VAL, header ? header : "\"\"");
 		Printf(".\r\n");
-		return;
+		break;
 	    }
 	}
 
@@ -1141,7 +1141,7 @@
 		if (!ARTopen(i))
 		    continue;
 		p = GetHeader(header, FALSE);
-		if (p && (!pattern || wildmat(p, pattern))) {
+		if (p && (!pattern || wildmat_classic(p, pattern))) {
 		    sprintf(buff, "%lu ", i);
 		    SendIOb(buff, strlen(buff));
 		    SendIOb(p, strlen(p));
@@ -1151,7 +1151,7 @@
 	    }
 	    SendIOb(".\r\n", 3);
 	    PushIOb();
-	    return;
+	    break;
 	}
 
 	/* Okay then, we can grab values from overview. */
@@ -1159,7 +1159,7 @@
 	if (handle == NULL) {
 	    Reply("%d %s no matches follow (NOV)\r\n.\r\n",
 		  NNTP_HEAD_FOLLOWS_VAL, header);
-	    return;
+	    break;
 	}	
 	
 	Printf("%d %s matches follow (NOV)\r\n", NNTP_HEAD_FOLLOWS_VAL,
@@ -1169,7 +1169,7 @@
 		&& !ARTinstorebytoken(token))
 		continue;
 	    if ((p = OVERGetHeader(data, Overview)) != NULL) {
-		if (!pattern || wildmat(p, pattern)) {
+		if (!pattern || wildmat_classic(p, pattern)) {
 		    sprintf(buff, "%lu ", artnum);
 		    SendIOb(buff, strlen(buff));
 		    SendIOb(p, strlen(p));
--- nnrpd/commands.c.orig	Fri Mar  9 00:58:53 2001
+++ nnrpd/commands.c	Fri Mar  9 01:00:04 2001
@@ -448,7 +448,7 @@
     else if (caseEQ(p, "extensions")) {
 	lp = &INFOextensions;
 	    Reply("%d %s.\r\n", NNTP_SLAVEOK_VAL, lp->Format);
-	    Printf(" LISTGROUP\r\n OVER\r\n PAT\r\n.\r\n");
+	    Printf(" HDR\r\n LISTGROUP\r\n OVER\r\n.\r\n");
 	    return;
     }
     else if (caseEQ(p, "moderators"))
--- nnrpd/nnrpd.c.orig	Thu Mar  8 23:35:55 2001
+++ nnrpd/nnrpd.c	Thu Mar  8 23:38:51 2001
@@ -133,6 +133,8 @@
 	NULL },
     {	"group",	CMDgroup,	TRUE,	2,	2,
 	"newsgroup" },
+    {	"hdr",		CMDpat,		TRUE,	3,	3,
+	"header range|MessageID" },
     {	"head",		CMDfetch,	TRUE,	1,	2,
 	CMDfetchhelp },
     {	"help",		CMDhelp,	FALSE,	1,	CMDany,
@@ -155,8 +157,6 @@
 	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,
--- lib/wildmat.c.orig	Thu Mar  8 23:17:47 2001
+++ lib/wildmat.c	Fri Mar  9 01:03:59 2001
@@ -288,10 +288,12 @@
 **  expression matches the text, WILDMAT_FAIL otherwise.  If allowpoison is
 **  set, allow @ to introduce a poison expression (the same as !, but if it
 **  triggers the failed match the routine returns WILDMAT_POISON instead).
+**  If usespecials is false, the special meanings of ! and the comma are
+**  disabled for compatibility with historical wildmat implementations.
 */
 static enum wildmat
 match_expression(const unsigned char *text, const unsigned char *start,
-                 bool allowpoison)
+                 bool allowpoison, bool usespecials)
 {
     const unsigned char *end, *split;
     const unsigned char *p = start;
@@ -312,7 +314,7 @@
     for (; p <= end + 1; p = split + 1) {
         if (allowpoison)
             poison = (*p == '@');
-        reverse = (*p == '!') || poison;
+        reverse = usespecials && (*p == '!') || poison;
         if (reverse)
             p++;
 
@@ -327,7 +329,7 @@
                 while (split <= end && *split != ']')
                     split++;
             }
-            if (*split == ',' && !escaped)
+            if (usespecials && *split == ',' && !escaped)
                 break;
             escaped = (*split == '\\') ? !escaped : false;
         }
@@ -359,7 +361,24 @@
     if (upat[0] == '*' && upat[1] == '\0')
         return true;
     else
-        return (match_expression(utext, upat, false) == WILDMAT_MATCH);
+        return (match_expression(utext, upat, false, true) == WILDMAT_MATCH);
+}
+
+
+/*
+**  User-level routine used for wildmats with legacy behavior
+**  (comma and bang are not special characters).
+*/
+enum wildmat
+wildmat_classic(const char *text, const char *pat)
+{
+    const unsigned char *utext = (const unsigned char *) text;
+    const unsigned char *upat  = (const unsigned char *) pat;
+
+    if (upat[0] == '*' && upat[1] == '\0')
+        return true;
+    else
+        return (match_expression(utext, upat, false, false) == WILDMAT_MATCH);
 }
 
 
@@ -375,5 +394,5 @@
     if (upat[0] == '*' && upat[1] == '\0')
         return WILDMAT_MATCH;
     else
-        return match_expression(utext, upat, true);
+        return match_expression(utext, upat, true, true);
 }
--- doc/pod/wildmat.pod.orig	Thu Mar  8 23:39:42 2001
+++ doc/pod/wildmat.pod	Thu Mar  8 23:54:35 2001
@@ -8,6 +8,8 @@
 
 B<bool wildmat(const char *>I<text>B<, const char *>I<pattern>B<);>
 
+B<bool wildmat_classic(const char *>I<text>B<, const char *>I<pattern>B<);>
+
 B<enum wildmat wildmat_poison(const char *>I<text>B<,
 const char *>I<pattern>B<);>
 
@@ -23,13 +25,19 @@
 should work as expected unless the ISO 8859-1 text contains valid UTF-8
 sequences, which thankfully is somewhat rare.)
 
-B<wildmat_poison> works similarly, except that C<@> as the first character
-of one of the patterns in the expression (see below) "poisons" the match
-if it matches.  B<wildmat_poison> returns B<WILDMAT_MATCH> if the
-expression matches the text, B<WILDMAT_FAIL> if it doesn't, and
-B<WILDMAT_POISON> if the expression doesn't match because a poisoned
-pattern matched the text.  These enumeration constants are defined in the
-B<libinn.h> header.
+B<wildmat_classic> is the same as B<wildmat>, with the exception that C<,>
+and C<!> lose their special meanings.  This function exists solely to
+support legacy interfaces like NNTP's XPAT command, and should be avoided
+when implementing new features.
+
+B<wildmat_poison> works similarly to <wildmat>, except that C<@> as the
+first character of one of the patterns in the expression (see below)
+"poisons" the match if it matches.  B<wildmat_poison> returns
+B<WILDMAT_MATCH> if the expression matches the text, B<WILDMAT_FAIL> if it
+doesn't, and B<WILDMAT_POISON> if the expression doesn't match because a
+poisoned pattern matched the text.  These enumeration constants are defined
+in the B<libinn.h> header.
+
 
 =head1 WILDMAT EXPRESSIONS
 


More information about the inn-patches mailing list