OSSP CVS Repository

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

ossp-pkg/lmtp2nntp/lmtp2nntp_main.c 1.79 -> 1.80

--- lmtp2nntp_main.c     2004/04/02 10:38:13     1.79
+++ lmtp2nntp_main.c     2004/05/07 14:52:03     1.80
@@ -221,6 +221,25 @@
 static void lmtp_gfs_rset(lmtp2nntp_t *);
 static void lmtp_gfs_quit(lmtp2nntp_t *);
 
+static void sa2errno(sa_rc_t rv)
+{
+    switch (rv) {
+        case SA_OK:      errno = 0;      break;
+        case SA_ERR_EOF: errno = 0;      break;
+        case SA_ERR_SYS:                 break;
+        case SA_ERR_ARG: errno = EINVAL; break;
+        case SA_ERR_USE: errno = EINVAL; break;
+        case SA_ERR_MTC: errno = ENOENT; break;
+        case SA_ERR_MEM: errno = ENOMEM; break;
+        case SA_ERR_IMP: errno = ENOSYS; break;
+        case SA_ERR_TMT: errno = EIO;    break;
+        case SA_ERR_NET: errno = EIO;    break;
+        case SA_ERR_FMT: errno = EIO;    break;
+        case SA_ERR_INT: errno = EIO;    break;
+        default:         errno = EIO;
+    }
+}
+
 static ssize_t hook_lmtp_read(void *_ctx, void *buf, size_t nbytes)
 {
     lmtp2nntp_t *ctx = (lmtp2nntp_t *)_ctx;
@@ -229,13 +248,25 @@
     sa_rc_t rv;
 
     if (ctx->saIO != NULL) {
-        if ((rv = sa_read(ctx->saIO, buf, nbytes, &n)) != SA_OK)
-            rc = -1;
+        if ((rv = sa_read(ctx->saIO, buf, nbytes, &n)) != SA_OK) {
+            if (rv == SA_ERR_SYS)
+                logbook(ctx->l2, L2_LEVEL_DEBUG, "hook_lmtp_read() sa_read failed with \"%s\" (%d) %s", sa_error(rv), errno, strerror(errno));
+            else
+                logbook(ctx->l2, L2_LEVEL_DEBUG, "hook_lmtp_read() sa_read failed with \"%s\"", sa_error(rv));
+            if (rv == SA_ERR_EOF)
+                rc = 0;
+            else
+                rc = -1;
+            sa2errno(rv);
+        }
         else
             rc = (ssize_t)n;
     }
-    else
+    else {
         rc = read(ctx->fdIOi, buf, nbytes);
+        if (rc == -1)
+            logbook(ctx->l2, L2_LEVEL_DEBUG, "hook_lmtp_read() read failed with (%d) %s", errno, strerror(errno));
+    }
     if (rc == -1)
         logbook(ctx->l2, L2_LEVEL_TRACE, "LMTP read error: %m");
     else
@@ -253,15 +284,24 @@
 
     logbook(ctx->l2, L2_LEVEL_TRACE, "LMTP %5d >> \"%{text}D\"", nbytes, buf, nbytes);
     if (ctx->saIO != NULL) {
-        if ((rv = sa_write(ctx->saIO, buf, nbytes, &n)) != SA_OK)
+        if ((rv = sa_write(ctx->saIO, buf, nbytes, &n)) != SA_OK) {
+            if (rv == SA_ERR_SYS)
+                logbook(ctx->l2, L2_LEVEL_DEBUG, "hook_lmtp_write() sa_write failed with \"%s\" (%d) %s", sa_error(rv), errno, strerror(errno));
+            else
+                logbook(ctx->l2, L2_LEVEL_DEBUG, "hook_lmtp_write() sa_write failed with \"%s\"", sa_error(rv));
             rc = -1;
+            sa2errno(rv);
+        }
         else
             rc = (ssize_t)n;
     }
-    else
+    else {
         rc = write(ctx->fdIOo, buf, nbytes);
+        if (rc == -1)
+            logbook(ctx->l2, L2_LEVEL_DEBUG, "hook_lmtp_write() write failed with (%d) %s", errno, strerror(errno));
+    }
     if (rc == -1)
-        logbook(ctx->l2, L2_LEVEL_TRACE, "LMTP write error: %m");
+        logbook(ctx->l2, L2_LEVEL_TRACE, "LMTP write error");
     return rc;
 }
 
@@ -272,8 +312,17 @@
     size_t n;
     sa_rc_t rv;
 
-    if ((rv = sa_read(ctx->sa, buf, nbytes, &n)) != SA_OK)
-        rc = -1;
+    if ((rv = sa_read(ctx->sa, buf, nbytes, &n)) != SA_OK) {
+        if (rv == SA_ERR_SYS)
+            logbook(ctx->l2, L2_LEVEL_DEBUG, "hook_lmtp_read() sa_read failed with \"%s\" (%d) %s", sa_error(rv), errno, strerror(errno));
+        else
+            logbook(ctx->l2, L2_LEVEL_DEBUG, "hook_lmtp_read() sa_read failed with \"%s\"", sa_error(rv));
+        if (rv == SA_ERR_EOF)
+            rc = 0;
+        else
+            rc = -1;
+        sa2errno(rv);
+    }
     else
         rc = (ssize_t)n;
     if (rc == -1)
@@ -291,12 +340,18 @@
     sa_rc_t rv;
 
     logbook(ctx->l2, L2_LEVEL_TRACE, "NNTP %5d >> \"%{text}D\"", nbytes, buf, nbytes);
-    if ((rv = sa_write(ctx->sa, buf, nbytes, &n)) != SA_OK)
+    if ((rv = sa_write(ctx->sa, buf, nbytes, &n)) != SA_OK) {
+        if (rv == SA_ERR_SYS)
+            logbook(ctx->l2, L2_LEVEL_DEBUG, "hook_nntp_write() sa_write failed with \"%s\" (%d) %s", sa_error(rv), errno, strerror(errno));
+        else
+            logbook(ctx->l2, L2_LEVEL_DEBUG, "hook_nntp_write() sa_write failed with \"%s\"", sa_error(rv));
         rc = -1;
+        sa2errno(rv);
+    }
     else
         rc = (ssize_t)n;
     if (rc == -1)
-        logbook(ctx->l2, L2_LEVEL_TRACE, "NNTP write error: %m");
+        logbook(ctx->l2, L2_LEVEL_TRACE, "NNTP write error");
     return rc;
 }
 

CVSTrac 2.0.1