diff -r e8619defde14 -r 27c7511c0e34 src/server/webdav/webdav.h --- a/src/server/webdav/webdav.h Wed May 16 12:47:28 2012 +0200 +++ b/src/server/webdav/webdav.h Thu May 24 12:51:52 2012 +0200 @@ -34,6 +34,8 @@ #include #include +#include + #include "../ucx/map.h" #include "../ucx/dlist.h" #include "../util/strbuf.h" @@ -51,10 +53,18 @@ typedef struct PropfindRequest PropfindRequest; typedef struct ProppatchRequest ProppatchRequest; typedef struct DavProperty DavProperty; -typedef struct DavPropertyCt DavPropertyCt; + +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; @@ -81,7 +91,19 @@ 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 { @@ -89,42 +111,66 @@ char *name; }; -struct DavPropertyCt { - char *xmlns; - char *name; - DavPropertyCt **props; - int npr; +struct XmlData { + XmlNsMap *nsmap; + XmlElement *elm; }; struct XmlElement { - char *xmlns; - char *name; - char *content; - int *ctlen; - int *numelm; - XmlElement **elms; + 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; }; /* - * dav_res_propfind_f + * dav_propfind_f * - * Gets all requested properties of a WebDAV resource(file). This function + * 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_res_propfind_f)(DAVPropertyBackend*,PropfindRequest*,char*); +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_res_propfind_f propfind; + 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); @@ -160,7 +206,90 @@ DAVPropertyBackend* create_property_backend(); -void dav_rq_propfind(DAVPropertyBackend *b,PropfindRequest *rq ,char *path); +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(); + +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 + */ + +/* + * 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 }