removed old webdav and expression code

Sat, 31 Oct 2015 16:39:12 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 31 Oct 2015 16:39:12 +0100
changeset 107
7e81699d1f77
parent 106
b122f34ddc80
child 108
2a394ccdd778

removed old webdav and expression code

make/linux.mk file | annotate | diff | comparison | revisions
make/osx.mk file | annotate | diff | comparison | revisions
make/solaris.mk file | annotate | diff | comparison | revisions
src/server/daemon/ws-fn.c file | annotate | diff | comparison | revisions
src/server/public/webdav.h file | annotate | diff | comparison | revisions
src/server/util/object.c file | annotate | diff | comparison | revisions
src/server/util/object.h file | annotate | diff | comparison | revisions
src/server/webdav/davparser.cpp file | annotate | diff | comparison | revisions
src/server/webdav/davparser.h file | annotate | diff | comparison | revisions
src/server/webdav/objs.mk file | annotate | diff | comparison | revisions
src/server/webdav/parser.c file | annotate | diff | comparison | revisions
src/server/webdav/parser.h file | annotate | diff | comparison | revisions
src/server/webdav/persistence.c file | annotate | diff | comparison | revisions
src/server/webdav/persistence.h file | annotate | diff | comparison | revisions
src/server/webdav/saxhandler.cpp file | annotate | diff | comparison | revisions
src/server/webdav/saxhandler.h file | annotate | diff | comparison | revisions
src/server/webdav/webdav.c file | annotate | diff | comparison | revisions
src/server/webdav/webdav.h file | annotate | diff | comparison | revisions
templates/config/init.conf file | annotate | diff | comparison | revisions
--- a/make/linux.mk	Sat Oct 31 15:01:07 2015 +0100
+++ b/make/linux.mk	Sat Oct 31 16:39:12 2015 +0100
@@ -29,7 +29,7 @@
 
 # compiler and linker flags
 CFLAGS += -DLINUX
-LDFLAGS += -lpthread -ldl -lnsl -lm -lxerces-c -lldap
+LDFLAGS += -lpthread -ldl -lnsl -lm -lldap
 
 
 # platform dependend source files
--- a/make/osx.mk	Sat Oct 31 15:01:07 2015 +0100
+++ b/make/osx.mk	Sat Oct 31 16:39:12 2015 +0100
@@ -29,7 +29,7 @@
 
 # compiler and linker flags
 CFLAGS += -DBSD -DOSX
-LDFLAGS += -lpthread -ldl -lm -lxerces-c -lldap
+LDFLAGS += -lpthread -ldl -lm -lldap
 
 
 # platform dependend source files
--- a/make/solaris.mk	Sat Oct 31 15:01:07 2015 +0100
+++ b/make/solaris.mk	Sat Oct 31 16:39:12 2015 +0100
@@ -29,7 +29,7 @@
 
 # compiler and linker flags
 CFLAGS += -DSOLARIS
-LDFLAGS += -lsocket -lnsl -lsendfile -lposix4 -lpthread -ldl -lm -lxerces-c -lldap
+LDFLAGS += -lsocket -lnsl -lsendfile -lposix4 -lpthread -ldl -lm -lldap
 
 #PLUGINS = java
 
--- a/src/server/daemon/ws-fn.c	Sat Oct 31 15:01:07 2015 +0100
+++ b/src/server/daemon/ws-fn.c	Sat Oct 31 16:39:12 2015 +0100
@@ -50,9 +50,6 @@
     { "common-index", service_index, NULL, NULL, 0},
     { "service-hello", service_hello, NULL, NULL, 0},
     { "send-options", send_options, NULL, NULL, 0},
-    { "webdav-init", webdav_init, NULL, NULL, 0},
-    { "webdav-setcollection", webdav_setcollection, NULL, NULL, 0},
-    { "webdav-service", webdav_service, NULL, NULL, 0},
     { "admin-init", admin_init, NULL, NULL, 0},
     { "admin-service", admin_service, NULL, NULL, 0},
     { "auth-basic", auth_basic, NULL, NULL, 0 },
--- a/src/server/public/webdav.h	Sat Oct 31 15:01:07 2015 +0100
+++ b/src/server/public/webdav.h	Sat Oct 31 16:39:12 2015 +0100
@@ -39,276 +39,6 @@
 extern "C" {
 #endif
 
-typedef struct DavCollection          DavCollection;
-    
-typedef struct PropfindResponse       PropfindResponse;
-typedef struct PersistenceManager     PersistenceManager;
-
-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;
-
-typedef struct UcxList                List;
-typedef struct UcxMap                 Map;
-
-typedef struct _strbuf                Buffer;
-
-struct DavCollection {
-    PersistenceManager *mgr;
-    // callbacks
-};
-
-struct PropfindRequest {
-    Session            *sn;
-    Request            *rq;
-    
-    XmlNsMap           *nsmap;
-    
-    List               *properties; /* DavProperty list, requested props */
-    int8_t             allprop;
-    int8_t             propname;
-    
-    int8_t             prop;
-    int8_t             isdir;
-    List               *notFoundProps;
-    List               *forbiddenProps;
-    PersistenceManager *persistencemgr;
-    void               *mgrdata;
-
-    char               *path;
-    char               *uri;
-
-    Buffer             *out;
-};
-
-struct ProppatchRequest {
-    Session            *sn;
-    Request            *rq;
-    
-    List               *setProps;    /* XmlElement list, set props */
-    List               *removeProps; /* DavProperty list, remove props */
-    
-    Propstat           *propstat;
-    XmlNsMap           *nsmap;
-    
-    PersistenceManager *backend;
-    
-    char               *path;
-    
-    Buffer             *out;
-};
-
-struct Propstat {
-    List           *okprop; /* properties with status 200 OK */
-    Map            *map;    /* all other properties */
-    pool_handle_t  *pool;
-};
-
-struct DavProperty {
-    XmlNs *xmlns;
-    char  *name;
-};
-
-struct XmlData {
-    XmlNsMap   *nsmap;
-    XmlElement *elm;
-};
-
-struct XmlElement {
-    XmlNs  *xmlns;
-    char   *name;
-    void   *content; /* xmlch* or UcxList* */
-    size_t ctlen;    /* content string length. If 0, content is a UcxDlist */
-};
-
-struct XmlNs {
-    char *xmlns;
-    char *prefix;
-    int  nslen;
-    int  prelen;
-};
-
-struct XmlNsMap {
-    Map           *map;
-    pool_handle_t *pool;
-    int num;
-};
-
-typedef void(*dav_propfind_begin_f)(PersistenceManager*, PropfindRequest*);
-typedef void(*dav_propfind_end_f)(PersistenceManager*, PropfindRequest*);
-typedef void(*dav_propfind_f)(PersistenceManager*,PropfindRequest*,char*);
-typedef void(*dav_proppatch_f)(PersistenceManager*,ProppatchRequest*);
-struct PersistenceManager {
-    void(*propfind_begin)(PersistenceManager *mgr, PropfindRequest *rq);
-    void(*propfind_end)(PersistenceManager *mgr, PropfindRequest *rq);
-    
-    /*
-     * void propfind(PersistenceManager *mgr, PropfindRequest *rq, char *path)
-     * 
-     * 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
-     * 
-     * 
-     * mgr:  WebDAV Persistence Manager
-     * rq:   current PropfindRequest object
-     * path: the webdav resource path
-     */
-    void(*propfind)(PersistenceManager *mgr, PropfindRequest *rq, char *path);
-    
-    /*
-     * void proppatch(PersistenceManager *mgr, ProppatchRequest *rq)
-     * 
-     * Sets properties for a WebDAV resource. It should add all properties to
-     * the propstat object (member of the ProppatchRequest).
-     * 
-     * mgr:  WebDAV backend
-     * path: current ProppatchRequest object
-     */
-    void(*proppatch)(PersistenceManager *mgr, ProppatchRequest *rq);
-    
-    /*
-     * bool
-     * if true, some properties are get from the VFS and not from this
-     * persistence manager
-     */
-    int vfs_props;
-};
-
-void webdav_add_persistence_manager(char *name, PersistenceManager *mgr);
-
-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);
-
-
-/*
- * 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);
-
-
-
-/*---------------------------------- 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
- */
-
-/*
- * 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, Buffer *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, Buffer *out, int wv);
-
 
 
 #ifdef	__cplusplus
--- a/src/server/util/object.c	Sat Oct 31 15:01:07 2015 +0100
+++ b/src/server/util/object.c	Sat Oct 31 16:39:12 2015 +0100
@@ -127,347 +127,9 @@
 }
 
 Expression* expression_from_str(pool_handle_t *pool, char *expr, size_t len) {
-    char str_qc = 0; // 0 or the quote char
-    char c_brace = 0;
-    int brace_count = 0; 
-    
-    Expression *expression = pool_malloc(pool, sizeof(Expression));
-    ZERO(expression, sizeof(Expression));
-    
-    Expression *ex = expression;
-    /*
-     * 0: first operand
-     * 1: second operand
-     * 2: next expression
-     */
-    int optoken = 0;
-    int token_start = 0; // index of token begin
-    int i;
-    for(i=0;i<=len;i++) {
-        char c = i == len ? ' ' : expr[i];
-        
-        if(brace_count > 0) {
-            if(c == c_brace) {
-                char *token = expr + token_start;
-                int token_len = i - token_start;
-                printf("Token {");
-                fwrite(token, token_len, 1, stdout);
-                printf("}\n");
-                
-                
-                
-                // reset token_start
-                token_start = -1;
-            }
-        } else {
-            if((c == '(' || c == '[') && !str_qc) {
-                brace_count++;
-                if(brace_count == 1) {
-                    if(c == '(') {
-                        c_brace = ')'; 
-                    } else {
-                        c_brace = ']';
-                    }
-                    token_start = i+1;
-                }
-            } else if(c == str_qc) {
-                str_qc = 0;
-            } else if(c == '\'' || c == '\"') {
-                if(token_start != -1) {
-                    // error
-                    printf("error: token_start != -1");
-                    return NULL;
-                }
-                token_start = i;
-                str_qc = c;
-            } else if(c < 33 && token_start != -1 && !str_qc) {
-                char *token = expr + token_start;
-                int token_len = i - token_start;
-                //printf("Token {");
-                //fwrite(token, token_len, 1, stdout);
-                //printf("}[%u]\n", token_len);
-                
-                int token_type = expr_token_type(token, token_len);
-                switch(optoken) {
-                    case 0: {
-                        // first operand
-                        if(token_type == 1) {
-                            ex->optype[1] = EXPR_OP_NULL;
-                            ex->opdata[1] = NULL;
-                            ex->expr_operator = expr_operator(
-                                    token,
-                                    token_len);
-                            break;
-                        } else {
-                            expr_set_op(pool, &ex->optype[0], &ex->opdata[0], token, token_len);
-                        }
-                        optoken++;
-                        break;
-                    }
-                    case 1: {
-                        // second operand
-                        if(token_type == 1) {
-                            Operator op = expr_operator(
-                                    token,
-                                    token_len);
-                            if(op != OP_AND && op != OP_OR && op != OP_XOR) {
-                                ex->expr_operator = op;
-                                break;
-                            } // else: jump to case 2
-                        } else if(ex->expr_operator != 0) {
-                            expr_set_op(pool, &ex->optype[1], &ex->opdata[1], token, token_len);
-                            optoken++;
-                            break;
-                        } else {
-                            // syntax error
-                            fprintf(stderr, "expr: missing operator(1)\n");
-                            return NULL;
-                        }
-                    }
-                    case 2: {
-                        // next
-                        if(token_type == 1) {
-                            ex->next_operator = expr_operator(
-                                    token,
-                                    token_len);
-                            optoken = 0;
-                            Expression *next_expr = pool_malloc(
-                                    pool,
-                                    sizeof(Expression));
-                            ZERO(next_expr, sizeof(Expression));
-                            ex->next = next_expr;
-                            ex = next_expr;
-                            break;
-                        } else {
-                            // syntax error
-                            fprintf(stderr, "expr: missing operator(2)\n");
-                            return NULL;
-                        }
-                    }
-                }
-
-                // reset token_start
-                token_start = -1;
-            } else if(c > 32 && token_start == -1) {
-                token_start = i;
-            }
-        }
-    }
-    
-    return expression;
+    return NULL;
 }
 
