Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2d1bbb13be |
No files matched your search
@@ -1,38 +1,5 @@
|
|||||||
2001-08-30 Robert James Kaes <rjkaes@flarenet.com>
|
|
||||||
|
|
||||||
* src/dnscache.c: Removed the insert_data() function and replaced
|
|
||||||
the "replace" logic in dns_insert() with a call to
|
|
||||||
ternary_replace(). This fixes the segmentation fault problem which
|
|
||||||
I introduced when I "tried" to fix the memory leak. Also changed
|
|
||||||
the LOCKing be around the entire dnscache() again since I still
|
|
||||||
need to work out how locking should be done when accessing the
|
|
||||||
ternary tree.
|
|
||||||
|
|
||||||
* src/ternary.c (ternary_insert_replace): Renamed ternary_insert()
|
|
||||||
to ternary_insert_replace() and added a extra argument. The
|
|
||||||
function can now "replace" data already in the tree without
|
|
||||||
causing a memory leak. Added two DEFINES to make coding easier:
|
|
||||||
ternary_insert() and ternary_replace() which both call this
|
|
||||||
function with the right arguments.
|
|
||||||
|
|
||||||
* src/utils.c: Removed xstrstr() since it was only used in once
|
|
||||||
place, and could be safely replaced with strstr. I can't even
|
|
||||||
remember why we had this function to begin with.
|
|
||||||
|
|
||||||
* src/reqs.c (compare_header): Removed the call to xstrstr() since
|
|
||||||
it's been removed from the source.
|
|
||||||
|
|
||||||
2001-08-28 Robert James Kaes <rjkaes@flarenet.com>
|
2001-08-28 Robert James Kaes <rjkaes@flarenet.com>
|
||||||
|
|
||||||
* src/log.c (log_message): Handle a debug enabled compile better.
|
|
||||||
|
|
||||||
* src/dnscache.c (dns_insert): Fixed a memory leak if the same
|
|
||||||
information was inserted into the ternary tree twice.
|
|
||||||
|
|
||||||
* configure.in: Fixed the test regarding the REGEX library. Even
|
|
||||||
if a working REGEX was found on the system, the included REGEX was
|
|
||||||
being compiled in. Double Doh.
|
|
||||||
|
|
||||||
* src/log.c (log_message): Finally got the log levels worked out
|
* src/log.c (log_message): Finally got the log levels worked out
|
||||||
properly. I've tested all the levels and they now produce the
|
properly. I've tested all the levels and they now produce the
|
||||||
correct output.
|
correct output.
|
||||||
|
|||||||
@@ -1,40 +1,38 @@
|
|||||||
Thursday, August 30, 2001
|
|
||||||
-------------------------
|
|
||||||
|
|
||||||
Maybe I just shouldn't be working on the code base this week. The
|
NEWS
|
||||||
memory fix I added in the last release contained a serious bug which
|
====
|
||||||
would cause a segmentation fault. I actually fixed this by removing
|
|
||||||
the code I added and just fixing the problem in ternary_insert()
|
|
||||||
instead. I don't know why I didn't do this in the first place. I also
|
|
||||||
removed the xstrstr() function since strstr() will do what tinyproxy
|
|
||||||
needs. Removing code is _always_ a good idea. Less code, less chance
|
|
||||||
of bugs.
|
|
||||||
|
|
||||||
-- Robert
|
Well so much for the 1.4.0 version being the best tinyproxy---there
|
||||||
|
were bugs. The most serious was a segmentation fault problem when an
|
||||||
|
invalid request was received. Also, anonymous filtering was not
|
||||||
|
actually working. Another bug fix is that on Debian systems (and maybe
|
||||||
|
others) child threads would not be closed if they had been created
|
||||||
|
after tinyproxy had been started. Finally, if MaxClientRequests was
|
||||||
|
set to 0, the status of the thread was not going back to T_WAITING.
|
||||||
|
|
||||||
|
Okay, now on to the new features. There is a new Connect log
|
||||||
|
level. This is basically "Info" without info's noise. Also, the error
|
||||||
|
reporting function sends back more HTTP headers, which should lead to
|
||||||
|
a more standards compliant proxy.
|
||||||
|
|
||||||
Wednesday, August 29, 2001
|
There are a couple of features which I'm working on for the next
|
||||||
--------------------------
|
release. There has been requests for logging on tunnelled
|
||||||
|
connections. Also, some people would like HTTP filtering on tunnelled
|
||||||
|
connections. Finally, I do have the information to include SSL
|
||||||
|
connections, so I will be including it in the next release.
|
||||||
|
|
||||||
There has been a tonne of work done on tinyproxy since the beginning
|
So, the above bugs are fixed, hopefully there are no other ones. The
|
||||||
of last week. I have been releasing minor-minor-minor point releases,
|
new features will be worked into the next few releases.
|
||||||
but the changes in this release constitute a minor-minor point
|
|
||||||
release. Please see the ChangeLog for detail descriptions of all the
|
|
||||||
changes, but here is a brief list.
|
|
||||||
|
|
||||||
The most serious fix is to the DNS caching system. There was a memory
|
Update
|
||||||
leak in the system whenever a domain was already in the database, but
|
------
|
||||||
had expired. The new domain information was placed in the database,
|
2001-08-28 - The log levels _now_ finally work correctly. I have
|
||||||
but the old information wasn't freed.
|
tested all the levels in the configuration file and the logging
|
||||||
|
function now outputs the correct information.
|
||||||
|
|
||||||
The second change is in regard to the regular expression library. For
|
2001-08-27 - Fix one bug and two more crop up. The MIME type was
|
||||||
a while now tinyproxy has included it's own library (the GNU version)
|
incorrect in the httperr() function; this has been fixed.
|
||||||
in case the system did not have a working copy. Due to a bug in the
|
Jeffrey D. Wheelhouse included a patch to increase the stack size on
|
||||||
configure.in script the included REGEX library was being used even if
|
some machine (notably FreeBSD) and also included a patch to allow
|
||||||
a working copy was detected. This was making tinyproxy larger than it
|
tinyproxy to compile on FreeBSD. I really hope that _this_ is that
|
||||||
needed.
|
last minor-minor version for a while.
|
||||||
|
|
||||||
I would suggest that everyone upgrade to this version; especially
|
|
||||||
anyone who is still running 1.4.0 or below.
|
|
||||||
|
|
||||||
-- Robert
|
|
||||||
+25
-25
@@ -1,4 +1,4 @@
|
|||||||
dnl $Id: configure.in,v 1.24 2001-08-30 16:54:04 rjkaes Exp $
|
dnl $Id: configure.in,v 1.21 2001-08-28 15:52:53 rjkaes Exp $
|
||||||
|
|
||||||
dnl Devlopers, please strive to achieve this order:
|
dnl Devlopers, please strive to achieve this order:
|
||||||
dnl
|
dnl
|
||||||
@@ -19,7 +19,7 @@ AC_INIT()
|
|||||||
AC_CANONICAL_SYSTEM
|
AC_CANONICAL_SYSTEM
|
||||||
AC_DEFINE_UNQUOTED(TARGET_SYSTEM, "$target")
|
AC_DEFINE_UNQUOTED(TARGET_SYSTEM, "$target")
|
||||||
|
|
||||||
AM_INIT_AUTOMAKE(tinyproxy,1.4.2.1)
|
AM_INIT_AUTOMAKE(tinyproxy,1.4.1.5)
|
||||||
AM_CONFIG_HEADER(config.h)
|
AM_CONFIG_HEADER(config.h)
|
||||||
|
|
||||||
dnl
|
dnl
|
||||||
@@ -58,7 +58,7 @@ AC_ARG_ENABLE(filter,
|
|||||||
[ --enable-filter Enable filtering of domains/URLs [default=yes]],
|
[ --enable-filter Enable filtering of domains/URLs [default=yes]],
|
||||||
filter_enabled=yes, filter_enabled=yes)
|
filter_enabled=yes, filter_enabled=yes)
|
||||||
if test "$filter_enabled" = "yes"; then
|
if test "$filter_enabled" = "yes"; then
|
||||||
LIBOBJS="filter.o $LIBOBJS"
|
LIBOBJS="$LIBOBJS filter.o"
|
||||||
AC_DEFINE(FILTER_ENABLE)
|
AC_DEFINE(FILTER_ENABLE)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -200,6 +200,27 @@ AC_UNP_CHECK_TYPE(in_addr_t, uint32_t)
|
|||||||
AC_TYPE_PID_T
|
AC_TYPE_PID_T
|
||||||
AC_TYPE_SIGNAL
|
AC_TYPE_SIGNAL
|
||||||
|
|
||||||
|
dnl
|
||||||
|
dnl Compiler characteristics
|
||||||
|
dnl
|
||||||
|
|
||||||
|
dnl Enable the debugging flags (by checking for the GCC compiler)
|
||||||
|
CFLAGS="-Wall $CFLAGS"
|
||||||
|
if test "$enable_debug" = "yes" ; then
|
||||||
|
dnl Add the warnings if we have the GCC compiler
|
||||||
|
if test x$ac_cv_prog_gcc = xyes ; then
|
||||||
|
CFLAGS="-Wshadow -Wcast-qual -Wcast-align -Wstrict-prototypes $CFLAGS"
|
||||||
|
CFLAGS="-Wmissing-prototypes -Wmissing-declarations $CFLAGS"
|
||||||
|
CFLAGS="-Wpointer-arith -Waggregate-return -Wnested-externs $CFLAGS"
|
||||||
|
fi
|
||||||
|
CFLAGS="-DYYDEBUG $CFLAGS"
|
||||||
|
YFLAGS="-v -d"
|
||||||
|
else
|
||||||
|
dnl No debugging information, include the optimizations
|
||||||
|
CFLAGS="-DNDEBUG $CFLAGS"
|
||||||
|
YFLAGS="-d"
|
||||||
|
fi
|
||||||
|
|
||||||
dnl
|
dnl
|
||||||
dnl Checks for functions
|
dnl Checks for functions
|
||||||
dnl
|
dnl
|
||||||
@@ -225,27 +246,6 @@ if test "$ac_cv_func_vprintf" != "yes"; then
|
|||||||
AC_CHECK_FUNC(_doprnt, AC_DEFINE(HAVE_DOPRNT))
|
AC_CHECK_FUNC(_doprnt, AC_DEFINE(HAVE_DOPRNT))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
dnl
|
|
||||||
dnl Compiler characteristics
|
|
||||||
dnl
|
|
||||||
|
|
||||||
dnl Enable the debugging flags (by checking for the GCC compiler)
|
|
||||||
CFLAGS="-Wall $CFLAGS"
|
|
||||||
if test "$enable_debug" = "yes" ; then
|
|
||||||
dnl Add the warnings if we have the GCC compiler
|
|
||||||
if test x$ac_cv_prog_gcc = xyes ; then
|
|
||||||
CFLAGS="-Wshadow -Wcast-qual -Wcast-align -Wstrict-prototypes $CFLAGS"
|
|
||||||
CFLAGS="-Wmissing-prototypes -Wmissing-declarations $CFLAGS"
|
|
||||||
CFLAGS="-Wpointer-arith -Waggregate-return -Wnested-externs $CFLAGS"
|
|
||||||
fi
|
|
||||||
CFLAGS="-DYYDEBUG $CFLAGS"
|
|
||||||
YFLAGS="-v -d"
|
|
||||||
else
|
|
||||||
dnl No debugging information, include the optimizations
|
|
||||||
CFLAGS="-DNDEBUG $CFLAGS"
|
|
||||||
YFLAGS="-d"
|
|
||||||
fi
|
|
||||||
|
|
||||||
dnl
|
dnl
|
||||||
dnl Make sure we can actually handle the "--with-*" and "--enable-*" stuff.
|
dnl Make sure we can actually handle the "--with-*" and "--enable-*" stuff.
|
||||||
dnl
|
dnl
|
||||||
@@ -261,7 +261,7 @@ if test "$socks_enabled" = "yes"; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
dnl Handle the REGEX library
|
dnl Handle the REGEX library
|
||||||
if test "$ac_cv_func_regexec" != "yes"; then
|
if test "$ac_cv_func_regex" != "yes"; then
|
||||||
dnl We don't have a functioning REGEX so include our copy
|
dnl We don't have a functioning REGEX so include our copy
|
||||||
tinyproxy_use_our_regex=yes
|
tinyproxy_use_our_regex=yes
|
||||||
else
|
else
|
||||||
|
|||||||
+18
-40
@@ -1,4 +1,4 @@
|
|||||||
/* $Id: dnscache.c,v 1.11 2001-08-30 16:50:42 rjkaes Exp $
|
/* $Id: dnscache.c,v 1.9 2001-05-27 02:24:00 rjkaes Exp $
|
||||||
*
|
*
|
||||||
* This is a caching DNS system. When a host name is needed we look it up here
|
* This is a caching DNS system. When a host name is needed we look it up here
|
||||||
* and see if there is already an answer for it. The domains are placed in a
|
* and see if there is already an answer for it. The domains are placed in a
|
||||||
@@ -34,14 +34,6 @@
|
|||||||
#include "ternary.h"
|
#include "ternary.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
/*
|
|
||||||
* The mutex is used for locking around accesses to the ternary tree.
|
|
||||||
*/
|
|
||||||
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
||||||
|
|
||||||
#define LOCK() pthread_mutex_lock(&mutex);
|
|
||||||
#define UNLOCK() pthread_mutex_unlock(&mutex);
|
|
||||||
|
|
||||||
#define DNSEXPIRE (5 * 60)
|
#define DNSEXPIRE (5 * 60)
|
||||||
|
|
||||||
struct dnscache_s {
|
struct dnscache_s {
|
||||||
@@ -49,25 +41,30 @@ struct dnscache_s {
|
|||||||
time_t expire;
|
time_t expire;
|
||||||
};
|
};
|
||||||
|
|
||||||
static TERNARY dns_tree = -1;
|
static TERNARY dns_tree;
|
||||||
|
|
||||||
|
TERNARY new_dnscache(void)
|
||||||
|
{
|
||||||
|
dns_tree = ternary_new();
|
||||||
|
|
||||||
|
return dns_tree;
|
||||||
|
}
|
||||||
|
|
||||||
static int dns_lookup(struct in_addr *addr, char *domain)
|
static int dns_lookup(struct in_addr *addr, char *domain)
|
||||||
{
|
{
|
||||||
int ret;
|
|
||||||
struct dnscache_s *ptr;
|
struct dnscache_s *ptr;
|
||||||
|
|
||||||
assert(addr != NULL);
|
assert(addr != NULL);
|
||||||
assert(domain != NULL);
|
assert(domain != NULL);
|
||||||
|
|
||||||
ret = ternary_search(dns_tree, domain, (void *)&ptr);
|
if (TE_ISERROR(ternary_search(dns_tree, domain, (void *)&ptr)))
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (TE_ISERROR(ret)
|
if (difftime(time(NULL), ptr->expire) > (double)DNSEXPIRE) {
|
||||||
|| difftime(time(NULL), ptr->expire) > DNSEXPIRE) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(addr, &ptr->ipaddr, sizeof(struct in_addr));
|
*addr = ptr->ipaddr;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,19 +75,15 @@ static int dns_insert(struct in_addr *addr, char *domain)
|
|||||||
assert(addr != NULL);
|
assert(addr != NULL);
|
||||||
assert(domain != NULL);
|
assert(domain != NULL);
|
||||||
|
|
||||||
DEBUG2("Inserting [%s] into DNS cache", domain);
|
|
||||||
|
|
||||||
if (!(newptr = malloc(sizeof(struct dnscache_s)))) {
|
if (!(newptr = malloc(sizeof(struct dnscache_s)))) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&newptr->ipaddr, addr, sizeof(struct in_addr));
|
newptr->ipaddr = *addr;
|
||||||
newptr->expire = time(NULL);
|
newptr->expire = time(NULL);
|
||||||
|
|
||||||
if (TE_ISERROR(ternary_replace(dns_tree, domain, newptr))) {
|
if (TE_ISERROR(ternary_insert(dns_tree, domain, newptr)))
|
||||||
safefree(newptr);
|
safefree(newptr);
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -102,34 +95,19 @@ int dnscache(struct in_addr *addr, char *domain)
|
|||||||
assert(addr != NULL);
|
assert(addr != NULL);
|
||||||
assert(domain != NULL);
|
assert(domain != NULL);
|
||||||
|
|
||||||
LOCK();
|
if (inet_aton(domain, (struct in_addr *) addr) != 0)
|
||||||
|
|
||||||
/* If the DNS tree doesn't exist, build a new one */
|
|
||||||
if (dns_tree < 0)
|
|
||||||
dns_tree = ternary_new();
|
|
||||||
|
|
||||||
if (inet_aton(domain, (struct in_addr *)addr) != 0) {
|
|
||||||
UNLOCK();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
/* Well, we're not dotted-decimal so we need to look it up */
|
/* Well, we're not dotted-decimal so we need to look it up */
|
||||||
if (dns_lookup(addr, domain) == 0) {
|
if (dns_lookup(addr, domain) == 0)
|
||||||
UNLOCK();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
/* Okay, so not in the list... need to actually look it up. */
|
/* Okay, so not in the list... need to actually look it up. */
|
||||||
if (!(resolv = gethostbyname(domain))) {
|
if (!(resolv = gethostbyname(domain)))
|
||||||
UNLOCK();
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(addr, resolv->h_addr_list[0], (size_t)resolv->h_length);
|
memcpy(addr, resolv->h_addr_list[0], (size_t)resolv->h_length);
|
||||||
|
|
||||||
dns_insert(addr, domain);
|
dns_insert(addr, domain);
|
||||||
|
|
||||||
UNLOCK();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
+4
-2
@@ -1,8 +1,8 @@
|
|||||||
/* $Id: dnscache.h,v 1.5 2001-08-29 03:58:39 rjkaes Exp $
|
/* $Id: dnscache.h,v 1.4 2001-05-27 02:24:00 rjkaes Exp $
|
||||||
*
|
*
|
||||||
* See 'dnscache.c' for a detailed description.
|
* See 'dnscache.c' for a detailed description.
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999 Robert James Kaes (rjkaes@flarenet.com)
|
* Copyright (C) 1999 Robert James Kaes (rjkaes@flarenet.com
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it
|
* 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
|
* under the terms of the GNU General Public License as published by the
|
||||||
@@ -19,7 +19,9 @@
|
|||||||
#define _TINYPROXY_DNSCACHE_H_
|
#define _TINYPROXY_DNSCACHE_H_
|
||||||
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
#include "ternary.h"
|
||||||
|
|
||||||
|
extern TERNARY new_dnscache(void);
|
||||||
extern int dnscache(struct in_addr *addr, char *domain);
|
extern int dnscache(struct in_addr *addr, char *domain);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id: log.c,v 1.13 2001-08-29 03:59:12 rjkaes Exp $
|
/* $Id: log.c,v 1.12 2001-08-28 15:51:58 rjkaes Exp $
|
||||||
*
|
*
|
||||||
* Logs the various messages which tinyproxy produces to either a log file or
|
* Logs the various messages which tinyproxy produces to either a log file or
|
||||||
* the syslog daemon. Not much to it...
|
* the syslog daemon. Not much to it...
|
||||||
@@ -48,7 +48,15 @@ static short int log_level = LOG_ERR;
|
|||||||
*/
|
*/
|
||||||
void set_log_level(short int level)
|
void set_log_level(short int level)
|
||||||
{
|
{
|
||||||
|
#ifndef NDEBUG
|
||||||
|
/*
|
||||||
|
* If we're running with debugging enabled, then set the log level
|
||||||
|
* to DEBUG regardless of what's in the configuration file.
|
||||||
|
*/
|
||||||
|
log_level = LOG_DEBUG;
|
||||||
|
#else
|
||||||
log_level = level;
|
log_level = level;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -65,7 +73,6 @@ void log_message(short int level, char *fmt, ...)
|
|||||||
char str[STRING_LENGTH];
|
char str[STRING_LENGTH];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NDEBUG
|
|
||||||
/*
|
/*
|
||||||
* Figure out if we should write the message or not.
|
* Figure out if we should write the message or not.
|
||||||
*/
|
*/
|
||||||
@@ -76,8 +83,8 @@ void log_message(short int level, char *fmt, ...)
|
|||||||
if (level > LOG_INFO && level != LOG_CONN)
|
if (level > LOG_INFO && level != LOG_CONN)
|
||||||
return;
|
return;
|
||||||
} else if (level > log_level)
|
} else if (level > log_level)
|
||||||
return;
|
return;
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef HAVE_SYSLOG_H
|
#ifdef HAVE_SYSLOG_H
|
||||||
|
|||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
/* $Id: reqs.c,v 1.18 2001-08-30 16:51:10 rjkaes Exp $
|
/* $Id: reqs.c,v 1.17 2001-08-28 04:32:14 rjkaes Exp $
|
||||||
*
|
*
|
||||||
* This is where all the work in tinyproxy is actually done. Incoming
|
* This is where all the work in tinyproxy is actually done. Incoming
|
||||||
* connections have a new thread created for them. The thread then
|
* connections have a new thread created for them. The thread then
|
||||||
@@ -326,7 +326,7 @@ static int compare_header(char *line)
|
|||||||
char *ptr;
|
char *ptr;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if ((ptr = strstr(line, ":")) == NULL)
|
if ((ptr = xstrstr(line, ":", strlen(line), FALSE)) == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if ((buffer = malloc(ptr - line + 1)) == NULL)
|
if ((buffer = malloc(ptr - line + 1)) == NULL)
|
||||||
|
|||||||
+18
-10
@@ -1,4 +1,4 @@
|
|||||||
/* $Id: sock.c,v 1.6 2001-08-29 04:00:22 rjkaes Exp $
|
/* $Id: sock.c,v 1.5 2001-05-27 02:31:20 rjkaes Exp $
|
||||||
*
|
*
|
||||||
* Sockets are created and destroyed here. When a new connection comes in from
|
* Sockets are created and destroyed here. When a new connection comes in from
|
||||||
* a client, we need to copy the socket and the create a second socket to the
|
* a client, we need to copy the socket and the create a second socket to the
|
||||||
@@ -29,14 +29,16 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The mutex is used for locking around any calls which access global
|
* The mutex is used for locking around the calls to the dnscache since I
|
||||||
* variables.
|
* don't want multiple threads accessing the linked list at the same time.
|
||||||
|
* This should be more fine grained, but it will do for now.
|
||||||
* - rjkaes
|
* - rjkaes
|
||||||
*/
|
*/
|
||||||
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t sock_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
|
#define SOCK_LOCK() pthread_mutex_lock(&sock_mutex);
|
||||||
|
#define SOCK_UNLOCK() pthread_mutex_unlock(&sock_mutex);
|
||||||
|
|
||||||
#define LOCK() pthread_mutex_lock(&mutex);
|
|
||||||
#define UNLOCK() pthread_mutex_unlock(&mutex);
|
|
||||||
|
|
||||||
/* This routine is so old I can't even remember writing it. But I do
|
/* This routine is so old I can't even remember writing it. But I do
|
||||||
* remember that it was an .h file because I didn't know putting code in a
|
* remember that it was an .h file because I didn't know putting code in a
|
||||||
@@ -62,8 +64,13 @@ int opensock(char *ip_addr, uint16_t port)
|
|||||||
|
|
||||||
port_info.sin_family = AF_INET;
|
port_info.sin_family = AF_INET;
|
||||||
|
|
||||||
/* Lookup and return the address if possible */
|
/* chris - Could block; neet to ensure that this is never called
|
||||||
|
* before a non-blocking DNS query happens for this address. Not
|
||||||
|
* relevant in the code as it stands.
|
||||||
|
*/
|
||||||
|
SOCK_LOCK();
|
||||||
ret = dnscache(&port_info.sin_addr, ip_addr);
|
ret = dnscache(&port_info.sin_addr, ip_addr);
|
||||||
|
SOCK_UNLOCK();
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
log_message(LOG_ERR, "opensock: Could not lookup address: %s", ip_addr);
|
log_message(LOG_ERR, "opensock: Could not lookup address: %s", ip_addr);
|
||||||
@@ -187,13 +194,14 @@ char *getpeer_string(int fd, char *string)
|
|||||||
if (getpeername(fd, (struct sockaddr *)&name, &namelen) != 0) {
|
if (getpeername(fd, (struct sockaddr *)&name, &namelen) != 0) {
|
||||||
log_message(LOG_ERR, "Connect: 'could not get peer name'");
|
log_message(LOG_ERR, "Connect: 'could not get peer name'");
|
||||||
} else {
|
} else {
|
||||||
LOCK();
|
SOCK_LOCK();
|
||||||
peername = gethostbyaddr((char *)&name.sin_addr.s_addr,
|
peername = gethostbyaddr((char *)&name.sin_addr.s_addr,
|
||||||
sizeof(name.sin_addr.s_addr),
|
sizeof(name.sin_addr.s_addr),
|
||||||
AF_INET);
|
AF_INET);
|
||||||
if (peername)
|
if (peername) {
|
||||||
strlcpy(string, peername->h_name, PEER_STRING_LENGTH);
|
strlcpy(string, peername->h_name, PEER_STRING_LENGTH);
|
||||||
UNLOCK();
|
}
|
||||||
|
SOCK_UNLOCK();
|
||||||
}
|
}
|
||||||
|
|
||||||
return string;
|
return string;
|
||||||
|
|||||||
+3
-10
@@ -1,4 +1,4 @@
|
|||||||
/* $Id: ternary.c,v 1.6 2001-08-30 16:52:09 rjkaes Exp $
|
/* $Id: ternary.c,v 1.5 2001-05-23 17:59:53 rjkaes Exp $
|
||||||
*
|
*
|
||||||
* This module creates a Ternary Search Tree which can store both string
|
* This module creates a Ternary Search Tree which can store both string
|
||||||
* keys, and arbitrary data for each key. It works similar to a hash, and
|
* keys, and arbitrary data for each key. It works similar to a hash, and
|
||||||
@@ -294,8 +294,7 @@ int ternary_destroy(TERNARY tno, void (*freeptr)(void *))
|
|||||||
* TE_TOOFULL tree is full, so no new elements can be added.
|
* TE_TOOFULL tree is full, so no new elements can be added.
|
||||||
* Exceptions: none
|
* Exceptions: none
|
||||||
*/
|
*/
|
||||||
int ternary_insert_replace(TERNARY tno, const char *s, void *data,
|
int ternary_insert(TERNARY tno, const char *s, void *data)
|
||||||
short int replace)
|
|
||||||
{
|
{
|
||||||
int cur; /* index of current tree */
|
int cur; /* index of current tree */
|
||||||
Ttree *tree; /* pointer to tree structure */
|
Ttree *tree; /* pointer to tree structure */
|
||||||
@@ -315,13 +314,7 @@ int ternary_insert_replace(TERNARY tno, const char *s, void *data,
|
|||||||
while ((pp = *p)) {
|
while ((pp = *p)) {
|
||||||
if ((d = *s - pp->splitchar) == 0) {
|
if ((d = *s - pp->splitchar) == 0) {
|
||||||
if (*s++ == 0) {
|
if (*s++ == 0) {
|
||||||
if (!replace)
|
return TE_EXISTS;
|
||||||
return TE_EXISTS;
|
|
||||||
else {
|
|
||||||
free(pp->eqkid);
|
|
||||||
pp->eqkid = (Tnode *)data;
|
|
||||||
return TE_NONE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
p = &(pp->eqkid);
|
p = &(pp->eqkid);
|
||||||
} else if (d < 0)
|
} else if (d < 0)
|
||||||
|
|||||||
+2
-6
@@ -1,4 +1,4 @@
|
|||||||
/* $Id: ternary.h,v 1.3 2001-08-30 16:52:09 rjkaes Exp $
|
/* $Id: ternary.h,v 1.2 2000-09-26 04:59:20 rjkaes Exp $
|
||||||
*
|
*
|
||||||
* See 'ternary.c' for a detailed description.
|
* See 'ternary.c' for a detailed description.
|
||||||
*
|
*
|
||||||
@@ -58,11 +58,7 @@ extern char te_errbuf[256];
|
|||||||
extern TERNARY ternary_new(void);
|
extern TERNARY ternary_new(void);
|
||||||
extern int ternary_destroy(TERNARY tno, void (*freeptr)(void *));
|
extern int ternary_destroy(TERNARY tno, void (*freeptr)(void *));
|
||||||
|
|
||||||
#define ternary_insert(x, y, z) ternary_insert_replace(x, y, z, 0)
|
extern int ternary_insert(TERNARY tno, const char *s, void *data);
|
||||||
#define ternary_replace(x, y, z) ternary_insert_replace(x, y, z, 1)
|
|
||||||
|
|
||||||
extern int ternary_insert_replace(TERNARY tno, const char *s, void *data,
|
|
||||||
short int replace);
|
|
||||||
extern int ternary_search(TERNARY tno, const char *s, void **data);
|
extern int ternary_search(TERNARY tno, const char *s, void **data);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
+8
-1
@@ -1,4 +1,4 @@
|
|||||||
/* $Id: tinyproxy.c,v 1.13 2001-08-29 04:01:05 rjkaes Exp $
|
/* $Id: tinyproxy.c,v 1.12 2001-08-26 21:17:30 rjkaes Exp $
|
||||||
*
|
*
|
||||||
* The initialise routine. Basically sets up all the initial stuff (logfile,
|
* The initialise routine. Basically sets up all the initial stuff (logfile,
|
||||||
* listening socket, config options, etc.) and then sits there and loops
|
* listening socket, config options, etc.) and then sits there and loops
|
||||||
@@ -347,6 +347,13 @@ int main(int argc, char **argv)
|
|||||||
exit(EX_OSERR);
|
exit(EX_OSERR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Initialize the various subsystems...
|
||||||
|
*/
|
||||||
|
log_message(LOG_INFO, "Starting the DNS caching subsystem.");
|
||||||
|
if (!new_dnscache())
|
||||||
|
exit(EX_SOFTWARE);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Start the main loop.
|
* Start the main loop.
|
||||||
*/
|
*/
|
||||||
|
|||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
/* $Id: tinyproxy.h,v 1.13 2001-08-29 04:04:01 rjkaes Exp $
|
/* $Id: tinyproxy.h,v 1.12 2001-08-27 17:46:20 rjkaes Exp $
|
||||||
*
|
*
|
||||||
* See 'tinyproxy.c' for a detailed description.
|
* See 'tinyproxy.c' for a detailed description.
|
||||||
*
|
*
|
||||||
@@ -70,7 +70,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Global variables for the main controls of the program */
|
/* Global variables for the main controls of the program */
|
||||||
#define MAXBUFFSIZE ((size_t)(1024 * 48)) /* Max size of buffer */
|
#define MAXBUFFSIZE (size_t)(1024 * 48) /* Max size of buffer */
|
||||||
#define MAXLISTEN 1024 /* Max number of connections */
|
#define MAXLISTEN 1024 /* Max number of connections */
|
||||||
#define MAX_IDLE_TIME (60 * 10) /* 10 minutes of no activity */
|
#define MAX_IDLE_TIME (60 * 10) /* 10 minutes of no activity */
|
||||||
|
|
||||||
|
|||||||
+29
-1
@@ -1,4 +1,4 @@
|
|||||||
/* $Id: utils.c,v 1.8 2001-08-30 16:52:56 rjkaes Exp $
|
/* $Id: utils.c,v 1.7 2001-08-28 04:33:54 rjkaes Exp $
|
||||||
*
|
*
|
||||||
* Misc. routines which are used by the various functions to handle strings
|
* Misc. routines which are used by the various functions to handle strings
|
||||||
* and memory allocation and pretty much anything else we can think of. Also,
|
* and memory allocation and pretty much anything else we can think of. Also,
|
||||||
@@ -30,6 +30,34 @@
|
|||||||
#include "sock.h"
|
#include "sock.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Find the start of the needle in the haystack. Limits the search to less
|
||||||
|
* than "length" characters. Returns NULL if the needle is not found.
|
||||||
|
*/
|
||||||
|
char *xstrstr(char *haystack, char *needle, size_t length,
|
||||||
|
bool_t case_sensitive)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
/* Used to specify which function to use... need the decl. */
|
||||||
|
int (*fn) (const char *s1, const char *s2, size_t n);
|
||||||
|
|
||||||
|
if (case_sensitive)
|
||||||
|
fn = strncmp;
|
||||||
|
else
|
||||||
|
fn = strncasecmp;
|
||||||
|
|
||||||
|
if (strlen(needle) > length)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
for (i = 0; i <= length - strlen(needle); i++) {
|
||||||
|
if ((*fn) (haystack + i, needle, strlen(needle)) == 0)
|
||||||
|
return (haystack + i);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Display an error to the client.
|
* Display an error to the client.
|
||||||
*/
|
*/
|
||||||
|
|||||||
+4
-1
@@ -1,4 +1,4 @@
|
|||||||
/* $Id: utils.h,v 1.6 2001-08-30 16:52:56 rjkaes Exp $
|
/* $Id: utils.h,v 1.5 2001-08-27 03:45:34 rjkaes Exp $
|
||||||
*
|
*
|
||||||
* See 'utils.h' for a detailed description.
|
* See 'utils.h' for a detailed description.
|
||||||
*
|
*
|
||||||
@@ -21,6 +21,9 @@
|
|||||||
|
|
||||||
#include "tinyproxy.h"
|
#include "tinyproxy.h"
|
||||||
|
|
||||||
|
extern char *xstrstr(char *haystack, char *needle, size_t length,
|
||||||
|
bool_t case_sensitive);
|
||||||
|
|
||||||
extern int httperr(struct conn_s *connptr, int err, const char *msg);
|
extern int httperr(struct conn_s *connptr, int err, const char *msg);
|
||||||
|
|
||||||
extern void makedaemon(void);
|
extern void makedaemon(void);
|
||||||
|
|||||||
Reference in new issue
Block a user