1 /* |
|
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
3 * |
|
4 * Copyright 2011 Olaf Wintermann. All rights reserved. |
|
5 * |
|
6 * Redistribution and use in source and binary forms, with or without |
|
7 * modification, are permitted provided that the following conditions are met: |
|
8 * |
|
9 * 1. Redistributions of source code must retain the above copyright |
|
10 * notice, this list of conditions and the following disclaimer. |
|
11 * |
|
12 * 2. Redistributions in binary form must reproduce the above copyright |
|
13 * notice, this list of conditions and the following disclaimer in the |
|
14 * documentation and/or other materials provided with the distribution. |
|
15 * |
|
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
26 * POSSIBILITY OF SUCH DAMAGE. |
|
27 */ |
|
28 |
|
29 #ifndef OBJECT_H |
|
30 #define OBJECT_H |
|
31 |
|
32 #include "nsapi.h" |
|
33 #include "pool.h" |
|
34 |
|
35 #ifdef __cplusplus |
|
36 extern "C" { |
|
37 #endif |
|
38 |
|
39 // TODO: Enum auslagern in andere Datei? |
|
40 enum RequestPhase { |
|
41 NSAPIAuthTrans = 0, |
|
42 NSAPINameTrans, |
|
43 NSAPIPathCheck, |
|
44 NSAPIObjectType, |
|
45 NSAPIService, |
|
46 NSAPIAddLog, |
|
47 REQ_FINISH, |
|
48 NUM_NSAPI_TYPES |
|
49 }; |
|
50 typedef enum RequestPhase RequestPhase; |
|
51 |
|
52 typedef struct Condition Condition; |
|
53 typedef int8_t ConditionResult; |
|
54 |
|
55 typedef struct NSAPIContext NSAPIContext; |
|
56 typedef struct HTTPObjectConfig HTTPObjectConfig; |
|
57 |
|
58 struct directive { |
|
59 FuncStruct *func; |
|
60 pblock *param; |
|
61 Condition *cond; |
|
62 }; |
|
63 |
|
64 struct dtable { |
|
65 directive **dirs; |
|
66 int ndir; |
|
67 }; |
|
68 |
|
69 struct httpd_object { |
|
70 char *name; |
|
71 char *path; |
|
72 dtable *dt; |
|
73 int nd; |
|
74 }; |
|
75 |
|
76 struct httpd_objset { |
|
77 httpd_object **obj; |
|
78 int pos; |
|
79 }; |
|
80 |
|
81 struct Condition { |
|
82 Condition *parent; |
|
83 int expression; |
|
84 int index; /* used by NSAPIContext to link expression with result */ |
|
85 }; |
|
86 |
|
87 |
|
88 struct NSAPIContext{ |
|
89 HTTPObjectConfig *conf; |
|
90 |
|
91 ConditionResult **results; |
|
92 int nres; |
|
93 |
|
94 //httpd_objset *objset; |
|
95 int last_req_code; |
|
96 |
|
97 int objset_index; |
|
98 int dtable_index; |
|
99 }; |
|
100 |
|
101 struct HTTPObjectConfig { |
|
102 httpd_object **objects; |
|
103 int nobj; |
|
104 pool_handle_t *pool; |
|
105 }; |
|
106 |
|
107 /* |
|
108 * creates a new httpd_object |
|
109 */ |
|
110 httpd_object* object_new(char *name); |
|
111 |
|
112 /* |
|
113 * frees an httpd_object |
|
114 */ |
|
115 void object_free(httpd_object *obj); |
|
116 |
|
117 /* |
|
118 * adds a directive to the object with the type dt (enum RequestPhase) |
|
119 */ |
|
120 void object_add_directive(httpd_object *obj, directive *dir, int dt); |
|
121 |
|
122 /* |
|
123 * get a list of all directives with a specific type |
|
124 */ |
|
125 #define object_get_dtable(obj,type) &obj->dt[type]; |
|
126 |
|
127 |
|
128 |
|
129 /* |
|
130 * creates a new httpd_objset |
|
131 */ |
|
132 httpd_objset* objset_create(pool_handle_t *pool); |
|
133 |
|
134 /* |
|
135 * adds a object to the objset |
|
136 */ |
|
137 void objset_add_object(pool_handle_t *p, httpd_objset *os, httpd_object *obj); |
|
138 |
|
139 |
|
140 /* |
|
141 * creates a new HTTPObjectConfig |
|
142 */ |
|
143 // TODO |
|
144 |
|
145 /* |
|
146 * adds an object to the object configuration |
|
147 */ |
|
148 void httpobjconf_add_object(HTTPObjectConfig *conf, httpd_object *obj); |
|
149 |
|
150 |
|
151 |
|
152 /* |
|
153 * prepares the NSAPI context for the next request stage |
|
154 */ |
|
155 void nsapi_context_next_stage(NSAPIContext *context); |
|
156 |
|
157 |
|
158 #ifdef __cplusplus |
|
159 } |
|
160 #endif |
|
161 |
|
162 #endif /* OBJECT_H */ |
|
163 |
|