OSSP CVS Repository

ossp - Difference in ossp-pkg/l2/l2_test.c versions 1.37 and 1.38
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/l2/l2_test.c 1.37 -> 1.38

--- l2_test.c    2001/11/03 22:51:36     1.37
+++ l2_test.c    2001/11/04 13:21:17     1.38
@@ -57,182 +57,88 @@
 
 int main(int argc, char *argv[])
 {
-    l2_channel_t *chFilt;
+    l2_channel_t *chFilter;
     l2_channel_t *chPrefix;
-    l2_channel_t *chBuf;
+    l2_channel_t *chBuffer;
     l2_channel_t *chFile;
-#ifdef WITH_SYSLOG
     l2_channel_t *chSyslog;
-#endif
-#ifdef WITH_PIPE
-    l2_channel_t *chPipe;
-#endif
-#ifdef WITH_SOCKET
-    l2_channel_t *chSock;
-#endif
-#ifdef WITH_IRC
-    l2_channel_t *chIrc;
-#endif
-#ifdef WITH_SMTP
     l2_channel_t *chSmtp;
-#endif
-    l2_stream_t *st;
+    l2_env_t *env;
 
-    /*
-     * Typical steps to use a buffered file logging stream
-     */
-    if ((st = l2_stream_create()) == NULL)
-        die("failed to create stream");
+    /* create environment */
+    if ((l2_env_create(&env)) != L2_OK)
+        die("failed to create environment");
+    if (l2_env_formatter(env, 'k', formatter, NULL) != L2_OK)
+        die("failed to configure formatter for %%x");
+    if (l2_env_formatter(env, 'S', l2_util_fmt_dump, NULL) != L2_OK)
+        die("failed to configure formatter for %%S");
 
-    if ((chPrefix  = l2_channel_create(&l2_handler_prefix)) == NULL) /* Prefix */
+    /* create prefix channel */
+    if ((l2_channel_create(&chPrefix, env, &l2_handler_prefix)) != L2_OK)
         die("failed to create prefix channel");
-
-    if (l2_channel_configure(chPrefix, "prefix,timezone", "[%d-%m-%Y/%H:%M:%S] %L test[%P]: ", "local") != L2_OK)
+    if (l2_channel_configure(chPrefix, "prefix,timezone", 
+                             "[%d-%m-%Y/%H:%M:%S] %L test[%P]: ", "local") != L2_OK)
         die("failed to configure prefix channel");
 
-    if ((chFilt = l2_channel_create(&l2_handler_filter)) == NULL)    /* Filter */
+    /* create prefix channel */
+    if ((l2_channel_create(&chFilter, env, &l2_handler_filter)) != L2_OK)
         die("failed to create filter channel");
-
-    if (l2_channel_configure(chFilt, "regex,negate", "hecking", 0) != L2_OK)
+    if (l2_channel_configure(chFilter, "regex,negate", "hecking", 0) != L2_OK)
         die("failed to configure filter channel");
 
-    if ((chBuf  = l2_channel_create(&l2_handler_buffer)) == NULL)    /* Buffer */
+    /* create buffer channel */
+    if ((l2_channel_create(&chBuffer, env, &l2_handler_buffer)) != L2_OK)
         die("failed to create buffer channel");
-
-    if (l2_channel_configure(chBuf, "size", 800) != L2_OK)
+    if (l2_channel_configure(chBuffer, "size", 800) != L2_OK)
         die("failed to configure buffer channel");
 
-    if ((chFile = l2_channel_create(&l2_handler_file)) == NULL)      /* File   */
+    /* create file channel */
+    if ((l2_channel_create(&chFile, env, &l2_handler_file)) != L2_OK)
         die("failed to create file channel");
-
     if (l2_channel_configure(chFile, "path,append,perm", "l2_test.log", TRUE, 0644) != L2_OK)
         die("failed to configure file channel");
+    if (l2_channel_levels(chFile, L2_LEVEL_UPTO(L2_LEVEL_INFO), L2_LEVEL_NONE) != L2_OK)
+        die("failed to level of smtp channel");
 
-    if (l2_channel_stack(chFile, chBuf) != L2_OK)
-        die("failed to stack buffer channel on top of file channel");
-    
-    if (l2_channel_stack(chBuf, chPrefix) != L2_OK)
-        die("failed to stack prefix channel on top of buffer channel");
-
-    if (l2_channel_stack(chPrefix, chFilt) != L2_OK)
-        die("failed to stack filter channel on top of prefix channel");
-    
-    if (l2_channel_open(chFilt) != L2_OK)
-        die("failed to open channel stack");
-
-    if (l2_stream_channel(st, chFilt, L2_LEVEL_UPTO(L2_LEVEL_WARNING), L2_LEVEL_NONE) != L2_OK)
-        die("failed to attach channel stack into stream");
-
-#ifdef WITH_SYSLOG
-    if ((chSyslog = l2_channel_create(&l2_handler_syslog)) == NULL)  /* Syslog */
+    /* create syslog channel */
+    if ((l2_channel_create(&chSyslog, env, &l2_handler_syslog)) != L2_OK)
         die("failed to create syslog channel");
-
     if (l2_channel_configure(chSyslog, "ident,facility,target,remotehost,logpid",
-        "L2-Test", "user", "remote", "en1", 1) != L2_OK)
+                             "L2-Test", "user", "remote", "en1", 1) != L2_OK)
         die("failed to configure syslog channel");
