OSSP CVS Repository

ossp - Difference in ossp-pkg/fsl/fsl.c versions 1.13 and 1.14
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/fsl/fsl.c 1.13 -> 1.14

--- fsl.c        2002/07/18 15:18:30     1.13
+++ fsl.c        2002/07/18 15:53:36     1.14
@@ -122,21 +122,36 @@
 };
 
 static struct {
-    int         level;
     char       *string;
+    int         level;
     l2_level_t  deflevelmap;
 } sysloglevel2string[] = {
-    { LOG_EMERG,   "emerg",   L2_LEVEL_PANIC    },
-    { LOG_ALERT,   "alert",   L2_LEVEL_PANIC    },
-    { LOG_CRIT,    "crit",    L2_LEVEL_CRITICAL },
-    { LOG_ERR,     "err",     L2_LEVEL_ERROR    },
-    { LOG_WARNING, "warning", L2_LEVEL_WARNING  },
-    { LOG_NOTICE,  "notice",  L2_LEVEL_NOTICE   },
-    { LOG_INFO,    "info",    L2_LEVEL_INFO     },
-    { LOG_DEBUG,   "debug",   L2_LEVEL_DEBUG    },
-    { 0,           NULL,      0                 }
+    { "emerg",   LOG_EMERG,   L2_LEVEL_PANIC    },
+    { "alert",   LOG_ALERT,   L2_LEVEL_PANIC    },
+    { "crit",    LOG_CRIT,    L2_LEVEL_CRITICAL },
+    { "err",     LOG_ERR,     L2_LEVEL_ERROR    },
+    { "warning", LOG_WARNING, L2_LEVEL_WARNING  },
+    { "notice",  LOG_NOTICE,  L2_LEVEL_NOTICE   },
+    { "info",    LOG_INFO,    L2_LEVEL_INFO     },
+    { "debug",   LOG_DEBUG,   L2_LEVEL_DEBUG    },
+    { NULL,      0,           0                 }
 };
 