-Operator expr_operator(char *token, size_t len) {  
-    if(!strncmp(token, "not", len) || !strncmp(token, "!", len)) {
-        return OP_NOT;
-    } else if(!strncmp(token, "and", len) || !strncmp(token, "&&", len)) {
-        return OP_AND;
-    } else if(!strncmp(token, "or", len) || !strncmp(token, "||", len)) {
-        return OP_OR;
-    } else if(!strncmp(token, "xor", len) || !strncmp(token, "^", len)) {
-        return OP_XOR;
-    } else if(!strncmp(token, "=", len)) {
-        return OP_WILDCARD;
-    } else if(!strncmp(token, "=~", len)) {
-        return OP_REGEX;
-    } else if(!strncmp(token, "!~", len)) {
-        return OP_NREGEX;
-    } else if(!strncmp(token, "+", len)) {
-        return OP_ADD;
-    } else if(!strncmp(token, "-", len)) {
-        return OP_SUB;
-    } else if(!strncmp(token, ".", len)) {
-        return OP_CAT;
-    } else if(!strncmp(token, "defined", len)) {
-        return OP_DEF;
-    } else if(!strncmp(token, "-d", len)) {
-        return OP_DEXISTS;
-    } else if(!strncmp(token, "-e", len)) {
-        return OP_FDEXISTS;
-    } else if(!strncmp(token, "-f", len)) {
-        return OP_FEXISTS;
-    } else if(!strncmp(token, "-l", len)) {
-        return OP_LEXISTS;
-    } else if(!strncmp(token, "-r", len)) {
-        return OP_READABLE;
-    } else if(!strncmp(token, "-s", len)) {
-        return OP_FSIZE;
-    } else if(!strncmp(token, "-U", len)) {
-        return OP_UMAP;
-    } else if(!strncmp(token, "<", len)) {
-        return OP_LESS;
-    } else if(!strncmp(token, "<=", len)) {
-        return OP_LESSEQ;
-    } else if(!strncmp(token, ">", len)) {
-        return OP_GREATER;
-    } else if(!strncmp(token, ">=", len)) {
-        return OP_GREATEREQ;
-    } else if(!strncmp(token, "lt", len)) {
-        return OP_STRLESS;
-    } else if(!strncmp(token, "le", len)) {
-        return OP_STRLESSEQ;
-    } else if(!strncmp(token, "gt", len)) {
-        return OP_GREATER;
-    } else if(!strncmp(token, "ge", len)) {
-        return OP_STRGREATEREQ;
-    } else if(!strncmp(token, "==", len)) {
-        return OP_EQUAL;
-    } else if(!strncmp(token, "!=", len)) {
-        return OP_NOTEQUAL;
-    } else if(!strncmp(token, "eq", len)) {
-        return OP_STREQUAL;
-    } else if(!strncmp(token, "ne", len)) {
-        return OP_STRNOTEQUAL;
-    }
-    return OP_NOOP;
-}
-
-int expr_token_type(char *token, size_t len) {
-    char c = token[0];
-    if(c == '$' || c == '"' || c == '\'') {
-        return 0;
-    } else {
-        if(expr_operator(token, len) == OP_NOOP) {
-            return 0;
-        } else {
-            return 1;
-        }
-    }
-}
-
-void expr_set_op(pool_handle_t *pool, OperandType *type, void **val, char *token, size_t len) {
-    char c = token[0];
-    if(c == '$') {
-        *type = EXPR_OP_VAR;
-        sstr_t s = sstrn(token+1, len-1);
-        s = sstrdup_pool(pool, s);
-        *val = s.ptr;
-    } else if(c == '"' || c == '\'') {
-        *type = EXPR_OP_STRING;
-        sstr_t s = sstrn(token+1, len-2);
-        //s = sstrdup_pool(pool, s);
-        *val = s.ptr;
-    }
-}
-
-
 int condition_evaluate(Condition *condition, Session *sn, Request *rq) {
-    return expression_evaluate(condition->expression, sn, rq);
+    return 1;
 }
-
-int expression_evaluate(Expression *ex, Session *sn, Request *rq) {
-    int ret = 0;
-    
-    int last_eval = 0;
-    Operator expr_lconn = OP_NOOP; // logical connective between 2 expressions
-    while(ex) {
-        int eval = 0;
-        
-        if(!ex->opdata[1]) {
-            /*
-             * Only one operand. Can be:
-             *   boolean with or without not operator
-             *   defined operator
-             *   file/directory/link exists operator
-             */
-            int not_op = 0;
-            switch(ex->expr_operator) {
-                case OP_NOT: {
-                    not_op = 1;
-                }
-                case OP_NOOP: {
-                    // must be boolean
-                    // TODO
-                }
-            }
-            
-        } else {
-            void *ops[2];
-            VarType types[2];
-            for(int i=0;i<2;i++) {
-                switch(ex->optype[i]) {
-                    case EXPR_OP_STRING: {
-                        ops[i] = ex->opdata[i];
-                        types[i] = VAR_STRING;
-                        break;
-                    }
-                    case EXPR_OP_VAR: {
-                        if(!expr_get_var(ex->opdata[i], sn, rq, &ops[i], &types[i]));
-                        break;
-                    }
-                }
-            }
-            
-            if(types[0] != types[1]) {
-                fprintf(stderr, "Condition: incompatible types\n");
-                return 0;
-            }
-            
-            if(types[0] == VAR_STRING) {
-                switch(ex->expr_operator) {
-                    case OP_WILDCARD: {
-                        eval = !shexp_match(ops[0], ops[1]);
-                        break;
-                    }
-                    case OP_STREQUAL: {
-                        eval = !strcmp(ops[0], ops[1]);
-                        break;
-                    }
-                }
-            }
-        }
-        
-        
-        // evaluate logical connective between last 2 expressions
-        switch(expr_lconn) {
-            case OP_AND: {
-                if(!last_eval || !eval) {
-                    return 0;
-                }
-                break;
-            }
-            case OP_OR: {
-                if(!last_eval && !eval) {
-                    return 0;
-                }
-            }
-            case OP_XOR: {
-                if(last_eval == eval) {
-                    return 0;
-                }
-            }
-        }
-        
-        last_eval = eval;
-        // switch to next expression
-        if(ex->next) {
-            expr_lconn = ex->next_operator;
-        }
-        ex = ex->next;
-    }
-    
-    return last_eval;
-}
-
-int expr_get_var(char *var, Session *sn, Request *rq, void **val, VarType *t) {
-    if(!strcmp(var, "path")) {
-        char *ppath = pblock_findval("ppath", rq->vars);
-        if(ppath) {
-            *t = VAR_STRING;
-            *val = ppath;
-            return 1;
-        }
-    } else if(!strcmp(var, "uri")) {
-        char *uri = pblock_findval("uri", rq->reqpb);
-        if(uri) {
-            *t = VAR_STRING;
-            *val = uri;
-            return 1;
-        }
-    }
-    
-    *val = NULL;
-    *t = 0;
-    return 0;
-}
-
--- a/src/server/util/object.h	Sat Oct 31 15:01:07 2015 +0100
+++ b/src/server/util/object.h	Sat Oct 31 16:39:12 2015 +0100
@@ -90,67 +90,9 @@
     int        index; // used by NSAPIContext to link expression with result
 };
 
