std_liveprop.c revision 6f15570e3adc0faf87bf55f70857028276fc9e32
6320N/A/* ====================================================================
6320N/A * The Apache Software License, Version 1.1
6320N/A *
6320N/A * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
6320N/A * reserved.
6320N/A *
6320N/A * Redistribution and use in source and binary forms, with or without
6320N/A * modification, are permitted provided that the following conditions
6320N/A * are met:
6320N/A *
6320N/A * 1. Redistributions of source code must retain the above copyright
6320N/A * notice, this list of conditions and the following disclaimer.
6320N/A *
6320N/A * 2. Redistributions in binary form must reproduce the above copyright
6320N/A * notice, this list of conditions and the following disclaimer in
6320N/A * the documentation and/or other materials provided with the
6320N/A * distribution.
6320N/A *
6320N/A * 3. The end-user documentation included with the redistribution,
6320N/A * if any, must include the following acknowledgment:
6320N/A * "This product includes software developed by the
6320N/A * Apache Software Foundation (http://www.apache.org/)."
6320N/A * Alternately, this acknowledgment may appear in the software itself,
6320N/A * if and wherever such third-party acknowledgments normally appear.
6320N/A *
6320N/A * 4. The names "Apache" and "Apache Software Foundation" must
6320N/A * not be used to endorse or promote products derived from this
6320N/A * software without prior written permission. For written
6320N/A * permission, please contact apache@apache.org.
6320N/A *
6320N/A * 5. Products derived from this software may not be called "Apache",
6320N/A * nor may "Apache" appear in their name, without prior written
6320N/A * permission of the Apache Software Foundation.
6320N/A *
6320N/A * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
6320N/A * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
6320N/A * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
6320N/A * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
6320N/A * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
6320N/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
6320N/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
6320N/A * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
6320N/A * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
6320N/A * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
6320N/A * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
6320N/A * SUCH DAMAGE.
6320N/A * ====================================================================
6320N/A *
6320N/A * This software consists of voluntary contributions made by many
6320N/A * individuals on behalf of the Apache Software Foundation. For more
6320N/A * information on the Apache Software Foundation, please see
6320N/A * <http://www.apache.org/>.
6320N/A */
6320N/A
6320N/A#include "httpd.h"
6320N/A#include "util_xml.h"
6320N/A#include "apr_strings.h"
6320N/A
6320N/A#include "mod_dav.h"
6320N/A
6320N/A/* forward-declare */
6320N/Astatic const dav_hooks_liveprop dav_core_hooks_liveprop;
6320N/A
6320N/A/*
6320N/A** The namespace URIs that we use. There will only ever be "DAV:".
6320N/A*/
6320N/Astatic const char * const dav_core_namespace_uris[] =
6320N/A{
6320N/A "DAV:",
6320N/A NULL /* sentinel */
6320N/A};
6320N/A
6320N/A/*
6320N/A** Define each of the core properties that this provider will handle.
6320N/A** Note that all of them are in the DAV: namespace, which has a
6320N/A** provider-local index of 0.
6320N/A*/
6320N/Astatic const dav_liveprop_spec dav_core_props[] =
6320N/A{
6320N/A { 0, "comment", DAV_PROPID_comment, 1 },
6320N/A { 0, "creator-displayname", DAV_PROPID_creator_displayname, 1 },
6320N/A { 0, "displayname", DAV_PROPID_displayname, 1 },
6320N/A { 0, "resourcetype", DAV_PROPID_resourcetype, 0 },
6320N/A { 0, "source", DAV_PROPID_source, 1 },
6320N/A
6320N/A { 0 } /* sentinel */
6320N/A};
6320N/A
6320N/Astatic const dav_liveprop_group dav_core_liveprop_group =
6320N/A{
6320N/A dav_core_props,
6320N/A dav_core_namespace_uris,
6320N/A &dav_core_hooks_liveprop
6320N/A};
6320N/A
6320N/Astatic dav_prop_insert dav_core_insert_prop(const dav_resource *resource,
6320N/A int propid, dav_prop_insert what,
6320N/A apr_text_header *phdr)
6320N/A{
6320N/A const char *value;
6320N/A const char *s;
6320N/A apr_pool_t *p = resource->pool;
6320N/A const dav_liveprop_spec *info;
6320N/A int global_ns;
6320N/A
6320N/A switch (propid)
6320N/A {
6320N/A case DAV_PROPID_resourcetype:
6320N/A switch (resource->type) {
6320N/A case DAV_RESOURCE_TYPE_VERSION:
6320N/A if (resource->baselined) {
6320N/A value = "<D:baseline/>";
6320N/A break;
6320N/A }
6320N/A /* fall through */
6320N/A case DAV_RESOURCE_TYPE_REGULAR:
6320N/A case DAV_RESOURCE_TYPE_WORKING:
6320N/A if (resource->collection) {
6320N/A value = "<D:collection/>";
6320N/A }
6320N/A else {
6320N/A /* ### should we denote lock-null resources? */
6320N/A
6320N/A value = ""; /* becomes: <D:resourcetype/> */
6320N/A }
6320N/A break;
6320N/A case DAV_RESOURCE_TYPE_HISTORY:
6320N/A value = "<D:version-history/>";
6320N/A break;
6320N/A case DAV_RESOURCE_TYPE_WORKSPACE:
6320N/A value = "<D:collection/>";
6320N/A break;
6320N/A case DAV_RESOURCE_TYPE_ACTIVITY:
6320N/A value = "<D:activity/>";
6320N/A break;
6320N/A
6320N/A default:
6320N/A /* ### bad juju */
6320N/A return DAV_PROP_INSERT_NOTDEF;
6320N/A }
6320N/A break;
6320N/A
6320N/A case DAV_PROPID_comment:
6320N/A case DAV_PROPID_creator_displayname:
6320N/A case DAV_PROPID_displayname:
6320N/A case DAV_PROPID_source:
6320N/A default:
6320N/A /*
6320N/A ** This property is known, but not defined as a liveprop. However,
6320N/A ** it may be a dead property.
6320N/A */
6320N/A return DAV_PROP_INSERT_NOTDEF;
6320N/A }
6320N/A
6320N/A /* assert: value != NULL */
6320N/A
6320N/A /* get the information and global NS index for the property */
6320N/A global_ns = dav_get_liveprop_info(propid, &dav_core_liveprop_group, &info);
6320N/A
6320N/A /* assert: info != NULL && info->name != NULL */
6320N/A
6320N/A if (what == DAV_PROP_INSERT_SUPPORTED) {
6320N/A s = apr_psprintf(p,
6320N/A "<D:supported-live-property D:name=\"%s\" "
6320N/A "D:namespace=\"%s\"/>" DEBUG_CR,
6320N/A info->name, dav_core_namespace_uris[info->ns]);
6320N/A }
6320N/A else if (what == DAV_PROP_INSERT_VALUE && *value != '\0') {
6320N/A s = apr_psprintf(p, "<lp%d:%s>%s</lp%d:%s>" DEBUG_CR,
6320N/A global_ns, info->name, value, global_ns, info->name);
6320N/A }
6320N/A else {
6320N/A s = apr_psprintf(p, "<lp%d:%s/>" DEBUG_CR, global_ns, info->name);
6320N/A }
6320N/A apr_text_append(p, phdr, s);
6320N/A
6320N/A /* we inserted what was asked for */
6320N/A return what;
6320N/A}
6320N/A
6320N/Astatic int dav_core_is_writable(const dav_resource *resource, int propid)
6320N/A{
6320N/A const dav_liveprop_spec *info;
6320N/A
6320N/A (void) dav_get_liveprop_info(propid, &dav_core_liveprop_group, &info);
6320N/A return info->is_writable;
6320N/A}
6320N/A
6320N/Astatic dav_error * dav_core_patch_validate(const dav_resource *resource,
6320N/A const apr_xml_elem *elem,
6320N/A int operation, void **context,
6320N/A int *defer_to_dead)
6320N/A{
6320N/A /* all of our writable props go in the dead prop database */
6320N/A *defer_to_dead = 1;
6320N/A
6320N/A return NULL;
6320N/A}
6320N/A
6320N/Astatic const dav_hooks_liveprop dav_core_hooks_liveprop = {
6320N/A dav_core_insert_prop,
6320N/A dav_core_is_writable,
6320N/A dav_core_namespace_uris,
6320N/A dav_core_patch_validate,
6320N/A NULL, /* patch_exec */
6320N/A NULL, /* patch_commit */
6320N/A NULL, /* patch_rollback */
6320N/A};
6320N/A
6320N/Aint dav_core_find_liveprop(const dav_resource *resource,
6320N/A const char *ns_uri, const char *name,
6320N/A const dav_hooks_liveprop **hooks)
6320N/A{
6320N/A return dav_do_find_liveprop(ns_uri, name, &dav_core_liveprop_group, hooks);
6320N/A}
6320N/A
6320N/Avoid dav_core_insert_all_liveprops(request_rec *r,
6320N/A const dav_resource *resource,
6320N/A dav_prop_insert what, apr_text_header *phdr)
6320N/A{
6320N/A (void) dav_core_insert_prop(resource, DAV_PROPID_resourcetype,
6320N/A what, phdr);
6320N/A}
6320N/A
6320N/Avoid dav_core_register_uris(apr_pool_t *p)
6320N/A{
6320N/A /* register the namespace URIs */
6320N/A dav_register_liveprop_group(p, &dav_core_liveprop_group);
6320N/A}
6320N/A