OSSP CVS Repository

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

Check-in Number: 875
Date: 2001-Sep-06 18:10:05 (local)
2001-Sep-06 16:10:05 (UTC)
User:rse
Branch:
Comment: Simplify channels again: The channel framework gurranties that the handler context is available if the handler has set it, so there is no need to perform an additional run-time check and try to return L2_ERR_ARG.
Tickets:
Inspections:
Files:
ossp-pkg/l2/l2_ch_buffer.c      1.16 -> 1.17     21 inserted, 49 deleted
ossp-pkg/l2/l2_ch_file.c      1.15 -> 1.16     8 inserted, 28 deleted
ossp-pkg/l2/l2_ch_prefix.c      1.9 -> 1.10     3 inserted, 7 deleted
ossp-pkg/l2/l2_ch_socket.c      1.15 -> 1.16     7 inserted, 19 deleted
ossp-pkg/l2/l2_ch_syslog.c      1.16 -> 1.17     6 inserted, 24 deleted

ossp-pkg/l2/l2_ch_buffer.c 1.16 -> 1.17

--- l2_ch_buffer.c       2001/09/06 14:37:53     1.16
+++ l2_ch_buffer.c       2001/09/06 16:10:05     1.17
@@ -61,34 +61,27 @@
 /* configure channel */
 static l2_result_t hook_configure(l2_context_t *ctx, l2_channel_t *ch, const char *fmt, va_list ap)
 {
-    l2_ch_buffer_t *cfg;
+    l2_ch_buffer_t *cfg = (l2_ch_buffer_t *)ctx->vp;
     l2_param_t pa[2];
     l2_result_t rv;
 
-    /* parameter checks */
-    if ((cfg = (l2_ch_buffer_t *)ctx->vp) == NULL)
-        return L2_ERR_ARG;
-
     /* feed and call generic parameter parsing engine */
     L2_PARAM_SET(pa[0], size, INT, &cfg->bufsize);
     L2_PARAM_END(pa[1]);
     rv = l2_util_setparams(pa, fmt, ap);
     if (cfg->bufsize < 0) 
         return L2_ERR_ARG;
+
     return rv;
 }
 
 /* open channel */
 static l2_result_t hook_open(l2_context_t *ctx, l2_channel_t *ch)
 {
-    l2_ch_buffer_t *cfg;
-    l2_channel_t *downstream;
+    l2_ch_buffer_t *cfg = (l2_ch_buffer_t *)ctx->vp;
+    l2_channel_t *downstream = l2_channel_downstream(ch);
     l2_result_t rv;
 
-    /* parameter checks */
-    if ((cfg = (l2_ch_buffer_t *)ctx->vp) == NULL)
-        return L2_ERR_ARG;
-
     /* open channel buffer */
     if (cfg->bufsize > 0) {
         if ((cfg->buf = malloc(cfg->bufsize)) == NULL)
@@ -97,9 +90,8 @@
     }
 
     /* optionally open downstream channel, too */
-    if ((downstream = l2_channel_downstream(ch)) != NULL)
-        if ((rv = l2_channel_open(downstream)) != L2_OK)
-            return rv;
+    if ((rv = l2_channel_open(downstream)) != L2_OK)
+        return rv;
 
     return L2_OK;
 }
