OSSP CVS Repository

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

Check-in Number: 2285
Date: 2002-Jul-16 15:20:33 (local)
2002-Jul-16 13:20:33 (UTC)
User:thl
Branch:
Comment: integration of lib_cfg including tree dump through traverse()
Tickets:
Inspections:
Files:
ossp-pkg/fsl/fsl.c      1.2 -> 1.3     104 inserted, 55 deleted
ossp-pkg/fsl/fsl.pod      1.1 -> 1.2     1 inserted, 2 deleted
ossp-pkg/fsl/l2.sample.cfg      added-> 1.1

ossp-pkg/fsl/fsl.c 1.2 -> 1.3

--- fsl.c        2002/07/11 15:43:15     1.2
+++ fsl.c        2002/07/16 13:20:33     1.3
@@ -35,12 +35,20 @@
 #include <errno.h>
 #include <string.h>
 #include <unistd.h>
+#include <fcntl.h>
 #include <time.h>
 #include <sys/time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>
 
 /* standard include we re-implement */
 #include <syslog.h>
 
+/* third party (linked in) */
+#include "l2.h"
+#include "cfg.h"
+
 /* default for the dedicated logfile */
 #ifndef LOGFILE
 #define LOGFILE "/tmp/syslog"
@@ -53,6 +61,36 @@
 #define LOG_PRI(p) ((p) & LOG_PRIMASK)
 #endif
 
+#include "config.h"
+#define FSL_PREFIX "l2."
+
+#define STMT(stuff) do { stuff } while (0)
+#define CU(returncode) STMT( rc = returncode; goto CUS; )
+#define VCU STMT( goto CUS; )
+
+typedef struct {
+    char   *base;
+    size_t  used;
+    size_t  size;
+} buf_t;
+
+/* general return codes */
+typedef enum {
+    FSL_OK = 0,               /* everything ok */
+    FSL_ERR_ARG,              /* invalid argument */
+    FSL_ERR_USE,              /* invalid use */
+    FSL_ERR_MEM,              /* no more memory available */
+    FSL_ERR_SYS               /* operating system error, see errno */
+    //FSL_ERR_FMT,              /* formatting error */
+    //FSL_ERR_INT,              /* internal error */
+    //FSL_ERR_SYN,              /* syntax error */
+} fsl_rc_t;
+
+fsl_rc_t readfileorallfiles(buf_t *, const char *);
+fsl_rc_t readfile          (buf_t *, const char *);
+fsl_rc_t readallfiles      (buf_t *);
+fsl_rc_t appendfiletobuffer(buf_t *, const char *);
+
 /* log level to string mapping */
 static struct {
     int level;
@@ -81,7 +119,7 @@
     NULL, LOGFILE, "unknown", 0, LOG_USER, 0xff
 };
 
-void openlog(const char *ident, int logopt, int facility)
+void FIXMEopenlog(const char *ident, int logopt, int facility)
 {
     /* remember parameters */
     ctx.ident    = ident;
@@ -101,6 +139,70 @@
     return;
 }
 
