OSSP CVS Repository

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

Check-in Number: 866
Date: 2001-Sep-05 17:01:57 (local)
2001-Sep-05 15:01:57 (UTC)
User:thl
Branch:
Comment: flush pending (unfinished) work.
Tickets:
Inspections:
Files:
ossp-pkg/lmtp2nntp/lmtp2nntp.c      1.40 -> 1.41     104 inserted, 14 deleted
ossp-pkg/lmtp2nntp/lmtp2nntp.pod      1.16 -> 1.17     8 inserted, 0 deleted

ossp-pkg/lmtp2nntp/lmtp2nntp.c 1.40 -> 1.41

--- lmtp2nntp.c  2001/09/05 09:14:26     1.40
+++ lmtp2nntp.c  2001/09/05 15:01:57     1.41
@@ -37,6 +37,7 @@
 #include "str.h"
 #include "argz.h"
 #include "shpat_match.h"
+#include "l2/l2.h" //FIXME
 
 /* own headers */
 #ifdef HAVE_CONFIG_H
@@ -113,6 +114,8 @@
     int             option_maxmessagesize;
     int             option_waittime;
     char           *option_mailfrom;
+    unsigned int    option_levelmask;
+    l2_stream_t    *l2;
     char           *cpBindh;
     char           *cpBindp;
     sa_t           *saBind;
@@ -171,18 +174,20 @@
 
 int main(int argc, char **argv)
 {
-    int          rc = 0;
-    lmtp_t      *lmtp;
-    lmtp_io_t    lmtp_io;
-    lmtp2nntp_t *ctx;
-    int          i;             /* general purpose scratch int, index ... */
-    char        *cp;            /* general purpose character pointer */
-    char        *progname;
-    char        *azHosts;
-    size_t       asHosts;
-    char        *cpHost;
-    char        *cpPort;
-    sa_t        *sa;
+    lmtp_t       *lmtp;
+    lmtp_io_t     lmtp_io;
+    lmtp2nntp_t  *ctx;
+    int           i;             /* general purpose scratch int, index ... */
+    char         *cp;            /* general purpose character pointer */
+    char         *progname;
+    char         *azHosts;
+    size_t        asHosts;
+    char         *cpHost;
+    char         *cpPort;
+    sa_t         *sa;
+    l2_channel_t *chPrefix;
+    l2_channel_t *chBuf;
+    l2_channel_t *chFile;
 
     progname = argv[0];
 
@@ -198,6 +203,8 @@
     ctx->option_maxmessagesize = 8 * 1024 * 1024;
     ctx->option_waittime = -1;
     ctx->option_mailfrom = NULL;
+    ctx->option_levelmask = L2_LEVEL_UPTO(L2_LEVEL_ERROR);
+    ctx->l2 = NULL;
     ctx->cpBindh = NULL;
     ctx->cpBindp = NULL;
     ctx->saBind = NULL;
@@ -234,6 +241,57 @@
     }
 #endif
 
