src/server/util/object.h

changeset 83
28433f06d5ee
parent 61
c858850f3d3a
child 95
74a81d9e19d0
equal deleted inserted replaced
82:740cfd9dd443 83:28433f06d5ee
49 }; 49 };
50 typedef enum RequestPhase RequestPhase; 50 typedef enum RequestPhase RequestPhase;
51 51
52 typedef struct Condition Condition; 52 typedef struct Condition Condition;
53 typedef int8_t ConditionResult; 53 typedef int8_t ConditionResult;
54 typedef struct Expression Expression;
55 typedef enum OperandType OperandType;
56 typedef enum Operator Operator;
57 typedef enum VarType VarType;
54 58
55 typedef struct NSAPIContext NSAPIContext; 59 typedef struct NSAPIContext NSAPIContext;
56 typedef struct HTTPObjectConfig HTTPObjectConfig; 60 typedef struct HTTPObjectConfig HTTPObjectConfig;
57 61
58 struct directive { 62 struct directive {
79 int pos; 83 int pos;
80 }; 84 };
81 85
82 struct Condition { 86 struct Condition {
83 Condition *parent; 87 Condition *parent;
84 int expression; 88 Expression *expression;
85 int index; /* used by NSAPIContext to link expression with result */ 89 int index; // used by NSAPIContext to link expression with result
90 };
91
92 enum OperandType {
93 EXPR_OP_NULL = 0, // no operand
94 EXPR_OP_STRING, // string literal
95 EXPR_OP_INTEGER, // integer literal
96 EXPR_OP_VAR, // variable
97 EXPR_OP_FUNC, // function,
98 EXPR_OP_EXPRESSION // operand is an expression
99 };
100
101 enum Operator {
102 OP_NOOP = 0,
103 OP_NOT, // not, !
104 OP_AND, // and, &&
105 OP_OR, // or, ||
106 OP_XOR, // xor, ^
107 OP_WILDCARD, // =
108 OP_REGEX, // =~
109 OP_NREGEX, // !~
110 OP_ADD, // +
111 OP_SUB, // -
112 OP_CAT, // .
113 OP_DEF, // defined
114 OP_DEXISTS, // -d
115 OP_FDEXISTS, // -e
116 OP_FEXISTS, // -f
117 OP_LEXISTS, // -l
118 OP_READABLE, // -r
119 OP_FSIZE, // -s
120 OP_UMAP, // -U
121 OP_LESS, // <
122 OP_LESSEQ, // <=
123 OP_GREATER, // >
124 OP_GREATEREQ, // >=
125 OP_STRLESS, // lt
126 OP_STRLESSEQ, // le
127 OP_STRGREATER, // gt
128 OP_STRGREATEREQ, // ge
129 OP_EQUAL, // ==
130 OP_NOTEQUAL, // !=
131 OP_STREQUAL, // eq
132 OP_STRNOTEQUAL, // ne
133 };
134
135 enum VarType {
136 VAR_NULL = 0,
137 VAR_STRING,
138 VAR_INTEGER,
139 VAR_BOOL
140 };
141
142 struct Expression {
143 // type of the operands
144 OperandType optype[2];
145 // operand data
146 void *opdata[2];
147 // operator
148 Operator expr_operator;
149 // logical connective to next expression
150 Operator next_operator;
151 // next expression
152 Expression *next;
86 }; 153 };
87 154
88 155
89 struct NSAPIContext{ 156 struct NSAPIContext{
90 HTTPObjectConfig *conf; 157 HTTPObjectConfig *conf;
91 158
92 ConditionResult **results; 159 ConditionResult **results;
93 int nres; 160 int nres;
161 int nmaxres;
94 162
95 //httpd_objset *objset; 163 //httpd_objset *objset;
96 int last_req_code; 164 int last_req_code;
97 165
98 int objset_index; 166 int objset_index;
154 /* 222 /*
155 * prepares the NSAPI context for the next request stage 223 * prepares the NSAPI context for the next request stage
156 */ 224 */
157 void nsapi_context_next_stage(NSAPIContext *context); 225 void nsapi_context_next_stage(NSAPIContext *context);
158 226
227 Condition* condition_from_str(pool_handle_t *pool, char *expr, size_t len);
228 Expression* expression_from_str(pool_handle_t *pool, char *expr, size_t len);
229 Operator expr_operator(char *token, size_t len);
230
231 /*
232 * get the type of the token
233 *
234 * returns
235 * 0: operand
236 * 1: operator
237 */
238 int expr_token_type(char *token, size_t len);
239 void expr_set_op(pool_handle_t *pool, OperandType *type, void **val, char *token, size_t len);
240
241
242 int condition_evaluate(Condition *condition, Session *sn, Request *rq);
243 int expression_evaluate(Expression *ex, Session *sn, Request *rq);
244 int expr_get_var(char *var, Session *sn, Request *rq, void **val, VarType *t);
159 245
160 #ifdef __cplusplus 246 #ifdef __cplusplus
161 } 247 }
162 #endif 248 #endif
163 249

mercurial