From 55185db499b1d7c6340d78edb223e26f3c5e5c72 Mon Sep 17 00:00:00 2001 From: Robert James Kaes Date: Mon, 11 Sep 2000 23:38:36 +0000 Subject: Removed the ternary tree code from these files and made it a separate module. --- src/anonymous.c | 58 ++++++++++++++------------------------------------------- src/anonymous.h | 6 +++--- 2 files changed, 17 insertions(+), 47 deletions(-) diff --git a/src/anonymous.c b/src/anonymous.c index a7684d8..76db940 100644 --- a/src/anonymous.c +++ b/src/anonymous.c @@ -1,4 +1,4 @@ -/* $Id: anonymous.c,v 1.1 2000-03-31 19:56:55 rjkaes Exp $ +/* $Id: anonymous.c,v 1.2 2000-09-11 23:38:36 rjkaes Exp $ * * Handles insertion and searches for headers which should be let through when * the anonymous feature is turned on. The headers are stored in a Ternary @@ -19,60 +19,30 @@ */ #ifdef HAVE_CONFIG_H -#include +# include #endif -#include +#include #include +#include +#include #include "anonymous.h" +#include "ternary.h" -typedef struct tnode *Tptr; -typedef struct tnode { - char splitchar; - Tptr lokid, eqkid, hikid; -} Tnode; - -static Tptr anon_root = NULL; - -static Tptr intern_insert(Tptr p, char *s) -{ - if (p == NULL) { - p = (Tptr) malloc(sizeof(Tnode)); - p->splitchar = tolower(*s); - p->lokid = p->eqkid = p->hikid = NULL; - } - - if (tolower(*s) < p->splitchar) - p->lokid = intern_insert(p->lokid, s); - else if (tolower(*s) == p->splitchar) { - if (tolower(*s) != 0) - p->eqkid = intern_insert(p->eqkid, ++s); - } else - p->hikid = intern_insert(p->hikid, s); - - return p; -} +static TERNARY anonymous_tree; int anon_search(char *s) { - Tptr p = anon_root; - - while (p) { - if (tolower(*s) < p->splitchar) - p = p->lokid; - else if (tolower(*s) == p->splitchar) { - if (*s++ == 0) - return 1; - p = p->eqkid; - } else - p = p->hikid; - } - - return 0; + return ternary_search(anonymous_tree, s, NULL); } void anon_insert(char *s) { - anon_root = intern_insert(anon_root, s); + if (anonymous_tree == 0) { + if (TE_ISERROR(anonymous_tree = ternary_new())) + return; + } + + ternary_insert(anonymous_tree, s, NULL); } diff --git a/src/anonymous.h b/src/anonymous.h index 399d6b1..81feb45 100644 --- a/src/anonymous.h +++ b/src/anonymous.h @@ -1,4 +1,4 @@ -/* $Id: anonymous.h,v 1.1 2000-03-31 19:56:55 rjkaes Exp $ +/* $Id: anonymous.h,v 1.2 2000-09-11 23:38:36 rjkaes Exp $ * * See 'anonymous.c' for a detailed description. * @@ -15,8 +15,8 @@ * General Public License for more details. */ -#ifndef ANONYMOUS_C -#define ANONYMOUS_C +#ifndef _TINYPROXY_ANONYMOUS_H_ +#define _TINYPROXY_ANONYMOUS_H_ extern int anon_search(char *s); extern void anon_insert(char *s); -- cgit v1.2.3