summaryrefslogtreecommitdiffhomepage
path: root/src/anonymous.c
blob: f1bf4e6e7cce8322f3402268c017f83791b08245 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* $Id: anonymous.c,v 1.7 2001-10-25 17:27:39 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
 * 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.
 */

#include "tinyproxy.h"

#include "anonymous.h"
#include "log.h"
#include "ternary.h"
#include "tinyproxy.h"

static TERNARY anonymous_tree = 0;
/*
 * Keep track of whether the Anonymous filtering is enabled. Off by
 * default.
 */
static short int anonymous_is_enabled = 0;

short int is_anonymous_enabled(void)
{
	return anonymous_is_enabled;
}

int anonymous_search(char *s)
{
	assert(s != NULL);
	assert(anonymous_is_enabled == 1);
	assert(anonymous_tree > 0);

	return ternary_search(anonymous_tree, s, NULL);
}

int anonymous_insert(char *s)
{
	assert(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);
}