OSSP CVS Repository

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

Check-in Number: 1721
Date: 2002-Jan-30 17:43:00 (local)
2002-Jan-30 16:43:00 (UTC)
User:rse
Branch:
Comment: add optional OSSP ex based exception handling support
Tickets:
Inspections:
Files:
ossp-pkg/sa/acconfig.h      1.3 -> 1.4     4 inserted, 0 deleted
ossp-pkg/sa/aclocal.m4      1.3 -> 1.4     112 inserted, 0 deleted
ossp-pkg/sa/configure.ac      1.7 -> 1.8     2 inserted, 0 deleted
ossp-pkg/sa/sa.c      1.54 -> 1.55     140 inserted, 127 deleted
ossp-pkg/sa/sa.h      1.28 -> 1.29     3 inserted, 0 deleted
ossp-pkg/sa/sa_test.c      1.13 -> 1.14     33 inserted, 0 deleted

ossp-pkg/sa/acconfig.h 1.3 -> 1.4

--- acconfig.h   2001/10/24 13:34:27     1.3
+++ acconfig.h   2002/01/30 16:43:00     1.4
@@ -4,3 +4,7 @@
 
 /* whether ssize_t exists */
 #undef HAVE_SSIZE_T
+
+/* whether to use OSSP ex */
+#undef WITH_EX
+


ossp-pkg/sa/aclocal.m4 1.3 -> 1.4

--- aclocal.m4   2002/01/02 12:43:50     1.3
+++ aclocal.m4   2002/01/30 16:43:00     1.4
@@ -115,3 +115,115 @@
 fi
 ])
 
+dnl ##
+dnl ##  Check for an external/extension library.
+dnl ##  - is aware of <libname>-config style scripts
+dnl ##  - searches under standard paths include, lib, etc.
+dnl ##  - searches under subareas like .libs, etc.
+dnl ##
+dnl ##  configure.in:
+dnl ##      AC_CHECK_EXTLIB(<realname>, <libname>, <func>, <header>,
+dnl ##                      [<success-action> [, <fail-action>]])
+dnl ##  Makefile.in:
+dnl ##      CFLAGS  = @CFLAGS@
+dnl ##      LDFLAGS = @LDFLAGS@
+dnl ##      LIBS    = @LIBS@
+dnl ##  shell:
+dnl ##      $ ./configure --with-<libname>[=DIR]
+dnl ##
+
+AC_DEFUN(AC_CHECK_EXTLIB,[dnl
+AC_ARG_WITH($2, [dnl
+[  --with-]m4_substr([$2[[=DIR]]                     ], 0, 19)[build with external $1 library (default=no)]], [dnl
+    if test ".$with_$2" = .yes; then
+        #   via config script in PATH
+        $2_version=`($2-config --version) 2>/dev/null`
+        if test ".$$2_version" != .; then
+            CPPFLAGS="$CPPFLAGS `$2-config --cflags`"
+            CFLAGS="$CFLAGS `$2-config --cflags`"
+            LDFLAGS="$LDFLAGS `$2-config --ldflags`"
+        fi
+    else
+        if test -d "$with_$2"; then
+            found=0
+            #   via config script
+            for dir in $with_$2/bin $with_$2; do
+                if test -f "$dir/$2-config" && test ! -f "$dir/$2-config.in"; then
+                    $2_version=`($dir/$2-config --version) 2>/dev/null`
+                    if test ".$$2_version" != .; then
+                        CPPFLAGS="$CPPFLAGS `$dir/$2-config --cflags`"
+                        CFLAGS="$CFLAGS `$dir/$2-config --cflags`"
+                        LDFLAGS="$LDFLAGS `$dir/$2-config --ldflags`"
+                        found=1
+                        break
+                    fi
+                fi
+            done
+            #   in standard sub-areas
+            if test ".$found" = .0; then
+                for dir in $with_$2/include/$2 $with_$2/include $with_$2; do
+                    if test -f "$dir/$4"; then
+                        CPPFLAGS="$CPPFLAGS -I$dir"
+                        CFLAGS="$CFLAGS -I$dir"
+                        found=1
+                        break
+                    fi
+                done
+                for dir in $with_$2/lib/$2 $with_$2/lib $with_$2; do
+                    if test -f "$dir/lib$2.la" && test -d "$dir/.libs"; then
+                        LDFLAGS="$LDFLAGS -L$dir -L$dir/.libs"
+                        found=1
+                        break
+                    elif test -f "$dir/lib$2.a" || test -f "$dir/lib$2.so"; then
+                        LDFLAGS="$LDFLAGS -L$dir"
+                        found=1
+                        break
+                    fi
+                done
+            fi
+            #   in any sub-area
+            if test ".$found" = .0; then
+changequote(, )dnl
+                for file in x `find $with_$2 -name "$4" -type f -print`; do
+                    test .$file = .x && continue
+                    dir=`echo $file | sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;'`
+                    CPPFLAGS="$CPPFLAGS -I$dir"
+                    CFLAGS="$CFLAGS -I$dir"
+                done
+                for file in x `find $with_$2 -name "lib$2.[aso]" -type f -print`; do
+                    test .$file = .x && continue
+                    dir=`echo $file | sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;'`
+                    LDFLAGS="$LDFLAGS -L$dir"
+                done
+changequote([, ])dnl
+            fi
+        fi
+    fi
+    AC_HAVE_HEADERS($4)
+    AC_CHECK_LIB($2, $3)
+    with_$2=yes
+    ac_var="ac_cv_header_`echo $4 | sed 'y%./+-%__p_%'`"
+    eval "ac_val=\$$ac_var"
+    if test ".$ac_val" != .yes; then
+        with_$2=no
+    fi
+    if test ".$ac_cv_lib_$2_$3" != .yes; then
+        with_$2=no
+    fi
+    if test ".$with_$2" = .no; then
+        AC_ERROR([Unable to find $1 library])
+    fi
+    ], [dnl
+if test ".$with_$2" = .; then
+    with_$2=no
+fi
+    ])dnl
+AC_MSG_CHECKING(whether to build against external $1 library)
+if test ".$with_$2" = .yes; then
+    ifelse([$5], , :, [$5])
+else
+    ifelse([$6], , :, [$6])
+fi
+AC_MSG_RESULT([$with_$2])
+])dnl
+


