bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / modules / ssl / ssl_expr_scan.l
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_scan.l
24  *  Expression Scanner
25  */
26                              /* ``Killing for peace is 
27                                   like fucking for virginity.''
28                                              -- Unknown  */
29
30 /*  _________________________________________________________________
31 **
32 **  Expression Scanner
33 **  _________________________________________________________________
34 */
35
36 %{
37 #include "mod_ssl.h"
38
39 #include "ssl_expr_parse.h"
40
41 #define YY_NO_UNPUT 1
42 int yyinput(char *buf, int max_size);
43
44 #undef  YY_INPUT
45 #define YY_INPUT(buf,result,max_size) \
46     (result = yyinput(buf, max_size))
47
48 #define MAX_STR_LEN 2048
49 %}
50
51 %pointer
52 /* %option stack */
53 %option never-interactive
54 %option noyywrap
55 %x str
56 %x regex regex_flags
57
58 %%
59   
60   char  caStr[MAX_STR_LEN];
61   char *cpStr = NULL;
62   char  caRegex[MAX_STR_LEN];
63   char *cpRegex = NULL;
64   char  cRegexDel = NUL;
65
66  /*
67   * Whitespaces
68   */
69 [ \t\n]+ { 
70     /* NOP */
71 }
72
73  /*
74   * C-style strings ("...")
75   */
76 \" {
77     cpStr = caStr;
78     BEGIN(str);
79 }
80 <str>\" {
81     BEGIN(INITIAL);
82     *cpStr = NUL;
83     yylval.cpVal = apr_pstrdup(ssl_expr_info.pool, caStr);
84     return T_STRING;
85 }
86 <str>\n {
87     yyerror("Unterminated string");
88 }
89 <str>\\[0-7]{1,3} {
90     int result;
91
92     (void)sscanf(yytext+1, "%o", &result);
93     if (result > 0xff)
94         yyerror("Escape sequence out of bound");
95     else
96         *cpStr++ = result;
97 }
98 <str>\\[0-9]+ {
99     yyerror("Bad escape sequence");
100 }
101 <str>\\n { *cpStr++ = '\n'; }
102 <str>\\r { *cpStr++ = '\r'; }
103 <str>\\t { *cpStr++ = '\t'; }
104 <str>\\b { *cpStr++ = '\b'; }
105 <str>\\f { *cpStr++ = '\f'; }
106 <str>\\(.|\n) {
107     *cpStr++ = yytext[1];
108 }
109 <str>[^\\\n\"]+ {
110     char *cp = yytext;
111     while (*cp != NUL)
112         *cpStr++ = *cp++;
113 }
114 <str>. {
115     *cpStr++ = yytext[1];
116 }
117
118  /*
119   * Regular Expression
120   */
121 "m". {
122     cRegexDel = yytext[1];
123     cpRegex = caRegex;
124     BEGIN(regex);
125 }
126 <regex>.|\n {
127     if (yytext[0] == cRegexDel) {
128         *cpRegex = NUL;
129         BEGIN(regex_flags);
130     }
131     else {
132         *cpRegex++ = yytext[0];
133     }
134 }
135 <regex_flags>i {
136     yylval.cpVal = apr_pstrdup(ssl_expr_info.pool, caRegex);
137     BEGIN(INITIAL);
138     return T_REGEX_I;
139 }
140 <regex_flags>.|\n {
141     yylval.cpVal = apr_pstrdup(ssl_expr_info.pool, caRegex);
142     yyless(0);
143     BEGIN(INITIAL);
144     return T_REGEX;
145 }
146 <regex_flags><<EOF>> {
147     yylval.cpVal = apr_pstrdup(ssl_expr_info.pool, caRegex);
148     BEGIN(INITIAL);
149     return T_REGEX;
150 }
151
152  /*
153   * Operators
154   */
155 "eq"  { return T_OP_EQ; }
156 "=="  { return T_OP_EQ; }
157 "ne"  { return T_OP_NE; }
158 "!="  { return T_OP_NE; }
159 "lt"  { return T_OP_LT; }
160 "<"   { return T_OP_LT; }
161 "le"  { return T_OP_LE; }
162 "<="  { return T_OP_LE; }
163 "gt"  { return T_OP_GT; }
164 ">"   { return T_OP_GT; }
165 "ge"  { return T_OP_GE; }
166 ">="  { return T_OP_GE; }
167 "=~"  { return T_OP_REG; }
168 "!~"  { return T_OP_NRE; }
169 "and" { return T_OP_AND; }
170 "&&"  { return T_OP_AND; }
171 "or"  { return T_OP_OR; }
172 "||"  { return T_OP_OR; }
173 "not" { return T_OP_NOT; }
174 "!"   { return T_OP_NOT; }
175 "in"  { return T_OP_IN; }
176
177  /*
178   * Functions
179   */
180 "file" { return T_FUNC_FILE; }
181
182  /*
183   * Specials
184   */
185 "true"  { return T_TRUE; }
186 "false" { return T_FALSE; }
187
188  /*
189   * Digits
190   */
191 [0-9]+ {
192     yylval.cpVal = apr_pstrdup(ssl_expr_info.pool, yytext);
193     return T_DIGIT;
194 }
195
196  /*
197   * Identifiers
198   */
199 [a-zA-Z][a-zA-Z0-9_:-]* {
200     yylval.cpVal = apr_pstrdup(ssl_expr_info.pool, yytext);
201     return T_ID;
202 }
203
204  /*
205   * Anything else is returned as is...
206   */
207 .|\n { 
208     return yytext[0];
209 }
210
211 %%
212
213 int yyinput(char *buf, int max_size)
214 {
215     int n;
216
217     if ((n = MIN(max_size, ssl_expr_info.inputbuf
218                          + ssl_expr_info.inputlen 
219                          - ssl_expr_info.inputptr)) <= 0)
220         return YY_NULL;
221     memcpy(buf, ssl_expr_info.inputptr, n);
222     ssl_expr_info.inputptr += n;
223     return n;
224 }
225