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 WS_WEBDAV_H
30 #define WS_WEBDAV_H
31
32 #include "nsapi.h"
33 #include "vfs.h"
34
35 #include <sys/file.h>
36 #include <sys/stat.h>
37 #include <inttypes.h>
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 typedef struct WebdavBackend WebdavBackend;
44
45 typedef struct WebdavProperty WebdavProperty;
46 typedef struct WebdavPList WebdavPList;
47 typedef struct WebdavNSList WebdavNSList;
48
49 typedef struct WebdavPListIterator WebdavPListIterator;
50
51 typedef enum WebdavLockScope WebdavLockScope;
52 typedef enum WebdavLockType WebdavLockType;
53
54 typedef enum WebdavValueType WebdavValueType;
55
56 typedef struct WebdavPropfindRequest WebdavPropfindRequest;
57 typedef struct WebdavProppatchRequest WebdavProppatchRequest;
58 typedef struct WebdavLockRequest WebdavLockRequest;
59
60 typedef struct WebdavVFSRequest WebdavVFSRequest;
61
62 typedef struct WebdavResponse WebdavResponse;
63 typedef struct WebdavResource WebdavResource;
64
65 typedef struct WebdavVFSProperties WebdavVFSProperties;
66
67 typedef struct WebdavOperation WebdavOperation;
68
69 typedef struct WSXmlData WSXmlData;
70 typedef struct WSText WSText;
71
72 typedef struct _xmlNs WSNamespace;
73 typedef struct _xmlNode WSXmlNode;
74
75 #define WS_NODE_ELEMENT 1
76 #define WS_NODE_TEXT 3
77 #define WS_NODE_CDATA 4
78 #define WS_NODE_ENTITY_REF 5
79
80 typedef int(*wsxml_func)(WSXmlNode *,
void *);
81
82
83
84
85
86
87 #define WS_WEBDAV_PROPFIND_USE_VFS 0x01
88
89
90
91
92 #define WS_WEBDAV_PROPPATCH_USE_VFS 0x02
93
94
95 typedef void*(*webdav_init_func)(ServerConfiguration *cfg,
pool_handle_t *pool, WSConfigNode *config);
96 typedef WebdavBackend*(*webdav_create_func)(Session *sn, Request *rq, pblock *pb,
void *initData);
97
98 enum WebdavValueType {
99 WS_VALUE_NO_TYPE =
0,
100 WS_VALUE_XML_NODE,
101 WS_VALUE_XML_DATA,
102 WS_VALUE_TEXT
103 };
104
105 struct WSText {
106 char *str;
107 size_t length;
108 };
109
110 struct WSXmlData {
111 WebdavNSList *namespaces;
112 char *data;
113 size_t length;
114 };
115
116 struct WebdavProperty {
117 WSNamespace *namespace;
118
119 const char *name;
120
121 char *lang;
122
123 union {
124 WSXmlNode *node;
125 WSXmlData data;
126 WSText text;
127 } value;
128 WebdavValueType vtype;
129 };
130
131 struct WebdavPList {
132 WebdavProperty *property;
133 WebdavPList *prev;
134 WebdavPList *next;
135 };
136
137 struct WebdavNSList {
138 WSNamespace *namespace;
139 WebdavNSList *prev;
140 WebdavNSList *next;
141 };
142
143 struct WebdavPListIterator {
144 WebdavPList **list;
145 WebdavPList *cur;
146 WebdavPList *next;
147 size_t index;
148 };
149
150 enum WebdavLockScope {
151 WEBDAV_LOCK_EXCLUSIVE =
0,
152 WEBDAV_LOCK_SHARED,
153 WEBDAV_LOCK_SCOPE_UNKNOWN
154 };
155
156 enum WebdavLockType {
157 WEBDAV_LOCK_WRITE =
0,
158 WEBDAV_LOCK_TYPE_UNKNOWN
159 };
160
161 struct WebdavPropfindRequest {
162 Session *sn;
163 Request *rq;
164
165 WebdavBackend *dav;
166
167 void *doc;
168
169
170
171
172 WebdavPList *properties;
173
174
175
176
177 size_t propcount;
178
179 WSBool allprop;
180 WSBool propname;
181 WSBool deadproperties;
182
183 int depth;
184
185
186
187
188 void *userdata;
189 };
190
191 struct WebdavProppatchRequest {
192 Session *sn;
193 Request *rq;
194
195 WebdavBackend *dav;
196
197 void *doc;
198
199 WebdavPList *set;
200 size_t setcount;
201
202 WebdavPList *remove;
203 size_t removecount;
204
205
206
207
208 void *userdata;
209 };
210
211 struct WebdavVFSRequest {
212 Session *sn;
213 Request *rq;
214
215 char *path;
216
217
218
219
220 void *userdata;
221 };
222
223 struct WebdavLockRequest {
224 Session *sn;
225 Request *rq;
226
227 void *doc;
228
229 WebdavLockScope scope;
230 WebdavLockType type;
231
232 WSXmlNode *owner;
233 };
234
235 struct WebdavVFSProperties {
236 uint32_t getcontentlength:
1;
237 uint32_t getlastmodified:
1;
238 uint32_t getresourcetype:
1;
239 uint32_t getetag:
1;
240 uint32_t creationdate:
1;
241 };
242
243 struct WebdavResponse {
244 WebdavOperation *op;
245
246 WebdavResource* (*addresource)(WebdavResponse*,
const char*);
247 };
248
249 struct WebdavResource {
250 char *href;
251
252 WSBool isclosed;
253
254 int err;
255
256
257
258
259
260
261 int (*addproperty)(WebdavResource*, WebdavProperty*,
int);
262
263
264
265
266
267
268 int (*close)(WebdavResource*);
269 };
270
271 struct WebdavBackend {
272
273
274
275
276
277
278
279
280
281
282
283
284 int (*propfind_init)(WebdavPropfindRequest *,
const char *,
const char *, WebdavPList **);
285
286
287
288
289
290
291
292
293
294
295
296
297 int (*propfind_do)(
298 WebdavPropfindRequest *,
299 WebdavResponse *,
300 VFS_DIR,
301 WebdavResource *,
302 struct stat *);
303
304
305
306
307
308
309 int (*propfind_finish)(WebdavPropfindRequest *);
310
311
312
313
314
315
316
317
318
319
320
321 int (*proppatch_do)(
322 WebdavProppatchRequest *,
323 WebdavResource *,
324 VFSFile *,
325 WebdavPList **,
326 WebdavPList **);
327
328
329
330
331
332
333
334
335
336
337
338
339 int (*proppatch_finish)(
340 WebdavProppatchRequest *,
341 WebdavResource *,
342 VFSFile *,
343 WSBool);
344
345
346
347
348
349
350
351 int (*opt_mkcol)(WebdavVFSRequest *, WSBool *);
352
353
354
355
356
357
358 int(*opt_mkcol_finish)(WebdavVFSRequest *, WSBool);
359
360
361
362
363
364
365
366
367
368 int (*opt_delete)(WebdavVFSRequest *, WSBool *);
369
370
371
372
373
374
375 int (*opt_delete_finish)(WebdavVFSRequest *, WSBool);
376
377
378
379
380 uint32_t settings;
381
382
383
384
385 void *instance;
386
387
388
389
390 WebdavBackend *next;
391 };
392
393
394
395
396 int webdav_register_backend(
const char *name, webdav_init_func webdavInit, webdav_create_func webdavCreate);
397
398 WebdavBackend* webdav_create(Session *sn, Request *rq,
const char *dav_class, pblock *pb,
void *initData);
399
400
401
402
403
404
405
406 int webdav_getdepth(Request *rq);
407
408 int webdav_plist_add(
409 pool_handle_t *pool,
410 WebdavPList **begin,
411 WebdavPList **end,
412 WebdavProperty *prop);
413
414 WebdavPList* webdav_plist_clone(
pool_handle_t *pool, WebdavPList *list);
415 WebdavPList* webdav_plist_clone_s(
416 pool_handle_t *pool,
417 WebdavPList *list,
418 size_t *newlen);
419
420 size_t webdav_plist_size(WebdavPList *list);
421
422 int webdav_nslist_add(
423 pool_handle_t *pool,
424 WebdavNSList **begin,
425 WebdavNSList **end,
426 WSNamespace *ns);
427
428 WebdavPListIterator webdav_plist_iterator(WebdavPList **list);
429 int webdav_plist_iterator_next(WebdavPListIterator *i, WebdavPList **cur);
430 void webdav_plist_iterator_remove_current(WebdavPListIterator *i);
431
432 WSNamespace* webdav_dav_namespace(
void);
433 WebdavProperty* webdav_resourcetype_collection(
void);
434 WebdavProperty* webdav_resourcetype_empty(
void);
435 WebdavProperty* webdav_dav_property(
436 pool_handle_t *pool,
437 const char *name);
438
439 int webdav_resource_add_dav_stringproperty(
440 WebdavResource *res,
441 pool_handle_t pool,
442 const char *name,
443 const char *str,
444 size_t len);
445 int webdav_resource_add_stringproperty(
446 WebdavResource *res,
447 pool_handle_t pool,
448 const char *xmlns_prefix,
449 const char *xmlns_href,
450 const char *name,
451 const char *str,
452 size_t len);
453
454 int webdav_property_set_value(
455 WebdavProperty *property,
456 pool_handle_t *pool,
457 char *value);
458
459 WebdavVFSProperties webdav_vfs_properties(
460 WebdavPList **plistInOut,
461 WSBool removefromlist,
462 WSBool appprop,
463 uint32_t flags);
464
465 int webdav_add_vfs_properties(
466 WebdavResource *res,
467 pool_handle_t *pool,
468 WebdavVFSProperties properties,
469 struct stat *s);
470
471 int wsxml_iterator(
472 pool_handle_t *pool,
473 WSXmlNode *node,
474 wsxml_func begincb,
475 wsxml_func endcb,
476 void *udata);
477
478 WebdavNSList* wsxml_get_required_namespaces(
479 pool_handle_t *pool,
480 WSXmlNode *node,
481 int *error);
482
483 WSXmlData* wsxml_node2data(
484 pool_handle_t *pool,
485 WSXmlNode *node);
486
487
488
489
490
491
492
493 char* wsxml_nslist2string(
pool_handle_t *pool, WebdavNSList *nslist);
494
495
496
497
498
499 WebdavNSList* wsxml_string2nslist(
pool_handle_t *pool,
char *nsliststr);
500
501 #ifdef __cplusplus
502 }
503 #endif
504
505 #endif
506
507