ossp-pkg/sa/configure.ac 1.7 -> 1.8

--- configure.ac 2001/10/31 19:58:00     1.7
+++ configure.ac 2002/01/30 16:43:00     1.8
@@ -47,6 +47,8 @@
 sinclude(sa.ac)
 SA_CHECK_ALL
 
+AC_CHECK_EXTLIB([OSSP ex], ex, __ex_ctx, ex.h, [AC_DEFINE(WITH_EX)])
+
 AC_CONFIG_HEADERS(config.h)
 AC_CONFIG_FILES(Makefile sa-config)
 AC_OUTPUT


ossp-pkg/sa/sa.c 1.54 -> 1.55

--- sa.c 2002/01/29 12:48:28     1.54
+++ sa.c 2002/01/30 16:43:00     1.55
@@ -53,6 +53,19 @@
 /* include own API header */
 #include "sa.h"
 
+/* unique library identifier */
+const char sa_id[] = "OSSP sa";
+
+/* support for OSSP ex based exception throwing */
+#ifdef WITH_EX
+#include "ex.h"
+#define SA_RC(rv) \
+    (  (rv) != SA_OK && (ex_catching && !ex_shielding) \
+     ? (ex_throw(sa_id, NULL, (rv)), (rv)) : (rv) )
+#else
+#define SA_RC(rv) (rv)
+#endif /* WITH_EX */
+
 /* boolean values */
 #ifndef FALSE
 #define FALSE (0)
@@ -400,11 +413,11 @@
 
     /* argument sanity check(s) */
     if (saap == NULL)
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     /* allocate and initialize new address object */
     if ((saa = (sa_addr_t *)malloc(sizeof(sa_addr_t))) == NULL)
-        return SA_ERR_MEM;
+        return SA_RC(SA_ERR_MEM);
     saa->nFamily = 0;
     saa->saBuf   = NULL;
     saa->slBuf   = 0;
@@ -420,7 +433,7 @@
 {
     /* argument sanity check(s) */
     if (saa == NULL)
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     /* free address objects and sub-object(s) */
     if (saa->saBuf != NULL)
@@ -458,7 +471,7 @@
 
     /* argument sanity check(s) */
     if (saa == NULL || uri == NULL)
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     /* on-the-fly create or just take over URI */
     va_start(ap, uri);
@@ -485,12 +498,12 @@
         /* fill-in socket address structure */
         n = strlen(cpPath);
         if (n == 0)
-            return SA_ERR_ARG;
+            return SA_RC(SA_ERR_ARG);
         if ((n+1) > sizeof(un.sun_path))
-            return SA_ERR_MEM;
+            return SA_RC(SA_ERR_MEM);
         if (cpPath[0] != '/') {
             if (getcwd(un.sun_path, sizeof(un.sun_path)-(n+1)) == NULL)
-                return SA_ERR_MEM;
+                return SA_RC(SA_ERR_MEM);
             cp = un.sun_path + strlen(un.sun_path);
         }
         else
@@ -510,22 +523,22 @@
         if (cpHost[0] == '[') {
             /* IPv6 address (see RFC2732) */
 #ifndef AF_INET6
-            return SA_ERR_IMP;
+            return SA_RC(SA_ERR_IMP);
 #else
             bIPv6 = TRUE;
             cpHost++;
             if ((cp = strchr(cpHost, ']')) == NULL)
-                return SA_ERR_ARG;
+                return SA_RC(SA_ERR_ARG);
             *cp++ = '\0';
             if (*cp != ':')
-                return SA_ERR_ARG;
+                return SA_RC(SA_ERR_ARG);
             cp++;
 #endif
         }
         else {
             /* IPv4 address or hostname */
             if ((cp = strrchr(cpHost, ':')) == NULL)
-                return SA_ERR_ARG;
+                return SA_RC(SA_ERR_ARG);
             *cp++ = '\0';
         }
         cpPort = cp;
@@ -548,7 +561,7 @@
             nPort = (unsigned int)atoi(cpPort);
         else {
             if ((se = getservbyname(cpPort, cpProto)) == NULL)
-                return SA_ERR_SYS;
+                return SA_RC(SA_ERR_SYS);
             nPort = ntohs(se->s_port);
         }
 
@@ -598,19 +611,19 @@
             }
 #endif
             else
