OSSP CVS Repository

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

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

--- nntp.c       2001/08/07 09:05:55     1.3
+++ nntp.c       2001/08/13 06:41:42     1.4
@@ -182,6 +182,7 @@
     buf[n] = '\0';          /* string termination */
     if (n == (buflen-1)) 
         return NNTP_ERR_OVERFLOW;
+    fprintf(stderr, "DEBUG: nntp_readline  >>>%s\n", buf);
     return NNTP_OK;
 }
 
@@ -193,73 +194,94 @@
         return NNTP_ERR_ARG;
     strncpy(tmp, buf, NNTP_LINE_MAXLEN-3);
     strcat(tmp, "\r\n");
+    fprintf(stderr, "DEBUG: nntp_writeline >>>%s", tmp);
     if (nntp->io.write(nntp->wfd, tmp, strlen(tmp)) < 0)
         return NNTP_ERR_SYSTEM;
     return NNTP_OK;
 }
 
-nntp_rc_t nntp_post(nntp_t *nntp, char *msg)
+nntp_rc_t nntp_post(nntp_t *nntp, msg_t *msg)
 {
     nntp_rc_t rc = NNTP_OK;
     char line[NNTP_LINE_MAXLEN];
 
-    if ((rc = nntp_readline(nntp, line, sizeof(line))) != NNTP_OK)
-        return rc;
-    fprintf(stderr, "READ:<%s>\n", line);
-    if ((rc = nntp_writeline(nntp, "mode reader")) != NNTP_OK)
+    /*  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
+     */
+    *line = '\0';
+    strcat(line, "STAT ");
+    strcat(line, msg->cpMsgid);
+    if ((rc = nntp_writeline(nntp, line)) != NNTP_OK)
         return rc;
-    fprintf(stderr, "WRITE:<mode reader>\n");
     if ((rc = nntp_readline(nntp, line, sizeof(line))) != NNTP_OK)
         return rc;
-    fprintf(stderr, "READ:<%s>\n", line);
-    if ((rc = nntp_writeline(nntp, "quit")) != NNTP_OK)
+    if (strncmp(line, "223", 3) == 0)
+        return NNTP_OK;
+    if (strncmp(line, "430", 3) != 0)
+        return NNTP_ERR_POSTPERM; //FIXME
+
+    /*  post the article
+     *  > POST
+     *  < 340 gimme that thing
+     *  > From: ...
+     *  > Subject: ...
+     *  > Newsgroups: ...
+     *  > Message-ID: <...>
+     *  > [additional headers]
+     *  > 
+     *  > [body with dots escaped]
+     *  > .
+     *  < 240 ok, thank you
+     *  < 441 duplicate (ok for us)
+     */
+    *line = '\0';
+    strcat(line, "POST ");
+    strcat(line, msg->cpMsgid);
+    if ((rc = nntp_writeline(nntp, line)) != NNTP_OK)
         return rc;
-    fprintf(stderr, "WRITE:<quit>\n");
     if ((rc = nntp_readline(nntp, line, sizeof(line))) != NNTP_OK)
         return rc;
-    fprintf(stderr, "READ:<%s>\n", line);
+    if (strncmp(line, "xxx", 3) == 0)
+        return NNTP_OK;
+    if (strncmp(line, "340", 3) != 0)
+        return NNTP_ERR_POSTPERM; //FIXME
+
+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)
+        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;
+    fprintf(stderr, "DEBUG: answer to post = ***%s***, rc = %s\n", line, nntp_error(nntp, rc));
+        };
+    }
+    return NNTP_OK;
 
-#if 0 //FIXME
-    allservers = x; /* total number of servers specified */
-    deliveries = 0; /* counts successful deliveries */
-    for (i=0; i < allservers; i++) {
-        if (post() == NNTP_OK) {
+#if 0
             /* check if this server accepts at least one of the newsgroups
             > GROUP
             < 211 yes, group exists
             < 411 no, group doesn't exist
             */
 
-            /* 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
-            */
-
-            /* post the article
-            > POST
-            < 340 gimme that thing
-            > From: ...
-            > Subject: ...
-            > Newsgroups: ...
-            > Message-ID: <...>
-            > [additional headers]
-            > 
-            > [body with dots escaped]
-            > .
-            < 240 ok, thank you
-            < 441 duplicate (ok for us)
-            */
-        }
-    }
-    if (((mode == DELIVERYMODE_MANY) || (mode == DELIVERYMODE_ONCE)) && (deliveries >= 1))
-        rc = NNTP_OK;
-    else if ((mode == DELIVERYMODE_ALL) && (deliveries == allservers))
-        rc = NNTP_OK
-    else
-        rc = NNTP_ERR_POST;
 #endif
-    return rc;
 }
 
 char *nntp_error(nntp_t *nntp, nntp_rc_t rc)

CVSTrac 2.0.1