propfind supports allprop

Sat, 19 Jan 2013 21:52:21 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 19 Jan 2013 21:52:21 +0100
changeset 50
4d39adda7a38
parent 49
1fd94945796e
child 51
b28cf69f42e8

propfind supports allprop

src/server/webdav/saxhandler.cpp file | annotate | diff | comparison | revisions
src/server/webdav/webdav.c file | annotate | diff | comparison | revisions
--- a/src/server/webdav/saxhandler.cpp	Sat Jan 19 20:51:16 2013 +0100
+++ b/src/server/webdav/saxhandler.cpp	Sat Jan 19 21:52:21 2013 +0100
@@ -75,9 +75,11 @@
     char *ns  = XMLString::transcode(uri);
     char *name = XMLString::transcode(localname);
     
-    if(!strcmp(ns, "DAV:") && !strcmp(name, "prop")) {
+    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) {
+    } else if(davPropTag && property == NULL && !davrq->allprop) {
         property = (DavProperty*)pool_malloc(pool, sizeof(DavProperty));
         //property = (DavProperty*)malloc(sizeof(DavProperty));
         /* TODO: pool_malloc makes big mistakes!! */
--- a/src/server/webdav/webdav.c	Sat Jan 19 20:51:16 2013 +0100
+++ b/src/server/webdav/webdav.c	Sat Jan 19 21:52:21 2013 +0100
@@ -520,6 +520,35 @@
         fprintf(stderr, "Cannot get stat of file: %s\n", path);
     }
     
+    if(rq->allprop) {
+        DavProperty prop;
+        prop.xmlns = "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, "%d", st.st_size);
+            dav_propfind_add_str_prop(rq, &prop, buf, n);
+        }
+        
+        prop.name = "getlastmodified";
+        sstr_t s = date_format_http(st.st_mtim.tv_sec, rq->sn->pool);
+        dav_propfind_add_str_prop(rq, &prop, s.ptr, s.length);
+        
+        prop.name = "creationdate";
+        s = date_format_iso8601(st.st_ctim.tv_sec, 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;
         

mercurial