OSSP CVS Repository

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

Check-in Number: 1142
Date: 2001-Oct-10 11:21:27 (local)
2001-Oct-10 09:21:27 (UTC)
User:rse
Branch:
Comment: Revert my idea of using an L2-style error handling also in SA, because this is not possible in a consistent way due to the multiple objects and the fact that we cannot remember anything without an object (in L2 an environment object will be introduced soon, so there is it is a different game). So we use a plain sa_error() which is now similar to strerror(3).
Tickets:
Inspections:
Files:
ossp-pkg/sa/TODO      1.21 -> 1.22     0 inserted, 2 deleted
ossp-pkg/sa/sa.c      1.27 -> 1.28     25 inserted, 92 deleted
ossp-pkg/sa/sa.h      1.21 -> 1.22     10 inserted, 10 deleted
ossp-pkg/sa/sa.pod      1.11 -> 1.12     1 inserted, 1 deleted

ossp-pkg/sa/TODO 1.21 -> 1.22

--- TODO 2001/10/10 09:05:18     1.21
+++ TODO 2001/10/10 09:21:27     1.22
@@ -10,8 +10,6 @@
   - inet://localhost:smtp -> inet://127.0.0.1:25
   - unix:/tmp/socket -> unix:/tmp/socket
 
-o Use sa_errorinfo() internally everywhere where it is reasonable.
-
 CANDO
 -----
 


ossp-pkg/sa/sa.c 1.27 -> 1.28

--- sa.c 2001/10/10 09:05:18     1.27
+++ sa.c 2001/10/10 09:21:27     1.28
@@ -170,9 +170,6 @@
     int              nWriteLen;        /* write buffer current length */
     int              nWriteSize;       /* write buffer current size */
     char            *cpWriteBuf;       /* write buffer memory chunk */
-    char             szError[256];     /* error temporary buffer */
-    char             szErrorInfo[128]; /* error additional information text */
-    sa_rc_t          rvErrorInfo;      /* error additional information code */
     sa_syscall_tab_t scSysCall;        /* table of system calls */
 };
 
@@ -375,88 +372,6 @@
     return chars;
 }
 
-/* remember extra error information */
-static sa_rc_t sa_errorinfo(sa_t *sa, sa_rc_t rv, const char *fmt, ...)
-{
-    va_list ap;
-
-    /* argument sanity check */
-    if (sa == NULL)
-        return SA_ERR_ARG;
-
-    if (rv == SA_OK && fmt == NULL) {
-        /* reset error information */
-        sa->szErrorInfo[0] = '\0';
-        sa->rvErrorInfo = SA_OK;
-    }
-    else {
-        /* remember error information */
-        va_start(ap, fmt);
-        sa_mvsnprintf(sa->szErrorInfo, sizeof(sa->szErrorInfo), fmt, ap);
-        sa->rvErrorInfo = rv;
-        va_end(ap);
-    }
-    return SA_OK;
-}
-
-/* return error string */
-sa_rc_t sa_error(sa_t *sa, sa_rc_t rv, char **str)
-{
-    char *sz;
-    char *cpBuf;
-    int nBuf;
-    int n;
-
-    /* argument sanity check */
-    if (str == NULL)
-        return SA_ERR_ARG;
-
-    /* translate result value into corresponding string */
-    if      (rv == SA_OK)      sz = "everything ok";
-    else if (rv == SA_ERR_ARG) sz = "invalid argument";
-    else if (rv == SA_ERR_USE) sz = "invalid use or context";
-    else if (rv == SA_ERR_MEM) sz = "not enough memory available";
-    else if (rv == SA_ERR_MTC) sz = "matching operation failed";
-    else if (rv == SA_ERR_EOF) sz = "communication end";
-    else if (rv == SA_ERR_TMT) sz = "communication timeout";
-    else if (rv == SA_ERR_SYS) sz = "operating system error";
-    else if (rv == SA_ERR_INT) sz = "internal error";
-    else
-        return SA_ERR_ARG;
-
-    /* if no context is available we have to stop */
-    if (sa == NULL) {
-        *str = sz;
-        return SA_OK;
-    }
-
-    /* start at begin of buffer */
-    cpBuf = sa->szError;
-    nBuf  = sizeof(sa->szError);
-    n = sa_msnprintf(cpBuf, nBuf, "%s", sz);
-    cpBuf += n;
-    nBuf  -= n;
-
-    /* optionally annotate with error information */
-    if (rv == sa->rvErrorInfo && sa->szErrorInfo[0] != '\0') {
-        n = sa_msnprintf(cpBuf, nBuf, "; %s", sa->szErrorInfo);
-        cpBuf += n;
-        nBuf  -= n;
-        sa_errorinfo(sa, SA_OK, NULL);
-    }
-
-    /* optionally annotate with operating system error information */
-    if (rv == SA_ERR_SYS) {
-        n = sa_msnprintf(cpBuf, nBuf, "; %s (%d)", strerror(errno), errno);
-        cpBuf += n;
-        nBuf  -= n;
-    }
-
-    /* return pointer to internal buffer */
-    *str = sa->szError;
-    return SA_OK;
-}
-
 /* create address object */
 sa_rc_t sa_addr_create(sa_addr_t **saap)
 {
@@ -639,12 +554,14 @@
                 sf = AF_INET6;
             }
 #endif
