OSSP CVS Repository

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

Check-in Number: 1067
Date: 2001-Oct-04 13:25:44 (local)
2001-Oct-04 11:25:44 (UTC)
User:rse
Branch:
Comment: Change sa_addr_t API: - there is now a constructor and destructor - renamed sa_x2x functions to sa_addr_x2x
Tickets:
Inspections:
Files:
ossp-pkg/sa/TODO      1.1 -> 1.2     0 inserted, 1 deleted
ossp-pkg/sa/sa.c      1.2 -> 1.3     59 inserted, 28 deleted
ossp-pkg/sa/sa.h      1.3 -> 1.4     33 inserted, 29 deleted

ossp-pkg/sa/TODO 1.1 -> 1.2

--- TODO 2001/10/02 13:27:45     1.1
+++ TODO 2001/10/04 11:25:44     1.2
@@ -13,5 +13,4 @@
 - Unix domain sockets support
 - aufpassen dasz fuer read/write STREAM socket ist
 - aufpassen dasz fuer readfrom/writeto DGRAM socket ist
-- destructor fuer sa_addr_t?
 


ossp-pkg/sa/sa.c 1.2 -> 1.3

--- sa.c 2001/10/03 19:40:31     1.2
+++ sa.c 2001/10/04 11:25:44     1.3
@@ -190,7 +190,30 @@
     return chars;
 }
 
-sa_rc_t sa_u2a(sa_addr_t **saa, const char *uri, ...)
+sa_rc_t sa_addr_create(sa_addr_t **saa)
+{
+    if (saa == NULL)
+        return SA_ERR_ARG;
+    if ((*saa = (sa_addr_t *)malloc(sizeof(sa_addr_t))) == NULL)
+        return SA_ERR_MEM;
+    (*saa)->saBuf   = NULL;
+    (*saa)->slBuf   = 0;
+    (*saa)->nFamily = 0;
+    (*saa)->nProto   = 0;
+    return SA_OK;
+}
+
+sa_rc_t sa_addr_destroy(sa_addr_t *saa)
+{
+    if (saa == NULL)
+        return SA_ERR_ARG;
+    if (saa->saBuf != NULL)
+        free(saa->saBuf);
+    free(saa);
+    return SA_OK;
+}
+
+sa_rc_t sa_addr_u2a(sa_addr_t *saa, const char *uri, ...)
 {
     va_list ap;
     int nPort;
@@ -308,20 +331,16 @@
         return SA_ERR_ARG;
         
     /* create result address structure */
-    if ((*saa = (sa_addr_t *)malloc(sizeof(sa_addr_t))) == NULL)
+    if ((saa->saBuf = (struct sockaddr *)malloc(sl)) == NULL)
         return SA_ERR_MEM;
-    if (((*saa)->saBuf = (struct sockaddr *)malloc(sl)) == NULL) {
-        free(*saa);
-        return SA_ERR_MEM;
-    }
-    memcpy((*saa)->saBuf, sa, sl);
-    (*saa)->slBuf = sl;
-    (*saa)->nFamily = sf;
-    (*saa)->nProto = nProto;
+    memcpy(saa->saBuf, sa, sl);
+    saa->slBuf = sl;
+    saa->nFamily = sf;
+    saa->nProto = nProto;
     return SA_OK;
 }
 
-sa_rc_t sa_s2a(sa_addr_t **saa, const struct sockaddr *sabuf, socklen_t salen)
+sa_rc_t sa_addr_s2a(sa_addr_t *saa, const struct sockaddr *sabuf, socklen_t salen)
 {
     struct sockaddr_in *sa4;
 #ifdef AF_INET6
@@ -334,14 +353,10 @@
         return SA_ERR_ARG;
 
     /* create result address structure */
-    if ((*saa = (sa_addr_t *)malloc(sizeof(sa_addr_t))) == NULL)
-        return SA_ERR_MEM;
-    if (((*saa)->saBuf = (struct sockaddr *)malloc(salen)) == NULL) {
-        free(*saa);
+    if ((saa->saBuf = (struct sockaddr *)malloc(salen)) == NULL)
         return SA_ERR_MEM;
-    }
-    memcpy((*saa)->saBuf, sabuf, salen);
-    (*saa)->slBuf = salen;
+    memcpy(saa->saBuf, sabuf, salen);
+    saa->slBuf = salen;
 
     /* fill in family */
     sf = 0;
@@ -357,17 +372,17 @@
             sf = AF_INET6;
     }
 #endif
-    (*saa)->nFamily = sf;
+    saa->nFamily = sf;
 
     /* fill in protocol */
     if ((pe = getprotobyname("tcp")) != NULL)
-        (*saa)->nProto = pe->p_proto;
+        saa->nProto = pe->p_proto;
     else
