src/server/public/webdav.h

Thu, 31 Oct 2019 10:26:35 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 31 Oct 2019 10:26:35 +0100
branch
webdav
changeset 211
2160585200ac
parent 107
7e81699d1f77
child 212
d7e7ea9c6bc6
permissions
-rw-r--r--

add propfind/proppatch parser and first iteration of the new webdav api

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright 2018 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 WS_WEBDAV_H
#define	WS_WEBDAV_H

#include "nsapi.h"
#include "vfs.h"

#include <sys/file.h>
#include <sys/stat.h>
#include <inttypes.h>

#ifdef	__cplusplus
extern "C" {
#endif

typedef struct WebdavBackend          WebdavBackend;
    
typedef struct WebdavProperty         WebdavProperty;
typedef struct WebdavPList            WebdavPList;

typedef enum   WebdavLockScope        WebdavLockScope;
typedef enum   WebdavLockType         WebdavLockType;

typedef struct WebdavPropfindRequest  WebdavPropfindRequest;
typedef struct WebdavProppatchRequest WebdavProppatchRequest;
typedef struct WebdavLockRequest      WebdavLockRequest;

typedef struct WebdavResponse         WebdavResponse;
typedef struct WebdavResource         WebdavResource;

typedef struct WebdavVFSProperties    WebdavVFSProperties;

typedef struct _xmlNs   WSNamespace;
typedef struct _xmlNode WSXmlNode;

#define WS_NODE_ELEMENT        1
#define WS_NODE_TEXT           3
#define WS_NODE_CDATA          4
#define WS_NODE_ENTITY_REF     5

/* propfind settings */

/*
 * Don't use the vfs to stat files or read the directory children
 */
#define WS_PROPFIND_NO_VFS 0x01

struct WebdavProperty {
    WSNamespace *namespace;
    
    const char *name;
    
    char *lang;
    
    WSXmlNode *value;
};

struct WebdavPList {
    WebdavProperty *property;
    WebdavPList *prev;
    WebdavPList *next;
};

enum WebdavLockScope {
    WEBDAV_LOCK_EXCLUSIVE = 0,
    WEBDAV_LOCK_SHARED,
    WEBDAV_LOCK_SCOPE_UNKNOWN
};

enum WebdavLockType {
    WEBDAV_LOCK_WRITE = 0,
    WEBDAV_LOCK_TYPE_UNKNOWN
};

struct WebdavPropfindRequest {
    Session *sn;
    Request *rq;

    void *doc;
      
    /*
     * list of requested properties
     */
    WebdavPList *properties;
    
    /*
     * number of properties
     */
    size_t propcount;
    
    WSBool allprop;
    WSBool propname;
    
    int depth;
    
    /*
     * custom userdata for the backend
     */
    void *userdata;
};

struct WebdavProppatchRequest {
    Session *sn;
    Request *rq;
    
    void *doc;
    
    WebdavPList *set;
    size_t setcount;
    
    WebdavPList *remove;
    size_t removecount;
};

struct WebdavLockRequest {
    Session *sn;
    Request *rq;
    
    void *doc;
    
    WebdavLockScope scope;
    WebdavLockType type;
    
    WSXmlNode *owner;
};

struct WebdavVFSProperties {
    uint32_t getcontentlength:1;
    uint32_t getlastmodified:1;
    uint32_t getresourcetype:1;
    uint32_t getetag:1;
    uint32_t creationdate:1;
};

struct WebdavResponse {
    WebdavResource* (*addresource)(WebdavResponse*, const char*);
};

struct WebdavResource {
    char *href;
    
    /*
     * int addprop(WebdavResource *res, WebdavProperty *property, int status);
     * 
     * Adds a property to the resource
     */
    int (*addproperty)(WebdavResource*, WebdavProperty*, int);
};

struct WebdavBackend {
    /*
     * int propfind_init(
     *     WebdavPropfindRequest *rq,
     *     const char *path,
     *     WebdavPList **outplist);
     * 
     * Initializes a propfind request. This is called once for each propfind
     * request and should initialize everything needed for generating the
     * multistatus response.
     * 
     * Optionally, the function can store a pointer to a list of all properties,
     * which will be processed by this backend, in the outplist argument.
     */
    int (*propfind_init)(WebdavPropfindRequest *, const char *, WebdavPList **);
    
    /*
     * int propfind_do(
     *     WebdavPropfindRequest *rq,
     *     WebdavResponse *response,
     *     VFS_DIR parent,
     *     const char *path,
     *     struct stat *s);
     * 
     * This function is called for the requsted resource and for all children
     * if WS_PROPFIND_NO_VFS_CHILDREN is not set.
     */
    int (*propfind_do)(
            WebdavPropfindRequest *,
            WebdavResponse *,
            VFS_DIR,
            const char *,
            struct stat *);
    
    /*
     * int propfind_finish(WebdavPropfindRequest *rq);
     * 
     * Finishes a propfind request.
     */
    int (*propfind_finish)(WebdavPropfindRequest *);
    
    /*
     * See the WS_PROPFIND_ macros for informations about the settings
     */
    uint32_t settings;
};

int webdav_getdepth(Request *rq);

WSNamespace* webdav_dav_namespace(void);
WebdavProperty* webdav_dav_property(
        pool_handle_t *pool,
        const char *name);

int webdav_property_set_value(
        WebdavProperty *p,
        pool_handle_t *pool,
        char *value);

WebdavVFSProperties webdav_vfs_properties(
        WebdavPropfindRequest *rq,
        WSBool removefromlist,
        uint32_t flags);

int webdav_add_vfs_properties(
        WebdavResource *res,
        pool_handle_t *pool,
        WebdavVFSProperties properties,
        struct stat *s);

#ifdef	__cplusplus
}
#endif

#endif	/* WS_WEBDAV_H */

mercurial