OSSP CVS Repository

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

Check-in Number: 1247
Date: 2001-Nov-03 23:51:36 (local)
2001-Nov-03 22:51:36 (UTC)
User:rse
Branch:
Comment: Channel-Only Revamping Step 1: allow multiple downstream channels in order to approach the later tree-like channel-only structure.
Tickets:
Inspections:
Files:
ossp-pkg/l2/l2.h.in      1.13 -> 1.14     7 inserted, 4 deleted
ossp-pkg/l2/l2_ch_buffer.c      1.30 -> 1.31     32 inserted, 43 deleted
ossp-pkg/l2/l2_ch_filter.c      1.10 -> 1.11     2 inserted, 15 deleted
ossp-pkg/l2/l2_ch_prefix.c      1.15 -> 1.16     7 inserted, 15 deleted
ossp-pkg/l2/l2_channel.c      1.20 -> 1.21     171 inserted, 86 deleted
ossp-pkg/l2/l2_p.h      1.24 -> 1.25     5 inserted, 1 deleted
ossp-pkg/l2/l2_stream.c      1.20 -> 1.21     7 inserted, 2 deleted
ossp-pkg/l2/l2_test.c      1.36 -> 1.37     12 inserted, 16 deleted

ossp-pkg/l2/l2.h.in 1.13 -> 1.14

--- l2.h.in      2001/10/09 15:34:55     1.13
+++ l2.h.in      2001/11/03 22:51:36     1.14
@@ -99,14 +99,16 @@
 
 /* list of return values */
 typedef enum {
-    L2_OK,
+    L2_OK,         /* everything ok */
+    L2_OK_PASS,    /* everything ok - pass downstream */
     L2_ERR_ARG,    /* invalid argument */
     L2_ERR_USE,    /* invalid usage */
     L2_ERR_MEM,    /* no more memory available */
     L2_ERR_SYS,    /* system error (see errno) */
     L2_ERR_IO,     /* input/output error */
     L2_ERR_FMT,    /* message formating error */
-    L2_ERR_INT     /* internal error */
+    L2_ERR_INT,    /* internal error */
+    L2_ERR_CH      /* no (more) channel found */
 } l2_result_t;
 
 /* context union for storing data */
@@ -199,8 +201,9 @@
 l2_result_t   l2_channel_close      (l2_channel_t *ch);
 l2_result_t   l2_channel_destroy    (l2_channel_t *ch);
 l2_result_t   l2_channel_stack      (l2_channel_t *ch, l2_channel_t *chTop);
-l2_channel_t *l2_channel_downstream (l2_channel_t *ch);
-l2_chtype_t   l2_channel_type       (l2_channel_t *ch);
+l2_result_t   l2_channel_upstream   (l2_channel_t *ch, l2_channel_t **chU);
+l2_result_t   l2_channel_downstream (l2_channel_t *ch, l2_channel_t **chD);
+l2_result_t   l2_channel_type       (l2_channel_t *ch, l2_chtype_t *type);
 l2_result_t   l2_channel_errorinfo  (l2_channel_t *ch, l2_result_t rv, const char *fmt, ...);
 char         *l2_channel_strerror   (l2_channel_t *ch, l2_result_t rv);
 


ossp-pkg/l2/l2_ch_buffer.c 1.30 -> 1.31

--- l2_ch_buffer.c       2001/10/31 16:47:05     1.30
+++ l2_ch_buffer.c       2001/11/03 22:51:36     1.31
@@ -180,9 +180,7 @@
 static l2_result_t hook_open(l2_context_t *ctx, l2_channel_t *ch)
 {
     l2_ch_buffer_t *cfg = (l2_ch_buffer_t *)ctx->vp;
-    l2_channel_t *downstream = l2_channel_downstream(ch);
     struct sigaction locact;
-    l2_result_t rv;
 
     if ((cfg->bufinterval != 0) && (cfg->bufinterval != -1L)) {
         /* initialize auto vars before using them */
@@ -208,11 +206,7 @@
         cfg->bufpos = 0;
     }
 
-    /* optionally open downstream channel, too */
-    if ((rv = l2_channel_open(downstream)) != L2_OK)
-        return rv;
-
-    return L2_OK;
+    return L2_OK_PASS;
 }
 
 /* write to channel */
