From 5710b413963d2fde9d062127ed72672b8a58a07e Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Thu, 7 Jul 2011 08:22:40 +0200 Subject: milestone/[PARTWORK]: integrted script filter, but var access is missing --- grammar/rainerscript.h | 176 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 grammar/rainerscript.h (limited to 'grammar/rainerscript.h') diff --git a/grammar/rainerscript.h b/grammar/rainerscript.h new file mode 100644 index 00000000..bab7e602 --- /dev/null +++ b/grammar/rainerscript.h @@ -0,0 +1,176 @@ +#ifndef INC_UTILS_H +#define INC_UTILS_H +#include +#include + +enum cnfobjType { + CNFOBJ_ACTION, + CNFOBJ_GLOBAL, + CNFOBJ_INPUT, + CNFOBJ_MODULE, + CNFOBJ_INVALID = 0 +}; + +static inline char* +cnfobjType2str(enum cnfobjType ot) +{ + switch(ot) { + case CNFOBJ_ACTION: + return "action"; + break; + case CNFOBJ_GLOBAL: + return "global"; + break; + case CNFOBJ_INPUT: + return "input"; + break; + case CNFOBJ_MODULE: + return "module"; + break; + default:return "error: invalid cnfobjType"; + } +} + +enum cnfactType { CNFACT_V2, CNFACT_LEGACY }; + +struct cnfobj { + enum cnfobjType objType; + struct nvlst *nvlst; +}; + +struct nvlst { + struct nvlst *next; + es_str_t *name; + es_str_t *value; +}; + +struct cnfcfsyslinelst { + struct cnfcfsyslinelst *next; + char *line; +}; + +struct cnfactlst { + struct cnfactlst *next; + struct cnfcfsyslinelst *syslines; + enum cnfactType actType; + union { + struct nvlst *lst; + char *legActLine; + } data; +}; + +/* the following structures support expressions, and may (very much later + * be the sole foundation for the AST. + * + * nodetypes (list not yet complete) + * F - function + * N - number + * P - fparamlst + * R - rule + * S - string + * V - var + */ +enum cnfFiltType { CNFFILT_NONE, CNFFILT_PRI, CNFFILT_PROP, CNFFILT_SCRIPT }; +static inline char* +cnfFiltType2str(enum cnfFiltType filttype) +{ + switch(filttype) { + case CNFFILT_NONE: + return("filter:none"); + case CNFFILT_PRI: + return("filter:pri"); + case CNFFILT_PROP: + return("filter:prop"); + case CNFFILT_SCRIPT: + return("filter:script"); + } + return("error:invalid_filter_type"); /* should never be reached */ +} + + +struct cnfrule { + unsigned nodetype; + enum cnfFiltType filttype; + union { + char *s; + struct cnfexpr *expr; + } filt; + struct cnfactlst *actlst; +}; + +struct cnfexpr { + unsigned nodetype; + struct cnfexpr *l; + struct cnfexpr *r; +}; + +struct cnfnumval { + unsigned nodetype; + long long val; +}; + +struct cnfstringval { + unsigned nodetype; + es_str_t *estr; +}; + +struct cnfvar { + unsigned nodetype; + char *name; +}; + +struct cnffparamlst { + unsigned nodetype; /* P */ + struct cnffparamlst *next; + struct cnfexpr *expr; +}; + +struct cnffunc { + unsigned nodetype; + es_str_t *fname; + struct cnffparamlst *paramlst; +}; + +/* future extensions +struct x { + int nodetype; +}; +*/ + +/* the return value of an expresion evaluation */ +struct exprret { + union { + es_str_t *estr; + long long n; + } d; + char datatype; /* 'N' - number, 'S' - string */ +}; + + +void readConfFile(FILE *fp, es_str_t **str); +struct nvlst* nvlstNew(es_str_t *name, es_str_t *value); +void nvlstDestruct(struct nvlst *lst); +void nvlstPrint(struct nvlst *lst); +struct cnfobj* cnfobjNew(enum cnfobjType objType, struct nvlst *lst); +void cnfobjDestruct(struct cnfobj *o); +void cnfobjPrint(struct cnfobj *o); +struct cnfactlst* cnfactlstNew(enum cnfactType actType, struct nvlst *lst, char *actLine); +void cnfactlstDestruct(struct cnfactlst *actlst); +void cnfactlstPrint(struct cnfactlst *actlst); +struct cnfactlst* cnfactlstAddSysline(struct cnfactlst* actlst, char *line); +struct cnfactlst* cnfactlstReverse(struct cnfactlst *actlst); +struct cnfexpr* cnfexprNew(unsigned nodetype, struct cnfexpr *l, struct cnfexpr *r); +void cnfexprPrint(struct cnfexpr *expr, int indent); +void cnfexprEval(struct cnfexpr *expr, struct exprret *ret); +int cnfexprEvalBool(struct cnfexpr *expr); +struct cnfnumval* cnfnumvalNew(long long val); +struct cnfstringval* cnfstringvalNew(es_str_t *estr); +struct cnfrule * cnfruleNew(enum cnfFiltType filttype, struct cnfactlst *actlst); +void cnfrulePrint(struct cnfrule *rule); +struct cnfvar* cnfvarNew(char *name); +struct cnffunc * cnffuncNew(es_str_t *fname, struct cnffparamlst* paramlst); +struct cnffparamlst * cnffparamlstNew(struct cnfexpr *expr, struct cnffparamlst *next); + +/* debug helper */ +void cstrPrint(char *text, es_str_t *estr); +#endif -- cgit v1.2.3 From 8a9e0cc68e3314b02065dcd3424201f25f176dfb Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Thu, 7 Jul 2011 16:35:51 +0200 Subject: milestone/[PARTWORK]: obtaining msg vars integrated, "==" works for strings --- grammar/rainerscript.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'grammar/rainerscript.h') diff --git a/grammar/rainerscript.h b/grammar/rainerscript.h index bab7e602..8b5c36de 100644 --- a/grammar/rainerscript.h +++ b/grammar/rainerscript.h @@ -161,8 +161,8 @@ struct cnfactlst* cnfactlstAddSysline(struct cnfactlst* actlst, char *line); struct cnfactlst* cnfactlstReverse(struct cnfactlst *actlst); struct cnfexpr* cnfexprNew(unsigned nodetype, struct cnfexpr *l, struct cnfexpr *r); void cnfexprPrint(struct cnfexpr *expr, int indent); -void cnfexprEval(struct cnfexpr *expr, struct exprret *ret); -int cnfexprEvalBool(struct cnfexpr *expr); +void cnfexprEval(struct cnfexpr *expr, struct exprret *ret, void *pusr); +int cnfexprEvalBool(struct cnfexpr *expr, void *usrptr); struct cnfnumval* cnfnumvalNew(long long val); struct cnfstringval* cnfstringvalNew(es_str_t *estr); struct cnfrule * cnfruleNew(enum cnfFiltType filttype, struct cnfactlst *actlst); -- cgit v1.2.3 From f2ef6cd10699ab9f91b9e3e53726512cd290ea68 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Fri, 8 Jul 2011 19:00:23 +0200 Subject: optimized function representation --- grammar/rainerscript.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'grammar/rainerscript.h') diff --git a/grammar/rainerscript.h b/grammar/rainerscript.h index 8b5c36de..b7abf153 100644 --- a/grammar/rainerscript.h +++ b/grammar/rainerscript.h @@ -128,7 +128,9 @@ struct cnffparamlst { struct cnffunc { unsigned nodetype; es_str_t *fname; - struct cnffparamlst *paramlst; + unsigned short nParams; + unsigned short *fID; /* function ID for built-ins, 0 means use name */ + struct cnfexpr *expr[]; }; /* future extensions -- cgit v1.2.3 From f5e0bbe2d9d1d9594a01fc869392374d1a44afbe Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Sat, 9 Jul 2011 09:30:17 +0200 Subject: milestone/[PARTWORK]: implemented RainerScript functions --- grammar/rainerscript.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'grammar/rainerscript.h') diff --git a/grammar/rainerscript.h b/grammar/rainerscript.h index b7abf153..5d9eff7f 100644 --- a/grammar/rainerscript.h +++ b/grammar/rainerscript.h @@ -3,6 +3,13 @@ #include #include +#define CNFFUNC_MAX_ARGS 32 + /**< maximum number of arguments that any function can have (among + * others, this is used to size data structures). + */ + +extern int Debug; /* 1 if in debug mode, 0 otherwise -- to be enhanced */ + enum cnfobjType { CNFOBJ_ACTION, CNFOBJ_GLOBAL, @@ -125,11 +132,21 @@ struct cnffparamlst { struct cnfexpr *expr; }; +enum cnffuncid { + CNFFUNC_INVALID = 0, /**< defunct entry, do not use (should normally not be present) */ + CNFFUNC_NAME = 1, /**< use name to call function (for future use) */ + CNFFUNC_STRLEN, + CNFFUNC_GETENV, + CNFFUNC_TOLOWER, + CNFFUNC_CSTR, + CNFFUNC_CNUM +}; + struct cnffunc { unsigned nodetype; es_str_t *fname; unsigned short nParams; - unsigned short *fID; /* function ID for built-ins, 0 means use name */ + enum cnffuncid fID; /* function ID for built-ins, 0 means use name */ struct cnfexpr *expr[]; }; -- cgit v1.2.3 From 6ebf9ada253ffd8c88cbe84a46fd5aa3bfd58367 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Sat, 9 Jul 2011 18:00:29 +0200 Subject: milestone/[WORKS AGAIN!]: looks like the new conf format is integrated finally completed $IncludeConfig processing. --- grammar/rainerscript.h | 1 + 1 file changed, 1 insertion(+) (limited to 'grammar/rainerscript.h') diff --git a/grammar/rainerscript.h b/grammar/rainerscript.h index 5d9eff7f..75bb782d 100644 --- a/grammar/rainerscript.h +++ b/grammar/rainerscript.h @@ -189,6 +189,7 @@ void cnfrulePrint(struct cnfrule *rule); struct cnfvar* cnfvarNew(char *name); struct cnffunc * cnffuncNew(es_str_t *fname, struct cnffparamlst* paramlst); struct cnffparamlst * cnffparamlstNew(struct cnfexpr *expr, struct cnffparamlst *next); +int cnfDoInclude(char *name); /* debug helper */ void cstrPrint(char *text, es_str_t *estr); -- cgit v1.2.3 From 5e2b03a31c312e6cd6a7f4cb0bca1f062668dc52 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Sat, 9 Jul 2011 18:31:50 +0200 Subject: cleaup & emergency config system reactivated --- grammar/rainerscript.h | 1 + 1 file changed, 1 insertion(+) (limited to 'grammar/rainerscript.h') diff --git a/grammar/rainerscript.h b/grammar/rainerscript.h index 75bb782d..62c2aa50 100644 --- a/grammar/rainerscript.h +++ b/grammar/rainerscript.h @@ -166,6 +166,7 @@ struct exprret { }; +int cnfParseBuffer(char *buf, unsigned lenBuf); void readConfFile(FILE *fp, es_str_t **str); struct nvlst* nvlstNew(es_str_t *name, es_str_t *value); void nvlstDestruct(struct nvlst *lst); -- cgit v1.2.3