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

« back to all changes in this revision

Viewing changes to server/provider.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_tables.h"
 
20
#include "apr_strings.h"
 
21
 
 
22
#include "ap_provider.h"
 
23
 
 
24
static apr_hash_t *global_providers = NULL;
 
25
static apr_hash_t *global_providers_names = NULL;
 
26
 
 
27
 
 
28
static apr_status_t cleanup_global_providers(void *ctx)
 
29
{
 
30
    global_providers = NULL;
 
31
    global_providers_names = NULL;
 
32
    return APR_SUCCESS;
 
33
}
 
34
 
 
35
AP_DECLARE(apr_status_t) ap_register_provider(apr_pool_t *pool,
 
36
                                              const char *provider_group,
 
37
                                              const char *provider_name,
 
38
                                              const char *provider_version,
 
39
                                              const void *provider)
 
40
{
 
41
    apr_hash_t *provider_group_hash, *provider_version_hash;
 
42
 
 
43
    if (global_providers == NULL) {
 
44
        global_providers = apr_hash_make(pool);
 
45
        global_providers_names = apr_hash_make(pool);;
 
46
        apr_pool_cleanup_register(pool, NULL, cleanup_global_providers,
 
47
                                  apr_pool_cleanup_null);
 
48
    }
 
49
 
 
50
    /* First, deal with storing the provider away */
 
51
    provider_group_hash = apr_hash_get(global_providers, provider_group,
 
52
                                       APR_HASH_KEY_STRING);
 
53
 
 
54
    if (!provider_group_hash) {
 
55
        provider_group_hash = apr_hash_make(pool);
 
56
        apr_hash_set(global_providers, provider_group, APR_HASH_KEY_STRING,
 
57
                     provider_group_hash);
 
58
 
 
59
    }
 
60
 
 
61
    provider_version_hash = apr_hash_get(provider_group_hash, provider_name,
 
62
                                         APR_HASH_KEY_STRING);
 
63
 
 
64
    if (!provider_version_hash) {
 
65
        provider_version_hash = apr_hash_make(pool);
 
66
        apr_hash_set(provider_group_hash, provider_name, APR_HASH_KEY_STRING,
 
67
                     provider_version_hash);
 
68
 
 
69
    }
 
70
 
 
71
    /* just set it. no biggy if it was there before. */
 
72
    apr_hash_set(provider_version_hash, provider_version, APR_HASH_KEY_STRING,
 
73
                 provider);
 
74
 
 
75
    /* Now, tuck away the provider names in an easy-to-get format */
 
76
    provider_group_hash = apr_hash_get(global_providers_names, provider_group,
 
77
                                       APR_HASH_KEY_STRING);
 
78
 
 
79
    if (!provider_group_hash) {
 
80
        provider_group_hash = apr_hash_make(pool);
 
81
        apr_hash_set(global_providers_names, provider_group, APR_HASH_KEY_STRING,
 
82
                     provider_group_hash);
 
83
 
 
84
    }
 
85
 
 
86
    provider_version_hash = apr_hash_get(provider_group_hash, provider_version,
 
87
                                         APR_HASH_KEY_STRING);
 
88
 
 
89
    if (!provider_version_hash) {
 
90
        provider_version_hash = apr_hash_make(pool);
 
91
        apr_hash_set(provider_group_hash, provider_version, APR_HASH_KEY_STRING,
 
92
                     provider_version_hash);
 
93
 
 
94
    }
 
95
 
 
96
    /* just set it. no biggy if it was there before. */
 
97
    apr_hash_set(provider_version_hash, provider_name, APR_HASH_KEY_STRING,
 
98
                 provider_name);
 
99
 
 
100
    return APR_SUCCESS;
 
101
}
 
102
 
 
103
AP_DECLARE(void *) ap_lookup_provider(const char *provider_group,
 
104
                                      const char *provider_name,
 
105
                                      const char *provider_version)
 
106
{
 
107
    apr_hash_t *provider_group_hash, *provider_name_hash;
 
108
 
 
109
    if (global_providers == NULL) {
 
110
        return NULL;
 
111
    }
 
112
 
 
113
    provider_group_hash = apr_hash_get(global_providers, provider_group,
 
114
                                       APR_HASH_KEY_STRING);
 
115
 
 
116
    if (provider_group_hash == NULL) {
 
117
        return NULL;
 
118
    }
 
119
 
 
120
    provider_name_hash = apr_hash_get(provider_group_hash, provider_name,
 
121
                                      APR_HASH_KEY_STRING);
 
122
 
 
123
    if (provider_name_hash == NULL) {
 
124
        return NULL;
 
125
    }
 
126
 
 
127
    return apr_hash_get(provider_name_hash, provider_version,
 
128
                        APR_HASH_KEY_STRING);
 
129
}
 
130
 
 
131
AP_DECLARE(apr_array_header_t *) ap_list_provider_names(apr_pool_t *pool,
 
132
                                              const char *provider_group,
 
133
                                              const char *provider_version)
 
134
{
 
135
    apr_array_header_t *ret = apr_array_make(pool, 10, sizeof(ap_list_provider_names_t));
 
136
    ap_list_provider_names_t *entry;
 
137
    apr_hash_t *provider_group_hash, *h;
 
138
    apr_hash_index_t *hi;
 
139
    char *val, *key;
 
140
 
 
141
    if (global_providers_names == NULL) {
 
142
        return ret;
 
143
    }
 
144
 
 
145
    provider_group_hash = apr_hash_get(global_providers_names, provider_group,
 
146
                                       APR_HASH_KEY_STRING);
 
147
 
 
148
    if (provider_group_hash == NULL) {
 
149
        return ret;
 
150
    }
 
151
 
 
152
    h = apr_hash_get(provider_group_hash, provider_version,
 
153
                                      APR_HASH_KEY_STRING);
 
154
 
 
155
    if (h == NULL) {
 
156
        return ret;
 
157
    }
 
158
 
 
159
    for (hi = apr_hash_first(pool, h); hi; hi = apr_hash_next(hi)) {
 
160
        apr_hash_this(hi, (void *)&key, NULL, (void *)&val);
 
161
        entry = apr_array_push(ret);
 
162
        entry->provider_name = apr_pstrdup(pool, val);
 
163
    }
 
164
    return ret;
 
165
}