OSSP CVS Repository

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

ossp-pkg/l2/l2_epreuve.c 1.4 -> 1.5

--- l2_epreuve.c 2001/08/24 15:15:47     1.4
+++ l2_epreuve.c 2001/08/26 13:02:27     1.5
@@ -30,17 +30,21 @@
     
 #include "l2.h"
 #include "l2_p.h"
+#include <syslog.h>
 
-#define L2_HEXBASE       16
-#define L2_COMMANDARG     0
-#define L2_BUFSIZEARG     1
-#define L2_FILEARG        2
-#define L2_MESSAGEARG     3
-#define L2_VONBUFSTRING   " in L2_buffer.\n"
-#define L2_VONFILESTRING  " von L2_file Kanal.\n"
+#define L2_HEXBASE          16
+#define L2_COMMANDARG        0
+#define L2_BUFSIZEARG        1
+#define L2_FILEARG           2
+#define L2_MESSAGEARG        3
+#define L2_VONBUFSTRING      " in L2_buffer.\n"
+#define L2_VONFILESTRING     " von L2_file Kanal.\n"
+#define L2_VONL2LIB          " L2Lib"
+#define L2_VONSYSLOGSTRING   " von L2_syslog Kanal.\n"
 
 void throwup(char *);
 int trybuf(char **);
+int trysyslog(char **);
 int tryfile(char **);
 
 /*--------------------------------------------------------*/
@@ -113,6 +117,61 @@
 }
 
 /*--------------------------------------------------------*/
+/* void trysyslog(char *pszArgs[])                        */
+/* Test logic for the syslog channel handler              */
+/*--------------------------------------------------------*/
+int trysyslog(char *pszArgs[])
+{
+    int iRet                       = 0;
+    int iMsgSize                   = 0;
+    char *pszMsgIn                 = NULL;
+    l2_channel_t *pMySChannel      = NULL;
+    l2_handler_t *g_pSLogHandler   = &l2_handler_syslog;
+
+    fprintf(stdout, "Trying syslog channel handler...\n");
+
+    pMySChannel = l2_channel_create(g_pSLogHandler);
+    if (pMySChannel == NULL)
+        return 1;
+
+    /* Params "ident", <String>, "logopts", <LOG_?>, "facility", <LOG_?> */
+    /*        "priority", <LOG_?>, "maskpriority", <LOG_?>               */
+    iRet = l2_channel_configure(pMySChannel, "ident", L2_VONL2LIB,\
+        "logopts", (LOG_PID|LOG_CONS), "facility", LOG_USER, "priority",\
+        (LOG_CRIT|LOG_ALERT|LOG_NOTICE), "maskpriority", 0xFFFFFFFF);
+    if (iRet != L2_OK)
+        return 1;
+
+    iRet = l2_channel_open(pMySChannel);
+    if (iRet != L2_OK)
+        return 1;
+
+    /* Need to add n bytes to string length to allow for the text we add */
+    iMsgSize = strlen(pszArgs[L2_MESSAGEARG]) + strlen(L2_VONSYSLOGSTRING);
+    pszMsgIn = malloc(iMsgSize);
+    strcpy(pszMsgIn, pszArgs[L2_MESSAGEARG]);
+    strcat(pszMsgIn, L2_VONSYSLOGSTRING);
+    iRet = l2_channel_write(pMySChannel, pszMsgIn, iMsgSize);
+    if (iRet != L2_OK)
+        return 1;
+    free(pszMsgIn);
+
+    iRet = l2_channel_flush(pMySChannel);
+    if (iRet != L2_OK)
+        return 1;
+
+    iRet = l2_channel_close(pMySChannel);
+    if (iRet != L2_OK)
+        return 1;
+
+    iRet = l2_channel_destroy(pMySChannel);
+    if (iRet != L2_OK)
+        return 1;
+
+    return 0; /* All stages of execution completed successfully */
+}
+
+/*--------------------------------------------------------*/
 /* void tryfile(char *pszArgs[])                          */
 /* Test logic for the file channel handler                */
 /*--------------------------------------------------------*/
@@ -130,7 +189,7 @@
     if (pMyFChannel == NULL)
         return 1;
 
-    /* Params "path", <File path>, "append", <TRUE/FALSE>, "perm", <0xValue>, */
+    /* Params "path", <File path>, "append", <TRUE/FALSE>, "perm", <0xValue> */
     iRet = l2_channel_configure(pMyFChannel, "path", pszArgs[L2_FILEARG],\
         "append", TRUE, "perm", 0x755);
     if (iRet != L2_OK)
@@ -185,6 +244,12 @@
         exit(1);
     }
 
+    if (trysyslog(argv))
+    {
+        throwup("Syslog channel handler failed!\n");
+        exit(1);
+    }
+
     if (tryfile(argv))
     {
         throwup("File channel handler failed!\n");

CVSTrac 2.0.1