44 extern "C" { |
39 extern "C" { |
45 #endif |
40 #endif |
46 |
41 |
47 #define DAV_FOREACH(elem, list) \ |
42 #define DAV_FOREACH(elem, list) \ |
48 for (UcxDlist *elem = list ; elem != NULL ; elem = elem->next) |
43 for (UcxDlist *elem = list ; elem != NULL ; elem = elem->next) |
49 |
|
50 typedef struct PropfindResponse PropfindResponse; |
|
51 typedef struct DAVPropertyBackend DAVPropertyBackend; |
|
52 |
44 |
53 typedef struct PropfindRequest PropfindRequest; |
45 int webdav_init(pblock *pb, Session *sn, Request *rq); |
54 typedef struct ProppatchRequest ProppatchRequest; |
46 int webdav_setcollection(pblock *pb, Session *sn, Request *rq); |
55 typedef struct DavProperty DavProperty; |
|
56 |
|
57 typedef struct Propstat Propstat; |
|
58 |
|
59 typedef struct XmlNs XmlNs; |
|
60 typedef struct XmlNsMap XmlNsMap; |
|
61 |
|
62 typedef struct XmlData XmlData; |
|
63 typedef struct XmlElement XmlElement; |
|
64 |
|
65 typedef uint8_t xmlch_t; |
|
66 |
|
67 |
|
68 struct PropfindRequest { |
|
69 Session *sn; |
|
70 Request *rq; |
|
71 |
|
72 UcxDlist *properties; /* DavProperty list, requested props */ |
|
73 int8_t allprop; |
|
74 int8_t propname; |
|
75 |
|
76 int8_t prop; |
|
77 UcxDlist *notFoundProps; |
|
78 UcxDlist *forbiddenProps; |
|
79 DAVPropertyBackend *propertyBackend; |
|
80 |
|
81 char *path; |
|
82 char *uri; |
|
83 |
|
84 sbuf_t *out; |
|
85 }; |
|
86 |
|
87 struct ProppatchRequest { |
|
88 Session *sn; |
|
89 Request *rq; |
|
90 |
|
91 UcxDlist *setProps; /* XmlElement list, set props */ |
|
92 UcxDlist *removeProps; /* DavProperty list, remove props */ |
|
93 |
|
94 Propstat *propstat; |
|
95 XmlNsMap *nsmap; |
|
96 |
|
97 DAVPropertyBackend *backend; |
|
98 |
|
99 |
|
100 sbuf_t *out; |
|
101 }; |
|
102 |
|
103 struct Propstat { |
|
104 UcxDlist *okprop; /* properties with status 200 OK */ |
|
105 UcxMap *map; /* all other properties */ |
|
106 pool_handle_t *pool; |
|
107 }; |
|
108 |
|
109 struct DavProperty { |
|
110 char *xmlns; |
|
111 char *name; |
|
112 }; |
|
113 |
|
114 struct XmlData { |
|
115 XmlNsMap *nsmap; |
|
116 XmlElement *elm; |
|
117 }; |
|
118 |
|
119 struct XmlElement { |
|
120 XmlNs *xmlns; |
|
121 sstr_t name; |
|
122 void *content; /* xmlch* or UcxDlist* */ |
|
123 size_t ctlen; /* content string length. If 0, content is a UcxDlist */ |
|
124 }; |
|
125 |
|
126 struct XmlNs { |
|
127 char *xmlns; |
|
128 char *prefix; |
|
129 int nslen; |
|
130 int prelen; |
|
131 }; |
|
132 |
|
133 struct XmlNsMap { |
|
134 UcxMap *map; |
|
135 pool_handle_t *pool; |
|
136 }; |
|
137 |
|
138 /* |
|
139 * dav_propfind_f |
|
140 * |
|
141 * Gets all requested properties for a WebDAV resource(file). This function |
|
142 * should add properties with dav_propfind_add_str_prop or |
|
143 * dav_prop_add_xml_prop. Unavailable properties should be added with |
|
144 * dav_propfind_add_prop_error |
|
145 * |
|
146 * |
|
147 * arg0: property backend |
|
148 * arg1: current PropfindRequest object |
|
149 * arg2: the webdav resource path |
|
150 */ |
|
151 typedef void(*dav_propfind_f)(DAVPropertyBackend*,PropfindRequest*,char*); |
|
152 |
|
153 /* |
|
154 * dav_proppatch_f |
|
155 * |
|
156 * Sets properties for a WebDAV resource. It should add all properties to the |
|
157 * propstat object (member of the ProppatchRequest). |
|
158 * |
|
159 * arg0: WebDAV backend |
|
160 * arg1: current ProppatchRequest object |
|
161 */ |
|
162 typedef void(*dav_proppatch_f)(DAVPropertyBackend*,ProppatchRequest*); |
|
163 |
|
164 struct DAVPropertyBackend { |
|
165 dav_propfind_f propfind; |
|
166 dav_proppatch_f proppatch; |
|
167 }; |
|
168 |
|
169 int webdav_service(pblock *pb, Session *sn, Request *rq); |
|
170 int webdav_put(pblock *pb, Session *sn, Request *rq); |
|
171 int webdav_delete(pblock *pb, Session *sn, Request *rq); |
|
172 int webdav_mkcol(pblock *pb, Session *sn, Request *rq); |
|
173 int webdav_copy(pblock *pb, Session *sn, Request *rq); |
|
174 int webdav_move(pblock *pb, Session *sn, Request *rq); |
|
175 int webdav_propfind(pblock *pb, Session *sn, Request *rq); |
|
176 int webdav_proppatch(pblock *pb, Session *sn, Request *rq); |
|
177 |
47 |
178 void dav_resource_response(PropfindRequest *rq, sstr_t path, sstr_t uri); |
48 void dav_resource_response(PropfindRequest *rq, sstr_t path, sstr_t uri); |
179 |
49 |
180 /* |
|
181 * dav_propfind_add_str_prop |
|
182 * |
|
183 * Adds a string property to the current WebDAV resource response |
|
184 */ |
|
185 void dav_propfind_add_str_prop( |
|
186 PropfindRequest *rq, |
|
187 DavProperty* prop, |
|
188 char *str, |
|
189 size_t len); |
|
190 |
|
191 //void dav_propfind_add_xml_prop(); |
|
192 |
|
193 /* |
|
194 * dav_propfind_add_prop_error |
|
195 * |
|
196 * Adds a unavailable property to the response |
|
197 * |
|
198 * rq: propfind request object |
|
199 * prop: unavailable property |
|
200 * error: HTTP status code |
|
201 */ |
|
202 void dav_propfind_add_prop_error( |
|
203 PropfindRequest *rq, |
|
204 DavProperty *prop, |
|
205 int error); |
|
206 |
50 |
207 |
51 |
|
52 PersistenceManager* create_property_backend(); |
|
53 void dav_rq_propfind(PersistenceManager *b, PropfindRequest *rq, char *path); |
|
54 void dav_rq_proppatch(PersistenceManager *b, ProppatchRequest *rq); |
208 |
55 |
209 DAVPropertyBackend* create_property_backend(); |
|
210 void dav_rq_propfind(DAVPropertyBackend *b, PropfindRequest *rq, char *path); |
|
211 void dav_rq_proppatch(DAVPropertyBackend *b, ProppatchRequest *rq); |
|
212 |
|
213 /*---------------------------------- utils ----------------------------------*/ |
|
214 |
|
215 /* |
|
216 * XmlNsMap |
|
217 * |
|
218 * a map containing xml namespaces |
|
219 * |
|
220 * key: namespace uri |
|
221 * value: XmlNs object, containing namespace uri and the prefix |
|
222 */ |
|
223 |
|
224 XmlNsMap* xmlnsmap_create(pool_handle_t *pool); |
|
225 |
|
226 void xmlnsmap_free(XmlNsMap *map); |
|
227 |
|
228 /* |
|
229 * Puts a namespace in the map. If the namespace is already in the map, the |
|
230 * available XmlNs object is returned |
|
231 */ |
|
232 XmlNs* xmlnsmap_put(XmlNsMap *map, char *ns); |
|
233 |
|
234 /* |
|
235 * Gets a namespace from the map. Returns NULL if the namespace is not in the |
|
236 * map |
|
237 */ |
|
238 XmlNs* xmlnsmap_get(XmlNsMap *map, char *ns); |
|
239 |
|
240 |
|
241 |
|
242 /* |
|
243 * XmlElement |
|
244 * |
|
245 * representing a xml element |
|
246 */ |
|
247 |
|
248 /* |
|
249 * adds a xml element to a parent element |
|
250 */ |
|
251 void xmlelm_add_child(XmlElement *parent, XmlElement *child); |
|
252 |
|
253 /* |
|
254 * writes an xml element to an output buffer |
|
255 * if wv is true, it writes the complete value of the element |
|
256 */ |
|
257 void xmlelm_write(XmlElement *elm, sbuf_t *out, int wv); |
|
258 |
|
259 |
|
260 /* |
|
261 * PropstatMap |
|
262 * |
|
263 * A map containing multiple propstat objects |
|
264 * |
|
265 * key: status code: int |
|
266 * value: prop list: UcxDlist* (list of XmlElement*) |
|
267 */ |
|
268 |
|
269 |
|
270 /* |
|
271 * creates a new Propstat |
|
272 */ |
|
273 Propstat* propstat_create(pool_handle_t *pool); |
|
274 |
|
275 |
|
276 /* |
|
277 * adds a property to the propstat map |
|
278 * |
|
279 * propstat: propstat object |
|
280 * status: http status code |
|
281 * prop: WebDAV property |
|
282 */ |
|
283 void propstat_add(Propstat *propstat, int status, XmlElement *prop); |
|
284 |
|
285 /* |
|
286 * writes the propstat object to an output buffer |
|
287 * if wv is true, it writes the values of the 'OK' properties |
|
288 * |
|
289 * propstat: propstat object |
|
290 * out: output buffer |
|
291 * wv: property output mode |
|
292 */ |
|
293 void propstat_write(Propstat *propstat, sbuf_t *out, int wv); |
|
294 |
56 |
295 #ifdef __cplusplus |
57 #ifdef __cplusplus |
296 } |
58 } |
297 #endif |
59 #endif |
298 |
60 |