2001-12-16 04:02:59 +08:00
|
|
|
/* $Id: anonymous.c,v 1.10 2001-12-15 20:02:59 rjkaes Exp $
|
2000-04-01 03:56:55 +08:00
|
|
|
*
|
|
|
|
* Handles insertion and searches for headers which should be let through when
|
2001-12-16 04:02:59 +08:00
|
|
|
* the anonymous feature is turned on. The headers are stored in a linked
|
|
|
|
* list.
|
2000-04-01 03:56:55 +08:00
|
|
|
*
|
|
|
|
* 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"
|
2001-12-16 04:02:59 +08:00
|
|
|
#include "utils.h"
|
2000-04-01 03:56:55 +08:00
|
|
|
|
2001-08-27 05:07:27 +08:00
|
|
|
/*
|
2001-12-16 04:02:59 +08:00
|
|
|
* Structure holding the various anonymous headers.
|
2001-08-27 05:07:27 +08:00
|
|
|
*/
|
2001-12-16 04:02:59 +08:00
|
|
|
struct anonymous_header_s {
|
|
|
|
char *header;
|
|
|
|
struct anonymous_header_s *next;
|
|
|
|
};
|
|
|
|
struct anonymous_header_s *anonymous_root = NULL;
|
2000-04-01 03:56:55 +08:00
|
|
|
|
2001-11-22 08:31:10 +08:00
|
|
|
inline short int
|
|
|
|
is_anonymous_enabled(void)
|
2000-10-24 05:43:52 +08:00
|
|
|
{
|
2001-12-16 04:02:59 +08:00
|
|
|
return (anonymous_root) ? 1 : 0;
|
2000-10-24 05:43:52 +08:00
|
|
|
}
|
|
|
|
|
2001-12-16 04:02:59 +08:00
|
|
|
/*
|
|
|
|
* Search through the linked list for the header. If it's found return 0
|
|
|
|
* else return -1.
|
|
|
|
*/
|
2001-11-22 08:31:10 +08:00
|
|
|
int
|
|
|
|
anonymous_search(char *s)
|
2000-04-01 03:56:55 +08:00
|
|
|
{
|
2001-12-16 04:02:59 +08:00
|
|
|
struct anonymous_header_s *ptr = anonymous_root;
|
|
|
|
|
2001-05-24 02:01:23 +08:00
|
|
|
assert(s != NULL);
|
2001-12-16 04:02:59 +08:00
|
|
|
assert(anonymous_root != NULL);
|
2001-05-24 02:01:23 +08:00
|
|
|
|
2001-12-16 04:02:59 +08:00
|
|
|
while (ptr) {
|
|
|
|
if (ptr->header) {
|
|
|
|
if (strcasecmp(ptr->header, s) == 0)
|
|
|
|
return 0;
|
|
|
|
} else
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
ptr = ptr->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
2000-04-01 03:56:55 +08:00
|
|
|
}
|
|
|
|
|
2001-12-16 04:02:59 +08:00
|
|
|
/*
|
|
|
|
* Insert a new header into the linked list.
|
|
|
|
*
|
|
|
|
* Return -1 if there is an error, 0 if the string already exists, and 1 if
|
|
|
|
* it's been inserted.
|
|
|
|
*/
|
2001-11-22 08:31:10 +08:00
|
|
|
int
|
|
|
|
anonymous_insert(char *s)
|
2000-04-01 03:56:55 +08:00
|
|
|
{
|
2001-12-16 04:02:59 +08:00
|
|
|
struct anonymous_header_s *ptr;
|
|
|
|
struct anonymous_header_s **prev_ptr;
|
|
|
|
|
2001-05-24 02:01:23 +08:00
|
|
|
assert(s != NULL);
|
|
|
|
|
2001-12-16 04:02:59 +08:00
|
|
|
if (!anonymous_root) {
|
|
|
|
anonymous_root = safemalloc(sizeof(struct anonymous_header_s));
|
|
|
|
if (!anonymous_root)
|
2001-08-27 05:07:27 +08:00
|
|
|
return -1;
|
|
|
|
|
2001-12-16 04:02:59 +08:00
|
|
|
anonymous_root->header = strdup(s);
|
|
|
|
anonymous_root->next = NULL;
|
|
|
|
} else {
|
|
|
|
ptr = anonymous_root;
|
2001-08-27 05:07:27 +08:00
|
|
|
|
2001-12-16 04:02:59 +08:00
|
|
|
while (ptr) {
|
|
|
|
if (ptr->header) {
|
|
|
|
if (strcasecmp(ptr->header, s) == 0)
|
|
|
|
return 0;
|
|
|
|
}
|
2001-08-27 05:07:27 +08:00
|
|
|
|
2001-12-16 04:02:59 +08:00
|
|
|
prev_ptr = &ptr;
|
|
|
|
ptr = ptr->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr = (*prev_ptr)->next
|
|
|
|
= safemalloc(sizeof(struct anonymous_header_s));
|
|
|
|
if (!ptr)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
ptr->header = strdup(s);
|
|
|
|
ptr->next = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
2000-04-01 03:56:55 +08:00
|
|
|
}
|