diff options
Diffstat (limited to 'mfd/gram.y')
-rw-r--r-- | mfd/gram.y | 131 |
1 files changed, 92 insertions, 39 deletions
@@ -301,3 +301,3 @@ _create_alias(void *item, void *data) %error-verbose -%expect 29 +%expect 28 @@ -362,3 +362,3 @@ _create_alias(void *item, void *data) %token <locus> FOR LOOP WHILE BREAK NEXT ARGCOUNT ALIAS DOTS ARGX VAPTR -%token <literal> STRING CODE XCODE +%token <literal> STRING %token <literal> SYMBOL IDENTIFIER @@ -388,3 +388,4 @@ _create_alias(void *item, void *data) if_cond else_cond on_cond atom argref paren_argref - funcall proccall expr common_expr simp_expr atom_expr + funcall proccall expr maybe_expr maybe_xcode_expr + common_expr simp_expr atom_expr asgn catch throw return case_cond autodcl constdecl @@ -396,6 +397,5 @@ _create_alias(void *item, void *data) %type <loop> opt_loop_parms loop_parm_list -%type <number> number %type <arglist> arglist %type <var> variable -%type <literal> string opt_ident loop_ident alias +%type <literal> string opt_ident loop_ident alias code xcode %type <state> state_ident @@ -894,6 +894,2 @@ sendmail_action: { - if ($2.code && $2.code->text[0] != '5') - parse_error(_("Reject code should be 5xx")); - if ($2.xcode && $2.xcode->text[0] != '5') - parse_error(_("Reject extended code should be 5.x.x")); $$ = alloc_node(node_type_result, &$1); @@ -902,8 +898,12 @@ sendmail_action: } + | ACT_REJECT '(' maybe_expr ',' maybe_xcode_expr ',' maybe_expr ')' + { + $$ = alloc_node(node_type_result, &$1); + $$->v.ret.stat = SMFIS_REJECT; + $$->v.ret.code = $3 ? cast_to(dtype_string, $3) : NULL; + $$->v.ret.xcode = $5 ? cast_to(dtype_string, $5) : NULL; + $$->v.ret.message = $7 ? cast_to(dtype_string, $7) : NULL; + } | ACT_TEMPFAIL maybe_triplet { - if ($2.code && $2.code->text[0] != '4') - parse_error(_("Tempfail code should be 4xx")); - if ($2.xcode && $2.xcode->text[0] != '4') - parse_error(_("Tempfail extended code should be 4.x.x")); $$ = alloc_node(node_type_result, &$1); @@ -912,2 +912,10 @@ sendmail_action: } + | ACT_TEMPFAIL '(' maybe_expr ',' maybe_xcode_expr ',' maybe_expr ')' + { + $$ = alloc_node(node_type_result, &$1); + $$->v.ret.stat = SMFIS_TEMPFAIL; + $$->v.ret.code = $3 ? cast_to(dtype_string, $3) : NULL; + $$->v.ret.xcode = $5 ? cast_to(dtype_string, $5) : NULL; + $$->v.ret.message = $7 ? cast_to(dtype_string, $7) : NULL; + } | ACT_CONTINUE @@ -926,2 +934,11 @@ sendmail_action: +maybe_xcode_expr: maybe_expr + | xcode + { + $$ = alloc_node(node_type_string, get_locus()); + $$->v.literal = $1; + } + ; + + header_action: @@ -957,5 +974,6 @@ maybe_triplet: /* empty */ -triplet : CODE +triplet : code { - $$.code = $1; + $$.code = alloc_node(node_type_string, get_locus()); + $$.code->v.literal = $1; $$.xcode = NULL; @@ -963,17 +981,22 @@ triplet : CODE } - | CODE XCODE + | code xcode { - $$.code = $1; - $$.xcode = $2; + $$.code = alloc_node(node_type_string, get_locus()); + $$.code->v.literal = $1; + $$.xcode = alloc_node(node_type_string, get_locus()); + $$.xcode->v.literal = $2; $$.message = NULL; } - | CODE XCODE expr + | code xcode expr { - $$.code = $1; - $$.xcode = $2; + $$.code = alloc_node(node_type_string, get_locus()); + $$.code->v.literal = $1; + $$.xcode = alloc_node(node_type_string, get_locus()); + $$.xcode->v.literal = $2; $$.message = cast_to(dtype_string, $3); } - | CODE expr + | code expr { - $$.code = $1; + $$.code = alloc_node(node_type_string, get_locus()); + $$.code->v.literal = $1; $$.xcode = NULL; @@ -983,2 +1006,38 @@ triplet : CODE +code : NUMBER + { + char buf[4]; + + if ($1 < 200 || $1 > 599) { + yyerror(_("Invalid SMTP reply code")); + buf[0] = 0; + } else + snprintf(buf, sizeof(buf), "%lu", $1); + $$ = string_alloc(buf, strlen(buf)); + } + ; + +xcode : NUMBER '.' NUMBER '.' NUMBER + { + char buf[sizeof("5.999.999")]; + + /* RFC 1893: + The syntax of the new status codes is defined as: + + status-code = class "." subject "." detail + class = "2"/"4"/"5" + subject = 1*3digit + detail = 1*3digit + */ + if (($1 != 2 && $1 != 4 && $1 !=5) + || $3 > 999 || $5 > 999) { + yyerror(_("Invalid extended reply code")); + buf[0] = 0; + } else + snprintf(buf, sizeof(buf), "%lu.%lu.%lu", + $1, $3, $5); + $$ = string_alloc(buf, strlen(buf)); + } + ; + condition : if_cond @@ -1123,3 +1182,3 @@ value : STRING } - | number + | NUMBER { @@ -1166,15 +1225,2 @@ fnmatches : FNMATCHES -number : NUMBER - | CODE - { - char *p; - $$ = strtol($1->text, &p, 10); - if (*p) { - /* should not happen */ - parse_error(_("Invalid number (near `%s')"), p); - YYERROR; - } - } - ; - @@ -1404,2 +1450,9 @@ expr : NOT expr +maybe_expr : /* empty */ + { + $$ = NULL; + } + | expr + ; + common_expr: simp_expr @@ -1952,3 +2005,3 @@ on : ON { - onblock(1); + tie_in_onblock(1); } @@ -1958,3 +2011,3 @@ do : DO { - onblock(0); + tie_in_onblock(0); } |