-enum OperandType {
-    EXPR_OP_NULL = 0,   // no operand
-    EXPR_OP_STRING,     // string literal
-    EXPR_OP_INTEGER,    // integer literal
-    EXPR_OP_VAR,        // variable
-    EXPR_OP_FUNC,       // function,
-    EXPR_OP_EXPRESSION  // operand is an expression
-};
-
-enum Operator {
-    OP_NOOP = 0,
-    OP_NOT,          // not, !
-    OP_AND,          // and, &&
-    OP_OR,           // or, ||
-    OP_XOR,          // xor, ^
-    OP_WILDCARD,     // =
-    OP_REGEX,        // =~
-    OP_NREGEX,       // !~
-    OP_ADD,          // +
-    OP_SUB,          // -
-    OP_CAT,          // .
-    OP_DEF,          // defined
-    OP_DEXISTS,      // -d
-    OP_FDEXISTS,     // -e
-    OP_FEXISTS,      // -f
-    OP_LEXISTS,      // -l
-    OP_READABLE,     // -r
-    OP_FSIZE,        // -s
-    OP_UMAP,         // -U
-    OP_LESS,         // <
-    OP_LESSEQ,       // <=
-    OP_GREATER,      // >
-    OP_GREATEREQ,    // >=
-    OP_STRLESS,      // lt
-    OP_STRLESSEQ,    // le
-    OP_STRGREATER,   // gt
-    OP_STRGREATEREQ, // ge
-    OP_EQUAL,        // ==
-    OP_NOTEQUAL,     // !=
-    OP_STREQUAL,     // eq
-    OP_STRNOTEQUAL,  // ne
-};
-
-enum VarType {
-    VAR_NULL = 0,
-    VAR_STRING,
-    VAR_INTEGER,
-    VAR_BOOL
-};
-
 struct Expression {
-    // type of the operands
-    OperandType optype[2];
-    // operand data
-    void *opdata[2];
-    // operator
-    Operator expr_operator;
-    // logical connective to next expression
-    Operator next_operator;
-    // next expression
-    Expression *next;
+    // TODO
+    int n;
 };
 
 
@@ -227,22 +169,9 @@
 
 Condition* condition_from_str(pool_handle_t *pool, char *expr, size_t len);
 Expression* expression_from_str(pool_handle_t *pool, char *expr, size_t len);
-Operator expr_operator(char *token, size_t len);
-
-/*
- * get the type of the token
- * 
- * returns
- *   0: operand
- *   1: operator
- */
-int expr_token_type(char *token, size_t len);
-void expr_set_op(pool_handle_t *pool, OperandType *type, void **val, char *token, size_t len);
-
 
 int condition_evaluate(Condition *condition, Session *sn, Request *rq);
-int expression_evaluate(Expression *ex, Session *sn, Request *rq);
-int expr_get_var(char *var, Session *sn, Request *rq, void **val, VarType *t);
+
 
 #ifdef	__cplusplus
 }
--- a/src/server/webdav/davparser.cpp	Sat Oct 31 15:01:07 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,162 +0,0 @@
-/*
- * 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.
- */
-
-#include "davparser.h"
-
-#include "../util/pool.h"
-#include "../util/pblock.h"
-
-#include "saxhandler.h"
-
-#include <xercesc/sax2/SAX2XMLReader.hpp>
-#include <xercesc/sax2/XMLReaderFactory.hpp>
-#include <xercesc/sax2/DefaultHandler.hpp>
-#include <xercesc/util/XMLString.hpp>
-#include <xercesc/framework/MemBufInputSource.hpp>
-
-XERCES_CPP_NAMESPACE_USE;
-
-int xcinit = 0;
-
-PropfindRequest* dav_parse_propfind(
-        Session *sn,
-        Request *rq,
-        char *xml,
-        size_t len)
-{
-    if(!xcinit) {
-        /* TODO: create webdav module init function */
-        XMLPlatformUtils::Initialize();
-        xcinit = 1;
-    }
-    PropfindRequest *davrq = (PropfindRequest*)pool_calloc(
-            sn->pool,
-            1,
-            sizeof(PropfindRequest));
-    davrq->nsmap = xmlnsmap_create(sn->pool);
-    xmlnsmap_put(davrq->nsmap, (char*)"DAV:");
-    davrq->allprop = 0;
-    davrq->propname = 0;
-    davrq->prop = 0;
-    davrq->properties = NULL;
-    davrq->forbiddenProps = NULL;
-    davrq->notFoundProps = NULL;
-    davrq->mgrdata = NULL;
-    // create xml parser
-    SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
-    parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
-
-    PropfindHandler handler(davrq, sn->pool);
-    parser->setContentHandler(&handler);
-    parser->setErrorHandler(&handler);
-
-    MemBufInputSource source((XMLByte*)xml, (XMLSize_t)len, "wsid");
-    try {
-        parser->parse(source);
-    }
-    catch (const XMLException& e) {
-        printf("XMLException\n");
-        
-    }
-    catch (const SAXParseException& e) {
-        printf("SAXParseException\n");
-        
-    }
-    catch (...) {
-        printf("davaparser Exception\n");
-    }
-
-    delete parser;
-    
-
-    return davrq;
-}
-
-void dav_free_propfind(PropfindRequest *rq) {
-    ucx_list_free(rq->forbiddenProps);
-    ucx_list_free(rq->notFoundProps);
-    //ucx_dlist_free(rq->properties); // uses pool
-    sbuf_free(rq->out);
-}
-
-ProppatchRequest* dav_parse_proppatch(
-        Session *sn,
-        Request *rq,
-        char *xml,
-        size_t len)
-{
-    if(!xcinit) {
-        /* TODO: create webdav module init function */
-        XMLPlatformUtils::Initialize();
-        xcinit = 1;
-    }
-    ProppatchRequest *davrq = (ProppatchRequest*)pool_calloc(
-            sn->pool,
-            1,
-            sizeof(PropfindRequest));
-    davrq->nsmap = xmlnsmap_create(sn->pool);
-    xmlnsmap_put(davrq->nsmap, (char*)"DAV:");
-    
-    
-    // create xml parser
-    SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
-    parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
-
-    ProppatchHandler handler(davrq, sn->pool);
-    parser->setContentHandler(&handler);
-    parser->setErrorHandler(&handler);
-
-    MemBufInputSource source((XMLByte*)xml, (XMLSize_t)len, "wsid");
-    try {
-        parser->parse(source);
-    }
-    catch (const XMLException& e) {
-        printf("XMLException\n");
-        
-    }
-    catch (const SAXParseException& e) {
-        printf("SAXParseException\n");
-        
-    }
-    catch (...) {
-        printf("davaparser Exception\n");
-    }
-
-    delete parser;
-    
-
-    return davrq;
-}
-
-void dav_free_proppatch(ProppatchRequest *rq) {
-    ucx_list_free(rq->removeProps);
-    ucx_list_free(rq->setProps);
-    xmlnsmap_free(rq->nsmap);
-    ucx_map_free(rq->propstat->map);
-    ucx_list_free(rq->propstat->okprop);
-}
--- a/src/server/webdav/davparser.h	Sat Oct 31 15:01:07 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,62 +0,0 @@
-/*
- * 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 DAVPARSER_H
-#define	DAVPARSER_H
-
-#include "../public/nsapi.h"
-
-#include <inttypes.h>
-#include "webdav.h"
-
-#ifdef	__cplusplus
-extern "C" {
-#endif
-
-PropfindRequest* dav_parse_propfind(
-        Session *sn,
-        Request *rq,
-        char *xml,
-        size_t len);
-
-void dav_free_propfind(PropfindRequest *rq);
-
-ProppatchRequest* dav_parse_proppatch(
-        Session *sn,
-        Request *rq,
-        char *xml,
-        size_t len);
-
-void dav_free_proppatch(ProppatchRequest *rq);
-
-#ifdef	__cplusplus
-}
-#endif
-
-#endif	/* DAVPARSER_H */
-
--- a/src/server/webdav/objs.mk	Sat Oct 31 15:01:07 2015 +0100
+++ b/src/server/webdav/objs.mk	Sat Oct 31 16:39:12 2015 +0100
@@ -31,15 +31,6 @@
 DAV_OBJPRE = $(OBJ_DIR)$(DAV_SRC_DIR)
 
 DAVOBJ = webdav.o
-DAVOBJ += persistence.o
-DAVOBJ += parser.o
 
 DAVOBJS = $(DAVOBJ:%=$(DAV_OBJPRE)%)
 DAVSOURCE = $(DAVOBJ:%.o=webdav/%.c)
