OSSP CVS Repository

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

Check-in Number: 890
Date: 2001-Sep-07 17:02:08 (local)
2001-Sep-07 15:02:08 (UTC)
User:thl
Branch:
Comment: Replace ad-hoc tracing with L2_LEVEL_TRACE based approach.
Tickets:
Inspections:
Files:
ossp-pkg/lmtp2nntp/Makefile.in      1.14 -> 1.15     2 inserted, 2 deleted
ossp-pkg/lmtp2nntp/lmtp.c      1.21 -> 1.22     25 inserted, 8 deleted
ossp-pkg/lmtp2nntp/lmtp.h      1.9 -> 1.10     4 inserted, 3 deleted
ossp-pkg/lmtp2nntp/lmtp2nntp.c      1.43 -> 1.44     60 inserted, 10 deleted
ossp-pkg/lmtp2nntp/lmtp2nntp.h      1.1 -> 1.2     7 inserted, 0 deleted
ossp-pkg/lmtp2nntp/nntp.c      1.20 -> 1.21     28 inserted, 11 deleted
ossp-pkg/lmtp2nntp/nntp.h      1.8 -> 1.9     4 inserted, 3 deleted
ossp-pkg/lmtp2nntp/trace.c      1.4->removed
ossp-pkg/lmtp2nntp/trace.h      1.3->removed

ossp-pkg/lmtp2nntp/Makefile.in 1.14 -> 1.15

--- Makefile.in  2001/09/07 13:53:16     1.14
+++ Makefile.in  2001/09/07 15:02:08     1.15
@@ -43,8 +43,8 @@
 POD2MAN     = pod2man
 
 PROG = lmtp2nntp
-HDRS = lmtp2nntp.h lmtp.h nntp.h sa.h argz.h shpat_match.h msg.h trace.h
-OBJS = lmtp2nntp.o lmtp.o nntp.o sa.o argz.o shpat_match.o msg.o trace.o version.o
+HDRS = lmtp2nntp.h lmtp.h nntp.h sa.h argz.h shpat_match.h msg.h 
+OBJS = lmtp2nntp.o lmtp.o nntp.o sa.o argz.o shpat_match.o msg.o version.o
 
 SUBDIRS = @SUBDIR_STR@ @SUBDIR_L2@ 
 


ossp-pkg/lmtp2nntp/lmtp.c 1.21 -> 1.22

--- lmtp.c       2001/09/04 09:46:06     1.21
+++ lmtp.c       2001/09/07 15:02:08     1.22
@@ -70,6 +70,21 @@
     int               wfd;      /* file descriptor for writing */
 };
 