+void traverse(cfg_t *cfg, cfg_node_t *cfgnode)
+{
+    int rc;
+    cfg_node_t *cfgchld;
+    cfg_rc_t cfgrv;
+    char *cp;
+
+    fprintf(stderr, "DEBUG: diving\n");
+    while (cfgnode != NULL) {
+        if ((cfgrv = cfg_node_get(cfg, cfgnode, CFG_NODE_ATTR_TOKEN, &cp)) != CFG_OK) {
+            (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(T) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+        fprintf(stderr, "DEBUG: cfgnode=0x%.8lx, *cp=\"%s\"\n", (unsigned long)cfgnode, cp);
+        if ((cfgrv = cfg_node_get(cfg, cfgnode, CFG_NODE_ATTR_CHILD1, &cfgchld)) != CFG_OK) {
+            (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(C) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+        if (cfgchld != NULL)
+            traverse(cfg, cfgchld);
+        if ((cfgrv = cfg_node_get(cfg, cfgnode, CFG_NODE_ATTR_RBROTH, &cfgnode)) != CFG_OK) {
+            (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(R) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+    }
+    fprintf(stderr, "DEBUG: climbing\n");
+    CU(0);
+CUS:
+    return;
+}
+
+void openlog(const char *ident, int logopt, int facility)
+{
+    int rc;
+    buf_t buf;
+    fsl_rc_t rv;
+    cfg_t      *cfg     = NULL;
+    cfg_rc_t    cfgrv   = CFG_OK;
+    cfg_node_t *cfgroot;
+    char *cp;
+
+fprintf(stderr, "DEBUG: main(ident=\"%s\", logopt=0x%.8lx, facility=0x%.8lx)\n", ident, (unsigned long)logopt, (unsigned long)facility);
+    buf.base = NULL;
+    buf.used = 0;
+    buf.size = 0;
+
+    if ((cfgrv = cfg_create(&cfg)) != CFG_OK) {
+        (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_create() failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+
+    if ((rv = readfileorallfiles(&buf, "config.log")) != FSL_OK)
+        fprintf(stderr, "DEBUG: error#%d, system#%s(%d)\n", rv, strerror(errno), errno);
+
+    if ((cfgrv = cfg_import(cfg, NULL, CFG_FMT_CFG, buf.base, buf.size)) != CFG_OK) {
+        (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_import() failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+
+    if ((cfgrv = cfg_node_root(cfg, &cfgroot)) != CFG_OK) {
+        (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_root() failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+    traverse(cfg, cfgroot);
+#if 0
+    if ((cfgrv = cfg_destroy(cfg)) != CFG_OK) {
+        (void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_destroy() failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+#endif
+
+fprintf(stderr, "DEBUG: main() OK, buf.base=0x%.8lx, buf.used=%d, buf.size=%d\n", (unsigned long)buf.base, (int)buf.used, (int)buf.size);
+    CU(0);
+CUS:
+    FIXMEopenlog(ident, logopt, facility);
+    return;
+}
+
 void closelog(void)
 {
     /* close open logfile*/
@@ -239,60 +341,6 @@
     return;
 }
 
-/* ------------------------------------------------------------------ */
-
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdio.h> /* strerror() */
-#include <dirent.h>
-
-#include "config.h"
-#define FSL_PREFIX "l2."
-
-#define STMT(stuff) do { stuff } while (0)
-#define CU(returncode) STMT( rc = returncode; goto CUS; )
-#define VCU STMT( goto CUS; )
-
-typedef struct {
-    char *base;
-    int   used;
-    int   size;
-} buf_t;
-
-/* general return codes */
-typedef enum {
-    FSL_OK = 0,               /* everything ok */
-    FSL_ERR_ARG,              /* invalid argument */
-    FSL_ERR_USE,              /* invalid use */
-    FSL_ERR_MEM,              /* no more memory available */
-    FSL_ERR_SYS               /* operating system error, see errno */
-    //FSL_ERR_FMT,              /* formatting error */
-    //FSL_ERR_INT,              /* internal error */
-    //FSL_ERR_SYN,              /* syntax error */
-} fsl_rc_t;
-
-fsl_rc_t readfileorallfiles(buf_t *, const char *);
-fsl_rc_t readfile          (buf_t *, const char *);
-fsl_rc_t readallfiles      (buf_t *);
-fsl_rc_t appendfiletobuffer(buf_t *, const char *);
-
-int main(int argc, char **argv)
-{
-    buf_t buf;
-    fsl_rc_t rv;
-
-    buf.base = NULL;
-    buf.used = 0;
-    buf.size = 0;
-
-    if ((rv = readfileorallfiles(&buf, "config.log")) != FSL_OK)
-        fprintf(stderr, "DEBUG: error#%d, system#%s(%d)\n", rv, strerror(errno), errno);
-
-    return 0;
-}
-
 fsl_rc_t readfileorallfiles(buf_t *buffer, const char *ident)
 {
     fsl_rc_t rv;
@@ -379,6 +427,7 @@
 
     if (filename == NULL || buffer == NULL)
         CU(FSL_ERR_ARG);
+fprintf(stderr, "DEBUG: appendfiletobuffer(..., %s)\n", filename);
 
     if ((fd = open(filename, O_RDONLY)) == -1)
         CU(FSL_ERR_SYS);


ossp-pkg/fsl/fsl.pod 1.1 -> 1.2

--- fsl.pod      2002/07/09 09:42:09     1.1
+++ fsl.pod      2002/07/16 13:20:33     1.2
@@ -74,8 +74,7 @@
 concatenated from "I<ident>/I<facility>" given to the openlog(3) call.
 
 The configuration section contains an B<OSSP l2> specification enclosed
-in curly brackets where the closing bracket must be placed on the
-beginning of a line and terminated with a semicolon. The B<OSSP l2>
+in curly brackets and terminated with a semicolon. The B<OSSP l2>
 specification may contain $1, $2, ... variables which are filled in from
 the I<match> regex parts enclosed in round brackets.
 


ossp-pkg/fsl/l2.sample.cfg -> 1.1

*** /dev/null    Mon Apr 29 18:22:10 2024
--- -    Mon Apr 29 18:26:51 2024
***************
*** 0 ****
--- 1,27 ----
+ 
+     #
+     # SAMPLE FAKESYSLOG CONFIGURATION FILE
+     #
+ 
+ ident sendmail/.* q{
+     debug:
+         prefix(prefix="%%b %%d %%H:%%M:%%S <%%L> $1 [%%P]: ",
+         timezone=local)
+         -> file(path="sendmail.debug.log", append=0,perm=432)
+     };
+ 
+ ident mail/.* q{
+     error:
+         prefix(prefix="%%b %%d %%H:%%M:%%S <%%L> $1 [%%P]: ",
+         timezone=local)
+         -> file(path="mail.error.log", append=0,perm=432)
+     };
+ 
+ ident news/.* q{
+     warning:
+         prefix(prefix="%%b %%d %%H:%%M:%%S <%%L> $1 [%%P]: ",
+         timezone=local)
+         -> file(path="news.warning.log", append=0,perm=432)
+     };
+ 
+ # have a nice day

CVSTrac 2.0.1