]> granicus.if.org Git - apache/blob - server/util_expr_private.h
ap_expr related fixes/enhancements:
[apache] / server / util_expr_private.h
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 #ifndef __AP_EXPR_PRIVATE_H__
18 #define __AP_EXPR_PRIVATE_H__
19
20 #include "httpd.h"
21 #include "apr_strings.h"
22 #include "apr_tables.h"
23 #include "ap_expr.h"
24
25 #ifndef YY_NULL
26 #define YY_NULL 0
27 #endif
28
29 #ifndef MIN
30 #define MIN(a,b) (((a)<(b))?(a):(b))
31 #endif
32
33 #ifndef YYDEBUG
34 #define YYDEBUG 0
35 #endif
36
37 /** The operations in a parse tree node */
38 typedef enum {
39     op_NOP,
40     op_True, op_False,
41     op_Not, op_Or, op_And,
42     op_Comp,
43     op_EQ, op_NE, op_LT, op_LE, op_GT, op_GE, op_IN,
44     op_REG, op_NRE,
45     op_STR_EQ, op_STR_NE, op_STR_LT, op_STR_LE, op_STR_GT, op_STR_GE,
46     op_Concat,
47     op_Digit, op_String, op_Regex, op_RegexBackref,
48     op_Var,
49     op_ListElement,
50     /*
51      * call external functions/operators.
52      * The info node contains the function pointer and some function specific
53      * info.
54      * For Binary operators, the Call node links to the Info node and the
55      * Args node, which in turn links to the left and right operand.
56      * For all other variants, the Call node links to the Info node and the
57      * argument.
58      */
59     op_UnaryOpCall, op_UnaryOpInfo,
60     op_BinaryOpCall, op_BinaryOpInfo, op_BinaryOpArgs,
61     op_StringFuncCall, op_StringFuncInfo,
62     op_ListFuncCall, op_ListFuncInfo
63 } ap_expr_node_op;
64
65 /** The basic parse tree node */
66 struct ap_expr_node {
67     ap_expr_node_op node_op;
68     const void *node_arg1;
69     const void *node_arg2;
70 };
71
72 /** The context used by scanner and parser */
73 typedef struct {
74     /* internal state of the scanner */
75     const char        *inputbuf;
76     int                inputlen;
77     const char        *inputptr;
78     void              *scanner;
79     char              *scan_ptr;
80     char               scan_buf[MAX_STRING_LEN];
81     char               scan_del;
82
83     /* pools for result and temporary usage */
84     apr_pool_t        *pool;
85     apr_pool_t        *ptemp;
86
87     /* The created parse tree */
88     ap_expr           *expr;
89
90     const char        *error;
91     const char        *error2;
92     unsigned           flags;
93
94     /*
95      * The function to use to lookup provider functions for variables
96      * and funtctions
97      */
98     ap_expr_lookup_fn   *lookup_fn;
99 } ap_expr_parse_ctx;
100
101 /* flex/bison functions */
102 int  ap_expr_yyparse(ap_expr_parse_ctx *context);
103 void ap_expr_yyerror(ap_expr_parse_ctx *context, char *err);
104 int  ap_expr_yylex_init(void **scanner);
105 int  ap_expr_yylex_destroy(void *scanner);
106 void ap_expr_yyset_extra(ap_expr_parse_ctx *context, void *scanner);
107
108 /* create a parse tree node */
109 ap_expr *ap_expr_make(ap_expr_node_op op, const void *arg1, const void *arg2,
110                         ap_expr_parse_ctx *ctx);
111 /* create parse tree node for the string-returning function 'name' */
112 ap_expr *ap_expr_str_func_make(const char *name, const ap_expr *arg,
113                                ap_expr_parse_ctx *ctx);
114 /* create parse tree node for the list-returning function 'name' */
115 ap_expr *ap_expr_list_func_make(const char *name, const ap_expr *arg,
116                                 ap_expr_parse_ctx *ctx);
117 /* create parse tree node for the variable 'name' */
118 ap_expr *ap_expr_var_make(const char *name, ap_expr_parse_ctx *ctx);
119 /* create parse tree node for the unary operator 'name' */
120 ap_expr *ap_expr_unary_op_make(const char *name, const ap_expr *arg,
121                                ap_expr_parse_ctx *ctx);
122 /* create parse tree node for the binary operator 'name' */
123 ap_expr *ap_expr_binary_op_make(const char *name, const ap_expr *arg1,
124                                 const ap_expr *arg2, ap_expr_parse_ctx *ctx);
125
126
127 #endif /* __AP_EXPR_PRIVATE_H__ */
128 /** @} */
129