OSSP CVS Repository

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

Check-in Number: 843
Date: 2001-Sep-04 17:41:17 (local)
2001-Sep-04 15:41:17 (UTC)
User:rse
Branch:
Comment: Revamp channel handler API:

Instead of passing the downstream channel to all channels we instead provide a l2_channel_downstream() function and provide the current channel. This way the handler API is prototype-wise fully orthogonal with the channel API (which it implements) and we no longer pass information to 2/3 of our (output) channels which is of no use there.

Additionally add a channel type field to l2_handler_t which allows a handler to say what type of channel it implements (filter or output). This information is now used in l2_channel_stack() to make sure that one can only stack a filter channel on top of another channel. For convinience reasons there is also a new l2_channel_type() function which allows one to query the type of a particular channel.

Tickets:
Inspections:
Files:
ossp-pkg/l2/l2.h      1.14 -> 1.15     31 inserted, 22 deleted
ossp-pkg/l2/l2_ch_buffer.c      1.11 -> 1.12     16 inserted, 12 deleted
ossp-pkg/l2/l2_ch_fd.c      1.4 -> 1.5     8 inserted, 7 deleted
ossp-pkg/l2/l2_ch_file.c      1.9 -> 1.10     17 inserted, 11 deleted
ossp-pkg/l2/l2_ch_filter.c      1.4 -> 1.5     8 inserted, 7 deleted
ossp-pkg/l2/l2_ch_null.c      1.4 -> 1.5     8 inserted, 8 deleted
ossp-pkg/l2/l2_ch_pipe.c      1.4 -> 1.5     8 inserted, 7 deleted
ossp-pkg/l2/l2_ch_prefix.c      1.4 -> 1.5     8 inserted, 7 deleted
ossp-pkg/l2/l2_ch_socket.c      1.7 -> 1.8     17 inserted, 11 deleted
ossp-pkg/l2/l2_ch_syslog.c      1.9 -> 1.10     17 inserted, 11 deleted
ossp-pkg/l2/l2_channel.c      1.11 -> 1.12     34 inserted, 18 deleted

ossp-pkg/l2/l2.h 1.14 -> 1.15

--- l2.h 2001/09/04 14:56:25     1.14
+++ l2.h 2001/09/04 15:41:17     1.15
@@ -120,15 +120,22 @@
 #define L2_PARAM_END(pa) \
     pa.name = NULL
 
+/* list of handler types */
+typedef enum {
+    L2_CHANNEL_FILTER,
+    L2_CHANNEL_OUTPUT
+} l2_chtype_t;
+
 /* channel handler specification structure */
 struct l2_handler_st {
-    int (*create)   (l2_context_t *ctx);
-    int (*configure)(l2_context_t *ctx, const char *fmt, va_list ap);
-    int (*open)     (l2_context_t *ctx, l2_channel_t *downstream);
-    int (*write)    (l2_context_t *ctx, l2_channel_t *downstream, const char *buf, size_t buf_size);
-    int (*flush)    (l2_context_t *ctx, l2_channel_t *downstream);
-    int (*close)    (l2_context_t *ctx, l2_channel_t *downstream);
-    int (*destroy)  (l2_context_t *ctx);
+    l2_chtype_t type;
+    int (*create)   (l2_context_t *ctx, l2_channel_t *ch);
+    int (*configure)(l2_context_t *ctx, l2_channel_t *ch, const char *fmt, va_list ap);
+    int (*open)     (l2_context_t *ctx, l2_channel_t *ch);
+    int (*write)    (l2_context_t *ctx, l2_channel_t *ch, const char *buf, size_t bufsize);
+    int (*flush)    (l2_context_t *ctx, l2_channel_t *ch);
+    int (*close)    (l2_context_t *ctx, l2_channel_t *ch);
+    int (*destroy)  (l2_context_t *ctx, l2_channel_t *ch);
 };
 
 /* type of formatter callback function */
@@ -156,23 +163,25 @@
 extern l2_handler_t l2_handler_buffer;
 
 /* channel operations */
-l2_channel_t *l2_channel_create   (l2_handler_t *h);
-l2_result_t   l2_channel_configure(l2_channel_t *ch, const char *fmt, ...);
-l2_result_t   l2_channel_open     (l2_channel_t *ch);
-l2_result_t   l2_channel_write    (l2_channel_t *ch, const char *buf, size_t bufsize);
-l2_result_t   l2_channel_flush    (l2_channel_t *ch);
-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_create     (l2_handler_t *h);
+l2_result_t   l2_channel_configure  (l2_channel_t *ch, const char *fmt, ...);
+l2_result_t   l2_channel_open       (l2_channel_t *ch);
+l2_result_t   l2_channel_write      (l2_channel_t *ch, const char *buf, size_t bufsize);
+l2_result_t   l2_channel_flush      (l2_channel_t *ch);
+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);
 
 /* stream operations */
