OSSP CVS Repository

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

Check-in Number: 1259
Date: 2001-Nov-07 12:37:18 (local)
2001-Nov-07 11:37:18 (UTC)
User:rse
Branch:
Comment: More preparations for forthcoming channel tree specification parser (especially to allow the parser to determine the handler structure from a handler name without introducing another and this way redundant sub-API):

- add "char *name" to l2_handler_t in order to tag each handler structure with the corresponding channel name

- add l2_env_handler() function to add handler to l2_env_t objects. All l2_handler_xxxx are automatically pre-configured there after l2_env_create().

- change l2_channel_create() to take a "const char *name" (handler name) instead of the "l2_handler_t *h" (handler pointer) to make the stuff consistent and more clear.

- adjust l2_test.c to reflect the changes.

Tickets:
Inspections:
Files:
ossp-pkg/l2/l2.h.in      1.18 -> 1.19     5 inserted, 3 deleted
ossp-pkg/l2/l2_ch_buffer.c      1.32 -> 1.33     1 inserted, 0 deleted
ossp-pkg/l2/l2_ch_fd.c      1.10 -> 1.11     1 inserted, 0 deleted
ossp-pkg/l2/l2_ch_file.c      1.17 -> 1.18     1 inserted, 0 deleted
ossp-pkg/l2/l2_ch_filter.c      1.12 -> 1.13     1 inserted, 0 deleted
ossp-pkg/l2/l2_ch_irc.c      1.2 -> 1.3     1 inserted, 0 deleted
ossp-pkg/l2/l2_ch_noop.c      1.1 -> 1.2     1 inserted, 0 deleted
ossp-pkg/l2/l2_ch_null.c      1.9 -> 1.10     1 inserted, 0 deleted
ossp-pkg/l2/l2_ch_pipe.c      1.26 -> 1.27     1 inserted, 0 deleted
ossp-pkg/l2/l2_ch_prefix.c      1.16 -> 1.17     1 inserted, 0 deleted
ossp-pkg/l2/l2_ch_smtp.c      1.6 -> 1.7     1 inserted, 0 deleted
ossp-pkg/l2/l2_ch_socket.c      1.32 -> 1.33     1 inserted, 0 deleted
ossp-pkg/l2/l2_ch_syslog.c      1.25 -> 1.26     1 inserted, 0 deleted
ossp-pkg/l2/l2_channel.c      1.24 -> 1.25     15 inserted, 2 deleted
ossp-pkg/l2/l2_env.c      1.2 -> 1.3     37 inserted, 0 deleted
ossp-pkg/l2/l2_p.h      1.29 -> 1.30     2 inserted, 0 deleted
ossp-pkg/l2/l2_test.c      1.41 -> 1.42     7 inserted, 7 deleted

ossp-pkg/l2/l2.h.in 1.18 -> 1.19

--- l2.h.in      2001/11/06 15:02:49     1.18
+++ l2.h.in      2001/11/07 11:37:18     1.19
@@ -169,6 +169,7 @@
 
 /* channel handler specification structure */
 struct l2_handler_st {
+    const char *name;
     l2_chtype_t type;
     l2_result_t (*create)   (l2_context_t *ctx, l2_channel_t *ch);
     l2_result_t (*configure)(l2_context_t *ctx, l2_channel_t *ch, const char *fmt, va_list ap);
@@ -190,7 +191,7 @@
     va_list      *ap        /* in/out arg: variable argument pointer */
 );
 
-/* list of shipped (output) channel handlers */
+/* list of shipped (output) channel handlers (pre-configured in l2_env_t objects) */
 extern l2_handler_t l2_handler_null;
 extern l2_handler_t l2_handler_fd;
 extern l2_handler_t l2_handler_file;
@@ -199,7 +200,7 @@
 extern l2_handler_t l2_handler_syslog;
 extern l2_handler_t l2_handler_smtp;
 
-/* list of shipped (filter) channel handlers */
+/* list of shipped (filter) channel handlers (pre-configured in l2_env_t objects) */
 extern l2_handler_t l2_handler_noop;
 extern l2_handler_t l2_handler_filter;
 extern l2_handler_t l2_handler_prefix;
@@ -210,11 +211,12 @@
 l2_result_t   l2_env_destroy        (l2_env_t *env);
 l2_result_t   l2_env_levels         (l2_env_t *env, unsigned int levelmask, unsigned int flushmask);
 l2_result_t   l2_env_formatter      (l2_env_t *env, char id, l2_formatter_t cb, l2_context_t *ctx);
