2008-05-24 16:05:49 +08:00
|
|
|
/* tinyproxy - A fast light-weight HTTP proxy
|
|
|
|
* Copyright (C) 2000 Robert James Kaes <rjkaes@users.sourceforge.net>
|
2000-04-01 03:56:55 +08:00
|
|
|
*
|
2008-05-24 16:05:49 +08:00
|
|
|
* 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 of the License, or
|
|
|
|
* (at your option) any later version.
|
2000-04-01 03:56:55 +08:00
|
|
|
*
|
2008-05-24 16:05:49 +08:00
|
|
|
* 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.
|
2000-04-01 03:56:55 +08:00
|
|
|
*
|
2008-05-24 16:05:49 +08:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Handles insertion and searches for headers which should be let through
|
|
|
|
* when the anonymous feature is turned on.
|
2000-04-01 03:56:55 +08:00
|
|
|
*/
|
|
|
|
|
2001-10-26 01:27:39 +08:00
|
|
|
#include "tinyproxy.h"
|
2000-04-01 03:56:55 +08:00
|
|
|
|
|
|
|
#include "anonymous.h"
|
2002-04-10 04:04:39 +08:00
|
|
|
#include "hashmap.h"
|
2002-05-24 02:20:27 +08:00
|
|
|
#include "heap.h"
|
2001-08-27 05:07:27 +08:00
|
|
|
#include "log.h"
|
2000-04-01 03:56:55 +08:00
|
|
|
|
2002-04-10 04:04:39 +08:00
|
|
|
static hashmap_t anonymous_map = NULL;
|
2000-04-01 03:56:55 +08:00
|
|
|
|
2002-04-10 04:04:39 +08:00
|
|
|
short int
|
2008-12-01 23:01:11 +08:00
|
|
|
is_anonymous_enabled (void)
|
2000-10-24 05:43:52 +08:00
|
|
|
{
|
2008-12-01 23:01:11 +08:00
|
|
|
return (anonymous_map != NULL) ? 1 : 0;
|
2000-10-24 05:43:52 +08:00
|
|
|
}
|
|
|
|
|
2001-12-16 04:02:59 +08:00
|
|
|
/*
|
2002-04-16 11:19:19 +08:00
|
|
|
* Search for the header. This function returns a positive value greater than
|
|
|
|
* zero if the string was found, zero if it wasn't and negative upon error.
|
2001-12-16 04:02:59 +08:00
|
|
|
*/
|
2001-11-22 08:31:10 +08:00
|
|
|
int
|
2008-12-01 23:01:11 +08:00
|
|
|
anonymous_search (char *s)
|
2000-04-01 03:56:55 +08:00
|
|
|
{
|
2008-12-01 23:01:11 +08:00
|
|
|
assert (s != NULL);
|
|
|
|
assert (anonymous_map != NULL);
|
2001-12-16 04:02:59 +08:00
|
|
|
|
2008-12-01 23:01:11 +08:00
|
|
|
return hashmap_search (anonymous_map, s);
|
2000-04-01 03:56:55 +08:00
|
|
|
}
|
|
|
|
|
2001-12-16 04:02:59 +08:00
|
|
|
/*
|
2002-04-10 04:04:39 +08:00
|
|
|
* Insert a new header.
|
2001-12-16 04:02:59 +08:00
|
|
|
*
|
2002-04-16 11:19:19 +08:00
|
|
|
* Return -1 if there is an error, otherwise a 0 is returned if the insert was
|
|
|
|
* successful.
|
2001-12-16 04:02:59 +08:00
|
|
|
*/
|
2001-11-22 08:31:10 +08:00
|
|
|
int
|
2008-12-01 23:01:11 +08:00
|
|
|
anonymous_insert (char *s)
|
2000-04-01 03:56:55 +08:00
|
|
|
{
|
2008-12-01 23:01:11 +08:00
|
|
|
char data = 1;
|
2001-12-16 04:02:59 +08:00
|
|
|
|
2008-12-01 23:01:11 +08:00
|
|
|
assert (s != NULL);
|
2001-05-24 02:01:23 +08:00
|
|
|
|
2008-12-01 23:01:11 +08:00
|
|
|
if (!anonymous_map)
|
|
|
|
{
|
|
|
|
anonymous_map = hashmap_create (32);
|
|
|
|
if (!anonymous_map)
|
2008-12-08 21:39:44 +08:00
|
|
|
return -1;
|
2008-12-01 23:01:11 +08:00
|
|
|
}
|
2001-12-16 04:02:59 +08:00
|
|
|
|
2008-12-01 23:01:11 +08:00
|
|
|
if (hashmap_search (anonymous_map, s) > 0)
|
|
|
|
{
|
|
|
|
/* The key was already found, so return a positive number. */
|
|
|
|
return 0;
|
|
|
|
}
|
2002-04-10 04:04:39 +08:00
|
|
|
|
2008-12-01 23:01:11 +08:00
|
|
|
/* Insert the new key */
|
|
|
|
return hashmap_insert (anonymous_map, s, &data, sizeof (data));
|
2000-04-01 03:56:55 +08:00
|
|
|
}
|