OSSP CVS Repository

ossp - Difference in ossp-pkg/lmtp2nntp/nntp.c versions 1.4 and 1.5
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/lmtp2nntp/nntp.c 1.4 -> 1.5

--- nntp.c       2001/08/13 06:41:42     1.4
+++ nntp.c       2001/08/13 15:16:32     1.5
@@ -182,7 +182,7 @@
     buf[n] = '\0';          /* string termination */
     if (n == (buflen-1)) 
         return NNTP_ERR_OVERFLOW;
-    fprintf(stderr, "DEBUG: nntp_readline  >>>%s\n", buf);
+    fprintf(stderr, "DEBUG: nntp_readline  <<<%s\n", buf);
     return NNTP_OK;
 }
 
@@ -205,11 +205,57 @@
     nntp_rc_t rc = NNTP_OK;
     char line[NNTP_LINE_MAXLEN];
 
+    /*  RFC 2980
+     *   
+     *  2.3 MODE READER
+     *  MODE READER is used by the client to indicate to the server that it is
+     *  a news reading client.  Some implementations make use of this
+     *  information to reconfigure themselves for better performance in
+     *  responding to news reader commands.  This command can be contrasted
+     *  with the SLAVE command in RFC 977, which was not widely implemented.
+     *  MODE READER was first available in INN.
+     *  
+     *  2.3.1 Responses
+     *  200 Hello, you can post
+     *  201 Hello, you can't post
+     *  
+     *  Research:
+     *  
+     *  < 200 dev16 InterNetNews server INN 2.3.2 ready
+     *  > POST
+     *  < 500 "post" not implemented; try "help".
+     *  > MODE READER
+     *  < 200 dev16 InterNetNews NNRP server INN 2.3.2 ready (posting ok).
+     *  > POST
+     *  < 340 Ok, recommended ID <...>
+     *  
+     *  In other words, INN *requires* the use of "MODE READER".
+     */
+    *line = '\0';
+    strcat(line, "MODE READER");
+    if ((rc = nntp_writeline(nntp, line)) != NNTP_OK)
+        return rc;
+    if ((rc = nntp_readline(nntp, line, sizeof(line))) != NNTP_OK)
+        return rc;
+
+    /*  A 200 response means posting ok, 201 means posting not allowed. We
+     *  don't care about 5xx errors, they simply mean the server doesn't know
+     *  about the RFC2980 "MODE READER" command. But any other response is not
+     *  expected and we treat this as an error.
+     */
+    if (strncmp(line, "201", 3) == 0)
+        return NNTP_ERR_POST;
+    if (   strncmp(line, "200", 3) != 0
+        && strncmp(line, "5"  , 1) != 0
+          )
+        return NNTP_ERR_POST;
+
     /*  check if this server already knows that artice
      *  > STAT <message-id>
      *  < 223 yes, article already known
      *  < 430 no, i don't know the article, yet
      */
+#if 0
     *line = '\0';
     strcat(line, "STAT ");
     strcat(line, msg->cpMsgid);
@@ -220,7 +266,8 @@
     if (strncmp(line, "223", 3) == 0)
         return NNTP_OK;
     if (strncmp(line, "430", 3) != 0)
-        return NNTP_ERR_POSTPERM; //FIXME
+        return NNTP_ERR_POST;
+#endif
 
     /*  post the article
      *  > POST
@@ -235,10 +282,22 @@
      *  > .
      *  < 240 ok, thank you
      *  < 441 duplicate (ok for us)
+     *  
+     *  Research:
+     *  
+     *  < 200 dev16 InterNetNews server INN 2.3.2 ready
+     *  > POST
+     *  [...]
+     *  240 Article posted <...>
+     *  441 435 Duplicate
+     *  441 437 Too old
+     *  441 Duplicate "Newsgroups" header
+     *  441 Required "Subject" header is missing
+     *  
+     *  In other words, INN uses 441 for other status messages as well.
      */
     *line = '\0';
-    strcat(line, "POST ");
-    strcat(line, msg->cpMsgid);
+    strcat(line, "POST");
     if ((rc = nntp_writeline(nntp, line)) != NNTP_OK)
         return rc;
     if ((rc = nntp_readline(nntp, line, sizeof(line))) != NNTP_OK)
@@ -246,33 +305,19 @@
     if (strncmp(line, "xxx", 3) == 0)
         return NNTP_OK;
     if (strncmp(line, "340", 3) != 0)
-        return NNTP_ERR_POSTPERM; //FIXME
+        return NNTP_ERR_POST;
 
-fprintf(stderr, "DEBUG: before write ***%s***(%d)\n", msg->cpMsg, strlen(msg->cpMsg));
-    if ((rc = nntp->io.write(nntp->wfd, msg->cpMsg, strlen(msg->cpMsg))) < 0)
+    if ((rc = nntp->io.write(nntp->wfd, msg->cpMsg, strlen(msg->cpMsg))) < 0) //FIXME while() wrapper around write required
         return NNTP_ERR_SYSTEM;
-fprintf(stderr, "DEBUG: after write, written = %i\n", rc);
 
-    {//DEBUG paragraph
-        int i;
-        char buf[NNTP_LINE_MAXLEN];
-
-        fprintf(stderr, "DEBUG: before writeline\n");
-        if ((rc = nntp_writeline(nntp, "\r\n.\r\nHELP\r\n")) != NNTP_OK);
-        fprintf(stderr, "DEBUG: writeline returned %d\n", rc);
-            
-        fprintf(stderr, "DEBUG: before io.read(%d, ..., %d)\n", nntp->rfd, NNTP_LINE_MAXLEN);
-        i = nntp->io.read(nntp->rfd, &buf, NNTP_LINE_MAXLEN);
-        fprintf(stderr, "DEBUG: io.read = ***%s***, rc = %d\n", buf, i);
-
-
-        for (i=0; i<10; i++) {
     if ((rc = nntp_readline(nntp, line, sizeof(line))) != NNTP_OK)
-        ; //return rc;
+        return rc;
     fprintf(stderr, "DEBUG: answer to post = ***%s***, rc = %s\n", line, nntp_error(nntp, rc));
-        };
-    }
-    return NNTP_OK;
+    if (   (strncmp(line, "240", 3) == 0)
+        || (strncmp(line, "441", 3) == 0)
+          )
+        return NNTP_OK;
+    return NNTP_ERR_POST;
 
 #if 0
             /* check if this server accepts at least one of the newsgroups
@@ -294,6 +339,7 @@
     else if (rc == NNTP_ERR_SYSTEM  ) str = "NNTP: see errno";
     else if (rc == NNTP_ERR_ARG     ) str = "NNTP: invalid argument";
     else if (rc == NNTP_ERR_OVERFLOW) str = "NNTP: buffer overflow";
+    else if (rc == NNTP_ERR_POST    ) str = "NNTP: cannot post message";
     return str;
 }
 

CVSTrac 2.0.1