Compare commits

..
1 Commits
13 changed files with 122 additions and 246 deletions

No files matched your search

-38
View File
@@ -1,41 +1,3 @@
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
properly. I've tested all the levels and they now produce the
correct output.
2001-08-27 Robert James Kaes <rjkaes@flarenet.com>
* src/reqs.c (trim): Moved the trim functionality out of
process_request() and added a test to make sure we don't back the
pointer past the beginning of the string.
* src/log.c (log_message): Fixed a problem where the connect
messages were not getting through if the log level was set to
INFO.
* src/tinyproxy.h: Moved some of the includes around so that
tinyproxy can compile correctly on FreeBSD systems.
* src/thread.c: Added the pthread_attr_t structure since we're
going to be using a non-default sized stack because some OS's have
a stack size which is too small.
* configure.in: Added a test for detecting FreeBSD's -pthread
mechanism for telling GCC to use POSIX threading.
* src/utils.c (httperr): Fixed the MIME type. Should be be
text/html, not text/mime. Fix one bug, add two new ones. Sigh.
2001-08-26 Robert James Kaes <rjkaes@flarenet.com> 2001-08-26 Robert James Kaes <rjkaes@flarenet.com>
* src/utils.c (httperr): Split the headers from the actual message * src/utils.c (httperr): Split the headers from the actual message
+20 -20
View File
@@ -1,25 +1,25 @@
Wednesday, August 29, 2001
--------------------------
There has been a tonne of work done on tinyproxy since the beginning NEWS
of last week. I have been releasing minor-minor-minor point 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 Well so much for the 1.4.0 version being the best tinyproxy---there
leak in the system whenever a domain was already in the database, but were bugs. The most serious was a segmentation fault problem when an
had expired. The new domain information was placed in the database, invalid request was received. Also, anonymous filtering was not
but the old information wasn't freed. 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.
The second change is in regard to the regular expression library. For Okay, now on to the new features. There is a new Connect log
a while now tinyproxy has included it's own library (the GNU version) level. This is basically "Info" without info's noise. Also, the error
in case the system did not have a working copy. Due to a bug in the reporting function sends back more HTTP headers, which should lead to
configure.in script the included REGEX library was being used even if a more standards compliant proxy.
a working copy was detected. This was making tinyproxy larger than it
needed.
I would suggest that everyone upgrade to this version; especially There are a couple of features which I'm working on for the next
anyone who is still running 1.4.0 or below. 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.
-- Robert So, the above bugs are fixed, hopefully there are no other ones. The
new features will be worked into the next few releases.
+26 -31
View File
@@ -1,4 +1,4 @@
dnl $Id: configure.in,v 1.23 2001-08-29 15:29:29 rjkaes Exp $ dnl $Id: configure.in,v 1.18 2001-08-27 03:47:47 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) AM_INIT_AUTOMAKE(tinyproxy,1.4.1.3)
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
@@ -106,12 +106,7 @@ else
if test "$ac_cv_lib_pthreads_pthread_create" = "yes"; then if test "$ac_cv_lib_pthreads_pthread_create" = "yes"; then
CFLAGS="-D_REENTRANT $CFLAGS" CFLAGS="-D_REENTRANT $CFLAGS"
else else
AC_CHECK_LIB(c_r, pthread_create) AC_MSG_ERROR(You must have a POSIX compliant threading library installed)
if test "$ac_cv_lib_c_r_pthread_create" = "yes"; then
CFLAGS="-pthread -D_REENTRANT $CFLAGS"
else
AC_MSG_ERROR(You must have a POSIX compliant threading library installed)
fi
fi fi
fi fi
@@ -200,6 +195,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 +241,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 +256,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
+1 -1
View File
@@ -116,4 +116,4 @@ Allow 192.168.1.0/25
# no Anonymous keyword is present, then all header are allowed through. # no Anonymous keyword is present, then all header are allowed through.
# #
#Anonymous Host #Anonymous Host
#Anonymous Authorization #Anonymous Authorization
+14 -78
View File
@@ -1,4 +1,4 @@
/* $Id: dnscache.c,v 1.10 2001-08-29 03:57:51 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,94 +41,49 @@ struct dnscache_s {
time_t expire; time_t expire;
}; };
static TERNARY dns_tree = -1; static TERNARY dns_tree;
/* TERNARY new_dnscache(void)
* Insert the data into the DNS tree.
*/
static int insert_data(char *domain, struct dnscache_s *newptr)
{ {
int ret; dns_tree = ternary_new();
LOCK();
ret = ternary_insert(dns_tree, domain, newptr);
UNLOCK();
return ret; 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);
LOCK(); if (TE_ISERROR(ternary_search(dns_tree, domain, (void *)&ptr)))
ret = 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) {
UNLOCK();
return -1; return -1;
} }
memcpy(addr, &ptr->ipaddr, sizeof(struct in_addr)); *addr = ptr->ipaddr;
UNLOCK();
return 0; return 0;
} }
static int dns_insert(struct in_addr *addr, char *domain) static int dns_insert(struct in_addr *addr, char *domain)
{ {
struct dnscache_s *newptr; struct dnscache_s *newptr;
int ret;
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);
ret = insert_data(domain, newptr); if (TE_ISERROR(ternary_insert(dns_tree, domain, newptr)))
safefree(newptr);
if (TE_ISERROR(ret)) {
if (ret == TE_EXISTS) {
/*
* The value already exists. First search for the
* value and then delete the data before inserting
* the new value.
*/
struct dnscache_s *existing;
DEBUG2("[%s] already exists in DNS cache", domain);
LOCK();
ret = ternary_search(dns_tree, domain, (void *)&existing);
UNLOCK();
if (TE_ISERROR(ret))
goto INSERT_ERROR;
safefree(existing);
ret = insert_data(domain, newptr);
if (TE_ISERROR(ret))
goto INSERT_ERROR;
} else {
INSERT_ERROR:
safefree(newptr);
return -1;
}
}
return 0; return 0;
} }
@@ -148,13 +95,7 @@ int dnscache(struct in_addr *addr, char *domain)
assert(addr != NULL); assert(addr != NULL);
assert(domain != NULL); assert(domain != NULL);
/* If the DNS tree doesn't exist, build a new one */ if (inet_aton(domain, (struct in_addr *) addr) != 0)
LOCK();
if (dns_tree < 0)
dns_tree = ternary_new();
UNLOCK();
if (inet_aton(domain, (struct in_addr *)addr) != 0)
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 */
@@ -162,15 +103,10 @@ int dnscache(struct in_addr *addr, char *domain)
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. */
LOCK(); 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);
UNLOCK();
dns_insert(addr, domain); dns_insert(addr, domain);
return 0; return 0;
+4 -2
View File
@@ -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
+14 -12
View File
@@ -1,4 +1,4 @@
/* $Id: log.c,v 1.13 2001-08-29 03:59:12 rjkaes Exp $ /* $Id: log.c,v 1.10 2001-08-26 23:37:26 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,20 +73,14 @@ 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.
*/ */
if (log_level == LOG_CONN) { if (level == LOG_INFO && log_level == LOG_CONN)
if (level == LOG_INFO) return;
return;
} else if (log_level == LOG_INFO) { if (level > log_level)
if (level > LOG_INFO && level != LOG_CONN) return;
return;
} else if (level > log_level)
return;
#endif
#ifdef HAVE_SYSLOG_H #ifdef HAVE_SYSLOG_H
if (config.syslog && level == LOG_CONN) if (config.syslog && level == LOG_CONN)
+6 -26
View File
@@ -1,10 +1,10 @@
/* $Id: reqs.c,v 1.17 2001-08-28 04:32:14 rjkaes Exp $ /* $Id: reqs.c,v 1.16 2001-08-27 03:44:22 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
* processes the headers from the client, the response from the server, * processes the headers from the client, the response from the server,
* and then relays the bytes between the two. * and then relays the bytes between the two.
* If TUNNEL_SUPPORT is enabled, then tinyproxy will actually work * If the UPSTEAM_PROXY is enabled, then tinyproxy will actually work
* as a simple buffering TCP tunnel. Very cool! (Robert actually uses * as a simple buffering TCP tunnel. Very cool! (Robert actually uses
* this feature for a buffering NNTP tunnel.) * this feature for a buffering NNTP tunnel.)
* *
@@ -81,29 +81,6 @@ static ssize_t safe_read(int fd, void *buffer, size_t count)
return len; return len;
} }
/*
* Remove any new lines or carriage returns from the end of a string.
*/
static inline void trim(char *string, unsigned int len)
{
char *ptr;
assert(string != NULL);
assert(len > 0);
ptr = string + len - 1;
while (*ptr == '\r' || *ptr == '\n') {
*ptr-- = '\0';
/*
* Don't let the ptr back past the beginning of the
* string.
*/
if (ptr < string)
return;
}
}
/* /*
* Parse a client HTTP request and then establish connection. * Parse a client HTTP request and then establish connection.
*/ */
@@ -112,6 +89,7 @@ static int process_method(struct conn_s *connptr)
URI *uri = NULL; URI *uri = NULL;
char inbuf[LINE_LENGTH]; char inbuf[LINE_LENGTH];
char *buffer = NULL, *request = NULL, *port = NULL; char *buffer = NULL, *request = NULL, *port = NULL;
char *inbuf_ptr = NULL;
regex_t preg; regex_t preg;
regmatch_t pmatch[NMATCH]; regmatch_t pmatch[NMATCH];
@@ -134,7 +112,9 @@ static int process_method(struct conn_s *connptr)
/* /*
* Strip the newline and character return from the string. * Strip the newline and character return from the string.
*/ */
trim(inbuf, len); inbuf_ptr = inbuf + len - 1;
while (*inbuf_ptr == '\r' || *inbuf_ptr == '\n')
*inbuf_ptr-- = '\0';
log_message(LOG_CONN, "Request: %s", inbuf); log_message(LOG_CONN, "Request: %s", inbuf);
+18 -10
View File
@@ -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 -19
View File
@@ -1,4 +1,4 @@
/* $Id: thread.c,v 1.8 2001-08-28 04:33:21 rjkaes Exp $ /* $Id: thread.c,v 1.6 2001-08-26 21:14:30 rjkaes Exp $
* *
* Handles the creation/destruction of the various threads required for * Handles the creation/destruction of the various threads required for
* processing incoming connections. * processing incoming connections.
@@ -23,12 +23,6 @@
#include "sock.h" #include "sock.h"
#include "thread.h" #include "thread.h"
/*
* This is the stack frame size used by all the threads. We'll start by
* setting it to 128 KB.
*/
#define THREAD_STACK_SIZE (1024 * 128)
static int listenfd; static int listenfd;
static socklen_t addrlen; static socklen_t addrlen;
@@ -48,9 +42,6 @@ struct thread_s {
static struct thread_s *thread_ptr; static struct thread_s *thread_ptr;
static pthread_mutex_t mlock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t mlock = PTHREAD_MUTEX_INITIALIZER;
/* Used to override the default statck size. */
static pthread_attr_t thread_attr;
static struct thread_config_s { static struct thread_config_s {
unsigned int maxclients, maxrequestsperchild; unsigned int maxclients, maxrequestsperchild;
unsigned int maxspareservers, minspareservers, startservers; unsigned int maxspareservers, minspareservers, startservers;
@@ -155,13 +146,6 @@ int thread_pool_create(void)
{ {
unsigned int i; unsigned int i;
/*
* Initialize thread_attr to contain a non-default stack size
* because the default on some OS's is too small.
*/
pthread_attr_init(&thread_attr);
pthread_attr_setstacksize(&thread_attr, THREAD_STACK_SIZE);
if (thread_config.maxclients == 0) { if (thread_config.maxclients == 0) {
log_message(LOG_ERR, "You must set MaxClients to a value greater than 0"); log_message(LOG_ERR, "You must set MaxClients to a value greater than 0");
return -1; return -1;
@@ -183,7 +167,7 @@ int thread_pool_create(void)
for (i = 0; i < thread_config.startservers; i++) { for (i = 0; i < thread_config.startservers; i++) {
thread_ptr[i].status = T_WAITING; thread_ptr[i].status = T_WAITING;
servers_waiting++; servers_waiting++;
pthread_create(&thread_ptr[i].tid, &thread_attr, &thread_main, &thread_ptr[i]); pthread_create(&thread_ptr[i].tid, NULL, &thread_main, &thread_ptr[i]);
} }
for (i = thread_config.startservers; i < thread_config.maxclients; i++) { for (i = thread_config.startservers; i < thread_config.maxclients; i++) {
thread_ptr[i].status = T_EMPTY; thread_ptr[i].status = T_EMPTY;
@@ -205,7 +189,7 @@ int thread_main_loop(void)
if (servers_waiting < thread_config.minspareservers) { if (servers_waiting < thread_config.minspareservers) {
for (i = 0; i < thread_config.maxclients; i++) { for (i = 0; i < thread_config.maxclients; i++) {
if (thread_ptr[i].status == T_EMPTY) { if (thread_ptr[i].status == T_EMPTY) {
pthread_create(&thread_ptr[i].tid, &thread_attr, &thread_main, &thread_ptr[i]); pthread_create(&thread_ptr[i].tid, NULL, &thread_main, &thread_ptr[i]);
thread_ptr[i].status = T_WAITING; thread_ptr[i].status = T_WAITING;
thread_ptr[i].connects = 0; thread_ptr[i].connects = 0;
+8 -1
View File
@@ -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.
*/ */
+4 -4
View File
@@ -1,4 +1,4 @@
/* $Id: tinyproxy.h,v 1.13 2001-08-29 04:04:01 rjkaes Exp $ /* $Id: tinyproxy.h,v 1.11 2001-08-26 21:18:04 rjkaes Exp $
* *
* See 'tinyproxy.c' for a detailed description. * See 'tinyproxy.c' for a detailed description.
* *
@@ -26,7 +26,6 @@
/* /*
* Include standard headers which are used through-out tinyproxy * Include standard headers which are used through-out tinyproxy
*/ */
#include <sys/types.h>
#ifdef HAVE_SYS_SELECT_H #ifdef HAVE_SYS_SELECT_H
# include <sys/select.h> # include <sys/select.h>
#endif #endif
@@ -42,9 +41,10 @@
# include <time.h> # include <time.h>
# endif # endif
#endif #endif
#include <sys/types.h>
#include <sys/uio.h> #include <sys/uio.h>
#include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <netinet/in.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <netdb.h> #include <netdb.h>
@@ -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 */
+4 -4
View File
@@ -1,4 +1,4 @@
/* $Id: utils.c,v 1.7 2001-08-28 04:33:54 rjkaes Exp $ /* $Id: utils.c,v 1.5 2001-08-27 03:45:34 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,
@@ -68,7 +68,7 @@ int httperr(struct conn_s *connptr, int err, const char *msg)
"HTTP/1.0 %d %s\r\n" \ "HTTP/1.0 %d %s\r\n" \
"Server: %s/%s\r\n" \ "Server: %s/%s\r\n" \
"Date: %s\r\n" \ "Date: %s\r\n" \
"Content-Type: text/html\r\n" \ "Content-Type: text/mime\r\n" \
"Content-Length: %d\r\n" \ "Content-Length: %d\r\n" \
"Connection: close\r\n" \ "Connection: close\r\n" \
"\r\n"; "\r\n";
@@ -79,8 +79,8 @@ int httperr(struct conn_s *connptr, int err, const char *msg)
"<font size=\"+2\">Cache Error!</font><br>\r\n" \ "<font size=\"+2\">Cache Error!</font><br>\r\n" \
"An error of type %d occurred: %s\r\n" \ "An error of type %d occurred: %s\r\n" \
"<hr>\r\n" \ "<hr>\r\n" \
"<font size=\"-1\"><em>Generated by %s (%s)</em></font>\r\n" \ "<font size=\"-1\"><em>Generated by %s/%s</em></font>\r\n" \
"</body></html>\r\n\r\n"; "</body></html>\r\n";
char *header_buffer; char *header_buffer;
char *message_buffer; char *message_buffer;