-l2_stream_t  *l2_stream_create    (void);
-l2_result_t   l2_stream_channel   (l2_stream_t *st, l2_channel_t *ch, unsigned int levelmask);
-l2_result_t   l2_stream_formatter (l2_stream_t *st, char id, l2_formatter_t cb, l2_context_t *ctx);
-l2_result_t   l2_stream_levels    (l2_stream_t *st, unsigned int levelmask);
-l2_result_t   l2_stream_log       (l2_stream_t *st, unsigned int level, const char *fmt, ...);
-l2_result_t   l2_stream_vlog      (l2_stream_t *st, unsigned int level, const char *fmt, va_list ap);
-l2_result_t   l2_stream_destroy   (l2_stream_t *st);
+l2_stream_t  *l2_stream_create     (void);
+l2_result_t   l2_stream_channel    (l2_stream_t *st, l2_channel_t *ch, unsigned int levelmask);
+l2_result_t   l2_stream_formatter  (l2_stream_t *st, char id, l2_formatter_t cb, l2_context_t *ctx);
+l2_result_t   l2_stream_levels     (l2_stream_t *st, unsigned int levelmask);
+l2_result_t   l2_stream_log        (l2_stream_t *st, unsigned int level, const char *fmt, ...);
+l2_result_t   l2_stream_vlog       (l2_stream_t *st, unsigned int level, const char *fmt, va_list ap);
+l2_result_t   l2_stream_destroy    (l2_stream_t *st);
 
 /* utility operations */
 l2_result_t   l2_util_setparams(l2_param_t p[], const char *fmt, va_list ap);


ossp-pkg/l2/l2_ch_buffer.c 1.11 -> 1.12

--- l2_ch_buffer.c       2001/09/04 14:54:03     1.11
+++ l2_ch_buffer.c       2001/09/04 15:41:17     1.12
@@ -40,7 +40,7 @@
 } l2_ch_buffer_t;
 
 /* create channel */
-static int hook_create(l2_context_t *ctx)
+static int hook_create(l2_context_t *ctx, l2_channel_t *ch)
 {
     l2_ch_buffer_t *cfg;
 
@@ -60,7 +60,7 @@
 }
 
 /* configure channel */
-static int hook_configure(l2_context_t *ctx, const char *fmt, va_list ap)
+static int hook_configure(l2_context_t *ctx, l2_channel_t *ch, const char *fmt, va_list ap)
 {
     l2_ch_buffer_t *cfg;
     l2_param_t pa[2];
@@ -80,9 +80,10 @@
 }
 
 /* open channel */
-static int hook_open(l2_context_t *ctx, l2_channel_t *downstream)
+static int hook_open(l2_context_t *ctx, l2_channel_t *ch)
 {
     l2_ch_buffer_t *cfg;
+    l2_channel_t *downstream;
 
     /* parameter checks */
     if ((cfg = (l2_ch_buffer_t *)ctx->vp) == NULL)
@@ -96,7 +97,7 @@
     }
 
     /* optionally open downstream channel, too */
-    if (downstream != NULL)
+    if ((downstream = l2_channel_downstream(ch)) != NULL)
         if (l2_channel_open(downstream) == L2_ERROR)
             return L2_ERROR;
 
@@ -104,7 +105,7 @@
 }
 
 /* write to channel */