+            else
+                return SA_ERR_ARG;
         }
+        else
+            return SA_ERR_ARG;
     }
-
-    /* make sure result variables are set */
-    if (sa == NULL || sl == 0 || sf == 0)
-        return SA_ERR_INT;
+    else
+        return SA_ERR_ARG;
 
     /* fill-in result address structure */
     if (saa->saBuf != NULL)
@@ -965,9 +882,6 @@
     sa->nWriteLen      = 0;
     sa->nWriteSize     = 0;
     sa->cpWriteBuf     = NULL;
-    sa->szError[0]     = '\0';
-    sa->szErrorInfo[0] = '\0';
-    sa->rvErrorInfo    = SA_OK;
 
     /* init timeval object attributes */
     for (i = 0; i < (sizeof(sa->tvTimeout)/sizeof(sa->tvTimeout[0])); i++) {
@@ -1952,3 +1866,22 @@
     return SA_OK;
 }
 
+/* return error string */
+char *sa_error(sa_rc_t rv)
+{
+    char *sz;
+
+    /* translate result value into corresponding string */
+    if      (rv == SA_OK)      sz = "Everything Ok";
+    else if (rv == SA_ERR_ARG) sz = "Invalid Argument";
+    else if (rv == SA_ERR_USE) sz = "Invalid Use Or Context";
+    else if (rv == SA_ERR_MEM) sz = "Not Enough Memory";
+    else if (rv == SA_ERR_MTC) sz = "Matching Failed";
+    else if (rv == SA_ERR_EOF) sz = "End Of Communication";
+    else if (rv == SA_ERR_TMT) sz = "Communication Timeout";
+    else if (rv == SA_ERR_SYS) sz = "Operating System Error";
+    else if (rv == SA_ERR_INT) sz = "Internal Error";
+    else                       sz = "Invalid Result Code";
+    return sz;
+}
+


ossp-pkg/sa/sa.h 1.21 -> 1.22

--- sa.h 2001/10/10 07:42:26     1.21
+++ sa.h 2001/10/10 09:21:27     1.22
@@ -104,15 +104,15 @@
 
 /* return codes */
 typedef enum {
-    SA_OK,      /* everything ok               */
-    SA_ERR_ARG, /* invalid argument            */
-    SA_ERR_USE, /* invalid use or context      */
-    SA_ERR_MEM, /* not enough memory available */
-    SA_ERR_MTC, /* matching operation failed   */
-    SA_ERR_EOF, /* communication end           */
-    SA_ERR_TMT, /* communication timeout       */
-    SA_ERR_SYS, /* operating system error      */
-    SA_ERR_INT  /* internal error              */
+    SA_OK,      /* Everything Ok          */
+    SA_ERR_ARG, /* Invalid Argument       */
+    SA_ERR_USE, /* Invalid Use Or Context */
+    SA_ERR_MEM, /* Not Enough Memory      */
+    SA_ERR_MTC, /* Matching Failed        */
+    SA_ERR_EOF, /* End Of Communication   */
+    SA_ERR_TMT, /* Communication Timeout  */
+    SA_ERR_SYS, /* Operating System Error */
+    SA_ERR_INT  /* Internal Error         */
 } sa_rc_t;
 
 /* list of timeouts */
@@ -184,7 +184,7 @@
 sa_rc_t sa_send         (sa_t *sa, const char *buf, size_t buflen, size_t *bufdone, sa_addr_t *raddr);
 
 /* error handling operations */
-sa_rc_t sa_error        (sa_t *sa, sa_rc_t rv, char **str);
+char   *sa_error        (sa_rc_t rv);
 
 /* cleanup */
 #if defined(HAVE_CONFIG_H) && !defined(HAVE_SOCKLEN_T)


ossp-pkg/sa/sa.pod 1.11 -> 1.12

--- sa.pod       2001/10/10 07:45:37     1.11
+++ sa.pod       2001/10/10 09:21:27     1.12
@@ -284,7 +284,7 @@
 
 =over 4
 
-=item sa_rc_t B<sa_error>(sa_t *I<sa>, sa_rc_t I<rv>, char **I<str>);
+=item char *B<sa_error>(sa_rc_t I<rv>);
 
 =back
 

CVSTrac 2.0.1