-                return SA_ERR_ARG;
+                return SA_RC(SA_ERR_ARG);
         }
         else
-            return SA_ERR_ARG;
+            return SA_RC(SA_ERR_ARG);
     }
     else
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     /* fill-in result address structure */
     if (saa->saBuf != NULL)
         free(saa->saBuf);
     if ((saa->saBuf = (struct sockaddr *)malloc(sl)) == NULL)
-        return SA_ERR_MEM;
+        return SA_RC(SA_ERR_MEM);
     memcpy(saa->saBuf, sa, sl);
     saa->slBuf = sl;
     saa->nFamily = sf;
@@ -623,7 +636,7 @@
 {
     /* argument sanity check(s) */
     if (saa == NULL || sabuf == NULL || salen == 0)
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     /* make sure we import only supported addresses */
     if (!(   sabuf->sa_family == AF_LOCAL
@@ -632,13 +645,13 @@
           || sabuf->sa_family == AF_INET6
 #endif
          ))
-        return SA_ERR_USE;
+        return SA_RC(SA_ERR_USE);
 
     /* create result address structure */
     if (saa->saBuf != NULL)
         free(saa->saBuf);
     if ((saa->saBuf = (struct sockaddr *)malloc(salen)) == NULL)
-        return SA_ERR_MEM;
+        return SA_RC(SA_ERR_MEM);
     memcpy(saa->saBuf, sabuf, salen);
     saa->slBuf = salen;
 
@@ -662,7 +675,7 @@
 
     /* argument sanity check(s) */
     if (saa == NULL || uri == NULL)
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     /* export object contents */
     if (saa->nFamily == AF_LOCAL) {
@@ -693,7 +706,7 @@
     }
 #endif
     else
-        return SA_ERR_INT;
+        return SA_RC(SA_ERR_INT);
 
     /* pass result to caller */
     *uri = strdup(uribuf);
@@ -706,11 +719,11 @@
 {
     /* argument sanity check(s) */
     if (saa == NULL || sabuf == NULL || salen == 0)
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     /* export underlying address structure */
     if ((*sabuf = (struct sockaddr *)malloc(saa->slBuf)) == NULL)
-        return SA_ERR_MEM;
+        return SA_RC(SA_ERR_MEM);
     memmove(*sabuf, saa->saBuf, saa->slBuf);
     *salen = saa->slBuf;
 
@@ -733,7 +746,7 @@
 
     /* argument sanity check(s) */
     if (saa1 == NULL || saa2 == NULL)
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     /* short circuiting for wildcard matching */
     if (prefixlen == 0)
@@ -749,12 +762,12 @@
         l2 = strlen(((struct sockaddr_un *)saa2->saBuf)->sun_path) * 8;
         if (prefixlen < 0) {
             if (l1 != l2)
-                return SA_ERR_MTC;
+                return SA_RC(SA_ERR_MTC);
             nBits = l1;
         }
         else {
             if (l1 < prefixlen || l2 < prefixlen)
-                return SA_ERR_MTC;
+                return SA_RC(SA_ERR_MTC);
             nBits = prefixlen;
         }
     }
@@ -781,9 +794,9 @@
         }
         for (i = 0; i < 10; i++)
             if (ucp0[i] != 0x00)
-                return SA_ERR_MTC;
+                return SA_RC(SA_ERR_MTC);
         if (!(ucp0[10] == 0xFF && ucp0[11] == 0xFF))
-            return SA_ERR_MTC;
+            return SA_RC(SA_ERR_MTC);
         nBits = 32;
     }
 #endif
@@ -804,11 +817,11 @@
 #endif
     }
     else
-        return SA_ERR_INT;
+        return SA_RC(SA_ERR_INT);
 
     /* make sure we do not compare than possible */
     if (prefixlen > (nBits+1))
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     /* support equal matching (= all bits plus optionally port) */
     bMatchPort = FALSE;
