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.
17 #include "apr_pools.h"
19 #include "apr_errno.h"
20 #include "apr_strings.h"
21 #include "util_xml.h" /* for apr_text_header */
25 static apr_hash_t *dav_liveprop_uris = NULL;
26 static int dav_liveprop_count = 0;
29 static apr_status_t dav_cleanup_liveprops(void *ctx)
31 dav_liveprop_uris = NULL;
32 dav_liveprop_count = 0;
36 static void dav_register_liveprop_namespace(apr_pool_t *p, const char *uri)
40 if (dav_liveprop_uris == NULL) {
41 dav_liveprop_uris = apr_hash_make(p);
42 apr_pool_cleanup_register(p, NULL, dav_cleanup_liveprops, apr_pool_cleanup_null);
45 value = (int)apr_hash_get(dav_liveprop_uris, uri, APR_HASH_KEY_STRING);
47 /* already registered */
51 /* start at 1, and count up */
52 apr_hash_set(dav_liveprop_uris, uri, APR_HASH_KEY_STRING,
53 (void *)++dav_liveprop_count);
56 DAV_DECLARE(int) dav_get_liveprop_ns_index(const char *uri)
58 return (int)apr_hash_get(dav_liveprop_uris, uri, APR_HASH_KEY_STRING);
61 DAV_DECLARE(int) dav_get_liveprop_ns_count(void)
63 return dav_liveprop_count;
66 DAV_DECLARE(void) dav_add_all_liveprop_xmlns(apr_pool_t *p,
67 apr_text_header *phdr)
69 apr_hash_index_t *idx = apr_hash_first(p, dav_liveprop_uris);
71 for ( ; idx != NULL; idx = apr_hash_next(idx) ) {
76 apr_hash_this(idx, &key, NULL, &val);
78 s = apr_psprintf(p, " xmlns:lp%d=\"%s\"", (int)val, (const char *)key);
79 apr_text_append(p, phdr, s);
83 DAV_DECLARE(int) dav_do_find_liveprop(const char *ns_uri, const char *name,
84 const dav_liveprop_group *group,
85 const dav_hooks_liveprop **hooks)
87 const char * const *uris = group->namespace_uris;
88 const dav_liveprop_spec *scan;
91 /* first: locate the namespace in the namespace table */
92 for (ns = 0; uris[ns] != NULL; ++ns)
93 if (strcmp(ns_uri, uris[ns]) == 0)
95 if (uris[ns] == NULL) {
96 /* not our property (the namespace matched none of ours) */
100 /* second: look for the property in the liveprop specs */
101 for (scan = group->specs; scan->name != NULL; ++scan)
102 if (ns == scan->ns && strcmp(name, scan->name) == 0) {
103 *hooks = group->hooks;
107 /* not our property (same namespace, but no matching prop name) */
111 DAV_DECLARE(int) dav_get_liveprop_info(int propid,
112 const dav_liveprop_group *group,
113 const dav_liveprop_spec **info)
115 const dav_liveprop_spec *scan;
117 for (scan = group->specs; scan->name != NULL; ++scan) {
118 if (scan->propid == propid) {
121 /* map the provider-local NS into a global NS index */
122 return dav_get_liveprop_ns_index(group->namespace_uris[scan->ns]);
126 /* assert: should not reach this point */
131 DAV_DECLARE(void) dav_register_liveprop_group(apr_pool_t *p,
132 const dav_liveprop_group *group)
134 /* register the namespace URIs */
135 const char * const * uris = group->namespace_uris;
137 for ( ; *uris != NULL; ++uris) {
138 dav_register_liveprop_namespace(p, *uris);