util_ldap_cache_mgr.c revision 78cd48acd325773619d78ac0d7263a99a8922fae
/* Copyright 2001-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* util_ldap_cache_mgr.c: LDAP cache manager things
*
* Original code from auth_ldap module for Apache v1.3:
* Copyright 1998, 1999 Enbridge Pipelines Inc.
* Copyright 1999-2001 Dave Carrigan
*/
#include <apr_ldap.h>
#include "util_ldap.h"
#include "util_ldap_cache.h"
#include <apr_strings.h>
#if APR_HAS_LDAP
/* only here until strdup is gone */
#include <string.h>
/* here till malloc is gone */
#include <stdlib.h>
static const unsigned long primes[] =
{
11,
19,
37,
73,
109,
163,
251,
367,
557,
823,
1237,
1861,
2777,
4177,
6247,
9371,
14057,
21089,
31627,
47431,
71143,
106721,
160073,
240101,
360163,
540217,
810343,
1215497,
1823231,
2734867,
4102283,
6153409,
9230113,
13845163,
0
};
{
if (ptr)
/* Free in shared memory */
}
else {
if (ptr)
/* Cache shm is not used */
}
#else
if (ptr)
#endif
}
{
if (0 == size)
return NULL;
/* allocate from shared memory */
}
else {
/* Cache shm is not used */
}
#else
#endif
}
{
/* allocate from shared memory */
char *buf = (char *)apr_rmm_addr_get(cache->rmm_addr, apr_rmm_calloc(cache->rmm_addr, strlen(s)+1));
if (buf) {
return buf;
}
else {
return NULL;
}
} else {
/* Cache shm is not used */
return strdup(s);
}
#else
return strdup(s);
#endif
}
/*
* Computes the hash on a set of strings. The first argument is the number
* of strings to hash, the rest of the args are strings.
* Algorithm taken from glibc.
*/
unsigned long util_ald_hash_string(int nstr, ...)
{
int i;
unsigned long h=0, g;
char *str, *p;
for (i=0; i < nstr; ++i) {
for (p = str; *p; ++p) {
h = ( h << 4 ) + *p;
if ( ( g = h & 0xf0000000 ) ) {
h = h ^ (g >> 24);
h = h ^ g;
}
}
}
return h;
}
/*
Purges a cache that has gotten full. We keep track of the time that we
added the entry that made the cache 3/4 full, then delete all entries
that were added before that time. It's pretty simplistic, but time to
purge is only O(n), which is more important.
*/
{
unsigned long i;
util_cache_node_t *p, *q;
apr_time_t t;
if (!cache)
return;
while (p != NULL) {
q = p->next;
util_ald_free(cache, p);
cache->numentries--;
p = q;
}
else {
p = p->next;
}
}
}
t = apr_time_now();
}
/*
* create caches
*/
{
/* create the three caches */
/* check that all the caches initialised successfully */
}
return curl;
}
unsigned long (*hashfunc)(void *),
int (*comparefunc)(void *, void *),
{
unsigned long i;
if (st->search_cache_size <= 0)
return NULL;
cache = (util_ald_cache_t *)apr_rmm_addr_get(st->cache_rmm, apr_rmm_calloc(st->cache_rmm, sizeof(util_ald_cache_t)));
#else
#endif
if (!cache)
return NULL;
cache->numentries = 0;
cache->nodes = (util_cache_node_t **)util_ald_alloc(cache, cache->size * sizeof(util_cache_node_t *));
return NULL;
}
cache->last_purge = 0;
return cache;
}
{
unsigned long i;
util_cache_node_t *p, *q;
return;
q = NULL;
while (p != NULL) {
q = p->next;
util_ald_free(cache, p);
p = q;
}
}
}
{
int hashval;
return NULL;
p = p->next) ;
if (p != NULL) {
return p->payload;
}
else {
return NULL;
}
}
/*
* Insert an item into the cache.
* *** Does not catch duplicates!!! ***
*/
{
int hashval;
return;
return;
}
{
int hashval;
util_cache_node_t *p, *q;
return;
p = p->next) {
q = p;
}
/* If p is null, it means that we couldn't find the node, so just return */
if (p == NULL)
return;
if (q == NULL) {
/* We found the node, and it's the first in the list */
}
else {
/* We found the node and it's not the first in the list */
}
util_ald_free(cache, p);
cache->numentries--;
}
{
unsigned long i;
int totchainlen = 0;
int nchains = 0;
double chainlen;
char *buf;
return "";
}
nchains++;
totchainlen++;
}
}
buf = apr_psprintf(p,
"<tr valign='top'>"
"<td nowrap>%s</td>"
"<td align='right' nowrap>%lu (%.0f%% full)</td>"
"<td align='right'>%.1f</td>"
"<td align='right'>%lu/%lu</td>"
"<td align='right'>%.0f%%</td>"
"<td align='right'>%lu/%lu</td>",
name,
char str_ctime[APR_CTIME_LEN];
buf = apr_psprintf(p,
"%s"
"<td align='right'>%lu</td>\n"
"<td align='right' nowrap>%s</td>\n",
buf,
}
else {
buf = apr_psprintf(p,
"%s<td colspan='2' align='center'>(none)</td>\n",
buf);
}
return buf;
}
{
unsigned long i;
if (!util_ldap_cache) {
return "<tr valign='top'><td nowrap colspan=7>Cache has not been enabled/initialised.</td></tr>";
}
for (i=0; i < util_ldap_cache->size; ++i) {
util_url_node_t *n;
n = (util_url_node_t *)p->payload;
"%s\n\n"
"%s\n\n"
"%s\n\n",
buf,
);
}
}
return buf;
}
#endif /* APR_HAS_LDAP */