summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/anonymous.c58
-rw-r--r--src/anonymous.h6
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 <defines.h>
+# include <config.h>
#endif
-#include <stdlib.h>
+#include <sys/types.h>
#include <ctype.h>
+#include <stdlib.h>
+#include <unistd.h>
#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);