2001-11-05 23:24:42 +08:00
|
|
|
/* $Id: anonymous.c,v 1.8 2001-11-05 15:24:42 rjkaes Exp $
|
2000-04-01 03:56:55 +08:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Search Tree. The initial code came from Dr. Dobb's Journal, April 1998
|
|
|
|
* "Ternary Search Trees", Jon Bentley and Bob Sedgewick, pg 20-25.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2000 Robert James Kaes (rjkaes@flarenet.com)
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
* later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
2001-10-26 01:27:39 +08:00
|
|
|
#include "tinyproxy.h"
|
2000-04-01 03:56:55 +08:00
|
|
|
|
|
|
|
#include "anonymous.h"
|
2001-08-27 05:07:27 +08:00
|
|
|
#include "log.h"
|
2000-09-12 07:38:36 +08:00
|
|
|
#include "ternary.h"
|
2001-08-27 05:07:27 +08:00
|
|
|
#include "tinyproxy.h"
|
2000-04-01 03:56:55 +08:00
|
|
|
|
2001-08-27 05:07:27 +08:00
|
|
|
static TERNARY anonymous_tree = 0;
|
|
|
|
/*
|
|
|
|
* Keep track of whether the Anonymous filtering is enabled. Off by
|
|
|
|
* default.
|
|
|
|
*/
|
|
|
|
static short int anonymous_is_enabled = 0;
|
2000-04-01 03:56:55 +08:00
|
|
|
|
2001-11-05 23:24:42 +08:00
|
|
|
inline short int is_anonymous_enabled(void)
|
2000-10-24 05:43:52 +08:00
|
|
|
{
|
2001-08-27 05:07:27 +08:00
|
|
|
return anonymous_is_enabled;
|
2000-10-24 05:43:52 +08:00
|
|
|
}
|
|
|
|
|
2001-08-27 05:07:27 +08:00
|
|
|
int anonymous_search(char *s)
|
2000-04-01 03:56:55 +08:00
|
|
|
{
|
2001-05-24 02:01:23 +08:00
|
|
|
assert(s != NULL);
|
2001-08-27 05:07:27 +08:00
|
|
|
assert(anonymous_is_enabled == 1);
|
|
|
|
assert(anonymous_tree > 0);
|
2001-05-24 02:01:23 +08:00
|
|
|
|
2000-09-12 07:38:36 +08:00
|
|
|
return ternary_search(anonymous_tree, s, NULL);
|
2000-04-01 03:56:55 +08:00
|
|
|
}
|
|
|
|
|
2001-08-27 05:07:27 +08:00
|
|
|
int anonymous_insert(char *s)
|
2000-04-01 03:56:55 +08:00
|
|
|
{
|
2001-05-24 02:01:23 +08:00
|
|
|
assert(s != NULL);
|
|
|
|
|
2001-08-27 05:07:27 +08:00
|
|
|
/*
|
|
|
|
* 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);
|
2000-04-01 03:56:55 +08:00
|
|
|
}
|