OSSP CVS Repository

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

Check-in Number: 859
Date: 2001-Sep-05 15:32:04 (local)
2001-Sep-05 13:32:04 (UTC)
User:thl
Branch:
Comment: added to utility functions for transforming levelmask between string and int and vice versa
Tickets:
Inspections:
Files:
ossp-pkg/l2/Makefile.in      1.13 -> 1.14     2 inserted, 1 deleted
ossp-pkg/l2/l2.h      1.17 -> 1.18     6 inserted, 1 deleted
ossp-pkg/l2/l2_ut_level.c      added-> 1.1

ossp-pkg/l2/Makefile.in 1.13 -> 1.14

--- Makefile.in  2001/09/04 14:52:28     1.13
+++ Makefile.in  2001/09/05 13:32:04     1.14
@@ -76,7 +76,8 @@
     l2_ch_buffer.lo \
     l2_ut_format.lo \
     l2_ut_param.lo \
-    l2_ut_pcre.lo
+    l2_ut_pcre.lo \
+    l2_ut_level.lo
 
 #   file containing the official version information
 _VERSION_FILE = \


ossp-pkg/l2/l2.h 1.17 -> 1.18

--- l2.h 2001/09/05 07:41:18     1.17
+++ l2.h 2001/09/05 13:32:04     1.18
@@ -72,6 +72,7 @@
     L2_LEVEL_TRACE    = (1 << 6),
     L2_LEVEL_DEBUG    = (1 << 7)
 } l2_level_t;
+#define L2_LEVEL_CUSTOM(n) (1 << (8+(n))
 
 /* all levels from highest (PANIC) to and including a particular low level */
 #define L2_LEVEL_UPTO(level) \
@@ -163,6 +164,8 @@
 extern l2_handler_t l2_handler_prefix;
 extern l2_handler_t l2_handler_buffer;
 
+/* level operations */
+
 /* channel operations */
 l2_channel_t *l2_channel_create     (l2_handler_t *h);
 l2_result_t   l2_channel_configure  (l2_channel_t *ch, const char *fmt, ...);
@@ -185,7 +188,9 @@
 l2_result_t   l2_stream_destroy    (l2_stream_t *st);
 
 /* utility operations */
-l2_result_t   l2_util_setparams(l2_param_t p[], const char *fmt, va_list ap);
+l2_result_t   l2_util_setparams    (l2_param_t p[], const char *fmt, va_list ap);
+l2_result_t   l2_util_l2s          (char *string,       size_t maxlen, int sep, unsigned int  levelmask);
+l2_result_t   l2_util_s2l          (const char *string, size_t maxlen, int sep, unsigned int *levelmask);
 
 #endif /* __L2_H__ */
 


ossp-pkg/l2/l2_ut_level.c -> 1.1

*** /dev/null    Thu Oct 21 07:55:00 2021
--- -    Thu Oct 21 07:56:40 2021
***************
*** 0 ****
--- 1,139 ----
+ /*
+ **  L2 - OSSP Logging Library
+ **  Copyright (c) 2001 The OSSP Project (http://www.ossp.org/)
+ **  Copyright (c) 2001 Cable & Wireless Deutschland (http://www.cw.com/de/)
+ **
+ **  This file is part of OSSP L2, a flexible logging library which
+ **  can be found at http://www.ossp.org/pkg/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_ut_level.c: level mask transformations
+ */
+ 
+ #include "l2.h"
+ #include "l2_p.h"
+ 
+ #include <string.h>
+ #include <ctype.h>
+ 
+ static struct {
+     l2_level_t level;
+     char *string;
+ } l2s_table[] = {
+     { L2_LEVEL_PANIC,    "panic"    },
+     { L2_LEVEL_CRITICAL, "critical" },
+     { L2_LEVEL_ERROR,    "error"    },
+     { L2_LEVEL_WARNING,  "warning"  },
+     { L2_LEVEL_NOTICE,   "notice"   },
+     { L2_LEVEL_INFO,     "info"     },
+     { L2_LEVEL_TRACE,    "trace"    },
+     { L2_LEVEL_DEBUG,    "debug"    },
+     { 0,                 NULL       }
+ };
+ 
+ l2_result_t l2_util_l2s(char *string, size_t maxlen, int sep, unsigned int levelmask)
+ {
+     char hexbuf[2+(sizeof(unsigned int)*2)+1];
+     int len;
+     int i;
+     int l;
+ 
+     len = maxlen;
+     string[0] = '\0';
+     for (i = 0; l2s_table[i].level != NULL; i++) {
+         if (levelmask & l2s_table[i].level) {
+             levelmask &= ~(l2s_table[i].level);
+             l = strlen(l2s_table[i].string) + 1;
+             if (len < l)
+                 return L2_ERROR;
+             sprintf(string+(maxlen-len), "%s%c", l2s_table[i].string, sep);
+             len -= l;
+         }
+     }
+     if (levelmask != 0) {
+         sprintf(hexbuf, "0x%x", levelmask);
+         l = strlen(hexbuf) + 1;
+         if (len < l)
+             return L2_ERROR;
+         sprintf(string+(maxlen-len), "%s%c", hexbuf, sep);
+         len -= l;
+     }
+     /* remove trailing comma */
+     if ((maxlen-len) > 0)
+         string[(maxlen-len)-1] = '\0'; 
+ 
+     return L2_OK;
+ }
+ 
+ static unsigned int hexval(const char *cpB, const char *cpE)
+ {
+     unsigned int hv;
+     unsigned int nibble;
+ 
+     hv = 0;
+     while (cpB < cpE) {
+         nibble = tolower((unsigned int)(*cpB++));
+         if (isdigit(nibble)) 
+             nibble = nibble - '0';
+         else
+             nibble = nibble - 'a';
+         hv = ((hv << 4) | nibble);
+     }
+     return hv;
+ }
+ 
+ l2_result_t l2_util_s2l(const char *string, size_t maxlen, int sep, unsigned int *levelmask)
+ {
+     const char *cpB;
+     const char *cpE;
+     int bFound;
+     int i;
+ 
+     *levelmask = 0;
+     cpE = string;
+     while (1) {
+         cpB = cpE;
+         if (cpB >= (string+maxlen))
+             break;
+         if ((int)(*cpB) == sep)
+             cpB++;
+         for (cpE = cpB; cpE < (string+maxlen) && (int)(*cpE) != sep; cpE++)
+             ;
+         if (cpE > (string+maxlen))
+             break;
+         bFound = 0;
+         for (i = 0; l2s_table[i].level != NULL; i++) {
+             if (strncasecmp(cpB, l2s_table[i].string, cpE-cpB) == 0) {
+                 *levelmask |= l2s_table[i].level;
+                 bFound = 1;
+                 break;
+             }
+         }
+         if (!bFound) {
+             if ((cpE > cpB+2) && strncasecmp(cpB, "0x", 2) == 0 && ishexnumber((int)(*(cpB+2)))) {
+                 *levelmask |= hexval(cpB+2, cpE);
+             }
+             else
+                 return L2_ERROR;
+         }
+     }
+     return L2_OK;
+ }
+ 

CVSTrac 2.0.1