src/server/public/webdav.h

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

mercurial