+    if (l2_channel_levels(chSyslog, L2_LEVEL_UPTO(L2_LEVEL_ERROR), L2_LEVEL_ALL) != L2_OK)
+        die("failed to level of syslog channel");
 
-    if (l2_channel_open(chSyslog) != L2_OK)
-        die("failed to open channel stack");
-
-    if (l2_stream_channel(st, chSyslog, L2_LEVEL_UPTO(L2_LEVEL_WARNING), L2_LEVEL_NONE) != L2_OK)
-        die("failed to attach channel syslog into stream");
-#endif /* Syslog */
-
-#ifdef WITH_PIPE
-    if ((chPipe = l2_channel_create(&l2_handler_pipe)) == NULL)      /* Pipe */
-        die("failed to create pipe channel");
-
-#if 0
-    if (l2_channel_configure(chPipe, "mode,path", "direct", "/u/ms/travail/cronolinux/sbin/cronolog -o /u/ms/tmp/crono.log") != L2_OK)
-        die("failed to configure pipe channel");
-#endif
-
-    if (l2_channel_configure(chPipe, "execmode,path", "shell", "$CRONOLOGDIR/cronolog -o $HOME/tmp/crono.log") != L2_OK)
-        die("failed to configure pipe channel due to mode and path parameters");
-
-    if (l2_channel_configure(chPipe, "runtime", "continuous") != L2_OK)
-        die("failed to configure pipe channel due to continuous parameter");
-
-    if (l2_channel_open(chPipe) != L2_OK)
-        die("failed to open pipe channel");
-
-    if (l2_stream_channel(st, chPipe, L2_LEVEL_UPTO(L2_LEVEL_WARNING), L2_LEVEL_NONE) != L2_OK)
-        die("failed to attach channel pipe into stream");
-#endif /* Pipe */
-
-#ifdef WITH_IRC
-    /* Atenzione! Before testing IRC start the IRC server. */
-    if ((chIrc = l2_channel_create(&l2_handler_irc)) == NULL)   /* IRC */
-        die("failed to create IRC channel");
-
-    if (l2_channel_configure(chIrc) != L2_OK)
-        die("failed to configure IRC channel");
-
-    if (l2_channel_open(chIrc) != L2_OK)
-        die("failed to open IRC channel");
-
-    if (l2_stream_channel(st, chIrc, L2_LEVEL_UPTO(L2_LEVEL_WARNING), L2_LEVEL_NONE) != L2_OK)
-        die("failed to attach channel IRC into stream");
-#endif /* IRC */
-
-#ifdef WITH_SOCKET
-    /* Atenzione! Before doing any socket testing, make sure you have a valid */
-    /* end point listening, or else you will only get an error message when   */
-    /* the thing tries to connect.                                            */
-    if ((chSock = l2_channel_create(&l2_handler_socket)) == NULL)   /* Socket */
-        die("failed to create socket channel");
-
-    if (l2_channel_configure(chSock, "proto,host,port",\
-        "tcp", "localhost", 2002) != L2_OK)
-        die("failed to configure socket tcp/ipv4 channel");
-#if 0
-    if (l2_channel_configure(chSock, "proto,host,port",\
-          "tcp", "0:0:0:0:0:0:0:1", 2002) != L2_OK)
-          die("failed to configure socket tcp/ipv6 channel");
-#endif
-    if (l2_channel_open(chSock) != L2_OK)
-        die("failed to open socket channel");
-
-    if (l2_stream_channel(st, chSock, L2_LEVEL_UPTO(L2_LEVEL_WARNING), L2_LEVEL_NONE) != L2_OK)
-        die("failed to attach channel socket into stream");
-#endif /* Socket */
-
-#ifdef WITH_SMTP
-    if ((chSmtp = l2_channel_create(&l2_handler_smtp)) == NULL)      /* SMTP */
+    /* create smtp channel */
+    if ((l2_channel_create(&chSmtp, env, &l2_handler_smtp)) != L2_OK)
         die("failed to create smtp channel");
