OSSP CVS Repository

ossp - Difference in ossp-pkg/fsl/fsl.c versions 1.2 and 1.3
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

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);

CVSTrac 2.0.1