From cvs-return-19261-apmail-httpd-cvs-archive=httpd.apache.org@httpd.apache.org Wed Jun 16 23:25:31 2004 Return-Path: Delivered-To: apmail-httpd-cvs-archive@www.apache.org Received: (qmail 74047 invoked from network); 16 Jun 2004 23:25:30 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 16 Jun 2004 23:25:30 -0000 Received: (qmail 24708 invoked by uid 500); 16 Jun 2004 23:26:02 -0000 Delivered-To: apmail-httpd-cvs-archive@httpd.apache.org Received: (qmail 24659 invoked by uid 500); 16 Jun 2004 23:26:01 -0000 Mailing-List: contact cvs-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@httpd.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cvs@httpd.apache.org Received: (qmail 24635 invoked by uid 500); 16 Jun 2004 23:26:01 -0000 Delivered-To: apmail-httpd-2.0-cvs@apache.org Received: (qmail 24624 invoked by uid 99); 16 Jun 2004 23:26:00 -0000 Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.27.1) with SMTP; Wed, 16 Jun 2004 16:26:00 -0700 Received: (qmail 74008 invoked by uid 1285); 16 Jun 2004 23:25:27 -0000 Date: 16 Jun 2004 23:25:27 -0000 Message-ID: <20040616232527.74007.qmail@minotaur.apache.org> From: bnicholes@apache.org To: httpd-2.0-cvs@apache.org Subject: cvs commit: httpd-2.0/modules/experimental util_ldap.c util_ldap_cache.c util_ldap_cache.h util_ldap_cache_mgr.c X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N bnicholes 2004/06/16 16:25:27 Modified: include util_ldap.h modules/experimental util_ldap.c util_ldap_cache.c util_ldap_cache.h util_ldap_cache_mgr.c Log: Enhance the util_ldap cache-info page to display the current contents of the search, compare and dn_compare caches Revision Changes Path 1.19 +1 -11 httpd-2.0/include/util_ldap.h Index: util_ldap.h =================================================================== RCS file: /home/cvs/httpd-2.0/include/util_ldap.h,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- util_ldap.h 20 May 2004 22:41:24 -0000 1.18 +++ util_ldap.h 16 Jun 2004 23:25:27 -0000 1.19 @@ -279,16 +279,6 @@ */ apr_status_t util_ldap_cache_init(apr_pool_t *pool, util_ldap_state_t *st); -/** - * Display formatted stats for cache - * @param The pool to allocate the returned string from - * @tip This function returns a string allocated from the provided pool that describes - * various stats about the cache. - * @deffunc char *util_ald_cache_display(apr_pool_t *pool, util_ldap_state_t *st) - */ -char *util_ald_cache_display(apr_pool_t *pool, util_ldap_state_t *st); - - /* from apr_ldap_cache_mgr.c */ /** @@ -298,7 +288,7 @@ * various stats about the cache. * @deffunc char *util_ald_cache_display(apr_pool_t *pool, util_ldap_state_t *st) */ -char *util_ald_cache_display(apr_pool_t *pool, util_ldap_state_t *st); +char *util_ald_cache_display(request_rec *r, util_ldap_state_t *st); #endif /* APR_HAS_LDAP */ #endif /* UTIL_LDAP_H */ 1.32 +1 -16 httpd-2.0/modules/experimental/util_ldap.c Index: util_ldap.c =================================================================== RCS file: /home/cvs/httpd-2.0/modules/experimental/util_ldap.c,v retrieving revision 1.31 retrieving revision 1.32 diff -u -r1.31 -r1.32 --- util_ldap.c 9 Jun 2004 21:54:50 -0000 1.31 +++ util_ldap.c 16 Jun 2004 23:25:27 -0000 1.32 @@ -134,22 +134,7 @@ "LDAP Cache Information\n", r); ap_rputs("

LDAP Cache Information

\n", r); - ap_rputs("

\n" - "\n" - "\n" - "" - "" - "" - "" - "" - "" - "" - "\n", r - ); - - ap_rputs(util_ald_cache_display(r->pool, st), r); - - ap_rputs("
Cache NameEntriesAvg. Chain Len.HitsIns/RemPurgesAvg Purge Time
\n

