OSSP CVS Repository

ossp - Check-in [666]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 666
Date: 2001-Aug-14 10:15:25 (local)
2001-Aug-14 08:15:25 (UTC)
User:thl
Branch:
Comment: cleanup msg.[ch], moved tracing to trace.[ch], added target to Makefile, added -t switch in lmtp2nntp.[c|pod], incorporated tracing into lmtp.[ch] and nntp.[ch], run.sh now using new tracing option
Tickets:
Inspections:
Files:
ossp-pkg/lmtp2nntp/lmtp.c      1.8 -> 1.9     6 inserted, 4 deleted
ossp-pkg/lmtp2nntp/lmtp.h      1.6 -> 1.7     1 inserted, 0 deleted
ossp-pkg/lmtp2nntp/lmtp2nntp.c      1.15 -> 1.16     23 inserted, 68 deleted
ossp-pkg/lmtp2nntp/lmtp2nntp.pod      1.4 -> 1.5     4 inserted, 4 deleted
ossp-pkg/lmtp2nntp/msg.c      1.2 -> 1.3     60 inserted, 72 deleted
ossp-pkg/lmtp2nntp/msg.h      1.1 -> 1.2     5 inserted, 5 deleted
ossp-pkg/lmtp2nntp/nntp.c      1.5 -> 1.6     5 inserted, 5 deleted
ossp-pkg/lmtp2nntp/test/run.sh      1.2 -> 1.3     4 inserted, 4 deleted
ossp-pkg/lmtp2nntp/trace.c      added-> 1.1
ossp-pkg/lmtp2nntp/trace.h      added-> 1.1

ossp-pkg/lmtp2nntp/lmtp.c 1.8 -> 1.9

--- lmtp.c       2001/08/01 07:07:55     1.8
+++ lmtp.c       2001/08/14 08:15:25     1.9
@@ -102,11 +102,13 @@
         return NULL;
 
     if (io == NULL) {
-        lmtp->io.read  = read;
-        lmtp->io.write = write;
+        lmtp->io.select = select;
+        lmtp->io.read   = read;
+        lmtp->io.write  = write;
     } else {
-        lmtp->io.read  = io->read  ? io->read  : read;
-        lmtp->io.write = io->write ? io->write : write;
+        lmtp->io.select = io->select ? io->select : select;
+        lmtp->io.read   = io->read   ? io->read   : read;
+        lmtp->io.write  = io->write  ? io->write  : write;
     }
 
     lmtp->rl.rl_cnt = 0;


ossp-pkg/lmtp2nntp/lmtp.h 1.6 -> 1.7

--- lmtp.h       2001/07/25 19:51:12     1.6
+++ lmtp.h       2001/08/14 08:15:25     1.7
@@ -39,6 +39,7 @@
 typedef struct lmtp_st lmtp_t;
 
 typedef struct {
+    int     (*select)(int, fd_set *, fd_set *, fd_set *, struct timeval *);
     ssize_t (*read)(int, void *, size_t);
     ssize_t (*write)(int, const void *, size_t);
 } lmtp_io_t;


ossp-pkg/lmtp2nntp/lmtp2nntp.c 1.15 -> 1.16

--- lmtp2nntp.c  2001/08/13 15:16:32     1.15
+++ lmtp2nntp.c  2001/08/14 08:15:25     1.16
@@ -25,6 +25,7 @@
 #include "nntp.h"
 #include "sa.h"
 #include "msg.h"
+#include "trace.h"
 
 #ifndef FALSE
 #define FALSE (1 != 1)
@@ -42,9 +43,6 @@
 
 extern void lmtp_debug_dumplmtp(lmtp_t *lmtp);
 
-static ssize_t trace_read(int d, void *buf, size_t nbytes);
-static ssize_t trace_write(int d, const void *buf, size_t nbytes);
-
 static lmtp_rc_t lmtp_cb_lhlo   (lmtp_t *lmtp, lmtp_io_t *io, lmtp_req_t *req, void *ctx);
 static lmtp_rc_t lmtp_cb_mail   (lmtp_t *lmtp, lmtp_io_t *io, lmtp_req_t *req, void *ctx);
 static lmtp_rc_t lmtp_cb_rcpt   (lmtp_t *lmtp, lmtp_io_t *io, lmtp_req_t *req, void *ctx);