@@ -824,20 +837,20 @@
     nBits  = (prefixlen % 8);
     if (nBytes > 0) {
         if (memcmp(ucp1, ucp2, nBytes) != 0)
-            return SA_ERR_MTC;
+            return SA_RC(SA_ERR_MTC);
     }
     if (nBits > 0) {
         uc1 = ucp1[nBytes];
         uc2 = ucp2[nBytes];
         mask = (0xFF << (8-nBits)) & 0xFF;
         if ((uc1 & mask) != (uc2 & mask))
-            return SA_ERR_MTC;
+            return SA_RC(SA_ERR_MTC);
     }
 
     /* optionally perform additional port matching */
     if (bMatchPort)
         if (np1 != np2)
-            return SA_ERR_MTC;
+            return SA_RC(SA_ERR_MTC);
 
     return SA_OK;
 }
@@ -851,13 +864,13 @@
             if (setsockopt(sa->fdSocket, SOL_SOCKET, SO_RCVTIMEO,
                            &sa->tvTimeout[SA_TIMEOUT_READ],
                            sizeof(sa->tvTimeout[SA_TIMEOUT_READ])) < 0)
-                return SA_ERR_SYS;
+                return SA_RC(SA_ERR_SYS);
         }
         if (SA_TVISZERO(sa->tvTimeout[SA_TIMEOUT_WRITE])) {
             if (setsockopt(sa->fdSocket, SOL_SOCKET, SO_SNDTIMEO,
                            &sa->tvTimeout[SA_TIMEOUT_WRITE],
                            sizeof(sa->tvTimeout[SA_TIMEOUT_WRITE])) < 0)
-                return SA_ERR_SYS;
+                return SA_RC(SA_ERR_SYS);
         }
     }
 #endif
@@ -875,11 +888,11 @@
 
     /* argument sanity check(s) */
     if (sa == NULL)
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     /* only perform operation if socket still does not exist */
     if (sa->fdSocket != -1)
-        return SA_ERR_USE;
+        return SA_RC(SA_ERR_USE);
 
     /* determine socket type */
     if (sa->eType == SA_TYPE_STREAM)
@@ -887,7 +900,7 @@
     else if (sa->eType == SA_TYPE_DATAGRAM)
         nType = SOCK_DGRAM;
     else
-        return SA_ERR_INT;
+        return SA_RC(SA_ERR_INT);
 
     /* determine socket protocol */
     if (nFamily == AF_LOCAL) 
@@ -903,25 +916,25 @@
         else if (nType == SOCK_DGRAM)
             nProto = IPPROTO_UDP;
         else
-            return SA_ERR_INT;
+            return SA_RC(SA_ERR_INT);
 #else
         if (nType == SOCK_STREAM)
             pe = getprotobyname("tcp");
         else if (nType == SOCK_DGRAM)
             pe = getprotobyname("udp");
         else
-            return SA_ERR_INT;
+            return SA_RC(SA_ERR_INT);
         if (pe == NULL)
-            return SA_ERR_SYS;
+            return SA_RC(SA_ERR_SYS);
         nProto = pe->p_proto;
 #endif
     }
     else
-        return SA_ERR_INT;
+        return SA_RC(SA_ERR_INT);
 
     /* create the underlying socket */
     if ((sa->fdSocket = socket(nFamily, nType, nProto)) == -1)
-        return SA_ERR_SYS;
+        return SA_RC(SA_ERR_SYS);
 
     /* optionally set kernel timeouts */
     sa_socket_settimeouts(sa);
