# HG changeset patch # User Olaf Wintermann # Date 1650990085 -7200 # Node ID 09676b559091cac9e862af052ee4df165a9d8dc6 # Parent 4090fc1b1c529482883b9c4ead5840fe4caa293e store property prefix in the database diff -r 4090fc1b1c52 -r 09676b559091 doc/development/postgresql_vfs.sql --- a/doc/development/postgresql_vfs.sql Tue Apr 26 15:19:12 2022 +0200 +++ b/doc/development/postgresql_vfs.sql Tue Apr 26 18:21:25 2022 +0200 @@ -17,8 +17,11 @@ create table Property ( property_id serial primary key, resource_id int references Resource(resource_id) on delete cascade, + prefix text not null, xmlns text not null, pname text not null, + lang text, + nsdeflist text, pvalue text ); diff -r 4090fc1b1c52 -r 09676b559091 src/server/plugins/postgresql/pgtest.c --- a/src/server/plugins/postgresql/pgtest.c Tue Apr 26 15:19:12 2022 +0200 +++ b/src/server/plugins/postgresql/pgtest.c Tue Apr 26 18:21:25 2022 +0200 @@ -512,7 +512,7 @@ const char* params[1] = { idstr }; PGresult *result = PQexecParams( test_connection, - "insert into Property(resource_id, xmlns, pname, pvalue) values ($1, 'http://example.com/', 'test', 'testvalue');", + "insert into Property(resource_id, prefix, xmlns, pname, pvalue) values ($1, 'x', 'http://example.com/', 'test', 'testvalue');", 1, // number of parameters NULL, params, // parameter value @@ -525,7 +525,7 @@ result = PQexecParams( test_connection, - "insert into Property(resource_id, xmlns, pname, pvalue) values ($1, 'http://example.com/', 'prop2', 'value2');", + "insert into Property(resource_id, prefix, xmlns, pname, pvalue) values ($1, 'x', 'http://example.com/', 'prop2', 'value2');", 1, // number of parameters NULL, params, // parameter value @@ -540,7 +540,7 @@ snprintf(idstr, 32, "%" PRId64, res2_id); result = PQexecParams( test_connection, - "insert into Property(resource_id, xmlns, pname, pvalue) values ($1, 'http://example.com/', 'test', 'res2test');", + "insert into Property(resource_id, prefix, xmlns, pname, pvalue) values ($1, 'x', 'http://example.com/', 'test', 'res2test');", 1, // number of parameters NULL, params, // parameter value diff -r 4090fc1b1c52 -r 09676b559091 src/server/plugins/postgresql/webdav.c --- a/src/server/plugins/postgresql/webdav.c Tue Apr 26 15:19:12 2022 +0200 +++ b/src/server/plugins/postgresql/webdav.c Tue Apr 26 18:21:25 2022 +0200 @@ -66,8 +66,11 @@ r.lastmodified,\n\ r.creationdate,\n\ r.contentlength,\n\ + p.prefix,\n\ p.xmlns,\n\ p.pname,\n\ + p.lang,\n\ + p.nsdeflist,\n\ p.pvalue\n\ from Resource r\n\ left join Property p on r.resource_id = p.resource_id\n\ @@ -85,8 +88,11 @@ r.lastmodified,\n\ r.creationdate,\n\ r.contentlength,\n\ + p.prefix,\n\ p.xmlns,\n\ p.pname,\n\ + p.lang,\n\ + p.nsdeflist,\n\ p.pvalue\n\ from Resource r\n\ left join (\n\ @@ -110,8 +116,11 @@ r.lastmodified,\n\ r.creationdate,\n\ r.contentlength,\n\ + p.prefix,\n\ p.xmlns,\n\ p.pname,\n\ + p.lang,\n\ + p.nsdeflist,\n\ p.pvalue\n\ from Resource r\n\ left join Property p on r.resource_id = p.resource_id\n\ @@ -133,8 +142,11 @@ r.lastmodified,\n\ r.creationdate,\n\ r.contentlength,\n\ + p.prefix,\n\ p.xmlns,\n\ p.pname,\n\ + p.lang,\n\ + p.nsdeflist,\n\ p.pvalue\n\ from Resource r\n\ left join (\n\ @@ -172,8 +184,11 @@ r.lastmodified,\n\ r.creationdate,\n\ r.contentlength,\n\ + p.prefix,\n\ p.xmlns,\n\ p.pname,\n\ + p.lang,\n\ + p.nsdeflist,\n\ p.pvalue\n\ from resolvepath r\n\ left join Property p on r.resource_id = p.resource_id\n\ @@ -208,8 +223,11 @@ r.lastmodified,\n\ r.creationdate,\n\ r.contentlength,\n\ + p.prefix,\n\ p.xmlns,\n\ p.pname,\n\ + p.lang,\n\ + p.nsdeflist,\n\ p.pvalue\n\ from resolvepath r\n\ left join (\n\ @@ -446,9 +464,12 @@ // 5: lastmodified // 6: creationdate // 7: contentlength - // 8: property xmlns - // 9: property name - // 10: property value + // 8: property prefix + // 9: property xmlns + // 10: property name + // 11: property lang + // 12: property nsdeflist + // 13: property value char *path = PQgetvalue(result, r, 0); char *res_id = PQgetvalue(result, r, 1); @@ -517,9 +538,17 @@ // dead properties if(!PQgetisnull(result, r, 9)) { - char *xmlns = PQgetvalue(result, r, 8); - char *pname = PQgetvalue(result, r, 9); - char *pvalue = PQgetvalue(result, r, 10); + char *prefix = PQgetvalue(result, r, 8); + char *xmlns = PQgetvalue(result, r, 9); + char *pname = PQgetvalue(result, r, 10); + char *lang = PQgetvalue(result, r, 11); + char *nsdef = PQgetvalue(result, r, 12); + char *pvalue = PQgetvalue(result, r, 13); + + int pvalue_len = PQgetlength(result, r, 13); + WSBool lang_isnull = PQgetisnull(result, r, 11); + WSBool nsdef_isnull = PQgetisnull(result, r, 12); + WSBool pvalue_isnull = PQgetisnull(result, r, 13); WebdavProperty *property = pool_malloc(pool, sizeof(WebdavProperty)); property->lang = NULL; @@ -528,12 +557,26 @@ xmlNs *namespace = pool_malloc(pool, sizeof(xmlNs)); memset(namespace, 0, sizeof(struct _xmlNs)); namespace->href = (xmlChar*)pool_strdup(pool, xmlns); - namespace->prefix = (xmlChar*)"zx1"; // TODO + namespace->prefix = (xmlChar*)pool_strdup(pool, prefix); property->namespace = namespace; - property->vtype = WS_VALUE_TEXT; - property->value.text.str = pool_strdup(pool, pvalue); - property->value.text.length = strlen(pvalue); + if(!lang_isnull) { + property->lang = (xmlChar*)pool_strdup(pool, lang); + } + + if(!pvalue_isnull) { + char *content = pool_malloc(pool, pvalue_len+1); + memcpy(content, pvalue, pvalue_len); + content[pvalue_len] = '\0'; + + if(nsdef_isnull) { + property->vtype = WS_VALUE_TEXT; + property->value.text.str = content; + property->value.text.length = pvalue_len; + } else { + // TODO + } + } resource->addproperty(resource, property, 200); }