+    if ((ctx->l2 = l2_stream_create()) == NULL) {
+        fprintf(stderr, "%s:Error: logging failed to create stream\n", progname);
+        exit(ERR_EXECUTION);
+    }
+
+    if ((chPrefix  = l2_channel_create(&l2_handler_prefix)) == NULL) {
+        fprintf(stderr, "%s:Error: logging failed to create prefix channel\n", progname);
+        exit(ERR_EXECUTION);
+    }
+    if (l2_channel_configure(chPrefix, "timefmt,timezone", "[%d-%m-%Y/%H:%M:%S] ", "local") != L2_OK) {
+        fprintf(stderr, "%s:Error: logging failed to configure prefix channel\n", progname);
+        exit(ERR_EXECUTION);
+    }
+
+    if ((chBuf  = l2_channel_create(&l2_handler_buffer)) == NULL) {
+        fprintf(stderr, "%s:Error: logging failed to create buffer channel\n", progname);
+        exit(ERR_EXECUTION);
+    }
+    if (l2_channel_configure(chBuf, "size", 4096) != L2_OK) {
+        fprintf(stderr, "%s:Error: logging failed to configure buffer channel\n", progname);
+        exit(ERR_EXECUTION);
+    }
+
+    if ((chFile = l2_channel_create(&l2_handler_file)) == NULL) {
+        fprintf(stderr, "%s:Error: logging failed to create file channel\n", progname);
+        exit(ERR_EXECUTION);
+    }
+    if (l2_channel_configure(chFile, "path,append,perm", "logtest", TRUE, 0644) != L2_OK) {
+        fprintf(stderr, "%s:Error: logging failed to configure file channel\n", progname);
+        exit(ERR_EXECUTION);
+    }
+
+    if (l2_channel_stack(chFile, chBuf) != L2_OK) {
+        fprintf(stderr, "%s:Error: logging failed to stack buffer channel on top of file channel\n", progname);
+        exit(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", progname);
+        exit(ERR_EXECUTION);
+    }
+
+    if (l2_channel_open(chPrefix) != L2_OK) {
+        fprintf(stderr, "%s:Error: logging failed to open buffer channel\n", progname);
+        exit(ERR_EXECUTION);
+    }
+
+    if (l2_stream_channel(ctx->l2, chPrefix, L2_LEVEL_UPTO(L2_LEVEL_DEBUG)) != L2_OK) {
+        fprintf(stderr, "%s:Error: logging failed to attach channel into stream\n", progname);
+        exit(ERR_EXECUTION);
+    }
+
     /*POD B<lmtp2nntp> */
 
     /*  use
@@ -242,8 +300,15 @@
      */
 
     /* read in the arguments */
-    while ((i = getopt(argc, argv, "Vb:d:g:h:m:n:s:t:vw:")) != -1) {
+    while ((i = getopt(argc, argv, "L:Vb:d:g:h:l:m:n:s:t:vw:")) != -1) {
         switch (i) {
+            case 'L': /*POD B<-L> I<level>*/
+                if (l2_util_s2l(optarg, strlen(optarg), ',', &ctx->option_levelmask) != L2_OK) {
+                    fprintf(stderr, "%s:Error: Invalid format \"%s\" to option -L\n", progname, optarg);
+                    exit(ERR_EXECUTION);
+                }
+                //FIXME
+                break;
             case 'V': /*POD [B<-V>] (version)*/
                 fprintf(stdout, "%s\n", lmtp2nntp_version.v_gnu);
                 exit(0);
@@ -420,6 +485,26 @@
         argz_add(&ctx->azGroupargs, &ctx->asGroupargs, argv[i]);
     }
 
+    /* initialize L2 logging context */
+    fprintf(stderr, "DEBUG: ctx->option_levelmask=0x%x\n", ctx->option_levelmask);
+    if (l2_stream_levels(ctx->l2, ctx->option_levelmask) != L2_OK) {
+        fprintf(stderr, "%s:Error: logging failed to set global logging level\n", progname);
+        exit(ERR_EXECUTION);
+    }
+
+    if (l2_stream_log(ctx->l2, L2_LEVEL_INFO, "%s: Startup", progname) != L2_OK) {
+        fprintf(stderr, "%s:Error: logging failed to log \"Startup\" message to stream\n", progname);
+        exit(ERR_EXECUTION);
+    }
+    if (l2_stream_log(ctx->l2, L2_LEVEL_DEBUG, "%s: Startup DEBUG-test", progname) != L2_OK) {
+        fprintf(stderr, "%s:Error: logging failed to log \"Startup\" message to stream\n", progname);
+        exit(ERR_EXECUTION);
+    }
+    if (l2_stream_log(ctx->l2, L2_LEVEL_PANIC, "%s: Startup PANIC-test", progname) != L2_OK) {
+        fprintf(stderr, "%s:Error: logging failed to log \"Startup\" message to stream\n", progname);
+        exit(ERR_EXECUTION);
+    }
+
     /* initialize LMTP context */
     lmtp_io.select = NULL;
     lmtp_io.read   = trace_read;
@@ -464,7 +549,12 @@
         free(ctx);
     str_parse(NULL, NULL);
 
-    return rc;
+    if (l2_stream_destroy(ctx->l2) != L2_OK) {
+        fprintf(stderr, "%s:Error: logging failed to destroy stream\n", progname);
+        exit(ERR_EXECUTION);
+    }
+
+    return 0;
 }
 
 /* taken from "UNIX Network Programming", Volume 1, second edition W. Richard


ossp-pkg/lmtp2nntp/lmtp2nntp.pod 1.16 -> 1.17

--- lmtp2nntp.pod        2001/09/05 09:14:27     1.16
+++ lmtp2nntp.pod        2001/09/05 15:01:57     1.17
@@ -178,9 +178,17 @@
 
 =item B<-l> C<file:>I<localfile>
 
+
 Logging target. This option can be specified more than once. Default is no
 logging. Default I<facility> for C<syslog:> is C<lmtp2nntp>.
 
+=item B<-L> I<level>
+
+Logging level. Default is C<warn>. Possible levels from highest priority with
+least output to lowest priority with most most outpout are C<panic>,
+C<critical>, C<error>, C<warning>, C<notice>, C<info>, C<trace>, C<debug>
+where the chosen level includes all levels with higher priority.
+
 =back
 
 =head1 SENDMAIL INTEGRATION

CVSTrac 2.0.1