upload http
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / modules / ssl / ssl_expr_parse.y
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /*                      _             _ 
18  *  _ __ ___   ___   __| |    ___ ___| |  
19  * | '_ ` _ \ / _ \ / _` |   / __/ __| |  
20  * | | | | | | (_) | (_| |   \__ \__ \ | mod_ssl - Apache Interface to OpenSSL
21  * |_| |_| |_|\___/ \__,_|___|___/___/_| http://www.modssl.org/
22  *                      |_____|         
23  *  ssl_expr_parse.y
24  *  Expression LR(1) Parser
25  */
26                              /* ``What you see is all you get.''
27                                                                       -- Brian Kernighan      */
28
29 /*  _________________________________________________________________
30 **
31 **  Expression Parser
32 **  _________________________________________________________________
33 */
34
35 %{
36 #include "mod_ssl.h"
37 %}
38
39 %union {
40     char     *cpVal;
41     ssl_expr *exVal;
42 }
43
44 %token  T_TRUE
45 %token  T_FALSE
46
47 %token  <cpVal> T_DIGIT
48 %token  <cpVal> T_ID
49 %token  <cpVal> T_STRING
50 %token  <cpVal> T_REGEX
51 %token  <cpVal> T_REGEX_I
52
53 %token  T_FUNC_FILE
54
55 %token  T_OP_EQ
56 %token  T_OP_NE
57 %token  T_OP_LT
58 %token  T_OP_LE
59 %token  T_OP_GT
60 %token  T_OP_GE
61 %token  T_OP_REG
62 %token  T_OP_NRE
63 %token  T_OP_IN
64
65 %token  T_OP_OR
66 %token  T_OP_AND
67 %token  T_OP_NOT
68
69 %left   T_OP_OR
70 %left   T_OP_AND
71 %left   T_OP_NOT
72
73 %type   <exVal>   expr
74 %type   <exVal>   comparison
75 %type   <exVal>   funccall
76 %type   <exVal>   regex
77 %type   <exVal>   words
78 %type   <exVal>   word
79
80 %%
81
82 root      : expr                         { ssl_expr_info.expr = $1; }
83           ;
84
85 expr      : T_TRUE                       { $$ = ssl_expr_make(op_True,  NULL, NULL); }
86           | T_FALSE                      { $$ = ssl_expr_make(op_False, NULL, NULL); }
87           | T_OP_NOT expr                { $$ = ssl_expr_make(op_Not,   $2,   NULL); }
88           | expr T_OP_OR expr            { $$ = ssl_expr_make(op_Or,    $1,   $3);   }
89           | expr T_OP_AND expr           { $$ = ssl_expr_make(op_And,   $1,   $3);   }
90           | comparison                   { $$ = ssl_expr_make(op_Comp,  $1,   NULL); }
91           | '(' expr ')'                 { $$ = $2; }
92           ;
93
94 comparison: word T_OP_EQ word            { $$ = ssl_expr_make(op_EQ,  $1, $3); }
95           | word T_OP_NE word            { $$ = ssl_expr_make(op_NE,  $1, $3); }
96           | word T_OP_LT word            { $$ = ssl_expr_make(op_LT,  $1, $3); }
97           | word T_OP_LE word            { $$ = ssl_expr_make(op_LE,  $1, $3); }
98           | word T_OP_GT word            { $$ = ssl_expr_make(op_GT,  $1, $3); }
99           | word T_OP_GE word            { $$ = ssl_expr_make(op_GE,  $1, $3); }
100           | word T_OP_IN '{' words '}'   { $$ = ssl_expr_make(op_IN,  $1, $4); }
101           | word T_OP_REG regex          { $$ = ssl_expr_make(op_REG, $1, $3); }
102           | word T_OP_NRE regex          { $$ = ssl_expr_make(op_NRE, $1, $3); }
103           ;
104
105 words     : word                         { $$ = ssl_expr_make(op_ListElement, $1, NULL); }
106           | words ',' word               { $$ = ssl_expr_make(op_ListElement, $3, $1);   }
107           ;
108
109 word      : T_DIGIT                      { $$ = ssl_expr_make(op_Digit,  $1, NULL); }
110           | T_STRING                     { $$ = ssl_expr_make(op_String, $1, NULL); }
111           | '%' '{' T_ID '}'             { $$ = ssl_expr_make(op_Var,    $3, NULL); }
112           | funccall                     { $$ = $1; }
113           ;
114
115 regex     : T_REGEX { 
116                 regex_t *regex;
117                 if ((regex = ap_pregcomp(ssl_expr_info.pool, $1, 
118                                          REG_EXTENDED|REG_NOSUB)) == NULL) {
119                     ssl_expr_error = "Failed to compile regular expression";
120                     YYERROR;
121                 }
122                 $$ = ssl_expr_make(op_Regex, regex, NULL);
123             }
124           | T_REGEX_I {
125                 regex_t *regex;
126                 if ((regex = ap_pregcomp(ssl_expr_info.pool, $1, 
127                                          REG_EXTENDED|REG_NOSUB|REG_ICASE)) == NULL) {
128                     ssl_expr_error = "Failed to compile regular expression";
129                     YYERROR;
130                 }
131                 $$ = ssl_expr_make(op_Regex, regex, NULL);
132             }
133           ;
134
135 funccall  : T_FUNC_FILE '(' T_STRING ')' { 
136                ssl_expr *args = ssl_expr_make(op_ListElement, $3, NULL);
137                $$ = ssl_expr_make(op_Func, "file", args);
138             }
139           ;
140
141 %%
142
143 int yyerror(char *s)
144 {
145     ssl_expr_error = s;
146     return 2;
147 }
148