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