@@ -934,11 +947,11 @@
 {
     /* argument sanity check(s) */
     if (sa == NULL)
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     /* check context */
     if (sa->fdSocket == -1)
-        return SA_ERR_USE;
+        return SA_RC(SA_ERR_USE);
 
     /* close socket */
     close(sa->fdSocket);
@@ -955,11 +968,11 @@
 
     /* argument sanity check(s) */
     if (sap == NULL)
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     /* allocate and initialize socket object */
     if ((sa = (sa_t *)malloc(sizeof(sa_t))) == NULL)
-        return SA_ERR_MEM;
+        return SA_RC(SA_ERR_MEM);
 
     /* init object attributes */
     sa->eType          = SA_TYPE_STREAM;
@@ -997,7 +1010,7 @@
 {
     /* argument sanity check(s) */
     if (sa == NULL)
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     /* kill underlying socket */
     sa_socket_kill(sa);
@@ -1017,9 +1030,9 @@
 {
     /* argument sanity check(s) */
     if (sa == NULL)
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
     if (!(type == SA_TYPE_STREAM || type == SA_TYPE_DATAGRAM))
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     /* kill underlying socket if type changes */
     if (sa->eType != type)
@@ -1038,7 +1051,7 @@
 
     /* argument sanity check(s) */
     if (sa == NULL)
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     if (id == SA_TIMEOUT_ALL) {
         for (i = 0; i < (sizeof(sa->tvTimeout)/sizeof(sa->tvTimeout[0])); i++) {
@@ -1064,19 +1077,19 @@
 
     /* argument sanity check(s) */
     if (sa == NULL)
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     if (id == SA_BUFFER_READ) {
         /* configure read/incoming buffer */
         if (sa->nReadLen > size)
-            return SA_ERR_USE;
+            return SA_RC(SA_ERR_USE);
         if (size > 0) {
             if (sa->cpReadBuf == NULL)
                 cp = (char *)malloc(size);
             else
                 cp = (char *)realloc(sa->cpReadBuf, size);
             if (cp == NULL)
-                return SA_ERR_SYS;
+                return SA_RC(SA_ERR_SYS);
             sa->cpReadBuf = cp;
             sa->nReadSize = size;
         }
@@ -1090,14 +1103,14 @@
     else if (id == SA_BUFFER_WRITE) {
         /* configure write/outgoing buffer */
         if (sa->nWriteLen > size)
-            return SA_ERR_USE;
+            return SA_RC(SA_ERR_USE);
         if (size > 0) {
             if (sa->cpWriteBuf == NULL)
                 cp = (char *)malloc(size);
             else
                 cp = (char *)realloc(sa->cpWriteBuf, size);
             if (cp == NULL)
-                return SA_ERR_SYS;
+                return SA_RC(SA_ERR_SYS);
             sa->cpWriteBuf = cp;
             sa->nWriteSize = size;
         }
@@ -1109,7 +1122,7 @@
         }
     }
     else
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     return SA_OK;
 }
@@ -1122,7 +1135,7 @@
 
     /* argument sanity check(s) */
     if (sa == NULL)
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     /* process option */
     rv = SA_OK;
@@ -1209,7 +1222,7 @@
     }
     va_end(ap);
 
-    return rv;
+    return SA_RC(rv);
 }
 
 /* override system call */
@@ -1219,7 +1232,7 @@
 
     /* argument sanity check(s) */
     if (sa == NULL || fptr == NULL)
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     /* assign system call */
     rv = SA_OK;
@@ -1234,7 +1247,7 @@
         default: rv = SA_ERR_ARG; 
     }
 
-    return rv;
+    return SA_RC(rv);
 }
 
 /* bind socket to a local address */
@@ -1245,12 +1258,12 @@
 
     /* argument sanity check(s) */
     if (sa == NULL || laddr == NULL)
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     /* lazy creation of underlying socket */
     if (sa->fdSocket == -1)
         if ((rv = sa_socket_init(sa, laddr->nFamily)) != SA_OK)
-            return rv;
+            return SA_RC(rv);
 
     /* remove a possibly existing old Unix Domain socket on filesystem */
     if (laddr->nFamily == AF_LOCAL) {
@@ -1260,7 +1273,7 @@
 
     /* perform bind operation on underlying socket */
     if (bind(sa->fdSocket, laddr->saBuf, laddr->slBuf) == -1)
-        return SA_ERR_SYS;
+        return SA_RC(SA_ERR_SYS);
 
     return SA_OK;
 }
@@ -1275,16 +1288,16 @@
 
     /* argument sanity check(s) */
     if (sa == NULL || raddr == NULL)
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     /* connecting is only possible for stream communication */ 
     if (sa->eType != SA_TYPE_STREAM)
-        return SA_ERR_USE;
+        return SA_RC(SA_ERR_USE);
 
     /* lazy creation of underlying socket */
     if (sa->fdSocket == -1)
         if ((rv = sa_socket_init(sa, raddr->nFamily)) != SA_OK)
-            return rv;
+            return SA_RC(rv);
 
     rv = SA_OK;
     if (SA_TVISZERO(sa->tvTimeout[SA_TIMEOUT_CONNECT])) {
@@ -1352,7 +1365,7 @@
             rv = SA_ERR_SYS;
         }
     }
-    return rv;
+    return SA_RC(rv);
 }
 
 /* listen on socket for connections */
@@ -1360,19 +1373,19 @@
 {
     /* argument sanity check(s) */
     if (sa == NULL)
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     /* listening is only possible for stream communication */ 
     if (sa->eType != SA_TYPE_STREAM)
-        return SA_ERR_USE;
+        return SA_RC(SA_ERR_USE);
 
     /* at least sa_bind() has to be already performed */
     if (sa->fdSocket == -1)
-        return SA_ERR_USE;
+        return SA_RC(SA_ERR_USE);
 
     /* perform listen operation on underlying socket */
     if (listen(sa->fdSocket, backlog) == -1)
-        return SA_ERR_SYS;
+        return SA_RC(SA_ERR_SYS);
 
     return SA_OK;
 }