+static int lmtp_select(void *ctx, int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tv)
+{
+    return select(nfds, rfds, wfds, efds, tv);
+}
+
+static ssize_t lmtp_read(void *ctx, int fd, void *buf, size_t buflen)
+{
+    return read(fd, buf, buflen);
+}
+
+static ssize_t lmtp_write(void *ctx, int fd, const void *buf, size_t buflen)
+{
+    return write(fd, buf, buflen);
+}
+
 static int verbindex(lmtp_t *lmtp, char *verb)
 {
     /* returns the index of the verb or -1 if verb not registered */
@@ -110,13 +125,15 @@
         return NULL;
 
     if (io == NULL) {
-        lmtp->io.select = select;
-        lmtp->io.read   = read;
-        lmtp->io.write  = write;
+        lmtp->io.ctx    = NULL;
+        lmtp->io.select = lmtp_select;
+        lmtp->io.read   = lmtp_read;
+        lmtp->io.write  = lmtp_write;
     } else {
-        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->io.ctx    = io->ctx;
+        lmtp->io.select = io->select ? io->select : lmtp_select;
+        lmtp->io.read   = io->read   ? io->read   : lmtp_read;
+        lmtp->io.write  = io->write  ? io->write  : lmtp_write;
     }
 
     lmtp->rl.rl_cnt = 0;
@@ -164,7 +181,7 @@
         /* fetch one character (but read more) */
         if (rl->rl_cnt <= 0) {
             do {
-                rl->rl_cnt = lmtp->io.read(lmtp->rfd, rl->rl_buf, LMTP_LINE_MAXLEN);
+                rl->rl_cnt = lmtp->io.read(lmtp->io.ctx, lmtp->rfd, rl->rl_buf, LMTP_LINE_MAXLEN);
             } while (rl->rl_cnt == -1 && errno == EINTR);
             if (rl->rl_cnt == -1)
                 return LMTP_ERR_SYSTEM;
@@ -353,7 +370,7 @@
         formatbuf[len++] = '\r';
         formatbuf[len++] = '\n';
         do {
-            rv = lmtp->io.write(lmtp->wfd, formatbuf, len);
+            rv = lmtp->io.write(lmtp->io.ctx, lmtp->wfd, formatbuf, len);
         } while (rv == -1 && errno == EINTR);
         if (rv == -1)
             return LMTP_ERR_SYSTEM;


ossp-pkg/lmtp2nntp/lmtp.h 1.9 -> 1.10

--- lmtp.h       2001/09/04 09:46:06     1.9
+++ lmtp.h       2001/09/07 15:02:08     1.10
@@ -36,9 +36,10 @@
 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);
+    void    *ctx;
+    int     (*select)(void *, int, fd_set *, fd_set *, fd_set *, struct timeval *);
+    ssize_t (*read)(void *, int, void *, size_t);
+    ssize_t (*write)(void *, int, const void *, size_t);
 } lmtp_io_t;
 
 typedef struct {


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


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

--- lmtp2nntp.h  2001/09/07 13:53:16     1.1
+++ lmtp2nntp.h  2001/09/07 15:02:08     1.2
@@ -27,6 +27,13 @@
 #ifndef __LMTP2NNTP_H__
 #define __LMTP2NNTP_H__
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#if defined(HAVE_DMALLOC_H) && defined(DMALLOC)
+#include "dmalloc.h"
+#endif
+
 #define log0(ctx,level,msg) \
     l2_stream_log((ctx)->l2, L2_LEVEL_##level, "%P: " msg)
 #define log1(ctx,level,msg,a1) \


ossp-pkg/lmtp2nntp/nntp.c 1.20 -> 1.21

--- nntp.c       2001/09/04 09:46:06     1.20
+++ nntp.c       2001/09/07 15:02:08     1.21
@@ -72,6 +72,21 @@
     int             kludgeinn441dup;
 };
 
+static int nntp_select(void *ctx, int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tv)
+{
+    return select(nfds, rfds, wfds, efds, tv);
+}
+
+static ssize_t nntp_read(void *ctx, int fd, void *buf, size_t buflen)
+{
+    return read(fd, buf, buflen);
+}
+
+static ssize_t nntp_write(void *ctx, int fd, const void *buf, size_t buflen)
+{
+    return write(fd, buf, buflen);
+}
+
 nntp_t *nntp_create(int rfd, int wfd, nntp_io_t *io)
 {
     nntp_t *nntp;
@@ -80,13 +95,15 @@
         return NULL;
 
     if (io == NULL) {
-        nntp->io.select = select;
-        nntp->io.read   = read;
-        nntp->io.write  = write;
+        nntp->io.ctx    = NULL;
+        nntp->io.select = nntp_select;
+        nntp->io.read   = nntp_read;
+        nntp->io.write  = nntp_write;
     } else {
-        nntp->io.select = io->select ? io->select : select;
-        nntp->io.read   = io->read   ? io->read   : read;
-        nntp->io.write  = io->write  ? io->write  : write;
+        nntp->io.ctx    = io->ctx;
+        nntp->io.select = io->select ? io->select : nntp_select;
+        nntp->io.read   = io->read   ? io->read   : nntp_read;
+        nntp->io.write  = io->write  ? io->write  : nntp_write;
     }
 
     nntp->rfd = rfd;
@@ -180,13 +197,13 @@
             FD_SET(nntp->rfd, &fds);
             tv.tv_sec  = nntp->tv.tv_sec;
             tv.tv_usec = nntp->tv.tv_usec;
-            rc = nntp->io.select(nntp->rfd + 1, &fds, NULL, NULL, &tv);
+            rc = nntp->io.select(nntp->io.ctx, nntp->rfd + 1, &fds, NULL, NULL, &tv);
             if (rc == 0)
                 return NNTP_TIMEOUT;
             else if (rc == -1)
                 return NNTP_ERR_SYSTEM;
             do {
-                rl->rl_cnt = nntp->io.read(nntp->rfd, rl->rl_buf, NNTP_LINE_MAXLEN);
+                rl->rl_cnt = nntp->io.read(nntp->io.ctx, nntp->rfd, rl->rl_buf, NNTP_LINE_MAXLEN);
             } while (rl->rl_cnt == -1 && errno == EINTR);
             if (rl->rl_cnt == -1)
                 return NNTP_ERR_SYSTEM;
@@ -219,7 +236,7 @@
         return NNTP_ERR_ARG;
     strncpy(tmp, buf, NNTP_LINE_MAXLEN-3);
     strcat(tmp, "\r\n");
-    if (nntp->io.write(nntp->wfd, tmp, strlen(tmp)) < 0)
+    if (nntp->io.write(nntp->io.ctx, nntp->wfd, tmp, strlen(tmp)) < 0)
         return NNTP_ERR_SYSTEM;
     return NNTP_OK;
 }
@@ -334,7 +351,7 @@
         return NNTP_ERR_POST;
 
     do {
-        rc = nntp->io.write(nntp->wfd, msg->cpMsg, strlen(msg->cpMsg));
+        rc = nntp->io.write(nntp->io.ctx, nntp->wfd, msg->cpMsg, strlen(msg->cpMsg));
     } while (rc == -1 && errno == EINTR);
     if (rc == -1)
         return NNTP_ERR_SYSTEM;
@@ -410,7 +427,7 @@
         return NNTP_ERR_POST;
 
     do {
-        rc = nntp->io.write(nntp->wfd, msg->cpMsg, strlen(msg->cpMsg));
+        rc = nntp->io.write(nntp->io.ctx, nntp->wfd, msg->cpMsg, strlen(msg->cpMsg));
     } while (rc == -1 && errno == EINTR);
     if (rc == -1)
         return NNTP_ERR_SYSTEM;


ossp-pkg/lmtp2nntp/nntp.h 1.8 -> 1.9

--- nntp.h       2001/09/04 09:46:06     1.8
+++ nntp.h       2001/09/07 15:02:08     1.9
@@ -37,9 +37,10 @@
 typedef struct nntp_st nntp_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);
+    void    *ctx;
+    int     (*select)(void *, int, fd_set *, fd_set *, fd_set *, struct timeval *);
+    ssize_t (*read)(void *, int, void *, size_t);
+    ssize_t (*write)(void *, int, const void *, size_t);
 } nntp_io_t;
 
 typedef enum {


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



ossp-pkg/lmtp2nntp/trace.h 1.3 -> 1.4


CVSTrac 2.0.1