# HG changeset patch # User Olaf Wintermann # Date 1651401228 -7200 # Node ID 44cf877b3d9f8d913425d405f94c9c94b86db4f7 # Parent dc5b0fee49df44597a8ad00638a09ebd728a70b2 add support for xml properties in propfind/proppatch requests (pg) diff -r dc5b0fee49df -r 44cf877b3d9f src/server/plugins/postgresql/pgtest.c --- 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; } diff -r dc5b0fee49df -r 44cf877b3d9f src/server/plugins/postgresql/pgtest.h --- 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 @@ \ " +#define PG_TEST_PROPPATCH2 " \ + \ + \ + \ + \ + value\ + example\ + \ + \ + \ + \ + \ + \ + " + #ifdef __cplusplus } #endif diff -r dc5b0fee49df -r 44cf877b3d9f src/server/plugins/postgresql/webdav.c --- 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, diff -r dc5b0fee49df -r 44cf877b3d9f src/server/test/xml.c --- 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); } diff -r dc5b0fee49df -r 44cf877b3d9f src/server/webdav/xml.c --- 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);