Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed0473f070 |
No files matched your search
@@ -1,34 +1,5 @@
|
||||
2002-04-28 Robert James Kaes <rjkaes@flarenet.com>
|
||||
|
||||
* src/reqs.c (process_client_headers):
|
||||
(process_server_headers): Added more error checking code and
|
||||
send HTTP errors back to the client to let them know what is
|
||||
happening.
|
||||
(handle_connection): If there was a server error when processing
|
||||
the headers, send an error back to the client.
|
||||
|
||||
2002-04-27 Robert James Kaes <rjkaes@flarenet.com>
|
||||
|
||||
* src/thread.c (thread_pool_create): Set the thread's status
|
||||
_before_ the thread is created. Thanks to Hans-Georg Bork for
|
||||
solving this problem.
|
||||
(thread_main): Fixed up the status setting code. Removed
|
||||
duplicated code and explicitly set the status when needed.
|
||||
|
||||
Fixed up all the code checking the return value from the pthread
|
||||
functions. These functions return 0 if OK, but a _positive_ error
|
||||
code.
|
||||
|
||||
2002-04-26 Robert James Kaes <rjkaes@flarenet.com>
|
||||
|
||||
* src/thread.c: servers_waiting needs to be signed, since it can
|
||||
go below 0 without causing a problem, but if it wraps around all
|
||||
hell can break loose.
|
||||
|
||||
* src/reqs.c (connect_to_tunnel): Changed the len type to an
|
||||
signed integer so that we can detect error conditions. Thanks to
|
||||
Tom Cross for pointing out this problem.
|
||||
|
||||
* src/log.c (send_stored_logs): Check the return value of
|
||||
hashmap_first() since it could be -1, indicating an empty hashmap.
|
||||
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
dnl $Id: configure.ac,v 2.23 2002-04-29 16:32:20 rjkaes Exp $
|
||||
dnl $Id: configure.ac,v 2.22 2002-04-26 16:59:44 rjkaes Exp $
|
||||
|
||||
dnl Devlopers, please strive to achieve this order:
|
||||
dnl
|
||||
@@ -14,7 +14,7 @@ dnl 8. System services
|
||||
dnl
|
||||
dnl Read the Autoconf manual for details.
|
||||
|
||||
AC_INIT([tinyproxy], [1.5.0rc7], [rjkaes@users.sourceforge.net])
|
||||
AC_INIT([tinyproxy], [1.5.0rc6], [rjkaes@users.sourceforge.net])
|
||||
AC_CONFIG_SRCDIR([src/tinyproxy.c])
|
||||
AC_PREREQ(2.52)
|
||||
|
||||
|
||||
+35
-69
@@ -1,4 +1,4 @@
|
||||
/* $Id: reqs.c,v 1.70 2002-04-28 20:03:18 rjkaes Exp $
|
||||
/* $Id: reqs.c,v 1.68 2002-04-26 16:43:20 rjkaes Exp $
|
||||
*
|
||||
* This is where all the work in tinyproxy is actually done. Incoming
|
||||
* connections have a new thread created for them. The thread then
|
||||
@@ -108,6 +108,7 @@ static int
|
||||
check_allowed_connect_ports(int port)
|
||||
{
|
||||
ssize_t i;
|
||||
ssize_t ret;
|
||||
int *data;
|
||||
|
||||
/*
|
||||
@@ -118,7 +119,8 @@ check_allowed_connect_ports(int port)
|
||||
return 1;
|
||||
|
||||
for (i = 0; i < vector_length(ports_allowed_by_connect); ++i) {
|
||||
if (vector_getentry(ports_allowed_by_connect, i, (void **)&data) < 0)
|
||||
ret = vector_getentry(ports_allowed_by_connect, i, (void **)&data);
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
|
||||
if (*data == port)
|
||||
@@ -653,14 +655,13 @@ get_content_length(hashmap_t hashofheaders)
|
||||
* FIXME: Need to add code to "hide" our internal information for security
|
||||
* purposes.
|
||||
*/
|
||||
static int
|
||||
static void
|
||||
write_via_header(int fd, hashmap_t hashofheaders,
|
||||
unsigned int major, unsigned int minor)
|
||||
{
|
||||
ssize_t len;
|
||||
char hostname[128];
|
||||
char *data;
|
||||
int ret;
|
||||
|
||||
gethostname(hostname, sizeof(hostname));
|
||||
|
||||
@@ -670,21 +671,19 @@ write_via_header(int fd, hashmap_t hashofheaders,
|
||||
*/
|
||||
len = hashmap_entry_by_key(hashofheaders, "via", (void **)&data);
|
||||
if (len > 0) {
|
||||
ret = write_message(fd,
|
||||
"Via: %s, %hu.%hu %s (%s/%s)\r\n",
|
||||
data,
|
||||
major, minor,
|
||||
hostname, PACKAGE, VERSION);
|
||||
write_message(fd,
|
||||
"Via: %s, %hu.%hu %s (%s/%s)\r\n",
|
||||
data,
|
||||
major, minor,
|
||||
hostname, PACKAGE, VERSION);
|
||||
|
||||
hashmap_remove(hashofheaders, "via");
|
||||
} else {
|
||||
ret = write_message(fd,
|
||||
"Via: %hu.%hu %s (%s/%s)\r\n",
|
||||
major, minor,
|
||||
hostname, PACKAGE, VERSION);
|
||||
write_message(fd,
|
||||
"Via: %hu.%hu %s (%s/%s)\r\n",
|
||||
major, minor,
|
||||
hostname, PACKAGE, VERSION);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -715,7 +714,6 @@ process_client_headers(struct conn_s *connptr)
|
||||
hashmap_t hashofheaders;
|
||||
hashmap_iter iter;
|
||||
long content_length = -1;
|
||||
int ret;
|
||||
|
||||
char *data, *header;
|
||||
|
||||
@@ -728,7 +726,9 @@ process_client_headers(struct conn_s *connptr)
|
||||
*/
|
||||
if (get_all_headers(connptr->client_fd, hashofheaders) < 0) {
|
||||
log_message(LOG_WARNING, "Could not retrieve all the headers from the client");
|
||||
goto ERROR_EXIT;
|
||||
|
||||
hashmap_delete(hashofheaders);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -763,14 +763,8 @@ process_client_headers(struct conn_s *connptr)
|
||||
}
|
||||
|
||||
/* Send, or add the Via header */
|
||||
ret = write_via_header(connptr->server_fd, hashofheaders,
|
||||
connptr->protocol.major,
|
||||
connptr->protocol.minor);
|
||||
if (ret < 0) {
|
||||
indicate_http_error(connptr, 503,
|
||||
"Could not send data to remote server.");
|
||||
goto PULL_CLIENT_DATA;
|
||||
}
|
||||
write_via_header(connptr->server_fd, hashofheaders,
|
||||
connptr->protocol.major, connptr->protocol.minor);
|
||||
|
||||
/*
|
||||
* Output all the remaining headers to the remote machine.
|
||||
@@ -784,43 +778,32 @@ process_client_headers(struct conn_s *connptr)
|
||||
(void**)&header);
|
||||
|
||||
if (!is_anonymous_enabled() || anonymous_search(data) <= 0) {
|
||||
ret = write_message(connptr->server_fd,
|
||||
"%s: %s\r\n",
|
||||
data, header);
|
||||
if (ret < 0) {
|
||||
indicate_http_error(connptr,
|
||||
503,
|
||||
"Could not send data to remove server.");
|
||||
goto PULL_CLIENT_DATA;
|
||||
}
|
||||
write_message(connptr->server_fd,
|
||||
"%s: %s\r\n",
|
||||
data, header);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Free the hashofheaders since it's no longer needed */
|
||||
hashmap_delete(hashofheaders);
|
||||
|
||||
#if defined(XTINYPROXY_ENABLE)
|
||||
if (config.my_domain)
|
||||
add_xtinyproxy_header(connptr);
|
||||
#endif
|
||||
|
||||
/* Write the final "blank" line to signify the end of the headers */
|
||||
if (safe_write(connptr->server_fd, "\r\n", 2) < 0)
|
||||
return -1;
|
||||
safe_write(connptr->server_fd, "\r\n", 2);
|
||||
|
||||
/*
|
||||
* Spin here pulling the data from the client.
|
||||
*/
|
||||
PULL_CLIENT_DATA:
|
||||
hashmap_delete(hashofheaders);
|
||||
|
||||
if (content_length > 0)
|
||||
return pull_client_data(connptr,
|
||||
(unsigned long int) content_length);
|
||||
else
|
||||
return ret;
|
||||
|
||||
ERROR_EXIT:
|
||||
hashmap_delete(hashofheaders);
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -844,7 +827,6 @@ process_server_headers(struct conn_s *connptr)
|
||||
char *data, *header;
|
||||
ssize_t len;
|
||||
int i;
|
||||
int ret;
|
||||
|
||||
/* FIXME: Remember to handle a "simple_req" type */
|
||||
|
||||
@@ -865,16 +847,12 @@ process_server_headers(struct conn_s *connptr)
|
||||
log_message(LOG_WARNING, "Could not retrieve all the headers from the remote server.");
|
||||
hashmap_delete(hashofheaders);
|
||||
safefree(response_line);
|
||||
|
||||
indicate_http_error(connptr, 503, "Could not retrieve all the headers from the remote server.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Send the saved response line first */
|
||||
ret = safe_write(connptr->client_fd, response_line, strlen(response_line));
|
||||
safe_write(connptr->client_fd, response_line, strlen(response_line));
|
||||
safefree(response_line);
|
||||
if (ret < 0)
|
||||
goto ERROR_EXIT;
|
||||
|
||||
/*
|
||||
* If there is a "Content-Length" header, retrieve the information
|
||||
@@ -896,10 +874,8 @@ process_server_headers(struct conn_s *connptr)
|
||||
}
|
||||
|
||||
/* Send, or add the Via header */
|
||||
ret = write_via_header(connptr->client_fd, hashofheaders,
|
||||
connptr->protocol.major, connptr->protocol.minor);
|
||||
if (ret < 0)
|
||||
goto ERROR_EXIT;
|
||||
write_via_header(connptr->client_fd, hashofheaders,
|
||||
connptr->protocol.major, connptr->protocol.minor);
|
||||
|
||||
/*
|
||||
* Okay, output all the remaining headers to the client.
|
||||
@@ -912,24 +888,17 @@ process_server_headers(struct conn_s *connptr)
|
||||
&data,
|
||||
(void **)&header);
|
||||
|
||||
ret = write_message(connptr->client_fd,
|
||||
"%s: %s\r\n",
|
||||
data, header);
|
||||
if (ret < 0)
|
||||
goto ERROR_EXIT;
|
||||
write_message(connptr->client_fd,
|
||||
"%s: %s\r\n",
|
||||
data, header);
|
||||
}
|
||||
}
|
||||
hashmap_delete(hashofheaders);
|
||||
|
||||
/* Write the final blank line to signify the end of the headers */
|
||||
if (safe_write(connptr->client_fd, "\r\n", 2) < 0)
|
||||
return -1;
|
||||
safe_write(connptr->client_fd, "\r\n", 2);
|
||||
|
||||
return 0;
|
||||
|
||||
ERROR_EXIT:
|
||||
hashmap_delete(hashofheaders);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1108,7 +1077,7 @@ static int
|
||||
connect_to_tunnel(struct conn_s *connptr)
|
||||
{
|
||||
char *request_buf;
|
||||
ssize_t len;
|
||||
size_t len;
|
||||
int pos;
|
||||
|
||||
request_buf = safemalloc(HTTP_LINE_LENGTH);
|
||||
@@ -1245,9 +1214,6 @@ handle_connection(int fd)
|
||||
|
||||
if (!connptr->connect_method || UPSTREAM_CONFIGURED()) {
|
||||
if (process_server_headers(connptr) < 0) {
|
||||
if (connptr->error_string)
|
||||
send_http_error_message(connptr);
|
||||
|
||||
update_stats(STAT_BADCONN);
|
||||
destroy_conn(connptr);
|
||||
return;
|
||||
|
||||
+44
-61
@@ -1,4 +1,4 @@
|
||||
/* $Id: thread.c,v 1.29 2002-04-28 18:32:16 rjkaes Exp $
|
||||
/* $Id: thread.c,v 1.26 2002-04-22 19:41:17 rjkaes Exp $
|
||||
*
|
||||
* Handles the creation/destruction of the various threads required for
|
||||
* processing incoming connections.
|
||||
@@ -66,7 +66,7 @@ static struct thread_config_s {
|
||||
unsigned int maxspareservers, minspareservers, startservers;
|
||||
} thread_config;
|
||||
|
||||
static int servers_waiting = 0; /* servers waiting for a connection */
|
||||
static unsigned int servers_waiting; /* servers waiting for a connection */
|
||||
static pthread_mutex_t servers_mutex;
|
||||
|
||||
#define SERVER_COUNT_LOCK() do { \
|
||||
@@ -80,15 +80,15 @@ assert(servers_mutex_ret == 0); \
|
||||
|
||||
#define SERVER_INC() do { \
|
||||
SERVER_COUNT_LOCK(); \
|
||||
DEBUG2("INC: servers_waiting: %u", servers_waiting); \
|
||||
++servers_waiting; \
|
||||
DEBUG2("INC: servers_waiting: %d", servers_waiting); \
|
||||
SERVER_COUNT_UNLOCK(); \
|
||||
} while (0)
|
||||
|
||||
#define SERVER_DEC() do { \
|
||||
SERVER_COUNT_LOCK(); \
|
||||
--servers_waiting; \
|
||||
DEBUG2("DEC: servers_waiting: %d", servers_waiting); \
|
||||
DEBUG2("DEC: servers_waiting: %u", servers_waiting); \
|
||||
SERVER_COUNT_UNLOCK(); \
|
||||
} while (0)
|
||||
|
||||
@@ -144,11 +144,7 @@ thread_main(void *arg)
|
||||
if (!cliaddr)
|
||||
return NULL;
|
||||
|
||||
ptr->connects = 0;
|
||||
|
||||
while (!config.quit) {
|
||||
ptr->status = T_WAITING;
|
||||
|
||||
clilen = addrlen;
|
||||
|
||||
/*
|
||||
@@ -194,31 +190,34 @@ thread_main(void *arg)
|
||||
ptr->connects,
|
||||
thread_config.maxrequestsperchild);
|
||||
|
||||
ptr->status = T_EMPTY;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SERVER_COUNT_LOCK();
|
||||
if (servers_waiting > thread_config.maxspareservers) {
|
||||
if (servers_waiting >= thread_config.maxspareservers) {
|
||||
/*
|
||||
* There are too many spare threads, kill ourself
|
||||
* off.
|
||||
*/
|
||||
log_message(LOG_NOTICE,
|
||||
"Waiting servers (%d) exceeds MaxSpareServers (%d). Killing thread.",
|
||||
servers_waiting, thread_config.maxspareservers);
|
||||
SERVER_COUNT_UNLOCK();
|
||||
|
||||
log_message(LOG_NOTICE,
|
||||
"Waiting servers exceeds MaxSpareServers. Killing thread.");
|
||||
|
||||
ptr->status = T_EMPTY;
|
||||
|
||||
break;
|
||||
} else {
|
||||
SERVER_COUNT_UNLOCK();
|
||||
}
|
||||
SERVER_COUNT_UNLOCK();
|
||||
|
||||
ptr->status = T_WAITING;
|
||||
|
||||
SERVER_INC();
|
||||
}
|
||||
|
||||
ptr->status = T_EMPTY;
|
||||
|
||||
safefree(cliaddr);
|
||||
return NULL;
|
||||
}
|
||||
@@ -231,9 +230,7 @@ thread_pool_create(void)
|
||||
{
|
||||
unsigned int i;
|
||||
int pthread_ret;
|
||||
#if 0
|
||||
pthread_mutexattr_t mutexattr;
|
||||
#endif
|
||||
// pthread_mutexattr_t mutexattr;
|
||||
|
||||
/*
|
||||
* Initialize thread_attr to contain a non-default stack size
|
||||
@@ -245,9 +242,7 @@ thread_pool_create(void)
|
||||
pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
|
||||
pthread_attr_setstacksize(&thread_attr, THREAD_STACK_SIZE);
|
||||
|
||||
#if 0
|
||||
pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_ERRORCHECK);
|
||||
#endif
|
||||
// pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_ERRORCHECK);
|
||||
pthread_mutex_init(&mlock, NULL);
|
||||
pthread_mutex_init(&servers_mutex, NULL);
|
||||
|
||||
@@ -262,12 +257,11 @@ thread_pool_create(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
thread_ptr = safecalloc((size_t) thread_config.maxclients,
|
||||
sizeof(struct thread_s));
|
||||
if (!thread_ptr) {
|
||||
log_message(LOG_ERR, "Could not allocate memory for threads.");
|
||||
thread_ptr =
|
||||
safecalloc((size_t) thread_config.maxclients,
|
||||
sizeof(struct thread_s));
|
||||
if (!thread_ptr)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (thread_config.startservers > thread_config.maxclients) {
|
||||
log_message(LOG_WARNING,
|
||||
@@ -276,33 +270,24 @@ thread_pool_create(void)
|
||||
thread_config.startservers = thread_config.maxclients;
|
||||
}
|
||||
|
||||
for (i = 0; i < thread_config.maxclients; i++) {
|
||||
for (i = 0; i < thread_config.startservers; i++) {
|
||||
pthread_ret = pthread_create(&thread_ptr[i].tid, &thread_attr,
|
||||
&thread_main, &thread_ptr[i]);
|
||||
if (pthread_ret < 0) {
|
||||
log_message(LOG_WARNING, "Could not create thread number %d of %d: %s",
|
||||
i, thread_config.startservers, strerror(errno));
|
||||
return -1;
|
||||
} else {
|
||||
thread_ptr[i].status = T_WAITING;
|
||||
}
|
||||
}
|
||||
servers_waiting = thread_config.startservers;
|
||||
|
||||
for (i = thread_config.startservers; i < thread_config.maxclients; i++) {
|
||||
thread_ptr[i].status = T_EMPTY;
|
||||
thread_ptr[i].connects = 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < thread_config.startservers; i++) {
|
||||
DEBUG2("Trying to create thread %d of %d", i + 1, thread_config.startservers);
|
||||
thread_ptr[i].status = T_WAITING;
|
||||
pthread_ret = pthread_create(&thread_ptr[i].tid, &thread_attr,
|
||||
&thread_main, &thread_ptr[i]);
|
||||
if (pthread_ret != 0) {
|
||||
log_message(LOG_WARNING,
|
||||
"Could not create thread number %d of %d: %s",
|
||||
i, thread_config.startservers,
|
||||
strerror(pthread_ret));
|
||||
return -1;
|
||||
} else {
|
||||
log_message(LOG_INFO,
|
||||
"Creating thread number %d of %d ...",
|
||||
i + 1, thread_config.startservers);
|
||||
|
||||
SERVER_INC();
|
||||
}
|
||||
}
|
||||
|
||||
log_message(LOG_INFO, "Finished creating all threads.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -323,36 +308,34 @@ thread_main_loop(void)
|
||||
/* If there are not enough spare servers, create more */
|
||||
SERVER_COUNT_LOCK();
|
||||
if (servers_waiting < thread_config.minspareservers) {
|
||||
log_message(LOG_NOTICE,
|
||||
"Waiting servers (%d) is less than MinSpareServers (%d). Creating new thread.",
|
||||
servers_waiting, thread_config.minspareservers);
|
||||
|
||||
SERVER_COUNT_UNLOCK();
|
||||
|
||||
for (i = 0; i < thread_config.maxclients; i++) {
|
||||
if (thread_ptr[i].status == T_EMPTY) {
|
||||
thread_ptr[i].status = T_WAITING;
|
||||
pthread_ret = pthread_create(&thread_ptr[i].tid,
|
||||
&thread_attr,
|
||||
&thread_main,
|
||||
&thread_ptr[i]);
|
||||
if (pthread_ret != 0) {
|
||||
if (pthread_ret < 0) {
|
||||
log_message(LOG_NOTICE,
|
||||
"Could not create thread: %s",
|
||||
strerror(pthread_ret));
|
||||
|
||||
thread_ptr[i].status = T_EMPTY;
|
||||
strerror(errno));
|
||||
break;
|
||||
}
|
||||
|
||||
thread_ptr[i].status = T_WAITING;
|
||||
thread_ptr[i].connects = 0;
|
||||
|
||||
SERVER_INC();
|
||||
|
||||
log_message(LOG_NOTICE,
|
||||
"Waiting servers is less than MinSpareServers. Creating new thread.");
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
SERVER_COUNT_UNLOCK();
|
||||
}
|
||||
SERVER_COUNT_UNLOCK();
|
||||
|
||||
sleep(5);
|
||||
|
||||
|
||||
+5
-6
@@ -1,4 +1,4 @@
|
||||
/* $Id: utils.c,v 1.29 2002-04-28 20:03:53 rjkaes Exp $
|
||||
/* $Id: utils.c,v 1.28 2002-04-18 17:59:21 rjkaes Exp $
|
||||
*
|
||||
* 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,
|
||||
@@ -129,11 +129,10 @@ send_http_message(struct conn_s *connptr, int http_code,
|
||||
strftime(timebuf, sizeof(timebuf), "%a, %d %b %Y %H:%M:%S GMT",
|
||||
gmtime(&global_time));
|
||||
|
||||
if (write_message(connptr->client_fd,
|
||||
headers,
|
||||
http_code, error_title, PACKAGE, VERSION,
|
||||
timebuf, message_len) < 0)
|
||||
return -1;
|
||||
write_message(connptr->client_fd,
|
||||
headers,
|
||||
http_code, error_title, PACKAGE, VERSION, timebuf,
|
||||
message_len);
|
||||
|
||||
return safe_write(connptr->client_fd, message, message_len);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user