OSSP CVS Repository

ossp - Difference in ossp-pkg/l2/l2_stream.c versions 1.5 and 1.6
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/l2/l2_stream.c 1.5 -> 1.6

--- l2_stream.c  2001/08/15 10:36:03     1.5
+++ l2_stream.c  2001/09/03 12:16:44     1.6
@@ -34,64 +34,103 @@
 l2_stream_t *l2_stream_create(void)
 {
     l2_stream_t *st;
+    int i;
     
     if ((st = (l2_stream_t *)malloc(sizeof(l2_stream_t))) == NULL)
         return NULL;
-    memset(st, 0, sizeof(l2_stream_t));
+    st->levelmask = 0;
+    for (i = 0; i < L2_MAX_CHANNELS; i++)
+        st->channels[i] = NULL;
+    for (i = 0; i < L2_MAX_FORMATTERS; i++)
+        st->formatters[i].name = NULL;
     return st;
 }
 
-l2_stream_t *l2_stream_channel(l2_stream_t *st, l2_channel_t *ch, unsigned int levelmask)
+l2_result_t l2_stream_channel(l2_stream_t *st, l2_channel_t *ch, unsigned int levelmask)
 {
-    size_t i;
+    int i;
 
-    for (i = 0; i <= L2_MAX_CHANNELS && st->channels[i] != NULL; i++)
+    if (st == NULL || ch == NULL)
+        return L2_ERROR;
+    for (i = 0; i < L2_MAX_CHANNELS && st->channels[i] != NULL; i++)
         ;
     if (i == L2_MAX_CHANNELS)
-        return NULL;
+        return L2_ERROR;
     st->channels[i] = ch;
-    return st;
+    return L2_OK;
 }
 
-l2_stream_t *l2_stream_formatter(l2_stream_t *st, l2_formatter_t *cb, l2_context_t *ctx)
+l2_result_t l2_stream_formatter(l2_stream_t *st, const char *name, l2_formatter_t cb, l2_context_t *ctx)
 {
-    return NULL;
+    int i;
+
+    if (st == NULL || name == NULL || cb != NULL)
+        return L2_ERROR;
+    for (i = 0; i < L2_MAX_FORMATTERS && st->formatters[i].name != NULL; i++)
+        ;
+    if (i == L2_MAX_FORMATTERS)
+        return L2_ERROR;
+    st->formatters[i].name = strdup(name);
+    st->formatters[i].context = ctx;
+    st->formatters[i].callback = cb;
+    return L2_OK;
 }
 
-unsigned int l2_stream_levels(l2_stream_t *st, unsigned int levelmask)
+l2_result_t l2_stream_levels(l2_stream_t *st, unsigned int levelmask, unsigned int *levelmaskold)
 {
-    return 0;
+    if (st == NULL)
+        return L2_ERROR;
+    if (levelmaskold != NULL)
+        *levelmaskold = st->levelmask;
+    st->levelmask = levelmask;
+    return L2_OK;
 }
 
-void l2_stream_log(l2_stream_t *st, unsigned int log_level, const char *fmt, ...)
+l2_result_t l2_stream_log(l2_stream_t *st, unsigned int log_level, const char *fmt, ...)
 {
     va_list ap;
+    l2_result_t rv;
+
+    if (st == NULL || log_level == 0 || fmt == NULL)
+        return L2_ERROR;
     va_start(ap, fmt);
-    l2_stream_vlog(st, log_level, fmt, ap);
+    rv = l2_stream_vlog(st, log_level, fmt, ap);
     va_end(ap);
-    return;
+    return rv;
 }
 
-void l2_stream_vlog(l2_stream_t *st, unsigned int log_level, const char *fmt, va_list ap)
+l2_result_t l2_stream_vlog(l2_stream_t *st, unsigned int log_level, const char *fmt, va_list ap)
 {
-    size_t i, len;
+    int i;
+    size_t len;
+    l2_result_t rv;
 
-    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]->downstream,
-                                       st->message, len);
-    return;
-}
+    if (st == NULL || log_level == 0 || fmt == NULL || ap == NULL)
+        return L2_ERROR;
 
-void l2_stream_destroy(l2_stream_t *st)
-{
-    size_t i;
+    /* XXX use st->formatter!! XXX */
+    len = vsnprintf(st->message, L2_MAX_MSGSIZE, fmt, ap);
 
-    for (i = 0; i <= L2_MAX_CHANNELS && st->channels[i] != NULL; i++)
+    rv = L2_OK;
+    for (i = 0; i < L2_MAX_CHANNELS && st->channels[i] != NULL; i++) {
+        /* XXX write only if st->levelmask contains log_level */
+        if ((rv = l2_channel_write(st->channels[i], st->message, len)) != L2_OK)
+            break;
+    }
+    return rv;
+}
+
+l2_result_t l2_stream_destroy(l2_stream_t *st)
+{
+    int i;
+
+    if (st == NULL)
+        return L2_ERROR;
+    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;
+    for (i = 0; i < L2_MAX_FORMATTERS && st->formatters[i].name != NULL; i++)
+        free(st->formatters[i].name);
+    free(st);
+    return L2_OK;
 }
 

CVSTrac 2.0.1