~ubuntu-branches/ubuntu/feisty/apache2/feisty

« back to all changes in this revision

Viewing changes to modules/dav/main/liveprop.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2006-12-09 21:05:45 UTC
  • mfrom: (0.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061209210545-h70s0xaqc2v8vqr2
Tags: 2.2.3-3.2
* Non-maintainer upload.
* 043_ajp_connection_reuse: Patch from upstream Bugzilla, fixing a critical
  issue with regard to connection reuse in mod_proxy_ajp.
  Closes: #396265

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
7
 *
 
8
 *     http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
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.
 
15
 */
 
16
 
 
17
#include "apr_pools.h"
 
18
#include "apr_hash.h"
 
19
#include "apr_errno.h"
 
20
#include "apr_strings.h"
 
21
#include "util_xml.h"   /* for apr_text_header */
 
22
#include "mod_dav.h"
 
23
 
 
24
 
 
25
static apr_hash_t *dav_liveprop_uris = NULL;
 
26
static long dav_liveprop_count = 0;
 
27
 
 
28
 
 
29
static apr_status_t dav_cleanup_liveprops(void *ctx)
 
30
{
 
31
    dav_liveprop_uris = NULL;
 
32
    dav_liveprop_count = 0;
 
33
    return APR_SUCCESS;
 
34
}
 
35
 
 
36
static void dav_register_liveprop_namespace(apr_pool_t *p, const char *uri)
 
37
{
 
38
    long value;
 
39
 
 
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);
 
43
    }
 
44
 
 
45
    value = (long)apr_hash_get(dav_liveprop_uris, uri, APR_HASH_KEY_STRING);
 
46
    if (value != 0) {
 
47
        /* already registered */
 
48
        return;
 
49
    }
 
50
 
 
51
    /* start at 1, and count up */
 
52
    apr_hash_set(dav_liveprop_uris, uri, APR_HASH_KEY_STRING,
 
53
                 (void *)++dav_liveprop_count);
 
54
}
 
55
 
 
56
DAV_DECLARE(long) dav_get_liveprop_ns_index(const char *uri)
 
57
{
 
58
    return (long)apr_hash_get(dav_liveprop_uris, uri, APR_HASH_KEY_STRING);
 
59
}
 
60
 
 
61
DAV_DECLARE(long) dav_get_liveprop_ns_count(void)
 
62
{
 
63
    return dav_liveprop_count;
 
64
}
 
65
 
 
66
DAV_DECLARE(void) dav_add_all_liveprop_xmlns(apr_pool_t *p,
 
67
                                             apr_text_header *phdr)
 
68
{
 
69
    apr_hash_index_t *idx = apr_hash_first(p, dav_liveprop_uris);
 
70
 
 
71
    for ( ; idx != NULL; idx = apr_hash_next(idx) ) {
 
72
        const void *key;
 
73
        void *val;
 
74
        const char *s;
 
75
 
 
76
        apr_hash_this(idx, &key, NULL, &val);
 
77
 
 
78
        s = apr_psprintf(p, " xmlns:lp%ld=\"%s\"", (long)val, (const char *)key);
 
79
        apr_text_append(p, phdr, s);
 
80
    }
 
81
}
 
82
 
 
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)
 
86
{
 
87
    const char * const *uris = group->namespace_uris;
 
88
    const dav_liveprop_spec *scan;
 
89
    int ns;
 
90
 
 
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)
 
94
            break;
 
95
    if (uris[ns] == NULL) {
 
96
        /* not our property (the namespace matched none of ours) */
 
97
        return 0;
 
98
    }
 
99
 
 
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;
 
104
            return scan->propid;
 
105
        }
 
106
 
 
107
    /* not our property (same namespace, but no matching prop name) */
 
108
    return 0;
 
109
}
 
110
 
 
111
DAV_DECLARE(long) dav_get_liveprop_info(int propid,
 
112
                                       const dav_liveprop_group *group,
 
113
                                       const dav_liveprop_spec **info)
 
114
{
 
115
    const dav_liveprop_spec *scan;
 
116
 
 
117
    for (scan = group->specs; scan->name != NULL; ++scan) {
 
118
        if (scan->propid == propid) {
 
119
            *info = scan;
 
120
 
 
121
            /* map the provider-local NS into a global NS index */
 
122
            return dav_get_liveprop_ns_index(group->namespace_uris[scan->ns]);
 
123
        }
 
124
    }
 
125
 
 
126
    /* assert: should not reach this point */
 
127
    *info = NULL;
 
128
    return 0;
 
129
}
 
130
 
 
131
DAV_DECLARE(void) dav_register_liveprop_group(apr_pool_t *p,
 
132
                                              const dav_liveprop_group *group)
 
133
{
 
134
    /* register the namespace URIs */
 
135
    const char * const * uris = group->namespace_uris;
 
136
 
 
137
    for ( ; *uris != NULL; ++uris) {
 
138
        dav_register_liveprop_namespace(p, *uris);
 
139
    }
 
140
}