OSSP CVS Repository

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

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;
     }

CVSTrac 2.0.1