-static int hook_write(l2_context_t *ctx, l2_channel_t *downstream, 
+static int hook_write(l2_context_t *ctx, l2_channel_t *ch, 
                       const char *buf, size_t bufsize)
 {
     l2_ch_buffer_t *cfg;
@@ -123,9 +124,10 @@
 }
 
 /* flush channel */
-static int hook_flush(l2_context_t *ctx, l2_channel_t *downstream)
+static int hook_flush(l2_context_t *ctx, l2_channel_t *ch)
 {
     l2_ch_buffer_t *cfg;
+    l2_channel_t *downstream;
 
     /* parameter checks */
     if ((cfg = (l2_ch_buffer_t *)ctx->vp) == NULL)
@@ -133,14 +135,14 @@
 
     /* write the buffer contents downstream */
     if (cfg->bufpos > 0) {
-        if (downstream != NULL)
+        if ((downstream = l2_channel_downstream(ch)) != NULL)
             if (l2_channel_write(downstream, cfg->buf, cfg->bufpos) == L2_ERROR)
                 return L2_ERROR;
         cfg->bufpos = 0;
     }
 
     /* optionally flush downstream channel, too */
-    if (downstream != NULL)
+    if ((downstream = l2_channel_downstream(ch)) != NULL)
         if (l2_channel_flush(downstream) == L2_ERROR)
             return L2_ERROR;
 
@@ -148,9 +150,10 @@
 }
 
 /* close channel */
-static int hook_close(l2_context_t *ctx, l2_channel_t *downstream)
+static int hook_close(l2_context_t *ctx, l2_channel_t *ch)
 {
     l2_ch_buffer_t *cfg;
+    l2_channel_t *downstream;
 
     /* parameter checks */
     if ((cfg = (l2_ch_buffer_t *)ctx->vp) == NULL)
@@ -158,14 +161,14 @@
 
     /* write stale data before closing down */
     if (cfg->bufpos > 0) {
-        if (downstream != NULL)
+        if ((downstream = l2_channel_downstream(ch)) != NULL)
             if (l2_channel_write(downstream, cfg->buf, cfg->bufpos) == L2_ERROR)
                 return L2_ERROR;
         cfg->bufpos = 0;
     }
 
     /* optionally close downstream channel, too */
-    if (downstream != NULL)
+    if ((downstream = l2_channel_downstream(ch)) != NULL)
         if (l2_channel_close(downstream) == L2_ERROR)
             return L2_ERROR;
 
@@ -179,7 +182,7 @@
 }
 
 /* destroy channel */
-static int hook_destroy(l2_context_t *ctx)
+static int hook_destroy(l2_context_t *ctx, l2_channel_t *ch)
 {
     l2_ch_buffer_t *cfg;
 
@@ -201,6 +204,7 @@
 
 /* exported channel handler structure */
 l2_handler_t l2_handler_buffer = {
+    L2_CHANNEL_FILTER,
     hook_create,
     hook_configure,
     hook_open,


ossp-pkg/l2/l2_ch_fd.c 1.4 -> 1.5

--- l2_ch_fd.c   2001/08/15 10:36:03     1.4
+++ l2_ch_fd.c   2001/09/04 15:41:17     1.5
@@ -30,43 +30,44 @@
 #include "l2.h"
 #include "l2_p.h"
 
-static int hook_create(l2_context_t *ctx)
+static int hook_create(l2_context_t *ctx, l2_channel_t *ch)
 {
     return L2_OK;
 }
 
-static int hook_configure(l2_context_t *ctx, const char *fmt, va_list ap)
+static int hook_configure(l2_context_t *ctx, l2_channel_t *ch, const char *fmt, va_list ap)
 {
     return L2_OK;
 }
 
-static int hook_open(l2_context_t *ctx, l2_channel_t *downstream)
+static int hook_open(l2_context_t *ctx, l2_channel_t *ch)
 {
     return L2_OK;
 }
 
-static int hook_write(l2_context_t *ctx, l2_channel_t *downstream, 
+static int hook_write(l2_context_t *ctx, l2_channel_t *ch, 
                       const char *buf, size_t buf_size)
 {
     return L2_OK;
 }
 
-static int hook_flush(l2_context_t *ctx, l2_channel_t *downstream)
+static int hook_flush(l2_context_t *ctx, l2_channel_t *ch)
 {
     return L2_OK;
 }
 
-static int hook_close(l2_context_t *ctx, l2_channel_t *downstream)
+static int hook_close(l2_context_t *ctx, l2_channel_t *ch)
 {
     return L2_OK;
 }
 
-static int hook_destroy(l2_context_t *ctx)
+static int hook_destroy(l2_context_t *ctx, l2_channel_t *ch)
 {
     return L2_OK;
 }
 
 l2_handler_t l2_handler_fd = {
+    L2_CHANNEL_OUTPUT,
     hook_create,
     hook_configure,
     hook_open,


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

--- l2_ch_file.c 2001/09/04 13:52:59     1.9
+++ l2_ch_file.c 2001/09/04 15:41:17     1.10
@@ -43,7 +43,7 @@
 } l2_ch_file_t;
 
 /* create channel */
-static int hook_create(l2_context_t *ctx)
+static int hook_create(l2_context_t *ctx, l2_channel_t *ch)
 {
     l2_ch_file_t *cfg;
 
@@ -64,7 +64,7 @@
 }
 
 /* configure channel */
-static int hook_configure(l2_context_t *ctx, const char *fmt, va_list ap)
+static int hook_configure(l2_context_t *ctx, l2_channel_t *ch, const char *fmt, va_list ap)
 {
     l2_ch_file_t *cfg;
     l2_param_t pa[4]; 
@@ -85,9 +85,10 @@
 }
 
 /* open channel */
-static int hook_open(l2_context_t *ctx, l2_channel_t *downstream)
+static int hook_open(l2_context_t *ctx, l2_channel_t *ch)
 {
     l2_ch_file_t *cfg;
+    l2_channel_t *downstream;
     int mode;
 
     /* parameter checks */
@@ -104,7 +105,7 @@
         return L2_ERROR;
 
     /* optionally open downstream channel, too */
-    if (downstream != NULL)
+    if ((downstream = l2_channel_downstream(ch)) != NULL)
         if (l2_channel_open(downstream) == L2_ERROR)
             return L2_ERROR;
 
@@ -112,10 +113,11 @@
 }
 
 /* write to channel */
-static int hook_write(l2_context_t *ctx, l2_channel_t *downstream, 
+static int hook_write(l2_context_t *ctx, l2_channel_t *ch, 
                       const char *buf, size_t buf_size)
 {
     l2_ch_file_t *cfg;
+    l2_channel_t *downstream;
 
     /* parameter checks */
     if ((cfg = (l2_ch_file_t *)ctx->vp) == NULL)
@@ -128,7 +130,7 @@
         return L2_ERROR;
 
     /* optionally write to downstream channel, too */
-    if (downstream != NULL)
+    if ((downstream = l2_channel_downstream(ch)) != NULL)
         if (l2_channel_write(downstream, buf, buf_size) == L2_ERROR)
             return L2_ERROR;
 
@@ -136,12 +138,14 @@
 }
 
 /* flush channel */
-static int hook_flush(l2_context_t *ctx, l2_channel_t *downstream)
+static int hook_flush(l2_context_t *ctx, l2_channel_t *ch)
 {
+    l2_channel_t *downstream;
+
     /* NOP for this channel, because Unix I/O files are unbuffered! */
 
     /* optionally flush downstream channel, too */
-    if (downstream != NULL)
+    if ((downstream = l2_channel_downstream(ch)) != NULL)
         if (l2_channel_flush(downstream) == L2_ERROR)
             return L2_ERROR;
 
@@ -149,12 +153,13 @@
 }
 
 /* close channel */
-static int hook_close(l2_context_t *ctx, l2_channel_t *downstream)
+static int hook_close(l2_context_t *ctx, l2_channel_t *ch)
 {
     l2_ch_file_t *cfg;
+    l2_channel_t *downstream;
 
     /* optionally close downstream channel, too */
-    if (downstream != NULL)
+    if ((downstream = l2_channel_downstream(ch)) != NULL)
         if (l2_channel_close(downstream) == L2_ERROR)
             return L2_ERROR;
 
@@ -172,7 +177,7 @@
 }
 
 /* destroy channel */
-static int hook_destroy(l2_context_t *ctx)
+static int hook_destroy(l2_context_t *ctx, l2_channel_t *ch)
 {
     /* parameter checks */
     if (ctx->vp == NULL) 
@@ -186,6 +191,7 @@
 
 /* exported channel handler structure */
 l2_handler_t l2_handler_file = {
+    L2_CHANNEL_OUTPUT,
     hook_create,
     hook_configure,
     hook_open,


ossp-pkg/l2/l2_ch_filter.c 1.4 -> 1.5

--- l2_ch_filter.c       2001/08/15 10:36:03     1.4
+++ l2_ch_filter.c       2001/09/04 15:41:17     1.5
@@ -30,43 +30,44 @@
 #include "l2.h"
 #include "l2_p.h"
 
-static int hook_create(l2_context_t *ctx)
+static int hook_create(l2_context_t *ctx, l2_channel_t *ch)
 {
     return L2_OK;
 }
 
-static int hook_configure(l2_context_t *ctx, const char *fmt, va_list ap)
+static int hook_configure(l2_context_t *ctx, l2_channel_t *ch, const char *fmt, va_list ap)
 {
     return L2_OK;
 }
 
-static int hook_open(l2_context_t *ctx, l2_channel_t *downstream)
+static int hook_open(l2_context_t *ctx, l2_channel_t *ch)
 {
     return L2_OK;
 }
 
-static int hook_write(l2_context_t *ctx, l2_channel_t *downstream, 
+static int hook_write(l2_context_t *ctx, l2_channel_t *ch, 
                       const char *buf, size_t buf_size)
 {
     return L2_OK;
 }
 
-static int hook_flush(l2_context_t *ctx, l2_channel_t *downstream)
+static int hook_flush(l2_context_t *ctx, l2_channel_t *ch)
 {
     return L2_OK;
 }
 
-static int hook_close(l2_context_t *ctx, l2_channel_t *downstream)
+static int hook_close(l2_context_t *ctx, l2_channel_t *ch)
 {
     return L2_OK;
 }
 
-static int hook_destroy(l2_context_t *ctx)
+static int hook_destroy(l2_context_t *ctx, l2_channel_t *ch)
 {
     return L2_OK;
 }
 
 l2_handler_t l2_handler_filter = {
+    L2_CHANNEL_FILTER,
     hook_create,
     hook_configure,
     hook_open,


ossp-pkg/l2/l2_ch_null.c 1.4 -> 1.5

--- l2_ch_null.c 2001/08/15 10:36:03     1.4
+++ l2_ch_null.c 2001/09/04 15:41:17     1.5
@@ -30,43 +30,43 @@
 #include "l2.h"
 #include "l2_p.h"
 
-static int hook_create(l2_context_t *ctx)
+static int hook_create(l2_context_t *ctx, l2_channel_t *ch)
 {
     return L2_OK;
 }
 
-static int hook_configure(l2_context_t *ctx, const char *fmt, va_list ap)
+static int hook_configure(l2_context_t *ctx, l2_channel_t *ch, const char *fmt, va_list ap)
 {
     return L2_OK;
 }
 
-static int hook_open(l2_context_t *ctx, l2_channel_t *downstream)
+static int hook_open(l2_context_t *ctx, l2_channel_t *ch)
 {
     return L2_OK;
 }
 
-static int hook_write(l2_context_t *ctx, l2_channel_t *downstream, 
-                      const char *buf, size_t buf_size)
+static int hook_write(l2_context_t *ctx, l2_channel_t *ch, const char *buf, size_t buf_size)
 {
     return L2_OK;
 }
 
-static int hook_flush(l2_context_t *ctx, l2_channel_t *downstream)
+static int hook_flush(l2_context_t *ctx, l2_channel_t *ch)
 {
     return L2_OK;
 }
 
-static int hook_close(l2_context_t *ctx, l2_channel_t *downstream)
+static int hook_close(l2_context_t *ctx, l2_channel_t *ch)
 {
     return L2_OK;
 }
 
-static int hook_destroy(l2_context_t *ctx)
+static int hook_destroy(l2_context_t *ctx, l2_channel_t *ch)
 {
     return L2_OK;
 }
 
 l2_handler_t l2_handler_null = {
+    L2_CHANNEL_OUTPUT,
     hook_create,
     hook_configure,
     hook_open,


ossp-pkg/l2/l2_ch_pipe.c 1.4 -> 1.5

--- l2_ch_pipe.c 2001/08/15 10:36:03     1.4
+++ l2_ch_pipe.c 2001/09/04 15:41:17     1.5
@@ -30,43 +30,44 @@
 #include "l2.h"
 #include "l2_p.h"
 
-static int hook_create(l2_context_t *ctx)
+static int hook_create(l2_context_t *ctx, l2_channel_t *ch)
 {
     return L2_OK;
 }
 
-static int hook_configure(l2_context_t *ctx, const char *fmt, va_list ap)
+static int hook_configure(l2_context_t *ctx, l2_channel_t *ch, const char *fmt, va_list ap)
 {
     return L2_OK;
 }
 
-static int hook_open(l2_context_t *ctx, l2_channel_t *downstream)
+static int hook_open(l2_context_t *ctx, l2_channel_t *ch)
 {
     return L2_OK;
 }
 
-static int hook_write(l2_context_t *ctx, l2_channel_t *downstream, 
+static int hook_write(l2_context_t *ctx, l2_channel_t *ch, 
                       const char *buf, size_t buf_size)
 {
     return L2_OK;
 }
 
-static int hook_flush(l2_context_t *ctx, l2_channel_t *downstream)
+static int hook_flush(l2_context_t *ctx, l2_channel_t *ch)
 {
     return L2_OK;
 }
 
-static int hook_close(l2_context_t *ctx, l2_channel_t *downstream)
+static int hook_close(l2_context_t *ctx, l2_channel_t *ch)
 {
     return L2_OK;
 }
 
-static int hook_destroy(l2_context_t *ctx)
+static int hook_destroy(l2_context_t *ctx, l2_channel_t *ch)
 {
     return L2_OK;
 }
 
 l2_handler_t l2_handler_pipe = {
+    L2_CHANNEL_OUTPUT,
     hook_create,
     hook_configure,
     hook_open,


ossp-pkg/l2/l2_ch_prefix.c 1.4 -> 1.5

--- l2_ch_prefix.c       2001/08/15 10:36:03     1.4
+++ l2_ch_prefix.c       2001/09/04 15:41:17     1.5
@@ -30,43 +30,44 @@
 #include "l2.h"
 #include "l2_p.h"
 
-static int hook_create(l2_context_t *ctx)
+static int hook_create(l2_context_t *ctx, l2_channel_t *ch)
 {
     return L2_OK;
 }
 
-static int hook_configure(l2_context_t *ctx, const char *fmt, va_list ap)
+static int hook_configure(l2_context_t *ctx, l2_channel_t *ch, const char *fmt, va_list ap)
 {
     return L2_OK;
 }
 
-static int hook_open(l2_context_t *ctx, l2_channel_t *downstream)
+static int hook_open(l2_context_t *ctx, l2_channel_t *ch)
 {
     return L2_OK;
 }
 
-static int hook_write(l2_context_t *ctx, l2_channel_t *downstream, 
+static int hook_write(l2_context_t *ctx, l2_channel_t *ch, 
                       const char *buf, size_t buf_size)
 {
     return L2_OK;
 }
 
-static int hook_flush(l2_context_t *ctx, l2_channel_t *downstream)
+static int hook_flush(l2_context_t *ctx, l2_channel_t *ch)
 {
     return L2_OK;
 }
 
-static int hook_close(l2_context_t *ctx, l2_channel_t *downstream)
+static int hook_close(l2_context_t *ctx, l2_channel_t *ch)
 {
     return L2_OK;
 }
 
-static int hook_destroy(l2_context_t *ctx)
+static int hook_destroy(l2_context_t *ctx, l2_channel_t *ch)
 {
     return L2_OK;
 }
 
 l2_handler_t l2_handler_prefix = {
+    L2_CHANNEL_FILTER,
     hook_create,
     hook_configure,
     hook_open,


ossp-pkg/l2/l2_ch_socket.c 1.7 -> 1.8

--- l2_ch_socket.c       2001/09/04 13:52:59     1.7
+++ l2_ch_socket.c       2001/09/04 15:41:17     1.8
@@ -95,7 +95,7 @@
 } l2_ch_socket_t;
 
 /* create channel */
-static int hook_create(l2_context_t *ctx)
+static int hook_create(l2_context_t *ctx, l2_channel_t *ch)
 {
     l2_ch_socket_t *cfg = NULL;
 
@@ -115,7 +115,7 @@
 }
 
 /* configure channel */
-static int hook_configure(l2_context_t *ctx, const char *fmt, va_list ap)
+static int hook_configure(l2_context_t *ctx, l2_channel_t *ch, const char *fmt, va_list ap)
 {
     l2_ch_socket_t *cfg;
     l2_param_t pa[3];
@@ -135,12 +135,13 @@
 }
 
 /* open channel */
-static int hook_open(l2_context_t *ctx, l2_channel_t *downstream)
+static int hook_open(l2_context_t *ctx, l2_channel_t *ch)
 {
     l2_ch_socket_t      *cfg;
     struct hostent      *pHostentry;
     struct sockaddr_in  IP4Sockaddr;
     struct sockaddr_in6 IP6Sockaddr;
+    l2_channel_t *downstream;
 
     /* parameter checks */
     if ((cfg = (l2_ch_socket_t *)ctx->vp) == NULL)
@@ -188,7 +189,7 @@
     }
 
     /* optionally open downstream channel, too */
-    if (downstream != NULL)
+    if ((downstream = l2_channel_downstream(ch)) != NULL)
         if (l2_channel_open(downstream) == L2_ERROR)
             return L2_ERROR;
 
@@ -196,10 +197,11 @@
 }
 
 /* write to channel */
-static int hook_write(l2_context_t *ctx, l2_channel_t *downstream, 
+static int hook_write(l2_context_t *ctx, l2_channel_t *ch, 
                       const char *buf, size_t buf_size)
 {
     l2_ch_socket_t *cfg;
+    l2_channel_t *downstream;
 
     /* parameter checks */
     if ((cfg = (l2_ch_socket_t *)ctx->vp) == NULL)
@@ -212,7 +214,7 @@
         return L2_ERROR;
 
     /* optionally write to downstream channel, too */
-    if (downstream != NULL)
+    if ((downstream = l2_channel_downstream(ch)) != NULL)
         if (l2_channel_write(downstream, buf, buf_size) == L2_ERROR)
             return L2_ERROR;
 
@@ -220,12 +222,14 @@
 }
 
 /* flush channel */
-static int hook_flush(l2_context_t *ctx, l2_channel_t *downstream)
+static int hook_flush(l2_context_t *ctx, l2_channel_t *ch)
 {
+    l2_channel_t *downstream;
+
     /* NOP for this channel, because Unix I/O sockets are unbuffered! */
 
     /* optionally flush downstream channel, too */
-    if (downstream != NULL)
+    if ((downstream = l2_channel_downstream(ch)) != NULL)
         if (l2_channel_flush(downstream) == L2_ERROR)
             return L2_ERROR;
 
@@ -233,12 +237,13 @@
 }
 
 /* close channel */
-static int hook_close(l2_context_t *ctx, l2_channel_t *downstream)
+static int hook_close(l2_context_t *ctx, l2_channel_t *ch)
 {
     l2_ch_socket_t *cfg;
+    l2_channel_t *downstream;
 
     /* optionally close downstream channel, too */
-    if (downstream != NULL)
+    if ((downstream = l2_channel_downstream(ch)) != NULL)
         if (l2_channel_close(downstream) == L2_ERROR)
             return L2_ERROR;
 
@@ -256,7 +261,7 @@
 }
 
 /* destroy channel */
-static int hook_destroy(l2_context_t *ctx)
+static int hook_destroy(l2_context_t *ctx, l2_channel_t *ch)
 {
     /* parameter checks */
     if (ctx->vp == NULL) 
@@ -270,6 +275,7 @@
 
 /* exported channel handler structure */
 l2_handler_t l2_handler_socket = {
+    L2_CHANNEL_OUTPUT,
     hook_create,
     hook_configure,
     hook_open,


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

--- l2_ch_syslog.c       2001/09/04 13:52:59     1.9
+++ l2_ch_syslog.c       2001/09/04 15:41:17     1.10
@@ -42,7 +42,7 @@
 } l2_ch_syslog_t;
 
 /* create channel */
-static int hook_create(l2_context_t *ctx)
+static int hook_create(l2_context_t *ctx, l2_channel_t *ch)
 {
     l2_ch_syslog_t *cfg;
 
@@ -64,7 +64,7 @@
 }
 
 /* configure channel */
-static int hook_configure(l2_context_t *ctx, const char *fmt, va_list ap)
+static int hook_configure(l2_context_t *ctx, l2_channel_t *ch, const char *fmt, va_list ap)
 {
     l2_ch_syslog_t *cfg;
     l2_param_t pa[3];
@@ -87,9 +87,10 @@
 }
 
 /* open channel */
-static int hook_open(l2_context_t *ctx, l2_channel_t *downstream)
+static int hook_open(l2_context_t *ctx, l2_channel_t *ch)
 {
     l2_ch_syslog_t *cfg;
+    l2_channel_t *downstream;
 
     /* parameter checks */
     if ((cfg = (l2_ch_syslog_t *)ctx->vp) == NULL)
@@ -100,7 +101,7 @@
     setlogmask(cfg->iMaskpri);
 
     /* optionally open downstream channel, too */
-    if (downstream != NULL)
+    if ((downstream = l2_channel_downstream(ch)) != NULL)
         if (l2_channel_open(downstream) == L2_ERROR)
             return L2_ERROR;
 
@@ -108,10 +109,11 @@
 }
 
 /* write to channel */
-static int hook_write(l2_context_t *ctx, l2_channel_t *downstream, 
+static int hook_write(l2_context_t *ctx, l2_channel_t *ch, 
                       const char *buf, size_t buf_size)
 {
     l2_ch_syslog_t *cfg;
+    l2_channel_t *downstream;
 
     /* parameter checks */
     if ((cfg = (l2_ch_syslog_t *)ctx->vp) == NULL)
@@ -121,7 +123,7 @@
     syslog(cfg->iPriority, buf);
 
     /* optionally write to downstream channel, too */
-    if (downstream != NULL)
+    if ((downstream = l2_channel_downstream(ch)) != NULL)
         if (l2_channel_write(downstream, buf, buf_size) == L2_ERROR)
             return L2_ERROR;
 
@@ -129,12 +131,14 @@
 }
 
 /* flush channel */
-static int hook_flush(l2_context_t *ctx, l2_channel_t *downstream)
+static int hook_flush(l2_context_t *ctx, l2_channel_t *ch)
 {
+    l2_channel_t *downstream;
+
     /* Noop for this channel, because syslog entries are unbuffered */
 
     /* optionally flush downstream channel, too */
-    if (downstream != NULL)
+    if ((downstream = l2_channel_downstream(ch)) != NULL)
         if (l2_channel_flush(downstream) == L2_ERROR)
             return L2_ERROR;
 
@@ -142,12 +146,13 @@
 }
 
 /* close channel */
-static int hook_close(l2_context_t *ctx, l2_channel_t *downstream)
+static int hook_close(l2_context_t *ctx, l2_channel_t *ch)
 {
     l2_ch_syslog_t *cfg;
+    l2_channel_t *downstream;
 
     /* optionally close downstream channel, too */
-    if (downstream != NULL)
+    if ((downstream = l2_channel_downstream(ch)) != NULL)
         if (l2_channel_close(downstream) == L2_ERROR)
             return L2_ERROR;
 
@@ -162,7 +167,7 @@
 }
 
 /* destroy channel */
-static int hook_destroy(l2_context_t *ctx)
+static int hook_destroy(l2_context_t *ctx, l2_channel_t *ch)
 {
     /* parameter checks */
     if (ctx->vp == NULL) 
@@ -176,6 +181,7 @@
 
 /* exported channel handler structure */
 l2_handler_t l2_handler_syslog = {
+    L2_CHANNEL_OUTPUT,
     hook_create,
     hook_configure,
     hook_open,


ossp-pkg/l2/l2_channel.c 1.11 -> 1.12

--- l2_channel.c 2001/09/04 13:52:59     1.11
+++ l2_channel.c 2001/09/04 15:41:17     1.12
@@ -45,24 +45,13 @@
     ch->downstream = NULL;
     memset(&ch->context, 0, sizeof(l2_context_t));
     memcpy(&ch->handler, h, sizeof(l2_handler_t));
-    if (ch->handler.create(&ch->context) == L2_ERROR) {
+    if (ch->handler.create(&ch->context, ch) == L2_ERROR) {
         free(ch);
         return NULL;
     }
     return ch;
 }
 
-l2_result_t l2_channel_stack(l2_channel_t *ch, l2_channel_t *chTop)
-{
-    if (ch == NULL || chTop == NULL)
-        return L2_ERROR;
-    if (   ch->state    != L2_CHSTATE_CREATED
-        || chTop->state != L2_CHSTATE_CREATED)
-        return L2_ERROR;
-    chTop->downstream = ch;
-    return L2_OK;
-}
-
 l2_result_t l2_channel_configure(l2_channel_t *ch, const char *fmt, ...)
 {
     l2_result_t rv;
@@ -73,7 +62,7 @@
     if (ch->state != L2_CHSTATE_CREATED)
         return L2_ERROR;
     va_start(ap, fmt);
-    rv = ch->handler.configure(&ch->context, fmt, ap);
+    rv = ch->handler.configure(&ch->context, ch, fmt, ap);
     va_end(ap);
     return rv;
 }
@@ -90,7 +79,7 @@
         ch = ch->downstream;
     if (ch == NULL)
         return L2_ERROR;
-    rv = ch->handler.open(&ch->context, ch->downstream);
+    rv = ch->handler.open(&ch->context, ch);
     if (rv == L2_OK)
         ch->state = L2_CHSTATE_OPENED;
     return rv;
@@ -112,7 +101,7 @@
         ch = ch->downstream;
     if (ch == NULL)
         return L2_ERROR;
-    rv = ch->handler.write(&ch->context, ch->downstream, buf, bufsize);
+    rv = ch->handler.write(&ch->context, ch, buf, bufsize);
     return rv;
 }
 
@@ -128,7 +117,7 @@
         ch = ch->downstream;
     if (ch == NULL)
         return L2_ERROR;
-    rv = ch->handler.flush(&ch->context, ch->downstream);
+    rv = ch->handler.flush(&ch->context, ch);
     return rv;
 }
 
@@ -144,7 +133,7 @@
         ch = ch->downstream;
     if (ch == NULL)
         return L2_ERROR;
-    rv = ch->handler.close(&ch->context, ch->downstream);
+    rv = ch->handler.close(&ch->context, ch);
     if (rv == L2_OK)
         ch->state = L2_CHSTATE_CREATED;
     return rv;
@@ -162,10 +151,37 @@
     while (ch != NULL && ch->handler.destroy == NULL)
         ch = ch->downstream;
     if (ch != NULL)
-        rv = ch->handler.destroy(&ch->context);
+        rv = ch->handler.destroy(&ch->context, ch);
     else
         rv = L2_OK;
     free(ch);
     return rv;
 }
 
+l2_result_t l2_channel_stack(l2_channel_t *ch, l2_channel_t *chTop)
+{
+    if (ch == NULL || chTop == NULL)
+        return L2_ERROR;
+    if (   ch->state    != L2_CHSTATE_CREATED
+        || chTop->state != L2_CHSTATE_CREATED)
+        return L2_ERROR;
+    if (chTop->handler.type != L2_CHANNEL_FILTER)
+        return L2_ERROR;
+    chTop->downstream = ch;
+    return L2_OK;
+}
+
+l2_channel_t *l2_channel_downstream(l2_channel_t *ch)
+{
+    if (ch == NULL)
+        return NULL;
+    return ch->downstream;
+}
+
+l2_chtype_t l2_channel_type(l2_channel_t *ch)
+{
+    if (ch == NULL)
+        return NULL;
+    return ch->handler.type;
+}
+

CVSTrac 2.0.1