-
-# add cpp files
-DAVOBJS += $(DAV_OBJPRE)saxhandler.o
-DAVOBJS += $(DAV_OBJPRE)davparser.o
-
-DAVSOURCE += webdav/saxhandler.cpp
-DAVSOURCE += webdav/davparser.cpp
--- a/src/server/webdav/parser.c	Sat Oct 31 15:01:07 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,126 +0,0 @@
-/*
- * 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.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include "parser.h"
-
-
-void xmlerrorfnc(void * ctx, const char * msg, ... ) {
-    // nothing
-}
-
-static int xinit = 0;
-
-PropfindRequest* dav_parse_propfind2(
-        Session *sn,
-        Request *rq,
-        char *xml,
-        size_t len)
-{
-    if(!xinit) {
-        xmlGenericErrorFunc fnc = xmlerrorfnc;
-        initGenericErrorDefaultFunc(&fnc);
-        xinit = 1;
-    }
-    
-    PropfindRequest *davrq = (PropfindRequest*)pool_calloc(
-            sn->pool,
-            1,
-            sizeof(PropfindRequest));
-    davrq->nsmap = xmlnsmap_create(sn->pool);
-    xmlnsmap_put(davrq->nsmap, (char*)"DAV:");
-    davrq->allprop = 0;
-    davrq->propname = 0;
-    davrq->prop = 0;
-    davrq->properties = NULL;
-    davrq->forbiddenProps = NULL;
-    davrq->notFoundProps = NULL;
-    davrq->mgrdata = NULL;
-    
-    
-    xmlTextReaderPtr reader = xmlReaderForMemory(xml, len, NULL, NULL, 0);
-    int r = 0;
-    
-    if(!reader) {
-        fprintf(stderr, "Cannot create xmlReader\n");
-        return davrq;
-    }
-    
-    PropfindParser parser;
-    parser.pool = sn->pool;
-    parser.rq = davrq;
-    parser.davPropTag = 0;
-    
-    while((r = xmlTextReaderRead(reader)) == 1) {
-         int nodetype = xmlTextReaderNodeType(reader);
-         if(nodetype == XML_READER_TYPE_ELEMENT) {
-             if(propfind_begin_elm(&parser, reader)) {
-                 fprintf(stderr, "propfind xml error\n");
-                 break;
-             }
-         }
-    }
-    
-    return davrq;
-}
-
-int propfind_begin_elm(PropfindParser *p, xmlTextReaderPtr elm) {
-    pool_handle_t *pool = p->pool;
-    const xmlChar *ns = xmlTextReaderConstNamespaceUri(elm);
-    const xmlChar *name = xmlTextReaderConstLocalName(elm);
-    int depth = xmlTextReaderDepth(elm);
-    
-    // check namespace
-    int dav_ns = 0;
-    if(ns) {
-        dav_ns = xstreq(ns, "DAV:") ? 1 : 0;
-    }
-    
-    if(dav_ns && xstreq(name, "allprop") && depth == 1) {
-        p->rq->allprop = 1;
-    } else if(dav_ns && xstreq(name, "prop") && depth == 1) {
-        p->davPropTag = 1;
-    } else if(p->davPropTag && !p->rq->allprop && depth == 2) {
-        DavProperty *property = pool_malloc(pool, sizeof(DavProperty));
-        property->xmlns = xmlnsmap_put(p->rq->nsmap, (char*)ns);
-        property->name = pool_strdup(pool, (const char*)name);
-        
-        // add property to DavRequest
-        UcxList *elm = pool_malloc(pool, sizeof(UcxList));
-        elm->prev = NULL;
-        elm->next = NULL;
-        elm->data = property;
-        p->rq->properties = ucx_list_concat(p->rq->properties, elm);
-    }
-    
-    return 0;
-}
-
--- a/src/server/webdav/parser.h	Sat Oct 31 15:01:07 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,64 +0,0 @@
-/*
- * 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 PARSER_H
-#define	PARSER_H
-
-#include <libxml/parser.h>
-#include <libxml/xmlreader.h>
-
-#include "webdav.h"
-
-#ifdef	__cplusplus
-extern "C" {
-#endif
-
-#define xstreq(a,b) xmlStrEqual(BAD_CAST a, BAD_CAST b)
-
-typedef struct PropfindParser {
-    PropfindRequest *rq;
-    pool_handle_t   *pool;
-    int             davPropTag;
-} PropfindParser;
-    
-    
-PropfindRequest* dav_parse_propfind2(
-        Session *sn,
-        Request *rq,
-        char *xml,
-        size_t len);
-
-int propfind_begin_elm(PropfindParser *parser, xmlTextReaderPtr elm);
-
-
-#ifdef	__cplusplus
-}
-#endif
-
-#endif	/* PARSER_H */
-
--- a/src/server/webdav/persistence.c	Sat Oct 31 15:01:07 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,59 +0,0 @@
-/*
- * 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.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
-
-#include "persistence.h"
-
-PersistenceManager* create_property_database() {
-    PropertyDatabase *mgr = malloc(sizeof(PropertyDatabase));
-    mgr->mgr.propfind_begin = (dav_propfind_begin_f)pdb_propfind_begin;
-    mgr->mgr.propfind_end = (dav_propfind_end_f)pdb_propfind_end;
-    mgr->mgr.propfind = (dav_propfind_f)pdb_propfind;
-    mgr->mgr.proppatch = (dav_proppatch_f)pdb_proppatch;
-    return (PersistenceManager*)mgr;
-}
-
-void pdb_propfind_begin(PropertyDatabase *mgr, PropfindRequest *rq) {
-    
-}
-
-void pdb_propfind_end(PropertyDatabase *mgr, PropfindRequest *rq) {
-    
-}
-
-void pdb_propfind(PropertyDatabase *mgr, PropfindRequest *rq, char *path) {
-    
-}
-
-void pdb_proppatch(PropertyDatabase *mgr, ProppatchRequest *rq) {
-    
-}
--- a/src/server/webdav/persistence.h	Sat Oct 31 15:01:07 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,53 +0,0 @@
-/*
- * 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 PERSISTENCE_H
-#define	PERSISTENCE_H
-
-#include "webdav.h"
-
-#ifdef	__cplusplus
-extern "C" {
-#endif
-
-typedef struct PropertyDatabase {
-    PersistenceManager mgr;
-} PropertyDatabase;
-
-PersistenceManager* create_property_database();
-void pdb_propfind_begin(PropertyDatabase *mgr, PropfindRequest *rq);
-void pdb_propfind_end(PropertyDatabase *mgr, PropfindRequest *rq);
-void pdb_propfind(PropertyDatabase *mgr, PropfindRequest *rq, char *path);
-void pdb_proppatch(PropertyDatabase *mgr, ProppatchRequest *rq);
-
-#ifdef	__cplusplus
-}
-#endif
-
-#endif	/* PERSISTENCE_H */
-
--- a/src/server/webdav/saxhandler.cpp	Sat Oct 31 15:01:07 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,293 +0,0 @@
-/*
- * 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.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <iostream>
-
-#include <ucx/string.h>
-#include <ucx/list.h>
-
-#include "../util/pool.h"
-
-#include "saxhandler.h"
-
-using namespace std;
-
-void xstack_push(UcxList **stack, XmlElement *elm) {
-    *stack = ucx_list_prepend(*stack, elm);
-}
-
-XmlElement* xstack_pop(UcxList **stack) {
-    if(*stack == NULL) {
-        return NULL;
-    }
-    XmlElement* ret = (XmlElement*)(*stack)->data;
-    UcxList *newstack = ucx_list_remove(*stack, *stack);
-    *stack = newstack;
-    return ret;
-}
-
-
-
-PropfindHandler::PropfindHandler(PropfindRequest *rq, pool_handle_t *p) {
-    davrq = rq;
-    pool  = p;
-
-    davPropTag = false;
-    property = NULL;
-}
-
-PropfindHandler::~PropfindHandler() {
-    
-}
-
-void PropfindHandler::startElement(
-        const XMLCh *const uri,
-        const XMLCh* const localname,
-        const XMLCh* const qname,
-        const Attributes& attrs)
-{
-    char *ns  = XMLString::transcode(uri);
-    char *name = XMLString::transcode(localname);
-    
-    if(!strcmp(ns, "DAV:") && !strcmp(name, "allprop")) {
-        davrq->allprop = 1;
-    } else if(!strcmp(ns, "DAV:") && !strcmp(name, "prop")) {
-        davPropTag = true;
-    } else if(davPropTag && property == NULL && !davrq->allprop) {
-        property = (DavProperty*)pool_malloc(pool, sizeof(DavProperty));
-
-        size_t nslen = strlen(ns);
-        size_t namelen = strlen(name);
-        if(nslen > 0) {
-            //property->xmlns = (char*)pool_malloc(pool, nslen + 1);
-            //property->xmlns[nslen] = 0;
-            property->xmlns = xmlnsmap_put(davrq->nsmap, ns);
-            //memcpy(property->xmlns, ns, nslen);
-        } else {
-            property->xmlns = NULL;
-        }
-
-        if(namelen > 0) {
-            property->name = (char*)pool_malloc(pool, namelen + 1);
-            property->name[namelen] = 0;
-            memcpy(property->name, name, namelen);
-        } else {
-            property->name = NULL;
-        }
-    }
-
-    XMLString::release(&ns);
-    XMLString::release(&name);
-}
-
-
-void PropfindHandler::endElement(
-        const XMLCh* const   uri,
-        const XMLCh* const   localname,
-        const XMLCh* const   qname)
-{
-    char *ns  = XMLString::transcode(uri);
-    char *name = XMLString::transcode(localname);
-
-    if(property != NULL) {
-        const char *xmlns = (property->xmlns) ? property->xmlns->xmlns : "";
-        
-        if(!strcmp(ns, xmlns) && !strcmp(name, property->name)) {
-            // add property to DavRequest
-            UcxList *elm = (UcxList*)pool_malloc(pool, sizeof(UcxList));
-            elm->prev = NULL;
-            elm->next = NULL;
-            elm->data = property;
-            //printf("saxhandler: add property: {%s}\n", property->name);
-            davrq->properties = ucx_list_concat(davrq->properties, elm);
-            
-            property = NULL;
-        }
-    }
-
-    XMLString::release(&ns);
-    XMLString::release(&name);
-}
-
-void PropfindHandler::startDocument() {
-    
-}
-
-void PropfindHandler::endDocument() {
-
-}
-
-
-/************* PropPatch Handler **************/
-
-ProppatchHandler::ProppatchHandler(ProppatchRequest *rq, pool_handle_t *p) {
-    davrq = rq;
-    pool  = p;
-    
-    davPropTag = false;
-    rootElement = NULL;
-    xmlStack = NULL;
-    newElement = NULL;
-    
-    updateMode = -1;
-}
-
-ProppatchHandler::~ProppatchHandler() {
-    ucx_list_free(xmlStack);
-}
-
-void ProppatchHandler::startElement(
-        const XMLCh *const uri,
-        const XMLCh* const localname,
-        const XMLCh* const qname,
-        const Attributes& attrs)
-{
-    char *ns  = XMLString::transcode(uri);
-    char *name = XMLString::transcode(localname);
-    
-    if(!strcmp(ns, "DAV:") && !strcmp(name, "set")) {
-        updateMode = 0;
-    } else if(!strcmp(ns, "DAV:") && !strcmp(name, "remove")) {
-        updateMode = 1;
-    } else if(!strcmp(ns, "DAV:") && !strcmp(name, "prop")) {
-        davPropTag = true;
-    } else if(davPropTag) {
-        newElement = (XmlElement*)pool_calloc(pool, 1, sizeof(XmlElement));
-        newElement->name = pool_strdup(pool, name);
-        newElement->xmlns = xmlnsmap_put(davrq->nsmap, ns);
-        
-        /*
-         * the xml stack manages the xml hierarchy
-         * new elements will be added to the top element on the stack
-         */
-        
-        XmlElement *currentElm = XSTACK_CUR();
-        if(currentElm) {
-            xmlelm_add_child(currentElm, newElement);
-        }
-        
-        /* newElement is now the parent for future elements */
-        XSTACK_PUSH(newElement);
-        
-        /* if the root element isn't set, the first new element is the root */
-        if(!rootElement) {
-            rootElement = newElement;
-        }
-    }
-
-    XMLString::release(&ns);
-    XMLString::release(&name);
-}
-
-
-void ProppatchHandler::endElement(
-        const XMLCh* const   uri,
-        const XMLCh* const   localname,
-        const XMLCh* const   qname)
-{
-    char *ns  = XMLString::transcode(uri);
-    char *name = XMLString::transcode(localname);
-
-    if(!strcmp(ns, "DAV:") && !strcmp(name, "set")) {
-        updateMode = -1;
-    } else if(!strcmp(ns, "DAV:") && !strcmp(name, "remove")) {
-        updateMode = -1;
-    } else if(!strcmp(ns, "DAV:") && !strcmp(name, "prop")) {
-        davPropTag = false;
-    } else if(davPropTag) {
-        XmlElement *elm = XSTACK_POP();
-        if(xmlStack == NULL) {
-            /* property complete */
-            
-            /*
-            XmlElement *r = rootElement;
-            printf("<%s>\n", sstrdup(r->name).ptr);
-            printf("%s\n", r->content);
-            printf("</%s>\n", sstrdup(r->name).ptr);
-            */
-            
-            /* add the property to the proppatch request */
-            switch(updateMode) {
-                case 0: {
-                    davrq->setProps = ucx_list_append(
-                            davrq->setProps,
-                            rootElement);
-                    break;
-                }
-                case 1: {
-                    davrq->removeProps = ucx_list_append(
-                            davrq->removeProps,
-                            rootElement);
-                    break;
-                }
-            }
-            
-            rootElement = NULL;
-            
-        }
-    }
-    
-
-    XMLString::release(&ns);
-    XMLString::release(&name);
-}
-
-void ProppatchHandler::characters(
-        const XMLCh *const chars,
-        const XMLSize_t length)
-{
-    
-    XMLString::trim((XMLCh *const)chars);
-    if(chars[0] == 0) {
-        return;
-    }
-    
-    XmlElement *currentElm = XSTACK_CUR();
-    if(currentElm) {
-        xmlch_t *str = (xmlch_t*)pool_calloc(pool, sizeof(xmlch_t), length + 1);
-        for(int i=0;i<length;i++) {
-            str[i] = chars[i];
-        }
-        str[length] = 0;
-        
-        currentElm->content = str;
-        currentElm->ctlen = length;
-    }
-}
-
-void ProppatchHandler::startDocument() {
-    
-}
-
-void ProppatchHandler::endDocument() {
-
-}
-
--- a/src/server/webdav/saxhandler.h	Sat Oct 31 15:01:07 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,110 +0,0 @@
-/*
- * 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 SAXHANDLER_H
-#define	SAXHANDLER_H
-
-#include "davparser.h"
-
-#include <xercesc/sax2/DefaultHandler.hpp>
-
-using namespace xercesc;
-
-/* stack */
-#define XSTACK_PUSH(elm) xstack_push(&xmlStack, elm)
-#define XSTACK_POP() xstack_pop(&xmlStack)
-#define XSTACK_CUR() (xmlStack) ? (XmlElement*)xmlStack->data : NULL;
-void xstack_push(UcxList **stack, XmlElement *elm);
-XmlElement* xstack_pop(UcxList **stack);
-
-class PropfindHandler : public DefaultHandler {
-public:
-    PropfindHandler(PropfindRequest *rq, pool_handle_t *p);
-    virtual ~PropfindHandler();
-
-    void startElement(
-        const XMLCh* const   uri,
-        const XMLCh* const   localname,
-        const XMLCh* const   qname,
-        const Attributes&    attrs);
-    
-    void endElement(
-        const XMLCh* const   uri,
-        const XMLCh* const   localname,
-        const XMLCh* const   qname);
-    
-    void startDocument();
-
-    void endDocument();
-
-private:
-    PropfindRequest *davrq;
-    pool_handle_t   *pool;
-
-    bool            davPropTag;
-    DavProperty     *property;
-};
-
-
-class ProppatchHandler : public DefaultHandler {
-public:
-    ProppatchHandler(ProppatchRequest *rq, pool_handle_t *p);
-    virtual ~ProppatchHandler();
-
-    void startElement(
-        const XMLCh* const   uri,
-        const XMLCh* const   localname,
-        const XMLCh* const   qname,
-        const Attributes&    attrs);
-    
-    void endElement(
-        const XMLCh* const   uri,
-        const XMLCh* const   localname,
-        const XMLCh* const   qname);
-
-    void characters(const XMLCh *const chars, const XMLSize_t length);
-    
-    void startDocument();
-
-    void endDocument();
-
-private:
-    ProppatchRequest *davrq;
-    pool_handle_t    *pool;
-
-    bool             davPropTag;
-    XmlElement       *rootElement;
-    XmlElement       *newElement; 
-    UcxList         *xmlStack;
-    
-    //DavProperty      *property;
-    int              updateMode; /* 0 = set, 1 = remove, -1 = undefined */
-};
-
-#endif	/* SAXHANDLER_H */
-
--- a/src/server/webdav/webdav.c	Sat Oct 31 15:01:07 2015 +0100
+++ b/src/server/webdav/webdav.c	Sat Oct 31 16:39:12 2015 +0100
@@ -31,788 +31,5 @@
 #include <string.h>
 
 #include "webdav.h"
