53 |
static void rc_stmt_list_destroy(RC_STMT *); |
static void rc_stmt_list_destroy(RC_STMT *); |
54 |
static void rc_stmt_print(RC_STMT *, int); |
static void rc_stmt_print(RC_STMT *, int); |
55 |
static int reg_modifier_add(int *, char *); |
static int reg_modifier_add(int *, char *); |
56 |
|
static int check_kw(char *ident); |
57 |
|
static int is_prog_allowed(); |
58 |
|
|
59 |
static RC_SECTION *rc_section; |
static RC_SECTION *rc_section; |
60 |
static int debug_level; |
static int debug_level; |
61 |
static int error_count; |
static int error_count; |
62 |
static int def_regex_modifier = R_POSIX; |
static int def_regex_modifier = R_POSIX; |
63 |
|
static struct rc_secdef *rc_secdef; |
64 |
%} |
%} |
65 |
|
|
66 |
%union { |
%union { |
142 |
begin : T_BEGIN { verbatim(); } string EOL |
begin : T_BEGIN { verbatim(); } string EOL |
143 |
{ |
{ |
144 |
$$ = $3; |
$$ = $3; |
145 |
|
rc_secdef = anubis_find_section($3); |
146 |
} |
} |
147 |
| D_BEGIN EOL |
| D_BEGIN EOL |
148 |
|
{ |
149 |
|
rc_secdef = anubis_find_section($1); |
150 |
|
} |
151 |
; |
; |
152 |
|
|
153 |
end : T_END EOL |
end : T_END EOL |
183 |
|
|
184 |
asgn_stmt: keyword meq { verbatim(); } arglist |
asgn_stmt: keyword meq { verbatim(); } arglist |
185 |
{ |
{ |
186 |
|
if (!check_kw($1)) { |
187 |
|
yyerror(_("unknown keyword")); |
188 |
|
YYERROR; |
189 |
|
} |
190 |
|
|
191 |
$$ = rc_stmt_create(rc_stmt_asgn); |
$$ = rc_stmt_create(rc_stmt_asgn); |
192 |
$$->v.asgn.lhs = $1; |
$$->v.asgn.lhs = $1; |
193 |
$$->v.asgn.rhs = $4; |
$$->v.asgn.rhs = $4; |
271 |
$$.part = HEADER; |
$$.part = HEADER; |
272 |
$$.key = NULL; |
$$.key = NULL; |
273 |
$$.string = $2; |
$$.string = $2; |
274 |
} |
} |
275 |
; |
; |
276 |
|
|
277 |
opt_key : /* empty */ |
opt_key : /* empty */ |
363 |
; |
; |
364 |
|
|
365 |
if : IF |
if : IF |
366 |
|
{ |
367 |
|
if (!is_prog_allowed()) |
368 |
|
YYERROR; |
369 |
|
} |
370 |
; |
; |
371 |
|
|
372 |
fi : FI |
fi : FI |
383 |
} |
} |
384 |
; |
; |
385 |
|
|
386 |
rule_start: RULE opt_modlist string |
rule_start: rule opt_modlist string |
387 |
{ |
{ |
388 |
$$ = rc_node_create(rc_node_expr); |
$$ = rc_node_create(rc_node_expr); |
389 |
$$->v.expr.part = HEADER; |
$$->v.expr.part = HEADER; |
393 |
} |
} |
394 |
; |
; |
395 |
|
|
396 |
|
rule : RULE |
397 |
|
{ |
398 |
|
if (!is_prog_allowed()) |
399 |
|
YYERROR; |
400 |
|
} |
401 |
|
; |
402 |
|
|
403 |
string : STRING |
string : STRING |
404 |
| IDENT |
| IDENT |
405 |
; |
; |
406 |
|
|
407 |
inst_stmt: STOP |
inst_stmt: STOP |
408 |
{ |
{ |
409 |
|
if (!is_prog_allowed()) |
410 |
|
YYERROR; |
411 |
$$ = rc_stmt_create(rc_stmt_inst); |
$$ = rc_stmt_create(rc_stmt_inst); |
412 |
$$->v.inst.opcode = inst_stop; |
$$->v.inst.opcode = inst_stop; |
413 |
$$->v.inst.part = NIL; |
$$->v.inst.part = NIL; |
417 |
} |
} |
418 |
| CALL string |
| CALL string |
419 |
{ |
{ |
420 |
|
if (!is_prog_allowed()) |
421 |
|
YYERROR; |
422 |
$$ = rc_stmt_create(rc_stmt_inst); |
$$ = rc_stmt_create(rc_stmt_inst); |
423 |
$$->v.inst.opcode = inst_call; |
$$->v.inst.opcode = inst_call; |
424 |
$$->v.inst.key = NULL; |
$$->v.inst.key = NULL; |
428 |
} |
} |
429 |
| ADD s_msgpart string |
| ADD s_msgpart string |
430 |
{ |
{ |
431 |
|
if (!is_prog_allowed()) |
432 |
|
YYERROR; |
433 |
$$ = rc_stmt_create(rc_stmt_inst); |
$$ = rc_stmt_create(rc_stmt_inst); |
434 |
$$->v.inst.opcode = inst_add; |
$$->v.inst.opcode = inst_add; |
435 |
$$->v.inst.part = $2.part; |
$$->v.inst.part = $2.part; |
439 |
} |
} |
440 |
| REMOVE r_msgpart |
| REMOVE r_msgpart |
441 |
{ |
{ |
442 |
|
if (!is_prog_allowed()) |
443 |
|
YYERROR; |
444 |
$$ = rc_stmt_create(rc_stmt_inst); |
$$ = rc_stmt_create(rc_stmt_inst); |
445 |
$$->v.inst.opcode = inst_remove; |
$$->v.inst.opcode = inst_remove; |
446 |
$$->v.inst.part = $2.part; |
$$->v.inst.part = $2.part; |
450 |
} |
} |
451 |
| MODIFY r_msgpart string_key string |
| MODIFY r_msgpart string_key string |
452 |
{ |
{ |
453 |
|
if (!is_prog_allowed()) |
454 |
|
YYERROR; |
455 |
$$ = rc_stmt_create(rc_stmt_inst); |
$$ = rc_stmt_create(rc_stmt_inst); |
456 |
$$->v.inst.opcode = inst_modify; |
$$->v.inst.opcode = inst_modify; |
457 |
$$->v.inst.part = $2.part; |
$$->v.inst.part = $2.part; |
461 |
} |
} |
462 |
| MODIFY r_msgpart string_key |
| MODIFY r_msgpart string_key |
463 |
{ |
{ |
464 |
|
if (!is_prog_allowed()) |
465 |
|
YYERROR; |
466 |
$$ = rc_stmt_create(rc_stmt_inst); |
$$ = rc_stmt_create(rc_stmt_inst); |
467 |
$$->v.inst.opcode = inst_modify; |
$$->v.inst.opcode = inst_modify; |
468 |
$$->v.inst.part = $2.part; |
$$->v.inst.part = $2.part; |
477 |
|
|
478 |
modf_stmt: REGEX modlist |
modf_stmt: REGEX modlist |
479 |
{ |
{ |
480 |
|
if (!is_prog_allowed()) |
481 |
|
YYERROR; |
482 |
def_regex_modifier = $2; |
def_regex_modifier = $2; |
483 |
$$ = NULL; |
$$ = NULL; |
484 |
} |
} |
489 |
int |
int |
490 |
yyerror(char *s) |
yyerror(char *s) |
491 |
{ |
{ |
492 |
anubis_error(SOFT, "%s:%d: %s", |
anubis_error(SOFT, "%s:%d: %s", cfg_file, cfg_line_num, s); |
|
cfg_file, cfg_line_num, s); |
|
493 |
error_count++; |
error_count++; |
494 |
return 0; |
return 0; |
495 |
} |
} |
633 |
|
|
634 |
case rc_node_expr: |
case rc_node_expr: |
635 |
free(node->v.expr.key); |
free(node->v.expr.key); |
636 |
anubis_regex_free(node->v.expr.re); |
anubis_regex_free(&node->v.expr.re); |
637 |
} |
} |
638 |
xfree(node); |
xfree(node); |
639 |
} |
} |
718 |
void |
void |
719 |
rc_inst_destroy(RC_INST *inst) |
rc_inst_destroy(RC_INST *inst) |
720 |
{ |
{ |
721 |
anubis_regex_free(inst->key); |
anubis_regex_free(&inst->key); |
722 |
free(inst->key2); |
free(inst->key2); |
723 |
free(inst->arg); |
free(inst->arg); |
724 |
} |
} |
1234 |
rc_run_section(method, sec, secdef, NULL, NULL); |
rc_run_section(method, sec, secdef, NULL, NULL); |
1235 |
} |
} |
1236 |
|
|
1237 |
|
static int |
1238 |
|
check_kw(char *ident) |
1239 |
|
{ |
1240 |
|
struct rc_secdef *p = rc_secdef; |
1241 |
|
int key; |
1242 |
|
|
1243 |
|
if (!p) |
1244 |
|
p = anubis_find_section("RULE"); |
1245 |
|
return rc_child_lookup(p->child, ident, CF_ALL, &key) != NULL; |
1246 |
|
} |
1247 |
|
|
1248 |
|
static int |
1249 |
|
is_prog_allowed() |
1250 |
|
{ |
1251 |
|
struct rc_secdef *p = rc_secdef; |
1252 |
|
if (!p) |
1253 |
|
p = anubis_find_section("RULE"); |
1254 |
|
|
1255 |
|
if (!p->allow_prog) |
1256 |
|
yyerror(_("program is not allowed in this section")); |
1257 |
|
return p->allow_prog; |
1258 |
|
} |