OSSP CVS Repository

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

Check-in Number: 485
Date: 2001-May-22 20:47:31 (local)
2001-May-22 18:47:31 (UTC)
User:rse
Branch:
Comment: Simplify things by merging the parameter stuff into l2_channel.c and the l2_stream_t related things into l2_stream.c
Tickets:
Inspections:
Files:
ossp-pkg/l2/Makefile.in      1.6 -> 1.7     0 inserted, 2 deleted
ossp-pkg/l2/l2.h      1.3 -> 1.4     2 inserted, 2 deleted
ossp-pkg/l2/l2_ch_file.c      1.4 -> 1.5     1 inserted, 1 deleted
ossp-pkg/l2/l2_channel.c      1.1 -> 1.2     68 inserted, 0 deleted
ossp-pkg/l2/l2_log.c      1.1->removed
ossp-pkg/l2/l2_param.c      1.1->removed
ossp-pkg/l2/l2_stream.c      1.2 -> 1.3     54 inserted, 19 deleted

ossp-pkg/l2/Makefile.in 1.6 -> 1.7

--- Makefile.in  2001/05/19 20:08:30     1.6
+++ Makefile.in  2001/05/22 18:47:31     1.7
@@ -63,10 +63,8 @@
 
 #   list of library object files
 OBJS = \
-    l2_log.lo \
     l2_stream.lo \
     l2_channel.lo \
-    l2_param.lo \
     l2_ch_fd.lo \
     l2_ch_file.lo \
     l2_ch_pipe.lo \


ossp-pkg/l2/l2.h 1.3 -> 1.4

--- l2.h 2001/05/19 20:08:30     1.3
+++ l2.h 2001/05/22 18:47:31     1.4
@@ -151,17 +151,17 @@
 extern l2_handler_t l2_handler_buffer;
 
 /* parameter operations */
-int           l2_param_parse      (l2_param_t p[], const char *fmt, va_list ap);
 
 /* channel operations */
 l2_channel_t *l2_channel_create   (l2_handler_t *h);
-l2_channel_t *l2_channel_stack    (l2_channel_t *ch1, l2_channel_t *ch2);
 int           l2_channel_configure(l2_channel_t *ch, const char *fmt, ...);
 int           l2_channel_open     (l2_channel_t *ch);
 int           l2_channel_write    (l2_channel_t *ch, const char *buf, size_t bufsize);
 int           l2_channel_flush    (l2_channel_t *ch);
 int           l2_channel_close    (l2_channel_t *ch);
 int           l2_channel_destroy  (l2_channel_t *ch);
+l2_channel_t *l2_channel_stack    (l2_channel_t *ch1, l2_channel_t *ch2);
+int           l2_channel_setparams(l2_param_t p[], const char *fmt, va_list ap);
 
 /* stream operations */
 l2_stream_t  *l2_stream_create    (void);


ossp-pkg/l2/l2_ch_file.c 1.4 -> 1.5

--- l2_ch_file.c 2001/05/21 20:15:11     1.4
+++ l2_ch_file.c 2001/05/22 18:47:31     1.5
@@ -79,7 +79,7 @@
     L2_PARAM_SET(pa[1], append, INT,     &cfg->append);
     L2_PARAM_SET(pa[1], perm,   LONG,    &cfg->perm);
     L2_PARAM_END(pa[2]);
-    rv = l2_param_parse(pa, fmt, ap);
+    rv = l2_channel_setparams(pa, fmt, ap);
 
     return rv;
 }


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

--- l2_channel.c 2001/05/10 19:46:01     1.1
+++ l2_channel.c 2001/05/22 18:47:31     1.2
@@ -134,3 +134,71 @@
     return rv;
 }
 
+int l2_channel_setparams(l2_param_t pa[], const char *fmt, va_list ap)
+{
+    const char *cpB, *cpE;
+    const char *cpC, *cpG;
+    int ok;
+    int i; 
+
+    cpE = fmt;
+    while (*cpE != '\0') {
+        /* determine begin of parameter name */
+        cpB = cpE;
+        while (*cpB == ',')
+            cpB++;
+
+        /* determine end of parameter name */
+        cpE = cpB;
+        while (*cpE != ',' && *cpE != '\0')
+            cpE++;
+
+        /* try to match with configured parameters */
+        ok = FALSE;
+        for (i = 0; pa[i].name != NULL; i++) {
+            cpC = pa[i].name;
+            cpG = cpB;
+            while (*cpC != '\0' && cpG < cpE) {
+                if (*cpC != *cpG)
+                    break;
+                cpC++;
+                cpG++;
+            }
+            if (*cpC == '\0' && cpG == cpE) {
+                /* parameter matched, so store value */
+                switch (pa[i].type) {
+                    case L2_TYPE_CHAR:
+                        *(char *)(pa[i].store) = va_get(ap, char); 
+                        break;
+                    case L2_TYPE_SHORT:
+                        *(short *)(pa[i].store) = va_get(ap, short); 
+                        break;
+                    case L2_TYPE_INT:
+                        *(int *)(pa[i].store) = va_get(ap, int); 
+                        break;
+                    case L2_TYPE_LONG:
+                        *(long *)(pa[i].store) = va_get(ap, long); 
+                        break;
+                    case L2_TYPE_FLOAT:
+                        *(float *)(pa[i].store) = va_get(ap, float); 
+                        break;
+                    case L2_TYPE_DOUBLE:
+                        *(double *)(pa[i].store) = va_get(ap, double); 
+                        break;
+                    case L2_TYPE_CHARPTR:
+                        *(char **)(pa[i].store) = va_get(ap, charptr); 
+                        break;
+                    case L2_TYPE_VOIDPTR:
+                        *(void **)(pa[i].store) = va_get(ap, voidptr); 
+                        break;
+                }
+                ok = TRUE;
+                break;
+            }
+        }
+        if (!ok)
+            return L2_ERROR;
+    }
+    return L2_OK;
+}
+


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



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



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

--- 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;
+}
+

CVSTrac 2.0.1