@@ -220,20 +214,27 @@
                               l2_level_t level, const char *buf, size_t buf_size)
 {
     l2_ch_buffer_t *cfg = (l2_ch_buffer_t *)ctx->vp;
-    l2_channel_t *downstream = l2_channel_downstream(ch);
+    l2_channel_t *downstream;
     l2_result_t rv;
 
     if (buf_size > (cfg->bufsize - cfg->bufpos)) {
         /* flush buffer if necessary */
         if (cfg->bufpos > 0) {
-            if ((rv = l2_channel_write(downstream, cfg->level, cfg->buf, cfg->bufpos)) != L2_OK)
-                return rv;
+            downstream = NULL;
+            while ((rv = l2_channel_downstream(ch, &downstream)) == L2_OK)
+                if ((rv = l2_channel_write(downstream, cfg->level, cfg->buf, cfg->bufpos)) != L2_OK)
+                    return rv;
             cfg->bufpos = 0;
             cfg->level  = L2_LEVEL_NONE;
         }
         /* pass through immediately to downstream if still too large */
-        if (buf_size > cfg->bufsize)
-            return l2_channel_write(downstream, level, buf, buf_size);
+        if (buf_size > cfg->bufsize) {
+            downstream = NULL;
+            while ((rv = l2_channel_downstream(ch, &downstream)) == L2_OK)
+                if ((rv = l2_channel_write(downstream, level, buf, buf_size)) != L2_OK)
+                    return rv;
+            return L2_OK;
+        }
     }
 
     /* flush if level of incoming message differs from those already in buffer */
@@ -241,8 +242,10 @@
         && (cfg->bufpos > 0)             /* and there is something in the buffer */
         && (cfg->level != L2_LEVEL_NONE) /* and a remembered level is known      */
         && (level != cfg->level)         /* and the levels really differ         */) {
-        if ((rv = l2_channel_write(downstream, cfg->level, cfg->buf, cfg->bufpos)) != L2_OK)
-            return rv;
+        downstream = NULL;
+        while (l2_channel_downstream(ch, &downstream) == L2_OK)
+            if ((rv = l2_channel_write(downstream, cfg->level, cfg->buf, cfg->bufpos)) != L2_OK)
+                return rv;
         cfg->bufpos = 0;
         cfg->level  = L2_LEVEL_NONE;
     }