+static struct {
+    char *string;
+    l2_level_t level;
+} l2level2string[] = {
+    { "none",     0,                  },
+    { "panic",    L2_LEVEL_PANIC,     },
+    { "critical", L2_LEVEL_CRITICAL,  },
+    { "error",    L2_LEVEL_ERROR,     },
+    { "warning",  L2_LEVEL_WARNING,   },
+    { "notice",   L2_LEVEL_NOTICE,    },
+    { "info",     L2_LEVEL_INFO,      },
+    { "trace",    L2_LEVEL_TRACE,     },
+    { "debug",    L2_LEVEL_DEBUG,     },
+    { NULL,       0                   }
+};
 typedef struct {
     int        syslog;
     l2_level_t l2;
@@ -307,7 +322,7 @@
     for (i = 0; sysloglevel2string[i].string != NULL; i++) {
         ctx.levelmap[i].syslog = sysloglevel2string[i].level;
         ctx.levelmap[i].l2     = sysloglevel2string[i].deflevelmap;
-        /*fprintf(stderr, "DEBUG: ctx.levelmap[%d].syslog = 0x%.8lx, ctx.levelmap[%d].l2 = 0x%.8lx\n", i, (unsigned long)ctx.levelmap[i].syslog, i, (unsigned long)ctx.levelmap[i].l2);*/
+        //fprintf(stderr, "DEBUG: ctx.levelmap[%d].syslog = 0x%.8lx, ctx.levelmap[%d].l2 = 0x%.8lx\n", i, (unsigned long)ctx.levelmap[i].syslog, i, (unsigned long)ctx.levelmap[i].l2);
     }
 
     /* create L2 environment */
@@ -476,19 +491,25 @@
         }
         else if (strcmp(cfgargtoka[0], "map") == 0) {
 
-            unsigned int levelmask;
+            int mapfrom;
+            int mapto;
 
-            for (i = 0; sysloglevel2string[i].string != NULL; i++) {
-                if (strcmp(sysloglevel2string[i].string, cfgargtoka[1]) == 0) {
-                    if ((l2rv = l2_util_s2l(cfgargtoka[2], strlen(cfgargtoka[2]), ',', &levelmask)) != L2_OK) {;
-                        cp = l2_env_strerror(ctx.l2_env, l2rv); fprintf(stderr, "Error: illegal l2 mask \"%s\" %s(%d)\n", cfgargtoka[2], cp, l2rv); CU(1); }
-                    ctx.levelmap[i].l2 = levelmask;
-                    /*fprintf(stderr, "DEBUG: ctx.levelmap[%d].syslog = 0x%.8lx, ctx.levelmap[%d].l2 = 0x%.8lx\n", i, (unsigned long)ctx.levelmap[i].syslog, i, (unsigned long)ctx.levelmap[i].l2);*/
-                    break;
-                }
+            for (i = 0, mapfrom = -1; (mapfrom == -1) && (sysloglevel2string[i].string != NULL); i++) {
+                if (strcmp(sysloglevel2string[i].string, cfgargtoka[1]) == 0)
+                    mapfrom = i;
             }
-            if (sysloglevel2string[i].string == NULL) {
-                fprintf(stderr, "Error: trying to map unknown syslog level \"%s\"\n", cfgargtoka[1]); CU(1); }
+            if (mapfrom == -1) {
+                fprintf(stderr, "Error: trying to map from unknown syslog level \"%s\"\n", cfgargtoka[1]); CU(1); }
+
+            for (i = 0, mapto = -1; (mapto == -1) && (l2level2string[i].string != NULL); i++) {
+                if (strcmp(l2level2string[i].string, cfgargtoka[2]) == 0)
+                    mapto = i;
+            }
+            if (mapto == -1) {
+                fprintf(stderr, "Error: trying to map to unknown l2 level \"%s\"\n", cfgargtoka[2]); CU(1); }
+            
+            ctx.levelmap[mapfrom].l2 = l2level2string[mapto].level;
+            //fprintf(stderr, "DEBUG: map levelmap[%10s/%d].l2 = l2level2string[%10s/%d].level = 0x%.8lx\n", cfgargtoka[1], mapfrom, cfgargtoka[2], mapto, (unsigned long)l2level2string[mapto].level);
         }
         else {
             fprintf(stderr, "Error: internal, argument \"%s\" not implemented\n", cfgargtoka[0]); CU(1); }
@@ -499,15 +520,6 @@
     }
     if ((l2rv = l2_channel_open(ctx.l2_nch)) != L2_OK) {
         cp = l2_env_strerror(ctx.l2_env, l2rv); fprintf(stderr, "Error: logging failed to open channel stream %s(%d)\n", cp, l2rv); CU(1); }
