INN commit: trunk (include/nntp.h innd/nc.c)

INN Commit rra at isc.org
Fri Oct 16 19:01:40 UTC 2009


    Date: Friday, October 16, 2009 @ 12:01:39
  Author: iulius
Revision: 8662

Use integers instead of strings for NNTP response codes
(HEAD and STAT).

Modified:
  trunk/include/nntp.h
  trunk/innd/nc.c

----------------+
 include/nntp.h |    3 ---
 innd/nc.c      |   41 ++++++++++++++++++++++++++---------------
 2 files changed, 26 insertions(+), 18 deletions(-)

Modified: include/nntp.h
===================================================================
--- include/nntp.h	2009-10-16 17:57:19 UTC (rev 8661)
+++ include/nntp.h	2009-10-16 19:01:39 UTC (rev 8662)
@@ -31,14 +31,11 @@
 #define NNTP_LIST_FOLLOWS		"215"
 #define NNTP_HELP_FOLLOWS		"100 Legal commands"
 #define NNTP_ARTICLE_FOLLOWS		"220"
-#define NNTP_HEAD_FOLLOWS		"221"
 #define NNTP_POSTOK			"200"
 #define NNTP_REJECTIT_EMPTY		"437 Empty article"
-#define NNTP_DONTHAVEIT			"430"
 #define NNTP_RESENDIT_LATER             "436 Retry later"
 #define NNTP_POSTEDOK			"240 Article posted"
 #define NNTP_SENDIT			"335"
-#define NNTP_SYNTAX_USE			"501 Bad command use"
 #define NNTP_BAD_SUBCMD			"501 Bad subcommand"
 #define NNTP_NOTINGROUP			"412 Not in a newsgroup"
 #define NNTP_NOSUCHGROUP		"411 No such group"

Modified: innd/nc.c
===================================================================
--- innd/nc.c	2009-10-16 17:57:19 UTC (rev 8661)
+++ innd/nc.c	2009-10-16 19:01:39 UTC (rev 8662)
@@ -284,7 +284,7 @@
 
 
 /*
-**  The "head" command.
+**  The HEAD command.
 */
 static void
 NChead(CHANNEL *cp)
@@ -295,12 +295,14 @@
     char                *buff = NULL;
 
     /* Snip off the Message-ID. */
-    for (p = cp->In.data + cp->Start + strlen("head"); ISWHITE(*p); p++)
+    for (p = cp->In.data + cp->Start + strlen("HEAD"); ISWHITE(*p); p++)
 	continue;
     cp->Start = cp->Next;
 
     if (!ARTidok(p)) {
-        NCwritereply(cp, NNTP_SYNTAX_USE);
+        xasprintf(&buff, "%d Syntax error in message-ID", NNTP_ERR_SYNTAX);
+        NCwritereply(cp, buff);
+        free(buff);
         syslog(L_NOTICE, "%s bad_messageid %s", CHANname(cp), MaxLength(p, p));
 	return;
     }
@@ -317,29 +319,32 @@
 
     /* Get the article token and retrieve it. */
     if (!HISlookup(History, p, NULL, NULL, NULL, &token)) {
-	NCwritereply(cp, NNTP_DONTHAVEIT);
+        xasprintf(&buff, "%d No such article", NNTP_FAIL_NOTFOUND);
+        NCwritereply(cp, buff);
+        free(buff);
 	return;
     }
     if ((art = SMretrieve(token, RETR_HEAD)) == NULL) {
-	NCwritereply(cp, NNTP_DONTHAVEIT);
+        xasprintf(&buff, "%d No such article", NNTP_FAIL_NOTFOUND);
+        NCwritereply(cp, buff);
+        free(buff);
 	return;
     }
 
     /* Write it. */
-    WCHANappend(cp, NNTP_HEAD_FOLLOWS, strlen(NNTP_HEAD_FOLLOWS));
-    WCHANappend(cp, " 0 ", 3);
-    WCHANappend(cp, p, strlen(p));
-    WCHANappend(cp, NCterm, strlen(NCterm));
+    xasprintf(&buff, "%d 0 %s%s", NNTP_OK_HEAD, p, NCterm);
+    WCHANappend(cp, buff, strlen(buff));
     WCHANappend(cp, art->data, art->len);
 
     /* Write the terminator. */
     NCwritereply(cp, NCdot);
+    free(buff);
     SMfreearticle(art);
 }
 
 
 /*
-**  The "stat" command.
+**  The STAT command.
 */
 static void
 NCstat(CHANNEL *cp)
@@ -350,12 +355,14 @@
     char		*buff = NULL;
 
     /* Snip off the Message-ID. */
-    for (p = cp->In.data + cp->Start + strlen("stat"); ISWHITE(*p); p++)
+    for (p = cp->In.data + cp->Start + strlen("STAT"); ISWHITE(*p); p++)
 	continue;
     cp->Start = cp->Next;
 
     if (!ARTidok(p)) {
-        NCwritereply(cp, NNTP_SYNTAX_USE);
+        xasprintf(&buff, "%d Syntax error in message-ID", NNTP_ERR_SYNTAX);
+        NCwritereply(cp, buff);
+        free(buff);
         syslog(L_NOTICE, "%s bad_messageid %s", CHANname(cp), MaxLength(p, p));
 	return;
     }
@@ -373,11 +380,15 @@
     /* Get the article filenames; open the first file (to make sure
      * the article is still here). */
     if (!HISlookup(History, p, NULL, NULL, NULL, &token)) {
-	NCwritereply(cp, NNTP_DONTHAVEIT);
+        xasprintf(&buff, "%d No such article", NNTP_FAIL_NOTFOUND);
+        NCwritereply(cp, buff);
+        free(buff);
 	return;
     }
     if ((art = SMretrieve(token, RETR_STAT)) == NULL) {
-	NCwritereply(cp, NNTP_DONTHAVEIT);
+        xasprintf(&buff, "%d No such article", NNTP_FAIL_NOTFOUND);
+        NCwritereply(cp, buff);
+        free(buff);
 	return;
     }
     SMfreearticle(art);
@@ -908,7 +919,7 @@
 	tmpstr = xmalloc(i - cp->Start + 1);
 	memcpy(tmpstr, bp->data + cp->Start, i - cp->Start);
 	tmpstr[i - cp->Start] = '\0';
-	
+
 	syslog(L_NOTICE, "%s bad_command %s", CHANname(cp),
 	  MaxLength(tmpstr, tmpstr));
 	free(tmpstr);




More information about the inn-committers mailing list