@@ -1396,15 +1409,15 @@
 
     /* argument sanity check(s) */
     if (sa == NULL || caddr == NULL || csa == NULL)
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     /* accepting connections is only possible for stream communication */ 
     if (sa->eType != SA_TYPE_STREAM)
-        return SA_ERR_USE;
+        return SA_RC(SA_ERR_USE);
 
     /* at least sa_listen() has to be already performed */
     if (sa->fdSocket == -1)
-        return SA_ERR_USE;
+        return SA_RC(SA_ERR_USE);
 
     /* if timeout is enabled, perform a smart-blocking wait */
     if (!SA_TVISZERO(sa->tvTimeout[SA_TIMEOUT_ACCEPT])) {
@@ -1415,28 +1428,28 @@
                              &sa->tvTimeout[SA_TIMEOUT_ACCEPT]);
         } while (n == -1 && errno == EINTR);
         if (n == 0) 
-            return SA_ERR_TMT;
+            return SA_RC(SA_ERR_TMT);
         if (n <= 0)
-            return SA_ERR_SYS;
+            return SA_RC(SA_ERR_SYS);
     }
 
     /* perform accept operation on underlying socket */
     sa_len = sizeof(sa_buf);
     if ((s = SA_SC_CALL_3(sa, accept, sa->fdSocket, (struct sockaddr *)&sa_buf, &sa_len)) == -1)
-        return SA_ERR_SYS;
+        return SA_RC(SA_ERR_SYS);
 
     /* create result address object */
     if ((rv = sa_addr_create(caddr)) != SA_OK)
-        return rv;
+        return SA_RC(rv);
     if ((rv = sa_addr_s2a(*caddr, (struct sockaddr *)&sa_buf, sa_len)) != SA_OK) {
         sa_addr_destroy(*caddr);
-        return rv;
+        return SA_RC(rv);
     }
 
     /* create result socket object */
     if ((rv = sa_create(csa)) != SA_OK) {
         sa_addr_destroy(*caddr);
-        return rv;
+        return SA_RC(rv);
     }
 
     /* fill-in child socket */
@@ -1474,27 +1487,27 @@
 
     /* argument sanity check(s) */
     if (sa == NULL || raddr == NULL)
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     /* peers exist only for stream communication */ 
     if (sa->eType != SA_TYPE_STREAM)
-        return SA_ERR_USE;
+        return SA_RC(SA_ERR_USE);
 
     /* at least sa_connect() or sa_accept() has to be already performed */
     if (sa->fdSocket == -1)
-        return SA_ERR_USE;
+        return SA_RC(SA_ERR_USE);
 
     /* determine remote address of underlying socket */
     sa_len = sizeof(sa_buf);
     if (getpeername(sa->fdSocket, (struct sockaddr *)&sa_buf, &sa_len) < 0)
-        return SA_ERR_SYS;
+        return SA_RC(SA_ERR_SYS);
 
     /* create result address object */
     if ((rv = sa_addr_create(raddr)) != SA_OK)
-        return rv;
+        return SA_RC(rv);
     if ((rv = sa_addr_s2a(*raddr, (struct sockaddr *)&sa_buf, sa_len)) != SA_OK) {
         sa_addr_destroy(*raddr);
-        return rv;
+        return SA_RC(rv);
     }
 
     return SA_OK;
@@ -1514,23 +1527,23 @@
 
     /* argument sanity check(s) */
     if (sa == NULL || laddr == NULL)
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     /* at least sa_bind() has to be already performed */
     if (sa->fdSocket == -1)
-        return SA_ERR_USE;
+        return SA_RC(SA_ERR_USE);
 
     /* determine local address of underlying socket */
     sa_len = sizeof(sa_buf);
     if (getsockname(sa->fdSocket, (struct sockaddr *)&sa_buf, &sa_len) < 0)
-        return SA_ERR_SYS;
+        return SA_RC(SA_ERR_SYS);
 
     /* create result address object */
     if ((rv = sa_addr_create(laddr)) != SA_OK)
-        return rv;
+        return SA_RC(rv);
     if ((rv = sa_addr_s2a(*laddr, (struct sockaddr *)&sa_buf, sa_len)) != SA_OK) {
         sa_addr_destroy(*laddr);
-        return rv;
+        return SA_RC(rv);
     }
 
     return SA_OK;
