|
Packit |
90a5c9 |
/* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
Packit |
90a5c9 |
* contributor license agreements. See the NOTICE file distributed with
|
|
Packit |
90a5c9 |
* this work for additional information regarding copyright ownership.
|
|
Packit |
90a5c9 |
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
Packit |
90a5c9 |
* (the "License"); you may not use this file except in compliance with
|
|
Packit |
90a5c9 |
* the License. You may obtain a copy of the License at
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Unless required by applicable law or agreed to in writing, software
|
|
Packit |
90a5c9 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit |
90a5c9 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit |
90a5c9 |
* See the License for the specific language governing permissions and
|
|
Packit |
90a5c9 |
* limitations under the License.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include "apr_pools.h"
|
|
Packit |
90a5c9 |
#include "apr_hash.h"
|
|
Packit |
90a5c9 |
#include "apr_errno.h"
|
|
Packit |
90a5c9 |
#include "apr_strings.h"
|
|
Packit |
90a5c9 |
#include "util_xml.h" /* for apr_text_header */
|
|
Packit |
90a5c9 |
#include "mod_dav.h"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_hash_t *dav_liveprop_uris = NULL;
|
|
Packit |
90a5c9 |
static long dav_liveprop_count = 0;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_status_t dav_cleanup_liveprops(void *ctx)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
dav_liveprop_uris = NULL;
|
|
Packit |
90a5c9 |
dav_liveprop_count = 0;
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void dav_register_liveprop_namespace(apr_pool_t *p, const char *uri)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
long value;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (dav_liveprop_uris == NULL) {
|
|
Packit |
90a5c9 |
dav_liveprop_uris = apr_hash_make(p);
|
|
Packit |
90a5c9 |
apr_pool_cleanup_register(p, NULL, dav_cleanup_liveprops, apr_pool_cleanup_null);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
value = (long)apr_hash_get(dav_liveprop_uris, uri, APR_HASH_KEY_STRING);
|
|
Packit |
90a5c9 |
if (value != 0) {
|
|
Packit |
90a5c9 |
/* already registered */
|
|
Packit |
90a5c9 |
return;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* start at 1, and count up */
|
|
Packit |
90a5c9 |
apr_hash_set(dav_liveprop_uris, uri, APR_HASH_KEY_STRING,
|
|
Packit |
90a5c9 |
(void *)++dav_liveprop_count);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
DAV_DECLARE(long) dav_get_liveprop_ns_index(const char *uri)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
return (long)apr_hash_get(dav_liveprop_uris, uri, APR_HASH_KEY_STRING);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
DAV_DECLARE(long) dav_get_liveprop_ns_count(void)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
return dav_liveprop_count;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
DAV_DECLARE(void) dav_add_all_liveprop_xmlns(apr_pool_t *p,
|
|
Packit |
90a5c9 |
apr_text_header *phdr)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_hash_index_t *idx = apr_hash_first(p, dav_liveprop_uris);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for ( ; idx != NULL; idx = apr_hash_next(idx) ) {
|
|
Packit |
90a5c9 |
const void *key;
|
|
Packit |
90a5c9 |
void *val;
|
|
Packit |
90a5c9 |
const char *s;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_hash_this(idx, &key, NULL, &val;;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
s = apr_psprintf(p, " xmlns:lp%ld=\"%s\"", (long)val, (const char *)key);
|
|
Packit |
90a5c9 |
apr_text_append(p, phdr, s);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
DAV_DECLARE(int) dav_do_find_liveprop(const char *ns_uri, const char *name,
|
|
Packit |
90a5c9 |
const dav_liveprop_group *group,
|
|
Packit |
90a5c9 |
const dav_hooks_liveprop **hooks)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
const char * const *uris = group->namespace_uris;
|
|
Packit |
90a5c9 |
const dav_liveprop_spec *scan;
|
|
Packit |
90a5c9 |
int ns;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* first: locate the namespace in the namespace table */
|
|
Packit |
90a5c9 |
for (ns = 0; uris[ns] != NULL; ++ns)
|
|
Packit |
90a5c9 |
if (strcmp(ns_uri, uris[ns]) == 0)
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
if (uris[ns] == NULL) {
|
|
Packit |
90a5c9 |
/* not our property (the namespace matched none of ours) */
|
|
Packit |
90a5c9 |
return 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* second: look for the property in the liveprop specs */
|
|
Packit |
90a5c9 |
for (scan = group->specs; scan->name != NULL; ++scan)
|
|
Packit |
90a5c9 |
if (ns == scan->ns && strcmp(name, scan->name) == 0) {
|
|
Packit |
90a5c9 |
*hooks = group->hooks;
|
|
Packit |
90a5c9 |
return scan->propid;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* not our property (same namespace, but no matching prop name) */
|
|
Packit |
90a5c9 |
return 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
DAV_DECLARE(long) dav_get_liveprop_info(int propid,
|
|
Packit |
90a5c9 |
const dav_liveprop_group *group,
|
|
Packit |
90a5c9 |
const dav_liveprop_spec **info)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
const dav_liveprop_spec *scan;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for (scan = group->specs; scan->name != NULL; ++scan) {
|
|
Packit |
90a5c9 |
if (scan->propid == propid) {
|
|
Packit |
90a5c9 |
*info = scan;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* map the provider-local NS into a global NS index */
|
|
Packit |
90a5c9 |
return dav_get_liveprop_ns_index(group->namespace_uris[scan->ns]);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* assert: should not reach this point */
|
|
Packit |
90a5c9 |
*info = NULL;
|
|
Packit |
90a5c9 |
return 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
DAV_DECLARE(void) dav_register_liveprop_group(apr_pool_t *p,
|
|
Packit |
90a5c9 |
const dav_liveprop_group *group)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
/* register the namespace URIs */
|
|
Packit |
90a5c9 |
const char * const * uris = group->namespace_uris;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for ( ; *uris != NULL; ++uris) {
|
|
Packit |
90a5c9 |
dav_register_liveprop_namespace(p, *uris);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|