--- l2_stream.c 2001/05/17 14:43:26 1.2
+++ l2_stream.c 2001/05/22 18:47:31 1.3
@@ -31,32 +31,67 @@
#include "l2.h"
#include "l2_p.h"
-l2_stream_t* l2_stream_create(void)
- {
+l2_stream_t *l2_stream_create(void)
+{
l2_stream_t *st;
- st = (l2_stream_t *)malloc(sizeof(l2_stream_t));
- if (!st)
+
+ if ((st = (l2_stream_t *)malloc(sizeof(l2_stream_t))) == NULL)
return NULL;
memset(st, 0, sizeof(l2_stream_t));
return st;
- }
+}
-void l2_stream_destroy(l2_stream_t* st)
- {
+l2_stream_t *l2_stream_channel(l2_stream_t *st, l2_channel_t *ch, unsigned int levelmask)
+{
size_t i;
- for (i = 0; i <= L2_MAX_CHANNELS && st->channels[i]; ++i)
- l2_channel_destroy(st->channels[i]);
- for (i = 0; i <= L2_MAX_FORMATTERS && st->formatters[i]; ++i)
- free(st->formatters[i]);
- }
-l2_stream_t* l2_stream_channel(l2_stream_t *st, l2_channel_t *ch, unsigned int levelmask)
- {
- size_t i;
- for (i = 0; i <= L2_MAX_CHANNELS && st->channels[i]; ++i)
- ;
+ for (i = 0; i <= L2_MAX_CHANNELS && st->channels[i] != NULL; i++)
+ ;
if (i == L2_MAX_CHANNELS)
- return 0; /* Array is full. */
+ return NULL;
st->channels[i] = ch;
return st;
- }
+}
+
+l2_stream_t *l2_stream_formatter(l2_stream_t *st, l2_formatter_t *cb, l2_context_t *ctx)
+{
+ return NULL;
+}
+
+unsigned int l2_stream_levels(l2_stream_t *st, unsigned int levelmask)
+{
+ return 0;
+}
+
+void l2_stream_log(l2_stream_t *st, unsigned int log_level, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ l2_stream_vlog(st, log_level, fmt, ap);
+ va_end(ap);
+ return;
+}
+
+void l2_stream_vlog(l2_stream_t *st, unsigned int log_level, const char *fmt, va_list ap)
+{
+ size_t i, len;
+
+ len = vsnprintf(st->message, L2_MAX_MSGSIZE, fmt, ap);
+ for (i = 0; i <= L2_MAX_CHANNELS && st->channels[i] != NULL; i++)
+ st->channels[i]->handler.write(&st->channels[i]->context,
+ st->channels[i]->below,
+ st->message, len);
+ return;
+}
+
+void l2_stream_destroy(l2_stream_t *st)
+{
+ size_t i;
+
+ for (i = 0; i <= L2_MAX_CHANNELS && st->channels[i] != NULL; i++)
+ l2_channel_destroy(st->channels[i]);
+ for (i = 0; i <= L2_MAX_FORMATTERS && st->formatters[i] != NULL; i++)
+ free(st->formatters[i]);
+ return;
+}
+
|