28 |
28 |
29 #ifndef OBJECT_H |
29 #ifndef OBJECT_H |
30 #define OBJECT_H |
30 #define OBJECT_H |
31 |
31 |
32 #include "nsapi.h" |
32 #include "nsapi.h" |
|
33 #include "pool.h" |
33 |
34 |
34 #ifdef __cplusplus |
35 #ifdef __cplusplus |
35 extern "C" { |
36 extern "C" { |
36 #endif |
37 #endif |
37 |
38 |
38 // TODO: Enum auslagern in andere Datei? |
39 // TODO: Enum auslagern in andere Datei? |
39 enum RequestPhase { |
40 enum RequestPhase { |
40 NSAPIAuthTrans = 0, |
41 NSAPIAuthTrans = 0, |
41 NSAPINameTrans, |
42 NSAPINameTrans, |
42 NSAPIPathCheck, |
43 NSAPIPathCheck, |
|
44 NSAPIObjectType, |
43 NSAPIService, |
45 NSAPIService, |
44 REQ_FINISH, |
46 REQ_FINISH, |
45 NUM_NSAPI_TYPES |
47 NUM_NSAPI_TYPES |
46 }; |
48 }; |
47 typedef enum RequestPhase RequestPhase; |
49 typedef enum RequestPhase RequestPhase; |
48 |
50 |
|
51 typedef struct Condition Condition; |
|
52 typedef int8_t ConditionResult; |
|
53 |
|
54 typedef struct NSAPIContext NSAPIContext; |
|
55 typedef struct HTTPObjectConfig HTTPObjectConfig; |
|
56 |
49 struct directive { |
57 struct directive { |
50 FuncStruct *func; |
58 FuncStruct *func; |
51 pblock *param; |
59 pblock *param; |
|
60 Condition *cond; |
52 }; |
61 }; |
53 |
62 |
54 struct dtable { |
63 struct dtable { |
55 directive **directive; |
64 directive **dirs; |
56 int ndir; |
65 int ndir; |
57 }; |
66 }; |
58 |
67 |
59 struct httpd_object { |
68 struct httpd_object { |
60 char *name; |
69 char *name; |
61 |
70 char *path; |
62 dtable *dt; |
71 dtable *dt; |
63 int nd; |
72 int nd; |
64 }; |
73 }; |
65 |
74 |
66 struct httpd_objset { |
75 struct httpd_objset { |
67 httpd_object **obj; |
76 httpd_object **obj; |
68 int pos; |
77 int pos; |
69 }; |
78 }; |
70 |
79 |
|
80 struct Condition { |
|
81 Condition *parent; |
|
82 int expression; |
|
83 int index; /* used by NSAPIContext to link expression with result */ |
|
84 }; |
|
85 |
|
86 |
|
87 struct NSAPIContext{ |
|
88 HTTPObjectConfig *conf; |
|
89 |
|
90 ConditionResult **results; |
|
91 int nres; |
|
92 |
|
93 httpd_objset *objset; |
|
94 }; |
|
95 |
|
96 struct HTTPObjectConfig { |
|
97 httpd_object **objects; |
|
98 int nobj; |
|
99 pool_handle_t *pool; |
|
100 }; |
71 |
101 |
72 /* |
102 /* |
73 * create a new httpd_object |
103 * creates a new httpd_object |
74 */ |
104 */ |
75 httpd_object* object_new(char *name); |
105 httpd_object* object_new(char *name); |
76 |
106 |
77 /* |
107 /* |
78 * frees an httpd_object |
108 * frees an httpd_object |
79 */ |
109 */ |
80 void object_free(httpd_object *obj); |
110 void object_free(httpd_object *obj); |
81 |
111 |
82 /* |
112 /* |
83 * adds a directive to the object with the type dt (enum DirectiveType) |
113 * adds a directive to the object with the type dt (enum RequestPhase) |
84 */ |
114 */ |
85 void object_add_directive(httpd_object *obj, directive *dir, int dt); |
115 void object_add_directive(httpd_object *obj, directive *dir, int dt); |
86 |
116 |
87 /* |
117 /* |
88 * get a list of all directives with a specific type |
118 * get a list of all directives with a specific type |
89 */ |
119 */ |
90 #define object_get_dtable(obj,type) &obj->dt[type]; |
120 #define object_get_dtable(obj,type) &obj->dt[type]; |
|
121 |
|
122 |
|
123 /* |
|
124 * creates a new HTTPObjectConfig |
|
125 */ |
|
126 // TODO |
|
127 |
|
128 /* |
|
129 * adds an object to the object configuration |
|
130 */ |
|
131 void httpobjconf_add_object(HTTPObjectConfig *conf, httpd_object *obj); |
91 |
132 |
92 |
133 |
93 |
134 |
94 httpd_objset* create_test_objset(); |
135 httpd_objset* create_test_objset(); |
95 |
136 |