2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 2018 Olaf Wintermann. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
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.
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.
34 #include <ucx/mempool.h>
36 #include <ucx/buffer.h>
37 #include <curl/curl.h>
38 #include <libxml/tree.h>
52 typedef struct DavContext DavContext;
53 typedef struct DavProxy DavProxy;
54 typedef struct DavSession DavSession;
55 typedef struct DavResource DavResource;
56 typedef struct DavResult DavResult;
57 typedef struct DavNamespace DavNamespace;
58 typedef struct DavProperty DavProperty;
59 typedef struct DavPropName DavPropName;
60 typedef struct DavKey DavKey;
61 typedef struct DavNSInfo DavNSInfo;
62 typedef struct DavXmlNode DavXmlNode;
63 typedef struct DavXmlAttr DavXmlAttr;
65 typedef size_t(*dav_read_func)(void*, size_t, size_t, void*);
66 typedef size_t(*dav_write_func)(const void*, size_t, size_t, void*);
67 typedef int(*dav_seek_func)(const void *, long, int);
69 typedef int(*dav_auth_func)(DavSession *, void *);
70 typedef void(*dav_progress_func)(DavResource *, int64_t, int64_t, void *);
78 DAV_METHOD_NOT_ALLOWED,
81 DAV_UNSUPPORTED_PROTOCOL,
82 DAV_COULDNT_RESOLVE_PROXY,
83 DAV_COULDNT_RESOLVE_HOST,
88 DAV_CONTENT_VERIFICATION_ERROR,
89 DAV_PRECONDITION_FAILED,
90 DAV_REQUEST_ENTITY_TOO_LARGE,
91 DAV_REQUEST_URL_TOO_LONG,
92 DAV_PROXY_AUTH_REQUIRED,
96 typedef enum DavError DavError;
104 typedef enum DavXmlNodeType DavXmlNodeType;
106 #define DAV_SESSION_ENCRYPT_CONTENT 0x0001
107 #define DAV_SESSION_ENCRYPT_NAME 0x0002
108 #define DAV_SESSION_ENCRYPT_PROPERTIES 0x0004
109 #define DAV_SESSION_DECRYPT_CONTENT 0x0008
110 #define DAV_SESSION_DECRYPT_NAME 0x0010
111 #define DAV_SESSION_DECRYPT_PROPERTIES 0x0020
112 #define DAV_SESSION_STORE_HASH 0x0040
114 #define DAV_SESSION_CONTENT_ENCRYPTION 0x0009
115 #define DAV_SESSION_FULL_ENCRYPTION 0x003f
118 #define DAV_NS "http://davutils.org/"
119 #define DAV_PROPS_NS "http://davutils.org/props/"
121 struct DavNamespace {
131 DavResource *children;
135 uint64_t contentlength;
156 int(*auth_prompt)(DavSession *sn, void *userdata);
157 void *authprompt_userdata;
159 void(*get_progress)(DavResource *res, int64_t total, int64_t now, void *userdata);
160 void(*put_progress)(DavResource *res, int64_t total, int64_t now, void *userdata);
161 void *progress_userdata;
166 UcxMap *namespaceinfo;
169 DavProxy *http_proxy;
170 DavProxy *https_proxy;
196 #define DAV_KEY_AES128 0
197 #define DAV_KEY_AES256 1
219 DavXmlNode *children;
222 DavXmlAttr *attributes;
225 size_t contentlength;
234 DavContext* dav_context_new(void);
235 void dav_context_destroy(DavContext *ctx);
237 void dav_context_add_key(DavContext *context, DavKey *key);
238 DavKey* dav_context_get_key(DavContext *context, char *name);
240 int dav_add_namespace(DavContext *context, const char *prefix, const char *ns);
241 DavNamespace* dav_get_namespace(DavContext *context, const char *prefix);
243 int dav_enable_namespace_encryption(DavContext *context, const char *ns, DavBool encrypt);
244 int dav_namespace_is_encrypted(DavContext *context, const char *ns);
246 DavSession* dav_session_new(DavContext *context, char *base_url);
247 DavSession* dav_session_new_auth(
252 void dav_session_set_auth(DavSession *sn, char *user, char *password);
253 void dav_session_set_baseurl(DavSession *sn, char *base_url);
254 void dav_session_enable_encryption(DavSession *sn, DavKey *key, int flags);
256 void dav_session_set_authcallback(DavSession *sn, dav_auth_func func, void *userdata);
257 void dav_session_set_progresscallback(DavSession *sn, dav_progress_func get, dav_progress_func put, void *userdata);
259 void dav_session_destroy(DavSession *sn);
261 void* dav_session_malloc(DavSession *sn, size_t size);
262 void* dav_session_calloc(DavSession *sn, size_t nelm, size_t size);
263 void* dav_session_realloc(DavSession *sn, void *ptr, size_t size);
264 void dav_session_free(DavSession *sn, void *ptr);
265 char* dav_session_strdup(DavSession *sn, const char *str);
267 void dav_set_effective_href(DavSession *sn, DavResource *resource);
268 DavResource* dav_get(DavSession *sn, char *path, char *properties);
270 UcxList* parse_properties_string(DavContext *context, sstr_t str);
272 DavResource* dav_query(DavSession *sn, char *query, ...);
274 sstr_t dav_property_key(const char *ns, const char *name);
275 void dav_get_property_namespace_str(
280 DavNamespace* dav_get_property_namespace(
285 /* ------------------------ resource functions ------------------------ */
287 DavResource* dav_resource_new(DavSession *sn, char *path);
288 DavResource* dav_resource_new_child(DavSession *sn, DavResource *parent, char *name);
289 DavResource* dav_resource_new_href(DavSession *sn, char *href);
291 void dav_resource_free(DavResource *res);
292 void dav_resource_free_all(DavResource *res);
294 char* dav_resource_get_href(DavResource *resource);
296 DavResource* dav_create_child(DavResource *parent, char *name);
297 int dav_delete(DavResource *res);
298 int dav_create(DavResource *res);
299 int dav_exists(DavResource *res);
301 int dav_copy(DavResource *res, char *newpath);
302 int dav_move(DavResource *res, char *newpath);
303 int dav_copy_o(DavResource *res, char *newpath, DavBool override);
304 int dav_move_o(DavResource *res, char *newpath, DavBool override);
305 int dav_copyto(DavResource *res, char *url, DavBool override);
306 int dav_moveto(DavResource *res, char *url, DavBool override);
308 int dav_lock(DavResource *res);
309 int dav_lock_t(DavResource *res, time_t timeout);
310 int dav_unlock(DavResource *res);
312 DavXmlNode* dav_get_property(DavResource *res, char *name);
313 DavXmlNode* dav_get_property_ns(DavResource *res, const char *ns, const char *name);
314 DavXmlNode* dav_get_encrypted_property_ns(DavResource *res, const char *ns, const char *name);
315 char* dav_get_string_property(DavResource *res, char *name);
316 char* dav_get_string_property_ns(DavResource *res, char *ns, char *name);
317 void dav_set_string_property(DavResource *res, char *name, char *value);
318 void dav_set_string_property_ns(DavResource *res, char *ns, char *name, char *value);
319 void dav_set_property(DavResource *res, char *name, DavXmlNode *value);
320 void dav_set_property_ns(DavResource *res, char *ns, char *name, DavXmlNode *value);
321 void dav_remove_property(DavResource *res, char *name);
322 void dav_remove_property_ns(DavResource *res, char *ns, char *name);
323 void dav_set_encrypted_property_ns(DavResource *res, char *ns, char *name, DavXmlNode *value);
324 void dav_set_encrypted_string_property_ns(DavResource *res, char *ns, char *name, char *value);
325 void dav_remove_encrypted_property_ns(DavResource *res, char *ns, char *name);
327 DavPropName* dav_get_property_names(DavResource *res, size_t *count);
329 void dav_set_content(DavResource *res, void *stream, dav_read_func read_func, dav_seek_func seek_func);
330 void dav_set_content_data(DavResource *res, char *content, size_t length);
331 void dav_set_content_length(DavResource *res, size_t length);
333 int dav_load(DavResource *res);
334 int dav_load_prop(DavResource *res, DavPropName *properties, size_t numprop);
335 int dav_store(DavResource *res);
336 int dav_get_content(DavResource *res, void *stream, dav_write_func write_func);
339 int dav_propfind(DavSession *sn, DavResource *root, UcxBuffer *rqbuf);
342 /* --------------------------- DeltaV ---------------------------- */
344 int dav_versioncontrol(DavResource *res);
345 int dav_checkout(DavResource *res);
346 int dav_checkin(DavResource *res);
347 int dav_uncheckout(DavResource *res);
348 DavResource* dav_versiontree(DavResource *res, char *properties);
350 /* ------------------------ xml functions ------------------------ */
351 char* dav_xml_getstring(DavXmlNode *node);
352 DavBool dav_xml_isstring(DavXmlNode *node);
353 DavXmlNode* dav_xml_nextelm(DavXmlNode *node);
354 DavXmlNode* dav_text_node(DavSession *sn, char *text);
356 DavXmlNode* dav_copy_node(DavXmlNode *node);
358 DavXmlNode* dav_xml_createnode(const char *ns, const char *name);
359 DavXmlNode* dav_xml_createnode_with_text(const char *ns, const char *name, const char *text);
360 DavXmlNode* dav_xml_createtextnode(const char *text);
361 void dav_xml_add_child(DavXmlNode *node, DavXmlNode *child);
362 void dav_xml_add_attr(DavXmlNode *node, const char *name, const char *value);
363 char* dav_xml_get_attr(DavXmlNode *node, const char *name);
365 DavXmlNode* dav_parse_xml(DavSession *sn, const char *str, size_t len);
371 #endif /* WEBDAV_H */