1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 #ifndef OBJECT_H
30 #define OBJECT_H
31
32 #include "../public/nsapi.h"
33 #include "pool.h"
34
35 #include <inttypes.h>
36 #include <cx/list.h>
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42
43 enum RequestStage {
44 NSAPIAuthTrans =
0,
45 NSAPINameTrans,
46 NSAPIPathCheck,
47 NSAPIObjectType,
48 NSAPIService,
49 NSAPIError,
50 NSAPIAddLog,
51 REQ_FINISH,
52 NUM_NSAPI_TYPES
53 };
54 typedef enum RequestStage RequestStage;
55
56 typedef struct Condition Condition;
57 typedef int8_t ConditionResult;
58 typedef struct Expression Expression;
59 typedef enum OperandType OperandType;
60 typedef enum Operator Operator;
61 typedef enum VarType VarType;
62
63 typedef struct NSAPIContext NSAPIContext;
64 typedef struct HTTPObjectConfig HTTPObjectConfig;
65
66 struct directive {
67 FuncStruct *func;
68 pblock *param;
69 Condition *cond;
70 };
71
72 struct dtable {
73 directive **dirs;
74 int ndir;
75 int alloc;
76 };
77
78 struct httpd_object {
79 pool_handle_t *pool;
80 char *name;
81 char *path;
82 dtable *dt;
83 int nd;
84 };
85
86 struct httpd_objset {
87 httpd_object **obj;
88 int pos;
89 };
90
91 struct Condition {
92 Condition *parent;
93 Condition *ifnot;
94 Expression *expression;
95 int depth;
96 int index;
97 };
98
99 struct Expression {
100
101 int n;
102 };
103
104
105 struct NSAPIContext{
106 HTTPObjectConfig *conf;
107
108 ConditionResult **results;
109 int nres;
110 int nmaxres;
111
112
113 int last_req_code;
114
115 int objset_index;
116 int dtable_index;
117 };
118
119 struct HTTPObjectConfig {
120 httpd_object **objects;
121 int nobj;
122 pool_handle_t *pool;
123 uint32_t ref;
124 };
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 NSAPI_EXPRESSION_IDENTIFIER
142 };
143
144 enum NSAPIExpressionOperator {
145 NSAPI_EXPRESSION_NOOP =
0,
146 NSAPI_EXPRESSION_CALL,
147 NSAPI_EXPRESSION_ARG,
148 NSAPI_EXPRESSION_WILDCARD_MATCH,
149 NSAPI_EXPRESSION_REGEX_MATCH,
150 NSAPI_EXPRESSION_REGEX_MISMATCH,
151 NSAPI_EXPRESSION_EQ,
152 NSAPI_EXPRESSION_NEQ,
153 NSAPI_EXPRESSION_GT,
154 NSAPI_EXPRESSION_LT,
155 NSAPI_EXPRESSION_GE,
156 NSAPI_EXPRESSION_LE,
157 NSAPI_EXPRESSION_ADD,
158 NSAPI_EXPRESSION_SUB,
159 NSAPI_EXPRESSION_MUL,
160 NSAPI_EXPRESSION_DIV,
161 NSAPI_EXPRESSION_MOD,
162 NSAPI_EXPRESSION_STRCAT,
163 NSAPI_EXPRESSION_NOT,
164 NSAPI_EXPRESSION_AND,
165 NSAPI_EXPRESSION_OR,
166 NSAPI_EXPRESSION_XOR,
167 NSAPI_EXPRESSION_VALUE_DEFINED,
168 NSAPI_EXPRESSION_DIR_EXISTS,
169 NSAPI_EXPRESSION_FILE_DIR_EXISTS,
170 NSAPI_EXPRESSION_FILE_EXISTS,
171 NSAPI_EXPRESSION_SYMLINK_EXISTS,
172 NSAPI_EXPRESSION_FILE_READABLE,
173 NSAPI_EXPRESSION_FILE_SIZE
174 };
175
176 union NSAPIExpressionValue {
177 cxstring str;
178 cxstring var;
179 cxstring identifier;
180 int64_t i;
181 double f;
182 int b;
183 };
184
185 struct NSAPIExpression {
186
187
188
189 union NSAPIExpressionValue value;
190
191 NSAPIExpressionType type;
192
193 NSAPIExpressionOperator operator;
194
195
196
197
198 NSAPIExpression *left;
199
200
201
202
203 NSAPIExpression *right;
204 };
205
206
207
208
209
210
211 httpd_object* object_new(
pool_handle_t *pool,
char *name);
212
213
214
215
216 void object_free(httpd_object *obj);
217
218
219
220
221 int object_add_directive(httpd_object *obj, directive *dir,
int dt);
222
223
224
225
226 #define object_get_dtable(obj,type) &obj->dt[type];
227
228
229
230
231
232
233 httpd_objset* objset_create(
pool_handle_t *pool);
234
235
236
237
238 void objset_add_object(
pool_handle_t *p, httpd_objset *os, httpd_object *obj);
239
240
241
242
243
244
245
246
247
248
249 void httpobjconf_add_object(HTTPObjectConfig *conf, httpd_object *obj);
250
251
252
253
254
255
256 void nsapi_context_next_stage(NSAPIContext *context);
257
258
259
260
261
262
263
264
265 Expression* condition_create(
pool_handle_t *pool, CxList *tokens);
266
267 NSAPIExpression* expr_parse_logical_expr(
pool_handle_t *pool, CxList *tokens,
size_t *pos);
268
269 int condition_evaluate(Condition *condition, Session *sn, Request *rq);
270
271
272 #ifdef __cplusplus
273 }
274 #endif
275
276 #endif
277
278