bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / server / provider.c
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
20 #include "ap_provider.h"
21
22 static apr_hash_t *global_providers = NULL;
23
24 static apr_status_t cleanup_global_providers(void *ctx)
25 {
26     global_providers = NULL;
27     return APR_SUCCESS;
28 }
29
30 AP_DECLARE(apr_status_t) ap_register_provider(apr_pool_t *pool,
31                                               const char *provider_group,
32                                               const char *provider_name,
33                                               const char *provider_version,
34                                               const void *provider)
35 {
36     apr_hash_t *provider_group_hash;
37     apr_hash_t *provider_version_hash;
38
39     if (global_providers == NULL) {
40         global_providers = apr_hash_make(pool);
41         apr_pool_cleanup_register(pool, NULL, cleanup_global_providers,
42                                   apr_pool_cleanup_null);
43     }
44
45     provider_group_hash = apr_hash_get(global_providers, provider_group,
46                                        APR_HASH_KEY_STRING);
47
48     if (!provider_group_hash) {
49         provider_group_hash = apr_hash_make(pool);
50         apr_hash_set(global_providers, provider_group, APR_HASH_KEY_STRING,
51                      provider_group_hash);
52         
53     }
54
55     provider_version_hash = apr_hash_get(provider_group_hash, provider_name,
56                                          APR_HASH_KEY_STRING);
57
58     if (!provider_version_hash) {
59         provider_version_hash = apr_hash_make(pool);
60         apr_hash_set(provider_group_hash, provider_name, APR_HASH_KEY_STRING,
61                      provider_version_hash);
62         
63     }
64
65     /* just set it. no biggy if it was there before. */
66     apr_hash_set(provider_version_hash, provider_version, APR_HASH_KEY_STRING,
67                  provider);
68
69     return APR_SUCCESS;
70 }
71
72 AP_DECLARE(void *) ap_lookup_provider(const char *provider_group,
73                                       const char *provider_name,
74                                       const char *provider_version)
75 {
76     apr_hash_t *provider_group_hash, *provider_name_hash;
77
78     if (global_providers == NULL) {
79         return NULL;
80     }
81
82     provider_group_hash = apr_hash_get(global_providers, provider_group,
83                                        APR_HASH_KEY_STRING);
84
85     if (provider_group_hash == NULL) {
86         return NULL;
87     }
88
89     provider_name_hash = apr_hash_get(provider_group_hash, provider_name,
90                                       APR_HASH_KEY_STRING);
91
92     if (provider_name_hash == NULL) {
93         return NULL;
94     }
95
96     return apr_hash_get(provider_name_hash, provider_version,
97                         APR_HASH_KEY_STRING);
98 }