--- a/src/server/webdav/webdav.h Tue Mar 19 17:38:32 2013 +0100 +++ b/src/server/webdav/webdav.h Mon May 06 13:44:27 2013 +0200 @@ -29,12 +29,7 @@ #ifndef WEBDAV_H #define WEBDAV_H -#include "../public/nsapi.h" - -#include <sys/file.h> -#include <sys/stat.h> - -#include <inttypes.h> +#include "../public/webdav.h" #include "../ucx/map.h" #include "../ucx/dlist.h" @@ -46,251 +41,18 @@ #define DAV_FOREACH(elem, list) \ for (UcxDlist *elem = list ; elem != NULL ; elem = elem->next) - -typedef struct PropfindResponse PropfindResponse; -typedef struct DAVPropertyBackend DAVPropertyBackend; -typedef struct PropfindRequest PropfindRequest; -typedef struct ProppatchRequest ProppatchRequest; -typedef struct DavProperty DavProperty; - -typedef struct Propstat Propstat; - -typedef struct XmlNs XmlNs; -typedef struct XmlNsMap XmlNsMap; - -typedef struct XmlData XmlData; -typedef struct XmlElement XmlElement; - -typedef uint8_t xmlch_t; - - -struct PropfindRequest { - Session *sn; - Request *rq; - - UcxDlist *properties; /* DavProperty list, requested props */ - int8_t allprop; - int8_t propname; - - int8_t prop; - UcxDlist *notFoundProps; - UcxDlist *forbiddenProps; - DAVPropertyBackend *propertyBackend; - - char *path; - char *uri; - - sbuf_t *out; -}; - -struct ProppatchRequest { - Session *sn; - Request *rq; - - UcxDlist *setProps; /* XmlElement list, set props */ - UcxDlist *removeProps; /* DavProperty list, remove props */ - - Propstat *propstat; - XmlNsMap *nsmap; - - DAVPropertyBackend *backend; - - - sbuf_t *out; -}; - -struct Propstat { - UcxDlist *okprop; /* properties with status 200 OK */ - UcxMap *map; /* all other properties */ - pool_handle_t *pool; -}; - -struct DavProperty { - char *xmlns; - char *name; -}; - -struct XmlData { - XmlNsMap *nsmap; - XmlElement *elm; -}; - -struct XmlElement { - XmlNs *xmlns; - sstr_t name; - void *content; /* xmlch* or UcxDlist* */ - size_t ctlen; /* content string length. If 0, content is a UcxDlist */ -}; - -struct XmlNs { - char *xmlns; - char *prefix; - int nslen; - int prelen; -}; - -struct XmlNsMap { - UcxMap *map; - pool_handle_t *pool; -}; - -/* - * dav_propfind_f - * - * Gets all requested properties for a WebDAV resource(file). This function - * should add properties with dav_propfind_add_str_prop or - * dav_prop_add_xml_prop. Unavailable properties should be added with - * dav_propfind_add_prop_error - * - * - * arg0: property backend - * arg1: current PropfindRequest object - * arg2: the webdav resource path - */ -typedef void(*dav_propfind_f)(DAVPropertyBackend*,PropfindRequest*,char*); - -/* - * dav_proppatch_f - * - * Sets properties for a WebDAV resource. It should add all properties to the - * propstat object (member of the ProppatchRequest). - * - * arg0: WebDAV backend - * arg1: current ProppatchRequest object - */ -typedef void(*dav_proppatch_f)(DAVPropertyBackend*,ProppatchRequest*); - -struct DAVPropertyBackend { - dav_propfind_f propfind; - dav_proppatch_f proppatch; -}; - -int webdav_service(pblock *pb, Session *sn, Request *rq); -int webdav_put(pblock *pb, Session *sn, Request *rq); -int webdav_delete(pblock *pb, Session *sn, Request *rq); -int webdav_mkcol(pblock *pb, Session *sn, Request *rq); -int webdav_copy(pblock *pb, Session *sn, Request *rq); -int webdav_move(pblock *pb, Session *sn, Request *rq); -int webdav_propfind(pblock *pb, Session *sn, Request *rq); -int webdav_proppatch(pblock *pb, Session *sn, Request *rq); +int webdav_init(pblock *pb, Session *sn, Request *rq); +int webdav_setcollection(pblock *pb, Session *sn, Request *rq); void dav_resource_response(PropfindRequest *rq, sstr_t path, sstr_t uri); -/* - * dav_propfind_add_str_prop - * - * Adds a string property to the current WebDAV resource response - */ -void dav_propfind_add_str_prop( - PropfindRequest *rq, - DavProperty* prop, - char *str, - size_t len); - -//void dav_propfind_add_xml_prop(); - -/* - * dav_propfind_add_prop_error - * - * Adds a unavailable property to the response - * - * rq: propfind request object - * prop: unavailable property - * error: HTTP status code - */ -void dav_propfind_add_prop_error( - PropfindRequest *rq, - DavProperty *prop, - int error); - -DAVPropertyBackend* create_property_backend(); -void dav_rq_propfind(DAVPropertyBackend *b, PropfindRequest *rq, char *path); -void dav_rq_proppatch(DAVPropertyBackend *b, ProppatchRequest *rq); - -/*---------------------------------- utils ----------------------------------*/ - -/* - * XmlNsMap - * - * a map containing xml namespaces - * - * key: namespace uri - * value: XmlNs object, containing namespace uri and the prefix - */ - -XmlNsMap* xmlnsmap_create(pool_handle_t *pool); - -void xmlnsmap_free(XmlNsMap *map); - -/* - * Puts a namespace in the map. If the namespace is already in the map, the - * available XmlNs object is returned - */ -XmlNs* xmlnsmap_put(XmlNsMap *map, char *ns); - -/* - * Gets a namespace from the map. Returns NULL if the namespace is not in the - * map - */ -XmlNs* xmlnsmap_get(XmlNsMap *map, char *ns); - - - -/* - * XmlElement - * - * representing a xml element - */ +PersistenceManager* create_property_backend(); +void dav_rq_propfind(PersistenceManager *b, PropfindRequest *rq, char *path); +void dav_rq_proppatch(PersistenceManager *b, ProppatchRequest *rq); -/* - * adds a xml element to a parent element - */ -void xmlelm_add_child(XmlElement *parent, XmlElement *child); - -/* - * writes an xml element to an output buffer - * if wv is true, it writes the complete value of the element - */ -void xmlelm_write(XmlElement *elm, sbuf_t *out, int wv); - - -/* - * PropstatMap - * - * A map containing multiple propstat objects - * - * key: status code: int - * value: prop list: UcxDlist* (list of XmlElement*) - */ - - -/* - * creates a new Propstat - */ -Propstat* propstat_create(pool_handle_t *pool); - - -/* - * adds a property to the propstat map - * - * propstat: propstat object - * status: http status code - * prop: WebDAV property - */ -void propstat_add(Propstat *propstat, int status, XmlElement *prop); - -/* - * writes the propstat object to an output buffer - * if wv is true, it writes the values of the 'OK' properties - * - * propstat: propstat object - * out: output buffer - * wv: property output mode - */ -void propstat_write(Propstat *propstat, sbuf_t *out, int wv); #ifdef __cplusplus }