OSSP CVS Repository

ossp - Difference in ossp-pkg/lmtp2nntp/lmtp2nntp.c versions 1.98 and 1.99
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/lmtp2nntp/lmtp2nntp.c 1.98 -> 1.99

--- lmtp2nntp.c  2001/11/08 10:08:09     1.98
+++ lmtp2nntp.c  2001/12/11 11:53:11     1.99
@@ -123,7 +123,7 @@
     sa_t           *sa;   /* socket abstraction */
     nntp_t         *nntp;
     nntp_rc_t       rc;
-    l2_stream_t    *l2;
+    l2_channel_t   *l2;
 };
 
 struct acl {
@@ -162,7 +162,8 @@
     int             option_veryverbose;
     int             option_childsmax;
     int             active_childs;
-    l2_stream_t    *l2;
+    l2_env_t       *l2_env;
+    l2_channel_t   *l2;
     sa_addr_t      *saaAltio;
     sa_t           *saAltio;
     char           *cpBindh;
@@ -363,7 +364,7 @@
                 return;
             case SIGUSR1:
                 log1(ctx, NOTICE, "caught signal %d - flush logging stream", sig);
-                l2_stream_flush(ctx->l2);
+                l2_channel_flush(ctx->l2);
                 return;
             case SIGHUP:
             case SIGINT:
@@ -373,7 +374,8 @@
             default:
                 log1(ctx, PANIC, "CAUGHT SIGNAL %d - EXIT - NO MORE LOGGING", sig);
         }
-        l2_stream_destroy(ctx->l2);
+        l2_channel_destroy(ctx->l2);
+        l2_env_destroy(ctx->l2_env);
     }
     exit(ERR_EXECUTION);
 }
@@ -396,9 +398,6 @@
     size_t        asACL;
     char         *cpHost;
     char         *cpPort;
-    l2_channel_t *chPrefix;
-    l2_channel_t *chBuf;
-    l2_channel_t *chFile;
     pid_t         pid;
     FILE         *fd;
     char         *cpName;
@@ -453,6 +452,7 @@
     ctx->option_veryverbose = FALSE;
     ctx->option_childsmax = 10;
     ctx->active_childs = 0;
+    ctx->l2_env = NULL;
     ctx->l2 = NULL;
     ctx->saaAltio = NULL;
     ctx->saAltio = NULL;
@@ -962,100 +962,62 @@
         }
     }
 