-
     if (l2_channel_configure(chSmtp, "rcpt,host,port", "rse@engelschall.com", "en1", "25") != L2_OK)
         die("failed to configure smtp channel");
+    if (l2_channel_levels(chSmtp, L2_LEVEL_UPTO(L2_LEVEL_PANIC), L2_LEVEL_ALL) != L2_OK)
+        die("failed to level of smtp channel");
 
-    if (l2_channel_open(chSmtp) != L2_OK)
-        die("failed to open smtp channel");
-
-    if (l2_stream_channel(st, chSmtp, L2_LEVEL_UPTO(L2_LEVEL_ERROR), L2_LEVEL_NONE) != L2_OK)
-        die("failed to attach smtp channel into stream");
-#endif /* SMTP */
-
-    if (l2_stream_levels(st, L2_LEVEL_UPTO(L2_LEVEL_WARNING), L2_LEVEL_NONE) != L2_OK)
-        die("failed to set global logging level");
+    /* build channel tree */
+    if (l2_channel_link(chFilter, L2_LINK_CHILDS, chPrefix, chBuffer, chFile, NULL) != L2_OK)
+        die("failed to link channels together as a child sequence");
+    if (l2_channel_link(chFilter, L2_LINK_SIBLINGS, chSyslog, NULL) != L2_OK)
+        die("failed to link filter channel on top of syslog channel");
+
+    /* open channel tree */
+    if (l2_channel_open(chFilter) != L2_OK)
+        die("failed to open channel tree");
     
-    if (l2_stream_formatter(st, 'k', formatter, NULL) != L2_OK)
-        die("failed to configure formatter for %%x");
-
-    if (l2_stream_formatter(st, 'S', l2_util_fmt_dump, NULL) != L2_OK)
-        die("failed to configure formatter for %%S");
-
-    if (l2_stream_log(st, L2_LEVEL_PANIC, "0Checking localhost %s %{myparm}k <%{text}S><%{hex}S><%{base64}S>\n", "foo", 12345, "foo\1bar", 7, "foo\1bar", 7, "foo\1bar", 7) != L2_OK)
-        die("failed to log message to stream");
-
-    if (l2_stream_log(st, L2_LEVEL_PANIC, "1Shecking\n") != L2_OK)
-        die("failed to log message to stream");
-
-    if (l2_stream_log(st, L2_LEVEL_PANIC, "2Checking localhost %s %{myparm}k <%{text}S><%{hex}S><%{base64}S>\n", "foo", 12345, "foo\1bar", 7, "foo\1bar", 7, "foo\1bar", 7) != L2_OK)
-        die("failed to log message to stream");
-
-    if (l2_stream_log(st, L2_LEVEL_PANIC, "3Shecking\n") != L2_OK)
-        die("failed to log message to stream");
+    /* perform a few log operations */
+    if (l2_channel_log(chFilter, L2_LEVEL_PANIC, "1: Checking localhost %s %{myparm}k <%{text}S><%{hex}S><%{base64}S>\n", "foo", 12345, "foo\1bar", 7, "foo\1bar", 7, "foo\1bar", 7) != L2_OK)
+        die("failed to log message #1 to channel");
+    if (l2_channel_log(chFilter, L2_LEVEL_PANIC, "2: Shecking\n") != L2_OK)
+        die("failed to log message #2 to channel");
+    if (l2_channel_log(chFilter, L2_LEVEL_PANIC, "3: Checking localhost %s %{myparm}k <%{text}S><%{hex}S><%{base64}S>\n", "foo", 12345, "foo\1bar", 7, "foo\1bar", 7, "foo\1bar", 7) != L2_OK)
+        die("failed to log message #3 to channel");
+    if (l2_channel_log(chFilter, L2_LEVEL_PANIC, "4: Shecking\n") != L2_OK)
+        die("failed to log message #4 to channel");
 
-    if (l2_stream_destroy(st) != L2_OK)
+    /* destroy channel tree */
+    if (l2_channel_destroy(chFilter) != L2_OK)
         die("failed to destroy stream");
 
     return 0;

CVSTrac 2.0.1