@@ -1541,11 +1554,11 @@
 {
     /* argument sanity check(s) */
     if (sa == NULL || fd == NULL)
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     /* if still no socket exists, say this explicitly */
     if (sa->fdSocket == -1)
-        return SA_ERR_USE;
+        return SA_RC(SA_ERR_USE);
 
     /* pass socket to caller */
     *fd = sa->fdSocket;
@@ -1600,15 +1613,15 @@
 
     /* argument sanity check(s) */
     if (sa == NULL || cpBuf == NULL || nBufReq == 0)
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     /* reading is only possible for stream communication */ 
     if (sa->eType != SA_TYPE_STREAM)
-        return SA_ERR_USE;
+        return SA_RC(SA_ERR_USE);
 
     /* at least a connection has to exist */
     if (sa->fdSocket == -1)
-        return SA_ERR_USE;
+        return SA_RC(SA_ERR_USE);
 
     /* perform read operation */
     rv = SA_OK;
@@ -1684,7 +1697,7 @@
     if (nBufRes != NULL)
         *nBufRes = (size_t)res;
 
-    return rv;
+    return SA_RC(rv);
 }
 
 /* read data from socket until [CR]LF (convinience function) */
@@ -1697,15 +1710,15 @@
 
     /* argument sanity check(s) */
     if (sa == NULL || cpBuf == NULL || nBufReq == 0)
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     /* reading is only possible for stream communication */ 
     if (sa->eType != SA_TYPE_STREAM)
-        return SA_ERR_USE;
+        return SA_RC(SA_ERR_USE);
 
     /* at least a connection has to exist */
     if (sa->fdSocket == -1)
-        return SA_ERR_USE;
+        return SA_RC(SA_ERR_USE);
 
     /* we just perform a plain sa_read() per character, because if
        buffers are enabled, this is not as stupid as it looks at the first
@@ -1729,7 +1742,7 @@
     if (nBufRes != NULL)
         *nBufRes = res;
 
-    return rv;
+    return SA_RC(rv);
 }
 
 /* internal raw write operation */
@@ -1779,15 +1792,15 @@
 
     /* argument sanity check(s) */
     if (sa == NULL || cpBuf == NULL || nBufReq == 0)
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     /* writing is only possible for stream communication */ 
     if (sa->eType != SA_TYPE_STREAM)
-        return SA_ERR_USE;
+        return SA_RC(SA_ERR_USE);
 
     /* at least a connection has to exist */
     if (sa->fdSocket == -1)
-        return SA_ERR_USE;
+        return SA_RC(SA_ERR_USE);
 
     rv = SA_OK;
     if (sa->nWriteSize == 0) {
@@ -1832,7 +1845,7 @@
     if (nBufRes != NULL)
         *nBufRes = (size_t)res;
 
-    return rv;
+    return SA_RC(rv);
 }
 
 /* output callback function context for sa_writef() */
@@ -1861,15 +1874,15 @@
 
     /* argument sanity check(s) */
     if (sa == NULL || cpFmt == NULL)
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     /* writing is only possible for stream communication */ 
     if (sa->eType != SA_TYPE_STREAM)
-        return SA_ERR_USE;
+        return SA_RC(SA_ERR_USE);
 
     /* at least a connection has to exist */
     if (sa->fdSocket == -1)
-        return SA_ERR_USE;
+        return SA_RC(SA_ERR_USE);
 
     /* format string into temporary buffer */
     va_start(ap, cpFmt);
@@ -1889,15 +1902,15 @@
 
     /* argument sanity check(s) */
     if (sa == NULL)
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     /* flushing is only possible for stream communication */ 
     if (sa->eType != SA_TYPE_STREAM)
-        return SA_ERR_USE;
+        return SA_RC(SA_ERR_USE);
 
     /* at least a connection has to exist */
     if (sa->fdSocket == -1)
-        return SA_ERR_USE;
+        return SA_RC(SA_ERR_USE);
 
     /* try to flush buffer */
     rv = SA_OK;
@@ -1915,7 +1928,7 @@
         }
         sa->nWriteLen = 0;
     }
-    return rv;
+    return SA_RC(rv);
 }
 
 /* shutdown a socket connection */
@@ -1925,15 +1938,15 @@
 
     /* argument sanity check(s) */
     if (sa == NULL || flags == NULL)
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     /* shutdown is only possible for stream communication */ 
     if (sa->eType != SA_TYPE_STREAM)
-        return SA_ERR_USE;
+        return SA_RC(SA_ERR_USE);
 
     /* at least a connection has to exist */
     if (sa->fdSocket == -1)
-        return SA_ERR_USE;
+        return SA_RC(SA_ERR_USE);
 
     /* determine flags for shutdown(2) */
     how = 0;
@@ -1944,11 +1957,11 @@
     else if (strcmp(flags, "rw") == 0)
         how = SHUT_RDWR;
     else
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     /* perform shutdown operation on underlying socket */
     if (shutdown(sa->fdSocket, how) == -1)
-        return SA_ERR_SYS;
+        return SA_RC(SA_ERR_SYS);
 
     return SA_OK;
 }
@@ -1969,15 +1982,15 @@
 
     /* argument sanity check(s) */
     if (sa == NULL || buf == NULL || buflen == 0 || raddr == NULL)
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     /* receiving is only possible for datagram communication */ 
     if (sa->eType != SA_TYPE_DATAGRAM)
