std_liveprop.c revision 71da3cca78eea6010f89b139ecadb79e6d213c4f
b66914021bd429f41311d2909a7e9289866da7fdnd/* Copyright 2000-2004 Apache Software Foundation
b51bf223f42d43ca6b1b33c95124edcfa5a871a4nd *
9963f91528694fb21e93da8584c31f226c6de97akess * Licensed under the Apache License, Version 2.0 (the "License");
b66914021bd429f41311d2909a7e9289866da7fdnd * you may not use this file except in compliance with the License.
b66914021bd429f41311d2909a7e9289866da7fdnd * You may obtain a copy of the License at
031b91a62d25106ae69d4693475c79618dd5e884fielding *
031b91a62d25106ae69d4693475c79618dd5e884fielding * http://www.apache.org/licenses/LICENSE-2.0
031b91a62d25106ae69d4693475c79618dd5e884fielding *
031b91a62d25106ae69d4693475c79618dd5e884fielding * Unless required by applicable law or agreed to in writing, software
031b91a62d25106ae69d4693475c79618dd5e884fielding * distributed under the License is distributed on an "AS IS" BASIS,
031b91a62d25106ae69d4693475c79618dd5e884fielding * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
b66914021bd429f41311d2909a7e9289866da7fdnd * See the License for the specific language governing permissions and
b66914021bd429f41311d2909a7e9289866da7fdnd * limitations under the License.
b66914021bd429f41311d2909a7e9289866da7fdnd */
b66914021bd429f41311d2909a7e9289866da7fdnd
b66914021bd429f41311d2909a7e9289866da7fdnd#include "httpd.h"
b66914021bd429f41311d2909a7e9289866da7fdnd#include "util_xml.h"
b66914021bd429f41311d2909a7e9289866da7fdnd#include "apr_strings.h"
b66914021bd429f41311d2909a7e9289866da7fdnd
b66914021bd429f41311d2909a7e9289866da7fdnd#include "mod_dav.h"
b66914021bd429f41311d2909a7e9289866da7fdnd
eed2a23d9b5986937f1e2b1c120be97744508a72nd/* forward-declare */
eed2a23d9b5986937f1e2b1c120be97744508a72ndstatic const dav_hooks_liveprop dav_core_hooks_liveprop;
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd/*
eed2a23d9b5986937f1e2b1c120be97744508a72nd** The namespace URIs that we use. There will only ever be "DAV:".
eed2a23d9b5986937f1e2b1c120be97744508a72nd*/
eed2a23d9b5986937f1e2b1c120be97744508a72ndstatic const char * const dav_core_namespace_uris[] =
eed2a23d9b5986937f1e2b1c120be97744508a72nd{
eed2a23d9b5986937f1e2b1c120be97744508a72nd "DAV:",
eed2a23d9b5986937f1e2b1c120be97744508a72nd NULL /* sentinel */
eed2a23d9b5986937f1e2b1c120be97744508a72nd};
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd/*
eed2a23d9b5986937f1e2b1c120be97744508a72nd** Define each of the core properties that this provider will handle.
eed2a23d9b5986937f1e2b1c120be97744508a72nd** Note that all of them are in the DAV: namespace, which has a
eed2a23d9b5986937f1e2b1c120be97744508a72nd** provider-local index of 0.
eed2a23d9b5986937f1e2b1c120be97744508a72nd*/
eed2a23d9b5986937f1e2b1c120be97744508a72ndstatic const dav_liveprop_spec dav_core_props[] =
eed2a23d9b5986937f1e2b1c120be97744508a72nd{
eed2a23d9b5986937f1e2b1c120be97744508a72nd { 0, "comment", DAV_PROPID_comment, 1 },
eed2a23d9b5986937f1e2b1c120be97744508a72nd { 0, "creator-displayname", DAV_PROPID_creator_displayname, 1 },
eed2a23d9b5986937f1e2b1c120be97744508a72nd { 0, "displayname", DAV_PROPID_displayname, 1 },
eed2a23d9b5986937f1e2b1c120be97744508a72nd { 0, "resourcetype", DAV_PROPID_resourcetype, 0 },
eed2a23d9b5986937f1e2b1c120be97744508a72nd { 0, "source", DAV_PROPID_source, 1 },
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd { 0 } /* sentinel */
eed2a23d9b5986937f1e2b1c120be97744508a72nd};
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72ndstatic const dav_liveprop_group dav_core_liveprop_group =
eed2a23d9b5986937f1e2b1c120be97744508a72nd{
eed2a23d9b5986937f1e2b1c120be97744508a72nd dav_core_props,
eed2a23d9b5986937f1e2b1c120be97744508a72nd dav_core_namespace_uris,
eed2a23d9b5986937f1e2b1c120be97744508a72nd &dav_core_hooks_liveprop
eed2a23d9b5986937f1e2b1c120be97744508a72nd};
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72ndstatic dav_prop_insert dav_core_insert_prop(const dav_resource *resource,
eed2a23d9b5986937f1e2b1c120be97744508a72nd int propid, dav_prop_insert what,
eed2a23d9b5986937f1e2b1c120be97744508a72nd apr_text_header *phdr)
eed2a23d9b5986937f1e2b1c120be97744508a72nd{
eed2a23d9b5986937f1e2b1c120be97744508a72nd const char *value;
eed2a23d9b5986937f1e2b1c120be97744508a72nd const char *s;
eed2a23d9b5986937f1e2b1c120be97744508a72nd apr_pool_t *p = resource->pool;
eed2a23d9b5986937f1e2b1c120be97744508a72nd const dav_liveprop_spec *info;
eed2a23d9b5986937f1e2b1c120be97744508a72nd int global_ns;
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd switch (propid)
f5e4573f2a3ca4b7d7d10bfb50950fa7eff27efbnilgun {
f5e4573f2a3ca4b7d7d10bfb50950fa7eff27efbnilgun case DAV_PROPID_resourcetype:
f5e4573f2a3ca4b7d7d10bfb50950fa7eff27efbnilgun switch (resource->type) {
f5e4573f2a3ca4b7d7d10bfb50950fa7eff27efbnilgun case DAV_RESOURCE_TYPE_VERSION:
eed2a23d9b5986937f1e2b1c120be97744508a72nd if (resource->baselined) {
eed2a23d9b5986937f1e2b1c120be97744508a72nd value = "<D:baseline/>";
eed2a23d9b5986937f1e2b1c120be97744508a72nd break;
eed2a23d9b5986937f1e2b1c120be97744508a72nd }
eed2a23d9b5986937f1e2b1c120be97744508a72nd /* fall through */
bcf004854091600aa279525d6772e1827114d39dnd case DAV_RESOURCE_TYPE_REGULAR:
eed2a23d9b5986937f1e2b1c120be97744508a72nd case DAV_RESOURCE_TYPE_WORKING:
eed2a23d9b5986937f1e2b1c120be97744508a72nd if (resource->collection) {
eed2a23d9b5986937f1e2b1c120be97744508a72nd value = "<D:collection/>";
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd }
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd else {
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd /* ### should we denote lock-null resources? */
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd value = ""; /* becomes: <D:resourcetype/> */
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd }
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd break;
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd case DAV_RESOURCE_TYPE_HISTORY:
eed2a23d9b5986937f1e2b1c120be97744508a72nd value = "<D:version-history/>";
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd break;
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd case DAV_RESOURCE_TYPE_WORKSPACE:
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd value = "<D:collection/>";
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd break;
eed2a23d9b5986937f1e2b1c120be97744508a72nd case DAV_RESOURCE_TYPE_ACTIVITY:
eed2a23d9b5986937f1e2b1c120be97744508a72nd value = "<D:activity/>";
eed2a23d9b5986937f1e2b1c120be97744508a72nd break;
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd default:
eed2a23d9b5986937f1e2b1c120be97744508a72nd /* ### bad juju */
eed2a23d9b5986937f1e2b1c120be97744508a72nd return DAV_PROP_INSERT_NOTDEF;
eed2a23d9b5986937f1e2b1c120be97744508a72nd }
eed2a23d9b5986937f1e2b1c120be97744508a72nd break;
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd case DAV_PROPID_comment:
eed2a23d9b5986937f1e2b1c120be97744508a72nd case DAV_PROPID_creator_displayname:
eed2a23d9b5986937f1e2b1c120be97744508a72nd case DAV_PROPID_displayname:
eed2a23d9b5986937f1e2b1c120be97744508a72nd case DAV_PROPID_source:
9963f91528694fb21e93da8584c31f226c6de97akess default:
bcf004854091600aa279525d6772e1827114d39dnd /*
9963f91528694fb21e93da8584c31f226c6de97akess ** This property is known, but not defined as a liveprop. However,
eed2a23d9b5986937f1e2b1c120be97744508a72nd ** it may be a dead property.
eed2a23d9b5986937f1e2b1c120be97744508a72nd */
b51bf223f42d43ca6b1b33c95124edcfa5a871a4nd return DAV_PROP_INSERT_NOTDEF;
b51bf223f42d43ca6b1b33c95124edcfa5a871a4nd }
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd /* assert: value != NULL */
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd /* get the information and global NS index for the property */
8daf1ddf6285e4ded262f7a7a8e2e983a84a3cbdhumbedooh global_ns = dav_get_liveprop_info(propid, &dav_core_liveprop_group, &info);
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd /* assert: info != NULL && info->name != NULL */
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd if (what == DAV_PROP_INSERT_SUPPORTED) {
eed2a23d9b5986937f1e2b1c120be97744508a72nd s = apr_psprintf(p,
b51bf223f42d43ca6b1b33c95124edcfa5a871a4nd "<D:supported-live-property D:name=\"%s\" "
eed2a23d9b5986937f1e2b1c120be97744508a72nd "D:namespace=\"%s\"/>" DEBUG_CR,
eed2a23d9b5986937f1e2b1c120be97744508a72nd info->name, dav_core_namespace_uris[info->ns]);
eed2a23d9b5986937f1e2b1c120be97744508a72nd }
eed2a23d9b5986937f1e2b1c120be97744508a72nd else if (what == DAV_PROP_INSERT_VALUE && *value != '\0') {
eed2a23d9b5986937f1e2b1c120be97744508a72nd s = apr_psprintf(p, "<lp%d:%s>%s</lp%d:%s>" DEBUG_CR,
eed2a23d9b5986937f1e2b1c120be97744508a72nd global_ns, info->name, value, global_ns, info->name);
eed2a23d9b5986937f1e2b1c120be97744508a72nd }
eed2a23d9b5986937f1e2b1c120be97744508a72nd else {
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd s = apr_psprintf(p, "<lp%d:%s/>" DEBUG_CR, global_ns, info->name);
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd }
eed2a23d9b5986937f1e2b1c120be97744508a72nd apr_text_append(p, phdr, s);
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd /* we inserted what was asked for */
eed2a23d9b5986937f1e2b1c120be97744508a72nd return what;
eed2a23d9b5986937f1e2b1c120be97744508a72nd}
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72ndstatic int dav_core_is_writable(const dav_resource *resource, int propid)
b3027c7641b1104ee50404cca6868e5101a7ca45nd{
b3ab5b870526aebe7da94a01350677b5087fc26and const dav_liveprop_spec *info;
b3ab5b870526aebe7da94a01350677b5087fc26and
b3027c7641b1104ee50404cca6868e5101a7ca45nd (void) dav_get_liveprop_info(propid, &dav_core_liveprop_group, &info);
f1110149b5b6c28ecc39d1958d98ad9cfa8e41f3nd return info->is_writable;
f1110149b5b6c28ecc39d1958d98ad9cfa8e41f3nd}
f1110149b5b6c28ecc39d1958d98ad9cfa8e41f3nd
f1110149b5b6c28ecc39d1958d98ad9cfa8e41f3ndstatic dav_error * dav_core_patch_validate(const dav_resource *resource,
f1110149b5b6c28ecc39d1958d98ad9cfa8e41f3nd const apr_xml_elem *elem,
f1110149b5b6c28ecc39d1958d98ad9cfa8e41f3nd int operation, void **context,
f1110149b5b6c28ecc39d1958d98ad9cfa8e41f3nd int *defer_to_dead)
f1110149b5b6c28ecc39d1958d98ad9cfa8e41f3nd{
f1110149b5b6c28ecc39d1958d98ad9cfa8e41f3nd /* all of our writable props go in the dead prop database */
eed2a23d9b5986937f1e2b1c120be97744508a72nd *defer_to_dead = 1;
eed2a23d9b5986937f1e2b1c120be97744508a72nd
return NULL;
}
static const dav_hooks_liveprop dav_core_hooks_liveprop = {
dav_core_insert_prop,
dav_core_is_writable,
dav_core_namespace_uris,
dav_core_patch_validate,
NULL, /* patch_exec */
NULL, /* patch_commit */
NULL, /* patch_rollback */
};
int dav_core_find_liveprop(const dav_resource *resource,
const char *ns_uri, const char *name,
const dav_hooks_liveprop **hooks)
{
return dav_do_find_liveprop(ns_uri, name, &dav_core_liveprop_group, hooks);
}
void dav_core_insert_all_liveprops(request_rec *r,
const dav_resource *resource,
dav_prop_insert what, apr_text_header *phdr)
{
(void) dav_core_insert_prop(resource, DAV_PROPID_resourcetype,
what, phdr);
}
void dav_core_register_uris(apr_pool_t *p)
{
/* register the namespace URIs */
dav_register_liveprop_group(p, &dav_core_liveprop_group);
}