src/server/util/object.h

changeset 423
bb7cff720dd0
parent 422
76f2f5d532d0
child 435
713ec3da79ec
equal deleted inserted replaced
422:76f2f5d532d0 423:bb7cff720dd0
30 #define OBJECT_H 30 #define OBJECT_H
31 31
32 #include "../public/nsapi.h" 32 #include "../public/nsapi.h"
33 #include "pool.h" 33 #include "pool.h"
34 34
35 #include <inttypes.h>
36 #include <cx/list.h>
37
35 #ifdef __cplusplus 38 #ifdef __cplusplus
36 extern "C" { 39 extern "C" {
37 #endif 40 #endif
38 41
39 // TODO: Enum auslagern in andere Datei? 42 // TODO: Enum auslagern in andere Datei?
118 int nobj; 121 int nobj;
119 pool_handle_t *pool; 122 pool_handle_t *pool;
120 uint32_t ref; // reference counter 123 uint32_t ref; // reference counter
121 }; 124 };
122 125
126
127
128 typedef struct NSAPIExpression NSAPIExpression;
129 typedef enum NSAPIExpressionType NSAPIExpressionType;
130 typedef enum NSAPIExpressionOperator NSAPIExpressionOperator;
131
132 enum NSAPIExpressionType {
133 NSAPI_EXPRESSION_BOOL = 0,
134 NSAPI_EXPRESSION_INT,
135 NSAPI_EXPRESSION_DOUBLE,
136 NSAPI_EXPRESSION_STRING,
137 NSAPI_EXPRESSION_VARIABLE,
138 NSAPI_EXPRESSION_LOGICAL,
139 NSAPI_EXPRESSION_UNARY,
140 NSAPI_EXPRESSION_BINARY
141 };
142
143 enum NSAPIExpressionOperator {
144 NSAPI_EXPRESSION_NOOP = 0,
145 NSAPI_EXPRESSION_NOT,
146 NSAPI_EXPRESSION_AND,
147 NSAPI_EXPRESSION_OR,
148 NSAPI_EXPRESSION_XOR,
149 NSAPI_EXPRESSION_EQ,
150 NSAPI_EXPRESSION_NEQ,
151 NSAPI_EXPRESSION_GT,
152 NSAPI_EXPRESSION_LT,
153 NSAPI_EXPRESSION_GE,
154 NSAPI_EXPRESSION_LE,
155 NSAPI_EXPRESSION_ADD,
156 NSAPI_EXPRESSION_SUB,
157 NSAPI_EXPRESSION_MUL,
158 NSAPI_EXPRESSION_DIV,
159 NSAPI_EXPRESSION_MOD
160 };
161
162 union NSAPIExpressionValue {
163 cxstring str;
164 cxstring var;
165 int64_t i;
166 double f;
167 int b;
168 };
169
170 struct NSAPIExpression {
171 // value.ptr is not null if
172 // type is one of (bool, int, string): literal text
173 // type is variable: variable name
174 union NSAPIExpressionValue value;
175
176 NSAPIExpressionType type;
177
178 NSAPIExpressionOperator operator;
179
180 /*
181 * left/single operand
182 */
183 NSAPIExpression *left;
184
185 /*
186 * right operand or NULL
187 */
188 NSAPIExpression *right;
189 };
190
191
192
123 /* 193 /*
124 * creates a new httpd_object 194 * creates a new httpd_object
125 */ 195 */
126 httpd_object* object_new(pool_handle_t *pool, char *name); 196 httpd_object* object_new(pool_handle_t *pool, char *name);
127 197
168 /* 238 /*
169 * prepares the NSAPI context for the next request stage 239 * prepares the NSAPI context for the next request stage
170 */ 240 */
171 void nsapi_context_next_stage(NSAPIContext *context); 241 void nsapi_context_next_stage(NSAPIContext *context);
172 242
243
244 /*
245 * parses an expression from a list of cxstring tokens and compiles the
246 * expression into an Expression object
247 *
248 * tokens: CxList that contains cxstring
249 */
250 Expression* condition_create(pool_handle_t *pool, CxList *tokens);
251
252 NSAPIExpression* expr_parse_logical_expr(pool_handle_t *pool, CxList *tokens, size_t *pos);
173 253
174 int condition_evaluate(Condition *condition, Session *sn, Request *rq); 254 int condition_evaluate(Condition *condition, Session *sn, Request *rq);
175 255
176 256
177 #ifdef __cplusplus 257 #ifdef __cplusplus

mercurial