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1_6:1.13 FSL_0_1_5:1.13 FSL_0_1_1:1.13 LMTP2NNTP_1_2a5:1.13 LMTP2NNTP_1_2a4:1.13 LMTP2NNTP_1_2a3:1.13 LMTP2NNTP_1_2a1:1.12 LMTP2NNTP_1_1_1:1.10 LMTP2NNTP_1_1_0:1.10 LMTP2NNTP_1_1b4:1.10 LMTP2NNTP_1_1b3:1.10 L2_CHANNEL_ONLY_REVAMPING_BEFORE:1.10 LMTP2NNTP_1_1b2:1.10 LMTP2NNTP_1_1b1:1.10 L2_0_1_0:1.10 START_MICHAEL:1.4 L2_INITIAL:1.1.1.1 OSSP:1.1.1; locks; strict; comment @ * @; 1.19 date 2005.10.03.08.08.11; author rse; state Exp; branches; next 1.18; 1.18 date 2005.01.24.15.03.17; author rse; state Exp; branches; next 1.17; 1.17 date 2003.06.30.12.38.17; author thl; state Exp; branches; next 1.16; 1.16 date 2003.01.06.11.41.51; author rse; state Exp; branches; next 1.15; 1.15 date 2002.07.31.07.39.21; author thl; state Exp; branches; next 1.14; 1.14 date 2002.07.30.19.08.24; author rse; state Exp; branches; next 1.13; 1.13 date 2002.01.02.17.07.38; author rse; state Exp; branches; next 1.12; 1.12 date 2001.11.07.13.05.20; author rse; state Exp; branches; next 1.11; 1.11 date 2001.11.07.11.37.18; author rse; state Exp; branches; next 1.10; 1.10 date 2001.09.12.09.35.57; author ms; state Exp; branches; next 1.9; 1.9 date 2001.09.08.11.07.51; author rse; state Exp; branches; next 1.8; 1.8 date 2001.09.06.19.27.02; author ms; state Exp; branches; next 1.7; 1.7 date 2001.09.05.07.47.12; author rse; state Exp; branches; next 1.6; 1.6 date 2001.09.04.19.18.49; author rse; state Exp; branches; next 1.5; 1.5 date 2001.09.04.15.41.17; author rse; state Exp; branches; next 1.4; 1.4 date 2001.08.15.10.36.03; author rse; state Exp; branches; next 1.3; 1.3 date 2001.05.26.08.02.55; author rse; state Exp; branches; next 1.2; 1.2 date 2001.05.11.17.07.52; author rse; state Exp; branches; next 1.1; 1.1 date 2001.05.10.19.46.01; author rse; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 2001.05.10.19.46.01; author rse; state Exp; branches; next ; desc @@ 1.19 log @Adjust copyright messages for new year 2005. @ text @/* ** OSSP l2 - Flexible Logging ** Copyright (c) 2001-2005 Cable & Wireless ** Copyright (c) 2001-2005 The OSSP Project ** Copyright (c) 2001-2005 Ralf S. Engelschall ** ** This file is part of OSSP l2, a flexible logging library which ** can be found at http://www.ossp.org/pkg/lib/l2/. ** ** Permission to use, copy, modify, and distribute this software for ** any purpose with or without fee is hereby granted, provided that ** the above copyright notice and this permission notice appear in all ** copies. ** ** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED ** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF ** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ** SUCH DAMAGE. ** ** l2_ch_fd.c: file descriptor channel implementation */ #include "l2.h" #include /* declare private channel configuration */ typedef struct { int fd; } l2_ch_fd_t; /* create channel */ static l2_result_t hook_create(l2_context_t *ctx, l2_channel_t *ch) { l2_ch_fd_t *cfg; /* allocate private channel configuration */ if ((cfg = (l2_ch_fd_t *)malloc(sizeof(l2_ch_fd_t))) == NULL) return L2_ERR_MEM; /* initialize configuration with reasonable defaults */ cfg->fd = -1; /* link private channel configuration into channel context */ ctx->vp = cfg; return L2_OK; } /* configure channel */ static l2_result_t hook_configure(l2_context_t *ctx, l2_channel_t *ch, const char *fmt, va_list ap) { l2_ch_fd_t *cfg; l2_param_t pa[2]; l2_result_t rv; l2_env_t *env; /* parameter checks */ if ((cfg = (l2_ch_fd_t *)ctx->vp) == NULL) return L2_ERR_ARG; /* feed and call generic parameter parsing engine */ L2_PARAM_SET(pa[0], fd, INT, &cfg->fd); L2_PARAM_END(pa[1]); l2_channel_env(ch, &env); rv = l2_util_setparams(env, pa, fmt, ap); return rv; } /* open channel */ static l2_result_t hook_open(l2_context_t *ctx, l2_channel_t *ch) { l2_ch_fd_t *cfg; /* parameter checks */ if ((cfg = (l2_ch_fd_t *)ctx->vp) == NULL) return L2_ERR_ARG; if ((cfg->fd == -1)) return L2_ERR_ARG; return L2_OK; } /* write to channel */ static l2_result_t hook_write(l2_context_t *ctx, l2_channel_t *ch, l2_level_t level, const char *buf, size_t buf_size) { l2_ch_fd_t *cfg; /* parameter checks */ if ((cfg = (l2_ch_fd_t *)ctx->vp) == NULL) return L2_ERR_ARG; if (cfg->fd == -1) return L2_ERR_ARG; /* write message to channel fd */ if (write(cfg->fd, buf, buf_size) == -1) return L2_ERR_SYS; return L2_OK; } /* flush channel */ static l2_result_t hook_flush(l2_context_t *ctx, l2_channel_t *ch) { /* NOP for this channel, because Unix I/O files are unbuffered! */ return L2_OK; } /* close channel */ static l2_result_t hook_close(l2_context_t *ctx, l2_channel_t *ch) { l2_ch_fd_t *cfg; /* parameter checks */ if ((cfg = (l2_ch_fd_t *)ctx->vp) == NULL) return L2_ERR_ARG; if (cfg->fd == -1) return L2_ERR_ARG; /* close channel fd */ /* nothing to close */ return L2_OK; } /* 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; /* destroy channel configuration */ free(ctx->vp); return L2_OK; } /* exported channel handler structure */ l2_handler_t l2_handler_fd = { "fd", L2_CHANNEL_OUTPUT, hook_create, hook_configure, hook_open, hook_write, hook_flush, hook_close, hook_destroy }; @ 1.18 log @Adjust copyright messages for new year 2005. @ text @d3 3 a5 3 ** Copyright (c) 2001-2004 Cable & Wireless ** Copyright (c) 2001-2004 The OSSP Project ** Copyright (c) 2001-2004 Ralf S. Engelschall @ 1.17 log @fix array too small by one element bug @ text @d3 3 a5 3 ** Copyright (c) 2001-2003 Cable & Wireless Deutschland GmbH ** Copyright (c) 2001-2003 The OSSP Project (http://www.ossp.org/) ** Copyright (c) 2001-2003 Ralf S. Engelschall @ 1.16 log @- remove trailing whitespaces - adjust copyright messages - consistently use "OSSP l2" - consistently talk about "Flexible Logging" - use standard OSSP ASCII-art @ text @d61 1 a61 1 l2_param_t pa[1]; @ 1.15 log @renamed L2 fd() channel argument "filedescriptor" to "fd" @ text @d2 4 a5 3 ** OSSP l2 - Logging Library ** Copyright (c) 2001-2002 The OSSP Project (http://www.ossp.org/) ** Copyright (c) 2001-2002 Cable & Wireless Deutschland (http://www.cw.com/de/) d7 1 a7 1 ** This file is part of OSSP L2, a flexible logging library which d49 1 a49 1 cfg->fd = -1; d61 1 a61 1 l2_param_t pa[1]; d140 1 a140 1 if (ctx->vp == NULL) @ 1.14 log @polish for release @ text @d69 1 a69 1 L2_PARAM_SET(pa[0], filedescriptor, INT, &cfg->fd); @ 1.13 log @bump copyright year @ text @d2 1 a2 1 ** L2 - OSSP Logging Library d7 1 a7 1 ** can be found at http://www.ossp.org/pkg/l2/. @ 1.12 log @Hell, I've seldom seen that it is needed to prepare and adjust such a lot of subtle details of existing code in order to make a new feature implementable in a straight-forward way. Anyway, here comes one more preparation change for the forthcoming channel tree specification parser: - change l2_util_setparam() to take an l2_env_t parameter which allows the function to report better error messages. - completely rewrite l2_util_setparam() to support calls l2_channel_configure(ch, "n1=v1,n2=v2,n3=v3") and/or l2_channel_configure(ch, "n1=%x,n2=%x,n3=%x", v1, v2, v3) instead of l2_channel_configure(ch, "n1,n2,n3", v1, v2, v3) This is both a step forward to make the interface of l2_channel_configure() more flexible (because one now can directly inline values instead of having them to be passed explicitly) and allows the spec parser not having to know the type (integer, floating point or string) of a parameter (which is important if one wants the parser to be independent of the implementing channel handlers). @ text @d3 2 a4 2 ** Copyright (c) 2001 The OSSP Project (http://www.ossp.org/) ** Copyright (c) 2001 Cable & Wireless Deutschland (http://www.cw.com/de/) @ 1.11 log @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. @ text @d62 1 d71 2 a72 1 rv = l2_util_setparams(pa, fmt, ap); @ 1.10 log @Bug fixes and upgraded file descriptor handler to new L2_LEVEL pass-through design. @ text @d148 1 @ 1.9 log @remove ununsed variable @ text @d36 1 a36 1 } l2_ch_file_t; d41 1 a41 1 l2_ch_file_t *cfg; d44 1 a44 1 if ((cfg = (l2_ch_file_t *)malloc(sizeof(l2_ch_file_t))) == NULL) d59 1 a59 1 l2_ch_file_t *cfg; d64 1 a64 1 if ((cfg = (l2_ch_file_t *)ctx->vp) == NULL) d78 1 a78 1 l2_ch_file_t *cfg; d81 1 a81 1 if ((cfg = (l2_ch_file_t *)ctx->vp) == NULL) d90 2 a91 2 static l2_result_t hook_write(l2_context_t *ctx, l2_channel_t *ch, const char *buf, size_t buf_size) d93 1 a93 1 l2_ch_file_t *cfg; d96 1 a96 1 if ((cfg = (l2_ch_file_t *)ctx->vp) == NULL) d101 1 a101 1 /* write message to channel file */ d119 1 a119 1 l2_ch_file_t *cfg; d122 1 a122 1 if ((cfg = (l2_ch_file_t *)ctx->vp) == NULL) d127 1 a127 1 /* close channel file */ @ 1.8 log @Added the file descriptor implementation, just a copy of the file channel with some stuff left out. @ text @a78 1 int mode; @ 1.7 log @Be politically correct: channels are intended to be implemented also by users, which have only access to the public API (l2.h), so do not even try to use anything more in our own shipped channels. @ text @d27 1 a27 1 ** l2_ch_syslog.c: filedescriptor channel implementation d31 1 d33 6 d41 12 d56 1 d59 14 a72 1 return L2_OK; d75 1 d78 9 d90 1 d94 12 d109 1 d112 2 d117 1 d120 11 d134 1 d137 7 d147 1 @ 1.6 log @Be pedantically correct: handler hooks return "l2_result_t" and not "int", although currently it is just an int/enum. @ text @a30 1 #include "l2_p.h" @ 1.5 log @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. @ text @d33 1 a33 1 static int hook_create(l2_context_t *ctx, l2_channel_t *ch) d38 1 a38 1 static int hook_configure(l2_context_t *ctx, l2_channel_t *ch, const char *fmt, va_list ap) d43 1 a43 1 static int hook_open(l2_context_t *ctx, l2_channel_t *ch) d48 1 a48 1 static int hook_write(l2_context_t *ctx, l2_channel_t *ch, d54 1 a54 1 static int hook_flush(l2_context_t *ctx, l2_channel_t *ch) d59 1 a59 1 static int hook_close(l2_context_t *ctx, l2_channel_t *ch) d64 1 a64 1 static int hook_destroy(l2_context_t *ctx, l2_channel_t *ch) @ 1.4 log @Fix more ossp.com references by replacing with the correct domain name ossp.org. @ text @d33 1 a33 1 static int hook_create(l2_context_t *ctx) d38 1 a38 1 static int hook_configure(l2_context_t *ctx, const char *fmt, va_list ap) d43 1 a43 1 static int hook_open(l2_context_t *ctx, l2_channel_t *downstream) d48 1 a48 1 static int hook_write(l2_context_t *ctx, l2_channel_t *downstream, d54 1 a54 1 static int hook_flush(l2_context_t *ctx, l2_channel_t *downstream) d59 1 a59 1 static int hook_close(l2_context_t *ctx, l2_channel_t *downstream) d64 1 a64 1 static int hook_destroy(l2_context_t *ctx) d70 1 @ 1.3 log @change terminology: below -> downstream @ text @d7 1 a7 1 ** can be found at http://www.ossp.com/pkg/l2/. @ 1.2 log @Fill in channel handler template code. @ text @d43 1 a43 1 static int hook_open(l2_context_t *ctx, l2_channel_t *below) d48 1 a48 1 static int hook_write(l2_context_t *ctx, l2_channel_t *below, d54 1 a54 1 static int hook_flush(l2_context_t *ctx, l2_channel_t *below) d59 1 a59 1 static int hook_close(l2_context_t *ctx, l2_channel_t *below) @ 1.1 log @Initial revision @ text @d33 46 @ 1.1.1.1 log @L2 initial source tree @ text @@