2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 /***************************************************************************
19 * Description: Context handling (Autoconf) *
20 * Author: Henri Gomez <hgomez@apache.org> *
21 * Version: $Revision: 466585 $ *
22 ***************************************************************************/
24 #include "jk_global.h"
25 #include "jk_context.h"
26 #include "jk_ajp_common.h"
30 * Set the virtual name of the context
33 int context_set_virtual(jk_context_t *c, char *virt)
38 c->virt = jk_pool_strdup(&c->p, virt);
51 * Init the context info struct
54 int context_open(jk_context_t *c, char *virt)
57 jk_open_pool(&c->p, c->buf, sizeof(jk_pool_atom_t) * SMALL_POOL_SIZE);
62 return context_set_virtual(c, virt);
69 * Close the context info struct
72 int context_close(jk_context_t *c)
84 * Allocate and open context
87 int context_alloc(jk_context_t **c, char *virt)
90 return context_open(*c =
91 (jk_context_t *)calloc(1, sizeof(jk_context_t)),
98 * Close and destroy context
101 int context_free(jk_context_t **c)
115 * Ensure there will be memory in context info to store Context Bases
118 static int context_realloc(jk_context_t *c)
120 if (c->size == c->capacity) {
121 jk_context_item_t **contexts;
122 int capacity = c->capacity + CBASE_INC_SIZE;
125 (jk_context_item_t **)jk_pool_alloc(&c->p,
126 sizeof(jk_context_item_t *) *
132 if (c->capacity && c->contexts)
133 memcpy(contexts, c->contexts,
134 sizeof(jk_context_item_t *) * c->capacity);
136 c->contexts = contexts;
137 c->capacity = capacity;
144 * Ensure there will be memory in context info to URIS
147 static int context_item_realloc(jk_context_t *c, jk_context_item_t *ci)
149 if (ci->size == ci->capacity) {
151 int capacity = ci->capacity + URI_INC_SIZE;
153 uris = (char **)jk_pool_alloc(&c->p, sizeof(char *) * capacity);
158 memcpy(uris, ci->uris, sizeof(char *) * ci->capacity);
161 ci->capacity = capacity;
169 * Locate a context base in context list
172 jk_context_item_t *context_find_base(jk_context_t *c, char *cbase)
175 jk_context_item_t *ci;
180 for (i = 0; i < c->size; i++) {
187 if (!strcmp(ci->cbase, cbase))
195 * Locate an URI in a context item
198 char *context_item_find_uri(jk_context_item_t *ci, char *uri)
205 for (i = 0; i < ci->size; i++) {
206 if (!strcmp(ci->uris[i], uri))
213 void context_dump_uris(jk_context_t *c, char *cbase, FILE * f)
215 jk_context_item_t *ci;
218 ci = context_find_base(c, cbase);
223 for (i = 0; i < ci->size; i++)
224 fprintf(f, "/%s/%s\n", ci->cbase, ci->uris[i]);
231 * Add a new context item to context
234 jk_context_item_t *context_add_base(jk_context_t *c, char *cbase)
236 jk_context_item_t *ci;
241 /* Check if the context base was not allready created */
242 ci = context_find_base(c, cbase);
247 if (context_realloc(c) != JK_TRUE)
250 ci = (jk_context_item_t *)jk_pool_alloc(&c->p, sizeof(jk_context_item_t));
255 c->contexts[c->size] = ci;
257 ci->cbase = jk_pool_strdup(&c->p, cbase);
267 * Add a new URI to a context item
270 int context_add_uri(jk_context_t *c, char *cbase, char *uri)
272 jk_context_item_t *ci;
277 /* Get/Create the context base */
278 ci = context_add_base(c, cbase);
283 if (context_item_find_uri(ci, uri) != NULL)
286 if (context_item_realloc(c, ci) == JK_FALSE)
289 ci->uris[ci->size] = jk_pool_strdup(&c->p, uri);
291 if (ci->uris[ci->size] == NULL)