Index: ossp-pkg/fsl/fsl.c RCS File: /v/ossp/cvs/ossp-pkg/fsl/fsl.c,v rcsdiff -q -kk '-r1.2' '-r1.3' -u '/v/ossp/cvs/ossp-pkg/fsl/fsl.c,v' 2>/dev/null --- 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 #include #include +#include #include #include +#include +#include +#include /* standard include we re-implement */ #include +/* 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 -#include -#include -#include -#include /* strerror() */ -#include - -#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); Index: ossp-pkg/fsl/fsl.pod RCS File: /v/ossp/cvs/ossp-pkg/fsl/fsl.pod,v rcsdiff -q -kk '-r1.1' '-r1.2' -u '/v/ossp/cvs/ossp-pkg/fsl/fsl.pod,v' 2>/dev/null --- 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/I" given to the openlog(3) call. The configuration section contains an B 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 +in curly brackets and terminated with a semicolon. The B specification may contain $1, $2, ... variables which are filled in from the I regex parts enclosed in round brackets. Index: ossp-pkg/fsl/l2.sample.cfg RCS File: /v/ossp/cvs/ossp-pkg/fsl/Attic/l2.sample.cfg,v co -q -kk -p'1.1' '/v/ossp/cvs/ossp-pkg/fsl/Attic/l2.sample.cfg,v' | diff -u /dev/null - -L'ossp-pkg/fsl/l2.sample.cfg' 2>/dev/null --- ossp-pkg/fsl/l2.sample.cfg +++ - 2024-05-16 14:02:44.041217060 +0200 @@ -0,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