diff -r c9d37bb97ea8 -r 0bbbb0341606 libidav/webdav.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libidav/webdav.h Mon Aug 26 14:42:09 2013 +0200 @@ -0,0 +1,174 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WEBDAV_H +#define WEBDAV_H + +#include +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct DavContext DavContext; +typedef struct DavSession DavSession; +typedef struct DavResource DavResource; +typedef struct DavRequest DavRequest; +typedef struct DavNamespace DavNamespace; +typedef struct DavProperty DavProperty; + +#include "davql.h" + +typedef size_t(*dav_read_func)(void*, size_t, size_t, void*); +typedef size_t(*dav_write_func)(const void*, size_t, size_t, void*); + +enum DavError { + DAV_OK = 0, + DAV_ERROR, + DAV_NOT_FOUND, + DAV_UNAUTHORIZED, + DAV_FORBIDDEN, + DAV_METHOD_NOT_ALLOWED, + DAV_CONFLICT +}; + +typedef enum DavError DavError; + +struct DavNamespace { + char *prefix; + char *name; +}; + +struct DavResource { + DavSession *session; + DavResource *prev; + DavResource *next; + DavResource *parent; + DavResource *children; + char *name; + char *path; + char *href; + uint64_t contentlength; + char *contenttype; + time_t creationdate; + time_t lastmodified; + void *data; + int iscollection; +}; + +struct DavSession { + DavContext *context; + CURL *handle; + char *base_url; + UcxMempool *mp; + UcxAllocator *allocator; + DavError error; + const char *errorstr; +}; + +struct DavContext { + UcxMap *namespaces; + UcxList *sessions; + char *http_proxy; + char *https_proxy; + char *no_proxy; +}; + +struct DavProperty { + DavNamespace *ns; + char *name; + char *value; +}; + +DavContext* dav_context_new(); +void dav_context_destroy(DavContext *ctx); +int dav_add_namespace(DavContext *context, char *prefix, char *ns); +DavNamespace* dav_get_namespace(DavContext *context, char *prefix); + +DavSession* dav_session_new(DavContext *context, char *base_url); +DavSession* dav_session_new_auth( + DavContext *context, + char *base_url, + char *user, + char *password); +void dav_session_set_auth(DavSession *sn, char *user, char *password); + +void session_set_error(DavSession *sn, CURLcode c, int status); + +void dav_session_destroy(DavSession *sn); + +DavResource* dav_get(DavSession *sn, char *path, char *properties); +DavResource* dav_get2(DavSession *sn, DavGetQuery *query); + +UcxList* parse_properties_string(DavContext *context, sstr_t str); + +DavResource* dav_query(DavSession *sn, char *query, ...); + +UcxKey dav_property_key(char *ns, char *name); +void dav_get_property_namespace( + DavContext *ctx, + char *prefixed_name, + char **ns, + char **name); + +/* ------------------------ resource functions ------------------------ */ + +DavResource* dav_resource_new(DavSession *sn, char *path); +DavResource* dav_resource_new_href(DavSession *sn, char *href); + +DavResource* dav_create_child(DavResource *parent, char *name); +int dav_delete(DavResource *res); +int dav_create(DavResource *res); +int dav_exists(DavResource *res); + +char* dav_get_property(DavResource *res, char *name); +char* dav_get_property_ns(DavResource *res, char *ns, char *name); +void dav_set_property(DavResource *res, char *name, char *value); +void dav_set_property_ns(DavResource *res, char *ns, char *name, char *value); +void dav_remove_property(DavResource *res, char *name); +void dav_remove_property_ns(DavResource *res, char *ns, char *name); + +void dav_set_content(DavResource *res, void *stream, dav_read_func read_func); +void dav_set_content_data(DavResource *res, char *content, size_t length); + +int dav_load(DavResource *res); +int dav_store(DavResource *res); +int dav_get_content(DavResource *res, void *stream, dav_write_func write_func); + +#ifdef __cplusplus +} +#endif + +#endif /* WEBDAV_H */ +