@@ -259,14 +262,16 @@
 static l2_result_t hook_flush(l2_context_t *ctx, l2_channel_t *ch)
 {
     l2_ch_buffer_t *cfg = (l2_ch_buffer_t *)ctx->vp;
-    l2_channel_t *downstream = l2_channel_downstream(ch);
+    l2_channel_t *downstream;
     l2_result_t rv;
 
     /* write the buffer contents downstream */
 TRACE("l2_ch_buffer hook_flush called\n");
     if (cfg->bufpos > 0) {
-        if ((rv = l2_channel_write(downstream, cfg->level, cfg->buf, cfg->bufpos)) != L2_OK)
-            return rv;
+        downstream = NULL;
+        while (l2_channel_downstream(ch, &downstream) == L2_OK)
+            if ((rv = l2_channel_write(downstream, cfg->level, cfg->buf, cfg->bufpos)) != L2_OK)
+                return rv;
         cfg->bufpos = 0;
         cfg->level  = L2_LEVEL_NONE; /* reset this->context->level */
     }
@@ -276,18 +281,14 @@
         if (reset_alarm(cfg))
             return L2_ERR_SYS;
 
-    /* optionally flush downstream channel, too */
-    if ((rv = l2_channel_flush(downstream)) != L2_OK)
-        return rv;
-
-    return L2_OK;
+    return L2_OK_PASS;
 }
 
 /* close channel */
 static l2_result_t hook_close(l2_context_t *ctx, l2_channel_t *ch)
 {
     l2_ch_buffer_t *cfg = (l2_ch_buffer_t *)ctx->vp;
-    l2_channel_t *downstream = l2_channel_downstream(ch);
+    l2_channel_t *downstream;
     l2_result_t rv;
 
     if ((cfg->bufinterval != 0) && (cfg->bufinterval != -1L)) {
@@ -305,46 +306,34 @@
 
     /* write pending data before closing down */
     if (cfg->bufpos > 0) {
-        if ((rv = l2_channel_write(downstream, cfg->level, cfg->buf, cfg->bufpos)) != L2_OK)
-            return rv;
+        downstream = NULL;
+        while (l2_channel_downstream(ch, &downstream) == L2_OK)
+            if ((rv = l2_channel_write(downstream, cfg->level, cfg->buf, cfg->bufpos)) != L2_OK)
+                return rv;
         cfg->bufpos = 0;
         cfg->level  = L2_LEVEL_NONE; /* reset this->context->level */
     }
 
-    /* optionally close downstream channel, too */
-    if ((rv = l2_channel_close(downstream)) != L2_OK)
-        return rv;
-
     /* close channel buffer */
     if (cfg->buf != NULL) {
         free(cfg->buf);
         cfg->buf = NULL;
     }
 
-    return L2_OK;
+    return L2_OK_PASS;
 }
 
 /* destroy channel */
 static l2_result_t hook_destroy(l2_context_t *ctx, l2_channel_t *ch)
 {
     l2_ch_buffer_t *cfg = (l2_ch_buffer_t *)ctx->vp;
-    l2_channel_t *downstream = l2_channel_downstream(ch);
-    l2_result_t rv;
-
-    /* if not already closed, close channel buffer now */
-    if (cfg->buf != NULL) {
-        free(cfg->buf);
-        cfg->buf = NULL;
-    }
 
     /* destroy channel configuration */
+    if (cfg->buf != NULL)
+        free(cfg->buf);
     free(cfg);
 
-    /* optionally destroy downstream channel, too */
-    if ((rv = l2_channel_destroy(downstream)) != L2_OK)
-        return rv;
-
-    return L2_OK;
+    return L2_OK_PASS;
 }
 
 /* exported channel handler structure */


ossp-pkg/l2/l2_ch_filter.c 1.10 -> 1.11

--- l2_ch_filter.c       2001/09/28 14:28:41     1.10
+++ l2_ch_filter.c       2001/11/03 22:51:36     1.11
@@ -100,8 +100,6 @@
                               l2_level_t level, const char *buf, size_t buf_size)
 {
     l2_ch_filter_t *cfg = (l2_ch_filter_t *)ctx->vp;
-    l2_channel_t *downstream = l2_channel_downstream(ch);
-    l2_result_t rv;
     int bPass, iCheck;
 
     bPass = TRUE;
@@ -117,23 +115,12 @@
            bPass = !bPass;
     }
 
-    /* write to downstream channel */
-    if (bPass)
-        if ((rv = l2_channel_write(downstream, level, buf, buf_size)) != L2_OK)
-            return rv;
-
-    return L2_OK;
+    return (bPass ? L2_OK_PASS : L2_OK);
 }
 
 static l2_result_t hook_destroy(l2_context_t *ctx, l2_channel_t *ch)
 {
     l2_ch_filter_t *cfg = (l2_ch_filter_t *)ctx->vp;
-    l2_channel_t *downstream = l2_channel_downstream(ch);
-    l2_result_t rv;
-
-    /* destroy downstream channel */
-    if ((rv = l2_channel_destroy(downstream)) != L2_OK)
-        return rv;
 
     /* destroy channel configuration */
     if (cfg->szRegex != NULL)
@@ -143,7 +130,7 @@
     if (cfg->pcreExtra != NULL)
         free(cfg->pcreExtra);
 
-    return L2_OK;
+    return L2_OK_PASS;
 }
 
 l2_handler_t l2_handler_filter = {


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

--- l2_ch_prefix.c       2001/10/09 15:34:55     1.15
+++ l2_ch_prefix.c       2001/11/03 22:51:36     1.16
@@ -134,7 +134,7 @@
                               l2_level_t level, const char *buf, size_t buf_size)
 {
     l2_ch_prefix_t *cfg = (l2_ch_prefix_t *)ctx->vp;
-    l2_channel_t *downstream = l2_channel_downstream(ch);
+    l2_channel_t *downstream;
     time_t t;
     struct tm *tm;
     size_t n;
@@ -158,23 +158,19 @@
             return L2_ERR_ARG;
         if ((n = strftime(buf2, sizeof(buf2), buf1, tm)) == 0)
             return L2_ERR_SYS;
-        if ((rv = l2_channel_write(downstream, level, buf2, n)) != L2_OK)
-            return rv;
+        downstream = NULL;
+        while ((rv = l2_channel_downstream(ch, &downstream)) == L2_OK)
+            if ((rv = l2_channel_write(downstream, level, buf2, n)) != L2_OK)
+                return rv;
     }
 