\n", r); + util_ald_cache_display(r, st); return OK; } 1.18 +81 -1 httpd-2.0/modules/experimental/util_ldap_cache.c Index: util_ldap_cache.c =================================================================== RCS file: /home/cvs/httpd-2.0/modules/experimental/util_ldap_cache.c,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- util_ldap_cache.c 26 May 2004 11:48:19 -0000 1.17 +++ util_ldap_cache.c 16 Jun 2004 23:25:27 -0000 1.18 @@ -22,6 +22,7 @@ */ #include +#include #include "util_ldap.h" #include "util_ldap_cache.h" @@ -78,6 +79,12 @@ util_ald_free(cache, node); } +void util_ldap_url_node_display(request_rec *r, util_ald_cache_t *cache, void *n) +{ + util_url_node_t *node = (util_url_node_t *)n; + +} + /* ------------------------------------------------------------------ */ /* Cache functions for search nodes */ @@ -156,6 +163,27 @@ util_ald_free(cache, node); } +void util_ldap_search_node_display(request_rec *r, util_ald_cache_t *cache, void *n) +{ + util_search_node_t *node = (util_search_node_t *)n; + char date_str[APR_CTIME_LEN+1]; + char *buf; + + apr_ctime(date_str, node->lastbind); + + buf = apr_psprintf(r->pool, + "" + "%s" + "%s" + "%s" + "", + node->username, + node->dn, + date_str); + + ap_rputs(buf, r); +} + /* ------------------------------------------------------------------ */ unsigned long util_ldap_compare_node_hash(void *n) @@ -203,6 +231,41 @@ util_ald_free(cache, node); } +void util_ldap_compare_node_display(request_rec *r, util_ald_cache_t *cache, void *n) +{ + util_compare_node_t *node = (util_compare_node_t *)n; + char date_str[APR_CTIME_LEN+1]; + char *buf, *cmp_result; + + apr_ctime(date_str, node->lastcompare); + + if (node->result == LDAP_COMPARE_TRUE) { + cmp_result = "LDAP_COMPARE_TRUE"; + } + else if (node->result == LDAP_COMPARE_FALSE) { + cmp_result = "LDAP_COMPARE_FALSE"; + } + else { + cmp_result = apr_itoa(r->pool, node->result); + } + + buf = apr_psprintf(r->pool, + "" + "%s" + "%s" + "%s" + "%s" + "%s" + "", + node->dn, + node->attrib, + node->value, + date_str, + cmp_result); + + ap_rputs(buf, r); +} + /* ------------------------------------------------------------------ */ unsigned long util_ldap_dn_compare_node_hash(void *n) @@ -241,6 +304,22 @@ util_ald_free(cache, node); } +void util_ldap_dn_compare_node_display(request_rec *r, util_ald_cache_t *cache, void *n) +{ + util_dn_compare_node_t *node = (util_dn_compare_node_t *)n; + char *buf; + + buf = apr_psprintf(r->pool, + "" + "%s" + "%s" + "", + node->reqdn, + node->dn); + + ap_rputs(buf, r); +} + /* ------------------------------------------------------------------ */ apr_status_t util_ldap_cache_child_kill(void *data); @@ -290,7 +369,8 @@ util_ldap_url_node_hash, util_ldap_url_node_compare, util_ldap_url_node_copy, - util_ldap_url_node_free); + util_ldap_url_node_free, + util_ldap_url_node_display); return APR_SUCCESS; } 1.14 +11 -3 httpd-2.0/modules/experimental/util_ldap_cache.h Index: util_ldap_cache.h =================================================================== RCS file: /home/cvs/httpd-2.0/modules/experimental/util_ldap_cache.h,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- util_ldap_cache.h 9 Feb 2004 20:29:18 -0000 1.13 +++ util_ldap_cache.h 16 Jun 2004 23:25:27 -0000 1.14 @@ -51,6 +51,7 @@ int (*compare)(void *, void *); /* Func to compare two payloads */ void * (*copy)(util_ald_cache_t *cache, void *); /* Func to alloc mem and copy payload to new mem */ void (*free)(util_ald_cache_t *cache, void *); /* Func to free mem used by the payload */ + void (*display)(request_rec *r, util_ald_cache_t *cache, void *); /* Func to display the payload contents */ util_cache_node_t **nodes; unsigned long numpurges; /* No. of times the cache has been purged */ @@ -157,18 +158,25 @@ int util_ldap_url_node_compare(void *a, void *b); void *util_ldap_url_node_copy(util_ald_cache_t *cache, void *c); void util_ldap_url_node_free(util_ald_cache_t *cache, void *n); +void util_ldap_url_node_display(request_rec *r, util_ald_cache_t *cache, void *n); + unsigned long util_ldap_search_node_hash(void *n); int util_ldap_search_node_compare(void *a, void *b); void *util_ldap_search_node_copy(util_ald_cache_t *cache, void *c); void util_ldap_search_node_free(util_ald_cache_t *cache, void *n); +void util_ldap_search_node_display(request_rec *r, util_ald_cache_t *cache, void *n); + unsigned long util_ldap_compare_node_hash(void *n); int util_ldap_compare_node_compare(void *a, void *b); void *util_ldap_compare_node_copy(util_ald_cache_t *cache, void *c); void util_ldap_compare_node_free(util_ald_cache_t *cache, void *n); +void util_ldap_compare_node_display(request_rec *r, util_ald_cache_t *cache, void *n); + unsigned long util_ldap_dn_compare_node_hash(void *n); int util_ldap_dn_compare_node_compare(void *a, void *b); void *util_ldap_dn_compare_node_copy(util_ald_cache_t *cache, void *c); void util_ldap_dn_compare_node_free(util_ald_cache_t *cache, void *n); +void util_ldap_dn_compare_node_display(request_rec *r, util_ald_cache_t *cache, void *n); /* util_ldap_cache_mgr.c */ @@ -186,14 +194,14 @@ unsigned long (*hashfunc)(void *), int (*comparefunc)(void *, void *), void * (*copyfunc)(util_ald_cache_t *cache, void *), - void (*freefunc)(util_ald_cache_t *cache, void *)); + void (*freefunc)(util_ald_cache_t *cache, void *), + void (*displayfunc)(request_rec *r, util_ald_cache_t *cache, void *)); void util_ald_destroy_cache(util_ald_cache_t *cache); void *util_ald_cache_fetch(util_ald_cache_t *cache, void *payload); void util_ald_cache_insert(util_ald_cache_t *cache, void *payload); void util_ald_cache_remove(util_ald_cache_t *cache, void *payload); -char *util_ald_cache_display_stats(apr_pool_t *p, util_ald_cache_t *cache, - char *name); +char *util_ald_cache_display_stats(request_rec *r, util_ald_cache_t *cache, char *name, char *id); #endif /* APR_HAS_LDAP */ #endif /* APU_LDAP_CACHE_H */ 1.17 +171 -46 httpd-2.0/modules/experimental/util_ldap_cache_mgr.c Index: util_ldap_cache_mgr.c =================================================================== RCS file: /home/cvs/httpd-2.0/modules/experimental/util_ldap_cache_mgr.c,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- util_ldap_cache_mgr.c 23 May 2004 22:15:10 -0000 1.16 +++ util_ldap_cache_mgr.c 16 Jun 2004 23:25:27 -0000 1.17 @@ -222,21 +222,25 @@ util_ldap_search_node_hash, util_ldap_search_node_compare, util_ldap_search_node_copy, - util_ldap_search_node_free); + util_ldap_search_node_free, + util_ldap_search_node_display); compare_cache = util_ald_create_cache(st, util_ldap_compare_node_hash, util_ldap_compare_node_compare, util_ldap_compare_node_copy, - util_ldap_compare_node_free); + util_ldap_compare_node_free, + util_ldap_compare_node_display); dn_compare_cache = util_ald_create_cache(st, util_ldap_dn_compare_node_hash, util_ldap_dn_compare_node_compare, util_ldap_dn_compare_node_copy, - util_ldap_dn_compare_node_free); + util_ldap_dn_compare_node_free, + util_ldap_dn_compare_node_display); /* check that all the caches initialised successfully */ if (search_cache && compare_cache && dn_compare_cache) { +/*XXX This can be allocated on the stack since it will be copied anyway */ curl = (util_url_node_t *)apr_pcalloc(st->pool, sizeof(util_url_node_t)); curl->url = url; curl->search_cache = search_cache; @@ -255,7 +259,8 @@ unsigned long (*hashfunc)(void *), int (*comparefunc)(void *, void *), void * (*copyfunc)(util_ald_cache_t *cache, void *), - void (*freefunc)(util_ald_cache_t *cache, void *)) + void (*freefunc)(util_ald_cache_t *cache, void *), + void (*displayfunc)(request_rec *r, util_ald_cache_t *cache, void *)) { util_ald_cache_t *cache; unsigned long i; @@ -297,6 +302,7 @@ cache->compare = comparefunc; cache->copy = copyfunc; cache->free = freefunc; + cache->display = displayfunc; cache->fullmark = cache->maxentries / 4 * 3; cache->marktime = 0; @@ -437,14 +443,15 @@ cache->numentries--; } -char *util_ald_cache_display_stats(apr_pool_t *p, util_ald_cache_t *cache, char *name) +char *util_ald_cache_display_stats(request_rec *r, util_ald_cache_t *cache, char *name, char *id) { unsigned long i; int totchainlen = 0; int nchains = 0; double chainlen; util_cache_node_t *n; - char *buf; + char *buf, *buf2; + apr_pool_t *p = r->pool; if (cache == NULL) { return ""; @@ -454,45 +461,56 @@ if (cache->nodes[i] != NULL) { nchains++; for (n = cache->nodes[i]; n != NULL; n = n->next) - totchainlen++; + totchainlen++; } } chainlen = nchains? (double)totchainlen / (double)nchains : 0; + if (id) { + buf2 = apr_psprintf(p, + "%s", + r->uri, + id, + name); + } + else { + buf2 = name; + } + buf = apr_psprintf(p, "" "%s" "%lu (%.0f%% full)" "%.1f" - "%lu/%lu" - "%.0f%%" + "%lu/%lu" + "%.0f%%" "%lu/%lu", - name, - cache->numentries, - (double)cache->numentries / (double)cache->maxentries * 100.0, - chainlen, - cache->hits, - cache->fetches, - (cache->fetches > 0 ? (double)(cache->hits) / (double)(cache->fetches) * 100.0 : 100.0), - cache->inserts, - cache->removes); + buf2, + cache->numentries, + (double)cache->numentries / (double)cache->maxentries * 100.0, + chainlen, + cache->hits, + cache->fetches, + (cache->fetches > 0 ? (double)(cache->hits) / (double)(cache->fetches) * 100.0 : 100.0), + cache->inserts, + cache->removes); if (cache->numpurges) { char str_ctime[APR_CTIME_LEN]; apr_ctime(str_ctime, cache->last_purge); buf = apr_psprintf(p, - "%s" - "%lu\n" - "%s\n", - buf, - cache->numpurges, - str_ctime); + "%s" + "%lu\n" + "%s\n", + buf, + cache->numpurges, + str_ctime); } else { buf = apr_psprintf(p, - "%s(none)\n", - buf); + "%s(none)\n", + buf); } buf = apr_psprintf(p, "%s%.2g\n", buf, cache->avg_purgetime); @@ -500,10 +518,16 @@ return buf; } -char *util_ald_cache_display(apr_pool_t *pool, util_ldap_state_t *st) +char *util_ald_cache_display(request_rec *r, util_ldap_state_t *st) { - unsigned long i; + unsigned long i,j; char *buf, *t1, *t2, *t3; + char *id1, *id2, *id3; + char *argfmt = "cache=%s&id=%d&off=%d"; + char *scanfmt = "cache=%4s&id=%u&off=%u%1s"; + apr_pool_t *pool = r->pool; + util_cache_node_t *p; + util_url_node_t *n; util_ald_cache_t *util_ldap_cache = st->util_ldap_cache; @@ -512,30 +536,131 @@ return "Cache has not been enabled/initialised."; } - buf = util_ald_cache_display_stats(pool, st->util_ldap_cache, "LDAP URL Cache"); + if (r->args && strlen(r->args)) { + char cachetype[5], lint[2]; + unsigned int id, off; + int ret; - for (i=0; i < util_ldap_cache->size; ++i) { - util_cache_node_t *p; - for (p = util_ldap_cache->nodes[i]; p != NULL; p = p->next) { - util_url_node_t *n; + if ((3 == sscanf(r->args, scanfmt, cachetype, &id, &off, lint)) && + (id < util_ldap_cache->size)) { + p = util_ldap_cache->nodes[id]; n = (util_url_node_t *)p->payload; - t1 = apr_psprintf(pool, "%s (Searches)", n->url); - t2 = apr_psprintf(pool, "%s (Compares)", n->url); - t3 = apr_psprintf(pool, "%s (DNCompares)", n->url); - - buf = apr_psprintf(pool, "%s\n\n" - "%s\n\n" - "%s\n\n" - "%s\n\n", - buf, - util_ald_cache_display_stats(pool, n->search_cache, t1), - util_ald_cache_display_stats(pool, n->compare_cache, t2), - util_ald_cache_display_stats(pool, n->dn_compare_cache, t3) - ); + ap_rputs(apr_psprintf(r->pool, + "

