1
/* Licensed to the Apache Software Foundation (ASF) under one or more
2
* contributor license agreements. See the NOTICE file distributed with
3
* this work for additional information regarding copyright ownership.
4
* The ASF licenses this file to You under the Apache License, Version 2.0
5
* (the "License"); you may not use this file except in compliance with
6
* the License. You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
18
** DAV extension module for Apache 2.0.*
19
** - Property database handling (repository-independent)
25
** This version assumes that there is a per-resource database provider
26
** to record properties. The database provider decides how and where to
27
** store these databases.
29
** The DBM keys for the properties have the following form:
31
** namespace ":" propname
33
** For example: 5:author
35
** The namespace provides an integer index into the namespace table
36
** (see below). propname is simply the property name, without a namespace
39
** A special case exists for properties that had a prefix starting with
40
** "xml". The XML Specification reserves these for future use. mod_dav
41
** stores and retrieves them unchanged. The keys for these properties
46
** The propname will contain the prefix and the property name. For
47
** example, a key might be ":xmlfoo:name"
49
** The ":name" style will also be used for properties that do not
50
** exist within a namespace.
52
** The DBM values consist of two null-terminated strings, appended
53
** together (the null-terms are retained and stored in the database).
54
** The first string is the xml:lang value for the property. An empty
55
** string signifies that a lang value was not in context for the value.
56
** The second string is the property value itself.
61
** The namespace table is an array that lists each of the namespaces
62
** that are in use by the properties in the given propdb. Each entry
63
** in the array is a simple URI.
65
** For example: http://www.foo.bar/standards/props/
67
** The prefix used for the property is stripped and the URI for it
68
** is entered into the namespace table. Also, any namespaces used
69
** within the property value will be entered into the table (and
70
** stripped from the child elements).
72
** The namespaces are stored in the DBM database under the "METADATA" key.
75
** STRIPPING NAMESPACES
77
** Within the property values, the namespace declarations (xmlns...)
78
** are stripped. Each element and attribute will have its prefix removed
79
** and a new prefix inserted.
81
** This must be done so that we can return multiple properties in a
82
** PROPFIND which may have (originally) used conflicting prefixes. For
83
** that case, we must bind all property value elements to new namespace
86
** This implies that clients must NOT be sensitive to the namespace
87
** prefix used for their properties. It WILL change when the properties
88
** are returned (we return them as "ns<index>", e.g. "ns5"). Also, the
89
** property value can contain ONLY XML elements and CDATA. PI and comment
90
** elements will be stripped. CDATA whitespace will be preserved, but
91
** whitespace within element tags will be altered. Attribute ordering
92
** may be altered. Element and CDATA ordering will be preserved.
95
** ATTRIBUTES ON PROPERTY NAME ELEMENTS
97
** When getting/setting properties, the XML used looks like:
100
** <propname1>value</propname1>
101
** <propname2>value</propname1>
104
** This implementation (mod_dav) DOES NOT save any attributes that are
105
** associated with the <propname1> element. The property value is deemed
106
** to be only the contents ("value" in the above example).
108
** We do store the xml:lang value (if any) that applies to the context
109
** of the <propname1> element. Whether the xml:lang attribute is on
110
** <propname1> itself, or from a higher level element, we will store it
111
** with the property value.
116
** The DBM db contains a key named "METADATA" that holds database-level
117
** information, such as the namespace table. The record also contains the
118
** db's version number as the very first 16-bit value. This first number
119
** is actually stored as two single bytes: the first byte is a "major"
120
** version number. The second byte is a "minor" number.
122
** If the major number is not what mod_dav expects, then the db is closed
123
** immediately and an error is returned. A minor number change is
124
** acceptable -- it is presumed that old/new dav_props.c can deal with
125
** the database format. For example, a newer dav_props might update the
126
** minor value and append information to the end of the metadata record
127
** (which would be ignored by previous versions).
132
** At the moment, for the dav_get_allprops() and dav_get_props() functions,
133
** we must return a set of xmlns: declarations for ALL known namespaces
134
** in the file. There isn't a way to filter this because we don't know
135
** which are going to be used or not. Examining property names is not
136
** sufficient because the property values could use entirely different
139
** ==> we must devise a scheme where we can "garbage collect" the namespace
140
** entries from the property database.
144
#include "apr_strings.h"
146
#define APR_WANT_STDIO
147
#define APR_WANT_BYTEFUNC
148
#include "apr_want.h"
152
#include "http_log.h"
153
#include "http_request.h"
156
** There is some rough support for writable DAV:getcontenttype and
157
** DAV:getcontentlanguage properties. If this #define is (1), then
158
** this support is disabled.
160
** We are disabling it because of a lack of support in GET and PUT
161
** operations. For GET, it would be "expensive" to look for a propdb,
162
** open it, and attempt to extract the Content-Type and Content-Language
163
** values for the response.
164
** (Handling the PUT would not be difficult, though)
166
#define DAV_DISABLE_WRITABLE_PROPS 1
168
#define DAV_EMPTY_VALUE "\0" /* TWO null terms */
171
apr_pool_t *p; /* the pool we should use */
172
request_rec *r; /* the request record */
174
const dav_resource *resource; /* the target resource */
176
int deferred; /* open of db has been deferred */
177
dav_db *db; /* underlying database containing props */
179
apr_array_header_t *ns_xlate; /* translation of an elem->ns to URI */
180
dav_namespace_map *mapping; /* namespace mapping */
182
dav_lockdb *lockdb; /* the lock database */
184
dav_buffer wb_lock; /* work buffer for lockdiscovery property */
186
/* if we ever run a GET subreq, it will be stored here */
189
/* hooks we should use for processing (based on the target resource) */
190
const dav_hooks_db *db_hooks;
193
/* NOTE: dav_core_props[] and the following enum must stay in sync. */
194
/* ### move these into a "core" liveprop provider? */
195
static const char * const dav_core_props[] =
198
"getcontentlanguage",
205
DAV_PROPID_CORE_getcontenttype = DAV_PROPID_CORE,
206
DAV_PROPID_CORE_getcontentlanguage,
207
DAV_PROPID_CORE_lockdiscovery,
208
DAV_PROPID_CORE_supportedlock,
210
DAV_PROPID_CORE_UNKNOWN
214
** This structure is used to track information needed for a rollback.
216
typedef struct dav_rollback_item {
217
/* select one of the two rollback context structures based on the
218
value of dav_prop_ctx.is_liveprop */
219
dav_deadprop_rollback *deadprop;
220
dav_liveprop_rollback *liveprop;
225
static int dav_find_liveprop_provider(dav_propdb *propdb,
227
const char *propname,
228
const dav_hooks_liveprop **provider)
234
if (ns_uri == NULL) {
235
/* policy: liveprop providers cannot define no-namespace properties */
236
return DAV_PROPID_CORE_UNKNOWN;
239
/* check liveprop providers first, so they can define core properties */
240
propid = dav_run_find_liveprop(propdb->resource, ns_uri, propname,
246
/* check for core property */
247
if (strcmp(ns_uri, "DAV:") == 0) {
248
const char * const *p = dav_core_props;
250
for (propid = DAV_PROPID_CORE; *p != NULL; ++p, ++propid)
251
if (strcmp(propname, *p) == 0) {
256
/* no provider for this property */
257
return DAV_PROPID_CORE_UNKNOWN;
260
static void dav_find_liveprop(dav_propdb *propdb, apr_xml_elem *elem)
263
dav_elem_private *priv = elem->priv;
264
const dav_hooks_liveprop *hooks;
267
if (elem->ns == APR_XML_NS_NONE)
269
else if (elem->ns == APR_XML_NS_DAV_ID)
272
ns_uri = APR_XML_GET_URI_ITEM(propdb->ns_xlate, elem->ns);
274
priv->propid = dav_find_liveprop_provider(propdb, ns_uri, elem->name,
277
/* ### this test seems redundant... */
278
if (priv->propid != DAV_PROPID_CORE_UNKNOWN) {
279
priv->provider = hooks;
283
/* is the live property read/write? */
284
static int dav_rw_liveprop(dav_propdb *propdb, dav_elem_private *priv)
286
int propid = priv->propid;
289
** Check the liveprop provider (if this is a provider-defined prop)
291
if (priv->provider != NULL) {
292
return (*priv->provider->is_writable)(propdb->resource, propid);
295
/* these are defined as read-only */
296
if (propid == DAV_PROPID_CORE_lockdiscovery
297
#if DAV_DISABLE_WRITABLE_PROPS
298
|| propid == DAV_PROPID_CORE_getcontenttype
299
|| propid == DAV_PROPID_CORE_getcontentlanguage
301
|| propid == DAV_PROPID_CORE_supportedlock
307
/* these are defined as read/write */
308
if (propid == DAV_PROPID_CORE_getcontenttype
309
|| propid == DAV_PROPID_CORE_getcontentlanguage
310
|| propid == DAV_PROPID_CORE_UNKNOWN) {
316
** We don't recognize the property, so it must be dead (and writable)
321
/* do a sub-request to fetch properties for the target resource's URI. */
322
static void dav_do_prop_subreq(dav_propdb *propdb)
324
/* perform a "GET" on the resource's URI (note that the resource
325
may not correspond to the current request!). */
326
propdb->subreq = ap_sub_req_lookup_uri(propdb->resource->uri, propdb->r,
330
static dav_error * dav_insert_coreprop(dav_propdb *propdb,
331
int propid, const char *name,
332
dav_prop_insert what,
333
apr_text_header *phdr,
334
dav_prop_insert *inserted)
336
const char *value = NULL;
339
*inserted = DAV_PROP_INSERT_NOTDEF;
341
/* fast-path the common case */
342
if (propid == DAV_PROPID_CORE_UNKNOWN)
347
case DAV_PROPID_CORE_lockdiscovery:
348
if (propdb->lockdb != NULL) {
351
if ((err = dav_lock_query(propdb->lockdb, propdb->resource,
353
return dav_push_error(propdb->p, err->status, 0,
354
"DAV:lockdiscovery could not be "
355
"determined due to a problem fetching "
356
"the locks for this resource.",
360
/* fast-path the no-locks case */
366
** This may modify the buffer. value may point to
367
** wb_lock.pbuf or a string constant.
369
value = dav_lock_get_activelock(propdb->r, locks,
372
/* make a copy to isolate it from changes to wb_lock */
373
value = apr_pstrdup(propdb->p, propdb->wb_lock.buf);
378
case DAV_PROPID_CORE_supportedlock:
379
if (propdb->lockdb != NULL) {
380
value = (*propdb->lockdb->hooks->get_supportedlock)(propdb->resource);
384
case DAV_PROPID_CORE_getcontenttype:
385
if (propdb->subreq == NULL) {
386
dav_do_prop_subreq(propdb);
388
if (propdb->subreq->content_type != NULL) {
389
value = propdb->subreq->content_type;
393
case DAV_PROPID_CORE_getcontentlanguage:
397
if (propdb->subreq == NULL) {
398
dav_do_prop_subreq(propdb);
400
if ((lang = apr_table_get(propdb->subreq->headers_out,
401
"Content-Language")) != NULL) {
408
/* fall through to interpret as a dead property */
412
/* if something was supplied, then insert it */
416
if (what == DAV_PROP_INSERT_SUPPORTED) {
417
/* use D: prefix to refer to the DAV: namespace URI,
418
* and let the namespace attribute default to "DAV:"
420
s = apr_psprintf(propdb->p,
421
"<D:supported-live-property D:name=\"%s\"/>" DEBUG_CR,
424
else if (what == DAV_PROP_INSERT_VALUE && *value != '\0') {
425
/* use D: prefix to refer to the DAV: namespace URI */
426
s = apr_psprintf(propdb->p, "<D:%s>%s</D:%s>" DEBUG_CR,
430
/* use D: prefix to refer to the DAV: namespace URI */
431
s = apr_psprintf(propdb->p, "<D:%s/>" DEBUG_CR, name);
433
apr_text_append(propdb->p, phdr, s);
441
static dav_error * dav_insert_liveprop(dav_propdb *propdb,
442
const apr_xml_elem *elem,
443
dav_prop_insert what,
444
apr_text_header *phdr,
445
dav_prop_insert *inserted)
447
dav_elem_private *priv = elem->priv;
449
*inserted = DAV_PROP_INSERT_NOTDEF;
451
if (priv->provider == NULL) {
452
/* this is a "core" property that we define */
453
return dav_insert_coreprop(propdb, priv->propid, elem->name,
454
what, phdr, inserted);
457
/* ask the provider (that defined this prop) to insert the prop */
458
*inserted = (*priv->provider->insert_prop)(propdb->resource, priv->propid,
464
static void dav_output_prop_name(apr_pool_t *pool,
465
const dav_prop_name *name,
467
apr_text_header *phdr)
471
if (*name->ns == '\0')
472
s = apr_psprintf(pool, "<%s/>" DEBUG_CR, name->name);
474
const char *prefix = dav_xmlns_add_uri(xi, name->ns);
476
s = apr_psprintf(pool, "<%s:%s/>" DEBUG_CR, prefix, name->name);
479
apr_text_append(pool, phdr, s);
482
static void dav_insert_xmlns(apr_pool_t *p, const char *pre_prefix, long ns,
483
const char *ns_uri, apr_text_header *phdr)
487
s = apr_psprintf(p, " xmlns:%s%ld=\"%s\"", pre_prefix, ns, ns_uri);
488
apr_text_append(p, phdr, s);
491
static dav_error *dav_really_open_db(dav_propdb *propdb, int ro)
495
/* we're trying to open the db; turn off the 'deferred' flag */
496
propdb->deferred = 0;
498
/* ask the DB provider to open the thing */
499
err = (*propdb->db_hooks->open)(propdb->p, propdb->resource, ro,
502
return dav_push_error(propdb->p, HTTP_INTERNAL_SERVER_ERROR,
503
DAV_ERR_PROP_OPENING,
504
"Could not open the property database.",
509
** NOTE: propdb->db could be NULL if we attempted to open a readonly
510
** database that doesn't exist. If we require read/write
511
** access, then a database was created and opened.
517
DAV_DECLARE(dav_error *)dav_open_propdb(request_rec *r, dav_lockdb *lockdb,
518
const dav_resource *resource,
520
apr_array_header_t * ns_xlate,
521
dav_propdb **p_propdb)
523
dav_propdb *propdb = apr_pcalloc(r->pool, sizeof(*propdb));
528
if (resource->uri == NULL) {
529
return dav_new_error(r->pool, HTTP_INTERNAL_SERVER_ERROR, 0,
530
"INTERNAL DESIGN ERROR: resource must define "
536
apr_pool_create(&propdb->p, r->pool);
537
propdb->resource = resource;
538
propdb->ns_xlate = ns_xlate;
540
propdb->db_hooks = DAV_GET_HOOKS_PROPDB(r);
542
propdb->lockdb = lockdb;
544
/* always defer actual open, to avoid expense of accessing db
545
* when only live properties are involved
547
propdb->deferred = 1;
549
/* ### what to do about closing the propdb on server failure? */
555
DAV_DECLARE(void) dav_close_propdb(dav_propdb *propdb)
557
if (propdb->db != NULL) {
558
(*propdb->db_hooks->close)(propdb->db);
561
/* Currently, mod_dav's pool usage doesn't allow clearing this pool. */
563
apr_pool_destroy(propdb->p);
568
DAV_DECLARE(dav_get_props_result) dav_get_allprops(dav_propdb *propdb,
569
dav_prop_insert what)
571
const dav_hooks_db *db_hooks = propdb->db_hooks;
572
apr_text_header hdr = { 0 };
573
apr_text_header hdr_ns = { 0 };
574
dav_get_props_result result = { 0 };
575
int found_contenttype = 0;
576
int found_contentlang = 0;
577
dav_prop_insert unused_inserted;
579
/* if not just getting supported live properties,
580
* scan all properties in the dead prop database
582
if (what != DAV_PROP_INSERT_SUPPORTED) {
583
if (propdb->deferred) {
584
/* ### what to do with db open error? */
585
(void) dav_really_open_db(propdb, 1 /*ro*/);
588
/* initialize the result with some start tags... */
589
apr_text_append(propdb->p, &hdr,
590
"<D:propstat>" DEBUG_CR
591
"<D:prop>" DEBUG_CR);
593
/* if there ARE properties, then scan them */
594
if (propdb->db != NULL) {
595
dav_xmlns_info *xi = dav_xmlns_create(propdb->p);
598
/* define (up front) any namespaces the db might need */
599
(void) (*db_hooks->define_namespaces)(propdb->db, xi);
601
/* get the first property name, beginning the scan */
602
(void) (*db_hooks->first_name)(propdb->db, &name);
603
while (name.ns != NULL) {
606
** We also look for <DAV:getcontenttype> and
607
** <DAV:getcontentlanguage>. If they are not stored as dead
608
** properties, then we need to perform a subrequest to get
609
** their values (if any).
611
if (*name.ns == 'D' && strcmp(name.ns, "DAV:") == 0
612
&& *name.name == 'g') {
613
if (strcmp(name.name, "getcontenttype") == 0) {
614
found_contenttype = 1;
616
else if (strcmp(name.name, "getcontentlanguage") == 0) {
617
found_contentlang = 1;
621
if (what == DAV_PROP_INSERT_VALUE) {
625
if ((err = (*db_hooks->output_value)(propdb->db, &name,
628
/* ### anything better to do? */
629
/* ### probably should enter a 500 error */
632
/* assert: found == 1 */
635
/* the value was not requested, so just add an empty
636
tag specifying the property name. */
637
dav_output_prop_name(propdb->p, &name, xi, &hdr);
641
(void) (*db_hooks->next_name)(propdb->db, &name);
644
/* all namespaces have been entered into xi. generate them into
646
dav_xmlns_generate(xi, &hdr_ns);
648
} /* propdb->db != NULL */
650
/* add namespaces for all the liveprop providers */
651
dav_add_all_liveprop_xmlns(propdb->p, &hdr_ns);
654
/* ask the liveprop providers to insert their properties */
655
dav_run_insert_all_liveprops(propdb->r, propdb->resource, what, &hdr);
657
/* insert the standard properties */
658
/* ### should be handling the return errors here */
659
(void)dav_insert_coreprop(propdb,
660
DAV_PROPID_CORE_supportedlock, "supportedlock",
661
what, &hdr, &unused_inserted);
662
(void)dav_insert_coreprop(propdb,
663
DAV_PROPID_CORE_lockdiscovery, "lockdiscovery",
664
what, &hdr, &unused_inserted);
666
/* if we didn't find these, then do the whole subreq thing. */
667
if (!found_contenttype) {
668
/* ### should be handling the return error here */
669
(void)dav_insert_coreprop(propdb,
670
DAV_PROPID_CORE_getcontenttype,
672
what, &hdr, &unused_inserted);
674
if (!found_contentlang) {
675
/* ### should be handling the return error here */
676
(void)dav_insert_coreprop(propdb,
677
DAV_PROPID_CORE_getcontentlanguage,
678
"getcontentlanguage",
679
what, &hdr, &unused_inserted);
682
/* if not just reporting on supported live props,
683
* terminate the result */
684
if (what != DAV_PROP_INSERT_SUPPORTED) {
685
apr_text_append(propdb->p, &hdr,
687
"<D:status>HTTP/1.1 200 OK</D:status>" DEBUG_CR
688
"</D:propstat>" DEBUG_CR);
691
result.propstats = hdr.first;
692
result.xmlns = hdr_ns.first;
696
DAV_DECLARE(dav_get_props_result) dav_get_props(dav_propdb *propdb,
699
const dav_hooks_db *db_hooks = propdb->db_hooks;
700
apr_xml_elem *elem = dav_find_child(doc->root, "prop");
701
apr_text_header hdr_good = { 0 };
702
apr_text_header hdr_bad = { 0 };
703
apr_text_header hdr_ns = { 0 };
705
dav_get_props_result result = { 0 };
706
char *marks_liveprop;
710
/* ### NOTE: we should pass in TWO buffers -- one for keys, one for
713
/* we will ALWAYS provide a "good" result, even if it is EMPTY */
714
apr_text_append(propdb->p, &hdr_good,
715
"<D:propstat>" DEBUG_CR
716
"<D:prop>" DEBUG_CR);
718
/* ### the marks should be in a buffer! */
719
/* allocate zeroed-memory for the marks. These marks indicate which
720
liveprop namespaces we've generated into the output xmlns buffer */
722
/* same for the liveprops */
723
marks_liveprop = apr_pcalloc(propdb->p, dav_get_liveprop_ns_count() + 1);
725
xi = dav_xmlns_create(propdb->p);
727
for (elem = elem->first_child; elem; elem = elem->next) {
728
dav_elem_private *priv;
730
dav_prop_insert inserted;
734
** First try live property providers; if they don't handle
735
** the property, then try looking it up in the propdb.
738
if (elem->priv == NULL) {
739
elem->priv = apr_pcalloc(propdb->p, sizeof(*priv));
743
/* cache the propid; dav_get_props() could be called many times */
744
if (priv->propid == 0)
745
dav_find_liveprop(propdb, elem);
747
if (priv->propid != DAV_PROPID_CORE_UNKNOWN) {
749
/* insert the property. returns 1 if an insertion was done. */
750
if ((err = dav_insert_liveprop(propdb, elem, DAV_PROP_INSERT_VALUE,
751
&hdr_good, &inserted)) != NULL) {
752
/* ### need to propagate the error to the caller... */
753
/* ### skip it for now, as if nothing was inserted */
755
if (inserted == DAV_PROP_INSERT_VALUE) {
759
** Add the liveprop's namespace URIs. Note that provider==NULL
760
** for core properties.
762
if (priv->provider != NULL) {
763
const char * const * scan_ns_uri;
765
for (scan_ns_uri = priv->provider->namespace_uris;
766
*scan_ns_uri != NULL;
770
ns = dav_get_liveprop_ns_index(*scan_ns_uri);
771
if (marks_liveprop[ns])
773
marks_liveprop[ns] = 1;
775
dav_insert_xmlns(propdb->p, "lp", ns, *scan_ns_uri,
780
/* property added. move on to the next property. */
783
else if (inserted == DAV_PROP_INSERT_NOTDEF) {
784
/* nothing to do. fall thru to allow property to be handled
785
as a dead property */
790
/* ### need to change signature to return an error */
791
return dav_new_error(propdb->p, HTTP_INTERNAL_SERVER_ERROR, 0,
792
"INTERNAL DESIGN ERROR: insert_liveprop "
793
"did not insert what was asked for.");
799
/* The property wasn't a live property, so look in the dead property
802
/* make sure propdb is really open */
803
if (propdb->deferred) {
804
/* ### what to do with db open error? */
805
(void) dav_really_open_db(propdb, 1 /*ro*/);
808
if (elem->ns == APR_XML_NS_NONE)
811
name.ns = APR_XML_GET_URI_ITEM(propdb->ns_xlate, elem->ns);
812
name.name = elem->name;
814
/* only bother to look if a database exists */
815
if (propdb->db != NULL) {
818
if ((err = (*db_hooks->output_value)(propdb->db, &name,
821
/* ### what to do? continue doesn't seem right... */
828
/* if we haven't added the db's namespaces, then do so... */
830
(void) (*db_hooks->define_namespaces)(propdb->db, xi);
837
/* not found as a live OR dead property. add a record to the "bad"
840
/* make sure we've started our "bad" propstat */
841
if (hdr_bad.first == NULL) {
842
apr_text_append(propdb->p, &hdr_bad,
843
"<D:propstat>" DEBUG_CR
844
"<D:prop>" DEBUG_CR);
847
/* output this property's name (into the bad propstats) */
848
dav_output_prop_name(propdb->p, &name, xi, &hdr_bad);
851
apr_text_append(propdb->p, &hdr_good,
853
"<D:status>HTTP/1.1 200 OK</D:status>" DEBUG_CR
854
"</D:propstat>" DEBUG_CR);
856
/* default to start with the good */
857
result.propstats = hdr_good.first;
859
/* we may not have any "bad" results */
860
if (hdr_bad.first != NULL) {
861
/* "close" the bad propstat */
862
apr_text_append(propdb->p, &hdr_bad,
864
"<D:status>HTTP/1.1 404 Not Found</D:status>" DEBUG_CR
865
"</D:propstat>" DEBUG_CR);
867
/* if there are no good props, then just return the bad */
869
result.propstats = hdr_bad.first;
872
/* hook the bad propstat to the end of the good one */
873
hdr_good.last->next = hdr_bad.first;
877
/* add in all the various namespaces, and return them */
878
dav_xmlns_generate(xi, &hdr_ns);
879
result.xmlns = hdr_ns.first;
884
DAV_DECLARE(void) dav_get_liveprop_supported(dav_propdb *propdb,
886
const char *propname,
887
apr_text_header *body)
890
const dav_hooks_liveprop *hooks;
892
propid = dav_find_liveprop_provider(propdb, ns_uri, propname, &hooks);
894
if (propid != DAV_PROPID_CORE_UNKNOWN) {
896
/* this is a "core" property that we define */
897
dav_prop_insert unused_inserted;
898
dav_insert_coreprop(propdb, propid, propname,
899
DAV_PROP_INSERT_SUPPORTED, body, &unused_inserted);
902
(*hooks->insert_prop)(propdb->resource, propid,
903
DAV_PROP_INSERT_SUPPORTED, body);
908
DAV_DECLARE_NONSTD(void) dav_prop_validate(dav_prop_ctx *ctx)
910
dav_propdb *propdb = ctx->propdb;
911
apr_xml_elem *prop = ctx->prop;
912
dav_elem_private *priv;
914
priv = ctx->prop->priv = apr_pcalloc(propdb->p, sizeof(*priv));
917
** Check to see if this is a live property, and fill the fields
918
** in the XML elem, as appropriate.
920
** Verify that the property is read/write. If not, then it cannot
921
** be SET or DELETEd.
923
if (priv->propid == 0) {
924
dav_find_liveprop(propdb, prop);
926
/* it's a liveprop if a provider was found */
927
/* ### actually the "core" props should really be liveprops, but
928
### there is no "provider" for those and the r/w props are
929
### treated as dead props anyhow */
930
ctx->is_liveprop = priv->provider != NULL;
933
if (!dav_rw_liveprop(propdb, priv)) {
934
ctx->err = dav_new_error(propdb->p, HTTP_CONFLICT,
935
DAV_ERR_PROP_READONLY,
936
"Property is read-only.");
940
if (ctx->is_liveprop) {
941
int defer_to_dead = 0;
943
ctx->err = (*priv->provider->patch_validate)(propdb->resource,
944
prop, ctx->operation,
947
if (ctx->err != NULL || !defer_to_dead)
950
/* clear is_liveprop -- act as a dead prop now */
951
ctx->is_liveprop = 0;
955
** The property is supposed to be stored into the dead-property
956
** database. Make sure the thing is truly open (and writable).
959
&& (ctx->err = dav_really_open_db(propdb, 0 /* ro */)) != NULL) {
964
** There should be an open, writable database in here!
966
** Note: the database would be NULL if it was opened readonly and it
969
if (propdb->db == NULL) {
970
ctx->err = dav_new_error(propdb->p, HTTP_INTERNAL_SERVER_ERROR,
971
DAV_ERR_PROP_NO_DATABASE,
972
"Attempted to set/remove a property "
973
"without a valid, open, read/write "
974
"property database.");
978
if (ctx->operation == DAV_PROP_OP_SET) {
980
** Prep the element => propdb namespace index mapping, inserting
981
** namespace URIs into the propdb that don't exist.
983
(void) (*propdb->db_hooks->map_namespaces)(propdb->db,
987
else if (ctx->operation == DAV_PROP_OP_DELETE) {
989
** There are no checks to perform here. If a property exists, then
990
** we will delete it. If it does not exist, then it does not matter
993
** Note that if a property does not exist, that does not rule out
994
** that a SET will occur during this PROPPATCH (thusly creating it).
999
DAV_DECLARE_NONSTD(void) dav_prop_exec(dav_prop_ctx *ctx)
1001
dav_propdb *propdb = ctx->propdb;
1002
dav_error *err = NULL;
1003
dav_elem_private *priv = ctx->prop->priv;
1005
ctx->rollback = apr_pcalloc(propdb->p, sizeof(*ctx->rollback));
1007
if (ctx->is_liveprop) {
1008
err = (*priv->provider->patch_exec)(propdb->resource,
1009
ctx->prop, ctx->operation,
1011
&ctx->rollback->liveprop);
1016
if (ctx->prop->ns == APR_XML_NS_NONE)
1019
name.ns = APR_XML_GET_URI_ITEM(propdb->ns_xlate, ctx->prop->ns);
1020
name.name = ctx->prop->name;
1022
/* save the old value so that we can do a rollback. */
1023
if ((err = (*propdb->db_hooks
1024
->get_rollback)(propdb->db, &name,
1025
&ctx->rollback->deadprop)) != NULL)
1028
if (ctx->operation == DAV_PROP_OP_SET) {
1030
/* Note: propdb->mapping was set in dav_prop_validate() */
1031
err = (*propdb->db_hooks->store)(propdb->db, &name, ctx->prop,
1035
** If an error occurred, then assume that we didn't change the
1036
** value. Remove the rollback item so that we don't try to set
1037
** its value during the rollback.
1039
/* ### euh... where is the removal? */
1041
else if (ctx->operation == DAV_PROP_OP_DELETE) {
1044
** Delete the property. Ignore errors -- the property is there, or
1045
** we are deleting it for a second time.
1047
/* ### but what about other errors? */
1048
(void) (*propdb->db_hooks->remove)(propdb->db, &name);
1053
/* push a more specific error here */
1056
** Use HTTP_INTERNAL_SERVER_ERROR because we shouldn't have seen
1057
** any errors at this point.
1059
ctx->err = dav_push_error(propdb->p, HTTP_INTERNAL_SERVER_ERROR,
1061
"Could not execute PROPPATCH.", err);
1065
DAV_DECLARE_NONSTD(void) dav_prop_commit(dav_prop_ctx *ctx)
1067
dav_elem_private *priv = ctx->prop->priv;
1070
** Note that a commit implies ctx->err is NULL. The caller should assume
1071
** a status of HTTP_OK for this case.
1074
if (ctx->is_liveprop) {
1075
(*priv->provider->patch_commit)(ctx->propdb->resource,
1078
ctx->rollback->liveprop);
1082
DAV_DECLARE_NONSTD(void) dav_prop_rollback(dav_prop_ctx *ctx)
1084
dav_error *err = NULL;
1085
dav_elem_private *priv = ctx->prop->priv;
1087
/* do nothing if there is no rollback information. */
1088
if (ctx->rollback == NULL)
1092
** ### if we have an error, and a rollback occurs, then the namespace
1093
** ### mods should not happen at all. Basically, the namespace management
1094
** ### is simply a bitch.
1097
if (ctx->is_liveprop) {
1098
err = (*priv->provider->patch_rollback)(ctx->propdb->resource,
1101
ctx->rollback->liveprop);
1104
err = (*ctx->propdb->db_hooks
1105
->apply_rollback)(ctx->propdb->db, ctx->rollback->deadprop);
1109
if (ctx->err == NULL)
1112
dav_error *scan = err;
1114
/* hook previous errors at the end of the rollback error */
1115
while (scan->prev != NULL)
1117
scan->prev = ctx->err;