-    /* write to downstream channel */
-    if ((rv = l2_channel_write(downstream, level, buf, buf_size)) != L2_OK)
-        return rv;
-
-    return L2_OK;
+    return L2_OK_PASS;
 }
 
 /* destroy channel */
 static l2_result_t hook_destroy(l2_context_t *ctx, l2_channel_t *ch)
 {
     l2_ch_prefix_t *cfg = (l2_ch_prefix_t *)ctx->vp;
-    l2_channel_t *downstream = l2_channel_downstream(ch);
-    l2_result_t rv;
 
     /* free prefix structure */
     if (cfg->prefix != NULL)
@@ -183,11 +179,7 @@
         free(cfg->timezone);
     free(cfg);
 
-    /* optionally destroy downstream channel, too */
-    if ((rv = l2_channel_destroy(downstream)) != L2_OK)
-        return rv;
-
-    return L2_OK;
+    return L2_OK_PASS;
 }
 
 /* exported channel handler structure */


ossp-pkg/l2/l2_channel.c 1.20 -> 1.21

--- l2_channel.c 2001/09/27 13:56:35     1.20
+++ l2_channel.c 2001/11/03 22:51:36     1.21
@@ -51,7 +51,7 @@
  * Last-modified: 2000-09-28/14:40
  * Name: l2_ch_lifecycle
  * Version: eo/1.0
- * H4sIAIsvszsCA62WTW/bMAyGz/WvENBzM5KyPnwusGFAdtp1l8BVWgOZUyTuhv77
+ * H4sIAGdztDsCA62WTW/bMAyGz/WvENBzM5KyPnwusGFAdtp1l8BVWgOZUyTuhv77
  * kfKHnC4t5CZJ7JAO3kcUKUq5/fr9m9IrKtab9uFYb55DcR/aLhyKH6E7NHWxDh17
  * ShUIsAIofjbt4y4Ud1QgASgqQGlSt3V8Fai0AoV8gTJyI76xLD6Tb35iPSpybNlS
  * PsknV5po5WC0BZZRWSlL8km+tlYsa3MwJfAP6Kdokl8iltHKwjiwJ5jJL52DbIxB
@@ -84,12 +84,16 @@
 
     /* initialize channel structure */
     ch->state = L2_CHSTATE_CREATED;
-    ch->downstream = NULL;
+    ch->parent = NULL;
+    ch->sibling = NULL;
+    ch->child = NULL;
     memset(&ch->context, 0, sizeof(l2_context_t));
     memcpy(&ch->handler, h, sizeof(l2_handler_t));
     ch->rvErrorInfo = L2_OK;
     ch->szErrorInfo[0] = '\0';
     ch->szError[0] = '\0';
+    ch->levelmask = L2_LEVEL_ALL;
+    ch->flushmask = L2_LEVEL_NONE;
 
     /* (optionally) perform create operation in handler */
     if (ch->handler.create != NULL) {
@@ -102,6 +106,84 @@
     return ch;
 }
 