\n" + "\n" + "\n" + "" + "" + "\n" + "
Cache Name:%s (%s)
\n

\n", + n->url, + cachetype[0] == 's' ? "Search" : (cachetype[0] == 'c' ? "Compares" : "DNCompares")), r); + + switch (cachetype[0]) { + case 's': + ap_rputs("

\n" + "\n" + "\n" + "" + "" + "" + "\n", r + ); + for (i=0; i < n->search_cache->size; ++i) { + for (p = n->search_cache->nodes[i]; p != NULL; p = p->next) { + + (*n->search_cache->display)(r, n->search_cache, p->payload); + } + } + ap_rputs("
LDAP FilterUser NameLast Bind
\n

\n", r); + break; + case 'c': + ap_rputs("

\n" + "\n" + "\n" + "" + "" + "" + "" + "" + "\n", r + ); + for (i=0; i < n->compare_cache->size; ++i) { + for (p = n->compare_cache->nodes[i]; p != NULL; p = p->next) { + + (*n->compare_cache->display)(r, n->compare_cache, p->payload); + } + } + ap_rputs("
DNAttributeValueLast CompareResult
\n

\n", r); + break; + case 'd': + ap_rputs("

\n" + "\n" + "\n" + "" + "" + "\n", r + ); + for (i=0; i < n->dn_compare_cache->size; ++i) { + for (p = n->dn_compare_cache->nodes[i]; p != NULL; p = p->next) { + + (*n->dn_compare_cache->display)(r, n->dn_compare_cache, p->payload); + } + } + ap_rputs("
Require DNActual DN
\n

