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.
This commit is contained in:
Markus Makela
2016-02-24 10:42:31 +02:00
parent cb2e3b898e
commit 57af3e3e24
4 changed files with 54 additions and 63 deletions

View File

@ -716,7 +716,7 @@ void add_users(char* rule, FW_INSTANCE* instance)
* @param instance Filter instance * @param instance Filter instance
* @param user User name * @param user User name
* @param rulelist List of rules to apply * @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 * @return True of the rules were successfully applied. False if memory allocation
* fails * fails
*/ */
@ -724,7 +724,7 @@ static bool apply_rule_to_user(FW_INSTANCE *instance, char *username,
RULELIST *rulelist, enum match_type type) RULELIST *rulelist, enum match_type type)
{ {
USER* user; 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) if ((user = (USER*) hashtable_fetch(instance->htable, username)) == NULL)
{ {
/**New user*/ /**New user*/
@ -748,15 +748,15 @@ static bool apply_rule_to_user(FW_INSTANCE *instance, char *username,
switch (type) switch (type)
{ {
case MATCH_ANY: case FWTOK_MATCH_ANY:
tail->next = user->rules_or; tail->next = user->rules_or;
user->rules_or = tl; user->rules_or = tl;
break; break;
case MATCH_STRICT_ALL: case FWTOK_MATCH_STRICT_ALL:
tail->next = user->rules_and; tail->next = user->rules_and;
user->rules_strict_and = tl; user->rules_strict_and = tl;
break; break;
case MATCH_ALL: case FWTOK_MATCH_ALL:
tail->next = user->rules_and; tail->next = user->rules_and;
user->rules_and = tl; user->rules_and = tl;
break; break;
@ -816,15 +816,15 @@ bool link_rules(char* orig, FW_INSTANCE* instance)
} }
if (strcmp(tok, "any") == 0) if (strcmp(tok, "any") == 0)
{ {
type = MATCH_ANY; type = FWTOK_MATCH_ANY;
} }
else if (strcmp(tok, "all") == 0) else if (strcmp(tok, "all") == 0)
{ {
type = MATCH_ALL; type = FWTOK_MATCH_ALL;
} }
else if (strcmp(tok, "strict_all") == 0) else if (strcmp(tok, "strict_all") == 0)
{ {
type = MATCH_STRICT_ALL; type = FWTOK_MATCH_STRICT_ALL;
} }
else else
{ {
@ -1562,6 +1562,13 @@ static bool process_user_templates(FW_INSTANCE *instance, user_template_t *templ
RULE* rules) RULE* rules)
{ {
bool rval = true; bool rval = true;
if (templates == NULL)
{
MXS_ERROR("No user definitions found in the rule file.");
rval = false;
}
while (templates) while (templates)
{ {
USER *user = hashtable_fetch(instance->htable, templates->name); 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) switch (templates->type)
{ {
case MATCH_ANY: case FWTOK_MATCH_ANY:
tail->next = user->rules_or; tail->next = user->rules_or;
user->rules_or = foundrules; user->rules_or = foundrules;
break; break;
case MATCH_ALL: case FWTOK_MATCH_ALL:
tail->next = user->rules_and; tail->next = user->rules_and;
user->rules_and = foundrules; user->rules_and = foundrules;
break; break;
case MATCH_STRICT_ALL: case FWTOK_MATCH_STRICT_ALL:
tail->next = user->rules_strict_and; tail->next = user->rules_strict_and;
user->rules_strict_and = foundrules; user->rules_strict_and = foundrules;
break; break;
@ -1632,12 +1639,6 @@ static bool process_user_templates(FW_INSTANCE *instance, user_template_t *templ
templates = templates->next; templates = templates->next;
} }
if (templates == NULL)
{
MXS_ERROR("No user definitions found in the rule file.");
rval = false;
}
return rval; return rval;
} }

View File

@ -28,16 +28,12 @@
#include <stdbool.h> #include <stdbool.h>
#ifndef YYSTYPE
#define YYSTYPE DBFW_YYSTYPE
#endif
/** Matching type */ /** Matching type */
enum match_type enum match_type
{ {
MATCH_ANY, FWTOK_MATCH_ANY,
MATCH_ALL, FWTOK_MATCH_ALL,
MATCH_STRICT_ALL FWTOK_MATCH_STRICT_ALL
}; };
/** Prototype for the parser's error handler */ /** Prototype for the parser's error handler */

View File

@ -30,19 +30,18 @@
/** We need a reentrant scanner so no global variables are used */ /** We need a reentrant scanner so no global variables are used */
%define api.pure full %define api.pure full
/** Verbose errors help figure out what went wrong */ /** Prefix all functions */
%define parse.error verbose %name-prefix "dbfw_yy"
%define api.token.prefix {FWTOK_}
%define api.prefix {dbfw_yy}
/** The pure parser requires one extra parameter */ /** The pure parser requires one extra parameter */
%param {void* scanner} %parse-param {void* scanner}
%lex-param {void* scanner}
/** Terminal symbols */ /** Terminal symbols */
%token RULE <strval>RULENAME USERS <strval>USER RULES MATCH ANY ALL STRICT_ALL DENY %token FWTOK_RULE <strval>FWTOK_RULENAME FWTOK_USERS <strval>FWTOK_USER FWTOK_RULES FWTOK_MATCH FWTOK_ANY FWTOK_ALL FWTOK_STRICT_ALL FWTOK_DENY
%token WILDCARD COLUMNS REGEX LIMIT_QUERIES WHERE_CLAUSE AT_TIMES ON_QUERIES %token FWTOK_WILDCARD FWTOK_COLUMNS FWTOK_REGEX FWTOK_LIMIT_QUERIES FWTOK_WHERE_CLAUSE FWTOK_AT_TIMES FWTOK_ON_QUERIES
%token <strval>SQLOP COMMENT <intval>INT <floatval>FLOAT PIPE <strval>TIME %token <strval>FWTOK_SQLOP FWTOK_COMMENT <intval>FWTOK_INT <floatval>FWTOK_FLOAT FWTOK_PIPE <strval>FWTOK_TIME
%token <strval>BTSTR <strval>QUOTEDSTR <strval>STR %token <strval>FWTOK_BTSTR <strval>FWTOK_QUOTEDSTR <strval>FWTOK_STR
/** Non-terminal symbols */ /** Non-terminal symbols */
%type <strval>rulename %type <strval>rulename
@ -60,11 +59,11 @@ line:
'\n' '\n'
| rule '\n' | rule '\n'
| user '\n' | user '\n'
| COMMENT '\n' | FWTOK_COMMENT '\n'
; ;
rule: rule:
RULE rulename {if (!create_rule(scanner, $2)){YYERROR;}} DENY ruleparams FWTOK_RULE rulename {if (!create_rule(scanner, $2)){YYERROR;}} FWTOK_DENY ruleparams
; ;
ruleparams: ruleparams:
@ -75,18 +74,18 @@ ruleparams:
; ;
rulename: rulename:
RULENAME FWTOK_RULENAME
| STR | FWTOK_STR
; ;
user: user:
USERS userlist MATCH cond RULES namelist FWTOK_USERS userlist FWTOK_MATCH cond FWTOK_RULES namelist
{if (!create_user_templates(scanner)){YYERROR;}} {if (!create_user_templates(scanner)){YYERROR;}}
; ;
userlist: userlist:
USER {if (!add_active_user(scanner, $1)){YYERROR;}} FWTOK_USER {if (!add_active_user(scanner, $1)){YYERROR;}}
| userlist USER {if (!add_active_user(scanner, $2)){YYERROR;}} | userlist FWTOK_USER {if (!add_active_user(scanner, $2)){YYERROR;}}
; ;
namelist: namelist:
@ -95,38 +94,38 @@ namelist:
; ;
cond: cond:
ANY {set_matching_mode(scanner, MATCH_ANY);} FWTOK_ANY {set_matching_mode(scanner, FWTOK_MATCH_ANY);}
| ALL {set_matching_mode(scanner, MATCH_ALL);} | FWTOK_ALL {set_matching_mode(scanner, FWTOK_MATCH_ALL);}
| STRICT_ALL {set_matching_mode(scanner, MATCH_STRICT_ALL);} | FWTOK_STRICT_ALL {set_matching_mode(scanner, FWTOK_MATCH_STRICT_ALL);}
; ;
mandatory: mandatory:
WILDCARD {define_wildcard_rule(scanner);} FWTOK_WILDCARD {define_wildcard_rule(scanner);}
| WHERE_CLAUSE {define_where_clause_rule(scanner);} | FWTOK_WHERE_CLAUSE {define_where_clause_rule(scanner);}
| LIMIT_QUERIES INT INT INT | FWTOK_LIMIT_QUERIES FWTOK_INT FWTOK_INT FWTOK_INT
{if (!define_limit_queries_rule(scanner, $2, $3, $4)){YYERROR;}} {if (!define_limit_queries_rule(scanner, $2, $3, $4)){YYERROR;}}
| REGEX QUOTEDSTR {if (!define_regex_rule(scanner, $2)){YYERROR;}} | FWTOK_REGEX FWTOK_QUOTEDSTR {if (!define_regex_rule(scanner, $2)){YYERROR;}}
| COLUMNS columnlist | FWTOK_COLUMNS columnlist
; ;
columnlist: columnlist:
BTSTR {if (!define_columns_rule(scanner, $1)){YYERROR;}} FWTOK_BTSTR {if (!define_columns_rule(scanner, $1)){YYERROR;}}
| STR {if (!define_columns_rule(scanner, $1)){YYERROR;}} | FWTOK_STR {if (!define_columns_rule(scanner, $1)){YYERROR;}}
| columnlist BTSTR {if (!define_columns_rule(scanner, $2)){YYERROR;}} | columnlist FWTOK_BTSTR {if (!define_columns_rule(scanner, $2)){YYERROR;}}
| columnlist STR {if (!define_columns_rule(scanner, $2)){YYERROR;}} | columnlist FWTOK_STR {if (!define_columns_rule(scanner, $2)){YYERROR;}}
; ;
optional: optional:
AT_TIMES timelist FWTOK_AT_TIMES timelist
| ON_QUERIES orlist | FWTOK_ON_QUERIES orlist
; ;
timelist: timelist:
TIME {if (!add_at_times_rule(scanner, $1)){YYERROR;}} FWTOK_TIME {if (!add_at_times_rule(scanner, $1)){YYERROR;}}
| timelist TIME {if (!add_at_times_rule(scanner, $2)){YYERROR;}} | timelist FWTOK_TIME {if (!add_at_times_rule(scanner, $2)){YYERROR;}}
; ;
orlist: orlist:
SQLOP {add_on_queries_rule(scanner, $1);} FWTOK_SQLOP {add_on_queries_rule(scanner, $1);}
| orlist PIPE SQLOP {add_on_queries_rule(scanner, $3);} | orlist FWTOK_PIPE FWTOK_SQLOP {add_on_queries_rule(scanner, $3);}
; ;

View File

@ -19,11 +19,6 @@
%{ %{
#include <ruleparser.yy.h> #include <ruleparser.yy.h>
/** 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" %option reentrant noyywrap bison-bridge prefix="dbfw_yy"