@@ -108,14 +100,10 @@
 static l2_result_t hook_write(l2_context_t *ctx, l2_channel_t *ch, 
                       const char *buf, size_t bufsize)
 {
+    l2_ch_buffer_t *cfg = (l2_ch_buffer_t *)ctx->vp;
     l2_channel_t *downstream = l2_channel_downstream(ch);
-    l2_ch_buffer_t *cfg;
     l2_result_t rv;
 
-    /* parameter checks */
-    if ((cfg = (l2_ch_buffer_t *)ctx->vp) == NULL)
-        return L2_ERR_ARG;
-
     if (bufsize > (cfg->bufsize - cfg->bufpos)) {
         /* flush buffer if necessary */
         if (cfg->bufpos > 0) {
@@ -138,26 +126,20 @@
 /* flush channel */
 static l2_result_t hook_flush(l2_context_t *ctx, l2_channel_t *ch)
 {
-    l2_ch_buffer_t *cfg;
-    l2_channel_t *downstream;
+    l2_ch_buffer_t *cfg = (l2_ch_buffer_t *)ctx->vp;
+    l2_channel_t *downstream = l2_channel_downstream(ch);
     l2_result_t rv;
 
-    /* parameter checks */
-    if ((cfg = (l2_ch_buffer_t *)ctx->vp) == NULL)
-        return L2_ERR_ARG;
-
     /* write the buffer contents downstream */
     if (cfg->bufpos > 0) {
-        if ((downstream = l2_channel_downstream(ch)) != NULL)
-            if ((rv = l2_channel_write(downstream, cfg->buf, cfg->bufpos)) != L2_OK)
-                return rv;
+        if ((rv = l2_channel_write(downstream, cfg->buf, cfg->bufpos)) != L2_OK)
+            return rv;
         cfg->bufpos = 0;
     }
 
     /* optionally flush downstream channel, too */
-    if ((downstream = l2_channel_downstream(ch)) != NULL)
-        if ((rv = l2_channel_flush(downstream)) != L2_OK)
-            return rv;
+    if ((rv = l2_channel_flush(downstream)) != L2_OK)
+        return rv;
 
     return L2_OK;
 }
@@ -165,26 +147,20 @@
 /* close channel */
 static l2_result_t hook_close(l2_context_t *ctx, l2_channel_t *ch)
 {
-    l2_ch_buffer_t *cfg;
-    l2_channel_t *downstream;
+    l2_ch_buffer_t *cfg = (l2_ch_buffer_t *)ctx->vp;
+    l2_channel_t *downstream = l2_channel_downstream(ch);
     l2_result_t rv;
 
-    /* parameter checks */
-    if ((cfg = (l2_ch_buffer_t *)ctx->vp) == NULL)
-        return L2_ERR_ARG;
-
-    /* write stale data before closing down */
+    /* write pending data before closing down */
     if (cfg->bufpos > 0) {
-        if ((downstream = l2_channel_downstream(ch)) != NULL)
-            if ((rv = l2_channel_write(downstream, cfg->buf, cfg->bufpos)) != L2_OK)
-                return rv;
+        if ((rv = l2_channel_write(downstream, cfg->buf, cfg->bufpos)) != L2_OK)
+            return rv;
         cfg->bufpos = 0;
     }
 
     /* optionally close downstream channel, too */
-    if ((downstream = l2_channel_downstream(ch)) != NULL)
-        if ((rv = l2_channel_close(downstream)) != L2_OK)
-            return rv;
+    if ((rv = l2_channel_close(downstream)) != L2_OK)
+        return rv;
 
     /* close channel buffer */
     if (cfg->buf != NULL) {
@@ -198,11 +174,7 @@
 /* destroy channel */
 static l2_result_t hook_destroy(l2_context_t *ctx, l2_channel_t *ch)
 {
-    l2_ch_buffer_t *cfg;
-
-    /* parameter checks */
-    if ((cfg = (l2_ch_buffer_t *)ctx->vp) == NULL)
-        return L2_ERR_ARG;
+    l2_ch_buffer_t *cfg = (l2_ch_buffer_t *)ctx->vp;
 
     /* if not already closed, close channel buffer now */
     if (cfg->buf != NULL) {


ossp-pkg/l2/l2_ch_file.c 1.15 -> 1.16

--- l2_ch_file.c 2001/09/06 14:43:25     1.15
+++ l2_ch_file.c 2001/09/06 16:10:05     1.16
@@ -65,14 +65,10 @@
 /* configure channel */
 static l2_result_t hook_configure(l2_context_t *ctx, l2_channel_t *ch, const char *fmt, va_list ap)
 {
-    l2_ch_file_t *cfg;
+    l2_ch_file_t *cfg = (l2_ch_file_t *)ctx->vp;
     l2_param_t pa[4]; 
     l2_result_t rv;
 
-    /* parameter checks */
-    if ((cfg = (l2_ch_file_t *)ctx->vp) == NULL)
-        return L2_ERR_ARG;
-
     /* feed and call generic parameter parsing engine */
     L2_PARAM_SET(pa[0], path,   CHARPTR, &cfg->path);
     L2_PARAM_SET(pa[1], append, INT,     &cfg->append);
@@ -86,12 +82,10 @@
 /* open channel */
 static l2_result_t hook_open(l2_context_t *ctx, l2_channel_t *ch)
 {
-    l2_ch_file_t *cfg;
+    l2_ch_file_t *cfg = (l2_ch_file_t *)ctx->vp;
     int mode;
 
-    /* parameter checks */
-    if ((cfg = (l2_ch_file_t *)ctx->vp) == NULL)
-        return L2_ERR_ARG;
+    /* make sure a path was set */
     if (cfg->path == NULL)
         return L2_ERR_USE;
 
@@ -109,14 +103,8 @@
 static l2_result_t hook_write(l2_context_t *ctx, l2_channel_t *ch, 
                       const char *buf, size_t buf_size)
 {
-    l2_ch_file_t *cfg;
-
-    /* parameter checks */
-    if ((cfg = (l2_ch_file_t *)ctx->vp) == NULL)
-        return L2_ERR_ARG;
-    if (cfg->fd == -1)
-        return L2_ERR_USE;
-
+    l2_ch_file_t *cfg = (l2_ch_file_t *)ctx->vp;
+    
     /* write message to channel file */
     if (write(cfg->fd, buf, buf_size) == -1)
         return L2_ERR_SYS;
@@ -127,13 +115,7 @@
 /* close channel */
 static l2_result_t hook_close(l2_context_t *ctx, l2_channel_t *ch)
 {
-    l2_ch_file_t *cfg;
-
-    /* parameter checks */
-    if ((cfg = (l2_ch_file_t *)ctx->vp) == NULL)
-        return L2_ERR_ARG;
-    if (cfg->fd == -1)
-        return L2_ERR_USE;
+    l2_ch_file_t *cfg = (l2_ch_file_t *)ctx->vp;
 
     /* close channel file */
     close(cfg->fd);
@@ -145,12 +127,10 @@
 /* destroy channel */
 static l2_result_t hook_destroy(l2_context_t *ctx, l2_channel_t *ch)
 {
-    /* parameter checks */
-    if (ctx->vp == NULL) 
-        return L2_ERR_ARG;
+    l2_ch_file_t *cfg = (l2_ch_file_t *)ctx->vp;
 
     /* destroy channel configuration */
-    free(ctx->vp);
+    free(cfg);
 
     return L2_OK;
 }


ossp-pkg/l2/l2_ch_prefix.c 1.9 -> 1.10

--- l2_ch_prefix.c       2001/09/06 14:37:53     1.9
+++ l2_ch_prefix.c       2001/09/06 16:10:05     1.10
@@ -86,17 +86,13 @@
 static l2_result_t hook_write(l2_context_t *ctx, l2_channel_t *ch, 
                               const char *buf, size_t buf_size)
 {
-    l2_ch_prefix_t *cfg;
-    l2_channel_t *downstream;
+    l2_ch_prefix_t *cfg = (l2_ch_prefix_t *)ctx->vp;
+    l2_channel_t *downstream = l2_channel_downstream(ch);
     time_t t;
     struct tm *tm;
     size_t n;
     l2_result_t rv;
 
-    /* get environment */
-    cfg = (l2_ch_prefix_t *)ctx->vp;
-    downstream = l2_channel_downstream(ch);
-
     /* optionally provide prefix */
     if (cfg->timefmt != NULL) {
         t = time(NULL);
@@ -124,12 +120,12 @@
 {
     l2_ch_prefix_t *cfg = (l2_ch_prefix_t *)ctx->vp;
 
+    /* free prefix structure */
     if (cfg->timefmt != NULL)
         free(cfg->timefmt);
     if (cfg->timezone != NULL)
         free(cfg->timezone);
     free(cfg);
-    ctx->vp = NULL;
 
     return L2_OK;
 }


ossp-pkg/l2/l2_ch_socket.c 1.15 -> 1.16

--- l2_ch_socket.c       2001/09/06 14:43:25     1.15
+++ l2_ch_socket.c       2001/09/06 16:10:05     1.16
@@ -126,14 +126,10 @@
 /* configure channel */
 static l2_result_t hook_configure(l2_context_t *ctx, l2_channel_t *ch, const char *fmt, va_list ap)
 {
-    l2_ch_socket_t *cfg;
+    l2_ch_socket_t *cfg = (l2_ch_socket_t *)ctx->vp;
     l2_param_t pa[4];
     l2_result_t rv;
 
-    /* parameter checks */
-    if ((cfg = (l2_ch_socket_t *)ctx->vp) == NULL)
-        return L2_ERR_ARG;
-
     /* feed and call generic parameter parsing engine */
     L2_PARAM_SET(pa[0], ipversion, INT,     &cfg->iFamily);
     L2_PARAM_SET(pa[1], host,      CHARPTR, &cfg->pszHost);
@@ -147,15 +143,13 @@
 /* open channel */
 static l2_result_t hook_open(l2_context_t *ctx, l2_channel_t *ch)
 {
-    l2_ch_socket_t      *cfg;
+    l2_ch_socket_t *cfg = (l2_ch_socket_t *)ctx->vp;
     struct hostent      *pHostentry;
     struct sockaddr_in  IP4Sockaddr;
     struct sockaddr_in6 IP6Sockaddr;
     struct in6_addr     *IP6Addr;
 
-    /* parameter checks */
-    if ((cfg = (l2_ch_socket_t *)ctx->vp) == NULL)
-        return L2_ERR_ARG;
+    /* make sure a target is configured */
     if (cfg->pszHost == NULL)
         return L2_ERR_USE;
 
@@ -245,13 +239,11 @@
 static l2_result_t hook_write(l2_context_t *ctx, l2_channel_t *ch, 
                       const char *buf, size_t buf_size)
 {
-    l2_ch_socket_t *cfg;
+    l2_ch_socket_t *cfg = (l2_ch_socket_t *)ctx->vp;
     size_t          sizeWrite;
     size_t          sizeRemain;
 
     /* parameter checks */
-    if ((cfg = (l2_ch_socket_t *)ctx->vp) == NULL)
-        return L2_ERR_ARG;
     if (cfg->iSocket == -1)
         return L2_ERR_USE;
 
@@ -274,11 +266,9 @@
 /* close channel */
 static l2_result_t hook_close(l2_context_t *ctx, l2_channel_t *ch)
 {
-    l2_ch_socket_t *cfg;
+    l2_ch_socket_t *cfg = (l2_ch_socket_t *)ctx->vp;
 
     /* parameter checks */
-    if ((cfg = (l2_ch_socket_t *)ctx->vp) == NULL)
-        return L2_ERR_ARG;
     if (cfg->iSocket == -1)
         return L2_ERR_USE;
 
@@ -292,12 +282,10 @@
 /* destroy channel */
 static l2_result_t hook_destroy(l2_context_t *ctx, l2_channel_t *ch)
 {
-    /* parameter checks */
-    if (ctx->vp == NULL) 
-        return L2_ERR_ARG;
+    l2_ch_socket_t *cfg = (l2_ch_socket_t *)ctx->vp;
 
     /* destroy channel configuration */
-    free(ctx->vp);
+    free(cfg);
 
     return L2_OK;
 }


ossp-pkg/l2/l2_ch_syslog.c 1.16 -> 1.17

--- l2_ch_syslog.c       2001/09/06 14:43:25     1.16
+++ l2_ch_syslog.c       2001/09/06 16:10:05     1.17
@@ -65,14 +65,10 @@
 /* configure channel */
 static l2_result_t hook_configure(l2_context_t *ctx, l2_channel_t *ch, const char *fmt, va_list ap)
 {
-    l2_ch_syslog_t *cfg;
+    l2_ch_syslog_t *cfg = (l2_ch_syslog_t *)ctx->vp;
     l2_param_t pa[6];
     l2_result_t rv;
 
-    /* parameter checks */
-    if ((cfg = (l2_ch_syslog_t *)ctx->vp) == NULL)
-        return L2_ERR_ARG;
-
     /* feed and call generic parameter parsing engine */
     L2_PARAM_SET(pa[0], ident,   CHARPTR,  &cfg->pszIdent);
     L2_PARAM_SET(pa[1], logopts, INT,      &cfg->iLogopt);
@@ -88,11 +84,7 @@
 /* open channel */
 static l2_result_t hook_open(l2_context_t *ctx, l2_channel_t *ch)
 {
-    l2_ch_syslog_t *cfg;
-
-    /* parameter checks */
-    if ((cfg = (l2_ch_syslog_t *)ctx->vp) == NULL)
-        return L2_ERR_ARG;
+    l2_ch_syslog_t *cfg = (l2_ch_syslog_t *)ctx->vp;
 
     /* open channel syslog */
     openlog(cfg->pszIdent, cfg->iLogopt, cfg->iFacility);
@@ -105,11 +97,7 @@
 static l2_result_t hook_write(l2_context_t *ctx, l2_channel_t *ch, 
                       const char *buf, size_t buf_size)
 {
-    l2_ch_syslog_t *cfg;
-
-    /* parameter checks */
-    if ((cfg = (l2_ch_syslog_t *)ctx->vp) == NULL)
-        return L2_ERR_ARG;
+    l2_ch_syslog_t *cfg = (l2_ch_syslog_t *)ctx->vp;
 
     /* write message to channel syslog */
     syslog(cfg->iPriority, buf);
@@ -120,11 +108,7 @@
 /* close channel */
 static l2_result_t hook_close(l2_context_t *ctx, l2_channel_t *ch)
 {
-    l2_ch_syslog_t *cfg;
-
-    /* parameter checks */
-    if ((cfg = (l2_ch_syslog_t *)ctx->vp) == NULL)
-        return L2_ERR_ARG;
+    l2_ch_syslog_t *cfg = (l2_ch_syslog_t *)ctx->vp;
 
     /* close channel syslog */
     closelog();
@@ -135,12 +119,10 @@
 /* destroy channel */
 static l2_result_t hook_destroy(l2_context_t *ctx, l2_channel_t *ch)
 {
-    /* parameter checks */
-    if (ctx->vp == NULL) 
-        return L2_ERR_ARG;
+    l2_ch_syslog_t *cfg = (l2_ch_syslog_t *)ctx->vp;
 
     /* destroy channel configuration */
-    free(ctx->vp);
+    free(cfg);
 
     return L2_OK;
 }

CVSTrac 2.0.1