\n", r); + break; + default: + break; + } + } } + else { + ap_rputs("

\n" + "\n" + "\n" + "" + "" + "" + "" + "" + "" + "" + "\n", r + ); + + + buf = util_ald_cache_display_stats(r, st->util_ldap_cache, "LDAP URL Cache", NULL); + + for (i=0; i < util_ldap_cache->size; ++i) { + for (p = util_ldap_cache->nodes[i],j=0; p != NULL; p = p->next,j++) { + + n = (util_url_node_t *)p->payload; + + t1 = apr_psprintf(pool, "%s (Searches)", n->url); + t2 = apr_psprintf(pool, "%s (Compares)", n->url); + t3 = apr_psprintf(pool, "%s (DNCompares)", n->url); + id1 = apr_psprintf(pool, argfmt, "srch", i, j); + id2 = apr_psprintf(pool, argfmt, "cmpr", i, j); + id3 = apr_psprintf(pool, argfmt, "dncp", i, j); + + buf = apr_psprintf(pool, "%s\n\n" + "%s\n\n" + "%s\n\n" + "%s\n\n", + buf, + util_ald_cache_display_stats(r, n->search_cache, t1, id1), + util_ald_cache_display_stats(r, n->compare_cache, t2, id2), + util_ald_cache_display_stats(r, n->dn_compare_cache, t3, id3) + ); + } + } + ap_rputs(buf, r); + ap_rputs("
Cache NameEntriesAvg. Chain Len.HitsIns/RemPurgesAvg Purge Time
\n

\n", r); + } + return buf; }