@@ -93,35 +91,6 @@
 };
 
 /*
- * tracing
- */
-ssize_t trace_read(int d, void *buf, size_t nbytes)
-{
-    ssize_t rc;
-    int tracefile;
-
-    rc = read(d, buf, nbytes);
-    if ((tracefile = open("/tmp/t", O_CREAT|O_WRONLY|O_APPEND, 0664)) != -1) {
-        write(tracefile, buf, rc);
-        close(tracefile);
-    }
-    return rc;
-}
-
-ssize_t trace_write(int d, const void *buf, size_t nbytes)
-{
-    ssize_t rc;
-    int tracefile;
-
-    rc = write(d, buf, nbytes);
-    if ((tracefile = open("/tmp/t", O_CREAT|O_WRONLY|O_APPEND, 0664)) != -1) {
-        write(tracefile, buf, rc);
-        close(tracefile);
-    }
-    return rc;
-}
-
-/*
  * print usage information
  */
 static void usage(char *command)
@@ -176,6 +145,7 @@
     initsession(&ctx->session);
     ctx->msg = NULL;
 
+#if 0
     {
         char buf[1000];
         int bufused = 0;
@@ -188,9 +158,10 @@
             close(tracefile);
         }
     }
+#endif
 
     /* read in the arguments */
-    while ((i = getopt(argc, argv, "g:h:tv")) != -1) {
+    while ((i = getopt(argc, argv, "g:h:t:v")) != -1) {
         switch (i) {
             case 'g': /* -g groupmode */
                 if      (strcasecmp(optarg, "arg") == 0)
@@ -247,6 +218,8 @@
                 break;
             case 't': // -t (tracing)
                 ctx->option_tracing = TRUE;
+                trace_read (-1, optarg, 0);
+                trace_write(-1, optarg, 0);
                 break;
             case 'v': // -v (verbose)
                 ctx->option_verbose = TRUE;
@@ -265,9 +238,10 @@
             argz_add(&ctx->azGroups, &ctx->asGroups, argv[i]);
 
     /* initialize LMTP context */
-    lmtp_io.read  = trace_read;
-    lmtp_io.write = trace_write;
-    if ((lmtp = lmtp_create(STDIN_FILENO, STDOUT_FILENO, &lmtp_io)) == NULL) {
+    lmtp_io.select = NULL;
+    lmtp_io.read   = trace_read;
+    lmtp_io.write  = trace_write;
+    if ((lmtp = lmtp_create(STDIN_FILENO, STDOUT_FILENO, ctx->option_tracing != TRUE ? NULL : &lmtp_io)) == NULL) {
         fprintf(stderr, "%s:Error: Unable to initialize LMTP library\n", progname);
         exit(ERR_EXECUTION);
     }
@@ -329,6 +303,11 @@
     char str[STDSTRLEN];
     int bOk;
     int i;
+    nntp_io_t nntp_io;
+
+    nntp_io.select = NULL;
+    nntp_io.read   = trace_read;
+    nntp_io.write  = trace_write;
 
     if (ctx->session.lhlo_seen == TRUE) {
         res.statuscode = "503";
@@ -360,15 +339,16 @@
     do {
         bOk = TRUE;
         if (connect(ctx->ns[i].s, ctx->ns[i].sa->sa_buf, ctx->ns[i].sa->sa_len) < 0) {
-            fprintf(stderr, "DEBUG: connect failed: %s\n", strerror(errno));
+            //fprintf(stderr, "DEBUG: connect failed: %s\n", strerror(errno));
             bOk = FALSE;
         }
-        if (bOk && ((ctx->ns[i].nntp = nntp_create(ctx->ns[i].s, ctx->ns[i].s, NULL)) == NULL)) {
-            fprintf(stderr, "DEBUG: nntp_create failed: %s\n", strerror(errno));
+        if (bOk && ((ctx->ns[i].nntp = nntp_create(ctx->ns[i].s, ctx->ns[i].s, 
+                                                   ctx->option_tracing != TRUE ? NULL : &nntp_io)) == NULL)) {
+            //fprintf(stderr, "DEBUG: nntp_create failed: %s\n", strerror(errno));
             bOk = FALSE;
         }
         if (bOk && ((rc = nntp_init(ctx->ns[i].nntp)) != NNTP_OK)) {
-            fprintf(stderr, "DEBUG: nntp_init failed: %s\n", nntp_error(ctx->ns[i].nntp, rc));
+            //fprintf(stderr, "DEBUG: nntp_init failed: %s\n", nntp_error(ctx->ns[i].nntp, rc));
             bOk = FALSE;
         }
         if (bOk)
@@ -595,7 +575,7 @@
      */
 
     if (ctx->option_groupmode == GROUPMODE_ENVELOPE) {
-        // fprintf(stderr, "DEBUG: before transform cp=***%s***\n", cp);
+        //fprintf(stderr, "DEBUG: before transform cp=***%s***\n", cp);
         if (!str_parse(cp, "m/^.+?\\+(.+)?@.+$/i", &group)) { //FIXME >=2 * @
             res.statuscode = "550";
             res.dsncode    = "5.1.1";
@@ -603,7 +583,7 @@
             lmtp_response(lmtp, &res);
             return LMTP_OK;
         }
-        // fprintf(stderr, "DEBUG: after  transform group=***%s***\n", group);
+        //fprintf(stderr, "DEBUG: after  transform group=***%s***\n", group);
         //FIXME do additional transform and checking
         if (0) {
             res.statuscode = "550";
@@ -691,10 +671,6 @@
         }
     }
 
-#if 0
-    fprintf(stderr, "DEBUG: calling msg_split();\n");
-    fprintf(stderr, "DEBUG: msg_split() returned %s\n", msg_error(ctx->msg, msg_split(ctx->msg)));
-#endif
     if (msg_split(ctx->msg) != MSG_OK) {
         while ((rcpt = argz_next(ctx->msg->azRcpt, ctx->msg->asRcpt, rcpt)) != NULL) {
             res.statuscode = "500";
@@ -705,30 +681,9 @@
         }
     }
 
-#if 0
-    { //FIXME just a debug paragraph
-        char *cp;
-        cp = NULL;
-        while((cp = argz_next(ctx->azGroups, ctx->asGroups, cp)) != NULL)
-            fprintf(stderr, "DEBUG: lmtp Groups: ***%s***\n", cp);
-    }
-#endif
     ctx->msg->azNewsgroups = ctx->azGroups;
     ctx->msg->asNewsgroups = ctx->asGroups;
-#if 0
-    { //FIXME just a debug paragraph
-        char *cp;
-        cp = NULL;
-        while((cp = argz_next(ctx->msg->azNewsgroups, ctx->msg->asNewsgroups, cp)) != NULL)
-            fprintf(stderr, "DEBUG: article Newsgroups: ***%s***\n", cp);
-        fprintf(stderr, "DEBUG: article Message-ID: ***%s***\n", ctx->msg->cpMsgid);
-    }
-#endif
 
-#if 0
-    fprintf(stderr, "DEBUG: calling msg_join();\n");
-    fprintf(stderr, "DEBUG: msg_join()  returned %s\n", msg_error(ctx->msg, msg_join(ctx->msg)));
-#endif
     if (msg_join(ctx->msg) != MSG_OK) {
         while ((rcpt = argz_next(ctx->msg->azRcpt, ctx->msg->asRcpt, rcpt)) != NULL) {
             res.statuscode = "500";
@@ -741,7 +696,7 @@
 
     bSuccess = FALSE;
     for (i = 0; i < ctx->nsc; i++) {
-        fprintf(stderr, "DEBUG: trying service %s\n", ctx->ns[i].h);
+        //fprintf(stderr, "DEBUG: trying service %s\n", ctx->ns[i].h);
         if (nntp_post(ctx->ns[i].nntp, ctx->msg) == NNTP_OK)
             bSuccess = TRUE;
     }


ossp-pkg/lmtp2nntp/lmtp2nntp.pod 1.4 -> 1.5

--- lmtp2nntp.pod        2001/08/07 09:05:55     1.4
+++ lmtp2nntp.pod        2001/08/14 08:15:25     1.5
@@ -16,7 +16,7 @@
 [B<-l> I<logtarget>]
 [B<-h> I<host>[I<:port>]]
 [B<-g> I<groupmode>]
-[B<-t>]
+[B<-t> I<tracefile>]
 [B<-v>]
 I<newsgroup> 
 [I<newsgroup> ...]
@@ -88,10 +88,10 @@
 these modes the command line arguments are filters representing allowed
 groups. Filters can be specified as wildmat's.
 
-=item B<-t>
+=item B<-t> I<tracefile>
 
-Enable LMTP protocol tracing in logfile. When using C<syslog:> these messages
-are logged with C<debug> level.
+Enable LMTP and NNTP protocol tracing into tracefile. When using C<syslog:>
+these messages are logged with C<debug> level.
 
 =item B<-v>
 


ossp-pkg/lmtp2nntp/msg.c 1.2 -> 1.3

--- msg.c        2001/08/13 15:16:32     1.2
+++ msg.c        2001/08/14 08:15:25     1.3
@@ -12,17 +12,16 @@
     if ((msg = (msg_t *)malloc(sizeof(msg_t))) == NULL)
         return NULL;
 
+    msg->cpMsg = NULL;
+    msg->azHeaders = NULL;
+    msg->asHeaders = 0;
+    msg->cpBody = NULL;
+    msg->cpMsgid = NULL;
     msg->mail_from = NULL;
     msg->azRcpt = NULL;
     msg->asRcpt = 0;
     msg->azNewsgroups = NULL;
     msg->asNewsgroups = 0;
-    msg->azHeaders = NULL;
-    msg->asHeaders = 0;
-    msg->cpMsg = NULL;
-    msg->cpHeaders = NULL;
-    msg->cpBody = NULL;
-    msg->cpMsgid = NULL;
 
     return msg;
 }
@@ -32,29 +31,32 @@
     if (msg == NULL)
         return;
                                              //FIXME what about non-graceful aborts?
+    if (msg->cpMsg != NULL)
+        free(msg->cpMsg);
+    if (msg->azHeaders != NULL)
+        free(msg->azHeaders);
+    if (msg->cpBody != NULL)
+        free(msg->cpBody);
+    if (msg->cpMsgid != NULL)
+        free(msg->cpMsgid);
     if (msg->mail_from != NULL)
         free(msg->mail_from);
     if (msg->azRcpt != NULL)
         free(msg->azRcpt);
-    if (msg->azHeaders != NULL)
-        free(msg->azHeaders);
     if (msg->azNewsgroups != NULL)
         free(msg->azNewsgroups);
-    if (msg->cpMsg != NULL)
-        free(msg->cpMsg);
-    if (msg->cpHeaders != NULL)
-        free(msg->cpHeaders);
-    if (msg->cpBody != NULL)
-        free(msg->cpBody);
+
     free(msg);
+    return;
 }
 
 msg_rc_t msg_split(msg_t *msg)
 {
     char        *cpName;
     char        *cpValue;
-    char        *cpRem;
+    char        *cpRem;     /* Remainder */
     char        *cp;
+    char        *cpHeaders;
 
     /* INPUTS
      *
@@ -65,12 +67,12 @@
      *
      * OUTPUTS
      *
-     * msg->azHeaders, msg->asHeaders
-     * contains the headers in argz format, one logical '\0'-terminated line
-     * per header which might be wrapped into multiple '\n'-ended physical
-     * lines. The "To:" and "Cc:" headers are silently. The "Newsgroups:" and
-     * "Message-ID" headers are removed and their values are stored in
-     * separate structures (see below).
+     * msg->azHeaders, msg->asHeaders contains the headers in argz format, one
+     * logical '\0'-terminated line per header which might be wrapped into
+     * multiple '\n'-ended physical lines. The "From " envelope, "To:" and
+     * "Cc:" headers are removed silently. The "Newsgroups:" and "Message-ID"
+     * headers are removed and their values are stored in separate structures
+     * (see below).
      *
      * msg->cpBody
      * contains the unmodified body of the message, '\0'-terminated, no
@@ -85,25 +87,25 @@
      */
 
     /* split message into header and body */
-    if (!str_parse(msg->cpMsg, "m/((?:.*?)\\n)\\n(.*)$/s", &msg->cpHeaders, &msg->cpBody))
+    if (!str_parse(msg->cpMsg, "m/((?:.*?)\\n)\\n(.*)$/s", &cpHeaders, &msg->cpBody))
         return MSG_ERR_SPLITSPLITBODY;
 
     /* replace envelope From w/o colon by X-F: pseudotag. This eliminates the
      * special case of having one header, which is really an embedded
-     * envelope, not ending with a colon while all other do. After splitting
+     * envelope, not ending with a colon while all others do. After splitting
      * headers into name and value pairs this action is reversed.
      */
-    if (strlen(msg->cpHeaders) < 4)
+    if (strlen(cpHeaders) < 4)
         return MSG_ERR_SPLITLEN;
-    if (strncasecmp(msg->cpHeaders, "From", 4) != 0)
+    if (strncasecmp(cpHeaders, "From", 4) != 0)
         return MSG_ERR_SPLITMISSINGFROM;
-    memcpy(msg->cpHeaders, "X-F:", 4);
+    memcpy(cpHeaders, "X-F:", 4);
 
     /* unwrap header lines */
     //FIXME poor man's s///g simulator as current str library doesn't support //global substitution
-    while (str_parse(msg->cpHeaders, "s/(.*?)\\n[ \\t]+(.*)/$1 $2/s", &cpRem)) {
-        free(msg->cpHeaders);
-        msg->cpHeaders = cpRem;
+    while (str_parse(cpHeaders, "s/(.*?)\\n[ \\t]+(.*)/$1 $2/s", &cpRem)) {
+        free(cpHeaders);
+        cpHeaders = cpRem;
     }
 
     /* split header lines into names and values */
@@ -111,9 +113,9 @@
     //FIXME - fix bug "not" [^...] working
     //FIXME - improve str_parse(foo, "...", &foo) should free foo() on it's own
     //FIXME - add "global" in s/search/replace/g (see above "unwrap hader lines")
-    while (str_parse(msg->cpHeaders, "m/^([\\w-]+?:)[ \\t]*(.*?)[ \\t]*\\n(.*)/s", &cpName, &cpValue, &cpRem)) {
-        free(msg->cpHeaders);
-        msg->cpHeaders = cpRem;
+    while (str_parse(cpHeaders, "m/^([\\w-]+?:)[ \\t]*(.*?)[ \\t]*\\n(.*)/s", &cpName, &cpValue, &cpRem)) {
+        free(cpHeaders);
+        cpHeaders = cpRem;
         argz_add(&msg->azHeaders, &msg->asHeaders, cpName);
         argz_add(&msg->azHeaders, &msg->asHeaders, cpValue);
     }
@@ -187,9 +189,10 @@
     int          i;
     char        *cpCut;
     char        *cpWrap;
-    char        *cpNew;
     char         c;
+    char         cOld;
     int          n;
+    char        *cpHeaders;
 
     /* verify asNewsgroups */
     if (msg->azNewsgroups == NULL)
@@ -211,10 +214,12 @@
 
     /* merge name/value pairs into single string */
     argz_add(&msg->azHeaders, &msg->asHeaders, ""); /* append empty string */
-    if ((aHeaders = (char **)malloc((argz_count(msg->azHeaders,
-        msg->asHeaders) + 1) * sizeof(char *))) == NULL)
-        exit(1); //FIXME
+    if ((aHeaders = (char **)malloc((argz_count(msg->azHeaders, msg->asHeaders) + 1) * sizeof(char *))) == NULL)
+        return MSG_ERR_MEM;
     argz_extract(msg->azHeaders, msg->asHeaders, aHeaders);
+    /* replace the trailing '\0', which is *(cp-1) of the predecessor, with a
+     * space at every second string. Break action when terminating NULL string
+     * is detected */
     i=0;
     while(1) {
         if ((cp = aHeaders[++i]) == NULL)
@@ -222,13 +227,10 @@
         *(cp-1) = ' ';
         if ((cp = aHeaders[++i]) == NULL)
             break;
-        // *(cp-1) = '\n';
     }
+    free(aHeaders);
 
     /* fold headers */
-//FIXME where to place this defines best
-#define WRAPAT 120
-#define WRAPUSING "\n    "
     cp = NULL;
     while ((cp = argz_next(msg->azHeaders, msg->asHeaders, cp)) != NULL) {
         if (strlen(cp) >= WRAPAT) {
@@ -244,12 +246,12 @@
                 //FIXME 1.) continue searching downwards skipping all whitespaces and 2.) as we know the length replace str_dup/ strcat/ free with strncat only
                 if (cpWrap == NULL) {
                     if ((cpWrap = (char *)malloc(strlen(cpCut)+strlen(WRAPUSING)+1)) == NULL)
-                        exit(1); //FIXME
+                        return MSG_ERR_MEM;
                     *cpWrap = '\0';
                 }
                 else {
                     if ((cpWrap = (char *)realloc(cpWrap, strlen(cpWrap)+strlen(cpCut)+strlen(WRAPUSING)+1)) == NULL)
-                        exit(1); //FIXME
+                        return MSG_ERR_MEM;
                     strcat(cpWrap, WRAPUSING);
                 }
                 strcat(cpWrap, cpCut);
@@ -260,7 +262,7 @@
             cpRem += i;
             if (strlen(cpRem) > 0) {
                 if ((cpWrap = (char *)realloc(cpWrap, strlen(cpWrap)+strlen(cpRem)+strlen(WRAPUSING)+1)) == NULL)
-                    exit(1); //FIXME
+                        return MSG_ERR_MEM;
                 strcat(cpWrap, WRAPUSING);
                 strcat(cpWrap, cpRem);
             }
@@ -271,28 +273,7 @@
     }
 
     argz_stringify(msg->azHeaders, msg->asHeaders, '\n');
-    msg->cpHeaders = msg->azHeaders;
-
-    if (argz_create_sep(msg->cpBody, '\n', &msg->azBody, &msg->asBody) != 0)
-        return MSG_ERR_MEM;
-
-    /* escape dots at the beginning of each line */
-    cp = NULL;
-    while ((cp =argz_next(msg->azBody, msg->asBody, cp)) != NULL) {
-        if (*cp == '.') {
-            if ((cpNew = malloc(strlen(cp) + 1)) == NULL)
-                return MSG_ERR_MEM;
-            *cpNew = '.';
-            cpNew++;
-            *cpNew = '\0';
-            strcat(cpNew, cp);
-            argz_delete(&msg->azBody, &msg->asBody, cp);
-            argz_insert(&msg->azBody, &msg->asBody, cp, cpNew);
-        }
-    }
-
-    argz_stringify(msg->azBody, msg->asBody, '\n');
-    msg->cpBody = msg->azBody;
+    cpHeaders = msg->azHeaders;
 
     /********************************************************************
      * header + CRLF + body + '.' + CRLF + '\0', replacing NL with CRLF *
@@ -300,21 +281,25 @@
 
     n = 0;
     /* count size of headers, reserve space for NL to CRLF conversion */
-    for (i = 0; ((c = msg->cpHeaders[i]) != '\0'); i++) {
+    for (i = 0; ((c = cpHeaders[i]) != '\0'); i++) {
         if (c == '\n')
             n++;
         n++;
     }
     /* if headers don't end with NL, reserve space for CRLF */
-    if (i >= 0 && msg->cpHeaders[i - 1] != '\n')
+    if (i >= 0 && cpHeaders[i - 1] != '\n')
         n+=2;
     /* reserve space for CRLF between headers and body */
     n+=2;
-    /* count size of body, reserve space for NL to CRLF conversion */
+    /* count size of body, reserve space for NL-DOT escape and NL to CRLF conversion */
+    cOld = '\n';
     for (i = 0; ((c = msg->cpBody[i]) != '\0'); i++) {
         if (c == '\n')
             n++;
+        if (c == '.' && cOld == '\n')
+            n++;
         n++;
+        cOld = c;
     }
     /* if body doesn't end with NL, reserve space for CRLF */
     if (i >= 0 && msg->cpBody[i - 1] != '\n')
@@ -327,24 +312,28 @@
 
     n = 0;
     /* copy headers, do NL to CRLF conversion */
-    for (i = 0; ((c = msg->cpHeaders[i]) != '\0'); i++) {
+    for (i = 0; ((c = cpHeaders[i]) != '\0'); i++) {
         if (c == '\n')
             msg->cpMsg[n++] = '\r';
         msg->cpMsg[n++] = c;
     }
     /* if headers don't end with NL, append CRLF */
-    if (i >= 0 && msg->cpHeaders[i - 1] != '\n') {
+    if (i >= 0 && cpHeaders[i - 1] != '\n') {
         msg->cpMsg[n++] = '\r';
         msg->cpMsg[n++] = '\n';
     }
     /* add CRLF between headers and body */
     msg->cpMsg[n++] = '\r';
     msg->cpMsg[n++] = '\n';
-    /* copy body, do NL to CRLF conversion */
+    /* copy body, do NL-DOT escape and NL to CRLF conversion */
+    cOld = '\n';
     for (i = 0; ((c = msg->cpBody[i]) != '\0'); i++) {
         if (c == '\n')
             msg->cpMsg[n++] = '\r';
+        if (c == '.' && cOld == '\n')
+            msg->cpMsg[n++] = '.';
         msg->cpMsg[n++] = c;
+        cOld = c;
     }
     /* if body doesn't end with NL, append CRLF */
     if (i >= 0 && msg->cpBody[i - 1] != '\n') {
@@ -358,7 +347,6 @@
     msg->cpMsg[n]   = '\0';
 
     //fprintf(stderr, "DEBUG: Message = ***%s***\n", msg->cpMsg);
-
     return MSG_OK;
 }
 


ossp-pkg/lmtp2nntp/msg.h 1.1 -> 1.2

--- msg.h        2001/08/13 06:41:41     1.1
+++ msg.h        2001/08/14 08:15:25     1.2
@@ -6,20 +6,20 @@
 
 typedef struct {
     char   *cpMsg;      /* the wholly message to be received by DATA command */
-    char   *cpHeaders;  /* header part of message above */
+    char   *azHeaders;  /* header part of message above */
+    size_t  asHeaders;
     char   *cpBody;     /* body part of message above */
     char   *cpMsgid;
     char   *mail_from;
     char   *azRcpt;
     size_t  asRcpt;
-    char   *azHeaders;
-    size_t  asHeaders;
-    char   *azBody;
-    size_t  asBody;
     char   *azNewsgroups;
     size_t  asNewsgroups;
 } msg_t;
 
+#define WRAPAT 120          /* join wraps header lines when exceeding this value */
+#define WRAPUSING "\n    "  /* join inserts this value when wrapping lines       */
+
 typedef enum {
     MSG_OK,
     MSG_ERR_MEM,


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

--- nntp.c       2001/08/13 15:16:32     1.5
+++ nntp.c       2001/08/14 08:15:25     1.6
@@ -114,12 +114,12 @@
 
     do {
         if ((rc = nntp_readline(nntp, line, sizeof(line))) != NNTP_OK) {
-            fprintf(stderr, "DEBUG: nntp_readline returned ***%d***\n", rc);
+            //fprintf(stderr, "DEBUG: nntp_readline returned ***%d***\n", rc);
             return rc;
             }
     } while (line[0] == '1');
 
-    // fprintf(stderr, "DEBUG: nntp_readline got ***%s***\n", line);
+    //fprintf(stderr, "DEBUG: nntp_readline got ***%s***\n", line);
 
     if (strncmp(line, "200", 3) == 0)
         return NNTP_OK;
@@ -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;
 }
 
@@ -194,7 +194,7 @@
         return NNTP_ERR_ARG;
     strncpy(tmp, buf, NNTP_LINE_MAXLEN-3);
     strcat(tmp, "\r\n");
-    fprintf(stderr, "DEBUG: nntp_writeline >>>%s", tmp);
+    //fprintf(stderr, "DEBUG: nntp_writeline >>>%s", tmp);
     if (nntp->io.write(nntp->wfd, tmp, strlen(tmp)) < 0)
         return NNTP_ERR_SYSTEM;
     return NNTP_OK;
@@ -312,7 +312,7 @@
 
     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));
+    //fprintf(stderr, "DEBUG: answer to post = ***%s***, rc = %s\n", line, nntp_error(nntp, rc));
     if (   (strncmp(line, "240", 3) == 0)
         || (strncmp(line, "441", 3) == 0)
           )


ossp-pkg/lmtp2nntp/test/run.sh 1.2 -> 1.3

--- run.sh       2001/08/13 15:16:32     1.2
+++ run.sh       2001/08/14 08:15:26     1.3
@@ -4,18 +4,18 @@
 then
     ssh -t -x root@localhost exec rm -f /tmp/t
 fi
-echo ------------------------------------------------------------
 #./lmtp2nntp -h news-muc1.de.cw.net -h news-ffm2.de.cw.net -h news-dus2.de.cw.net -h news-ecrc.de
 #clear ; ./lmtp2nntp <testmessage2 -g envelope -h dev16
 #exit
-
-clear ; awk <testmessage2 "\
+clear 
+echo ------------------------------------------------------------
+awk <testmessage2 "\
   /Message-ID/ { print \"Message-ID: <`date +%Y%m%d%H%M%S`@dev12.dev.de.cw.net>\" } \
  !/Message-ID/ { print \$0 } \
  " \
  | tee /tmp/reusetestmessage \
  | ./lmtp2nntp -g envelope -h dev16
-cat /tmp/reusetestmessage | ./lmtp2nntp -g envelope -h dev16
+cat /tmp/reusetestmessage | ./lmtp2nntp -t /tmp/tx -g envelope -h dev16
 echo -----------------------------------------------------------
 exit
 


ossp-pkg/lmtp2nntp/trace.c -> 1.1

*** /dev/null    Tue Oct 19 17:22:04 2021
--- -    Tue Oct 19 17:24:32 2021
***************
*** 0 ****
--- 1,42 ----
+ 
+ #include "trace.h"
+ 
+ /*
+  * tracing
+  */
+ 
+ ssize_t trace_read(int d, void *buf, size_t nbytes)
+ {
+     ssize_t rc;
+     int tf;
+     static char tfn[PATH_MAX] = "/tmp/trace";
+ 
+     if ((d == -1) && (buf != NULL) && (nbytes == 0)) {
+         strncpy(tfn, buf, PATH_MAX-1);
+     }
+     rc = read(d, buf, nbytes);
+     if ((tf = open(tfn, O_CREAT|O_WRONLY|O_APPEND, 0664)) != -1) {
+         write(tf, buf, rc);
+         close(tf);
+     }
+     return rc;
+ }
+ 
+ ssize_t trace_write(int d, const void *buf, size_t nbytes)
+ {
+     ssize_t rc;
+     int tf;
+     static char tfn[PATH_MAX] = "/tmp/trace";
+ 
+     if ((d == -1) && (buf != NULL) && (nbytes == 0)) {
+         strncpy(tfn, buf, PATH_MAX-1);
+     }
+ 
+     rc = write(d, buf, nbytes);
+     if ((tf = open(tfn, O_CREAT|O_WRONLY|O_APPEND, 0664)) != -1) {
+         write(tf, buf, rc);
+         close(tf);
+     }
+     return rc;
+ }
+ 


ossp-pkg/lmtp2nntp/trace.h -> 1.1

*** /dev/null    Tue Oct 19 17:22:04 2021
--- -    Tue Oct 19 17:24:32 2021
***************
*** 0 ****
--- 1,17 ----
+ 
+ #ifndef __TRACE_H__
+ #define __TRACE_H__
+ 
+ #include <stdlib.h>
+ #include <stdio.h>
+ #include <unistd.h>
+ #include <errno.h>
+ #include <string.h>
+ #include <fcntl.h>
+ #include <sys/syslimits.h>
+ 
+ ssize_t trace_read (int,       void *, size_t);
+ ssize_t trace_write(int, const void *, size_t);
+ 
+ #endif /*  __TRACE_H__ */
+ 

CVSTrac 2.0.1