--- fsl.c 2002/07/16 14:59:53 1.6
+++ fsl.c 2002/07/16 15:59:44 1.7
@@ -108,6 +108,35 @@
{ 0, NULL }
};
+static struct {
+ int facility;
+ char *string;
+} facility2string[] = {
+ { LOG_AUTH, "auth" },
+ { LOG_AUTHPRIV, "authpriv" },
+ { LOG_CONSOLE, "console" },
+ { LOG_CRON, "cron" },
+ { LOG_DAEMON, "daemon" },
+ { LOG_FTP, "ftp" },
+ { LOG_KERN, "kern" },
+ { LOG_LPR, "lpr" },
+ { LOG_MAIL, "mail" },
+ { LOG_NEWS, "news" },
+ { LOG_SECURITY, "security" },
+ { LOG_SYSLOG, "syslog" },
+ { LOG_USER, "user" },
+ { LOG_UUCP, "uucp" },
+ { LOG_LOCAL0, "local0" },
+ { LOG_LOCAL1, "local1" },
+ { LOG_LOCAL2, "local2" },
+ { LOG_LOCAL3, "local3" },
+ { LOG_LOCAL4, "local4" },
+ { LOG_LOCAL5, "local5" },
+ { LOG_LOCAL6, "local6" },
+ { LOG_LOCAL7, "local7" },
+ { 0, NULL }
+};
+
/* internal context structure */
static struct {
FILE *log;
@@ -176,8 +205,8 @@
int rc;
buf_t buf;
fsl_rc_t rv;
- cfg_t *cfg = NULL;
- cfg_rc_t cfgrv = CFG_OK;
+ cfg_t *cfg;
+ cfg_rc_t cfgrv;
cfg_node_t *cfgseq;
cfg_node_t *cfgdir;
cfg_node_t *cfgarg;
@@ -187,11 +216,38 @@
char *argmatch;
char *argl2spec;
char *cp;
+ int i;
+ char *cpIdent;
+ char *cpFacility;
+ char *cpISF;
+#define OVECSIZE 30 //FIXME find a good place for this
+ int ovec[OVECSIZE];
+ const char **acpMatch;
-fprintf(stderr, "DEBUG: BEGIN ident=\"%s\", logopt=0x%.8lx, facility=0x%.8lx\n", ident, (unsigned long)logopt, (unsigned long)facility);
+ cfg = NULL;
buf.base = NULL;
buf.used = 0;
buf.size = 0;
+ cpISF = NULL;
+
+fprintf(stderr, "DEBUG: BEGIN ident=\"%s\", logopt=0x%.8lx, facility=0x%.8lx\n", ident, (unsigned long)logopt, (unsigned long)facility);
+
+ /* create IdentSlashFacility */
+ cpIdent = ident != NULL ? ident : "unknown";
+ cpFacility = "unknown";
+ for (i = 0; facility2string[i].string != NULL; i++) {
+ if (facility == facility2string[i].facility) {
+ cpFacility = facility2string[i].string;
+ break;
+ }
+ }
+ if ((cpISF = (char *)malloc(strlen(cpIdent) + 1 + strlen(cpFacility) + 1)) == NULL) {
+ fprintf(stderr, "ERROR: malloc() failed\n"); CU(1); }
+ cpISF[0] = '\0';
+ strcat(cpISF, cpIdent);
+ strcat(cpISF, "/");
+ strcat(cpISF, cpFacility);
+fprintf(stderr, "DEBUG: ISF=\"%s\"\n", cpISF);
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); }
@@ -276,21 +332,48 @@
/* process the directive using the three arguments found */
fprintf(stderr, "DEBUG: argident=%s, argmatch=%s, argl2spec=%s\n", argident, argmatch, argl2spec);
+ {
+ pcre *pcreRegex;
+ pcre_extra *pcreExtra;
+ const char *cpError;
+ int iError;
+ int nMatch;
+
+ /* compile regular expression into finite state machine and optimize */
+ if ((pcreRegex = pcre_compile(argmatch, PCRE_CASELESS, &cpError, &iError, NULL)) == NULL) {
+ fprintf(stderr, "ERROR: pcre_compile() failed with error %s (%d)\n", cpError, iError); CU(1); }
+ pcreExtra = pcre_study(pcreRegex, 0, &cpError);
+ if (cpError != NULL) {
+ fprintf(stderr, "ERROR: pcre_study() failed with error %s\n", cpError); CU(1); }
+
+ nMatch = pcre_exec(pcreRegex, pcreExtra, cpISF, strlen(cpISF), 0, 0, ovec, OVECSIZE);
+ fprintf(stderr, "DEBUG: nMatch=%d when \"%s\" is used against \"%s\"\n", nMatch, argmatch, cpISF);
+ if (nMatch >= 1) {
+ int i;
+ char *cp;
+ pcre_get_substring_list(cpISF, ovec, nMatch, &acpMatch);
+ if (acpMatch != NULL)
+ for (i = 0; i < nMatch; i++)
+ fprintf(stderr, "DEBUG: regex reference[%d]=\'%s\'\n", i, acpMatch[i] == NULL ? "(UNDEFINED)" : acpMatch[i]);
+ }
+ }
+
/* get right brother of current directive */
if ((cfgrv = cfg_node_get(cfg, cfgdir, CFG_NODE_ATTR_RBROTH, &cfgdir)) != CFG_OK) {
(void)cfg_error(cfg, cfgrv, &cp); fprintf(stderr, "ERROR: cfg_node_get(CFG_NODE_ATTR_RBROTH) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
}
-
-#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: *END*, 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);
+CUS:
+ if (cpISF != NULL)
+ free(cpISF);
+#if 0
+ if (cfg != NULL)
+ 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
return;
}
|