+/* stack channel on top of another channel */
+l2_result_t l2_channel_stack(l2_channel_t *ch, l2_channel_t *chP)
+{
+    l2_channel_t *chT;
+
+    /* argument sanity check */
+    if (ch == NULL || chP == NULL)
+        return L2_ERR_ARG;
+
+    /* make sure both channels are in state "created" */
+    if (   ch->state  != L2_CHSTATE_CREATED
+        || chP->state != L2_CHSTATE_CREATED)
+        return L2_ERR_USE;
+
+    /* make sure parent channel is a filter channel */
+    if (chP->handler.type != L2_CHANNEL_FILTER)
+        return L2_ERR_USE;
+
+    /* make sure child still has no parent */
+    if (ch->parent != NULL)
+        return L2_ERR_USE;
+
+    /* stack the two channels */
+    ch->parent = chP;
+    if (chP->child == NULL)
+        chP->child = ch;
+    else {
+        chT = chP->child;
+        while (chT->sibling != NULL)
+            chT = chT->sibling;
+        chT->sibling = ch;
+    }
+
+    return L2_OK;
+}
+
+/* return upstream channel */
+l2_result_t l2_channel_upstream(l2_channel_t *ch, l2_channel_t **chU)
+{
+    /* argument sanity check */
+    if (ch == NULL || chU == NULL)
+        return L2_ERR_ARG;
+
+    /* determine parent/upstream channel */
+    *chU = ch->parent;
+
+    return (*chU != NULL ? L2_OK : L2_ERR_CH);
+}
+
+/* return (subsequent) downstream channel(s) */
+l2_result_t l2_channel_downstream(l2_channel_t *ch, l2_channel_t **chD)
+{
+    /* argument sanity check */
+    if (ch == NULL || chD == NULL)
+        return L2_ERR_ARG;
+
+    /* determine (next) downstream/child channel */
+    if (*chD == NULL)
+        *chD = ch->child;
+    else
+        *chD = (*chD)->sibling;
+
+    return (*chD != NULL ? L2_OK : L2_ERR_CH);
+}
+
+/* return channel type */
+l2_result_t l2_channel_type(l2_channel_t *ch, l2_chtype_t *type)
+{
+    /* argument sanity check */
+    if (ch == NULL || type == NULL)
+        return L2_ERR_ARG;
+
+    /* return type */
+    (*type) = ch->handler.type;
+
+    return L2_OK;
+}
+
 /* configure channel */
 l2_result_t l2_channel_configure(l2_channel_t *ch, const char *fmt, ...)
 {
@@ -126,10 +208,12 @@
     return rv;
 }
 
