liveprop.c revision 75ba48124689705b1eee2b4fe10fe24a2d2467cd
6ae232055d4d8a97267517c5e50074c2c819941and/* ====================================================================
6ae232055d4d8a97267517c5e50074c2c819941and * The Apache Software License, Version 1.1
6ae232055d4d8a97267517c5e50074c2c819941and *
6ae232055d4d8a97267517c5e50074c2c819941and * Copyright (c) 2000 The Apache Software Foundation. All rights
6ae232055d4d8a97267517c5e50074c2c819941and * reserved.
6ae232055d4d8a97267517c5e50074c2c819941and *
6ae232055d4d8a97267517c5e50074c2c819941and * Redistribution and use in source and binary forms, with or without
6ae232055d4d8a97267517c5e50074c2c819941and * modification, are permitted provided that the following conditions
6ae232055d4d8a97267517c5e50074c2c819941and * are met:
6ae232055d4d8a97267517c5e50074c2c819941and *
6ae232055d4d8a97267517c5e50074c2c819941and * 1. Redistributions of source code must retain the above copyright
6ae232055d4d8a97267517c5e50074c2c819941and * notice, this list of conditions and the following disclaimer.
6ae232055d4d8a97267517c5e50074c2c819941and *
6ae232055d4d8a97267517c5e50074c2c819941and * 2. Redistributions in binary form must reproduce the above copyright
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * notice, this list of conditions and the following disclaimer in
6ae232055d4d8a97267517c5e50074c2c819941and * the documentation and/or other materials provided with the
6ae232055d4d8a97267517c5e50074c2c819941and * distribution.
6ae232055d4d8a97267517c5e50074c2c819941and *
b43f840409794ed298e8634f6284741f193b6c4ftakashi * 3. The end-user documentation included with the redistribution,
6ae232055d4d8a97267517c5e50074c2c819941and * if any, must include the following acknowledgment:
b43f840409794ed298e8634f6284741f193b6c4ftakashi * "This product includes software developed by the
c04f76acce77126cf88b09350e56ea8c6b4a064enilgun * Apache Software Foundation (http://www.apache.org/)."
6ae232055d4d8a97267517c5e50074c2c819941and * Alternately, this acknowledgment may appear in the software itself,
91f378b5a10f2d83820902ed10ba7967a3920c18nilgun * if and wherever such third-party acknowledgments normally appear.
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung *
6ae232055d4d8a97267517c5e50074c2c819941and * 4. The names "Apache" and "Apache Software Foundation" must
b43f840409794ed298e8634f6284741f193b6c4ftakashi * not be used to endorse or promote products derived from this
b43f840409794ed298e8634f6284741f193b6c4ftakashi * software without prior written permission. For written
b43f840409794ed298e8634f6284741f193b6c4ftakashi * permission, please contact apache@apache.org.
b43f840409794ed298e8634f6284741f193b6c4ftakashi *
6ae232055d4d8a97267517c5e50074c2c819941and * 5. Products derived from this software may not be called "Apache",
6ae232055d4d8a97267517c5e50074c2c819941and * nor may "Apache" appear in their name, without prior written
6ae232055d4d8a97267517c5e50074c2c819941and * permission of the Apache Software Foundation.
6ae232055d4d8a97267517c5e50074c2c819941and *
6ae232055d4d8a97267517c5e50074c2c819941and * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
6ae232055d4d8a97267517c5e50074c2c819941and * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
6ae232055d4d8a97267517c5e50074c2c819941and * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
6ae232055d4d8a97267517c5e50074c2c819941and * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
6ae232055d4d8a97267517c5e50074c2c819941and * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
6ae232055d4d8a97267517c5e50074c2c819941and * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
6ae232055d4d8a97267517c5e50074c2c819941and * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
6ae232055d4d8a97267517c5e50074c2c819941and * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
6ae232055d4d8a97267517c5e50074c2c819941and * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
6ae232055d4d8a97267517c5e50074c2c819941and * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
6ae232055d4d8a97267517c5e50074c2c819941and * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
6ae232055d4d8a97267517c5e50074c2c819941and * SUCH DAMAGE.
6ae232055d4d8a97267517c5e50074c2c819941and * ====================================================================
6ae232055d4d8a97267517c5e50074c2c819941and *
6ae232055d4d8a97267517c5e50074c2c819941and * This software consists of voluntary contributions made by many
6ae232055d4d8a97267517c5e50074c2c819941and * individuals on behalf of the Apache Software Foundation. For more
6ae232055d4d8a97267517c5e50074c2c819941and * information on the Apache Software Foundation, please see
6ae232055d4d8a97267517c5e50074c2c819941and * <http://www.apache.org/>.
6ae232055d4d8a97267517c5e50074c2c819941and */
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and#include "apr_pools.h"
6ae232055d4d8a97267517c5e50074c2c819941and#include "apr_hash.h"
6ae232055d4d8a97267517c5e50074c2c819941and#include "apr_errno.h"
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and#include "ap_hooks.h" /* ### for ap_global_hook_pool */
6ae232055d4d8a97267517c5e50074c2c819941and#include "util_xml.h" /* for ap_text_header */
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and#include "mod_dav.h"
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941andstatic ap_hash_t *dav_liveprop_uris = NULL;
6ae232055d4d8a97267517c5e50074c2c819941andstatic int dav_liveprop_count = 0;
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941andstatic ap_status_t dav_cleanup_liveprops(void *ctx)
6ae232055d4d8a97267517c5e50074c2c819941and{
6ae232055d4d8a97267517c5e50074c2c819941and dav_liveprop_uris = NULL;
6ae232055d4d8a97267517c5e50074c2c819941and dav_liveprop_count = 0;
6ae232055d4d8a97267517c5e50074c2c819941and return APR_SUCCESS;
6ae232055d4d8a97267517c5e50074c2c819941and}
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941andvoid dav_register_liveprop_namespace(ap_pool_t *p, const char *uri)
6ae232055d4d8a97267517c5e50074c2c819941and{
6ae232055d4d8a97267517c5e50074c2c819941and int value;
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and /* ### ignore the pool; it is NULL right now */
6ae232055d4d8a97267517c5e50074c2c819941and p = ap_global_hook_pool;
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and if (dav_liveprop_uris == NULL) {
6ae232055d4d8a97267517c5e50074c2c819941and dav_liveprop_uris = ap_make_hash(p);
6ae232055d4d8a97267517c5e50074c2c819941and ap_register_cleanup(p, NULL, dav_cleanup_liveprops, ap_null_cleanup);
6ae232055d4d8a97267517c5e50074c2c819941and }
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and value = (int)ap_hash_get(dav_liveprop_uris, uri, 0);
6ae232055d4d8a97267517c5e50074c2c819941and if (value != 0) {
6ae232055d4d8a97267517c5e50074c2c819941and /* already registered */
6ae232055d4d8a97267517c5e50074c2c819941and return;
6ae232055d4d8a97267517c5e50074c2c819941and }
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and /* start at 1, and count up */
6ae232055d4d8a97267517c5e50074c2c819941and ap_hash_set(dav_liveprop_uris, uri, 0, (void *)++dav_liveprop_count);
6ae232055d4d8a97267517c5e50074c2c819941and}
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941andint dav_get_liveprop_ns_index(const char *uri)
6ae232055d4d8a97267517c5e50074c2c819941and{
6ae232055d4d8a97267517c5e50074c2c819941and return (int)ap_hash_get(dav_liveprop_uris, uri, 0);
6ae232055d4d8a97267517c5e50074c2c819941and}
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941andint dav_get_liveprop_ns_count(void)
6ae232055d4d8a97267517c5e50074c2c819941and{
6ae232055d4d8a97267517c5e50074c2c819941and return dav_liveprop_count;
6ae232055d4d8a97267517c5e50074c2c819941and}
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941andvoid dav_add_all_liveprop_xmlns(ap_pool_t *p, ap_text_header *phdr)
6ae232055d4d8a97267517c5e50074c2c819941and{
6ae232055d4d8a97267517c5e50074c2c819941and ap_hash_index_t *idx = ap_hash_first(dav_liveprop_uris);
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and for ( ; idx != NULL; idx = ap_hash_next(idx) ) {
6ae232055d4d8a97267517c5e50074c2c819941and const void *key;
6ae232055d4d8a97267517c5e50074c2c819941and void *val;
6ae232055d4d8a97267517c5e50074c2c819941and const char *s;
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and ap_hash_this(idx, &key, NULL, &val);
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and s = ap_psprintf(p, " xmlns:lp%d=\"%s\"", (int)val, key);
6ae232055d4d8a97267517c5e50074c2c819941and ap_text_append(p, phdr, s);
6ae232055d4d8a97267517c5e50074c2c819941and }
6ae232055d4d8a97267517c5e50074c2c819941and}
6ae232055d4d8a97267517c5e50074c2c819941and