*/
int cache_select_url(request_rec *r, const char *types, char *url)
{
- cache_handle *h;
const char *next = types;
const char *type;
apr_status_t rv;
&cache_module);
/* go through the cache types till we get a match */
+ cache->handle = apr_palloc(r->pool, sizeof(cache_handle));
+
while (next) {
type = ap_cache_tokstr(r->pool, next, &next);
- switch ((rv = cache_run_open_entity(&h, type, url))) {
+ switch ((rv = cache_run_open_entity(cache->handle, type, url))) {
case OK: {
/* cool bananas! */
- cache->handle = h;
/*** loop through returned entities */
/*** do freshness calculation here */
cache->fresh = 1;
}
default: {
/* oo-er! an error */
+ cache->handle = NULL;
return rv;
}
}
}
+ cache->handle = NULL;
return DECLINED;
}
(cache_handle **hp, const char *type,
char *url, apr_size_t len),(hp,type,url,len),DECLINED)
APR_IMPLEMENT_EXTERNAL_HOOK_RUN_FIRST(cache, CACHE, int, open_entity,
- (cache_handle **hp, const char *type,
- char *url),(hp,type,url),DECLINED)
+ (cache_handle *h, const char *type,
+ char *url),(h,type,url),DECLINED)
APR_IMPLEMENT_EXTERNAL_HOOK_RUN_ALL(cache, CACHE, int, remove_url,
(const char *type, char *url),(type,url),OK,DECLINED)
#if 0
(cache_handle **hp, const char *type,
char *url, apr_size_t len))
APR_DECLARE_EXTERNAL_HOOK(cache, CACHE, int, open_entity,
- (cache_handle **hp, const char *type,
+ (cache_handle *h, const char *type,
char *url))
APR_DECLARE_EXTERNAL_HOOK(cache, CACHE, int, remove_url,
(const char *type, char *url))
return OK;
}
-static int open_entity(cache_handle **hp, const char *type, char *key)
+static int open_entity(cache_handle *h, const char *type, char *key)
{
cache_object_t *obj;
- cache_handle *h;
/* Look up entity keyed to 'url' */
if (strcasecmp(type, "mem")) {
return DECLINED;
}
- /* Allocate the cache_handle and initialize it */
- h = malloc(sizeof(cache_handle));
- *hp = h;
- if (!h) {
- /* handle the error */
- return DECLINED;
- }
+ /* Initialize the cache_handle */
h->read_body = &read_body;
h->read_headers = &read_headers;
h->write_body = &write_body;
/* Reinit the cache_handle fields? */
h->cache_obj = NULL;
- /* The caller should free the cache_handle ? */
- free(h);
return OK;
}