dav/webdav.h

Thu, 22 Aug 2013 12:45:12 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 22 Aug 2013 12:45:12 +0200
changeset 29
938957a4eea7
parent 27
e584c351b402
permissions
-rw-r--r--

added date command

/*
 * 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 <inttypes.h>
#include <ucx/map.h>
#include <ucx/mempool.h>
#include <ucx/list.h>
#include <ucx/buffer.h>
#include <curl/curl.h>
#include <libxml/tree.h>

#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 DavNodeData   DavNodeData;
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;
    DavNodeData   *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 dav_content_data {
    char   *data;
    size_t length;
};

struct dav_content_stream {
    void      *stream;
    read_func read;
};

struct DavNodeData {
    UcxMap  *properties;
    UcxList *set;
    UcxList *remove;
    
    /*
     * char* or stream
     */
    void      *content;
    /*
     * if NULL, content is a char*
     */
    read_func read;
    /*
     * content length
     */
    size_t    length;
};

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, ...);

DavResource* dav_resource_new(DavSession *sn, char *path);
DavResource* resource_new_href(DavSession *sn, char *href);

void resource_add_property(DavResource *res, char *ns, char *name, char *value);
void resource_add_child(DavResource *parent, DavResource *child);
UcxKey dav_property_key(char *ns, char *name);
void resource_set_info(DavResource *res, char *href);
DavNodeData* node_data_new(DavSession *sn);

int dav_load(DavResource *res);
int dav_store(DavResource *res);

void get_property_namespace(
        DavContext *ctx,
        char *prefixed_name,
        char **ns,
        char **name);

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_get_content(DavResource *res, void *stream, dav_write_func write_func);

int dav_delete(DavResource *res);
int dav_create(DavResource *res);

int dav_exists(DavResource *res);

#ifdef	__cplusplus
}
#endif

#endif	/* WEBDAV_H */

mercurial