OSSP CVS Repository

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

ossp-pkg/lmtp2nntp/lmtp2nntp.c 1.43 -> 1.44

--- lmtp2nntp.c  2001/09/07 13:56:31     1.43
+++ lmtp2nntp.c  2001/09/07 15:02:08     1.44
@@ -51,7 +51,6 @@
 #include "nntp.h"
 #include "sa.h"
 #include "msg.h"
-#include "trace.h"
 #define _VERSION_C_AS_HEADER_
 #include "version.c"
 #undef  _VERSION_C_AS_HEADER_
@@ -172,6 +171,56 @@
     return;
 }
 
+static ssize_t trace_lmtp_read(void *_ctx, int d, void *buf, size_t nbytes)
+{
+    lmtp2nntp_t *ctx = (lmtp2nntp_t *)_ctx;
+    ssize_t rc;
+
+    rc = read(d, buf, nbytes);
+    if (rc == -1)
+        log0(ctx, TRACE, "LMTP read error: %m");
+    else
+        log3(ctx, TRACE, "LMTP %5d << \"%{text}D\"", rc, buf, rc);
+    return rc;
+}
+
+static ssize_t trace_lmtp_write(void *_ctx, int d, const void *buf, size_t nbytes)
+{
+    lmtp2nntp_t *ctx = (lmtp2nntp_t *)_ctx;
+    ssize_t rc;
+
+    log3(ctx, TRACE, "LMTP %5d >> \"%{text}D\"", nbytes, buf, nbytes);
+    rc = write(d, buf, nbytes);
+    if (rc == -1)
+        log0(ctx, TRACE, "LMTP write error: %m");
+    return rc;
+}
+
+static ssize_t trace_nntp_read(void *_ctx, int d, void *buf, size_t nbytes)
+{
+    lmtp2nntp_t *ctx = (lmtp2nntp_t *)_ctx;
+    ssize_t rc;
+
+    rc = read(d, buf, nbytes);
+    if (rc == -1)
+        log0(ctx, TRACE, "NNTP read error: %m");
+    else
+        log3(ctx, TRACE, "NNTP %5d << \"%{text}D\"", rc, buf, rc);
+    return rc;
+}
+
+static ssize_t trace_nntp_write(void *_ctx, int d, const void *buf, size_t nbytes)
+{
+    lmtp2nntp_t *ctx = (lmtp2nntp_t *)_ctx;
+    ssize_t rc;
+
+    log3(ctx, TRACE, "NNTP %5d >> \"%{text}D\"", nbytes, buf, nbytes);
+    rc = write(d, buf, nbytes);
+    if (rc == -1)
+        log0(ctx, TRACE, "NNTP write error: %m");
+    return rc;
+}
+
 static l2_result_t 
 formatter_prefix(l2_context_t *_ctx, const char id, const char *param,
           char *bufptr, size_t bufsize, size_t *buflen, va_list *ap)
@@ -455,6 +504,10 @@
         fprintf(stderr, "%s:Error: logging failed to register dump formatter\n", ctx->progname);
         exit(ERR_EXECUTION);
     }
+    if (l2_stream_formatter(ctx->l2, 'S', l2_util_fmt_string, NULL) != L2_OK) {
+        fprintf(stderr, "%s:Error: logging failed to register string formatter\n", ctx->progname);
+        exit(ERR_EXECUTION);
+    }
     if (l2_stream_formatter(ctx->l2, 'm', formatter_errno, NULL) != L2_OK) {
         fprintf(stderr, "%s:Error: logging failed to register dump formatter\n", ctx->progname);
         exit(ERR_EXECUTION);
@@ -516,15 +569,11 @@
         exit(ERR_EXECUTION);
     }
 
-    if (ctx->option_logfile && (ctx->option_levelmask >= L2_LEVEL_TRACE)) {
-        trace_read (-1, ctx->option_logfile, 0);
-        trace_write(-1, ctx->option_logfile, 0);
-    }
-
     /* initialize LMTP context */
+    lmtp_io.ctx    = ctx;
     lmtp_io.select = NULL;
-    lmtp_io.read   = trace_read;
-    lmtp_io.write  = trace_write;
+    lmtp_io.read   = trace_lmtp_read;
+    lmtp_io.write  = trace_lmtp_write;
     if ((lmtp = lmtp_create(STDIN_FILENO, STDOUT_FILENO,
                             (ctx->option_logfile && (ctx->option_levelmask >= L2_LEVEL_TRACE)) ?
                              &lmtp_io : NULL )) == NULL) {
@@ -678,9 +727,10 @@
 
     log0(ctx, INFO, "lmtp_cb_lhlo");
 
+    nntp_io.ctx    = ctx;
     nntp_io.select = NULL;
-    nntp_io.read   = trace_read;
-    nntp_io.write  = trace_write;
+    nntp_io.read   = trace_nntp_read;
+    nntp_io.write  = trace_nntp_write;
 
     /*  RFC0821 4.2.1. REPLY CODES BY FUNCTION GROUPS   503 Bad sequence of commands
      *  RFC1893 2. Status Codes                         5.X.X   Permanent Failure

CVSTrac 2.0.1