add support for xml properties in propfind/proppatch requests (pg) webdav

Sun, 01 May 2022 12:33:48 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 01 May 2022 12:33:48 +0200
branch
webdav
changeset 324
44cf877b3d9f
parent 323
dc5b0fee49df
child 325
2d14055c3543

add support for xml properties in propfind/proppatch requests (pg)

src/server/plugins/postgresql/pgtest.c file | annotate | diff | comparison | revisions
src/server/plugins/postgresql/pgtest.h file | annotate | diff | comparison | revisions
src/server/plugins/postgresql/webdav.c file | annotate | diff | comparison | revisions
src/server/test/xml.c file | annotate | diff | comparison | revisions
src/server/webdav/xml.c file | annotate | diff | comparison | revisions
--- a/src/server/plugins/postgresql/pgtest.c	Sun May 01 11:14:47 2022 +0200
+++ b/src/server/plugins/postgresql/pgtest.c	Sun May 01 12:33:48 2022 +0200
@@ -844,6 +844,22 @@
     test_multistatus_destroy(ms);
     testutil_iostream_destroy(st);
     
+    // Test 2: xml property value
+    init_test_webdav_method(&sn, &rq, &st, &pb, "PROPPATCH", "/proppatch/pp1", PG_TEST_PROPPATCH2);
+    rq->davCollection = create_test_pgdav(sn, rq);
+    
+    ret = webdav_proppatch(pb, sn, rq);
+    UCX_TEST_ASSERT(ret == REQ_PROCEED, "proppatch2 failed");
+    
+    //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space);
+    
+    ms = test_parse_multistatus(st->buf->space, st->buf->size);
+    UCX_TEST_ASSERT(ms, "proppatch2 response is not valid xml");
+    
+    testutil_destroy_session(sn);
+    test_multistatus_destroy(ms);
+    testutil_iostream_destroy(st);
+    
     
     UCX_TEST_END;
 }
--- a/src/server/plugins/postgresql/pgtest.h	Sun May 01 11:14:47 2022 +0200
+++ b/src/server/plugins/postgresql/pgtest.h	Sun May 01 12:33:48 2022 +0200
@@ -104,6 +104,21 @@
             </D:set> \
         </D:propertyupdate>"
 
+#define PG_TEST_PROPPATCH2 "<?xml version=\"1.0\" encoding=\"utf-8\" ?> \
+        <D:propertyupdate xmlns:D=\"DAV:\" xmlns:X=\"http://example.com/\" xmlns:XA=\"http://example.com/a/\"> \
+            <D:set> \
+                <D:prop>\
+                    <XA:xtest>\
+                        <XA:elm>value</XA:elm>\
+                        <X:ex>example</X:ex>\
+                        <Z:nstest xmlns:Z=\"http://example.com/z\">\
+                            <Y:nstest2 xmlns:Y=\"http://example.com/y\"></Y:nstest2>\
+                        </Z:nstest>\
+                    </XA:xtest>\
+                </D:prop> \
+            </D:set> \
+        </D:propertyupdate>"
+
 #ifdef __cplusplus
 }
 #endif
--- a/src/server/plugins/postgresql/webdav.c	Sun May 01 11:14:47 2022 +0200
+++ b/src/server/plugins/postgresql/webdav.c	Sun May 01 12:33:48 2022 +0200
@@ -598,7 +598,12 @@
                     property->value.text.str = content;
                     property->value.text.length = pvalue_len;
                 } else {
-                    // TODO
+                    WebdavNSList *nslist = wsxml_string2nslist(pool, nsdef); 
+                    property->vtype = WS_VALUE_XML_DATA;
+                    property->value.data->data = content;
+                    property->value.data->length = pvalue_len;
+                    property->value.data->namespaces = nslist;
+                    
                 }
             }
             
@@ -731,12 +736,20 @@
     // convert the property value to WSXmlData
     // property->vtype == WS_VALUE_XML_NODE should always be true
     WSXmlData *property_value = property->vtype == WS_VALUE_XML_NODE ? wsxml_node2data(pool, property->value.node) : NULL;
-    char *value_str = property_value ? property_value->data : NULL;
-
-    // TODO: convert WebdavNSList to a string
+    char *value_str = NULL;
+    char *nsdef_str = NULL;
+    if(property_value) {
+        value_str = property_value->data;
+        if(property_value->namespaces) {
+            nsdef_str = wsxml_nslist2string(pool, property_value->namespaces);
+            if(!nsdef_str) {
+                return 1; // OOM
+            }
+        }
+    }
 
     // exec sql
-    const char* params[7] = { resource_id_str, (const char*)ns->prefix, (const char*)ns->href, property->name, NULL, NULL, value_str}; 
+    const char* params[7] = { resource_id_str, (const char*)ns->prefix, (const char*)ns->href, property->name, NULL, nsdef_str, value_str}; 
     PGresult *result = PQexecParams(
         pgdav->connection,
         sql_proppatch_set,
--- a/src/server/test/xml.c	Sun May 01 11:14:47 2022 +0200
+++ b/src/server/test/xml.c	Sun May 01 12:33:48 2022 +0200
@@ -426,5 +426,5 @@
     
     
     UCX_TEST_END;
-    //testutil_destroy_session(sn);
+    testutil_destroy_session(sn);
 }
--- a/src/server/webdav/xml.c	Sun May 01 11:14:47 2022 +0200
+++ b/src/server/webdav/xml.c	Sun May 01 12:33:48 2022 +0200
@@ -340,7 +340,7 @@
     writer_init_with_stream(&writer, buf, buf_writefunc, buffer, 512);
     
     WSXmlData *data = NULL;
-    if(!wsxml_write_nodes_without_nsdef(pool, &writer, node) && !writer_flush(&writer)) {
+    if(!wsxml_write_nodes(pool, &writer, NULL, node) && !writer_flush(&writer)) {
         data = pool_malloc(pool, sizeof(WSXmlData));
         if(data) {
             data->data = pool_malloc(pool, buf->size + 1);

mercurial