summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert James Kaes <rjkaes@users.sourceforge.net>2002-04-09 20:04:39 +0000
committerRobert James Kaes <rjkaes@users.sourceforge.net>2002-04-09 20:04:39 +0000
commit7409281e3412000e9f6a325a2aeef73342b18f88 (patch)
tree0c3a1af5537ee0429960e7c9ef4a8a29aff15602 /src
parent607e4c4c6cd00ca6c164251f9649d9d87d96d05d (diff)
downloadtinyproxy-7409281e3412000e9f6a325a2aeef73342b18f88.tar.gz
tinyproxy-7409281e3412000e9f6a325a2aeef73342b18f88.zip
Replaced the internally used linked list with a call to the hashmap
module. Code reuse is a good thing.
Diffstat (limited to '')
-rw-r--r--src/anonymous.c81
1 files changed, 23 insertions, 58 deletions
diff --git a/src/anonymous.c b/src/anonymous.c
index 0f687f3..fb7b443 100644
--- a/src/anonymous.c
+++ b/src/anonymous.c
@@ -1,8 +1,7 @@
-/* $Id: anonymous.c,v 1.10 2001-12-15 20:02:59 rjkaes Exp $
+/* $Id: anonymous.c,v 1.11 2002-04-09 20:04: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 linked
- * list.
+ * the anonymous feature is turned on.
*
* Copyright (C) 2000 Robert James Kaes (rjkaes@flarenet.com)
*
@@ -20,51 +19,33 @@
#include "tinyproxy.h"
#include "anonymous.h"
+#include "hashmap.h"
#include "log.h"
#include "utils.h"
-/*
- * Structure holding the various anonymous headers.
- */
-struct anonymous_header_s {
- char *header;
- struct anonymous_header_s *next;
-};
-struct anonymous_header_s *anonymous_root = NULL;
+static hashmap_t anonymous_map = NULL;
-inline short int
+short int
is_anonymous_enabled(void)
{
- return (anonymous_root) ? 1 : 0;
+ return (anonymous_map != NULL) ? 1 : 0;
}
/*
- * Search through the linked list for the header. If it's found return 0
+ * Search for the header. If it's found return 0
* else return -1.
*/
int
anonymous_search(char *s)
{
- struct anonymous_header_s *ptr = anonymous_root;
-
assert(s != NULL);
- assert(anonymous_root != NULL);
-
- while (ptr) {
- if (ptr->header) {
- if (strcasecmp(ptr->header, s) == 0)
- return 0;
- } else
- return -1;
-
- ptr = ptr->next;
- }
+ assert(anonymous_map != NULL);
- return -1;
+ return (hashmap_search(anonymous_map, s, NULL) > 0) ? 0 : -1;
}
/*
- * Insert a new header into the linked list.
+ * Insert a new header.
*
* Return -1 if there is an error, 0 if the string already exists, and 1 if
* it's been inserted.
@@ -72,39 +53,23 @@ anonymous_search(char *s)
int
anonymous_insert(char *s)
{
- struct anonymous_header_s *ptr;
- struct anonymous_header_s **prev_ptr;
+ int len;
+ char data = 1;
assert(s != NULL);
- if (!anonymous_root) {
- anonymous_root = safemalloc(sizeof(struct anonymous_header_s));
- if (!anonymous_root)
- return -1;
-
- anonymous_root->header = strdup(s);
- anonymous_root->next = NULL;
- } else {
- ptr = anonymous_root;
-
- while (ptr) {
- if (ptr->header) {
- if (strcasecmp(ptr->header, s) == 0)
- return 0;
- }
-
- prev_ptr = &ptr;
- ptr = ptr->next;
- }
-
- ptr = (*prev_ptr)->next
- = safemalloc(sizeof(struct anonymous_header_s));
- if (!ptr)
+ if (!anonymous_map) {
+ anonymous_map = hashmap_create(32);
+ if (!anonymous_map)
return -1;
+ }
- ptr->header = strdup(s);
- ptr->next = NULL;
+ if (hashmap_search(anonymous_map, s, NULL) > 0) {
+ /* The key was already found, so return a positive number. */
+ return 0;
}
-
- return 1;
+
+ /* Insert the new key */
+ len = hashmap_insert(anonymous_map, s, &data, sizeof(data));
+ return (len == 0) ? 1 : len;
}