+l2_result_t   l2_env_handler        (l2_env_t *env, l2_handler_t *h);
 l2_result_t   l2_env_errorinfo      (l2_env_t *env, l2_result_t rv, const char *fmt, ...);
 char         *l2_env_strerror       (l2_env_t *env, l2_result_t rv);
 
 /* channel operations */
-l2_result_t   l2_channel_create     (l2_channel_t **ch, l2_env_t *env, l2_handler_t *h);
+l2_result_t   l2_channel_create     (l2_channel_t **ch, l2_env_t *env, const char *name);
 l2_result_t   l2_channel_destroy    (l2_channel_t *ch);
 l2_result_t   l2_channel_levels     (l2_channel_t *ch, unsigned int levelmask, unsigned int flushmask);
 l2_result_t   l2_channel_configure  (l2_channel_t *ch, const char *fmt, ...);


ossp-pkg/l2/l2_ch_buffer.c 1.32 -> 1.33

--- l2_ch_buffer.c       2001/11/04 14:11:04     1.32
+++ l2_ch_buffer.c       2001/11/07 11:37:18     1.33
@@ -338,6 +338,7 @@
 
 /* exported channel handler structure */
 l2_handler_t l2_handler_buffer = {
+    "buffer",
     L2_CHANNEL_FILTER,
     hook_create,
     hook_configure,


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

--- l2_ch_fd.c   2001/09/12 09:35:57     1.10
+++ l2_ch_fd.c   2001/11/07 11:37:18     1.11
@@ -145,6 +145,7 @@
 
 /* exported channel handler structure */
 l2_handler_t l2_handler_fd = {
+    "fd",
     L2_CHANNEL_OUTPUT,
     hook_create,
     hook_configure,


ossp-pkg/l2/l2_ch_file.c 1.17 -> 1.18

--- l2_ch_file.c 2001/09/12 09:42:34     1.17
+++ l2_ch_file.c 2001/11/07 11:37:18     1.18
@@ -137,6 +137,7 @@
 
 /* exported channel handler structure */
 l2_handler_t l2_handler_file = {
+    "file",
     L2_CHANNEL_OUTPUT,
     hook_create,
     hook_configure,


ossp-pkg/l2/l2_ch_filter.c 1.12 -> 1.13

--- l2_ch_filter.c       2001/11/04 13:21:17     1.12
+++ l2_ch_filter.c       2001/11/07 11:37:18     1.13
@@ -137,6 +137,7 @@
 }
 
 l2_handler_t l2_handler_filter = {
+    "filter",
     L2_CHANNEL_FILTER,
     hook_create,
     hook_configure,


ossp-pkg/l2/l2_ch_irc.c 1.2 -> 1.3

--- l2_ch_irc.c  2001/10/19 13:06:35     1.2
+++ l2_ch_irc.c  2001/11/07 11:37:18     1.3
@@ -289,6 +289,7 @@
 
 /* exported channel handler structure */
 l2_handler_t l2_handler_irc = {
+    "irc",
     L2_CHANNEL_OUTPUT,
     hook_create,
     hook_configure,


ossp-pkg/l2/l2_ch_noop.c 1.1 -> 1.2

--- l2_ch_noop.c 2001/11/05 20:39:35     1.1
+++ l2_ch_noop.c 2001/11/07 11:37:18     1.2
@@ -30,6 +30,7 @@
 #include "l2.h"
 
 l2_handler_t l2_handler_noop = {
+    "noop",
     L2_CHANNEL_FILTER,
     NULL,
     NULL,


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

--- l2_ch_null.c 2001/11/04 14:08:24     1.9
+++ l2_ch_null.c 2001/11/07 11:37:18     1.10
@@ -30,6 +30,7 @@
 #include "l2.h"
 
 l2_handler_t l2_handler_null = {
+    "null",
     L2_CHANNEL_OUTPUT,
     NULL,
     NULL,


ossp-pkg/l2/l2_ch_pipe.c 1.26 -> 1.27

--- l2_ch_pipe.c 2001/10/30 18:56:13     1.26
+++ l2_ch_pipe.c 2001/11/07 11:37:18     1.27
@@ -411,6 +411,7 @@
 
 /* exported channel handler structure */
 l2_handler_t l2_handler_pipe = {
+    "pipe",
     L2_CHANNEL_OUTPUT,
     hook_create,
     hook_configure,


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

--- l2_ch_prefix.c       2001/11/03 22:51:36     1.16
+++ l2_ch_prefix.c       2001/11/07 11:37:18     1.17
@@ -184,6 +184,7 @@
 
 /* exported channel handler structure */
 l2_handler_t l2_handler_prefix = {
+    "prefix",
     L2_CHANNEL_FILTER,
     hook_create,
     hook_configure,


ossp-pkg/l2/l2_ch_smtp.c 1.6 -> 1.7

--- l2_ch_smtp.c 2001/10/19 11:55:00     1.6
+++ l2_ch_smtp.c 2001/11/07 11:37:18     1.7
@@ -330,6 +330,7 @@
 
 /* exported channel handler structure */
 l2_handler_t l2_handler_smtp = {
+    "smtp",
     L2_CHANNEL_OUTPUT,
     hook_create,
     hook_configure,


ossp-pkg/l2/l2_ch_socket.c 1.32 -> 1.33

--- l2_ch_socket.c       2001/11/03 20:49:25     1.32
+++ l2_ch_socket.c       2001/11/07 11:37:18     1.33
@@ -201,6 +201,7 @@
 
 /* exported channel handler structure */
 l2_handler_t l2_handler_socket = {
+    "socket",
     L2_CHANNEL_OUTPUT,
     hook_create,
     hook_configure,


ossp-pkg/l2/l2_ch_syslog.c 1.25 -> 1.26

--- l2_ch_syslog.c       2001/10/12 13:51:41     1.25
+++ l2_ch_syslog.c       2001/11/07 11:37:18     1.26
@@ -351,6 +351,7 @@
 
 /* exported channel handler structure */
 l2_handler_t l2_handler_syslog = {
+    "syslog",
     L2_CHANNEL_OUTPUT,
     hook_create,
     hook_configure,


ossp-pkg/l2/l2_channel.c 1.24 -> 1.25

--- l2_channel.c 2001/11/06 15:02:49     1.24
+++ l2_channel.c 2001/11/07 11:37:18     1.25
@@ -67,14 +67,27 @@
  */
 
 /* create channel */
-l2_result_t l2_channel_create(l2_channel_t **chp, l2_env_t *env, l2_handler_t *h)
+l2_result_t l2_channel_create(l2_channel_t **chp, l2_env_t *env, const char *name)
 {
     l2_channel_t *ch;
+    l2_handler_t *h;
+    int i;
 
     /* argument sanity check */
-    if (h == NULL || env == NULL)
+    if (env == NULL || name == NULL)
         return L2_ERR_ARG;
 
+    /* lookup channel handler */
+    h = NULL;
+    for (i = 0; i < L2_MAX_HANDLERS && env->handlers[i] != NULL; i++) {
+        if (strcmp(env->handlers[i]->name, name) == 0) {
+            h = env->handlers[i];
+            break;
+        }
+    }
+    if (h == NULL)
+        return L2_ERR_CH;
+
     /* allocate channel structure */
     if ((ch = (l2_channel_t *)malloc(sizeof(l2_channel_t))) == NULL)
         return L2_ERR_SYS;


ossp-pkg/l2/l2_env.c 1.2 -> 1.3

--- l2_env.c     2001/11/04 13:55:06     1.2
+++ l2_env.c     2001/11/07 11:37:18     1.3
@@ -51,6 +51,21 @@
     env->flushmask = L2_LEVEL_NONE;
     for (i = 0; i < L2_MAX_FORMATTERS; i++)
         env->formatters[i].cb = NULL;
+    for (i = 0; i < L2_MAX_HANDLERS; i++)
+        env->handlers[i] = NULL;
+
+    /* pre-configure all handlers we ship */
+    l2_env_handler(env, &l2_handler_null);
+    l2_env_handler(env, &l2_handler_fd);
+    l2_env_handler(env, &l2_handler_file);
+    l2_env_handler(env, &l2_handler_pipe);
+    l2_env_handler(env, &l2_handler_socket);
+    l2_env_handler(env, &l2_handler_syslog);
+    l2_env_handler(env, &l2_handler_smtp);
+    l2_env_handler(env, &l2_handler_noop);
+    l2_env_handler(env, &l2_handler_filter);
+    l2_env_handler(env, &l2_handler_prefix);
+    l2_env_handler(env, &l2_handler_buffer);
 
     /* pass new object to caller */
     (*envp) = env;
@@ -108,6 +123,28 @@
 
     return L2_OK;
 }
+
+/* attach handler to environment */
+l2_result_t l2_env_handler(l2_env_t *env, l2_handler_t *h)
+{
+    int i;
+
+    /* argument sanity check */
+    if (env == NULL || h == NULL)
+        return L2_ERR_ARG;
+
+    /* find next free handler position in handler array */
+    for (i = 0; i < L2_MAX_HANDLERS && env->handlers[i] != NULL; i++)
+        ;
+    if (i == L2_MAX_HANDLERS)
+        return L2_ERR_MEM;
+
+    /* attach handler to env */
+    env->handlers[i] = h;
+    env->handlers[i] = h;
+
+    return L2_OK;
+}
 
 /* remember additional error information */
 l2_result_t l2_env_errorinfo(l2_env_t *env, l2_result_t rv, const char *fmt, ...)


ossp-pkg/l2/l2_p.h 1.29 -> 1.30

--- l2_p.h       2001/11/04 13:55:06     1.29
+++ l2_p.h       2001/11/07 11:37:18     1.30
@@ -69,6 +69,7 @@
 /* some hard-coded sizes :-( */
 #define L2_MAX_MSGSIZE    4096
 #define L2_MAX_FORMATTERS  128
+#define L2_MAX_HANDLERS    128
 
 /* internal channel state */
 typedef enum {
@@ -101,6 +102,7 @@
     unsigned int          levelmask;
     unsigned int          flushmask;
     l2_formatter_entry_t  formatters[L2_MAX_FORMATTERS];
+    l2_handler_t         *handlers[L2_MAX_HANDLERS];
     char                  message[L2_MAX_MSGSIZE];
     char                  szError[1024];
     char                  szErrorInfo[512];


ossp-pkg/l2/l2_test.c 1.41 -> 1.42

--- l2_test.c    2001/11/06 15:02:49     1.41
+++ l2_test.c    2001/11/07 11:37:18     1.42
@@ -75,30 +75,30 @@
         die("failed to configure formatter for %%S");
 
     /* create noop channel */
-    if ((l2_channel_create(&ch, env, &l2_handler_noop)) != L2_OK)
+    if ((l2_channel_create(&ch, env, "noop")) != L2_OK)
         die("failed to create noop channel");
 
     /* create prefix channel */
-    if ((l2_channel_create(&chPrefix, env, &l2_handler_prefix)) != L2_OK)
+    if ((l2_channel_create(&chPrefix, env, "prefix")) != L2_OK)
         die("failed to create prefix channel");
     if (l2_channel_configure(chPrefix, "prefix,timezone", 
                              "[%d-%m-%Y/%H:%M:%S] %L test[%P]: ", "local") != L2_OK)
         die("failed to configure prefix channel");
 
     /* create prefix channel */
-    if ((l2_channel_create(&chFilter, env, &l2_handler_filter)) != L2_OK)
+    if ((l2_channel_create(&chFilter, env, "filter")) != L2_OK)
         die("failed to create filter channel");
     if (l2_channel_configure(chFilter, "regex,negate", "hecking", 0) != L2_OK)
         die("failed to configure filter channel");
 
     /* create buffer channel */
-    if ((l2_channel_create(&chBuffer, env, &l2_handler_buffer)) != L2_OK)
+    if ((l2_channel_create(&chBuffer, env, "buffer")) != L2_OK)
         die("failed to create buffer channel");
     if (l2_channel_configure(chBuffer, "size", 800) != L2_OK)
         die("failed to configure buffer channel");
 
     /* create file channel */
-    if ((l2_channel_create(&chFile, env, &l2_handler_file)) != L2_OK)
+    if ((l2_channel_create(&chFile, env, "file")) != L2_OK)
         die("failed to create file channel");
     if (l2_channel_configure(chFile, "path,append,perm", "l2_test.log", TRUE, 0644) != L2_OK)
         die("failed to configure file channel");
@@ -106,7 +106,7 @@
         die("failed to level of smtp channel");
 
     /* create syslog channel */
-    if ((l2_channel_create(&chSyslog, env, &l2_handler_syslog)) != L2_OK)
+    if ((l2_channel_create(&chSyslog, env, "syslog")) != L2_OK)
         die("failed to create syslog channel");
     if (l2_channel_configure(chSyslog, "ident,facility,target,remotehost,logpid",
                              "L2-Test", "user", "remote", "en1", 1) != L2_OK)
@@ -115,7 +115,7 @@
         die("failed to level of syslog channel");
 
     /* create smtp channel */
-    if ((l2_channel_create(&chSmtp, env, &l2_handler_smtp)) != L2_OK)
+    if ((l2_channel_create(&chSmtp, env, "smtp")) != L2_OK)
         die("failed to create smtp channel");
     if (l2_channel_configure(chSmtp, "rcpt,host,port", "rse@engelschall.com", "en1", "25") != L2_OK)
         die("failed to configure smtp channel");

CVSTrac 2.0.1