util_ldap_cache_mgr.c revision 34c31900b28fece91a68e8eb29fc574940431fec
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
*/
/*
* 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>
#ifdef APU_HAS_LDAP
/* only here until strdup is gone */
#include <string.h>
/* here till malloc is gone */
#include <stdlib.h>
static const int 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
};
void util_ald_free(const void *ptr)
{
#ifdef APU_HAS_LDAP_SHARED_CACHE
if (util_ldap_shm) {
} else {
}
#else
#endif
}
void *util_ald_alloc(int size)
{
#ifdef APU_HAS_LDAP_SHARED_CACHE
if (util_ldap_shm) {
} else {
}
#else
#endif
}
const char *util_ald_strdup(const char *s)
{
#ifdef APU_HAS_LDAP_SHARED_CACHE
if (util_ldap_shm) {
if (buf) {
return buf;
}
else {
return NULL;
}
} else {
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.
*/
{
int i;
util_cache_node_t *p, *q;
apr_time_t t;
while (p != NULL) {
q = p->next;
util_ald_free(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 *),
void * (*copyfunc)(void *),
void (*freefunc)(void *))
{
int i;
if (maxentries <= 0)
return NULL;
if (!cache)
return NULL;
cache->numentries = 0;
return NULL;
}
cache->last_purge = 0;
return cache;
}
{
int i;
util_cache_node_t *p, *q;
return;
q = NULL;
while (p != NULL) {
q = p->next;
util_ald_free(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;
}
{
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(p);
cache->numentries--;
}
{
int 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;
}
{
int 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 /* APU_HAS_LDAP */