Index: ossp-pkg/l2/l2.h.in RCS File: /v/ossp/cvs/ossp-pkg/l2/l2.h.in,v rcsdiff -q -kk '-r1.18' '-r1.19' -u '/v/ossp/cvs/ossp-pkg/l2/l2.h.in,v' 2>/dev/null --- 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, ...); Index: ossp-pkg/l2/l2_ch_buffer.c RCS File: /v/ossp/cvs/ossp-pkg/l2/l2_ch_buffer.c,v rcsdiff -q -kk '-r1.32' '-r1.33' -u '/v/ossp/cvs/ossp-pkg/l2/l2_ch_buffer.c,v' 2>/dev/null --- 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, Index: ossp-pkg/l2/l2_ch_fd.c RCS File: /v/ossp/cvs/ossp-pkg/l2/l2_ch_fd.c,v rcsdiff -q -kk '-r1.10' '-r1.11' -u '/v/ossp/cvs/ossp-pkg/l2/l2_ch_fd.c,v' 2>/dev/null --- 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, Index: ossp-pkg/l2/l2_ch_file.c RCS File: /v/ossp/cvs/ossp-pkg/l2/l2_ch_file.c,v rcsdiff -q -kk '-r1.17' '-r1.18' -u '/v/ossp/cvs/ossp-pkg/l2/l2_ch_file.c,v' 2>/dev/null --- 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, Index: ossp-pkg/l2/l2_ch_filter.c RCS File: /v/ossp/cvs/ossp-pkg/l2/l2_ch_filter.c,v rcsdiff -q -kk '-r1.12' '-r1.13' -u '/v/ossp/cvs/ossp-pkg/l2/l2_ch_filter.c,v' 2>/dev/null --- 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, Index: ossp-pkg/l2/l2_ch_irc.c RCS File: /v/ossp/cvs/ossp-pkg/l2/l2_ch_irc.c,v rcsdiff -q -kk '-r1.2' '-r1.3' -u '/v/ossp/cvs/ossp-pkg/l2/l2_ch_irc.c,v' 2>/dev/null --- 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, Index: ossp-pkg/l2/l2_ch_noop.c RCS File: /v/ossp/cvs/ossp-pkg/l2/l2_ch_noop.c,v rcsdiff -q -kk '-r1.1' '-r1.2' -u '/v/ossp/cvs/ossp-pkg/l2/l2_ch_noop.c,v' 2>/dev/null --- 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, Index: ossp-pkg/l2/l2_ch_null.c RCS File: /v/ossp/cvs/ossp-pkg/l2/l2_ch_null.c,v rcsdiff -q -kk '-r1.9' '-r1.10' -u '/v/ossp/cvs/ossp-pkg/l2/l2_ch_null.c,v' 2>/dev/null --- 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, Index: ossp-pkg/l2/l2_ch_pipe.c RCS File: /v/ossp/cvs/ossp-pkg/l2/l2_ch_pipe.c,v rcsdiff -q -kk '-r1.26' '-r1.27' -u '/v/ossp/cvs/ossp-pkg/l2/l2_ch_pipe.c,v' 2>/dev/null --- 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, Index: ossp-pkg/l2/l2_ch_prefix.c RCS File: /v/ossp/cvs/ossp-pkg/l2/l2_ch_prefix.c,v rcsdiff -q -kk '-r1.16' '-r1.17' -u '/v/ossp/cvs/ossp-pkg/l2/l2_ch_prefix.c,v' 2>/dev/null --- 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, Index: ossp-pkg/l2/l2_ch_smtp.c RCS File: /v/ossp/cvs/ossp-pkg/l2/l2_ch_smtp.c,v rcsdiff -q -kk '-r1.6' '-r1.7' -u '/v/ossp/cvs/ossp-pkg/l2/l2_ch_smtp.c,v' 2>/dev/null --- 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, Index: ossp-pkg/l2/l2_ch_socket.c RCS File: /v/ossp/cvs/ossp-pkg/l2/l2_ch_socket.c,v rcsdiff -q -kk '-r1.32' '-r1.33' -u '/v/ossp/cvs/ossp-pkg/l2/l2_ch_socket.c,v' 2>/dev/null --- 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, Index: ossp-pkg/l2/l2_ch_syslog.c RCS File: /v/ossp/cvs/ossp-pkg/l2/l2_ch_syslog.c,v rcsdiff -q -kk '-r1.25' '-r1.26' -u '/v/ossp/cvs/ossp-pkg/l2/l2_ch_syslog.c,v' 2>/dev/null --- 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, Index: ossp-pkg/l2/l2_channel.c RCS File: /v/ossp/cvs/ossp-pkg/l2/l2_channel.c,v rcsdiff -q -kk '-r1.24' '-r1.25' -u '/v/ossp/cvs/ossp-pkg/l2/l2_channel.c,v' 2>/dev/null --- 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; Index: ossp-pkg/l2/l2_env.c RCS File: /v/ossp/cvs/ossp-pkg/l2/l2_env.c,v rcsdiff -q -kk '-r1.2' '-r1.3' -u '/v/ossp/cvs/ossp-pkg/l2/l2_env.c,v' 2>/dev/null --- 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, ...) Index: ossp-pkg/l2/l2_p.h RCS File: /v/ossp/cvs/ossp-pkg/l2/l2_p.h,v rcsdiff -q -kk '-r1.29' '-r1.30' -u '/v/ossp/cvs/ossp-pkg/l2/l2_p.h,v' 2>/dev/null --- 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]; Index: ossp-pkg/l2/l2_test.c RCS File: /v/ossp/cvs/ossp-pkg/l2/l2_test.c,v rcsdiff -q -kk '-r1.41' '-r1.42' -u '/v/ossp/cvs/ossp-pkg/l2/l2_test.c,v' 2>/dev/null --- 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");