-/* open channel (stack) */
+/* open channel */
 l2_result_t l2_channel_open(l2_channel_t *ch)
 {
     l2_result_t rv;
+    l2_result_t rvD;
+    l2_channel_t *chD;
 
     /* argument sanity check */
     if (ch == NULL)
@@ -139,29 +223,42 @@
     if (ch->state != L2_CHSTATE_CREATED)
         return L2_ERR_USE;
 
-    /* skip empty open handlers on channel stack */
-    while (ch != NULL && ch->handler.open == NULL) {
-        ch->state = L2_CHSTATE_OPENED;
-        ch = ch->downstream;
+    /* perform operation */
+    if (ch->handler.open != NULL)
+        rv = ch->handler.open(&ch->context, ch);
+    else
+        rv = L2_OK_PASS;
+   
+    /* optionally pass operation downstream */ 
+    if (rv == L2_OK_PASS) {
+        rv = L2_OK;
+        chD = NULL;
+        while (l2_channel_downstream(ch, &chD) == L2_OK)
+            if ((rvD = l2_channel_open(chD)) != L2_OK)
+                rv = rvD;
+        if (rv != L2_OK) {
+            chD = NULL;
+            while (l2_channel_downstream(ch, &chD) == L2_OK)
+                l2_channel_close(chD);
+        }
     }
-    if (ch == NULL)
-        return L2_ERR_USE;
 
-    /* pass operation to handler */
-    rv = ch->handler.open(&ch->context, ch);
+    /* mark channel as opened */
     if (rv == L2_OK)
         ch->state = L2_CHSTATE_OPENED;
 
     return rv;
 }
 
-/* write to channel (stack) */
+/* write to channel */
 l2_result_t l2_channel_write(l2_channel_t *ch, l2_level_t level, const char *buf, size_t bufsize)
 {
     l2_result_t rv;
+    l2_result_t rvD;
+    l2_channel_t *chD;
 
     /* argument sanity check */
-    if (ch == NULL || buf == NULL)
+    if (ch == NULL || level == 0 || buf == NULL)
         return L2_ERR_ARG;
 
     /* make sure channel is in state "opened" */
@@ -172,14 +269,20 @@
     if (bufsize == 0)
         return L2_OK;
 
-    /* walk to next available write handler */
-    while (ch != NULL && ch->handler.write == NULL)
-        ch = ch->downstream;
-    if (ch == NULL)
-        return L2_ERR_USE;
-
-    /* pass operation to handler */
-    rv = ch->handler.write(&ch->context, ch, level, buf, bufsize);
+    /* perform operation */
+    if (ch->handler.write != NULL)
+        rv = ch->handler.write(&ch->context, ch, level, buf, bufsize);
+    else
+        rv = L2_OK_PASS;
+   
+    /* optionally pass operation downstream */ 
+    if (rv == L2_OK_PASS) {
+        rv = L2_OK;
+        chD = NULL;
+        while (l2_channel_downstream(ch, &chD) == L2_OK)
+            if ((rvD = l2_channel_write(chD, level, buf, bufsize)) != L2_OK)
+                rv = rvD;
+    }
 
     return rv;
 }
@@ -188,6 +291,8 @@
 l2_result_t l2_channel_flush(l2_channel_t *ch)
 {
     l2_result_t rv;
+    l2_result_t rvD;
+    l2_channel_t *chD;
 
     /* argument sanity check */
     if (ch == NULL)
@@ -197,14 +302,20 @@
     if (ch->state != L2_CHSTATE_OPENED)
         return L2_ERR_USE;
 
-    /* walk to next available flush handler */
-    while (ch != NULL && ch->handler.flush == NULL)
-        ch = ch->downstream;
-    if (ch == NULL)
-        return L2_ERR_USE;
-
-    /* pass operation to handler */
-    rv = ch->handler.flush(&ch->context, ch);
+    /* perform operation */
+    if (ch->handler.flush != NULL)
+        rv = ch->handler.flush(&ch->context, ch);
+    else
+        rv = L2_OK_PASS;
+   
+    /* optionally pass operation downstream */ 
+    if (rv == L2_OK_PASS) {
+        rv = L2_OK;
+        chD = NULL;
+        while (l2_channel_downstream(ch, &chD) == L2_OK)
+            if ((rvD = l2_channel_flush(chD)) != L2_OK)
+                rv = rvD;
+    }
 
     return rv;
 }
@@ -213,6 +324,8 @@
 l2_result_t l2_channel_close(l2_channel_t *ch)
 {
     l2_result_t rv;
+    l2_result_t rvD;
+    l2_channel_t *chD;
 
     /* argument sanity check */
     if (ch == NULL)
@@ -222,16 +335,22 @@
     if (ch->state != L2_CHSTATE_OPENED)
         return L2_ERR_USE;
 
-    /* walk to next available close handler */
-    while (ch != NULL && ch->handler.close == NULL) {
-        ch->state = L2_CHSTATE_CREATED;
-        ch = ch->downstream;
+    /* perform operation */
+    if (ch->handler.close != NULL)
+        rv = ch->handler.close(&ch->context, ch);
+    else
+        rv = L2_OK_PASS;
+   
+    /* optionally pass operation downstream */ 
+    if (rv == L2_OK_PASS) {
+        rv = L2_OK;
+        chD = NULL;
+        while (l2_channel_downstream(ch, &chD) == L2_OK)
+            if ((rvD = l2_channel_close(chD)) != L2_OK)
+                rv = rvD;
     }
-    if (ch == NULL)
-        return L2_ERR_USE;
 
-    /* pass operation to handler */
-    rv = ch->handler.close(&ch->context, ch);
+    /* mark channel as closed */
     if (rv == L2_OK)
         ch->state = L2_CHSTATE_CREATED;
 
@@ -242,6 +361,8 @@
 l2_result_t l2_channel_destroy(l2_channel_t *ch)
 {
     l2_result_t rv;
+    l2_result_t rvD;
+    l2_channel_t *chD;
 
     /* argument sanity check */
     if (ch == NULL)
@@ -252,18 +373,24 @@
         if ((rv = l2_channel_close(ch)) != L2_OK)
             return rv;
 
-    /* walk to next available destroy handler */
-    while (ch != NULL && ch->handler.destroy == NULL)
-        ch = ch->downstream;
-    
-    /* pass operation to handler */
-    if (ch != NULL)
+    /* perform operation */
+    if (ch->handler.destroy != NULL)
         rv = ch->handler.destroy(&ch->context, ch);
     else
+        rv = L2_OK_PASS;
+   
+    /* optionally pass operation downstream */ 
+    if (rv == L2_OK_PASS) {
         rv = L2_OK;
+        chD = NULL;
+        while (l2_channel_downstream(ch, &chD) == L2_OK)
+            if ((rvD = l2_channel_destroy(chD)) != L2_OK)
+                rv = rvD;
+    }
 
     /* free channel structure */
-    free(ch);
+    if (rv == L2_OK)
+        free(ch);
 
     return rv;
 }
@@ -332,45 +459,3 @@
     return ch->szError;
 }
 
-/* stack channel on top of another channel */
-l2_result_t l2_channel_stack(l2_channel_t *ch, l2_channel_t *chTop)
-{
-    /* argument sanity check */
-    if (ch == NULL || chTop == NULL)
-        return L2_ERR_ARG;
-
-    /* make sure both channels are in state "created" */
-    if (   ch->state    != L2_CHSTATE_CREATED
-        || chTop->state != L2_CHSTATE_CREATED)
-        return L2_ERR_USE;
-
-    /* make sure top channel is a filter channel */
-    if (chTop->handler.type != L2_CHANNEL_FILTER)
-        return L2_ERR_USE;
-
-    /* stack the channels */
-    chTop->downstream = ch;
-
-    return L2_OK;
-}
-
-/* return downstream channel */
-l2_channel_t *l2_channel_downstream(l2_channel_t *ch)
-{
-    /* argument sanity check */
-    if (ch == NULL)
-        return NULL;
-
-    return ch->downstream;
-}
-
-/* return channel type */
-l2_chtype_t l2_channel_type(l2_channel_t *ch)
-{
-    /* argument sanity check */
-    if (ch == NULL)
-        return L2_CHANNEL_FILTER; /* FIXME */
-
-    return ch->handler.type;
-}
-


ossp-pkg/l2/l2_p.h 1.24 -> 1.25

--- l2_p.h       2001/10/06 14:33:09     1.24
+++ l2_p.h       2001/11/03 22:51:36     1.25
@@ -77,12 +77,16 @@
 
 struct l2_channel_st {
     l2_chstate_t  state;
-    l2_channel_t *downstream;
+    l2_channel_t *parent;
+    l2_channel_t *sibling;
+    l2_channel_t *child;
     l2_context_t  context;
     l2_handler_t  handler;
     char          szError[1024];
     char          szErrorInfo[512];
     l2_result_t   rvErrorInfo;
+    unsigned int  levelmask;
+    unsigned int  flushmask;
 };
 
 typedef struct {


ossp-pkg/l2/l2_stream.c 1.20 -> 1.21

--- l2_stream.c  2001/09/13 19:20:48     1.20
+++ l2_stream.c  2001/11/03 22:51:36     1.21
@@ -55,8 +55,11 @@
 /* attach channel to stream */
 l2_result_t l2_stream_channel(l2_stream_t *st, l2_channel_t *ch, unsigned int levelmask, unsigned int flushmask)
 {
+#if 0
     l2_channel_t *chC;
     l2_channel_t *chN;
+    l2_chtype_t t;
+#endif
     int i;
 
     /* argument sanity check */
@@ -65,11 +68,13 @@
 
     /* make sure the stack of channels consists of zero or more
        filter channels followed by exactly one output channel */
+#if 0
     for (chC = ch; (chN = l2_channel_downstream(chC)) != NULL; chC = chN)
-        if (l2_channel_type(chC) != L2_CHANNEL_FILTER)
+        if (l2_channel_type(chC, &t) == L2_OK && t != L2_CHANNEL_FILTER)
             return L2_ERR_USE;
-    if (l2_channel_type(chC) != L2_CHANNEL_OUTPUT)
+    if (l2_channel_type(chC, &t) == L2_OK && t != L2_CHANNEL_OUTPUT)
         return L2_ERR_USE;
+#endif
 
     /* find next free channel position in channel array */
     for (i = 0; i < L2_MAX_CHANNELS && st->channels[i].ch != NULL; i++)


ossp-pkg/l2/l2_test.c 1.36 -> 1.37

--- l2_test.c    2001/11/03 20:49:25     1.36
+++ l2_test.c    2001/11/03 22:51:36     1.37
@@ -57,7 +57,6 @@
 
 int main(int argc, char *argv[])
 {
-    int i;                  /* For testing l2_stream_log() */
     l2_channel_t *chFilt;
     l2_channel_t *chPrefix;
     l2_channel_t *chBuf;
@@ -100,7 +99,7 @@
     if ((chBuf  = l2_channel_create(&l2_handler_buffer)) == NULL)    /* Buffer */
         die("failed to create buffer channel");
 
-    if (l2_channel_configure(chBuf, "size,interval", 800, 12) != L2_OK)
+    if (l2_channel_configure(chBuf, "size", 800) != L2_OK)
         die("failed to configure buffer channel");
 
     if ((chFile = l2_channel_create(&l2_handler_file)) == NULL)      /* File   */
@@ -221,20 +220,17 @@
     if (l2_stream_formatter(st, 'S', l2_util_fmt_dump, NULL) != L2_OK)
         die("failed to configure formatter for %%S");
 
-    while (1) {
-        for (i = 1; i != 0; i++);
-        if (l2_stream_log(st, L2_LEVEL_PANIC, "0Checking localhost %s %{myparm}k <%{text}S><%{hex}S><%{base64}S>\n", "foo", 12345, "foo\1bar", 7, "foo\1bar", 7, "foo\1bar", 7) != L2_OK)
-            die("failed to log message to stream");
-
-        if (l2_stream_log(st, L2_LEVEL_PANIC, "1Shecking\n") != L2_OK)
-            die("failed to log message to stream");
-
-        if (l2_stream_log(st, L2_LEVEL_PANIC, "2Checking localhost %s %{myparm}k <%{text}S><%{hex}S><%{base64}S>\n", "foo", 12345, "foo\1bar", 7, "foo\1bar", 7, "foo\1bar", 7) != L2_OK)
-            die("failed to log message to stream");
-
-        if (l2_stream_log(st, L2_LEVEL_PANIC, "3Shecking\n") != L2_OK)
-            die("failed to log message to stream");
-    }
+    if (l2_stream_log(st, L2_LEVEL_PANIC, "0Checking localhost %s %{myparm}k <%{text}S><%{hex}S><%{base64}S>\n", "foo", 12345, "foo\1bar", 7, "foo\1bar", 7, "foo\1bar", 7) != L2_OK)
+        die("failed to log message to stream");
+
+    if (l2_stream_log(st, L2_LEVEL_PANIC, "1Shecking\n") != L2_OK)
+        die("failed to log message to stream");
+
+    if (l2_stream_log(st, L2_LEVEL_PANIC, "2Checking localhost %s %{myparm}k <%{text}S><%{hex}S><%{base64}S>\n", "foo", 12345, "foo\1bar", 7, "foo\1bar", 7, "foo\1bar", 7) != L2_OK)
+        die("failed to log message to stream");
+
+    if (l2_stream_log(st, L2_LEVEL_PANIC, "3Shecking\n") != L2_OK)
+        die("failed to log message to stream");
 
     if (l2_stream_destroy(st) != L2_OK)
         die("failed to destroy stream");

CVSTrac 2.0.1