OSSP CVS Repository

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

Check-in Number: 1132
Date: 2001-Oct-09 20:55:22 (local)
2001-Oct-09 18:55:22 (UTC)
User:rse
Branch:
Comment: - error text cleanup - allow "sa_t *" to be NULL
Tickets:
Inspections:
Files:
ossp-pkg/sa/sa.c      1.22 -> 1.23     18 inserted, 9 deleted
ossp-pkg/sa/sa.h      1.18 -> 1.19     12 inserted, 12 deleted

ossp-pkg/sa/sa.c 1.22 -> 1.23

--- sa.c 2001/10/09 18:38:29     1.22
+++ sa.c 2001/10/09 18:55:22     1.23
@@ -357,22 +357,31 @@
     int n;
 
     /* argument sanity check */
-    if (sa == NULL || str == NULL)
+    if (str == NULL)
         return SA_ERR_ARG;
 
-    /* start at begin of buffer */
-    cpBuf = sa->szError;
-    nBuf  = sizeof(sa->szError);
-
     /* 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";
-    else if (rv == SA_ERR_MEM) sz = "no more memory available";
+    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_EOF) sz = "end of file in socket communication";
     else if (rv == SA_ERR_INT) sz = "internal error";
-    else                       sz = "unknown 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;


ossp-pkg/sa/sa.h 1.18 -> 1.19

--- sa.h 2001/10/09 18:34:12     1.18
+++ sa.h 2001/10/09 18:55:22     1.19
@@ -104,15 +104,15 @@
 
 /* return codes */
 typedef enum {
-    SA_OK,      /* everything ok */
-    SA_ERR_ARG, /* invalid argument (wrong parameter) */
-    SA_ERR_USE, /* invalid use (wrong context) */
-    SA_ERR_MEM, /* out of memory */
-    SA_ERR_SYS, /* system error (see errno) */
-    SA_ERR_EOF, /* end of file/socket communication */
-    SA_ERR_MTC, /* error in match */
-    SA_ERR_TMT, /* operation timeout */
-    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 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_rc_t;
 
 /* list of timeouts */
@@ -137,9 +137,6 @@
     SA_SYSCALL_SENDTO
 } sa_syscall_t;
 
-/* error handling operations */
-sa_rc_t sa_error        (sa_t *sa, sa_rc_t rv, char **str);
-
 /* address object operations */
 sa_rc_t sa_addr_create  (sa_addr_t **saa);
 sa_rc_t sa_addr_destroy (sa_addr_t *saa);
@@ -182,6 +179,9 @@
 sa_rc_t sa_recv         (sa_t *sa, char *buf, size_t buflen, size_t *bufdone, sa_addr_t **raddr);
 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);
+
 /* cleanup */
 #if defined(HAVE_CONFIG_H) && !defined(HAVE_SOCKLEN_T)
 #undef socklen_t

CVSTrac 2.0.1