From 57af3e3e24d5c87a2427f61b647a07b67b5826ac Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Wed, 24 Feb 2016 10:42:31 +0200 Subject: [PATCH] Added support for older Bison versions The older versions of Bison use the deprecated versions of various options. The automatic prefixing of tokens is not present in older versions so to accommodate for this, all tokens were manually prefixed. --- server/modules/filter/dbfwfilter/dbfwfilter.c | 35 +++++----- server/modules/filter/dbfwfilter/dbfwfilter.h | 10 +-- server/modules/filter/dbfwfilter/ruleparser.y | 67 +++++++++---------- server/modules/filter/dbfwfilter/token.l | 5 -- 4 files changed, 54 insertions(+), 63 deletions(-) diff --git a/server/modules/filter/dbfwfilter/dbfwfilter.c b/server/modules/filter/dbfwfilter/dbfwfilter.c index 087653381..647aba3fe 100644 --- a/server/modules/filter/dbfwfilter/dbfwfilter.c +++ b/server/modules/filter/dbfwfilter/dbfwfilter.c @@ -716,7 +716,7 @@ void add_users(char* rule, FW_INSTANCE* instance) * @param instance Filter instance * @param user User name * @param rulelist List of rules to apply - * @param type Matching type, one of MATCH_ANY, MATCH_ALL or MATCH_STRICT_ALL + * @param type Matching type, one of FWTOK_MATCH_ANY, FWTOK_MATCH_ALL or FWTOK_MATCH_STRICT_ALL * @return True of the rules were successfully applied. False if memory allocation * fails */ @@ -724,7 +724,7 @@ static bool apply_rule_to_user(FW_INSTANCE *instance, char *username, RULELIST *rulelist, enum match_type type) { USER* user; - ss_dassert(type == MATCH_ANY || type == MATCH_STRICT_ALL || type == MATCH_ALL); + ss_dassert(type == FWTOK_MATCH_ANY || type == FWTOK_MATCH_STRICT_ALL || type == FWTOK_MATCH_ALL); if ((user = (USER*) hashtable_fetch(instance->htable, username)) == NULL) { /**New user*/ @@ -748,15 +748,15 @@ static bool apply_rule_to_user(FW_INSTANCE *instance, char *username, switch (type) { - case MATCH_ANY: + case FWTOK_MATCH_ANY: tail->next = user->rules_or; user->rules_or = tl; break; - case MATCH_STRICT_ALL: + case FWTOK_MATCH_STRICT_ALL: tail->next = user->rules_and; user->rules_strict_and = tl; break; - case MATCH_ALL: + case FWTOK_MATCH_ALL: tail->next = user->rules_and; user->rules_and = tl; break; @@ -816,15 +816,15 @@ bool link_rules(char* orig, FW_INSTANCE* instance) } if (strcmp(tok, "any") == 0) { - type = MATCH_ANY; + type = FWTOK_MATCH_ANY; } else if (strcmp(tok, "all") == 0) { - type = MATCH_ALL; + type = FWTOK_MATCH_ALL; } else if (strcmp(tok, "strict_all") == 0) { - type = MATCH_STRICT_ALL; + type = FWTOK_MATCH_STRICT_ALL; } else { @@ -1562,6 +1562,13 @@ static bool process_user_templates(FW_INSTANCE *instance, user_template_t *templ RULE* rules) { bool rval = true; + + if (templates == NULL) + { + MXS_ERROR("No user definitions found in the rule file."); + rval = false; + } + while (templates) { USER *user = hashtable_fetch(instance->htable, templates->name); @@ -1607,17 +1614,17 @@ static bool process_user_templates(FW_INSTANCE *instance, user_template_t *templ switch (templates->type) { - case MATCH_ANY: + case FWTOK_MATCH_ANY: tail->next = user->rules_or; user->rules_or = foundrules; break; - case MATCH_ALL: + case FWTOK_MATCH_ALL: tail->next = user->rules_and; user->rules_and = foundrules; break; - case MATCH_STRICT_ALL: + case FWTOK_MATCH_STRICT_ALL: tail->next = user->rules_strict_and; user->rules_strict_and = foundrules; break; @@ -1632,12 +1639,6 @@ static bool process_user_templates(FW_INSTANCE *instance, user_template_t *templ templates = templates->next; } - if (templates == NULL) - { - MXS_ERROR("No user definitions found in the rule file."); - rval = false; - } - return rval; } diff --git a/server/modules/filter/dbfwfilter/dbfwfilter.h b/server/modules/filter/dbfwfilter/dbfwfilter.h index 960d478df..e307fa06b 100644 --- a/server/modules/filter/dbfwfilter/dbfwfilter.h +++ b/server/modules/filter/dbfwfilter/dbfwfilter.h @@ -28,16 +28,12 @@ #include -#ifndef YYSTYPE -#define YYSTYPE DBFW_YYSTYPE -#endif - /** Matching type */ enum match_type { - MATCH_ANY, - MATCH_ALL, - MATCH_STRICT_ALL + FWTOK_MATCH_ANY, + FWTOK_MATCH_ALL, + FWTOK_MATCH_STRICT_ALL }; /** Prototype for the parser's error handler */ diff --git a/server/modules/filter/dbfwfilter/ruleparser.y b/server/modules/filter/dbfwfilter/ruleparser.y index e8accb017..f79074ef0 100644 --- a/server/modules/filter/dbfwfilter/ruleparser.y +++ b/server/modules/filter/dbfwfilter/ruleparser.y @@ -30,19 +30,18 @@ /** We need a reentrant scanner so no global variables are used */ %define api.pure full -/** Verbose errors help figure out what went wrong */ -%define parse.error verbose +/** Prefix all functions */ +%name-prefix "dbfw_yy" -%define api.token.prefix {FWTOK_} -%define api.prefix {dbfw_yy} /** The pure parser requires one extra parameter */ -%param {void* scanner} +%parse-param {void* scanner} +%lex-param {void* scanner} /** Terminal symbols */ -%token RULE RULENAME USERS USER RULES MATCH ANY ALL STRICT_ALL DENY -%token WILDCARD COLUMNS REGEX LIMIT_QUERIES WHERE_CLAUSE AT_TIMES ON_QUERIES -%token SQLOP COMMENT INT FLOAT PIPE TIME -%token BTSTR QUOTEDSTR STR +%token FWTOK_RULE FWTOK_RULENAME FWTOK_USERS FWTOK_USER FWTOK_RULES FWTOK_MATCH FWTOK_ANY FWTOK_ALL FWTOK_STRICT_ALL FWTOK_DENY +%token FWTOK_WILDCARD FWTOK_COLUMNS FWTOK_REGEX FWTOK_LIMIT_QUERIES FWTOK_WHERE_CLAUSE FWTOK_AT_TIMES FWTOK_ON_QUERIES +%token FWTOK_SQLOP FWTOK_COMMENT FWTOK_INT FWTOK_FLOAT FWTOK_PIPE FWTOK_TIME +%token FWTOK_BTSTR FWTOK_QUOTEDSTR FWTOK_STR /** Non-terminal symbols */ %type rulename @@ -60,11 +59,11 @@ line: '\n' | rule '\n' | user '\n' - | COMMENT '\n' + | FWTOK_COMMENT '\n' ; rule: - RULE rulename {if (!create_rule(scanner, $2)){YYERROR;}} DENY ruleparams + FWTOK_RULE rulename {if (!create_rule(scanner, $2)){YYERROR;}} FWTOK_DENY ruleparams ; ruleparams: @@ -75,18 +74,18 @@ ruleparams: ; rulename: - RULENAME - | STR + FWTOK_RULENAME + | FWTOK_STR ; user: - USERS userlist MATCH cond RULES namelist + FWTOK_USERS userlist FWTOK_MATCH cond FWTOK_RULES namelist {if (!create_user_templates(scanner)){YYERROR;}} ; userlist: - USER {if (!add_active_user(scanner, $1)){YYERROR;}} - | userlist USER {if (!add_active_user(scanner, $2)){YYERROR;}} + FWTOK_USER {if (!add_active_user(scanner, $1)){YYERROR;}} + | userlist FWTOK_USER {if (!add_active_user(scanner, $2)){YYERROR;}} ; namelist: @@ -95,38 +94,38 @@ namelist: ; cond: - ANY {set_matching_mode(scanner, MATCH_ANY);} - | ALL {set_matching_mode(scanner, MATCH_ALL);} - | STRICT_ALL {set_matching_mode(scanner, MATCH_STRICT_ALL);} + FWTOK_ANY {set_matching_mode(scanner, FWTOK_MATCH_ANY);} + | FWTOK_ALL {set_matching_mode(scanner, FWTOK_MATCH_ALL);} + | FWTOK_STRICT_ALL {set_matching_mode(scanner, FWTOK_MATCH_STRICT_ALL);} ; mandatory: - WILDCARD {define_wildcard_rule(scanner);} - | WHERE_CLAUSE {define_where_clause_rule(scanner);} - | LIMIT_QUERIES INT INT INT + FWTOK_WILDCARD {define_wildcard_rule(scanner);} + | FWTOK_WHERE_CLAUSE {define_where_clause_rule(scanner);} + | FWTOK_LIMIT_QUERIES FWTOK_INT FWTOK_INT FWTOK_INT {if (!define_limit_queries_rule(scanner, $2, $3, $4)){YYERROR;}} - | REGEX QUOTEDSTR {if (!define_regex_rule(scanner, $2)){YYERROR;}} - | COLUMNS columnlist + | FWTOK_REGEX FWTOK_QUOTEDSTR {if (!define_regex_rule(scanner, $2)){YYERROR;}} + | FWTOK_COLUMNS columnlist ; columnlist: - BTSTR {if (!define_columns_rule(scanner, $1)){YYERROR;}} - | STR {if (!define_columns_rule(scanner, $1)){YYERROR;}} - | columnlist BTSTR {if (!define_columns_rule(scanner, $2)){YYERROR;}} - | columnlist STR {if (!define_columns_rule(scanner, $2)){YYERROR;}} + FWTOK_BTSTR {if (!define_columns_rule(scanner, $1)){YYERROR;}} + | FWTOK_STR {if (!define_columns_rule(scanner, $1)){YYERROR;}} + | columnlist FWTOK_BTSTR {if (!define_columns_rule(scanner, $2)){YYERROR;}} + | columnlist FWTOK_STR {if (!define_columns_rule(scanner, $2)){YYERROR;}} ; optional: - AT_TIMES timelist - | ON_QUERIES orlist + FWTOK_AT_TIMES timelist + | FWTOK_ON_QUERIES orlist ; timelist: - TIME {if (!add_at_times_rule(scanner, $1)){YYERROR;}} - | timelist TIME {if (!add_at_times_rule(scanner, $2)){YYERROR;}} + FWTOK_TIME {if (!add_at_times_rule(scanner, $1)){YYERROR;}} + | timelist FWTOK_TIME {if (!add_at_times_rule(scanner, $2)){YYERROR;}} ; orlist: - SQLOP {add_on_queries_rule(scanner, $1);} - | orlist PIPE SQLOP {add_on_queries_rule(scanner, $3);} + FWTOK_SQLOP {add_on_queries_rule(scanner, $1);} + | orlist FWTOK_PIPE FWTOK_SQLOP {add_on_queries_rule(scanner, $3);} ; diff --git a/server/modules/filter/dbfwfilter/token.l b/server/modules/filter/dbfwfilter/token.l index a2099da64..fd0f92d0f 100644 --- a/server/modules/filter/dbfwfilter/token.l +++ b/server/modules/filter/dbfwfilter/token.l @@ -19,11 +19,6 @@ %{ #include -/** The tokenizer needs this declared in order to avoid naming conflicts */ -#ifndef YYSTYPE -#define YYSTYPE DBFW_YYSTYPE -#endif - %} %option reentrant noyywrap bison-bridge prefix="dbfw_yy"