-    if ((l2rv = l2_channel_log(ctx.l2_nch, L2_LEVEL_PANIC,    "testing L2_LEVEL_PANIC    0x%.8x", L2_LEVEL_PANIC   )) != L2_OK)               fprintf(stderr, "DEBUG: GOTCHA#0:%s(%d)\n", l2_env_strerror(ctx.l2_env, l2rv), l2rv);
-    if ((l2rv = l2_channel_log(ctx.l2_nch, L2_LEVEL_CRITICAL, "testing L2_LEVEL_CRITICAL 0x%.8x", L2_LEVEL_CRITICAL)) != L2_OK)               fprintf(stderr, "DEBUG: GOTCHA#1:%s(%d)\n", l2_env_strerror(ctx.l2_env, l2rv), l2rv);
-    if ((l2rv = l2_channel_log(ctx.l2_nch, L2_LEVEL_ERROR,    "testing L2_LEVEL_ERROR    0x%.8x", L2_LEVEL_ERROR   )) != L2_OK)               fprintf(stderr, "DEBUG: GOTCHA#2:%s(%d)\n", l2_env_strerror(ctx.l2_env, l2rv), l2rv);
-    if ((l2rv = l2_channel_log(ctx.l2_nch, L2_LEVEL_WARNING,  "testing L2_LEVEL_WARNING  0x%.8x", L2_LEVEL_WARNING )) != L2_OK)               fprintf(stderr, "DEBUG: GOTCHA#3:%s(%d)\n", l2_env_strerror(ctx.l2_env, l2rv), l2rv);
-    if ((l2rv = l2_channel_log(ctx.l2_nch, L2_LEVEL_NOTICE,   "testing L2_LEVEL_NOTICE   0x%.8x", L2_LEVEL_NOTICE  )) != L2_OK)               fprintf(stderr, "DEBUG: GOTCHA#4:%s(%d)\n", l2_env_strerror(ctx.l2_env, l2rv), l2rv);
-    if ((l2rv = l2_channel_log(ctx.l2_nch, L2_LEVEL_INFO,     "testing L2_LEVEL_INFO     0x%.8x", L2_LEVEL_INFO    )) != L2_OK)               fprintf(stderr, "DEBUG: GOTCHA#5:%s(%d)\n", l2_env_strerror(ctx.l2_env, l2rv), l2rv);
-    if ((l2rv = l2_channel_log(ctx.l2_nch, L2_LEVEL_TRACE,    "testing L2_LEVEL_TRACE    0x%.8x", L2_LEVEL_TRACE   )) != L2_OK)               fprintf(stderr, "DEBUG: GOTCHA#6:%s(%d)\n", l2_env_strerror(ctx.l2_env, l2rv), l2rv);
-    if ((l2rv = l2_channel_log(ctx.l2_nch, L2_LEVEL_DEBUG,    "testing L2_LEVEL_DEBUG    0x%.8x", L2_LEVEL_DEBUG   )) != L2_OK)               fprintf(stderr, "DEBUG: GOTCHA#7:%s(%d)\n", l2_env_strerror(ctx.l2_env, l2rv), l2rv);
-    if ((l2rv = l2_channel_log(ctx.l2_nch, L2_LEVEL_INFO|L2_LEVEL_CRITICAL, "combitest   0x%.8x", L2_LEVEL_INFO|L2_LEVEL_CRITICAL)) != L2_OK) fprintf(stderr, "DEBUG: GOTCHA#8:%s(%d)\n", l2_env_strerror(ctx.l2_env, l2rv), l2rv);
 
     ctx.maskpri = LOG_UPTO(LOG_DEBUG);
 
@@ -579,15 +591,17 @@
         return;
 
     priority &= LOG_PRIMASK; /* strip off facility */
-    fprintf(stderr, "DEBUG: prioriy=0x%.8lx\n", (unsigned long)priority);
+    //fprintf(stderr, "DEBUG: prioriy  =0x%.8lx  ", (unsigned long)priority);
 
     levelmask = 0;
     for (i = 0; sysloglevel2string[i].string != NULL; i++) {
-    /*fprintf(stderr, "DEBUG: ctx.levelmap[%d].syslog = 0x%.8lx, ctx.levelmap[%d].l2 = 0x%.8lx\n", i, (unsigned long)ctx.levelmap[i].syslog, i, (unsigned long)ctx.levelmap[i].l2);*/
-        if (ctx.levelmap[i].syslog == priority)
-            levelmask |= ctx.levelmap[i].l2;
+    //fprintf(stderr, "DEBUG: ctx.levelmap[%d].syslog = 0x%.8lx, ctx.levelmap[%d].l2 = 0x%.8lx\n", i, (unsigned long)ctx.levelmap[i].syslog, i, (unsigned long)ctx.levelmap[i].l2);
+        if (ctx.levelmap[i].syslog == priority) {
+            levelmask = ctx.levelmap[i].l2;
+            break;
+        }
     }
-    fprintf(stderr, "DEBUG: levelmask=0x%.8lx\n", (unsigned long)levelmask);
+    //fprintf(stderr, "DEBUG: levelmask=0x%.8lx\n", (unsigned long)levelmask);
     l2_channel_vlog(ctx.l2_nch, levelmask, fmt, args);
     return;
 }

CVSTrac 2.0.1