removed some of the debug logging and added author details
[httpd-crcsyncproxy.git] / server / provider.c
bloba5406ab1e8d386b565cc228e956f1e326ccec07f
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"
18 #include "apr_hash.h"
19 #include "apr_tables.h"
20 #include "apr_strings.h"
22 #include "ap_provider.h"
24 static apr_hash_t *global_providers = NULL;
25 static apr_hash_t *global_providers_names = NULL;
28 static apr_status_t cleanup_global_providers(void *ctx)
30 global_providers = NULL;
31 global_providers_names = NULL;
32 return APR_SUCCESS;
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)
41 apr_hash_t *provider_group_hash, *provider_version_hash;
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);
50 /* First, deal with storing the provider away */
51 provider_group_hash = apr_hash_get(global_providers, provider_group,
52 APR_HASH_KEY_STRING);
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);
61 provider_version_hash = apr_hash_get(provider_group_hash, provider_name,
62 APR_HASH_KEY_STRING);
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);
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);
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);
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);
86 provider_version_hash = apr_hash_get(provider_group_hash, provider_version,
87 APR_HASH_KEY_STRING);
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);
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);
100 return APR_SUCCESS;
103 AP_DECLARE(void *) ap_lookup_provider(const char *provider_group,
104 const char *provider_name,
105 const char *provider_version)
107 apr_hash_t *provider_group_hash, *provider_name_hash;
109 if (global_providers == NULL) {
110 return NULL;
113 provider_group_hash = apr_hash_get(global_providers, provider_group,
114 APR_HASH_KEY_STRING);
116 if (provider_group_hash == NULL) {
117 return NULL;
120 provider_name_hash = apr_hash_get(provider_group_hash, provider_name,
121 APR_HASH_KEY_STRING);
123 if (provider_name_hash == NULL) {
124 return NULL;
127 return apr_hash_get(provider_name_hash, provider_version,
128 APR_HASH_KEY_STRING);
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)
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;
141 if (global_providers_names == NULL) {
142 return ret;
145 provider_group_hash = apr_hash_get(global_providers_names, provider_group,
146 APR_HASH_KEY_STRING);
148 if (provider_group_hash == NULL) {
149 return ret;
152 h = apr_hash_get(provider_group_hash, provider_version,
153 APR_HASH_KEY_STRING);
155 if (h == NULL) {
156 return ret;
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);
164 return ret;