-        (*saa)->nProto = 0;
+        saa->nProto = 0;
     return SA_OK;
 }
 
-sa_rc_t sa_a2u(const sa_addr_t *saa, char **uri)
+sa_rc_t sa_addr_a2u(sa_addr_t *saa, char **uri)
 {
     char uribuf[1024];
     struct protoent *pe;
@@ -401,7 +416,7 @@
     return SA_OK;
 }
 
-sa_rc_t sa_a2s(const sa_addr_t *saa, struct sockaddr **sabuf, socklen_t *salen)
+sa_rc_t sa_addr_a2s(sa_addr_t *saa, struct sockaddr **sabuf, socklen_t *salen)
 {
     if (saa == NULL || sabuf == NULL || salen == 0)
         return SA_ERR_ARG;
@@ -674,10 +689,14 @@
     sa_len = sizeof(sa_buf);
     if ((s = accept(sa->sSocket, (struct sockaddr *)&sa_buf, &sa_len)) == -1)
         return SA_ERR_SYS;
-    if ((rv = sa_s2a(caddr, (struct sockaddr *)&sa_buf, sa_len)) != SA_OK)
+    if ((rv = sa_addr_create(caddr)) != SA_OK)
+        return rv;
+    if ((rv = sa_addr_s2a(*caddr, (struct sockaddr *)&sa_buf, sa_len)) != SA_OK) {
+        sa_addr_destroy(*caddr);
         return rv;
+    }
     if ((rv = sa_create(csa)) != SA_OK) {
-        free(*caddr);
+        sa_addr_destroy(*caddr);
         return rv;
     }
     (*csa)->sSocket = s;
@@ -700,8 +719,12 @@
     sa_len = sizeof(sa_buf);
     if (getpeername(sa->sSocket, (struct sockaddr *)&sa_buf, &sa_len) < 0)
         return SA_ERR_SYS;
-    if ((rv = sa_s2a(raddr, (struct sockaddr *)&sa_buf, sa_len)) != SA_OK)
+    if ((rv = sa_addr_create(raddr)) != SA_OK)
         return rv;
+    if ((rv = sa_addr_s2a(*raddr, (struct sockaddr *)&sa_buf, sa_len)) != SA_OK) {
+        sa_addr_destroy(*raddr);
+        return rv;
+    }
     return SA_OK;
 }
 
@@ -721,8 +744,12 @@
     sa_len = sizeof(sa_buf);
     if (getsockname(sa->sSocket, (struct sockaddr *)&sa_buf, &sa_len) < 0)
         return SA_ERR_SYS;
-    if ((rv = sa_s2a(laddr, (struct sockaddr *)&sa_buf, sa_len)) != SA_OK)
+    if ((rv = sa_addr_create(laddr)) != SA_OK)
+        return rv;
+    if ((rv = sa_addr_s2a(*laddr, (struct sockaddr *)&sa_buf, sa_len)) != SA_OK) {
+        sa_addr_destroy(*laddr);
         return rv;
+    }
     return SA_OK;
 }
 
@@ -842,8 +869,12 @@
     sa_len = sizeof(sa_buf);
     if ((n = recvfrom(sa->sSocket, buf, buflen, 0, (struct sockaddr *)&sa_buf, &sa_len)) == -1)
         return SA_ERR_SYS;
-    if ((rv = sa_s2a(raddr, (struct sockaddr *)&sa_buf, sa_len)) != SA_OK)
+    if ((rv = sa_addr_create(raddr)) != SA_OK)
+        return rv;
+    if ((rv = sa_addr_s2a(*raddr, (struct sockaddr *)&sa_buf, sa_len)) != SA_OK) {
+        sa_addr_destroy(*raddr);
         return rv;
+    }
     if (bufdone != NULL)
         *bufdone = n;
     return SA_OK;


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

--- sa.h 2001/10/03 19:40:31     1.3
+++ sa.h 2001/10/04 11:25:44     1.4
@@ -92,40 +92,44 @@
     SA_ERR_INT
 } sa_rc_t;
 
+/* address object operations */
+sa_rc_t sa_addr_create  (sa_addr_t **saa);
+sa_rc_t sa_addr_destroy (sa_addr_t *saa);
+
 /* address operations */