-    if ((ctx->l2 = l2_stream_create()) == NULL) {
-        fprintf(stderr, "%s:Error: logging failed to create stream\n", ctx->progname);
-        CU(ERR_EXECUTION);
-    }
-    if (l2_stream_levels(ctx->l2, L2_LEVEL_UPTO(L2_LEVEL_DEBUG), L2_LEVEL_NONE) != L2_OK) {
-        fprintf(stderr, "%s:Error: logging failed to set global logging level\n", ctx->progname);
+    /* create L2 environment */
+    if (l2_env_create(&ctx->l2_env) != L2_OK) {
+        fprintf(stderr, "%s:Error: failed to create L2 environment\n", ctx->progname);
         CU(ERR_EXECUTION);
     }
 
-    if (l2_stream_formatter(ctx->l2, 'P', formatter_prefix, &ctx->ctx) != L2_OK) {
+    /* register custom L2 formatters */
+    if (l2_env_formatter(ctx->l2_env, 'P', formatter_prefix, &ctx->ctx) != L2_OK) {
         fprintf(stderr, "%s:Error: logging failed to register prefix formatter\n", ctx->progname);
         CU(ERR_EXECUTION);
     }
-    if (l2_stream_formatter(ctx->l2, 'D', l2_util_fmt_dump, NULL) != L2_OK) {
+    if (l2_env_formatter(ctx->l2_env, 'D', l2_util_fmt_dump, NULL) != L2_OK) {
         fprintf(stderr, "%s:Error: logging failed to register dump formatter\n", ctx->progname);
         CU(ERR_EXECUTION);
     }
-    if (l2_stream_formatter(ctx->l2, 'S', l2_util_fmt_string, NULL) != L2_OK) {
+    if (l2_env_formatter(ctx->l2_env, 'S', l2_util_fmt_string, NULL) != L2_OK) {
         fprintf(stderr, "%s:Error: logging failed to register string formatter\n", ctx->progname);
         CU(ERR_EXECUTION);
     }
-    if (l2_stream_formatter(ctx->l2, 'm', formatter_errno, NULL) != L2_OK) {
+    if (l2_env_formatter(ctx->l2_env, 'm', formatter_errno, NULL) != L2_OK) {
         fprintf(stderr, "%s:Error: logging failed to register errno formatter\n", ctx->progname);
         CU(ERR_EXECUTION);
     }
 
-    if((ctx->option_levelmask != L2_LEVEL_NONE) && (ctx->option_logfile != NULL)) {
-        if ((chPrefix  = l2_channel_create(&l2_handler_prefix)) == NULL) {
-            fprintf(stderr, "%s:Error: logging failed to create prefix channel\n", ctx->progname);
-            CU(ERR_EXECUTION);
-        }
-        if (l2_channel_configure(chPrefix, "prefix,timezone", "%b %d %H:%M:%S <%L> lmtp2nntp[%P]: ", "local") != L2_OK) {
-            fprintf(stderr, "%s:Error: logging failed to configure prefix channel\n", ctx->progname);
-            CU(ERR_EXECUTION);
-        }
-
-        if (!ctx->option_veryverbose) {
-            if ((chBuf  = l2_channel_create(&l2_handler_buffer)) == NULL) {
-                fprintf(stderr, "%s:Error: logging failed to create buffer channel\n", ctx->progname);
-                CU(ERR_EXECUTION);
-            }
-            if (l2_channel_configure(chBuf, "size", 65536) != L2_OK) {
-                fprintf(stderr, "%s:Error: logging failed to configure buffer channel\n", ctx->progname);
-                CU(ERR_EXECUTION);
-            }
-        }
+    /* create channel stream */
+    if (ctx->option_levelmask != L2_LEVEL_NONE && ctx->option_logfile != NULL) {
+        if (ctx->option_veryverbose)
+            rc = l2_spec(&ctx->l2, ctx->l2_env, 
+                         "prefix(prefix=\"%%b %%d %%H:%%M:%%S <%%L> lmtp2nntp[%%P]: \",timezone=local)"
+                         "  -> buffer(size=65536)"
+                         "  -> file(path=%s,append=1,perm=%d)",
+                         ctx->option_logfile, 0644);
         else
-            chBuf = NULL;
-
-        if ((chFile = l2_channel_create(&l2_handler_file)) == NULL) {
-            fprintf(stderr, "%s:Error: logging failed to create file channel\n", ctx->progname);
+            rc = l2_spec(&ctx->l2, ctx->l2_env, 
+                         "prefix(prefix=\"%%b %%d %%H:%%M:%%S <%%L> lmtp2nntp[%%P]: \",timezone=local)"
+                         "  -> file(path=%s,append=1,perm=%d)",
+                         ctx->option_logfile, 0644);
+        if (rc != L2_OK) {
+            fprintf(stderr, "%s:Error: logging failed to create stream\n", ctx->progname);
             CU(ERR_EXECUTION);
         }
-        if (l2_channel_configure(chFile, "path,append,perm", ctx->option_logfile, TRUE, 0644) != L2_OK) {
-            fprintf(stderr, "%s:Error: logging failed to configure file channel\n", ctx->progname);
+        if (l2_channel_levels(ctx->l2, ctx->option_levelmask, L2_LEVEL_NONE) != L2_OK) {
+            fprintf(stderr, "%s:Error: logging failed to set global logging level\n", ctx->progname);
             CU(ERR_EXECUTION);
         }
-
-        if (!ctx->option_veryverbose) {
-            if (l2_channel_stack(chFile, chBuf) != L2_OK) {
-                fprintf(stderr, "%s:Error: logging failed to stack buffer channel on top of file channel\n", ctx->progname);
-                CU(ERR_EXECUTION);
-            }
-            if (l2_channel_stack(chBuf, chPrefix) != L2_OK) {
-                fprintf(stderr, "%s:Error: logging failed to stack prefix channel on top of buffer channel\n", ctx->progname);
-                CU(ERR_EXECUTION);
-            }
-        }
-        else {
-            if (l2_channel_stack(chFile, chPrefix) != L2_OK) {
-                fprintf(stderr, "%s:Error: logging failed to stack prefix channel on top of buffer channel\n", ctx->progname);
-                CU(ERR_EXECUTION);
-            }
-        }
-
-        if (l2_channel_open(chPrefix) != L2_OK) {
-            fprintf(stderr, "%s:Error: logging failed to open buffer channel\n", ctx->progname);
-            CU(ERR_EXECUTION);
-        }
-
-        if (l2_stream_channel(ctx->l2, chPrefix, ctx->option_levelmask, L2_LEVEL_NONE) != L2_OK) {
-            fprintf(stderr, "%s:Error: logging failed to attach channel into stream\n", ctx->progname);
+        if (l2_channel_open(ctx->l2) != L2_OK) {
+            fprintf(stderr, "%s:Error: logging failed to open channel stream\n", ctx->progname);
             CU(ERR_EXECUTION);
         }
     }
 
-    if (log1(ctx, NOTICE, "startup, version %s", lmtp2nntp_version.v_gnu) != L2_OK) {
-        fprintf(stderr, "%s:Error: logging failed to log startup message to stream\n", ctx->progname);
-        CU(ERR_EXECUTION);
-    }
     /* from this point on logging is up and running and fprintf(stderr, ...)
      * should not be used in the remainder of the code
      */
 
+    log1(ctx, NOTICE, "startup, version %s", lmtp2nntp_version.v_gnu);
     if (ctx->option_veryverbose)
         log0(ctx, NOTICE, "logging very verbose (unbuffered)");
 
@@ -1219,7 +1181,7 @@
 
             /* logging buffer must be empty before fork otherwise content is
              * duplicated and written twice on next flush */
-            l2_stream_flush(ctx->l2);
+            l2_channel_flush(ctx->l2);
             pid = fork();
             if (pid == -1) {
                 log0(ctx, ERROR, "daemon cannot spawn child %m");
@@ -1280,7 +1242,8 @@
     /* graceful shutdown */
     CUS:
     log0(ctx, NOTICE, "graceful shutdown shortly before exit - no more logging");
-    l2_stream_destroy(ctx->l2);
+    l2_channel_destroy(ctx->l2);
+    l2_env_destroy(ctx->l2_env);
     if (ctx->saAltio)
         sa_destroy(ctx->saAltio);
     if (ctx->saaAltio)

CVSTrac 2.0.1