From 849345e88bd3bdb2bde1e531a3815308dc3e7bf0 Mon Sep 17 00:00:00 2001 From: Robert James Kaes Date: Sun, 26 Aug 2001 21:07:27 +0000 Subject: Removed the anon_new() function and moved it's functionality into anonymous_insert(). Also renamed all the anon_* functions to anonymous_* function. --- src/anonymous.c | 38 ++++++++++++++++++++++++++++++-------- src/anonymous.h | 8 ++++---- 2 files changed, 34 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/anonymous.c b/src/anonymous.c index a03347d..4463080 100644 --- a/src/anonymous.c +++ b/src/anonymous.c @@ -1,4 +1,4 @@ -/* $Id: anonymous.c,v 1.5 2001-05-27 02:21:37 rjkaes Exp $ +/* $Id: anonymous.c,v 1.6 2001-08-26 21:07:27 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 @@ -29,26 +29,48 @@ #include #include "anonymous.h" +#include "log.h" #include "ternary.h" +#include "tinyproxy.h" -static TERNARY anonymous_tree; +static TERNARY anonymous_tree = 0; +/* + * Keep track of whether the Anonymous filtering is enabled. Off by + * default. + */ +static short int anonymous_is_enabled = 0; -TERNARY new_anonymous(void) +short int is_anonymous_enabled(void) { - anonymous_tree = ternary_new(); - return anonymous_tree; + return anonymous_is_enabled; } -int anon_search(char *s) +int anonymous_search(char *s) { assert(s != NULL); + assert(anonymous_is_enabled == 1); + assert(anonymous_tree > 0); return ternary_search(anonymous_tree, s, NULL); } -void anon_insert(char *s) +int anonymous_insert(char *s) { assert(s != NULL); - ternary_insert(anonymous_tree, s, NULL); + /* + * If this is the first time we're inserting a word, create the + * search tree. + */ + if (!anonymous_is_enabled) { + anonymous_tree = ternary_new(); + if (anonymous_tree < 0) + return -1; + + anonymous_is_enabled = 1; + + DEBUG1("Starting the Anonymous header subsytem."); + } + + return ternary_insert(anonymous_tree, s, NULL); } diff --git a/src/anonymous.h b/src/anonymous.h index cf7eec6..f6ba5f0 100644 --- a/src/anonymous.h +++ b/src/anonymous.h @@ -1,4 +1,4 @@ -/* $Id: anonymous.h,v 1.4 2001-05-27 02:21:37 rjkaes Exp $ +/* $Id: anonymous.h,v 1.5 2001-08-26 21:07:27 rjkaes Exp $ * * See 'anonymous.c' for a detailed description. * @@ -20,8 +20,8 @@ #include "ternary.h" -extern TERNARY new_anonymous(void); -extern int anon_search(char *s); -extern void anon_insert(char *s); +extern short int is_anonymous_enabled(void); +extern int anonymous_search(char *s); +extern int anonymous_insert(char *s); #endif -- cgit v1.2.3