src/server/util/object.h

changeset 107
7e81699d1f77
parent 95
74a81d9e19d0
child 108
2a394ccdd778
equal deleted inserted replaced
106:b122f34ddc80 107:7e81699d1f77
88 Condition *parent; 88 Condition *parent;
89 Expression *expression; 89 Expression *expression;
90 int index; // used by NSAPIContext to link expression with result 90 int index; // used by NSAPIContext to link expression with result
91 }; 91 };
92 92
93 enum OperandType {
94 EXPR_OP_NULL = 0, // no operand
95 EXPR_OP_STRING, // string literal
96 EXPR_OP_INTEGER, // integer literal
97 EXPR_OP_VAR, // variable
98 EXPR_OP_FUNC, // function,
99 EXPR_OP_EXPRESSION // operand is an expression
100 };
101
102 enum Operator {
103 OP_NOOP = 0,
104 OP_NOT, // not, !
105 OP_AND, // and, &&
106 OP_OR, // or, ||
107 OP_XOR, // xor, ^
108 OP_WILDCARD, // =
109 OP_REGEX, // =~
110 OP_NREGEX, // !~
111 OP_ADD, // +
112 OP_SUB, // -
113 OP_CAT, // .
114 OP_DEF, // defined
115 OP_DEXISTS, // -d
116 OP_FDEXISTS, // -e
117 OP_FEXISTS, // -f
118 OP_LEXISTS, // -l
119 OP_READABLE, // -r
120 OP_FSIZE, // -s
121 OP_UMAP, // -U
122 OP_LESS, // <
123 OP_LESSEQ, // <=
124 OP_GREATER, // >
125 OP_GREATEREQ, // >=
126 OP_STRLESS, // lt
127 OP_STRLESSEQ, // le
128 OP_STRGREATER, // gt
129 OP_STRGREATEREQ, // ge
130 OP_EQUAL, // ==
131 OP_NOTEQUAL, // !=
132 OP_STREQUAL, // eq
133 OP_STRNOTEQUAL, // ne
134 };
135
136 enum VarType {
137 VAR_NULL = 0,
138 VAR_STRING,
139 VAR_INTEGER,
140 VAR_BOOL
141 };
142
143 struct Expression { 93 struct Expression {
144 // type of the operands 94 // TODO
145 OperandType optype[2]; 95 int n;
146 // operand data
147 void *opdata[2];
148 // operator
149 Operator expr_operator;
150 // logical connective to next expression
151 Operator next_operator;
152 // next expression
153 Expression *next;
154 }; 96 };
155 97
156 98
157 struct NSAPIContext{ 99 struct NSAPIContext{
158 HTTPObjectConfig *conf; 100 HTTPObjectConfig *conf;
225 */ 167 */
226 void nsapi_context_next_stage(NSAPIContext *context); 168 void nsapi_context_next_stage(NSAPIContext *context);
227 169
228 Condition* condition_from_str(pool_handle_t *pool, char *expr, size_t len); 170 Condition* condition_from_str(pool_handle_t *pool, char *expr, size_t len);
229 Expression* expression_from_str(pool_handle_t *pool, char *expr, size_t len); 171 Expression* expression_from_str(pool_handle_t *pool, char *expr, size_t len);
230 Operator expr_operator(char *token, size_t len);
231
232 /*
233 * get the type of the token
234 *
235 * returns
236 * 0: operand
237 * 1: operator
238 */
239 int expr_token_type(char *token, size_t len);
240 void expr_set_op(pool_handle_t *pool, OperandType *type, void **val, char *token, size_t len);
241
242 172
243 int condition_evaluate(Condition *condition, Session *sn, Request *rq); 173 int condition_evaluate(Condition *condition, Session *sn, Request *rq);
244 int expression_evaluate(Expression *ex, Session *sn, Request *rq); 174
245 int expr_get_var(char *var, Session *sn, Request *rq, void **val, VarType *t);
246 175
247 #ifdef __cplusplus 176 #ifdef __cplusplus
248 } 177 }
249 #endif 178 #endif
250 179

mercurial