-#include <ucx/list.h>
-#include <ucx/string.h>
-#include "../util/pool.h"
-#include "../util/pblock.h"
-#include "../util/date.h"
-#include "../util/util.h"
-
-#include "../daemon/vfs.h"
-#include "../daemon/protocol.h"
-
-#include "davparser.h"
-#include "parser.h"
-#include "persistence.h"
-
-static UcxMap *pmgr_map; // char*, PersistenceManager
-
-int webdav_init(pblock *pb, Session *sn, Request *rq) {
-    pmgr_map = ucx_map_new(8);
-    PersistenceManager *defaultmgr = create_property_backend();
-    ucx_map_cstr_put(pmgr_map, "default", defaultmgr);
-    return REQ_PROCEED;
-}
-
-void webdav_add_persistence_manager(char *name, PersistenceManager *mgr) {
-    if(!pmgr_map) {
-        webdav_init(NULL, NULL, NULL);
-    }
-    ucx_map_cstr_put(pmgr_map, name, mgr);
-}
-
-int webdav_setcollection(pblock *pb, Session *sn, Request *rq) {
-    //char *name = pblock_findkeyval(pb_key_name, pb);
-    char *db = pblock_findval("db", pb);
-    
-    if(!db) {
-        db = "default";
-    }
-    
-    // setup DavCollection
-    DavCollection *dav = pool_malloc(sn->pool, sizeof(DavCollection));
-    dav->mgr = ucx_map_cstr_get(pmgr_map, db);
-    rq->davCollection = dav;
-    
-    return REQ_NOACTION;
-}
-
-int webdav_service(pblock *pb, Session *sn, Request *rq) {
-    char *method = pblock_findkeyval(pb_key_method, rq->reqpb);
-    if(method == NULL) {
-        return REQ_ABORTED;
-    }
-    
-    if(!strcmp(method, "PROPFIND")) {
-        return webdav_propfind(pb, sn, rq);
-    } else if(!strcmp(method, "PROPPATCH")) {
-        return webdav_proppatch(pb, sn, rq);
-    } else if(!strcmp(method, "PUT")) {
-        return webdav_put(pb, sn, rq);
-    } else if(!strcmp(method, "DELETE")) {
-        return webdav_delete(pb, sn, rq);
-    } else if(!strcmp(method, "MKCOL")) {
-        return webdav_mkcol(pb, sn, rq);
-    }
-    
-    return REQ_NOACTION;
-}
-
-int webdav_put(pblock *pb, Session *sn, Request *rq) {
-    int length = 0;
-    
-    char *ppath = pblock_findkeyval(pb_key_ppath, rq->vars);
-    char *ctlen = pblock_findkeyval(pb_key_content_length, rq->headers);
-    if(ctlen) {
-        length = atoi(ctlen);
-    } else {
-        /* invalid request */
-        printf("invalid request\n");
-        return REQ_ABORTED;
-    }
-    
-    printf("PUT length: %d\n", length);
-    
-    //int status = 201;
-    //FILE *out = fopen(ppath, "w");
-    
-    VFSContext *vfs = vfs_request_context(sn, rq);
-    SYS_FILE out = vfs_openWO(vfs, ppath);
-    if(out == NULL) {
-        fprintf(stderr, "vfs_openWO(%s, \"w\") failed\n", ppath);
-        //protocol_status(sn, rq, 500, NULL);
-        return REQ_ABORTED;
-    }
-    
-    if(length > 0) {
-        size_t len = (length > 4096) ? (4096) : (length);
-        char *buffer = pool_malloc(sn->pool, len);
-        
-        int r;
-        int r2 = 0;
-        while(r2 < length) {
-            r = netbuf_getbytes(sn->inbuf, buffer, len);
-            if(r == NETBUF_EOF) {
-                break;
-            }
-            system_fwrite(out, buffer, r);
-            
-            r2 += r;
-        }
-        
-        pool_free(sn->pool, buffer);
-    } else {
-        
-    }
-    vfs_close(out);
-    
-    protocol_status(sn, rq, 201, NULL);
-    pblock_removekey(pb_key_content_type, rq->srvhdrs);
-    pblock_nninsert("content-length", 0, rq->srvhdrs);
-    http_start_response(sn, rq);
-    
-    return REQ_PROCEED;
-}
-
-int webdav_delete(pblock *pb, Session *sn, Request *rq) {
-    char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb);
-    char *ppath = pblock_findkeyval(pb_key_ppath, rq->vars);
-    
-    VFSContext *vfs = vfs_request_context(sn, rq);
-    
-    int status = 204;
-    
-    struct stat st;
-    if(vfs_stat(vfs, ppath, &st)) {
-        return REQ_ABORTED;
-    }
-    
-    if(!strcmp(uri, "/")) {
-        status = 403;
-    } else if((st.st_mode & S_IFDIR) == S_IFDIR) {
-        if(rmdir(ppath) != 0) {
-            /* ERROR */
-            status = 403;
-        }
-    } else {
-        if(vfs_unlink(vfs, ppath)) {
-            /* ERROR */
-            return REQ_ABORTED;
-        }
-    }
-    
-    protocol_status(sn, rq, status, NULL);
-    pblock_removekey(pb_key_content_type, rq->srvhdrs);
-    pblock_nninsert("content-length", 0, rq->srvhdrs);
-    http_start_response(sn, rq);
-    
-    return REQ_PROCEED;
-}
-
-int webdav_mkcol(pblock *pb, Session *sn, Request *rq) {
-    char *ppath = pblock_findkeyval(pb_key_ppath, rq->vars);
-    
-    VFSContext *vfs = vfs_request_context(sn, rq);
-    if(vfs_mkdir(vfs, ppath)) {
-        return REQ_ABORTED;
-    }
-    
-    protocol_status(sn, rq, 201, NULL);
-    pblock_removekey(pb_key_content_type, rq->srvhdrs);
-    pblock_nninsert("content-length", 0, rq->srvhdrs);
-    http_start_response(sn, rq);
-    
-    return REQ_ABORTED;
-}
-
-int webdav_copy(pblock *pb, Session *sn, Request *rq) {
-    return REQ_ABORTED;
-}
-
-int webdav_move(pblock *pb, Session *sn, Request *rq) {
-    return REQ_ABORTED;
-}
-
-int webdav_propfind(pblock *pb, Session *sn, Request *rq) {
-    /* TODO: clean up if errors occurs */
-
-    /* Get request body which contains the webdav XML request */
-    char   *xml_body;
-    size_t xml_len = 0;
-
-    char *ctlen = pblock_findkeyval(pb_key_content_length, rq->headers);
-    if(ctlen) {
-        xml_len = atoi(ctlen);
-    } else {
-        /* invalid request */
-        printf("invalid request\n");
-        return REQ_ABORTED;
-    }
-
-    xml_body = pool_malloc(sn->pool, xml_len + 1);
-    if(xml_body == NULL) {
-        return REQ_ABORTED;
-    }
-    xml_body[xml_len] = 0;
-    if(!xml_body) {
-        /* server error */
-        printf("server error\n");
-        return REQ_ABORTED;
-    }
-
-    /* get request body */
-    int r = 0;
-    char *xb = xml_body;
-    size_t xl = xml_len;
-    while((r = netbuf_getbytes(sn->inbuf, xb, xl)) != NETBUF_EOF) {
-        xb += r;
-        xl -= r;
-    }
-
-    /*
-     * get requested properties and initialize some stuff
-     */
-    DavCollection *collection = rq->davCollection;
-    if(!collection) {
-        collection = pool_malloc(sn->pool, sizeof(DavCollection));
-        collection->mgr = ucx_map_cstr_get(pmgr_map, "default");
-    }
-    
-    PropfindRequest *davrq = dav_parse_propfind2(sn, rq, xml_body, xml_len);  
-    davrq->sn = sn;
-    davrq->rq = rq;
-    davrq->out = sbuf_new(512);
-    davrq->persistencemgr = collection->mgr;
-    
-    /* begin multistatus response */
-    char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb);
-    char *ppath = pblock_findkeyval(pb_key_ppath, rq->vars);
-    davrq->uri = uri;
-    davrq->path = ppath;
-    
-    VFSContext *vfs = vfs_request_context(sn, rq);
-    
-    struct stat st;
-    if(vfs_stat(vfs, ppath, &st) != 0) {
-        return REQ_ABORTED;
-    }
-    
-    // begin propfind
-    davrq->isdir = S_ISDIR(st.st_mode);
-    davrq->persistencemgr->propfind_begin(davrq->persistencemgr, davrq);
-    
-    // create the response for the requested resource
-    dav_resource_response(davrq, sstr(ppath), sstr(uri));
-    
-    /*
-     * if the requested webdav resource(file) is a directory, we create
-     * a response for every child
-     */
-    if(S_ISDIR(st.st_mode)) {
-        VFS_DIR dir = vfs_opendir(vfs, ppath);
-        if(dir == NULL) {
-            return REQ_ABORTED;
-        }
-        
-        VFS_ENTRY entry;
-        while(vfs_readdir(dir, &entry)) {
-            sstr_t newpath = util_path_append(sn->pool, ppath, entry.name);
-            sstr_t newuri = util_path_append(sn->pool, uri, entry.name); 
-            // child response
-            dav_resource_response(davrq, newpath, newuri);
-        }
-    }
-    
-    // end propfind
-    davrq->persistencemgr->propfind_begin(davrq->persistencemgr, davrq);
-    
-    // end xml
-    sbuf_puts(davrq->out, "</D:multistatus>\n");
-    
-    //printf("%s\n", davrq->out->ptr);
-    
-    // write xml response header
-    sbuf_t *out = sbuf_new(256);
-    sbuf_puts(out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
-    sbuf_puts(out, "<D:multistatus");
-    UcxMapIterator nsiter = ucx_map_iterator(davrq->nsmap->map);
-    XmlNs *ns;
-    UCX_MAP_FOREACH(key, ns, nsiter) {
-        sbuf_puts(out, " xmlns:");
-        sbuf_puts(out, ns->prefix);
-        sbuf_puts(out, "=\"");
-        sbuf_puts(out, ns->xmlns);
-        sbuf_puts(out, "\"");
-    }
-    sbuf_puts(out, ">\n");
-    
-    // send the xml response to the client
-    protocol_status(sn, rq, 207, "Multi Status");
-    pblock_removekey(pb_key_content_type, rq->srvhdrs);
-    pblock_nvinsert("content-type", "text/xml", rq->srvhdrs);
-    pblock_nninsert(
-            "content-length",
-            out->length + davrq->out->length,
-            rq->srvhdrs);
-    
-    http_start_response(sn, rq);
-    
-    // write content
-    size_t nr;
-    nr = net_write(sn->csd, out->ptr, out->length);
-    nr = net_write(sn->csd, davrq->out->ptr, davrq->out->length);
-    
-    sbuf_free(out);
-    dav_free_propfind(davrq);
-    
-    return REQ_PROCEED;
-}
-
-int webdav_proppatch(pblock *pb, Session *sn, Request *rq) {
-    printf("webdav-proppatch\n");
-    /* TODO: clean up if errors occurs */
-    /* TODO: this is the same code as in propfind */
-    char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb);
-    if(uri == NULL) {
-        /* TODO: error */
-        return REQ_ABORTED;
-    }
-
-    // Get request body which contains the webdav XML request
-    char   *xml_body;
-    size_t xml_len = 0;
-
-    char *ctlen = pblock_findkeyval(pb_key_content_length, rq->headers);
-    if(ctlen) {
-        xml_len = atoi(ctlen);
-    } else {
-        // invalid request
-        printf("invalid request\n");
-        return REQ_ABORTED;
-    }
-
-    xml_body = pool_malloc(sn->pool, xml_len + 1);
-    if(xml_body == NULL) {
-        return REQ_ABORTED;
-    }
-    xml_body[xml_len] = 0;
-    if(!xml_body) {
-        // server error
-        printf("server error\n");
-        return REQ_ABORTED;
-    }
-
-    // get request body
-    int r = 0;
-    char *xb = xml_body;
-    size_t xl = xml_len;
-    while((r = netbuf_getbytes(sn->inbuf, xb, xl)) != NETBUF_EOF) {
-        xb += r;
-        xl -= r;
-    }
-    
-    /*
-     * parse the xml request and create the proppatch object
-     */
-    DavCollection *collection = rq->davCollection;
-    if(!collection) {
-        collection = pool_malloc(sn->pool, sizeof(DavCollection));
-        collection->mgr = ucx_map_cstr_get(pmgr_map, "default");
-    }
-    
-    ProppatchRequest *davrq = dav_parse_proppatch(sn, rq, xml_body, xml_len);
-    davrq->sn = sn;
-    davrq->rq = rq;
-    davrq->out = sbuf_new(512);
-    davrq->backend = collection->mgr;
-    davrq->propstat = propstat_create(sn->pool);
-    
-    
-    /* 
-     * begin multistatus response
-     * 
-     * The webdav backend does the most work. The backend->proppatch function
-     * modifies the properties and adds status informations to the propstat
-     * member of the ProppatchRequest. All we have to do here is to create
-     * the xml response and send it to the client
-     */ 
-    
-    /* write xml response header */
-    sbuf_puts(davrq->out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
-    //sbuf_puts(davrq->out, "<D:multistatus xmlns:D=\"DAV:\">\n");
-    sbuf_puts(davrq->out, "<D:multistatus");
-    UcxMapIterator nsiter = ucx_map_iterator(davrq->nsmap->map);
-    XmlNs *ns;
-    UCX_MAP_FOREACH(key, ns, nsiter) {
-        sbuf_puts(davrq->out, " xmlns:");
-        sbuf_puts(davrq->out, ns->prefix);
-        sbuf_puts(davrq->out, "=\"");
-        sbuf_puts(davrq->out, ns->xmlns);
-        sbuf_puts(davrq->out, "\"");
-    }
-    sbuf_puts(davrq->out, ">\n");
-    
-    sbuf_puts(davrq->out, "<D:response>\n<D:href>");
-    sbuf_puts(davrq->out, uri);
-    sbuf_puts(davrq->out, "</D:href>\n");
-    
-    /* do proppatch operation */
-    davrq->backend->proppatch(davrq->backend, davrq);
-    
-    propstat_write(davrq->propstat, davrq->out, 0);
-    
-    sbuf_puts(davrq->out, "</D:response>\n");
-    sbuf_puts(davrq->out, "</D:multistatus>\n");
-    
-    
-    /* send the xml response to the client */
-    protocol_status(sn, rq, 207, "Multi Status");
-    pblock_removekey(pb_key_content_type, rq->srvhdrs);
-    pblock_nvinsert("content-type", "text/xml", rq->srvhdrs);
-    pblock_nninsert("content-length", davrq->out->length, rq->srvhdrs);
-    
-    //pblock_nvinsert("connection", "close", rq->srvhdrs);
-    http_start_response(sn, rq);
-    
-    net_write(sn->csd, davrq->out->ptr, davrq->out->length);
-    
-    dav_free_proppatch(davrq);
-    
-    return REQ_PROCEED;
-}
-
-void dav_resource_response(PropfindRequest *davrq, sstr_t path, sstr_t uri) {
-    printf("dav_resource_response %s %s\n", sstrdup(path).ptr, sstrdup(uri).ptr);
-    
-    sbuf_puts(davrq->out, "<D:response>\n");
-    sbuf_puts(davrq->out, "<D:href>");
-    sbuf_append(davrq->out, uri);
-    sbuf_puts(davrq->out, "</D:href>\n");
-    
-    if(davrq->persistencemgr->vfs_props) {
-        // get some DAV properties from the file system
-        dav_rq_propfind(davrq->persistencemgr, davrq, path.ptr);
-    }
-    davrq->persistencemgr->propfind(davrq->persistencemgr, davrq, path.ptr);
-    
-    if(davrq->prop) {
-        /* 
-         * there are some properties written, so we close the
-         * prop and propstat tag
-         */
-        sbuf_puts(davrq->out, "</D:prop>\n");
-        sbuf_puts(davrq->out, "<D:status>HTTP/1.1 200 OK</D:status>\n");
-        sbuf_puts(davrq->out, "</D:propstat>\n");
-    }
-    
-    if(davrq->notFoundProps != NULL) {
-        sbuf_puts(davrq->out, "<D:propstat>\n<D:prop>\n");
-        DAV_FOREACH(elm, davrq->notFoundProps) {
-            DavProperty *prop = (DavProperty*)elm->data;
-            sbuf_put(davrq->out, '<');
-            sbuf_puts(davrq->out, prop->xmlns->prefix);
-            sbuf_put(davrq->out, ':');
-            
-            sbuf_puts(davrq->out, prop->name);
-            sbuf_puts(davrq->out, " />\n");
-        }
-        sbuf_puts(davrq->out, "</D:prop>\n");
-        sbuf_puts(davrq->out, "<D:status>HTTP/1.1 404 Not Found</D:status>\n");
-        sbuf_puts(davrq->out, "</D:propstat>\n");
-    }
-    
-    sbuf_puts(davrq->out, "</D:response>\n");
-    
-    /* reset */
-    davrq->prop = 0;
-    davrq->notFoundProps = NULL;
-    davrq->forbiddenProps = NULL;
-    
-}
-
-void dav_propfind_add_str_prop(
-        PropfindRequest *davrq,
-        DavProperty* prop,
-        char *str,
-        size_t len)
-{
-    if(!davrq->prop) {
-        sbuf_puts(davrq->out, "<D:propstat>\n<D:prop>\n");
-        davrq->prop = 1;
-    }
-    
-    sbuf_put(davrq->out, '<');
-    sbuf_puts(davrq->out, prop->xmlns->prefix);
-    sbuf_put(davrq->out, ':');
-    sbuf_puts(davrq->out, prop->name);
-    sbuf_put(davrq->out, '>');
-    
-    sbuf_append(davrq->out, sstrn(str, len));
-    
-    sbuf_puts(davrq->out, "</");
-    sbuf_puts(davrq->out, prop->xmlns->prefix);
-    sbuf_put(davrq->out, ':');
-    sbuf_puts(davrq->out, prop->name);
-    sbuf_puts(davrq->out, ">\n");
-}
-
-void dav_propfind_add_prop_error(
-        PropfindRequest *davrq,
-        DavProperty *prop,
-        int error)
-{
-    // TODO: different errors
-    davrq->notFoundProps = ucx_list_append(davrq->notFoundProps, prop);
-}
 
 
-
-
-/* WebDAV Default Backend */
-static PersistenceManager dav_file_backend = {
-    dav_rq_propfind_begin,
-    dav_rq_propfind_end,
-    dav_rq_propfind,
-    dav_rq_proppatch,
-    0
-};
-
-PersistenceManager* create_property_backend() {
-    return &dav_file_backend;
-}
-
-void dav_rq_propfind_begin(PersistenceManager *mgr, PropfindRequest *rq) {
-    
-}
-
-void dav_rq_propfind_end(PersistenceManager *mgr, PropfindRequest *rq) {
-    
-}
-
-void dav_rq_propfind(PersistenceManager *b, PropfindRequest *rq ,char *path) {
-    struct stat st;
-    if(stat(path, &st) != 0) {
-        perror("dav_be_propfind");
-        fprintf(stderr, "Cannot get stat of file: %s\n", path);
-    }
-    
-    if(rq->allprop) {
-        DavProperty prop;
-        prop.xmlns = xmlnsmap_get(rq->nsmap, "DAV:");
-        
-        prop.name = "resourcetype";
-        if(S_ISDIR(st.st_mode)) {
-            dav_propfind_add_str_prop(rq, &prop, "<D:collection/>", 15);
-        } else {
-            dav_propfind_add_str_prop(rq, &prop, NULL, 0);
-        }
-        
-        if(!S_ISDIR(st.st_mode)) {
-            prop.name = "getcontentlength";
-            char buf[32];
-            size_t n = snprintf(buf, 32, "%jd", st.st_size);
-            dav_propfind_add_str_prop(rq, &prop, buf, n);
-        }
-        
-        prop.name = "getlastmodified";
-
-        sstr_t s = date_format_http(st.st_mtime, rq->sn->pool);
-        dav_propfind_add_str_prop(rq, &prop, s.ptr, s.length);
-        
-        prop.name = "creationdate";
-        s = date_format_iso8601(st.st_ctime, rq->sn->pool);
-        dav_propfind_add_str_prop(rq, &prop, s.ptr, s.length);
-        
-        return;
-    }
-    
-    DAV_FOREACH(elm, rq->properties) {
-        DavProperty *prop = (DavProperty*)elm->data;
-        
-        char *s = prop->name;
-        if(!strcmp(s, "resourcetype")) {
-            if(S_ISDIR(st.st_mode)) {
-                dav_propfind_add_str_prop(rq, prop, "<D:collection/>", 15);
-            } else {
-                dav_propfind_add_str_prop(rq, prop, NULL, 0);
-            }
-        } else if(!strcmp(s, "getcontentlength") && !S_ISDIR(st.st_mode)) {
-            char buf[32];
-            size_t n = snprintf(buf, 32, "%jd", st.st_size);
-            dav_propfind_add_str_prop(rq, prop, buf, n);
-        } else if(!strcmp(s, "getlastmodified")) {
-            sstr_t s = date_format_http(st.st_mtime, rq->sn->pool);
-            dav_propfind_add_str_prop(rq, prop, s.ptr, s.length);
-        } else if(!strcmp(s, "creationdate")) {
-            sstr_t s = date_format_iso8601(st.st_ctime, rq->sn->pool);
-            dav_propfind_add_str_prop(rq, prop, s.ptr, s.length);
-        } else {
-            dav_propfind_add_prop_error(rq, prop, 404);
-        }
-    }
-}
-
-void dav_rq_proppatch(PersistenceManager *b, ProppatchRequest *rq) {
-    DAV_FOREACH(p, rq->setProps) {
-        XmlElement *prop = (XmlElement*)p->data;
-        propstat_add(rq->propstat, 403, prop);
-    }
-    
-    DAV_FOREACH(p, rq->removeProps) {
-        XmlElement *prop = (XmlElement*)p->data;
-        propstat_add(rq->propstat, 403, prop);
-    }
-}
-
-
-
-/*---------------------------------- utils ----------------------------------*/
-
-/* XmlNsMap */
-
-XmlNsMap* xmlnsmap_create(pool_handle_t *pool) {
-    XmlNsMap *map = pool_malloc(pool, sizeof(XmlNsMap));
-    UcxMap *uxm = ucx_map_new(16); // TODO: use pool for map
-    if(map == NULL || uxm == NULL) {
-        return NULL;
-    }
-    map->map = uxm;
-    map->pool = pool;
-    map->num = 0;
-    
-    // create DAV: namespace
-    XmlNs *ns = pool_malloc(map->pool, sizeof(XmlNs));
-    ns->xmlns = "DAV:";
-    ns->prefix = "D";
-    ns->nslen = 4;
-    ns->prelen = 1;
-    
-    ucx_map_cstr_put(uxm, "DAV:", ns);
-    
-    return map;
-}
-
-void xmlnsmap_free(XmlNsMap *map) {
-    ucx_map_free(map->map);
-}
-
-XmlNs* xmlnsmap_put(XmlNsMap *map, char *ns) {
-    if(!ns) {
-        return NULL;
-    }
-    
-    XmlNs *xmlns = xmlnsmap_get(map, ns);
-    if(xmlns != NULL) {
-        return xmlns;
-    }
-    
-    xmlns = pool_malloc(map->pool, sizeof(XmlNs));
-    if(xmlns == NULL) {
-        return NULL;
-    }
-    
-    sstr_t newns = sstrdup(sstr(ns));
-    
-    xmlns->xmlns = newns.ptr;
-    xmlns->nslen = newns.length;
-    
-    xmlns->prefix = pool_calloc(map->pool, 1, 8);
-    xmlns->prelen = snprintf(xmlns->prefix, 7, "x%d", map->num);
-    
-    ucx_map_cstr_put(map->map, ns, xmlns); // TODO: check return value
-    map->num++;
-    return xmlns;
-}
-
-XmlNs* xmlnsmap_get(XmlNsMap *map, char *ns) {
-    return ucx_map_cstr_get(map->map, ns);
-}
-
-
-/* XmlElement */
-
-void xmlelm_add_child(XmlElement *parent, XmlElement *child) {
-    if(parent->ctlen == 0) {
-        parent->content = ucx_list_append(parent->content, child);
-    }
-}
-
-void xmlelm_write(XmlElement *elm, Buffer *out, int wv) {
-    sbuf_append(out, sstrn("<", 1));
-    sbuf_append(out, sstrn(elm->xmlns->prefix, elm->xmlns->prelen));
-    sbuf_append(out, sstrn(":", 1));
-    sbuf_append(out, sstr(elm->name));
-    
-    if(wv) {
-        if(elm->ctlen == 0) {
-            if(elm->content == NULL) {
-                sbuf_append(out, sstrn(" />", 3));
-            } else {
-                sbuf_append(out, sstrn(">", 1));
-                DAV_FOREACH(pr, (UcxList*)elm->content) {
-                    xmlelm_write((XmlElement*)pr->data, out, 1);
-                }
-                sbuf_append(out, sstrn("</", 2));
-                sbuf_append(out, sstrn(elm->xmlns->prefix, elm->xmlns->prelen));
-                sbuf_append(out, sstrn(":", 1));
-                sbuf_append(out, sstr(elm->name));
-                sbuf_append(out, sstrn(">", 1));
-            }
-        } else {
-            sbuf_append(out, sstrn(" />", 3));
-            sbuf_append(out, sstrn((char*)elm->content, elm->ctlen));
-            sbuf_append(out, sstrn("</", 2));
-            sbuf_append(out, sstrn(elm->xmlns->prefix, elm->xmlns->prelen));
-            sbuf_append(out, sstrn(":", 1));
-            sbuf_append(out, sstr(elm->name));
-            sbuf_append(out, sstrn(">", 1));
-        }
-    } else {
-        sbuf_append(out, sstrn(" />", 3));
-    }
-}
-
-
-/* PropstatMap */
-
-Propstat* propstat_create(pool_handle_t *pool) {
-    Propstat *propstat = (Propstat*)pool_malloc(pool, sizeof(Propstat));
-    propstat->map = ucx_map_new(8);
-    propstat->okprop = NULL;
-    propstat->pool = pool;
-    return propstat;
-}
-
-void propstat_add(Propstat *propstat, int status, XmlElement *prop) {
-    if(status == 200) {
-        propstat->okprop = ucx_list_append(propstat->okprop, prop);
-    } else {
-        UcxKey key;
-        key.data = &status;
-        key.len = sizeof(int);
-
-        UcxList *list = ucx_map_get(propstat->map, key);
-        list = ucx_list_append(list, prop);
-
-        ucx_map_put(propstat->map, key, list);
-    }
-}
-
-void propstat_write(Propstat *propstat, Buffer *out, int wv) {
-    if(propstat->okprop) {
-        sbuf_puts(out, "<D:propstat>\n<D:prop>\n");
-        
-        DAV_FOREACH(prop, propstat->okprop) {    
-            xmlelm_write((XmlElement*)prop->data, out, wv);
-        }
-        
-        sbuf_puts(out, "\n</D:prop>\n<D:status>HTTP/1.1 200 OK</D:status>\n");
-        sbuf_puts(out, "</D:propstat>\n");
-    }
-    
-    UcxMapIterator iter = ucx_map_iterator(propstat->map);
-    UcxList *proplist;
-    UCX_MAP_FOREACH(key, proplist, iter) { 
-        if(proplist) {
-            sbuf_puts(out, "<D:propstat>\n<D:prop>\n");
-            
-            DAV_FOREACH(prop, proplist) {
-                xmlelm_write((XmlElement*)prop->data, out, wv);
-            }
-                
-            sbuf_puts(out, "\n</D:prop>\n<D:status>");
-                
-            int status = *(int*)iter.cur->key.data;
-            if(status < 1000 && status > 0) {
-                char buf[5];
-                buf[4] = 0;
-                sprintf(buf, "%d ", status);
-                sbuf_puts(out, "HTTP/1.1 ");
-                sbuf_puts(out, buf);
-                sbuf_puts(out, (char*)protocol_status_message(status));
-            }
-            
-            sbuf_puts(out, "</D:status>\n</D:propstat>\n");
-        }
-    }
-}
--- a/src/server/webdav/webdav.h	Sat Oct 31 15:01:07 2015 +0100
+++ b/src/server/webdav/webdav.h	Sat Oct 31 16:39:12 2015 +0100
@@ -39,21 +39,6 @@
 extern "C" {
 #endif
 
-#define DAV_FOREACH(elem, list) \
-        for (UcxList *elem = list ; elem != NULL ; elem = elem->next)
-
-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);
-
-
-
-PersistenceManager* create_property_backend();
-void dav_rq_propfind_begin(PersistenceManager *mgr, PropfindRequest *rq);
-void dav_rq_propfind_end(PersistenceManager *mgr, PropfindRequest *rq);
-void dav_rq_propfind(PersistenceManager *mgr, PropfindRequest *rq, char *path);
-void dav_rq_proppatch(PersistenceManager *mgr, ProppatchRequest *rq);
 
 
 #ifdef	__cplusplus
--- a/templates/config/init.conf	Sat Oct 31 15:01:07 2015 +0100
+++ b/templates/config/init.conf	Sat Oct 31 16:39:12 2015 +0100
@@ -3,4 +3,4 @@
 #
 
 Init fn="admin-init"
-Init fn="webdav-init"
+

mercurial