-        return SA_ERR_USE;
+        return SA_RC(SA_ERR_USE);
 
     /* at least a sa_bind() has to be performed */
     if (sa->fdSocket == -1)
-        return SA_ERR_USE;
+        return SA_RC(SA_ERR_USE);
 
     /* if timeout is enabled, perform explicit/smart blocking instead 
        of implicitly/hard blocking in the recvfrom(2) system call */
@@ -1991,14 +2004,14 @@
         if (n == 0) 
             errno = ETIMEDOUT;
         if (n <= 0)
-            return SA_ERR_SYS;
+            return SA_RC(SA_ERR_SYS);
     }
 
     /* perform receive operation on underlying socket */
     sa_len = sizeof(sa_buf);
     if ((n = SA_SC_CALL_6(sa, recvfrom, sa->fdSocket, buf, buflen, 0, 
                           (struct sockaddr *)&sa_buf, &sa_len)) == -1)
-        return SA_ERR_SYS;
+        return SA_RC(SA_ERR_SYS);
 
     /* create result address object */
     if ((rv = sa_addr_create(raddr)) != SA_OK)
@@ -2024,11 +2037,11 @@
 
     /* argument sanity check(s) */
     if (sa == NULL || buf == NULL || buflen == 0 || raddr == NULL)
-        return SA_ERR_ARG;
+        return SA_RC(SA_ERR_ARG);
 
     /* sending is only possible for datagram communication */ 
     if (sa->eType != SA_TYPE_DATAGRAM)
-        return SA_ERR_USE;
+        return SA_RC(SA_ERR_USE);
 
     /* lazy creation of underlying socket */
     if (sa->fdSocket == -1)
@@ -2047,12 +2060,12 @@
         if (n == 0) 
             errno = ETIMEDOUT;
         if (n <= 0)
-            return SA_ERR_SYS;
+            return SA_RC(SA_ERR_SYS);
     }
 
     /* perform send operation on underlying socket */
     if ((n = SA_SC_CALL_6(sa, sendto, sa->fdSocket, buf, buflen, 0, raddr->saBuf, raddr->slBuf)) == -1)
-        return SA_ERR_SYS;
+        return SA_RC(SA_ERR_SYS);
 
     /* pass actual number of sent bytes to caller */
     if (bufdone != NULL)


ossp-pkg/sa/sa.h 1.28 -> 1.29

--- sa.h 2002/01/02 13:44:48     1.28
+++ sa.h 2002/01/30 16:43:00     1.29
@@ -155,6 +155,9 @@
     SA_SYSCALL_SENDTO
 } sa_syscall_t;
 
+/* unique library identifier */
+extern const char sa_id[];
+
 /* address object operations */
 sa_rc_t sa_addr_create  (sa_addr_t **saa);
 sa_rc_t sa_addr_destroy (sa_addr_t *saa);


ossp-pkg/sa/sa_test.c 1.13 -> 1.14

--- sa_test.c    2002/01/02 12:43:50     1.13
+++ sa_test.c    2002/01/30 16:43:00     1.14
@@ -28,6 +28,10 @@
 **  sa_test.c: socket abstraction library test suite
 */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
@@ -145,6 +149,32 @@
     /* FIXME */
 }
 
+/* test: exception handling */
+#ifdef WITH_EX
+#include "ex.h"
+TS_TEST(test_sa_ex)
+{
+    sa_addr_t *saa;
+    ex_t ex;
+    int caught;
+
+    ts_test_check(TS_CTX, "exception handling");
+    caught = 0;
+    ex_try {
+        sa_addr_create(&saa);
+        sa_addr_u2a(saa, "inet:DUMMY");
+        sa_addr_destroy(saa);
+    }
+    ex_catch (ex) {
+        if ((sa_rc_t)ex.ex_value != SA_ERR_ARG)
+            ts_test_fail(TS_CTX, "unexpected exception: %d\n", (sa_rc_t)ex.ex_value);
+        caught = 1;
+    }
+    if (!caught)
+        ts_test_fail(TS_CTX, "expected exception not caught\n");
+}
+#endif
+
 int main(int argc, char *argv[])
 {
     ts_suite_t *ts;
@@ -155,6 +185,9 @@
     ts_suite_test(ts, test_saa_match,   "socket address abstraction matching");
     ts_suite_test(ts, test_sa_stream,   "socket abstraction stream communication");
     ts_suite_test(ts, test_sa_datagram, "socket abstraction datagram communication");
+#ifdef WITH_EX
+    ts_suite_test(ts, test_sa_ex,       "exception handling");
+#endif
     n = ts_suite_run(ts);
     ts_suite_free(ts);
     return n;

CVSTrac 2.0.1