-sa_rc_t sa_u2a      (sa_addr_t **saa, const char *uri, ...);
-sa_rc_t sa_s2a      (sa_addr_t **saa, const struct sockaddr *sabuf, socklen_t salen);
-sa_rc_t sa_a2u      (const sa_addr_t *saa, char **uri);
-sa_rc_t sa_a2s      (const sa_addr_t *saa, struct sockaddr **sabuf, socklen_t *salen);
-
-/* object operations */
-sa_rc_t sa_create   (sa_t **sa);
-sa_rc_t sa_destroy  (sa_t *sa);
-
-/* parameter operations */
-sa_rc_t sa_timeout  (sa_t *sa, long sec, long usec);
-sa_rc_t sa_buffers  (sa_t *sa, size_t rsize, size_t wsize);
-sa_rc_t sa_getoption(sa_t *sa, int optname, void *optval, socklen_t *optlen);
-sa_rc_t sa_setoption(sa_t *sa, int optname, const void *optval, socklen_t optlen);
-
-/* connection operations */
-sa_rc_t sa_bind     (sa_t *sa, sa_addr_t *laddr);
-sa_rc_t sa_connect  (sa_t *sa, sa_addr_t *raddr);
-sa_rc_t sa_listen   (sa_t *sa, int backlog);
-sa_rc_t sa_accept   (sa_t *sa, sa_addr_t **caddr, sa_t **csa);
-sa_rc_t sa_getremote(sa_t *sa, sa_addr_t **raddr);
-sa_rc_t sa_getlocal (sa_t *sa, sa_addr_t **laddr);
-sa_rc_t sa_getfd    (sa_t *sa, int *fd);
-sa_rc_t sa_shutdown (sa_t *sa, char *flags);
-
-/* input/output operations */
-sa_rc_t sa_read     (sa_t *sa, char *buf, size_t buflen, size_t *bufdone);
-sa_rc_t sa_readfrom (sa_t *sa, char *buf, size_t buflen, size_t *bufdone, sa_addr_t **raddr);
-sa_rc_t sa_readline (sa_t *sa, char *buf, size_t buflen, size_t *bufdone);
-sa_rc_t sa_write    (sa_t *sa, const char *buf, size_t buflen, size_t *bufdone);
-sa_rc_t sa_writeto  (sa_t *sa, const char *buf, size_t buflen, size_t *bufdone, sa_addr_t *raddr);
-sa_rc_t sa_writef   (sa_t *sa, const char *fmt, ...);
-sa_rc_t sa_flush    (sa_t *sa);
+sa_rc_t sa_addr_u2a     (sa_addr_t *saa, const char *uri, ...);
+sa_rc_t sa_addr_s2a     (sa_addr_t *saa, const struct sockaddr *sabuf, socklen_t salen);
+sa_rc_t sa_addr_a2u     (sa_addr_t *saa, char **uri);
+sa_rc_t sa_addr_a2s     (sa_addr_t *saa, struct sockaddr **sabuf, socklen_t *salen);
+
+/* socket object operations */
+sa_rc_t sa_create       (sa_t **sa);
+sa_rc_t sa_destroy      (sa_t *sa);
+
+/* socket parameter operations */
+sa_rc_t sa_timeout      (sa_t *sa, long sec, long usec);
+sa_rc_t sa_buffers      (sa_t *sa, size_t rsize, size_t wsize);
+sa_rc_t sa_getoption    (sa_t *sa, int optname, void *optval, socklen_t *optlen);
+sa_rc_t sa_setoption    (sa_t *sa, int optname, const void *optval, socklen_t optlen);
+
+/* socket connection operations */
+sa_rc_t sa_bind         (sa_t *sa, sa_addr_t *laddr);
+sa_rc_t sa_connect      (sa_t *sa, sa_addr_t *raddr);
+sa_rc_t sa_listen       (sa_t *sa, int backlog);
+sa_rc_t sa_accept       (sa_t *sa, sa_addr_t **caddr, sa_t **csa);
+sa_rc_t sa_getremote    (sa_t *sa, sa_addr_t **raddr);
+sa_rc_t sa_getlocal     (sa_t *sa, sa_addr_t **laddr);
+sa_rc_t sa_getfd        (sa_t *sa, int *fd);
+sa_rc_t sa_shutdown     (sa_t *sa, char *flags);
+
+/* socket input/output operations */
+sa_rc_t sa_read         (sa_t *sa, char *buf, size_t buflen, size_t *bufdone);
+sa_rc_t sa_readfrom     (sa_t *sa, char *buf, size_t buflen, size_t *bufdone, sa_addr_t **raddr);
+sa_rc_t sa_readline     (sa_t *sa, char *buf, size_t buflen, size_t *bufdone);
+sa_rc_t sa_write        (sa_t *sa, const char *buf, size_t buflen, size_t *bufdone);
+sa_rc_t sa_writeto      (sa_t *sa, const char *buf, size_t buflen, size_t *bufdone, sa_addr_t *raddr);
+sa_rc_t sa_writef       (sa_t *sa, const char *fmt, ...);
+sa_rc_t sa_flush        (sa_t *sa);
 
 #endif /* __SA_H__ */
 

CVSTrac 2.0.1