From 385fae593dac9010eb9cba3e64facc823fa2cb8c Mon Sep 17 00:00:00 2001 From: Robert James Kaes Date: Fri, 6 Aug 2004 16:56:55 +0000 Subject: [PATCH] [Fixes Bug 996518] Merged in a patch from Hans-Dieter that fixes a problem with upstream proxy support. --- src/conns.c | 4 +++- src/conns.h | 6 +++++- src/reqs.c | 11 ++++++----- src/tinyproxy.h | 8 +++++--- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/conns.c b/src/conns.c index 1de8f40..d8aee10 100644 --- a/src/conns.c +++ b/src/conns.c @@ -1,4 +1,4 @@ -/* $Id: conns.c,v 1.17 2003-05-31 23:02:21 rjkaes Exp $ +/* $Id: conns.c,v 1.17.2.1 2004-08-06 16:56:55 rjkaes Exp $ * * Create and free the connection structure. One day there could be * other connection related tasks put here, but for now the header @@ -75,6 +75,8 @@ initialize_conn(int client_fd, const char* ipaddr, const char* string_addr) connptr->client_ip_addr = safestrdup(ipaddr); connptr->client_string_addr = safestrdup(string_addr); + connptr->upstream_proxy = NULL; + update_stats(STAT_OPEN); return connptr; diff --git a/src/conns.h b/src/conns.h index a2c9017..cc08e98 100644 --- a/src/conns.h +++ b/src/conns.h @@ -1,4 +1,4 @@ -/* $Id: conns.h,v 1.14 2003-05-04 04:35:10 rjkaes Exp $ +/* $Id: conns.h,v 1.14.2.1 2004-08-06 16:56:55 rjkaes Exp $ * * See 'conns.c' for a detailed description. * @@ -70,6 +70,10 @@ struct conn_s { unsigned int major; unsigned int minor; } protocol; + /* + * Pointer to upstream proxy. + */ + struct upstream *upstream_proxy; }; /* diff --git a/src/reqs.c b/src/reqs.c index 91cc1ba..c58c25d 100644 --- a/src/reqs.c +++ b/src/reqs.c @@ -1,4 +1,4 @@ -/* $Id: reqs.c,v 1.105.2.1 2003-11-19 19:20:18 rjkaes Exp $ +/* $Id: reqs.c,v 1.105.2.2 2004-08-06 16:56:55 rjkaes Exp $ * * This is where all the work in tinyproxy is actually done. Incoming * connections have a new child created for them. The child then @@ -1072,7 +1072,7 @@ process_client_headers(struct conn_s *connptr, hashmap_t hashofheaders) * proxy is in use.) */ if (connptr->server_fd == -1 || connptr->show_stats - || (connptr->connect_method && !UPSTREAM_CONFIGURED())) { + || (connptr->connect_method && (connptr->upstream_proxy == NULL))) { log_message(LOG_INFO, "Not sending client headers to remote machine"); return 0; } @@ -1410,7 +1410,7 @@ connect_to_upstream(struct conn_s *connptr, struct request_s *request) char *combined_string; int len; - struct upstream *cur_upstream = upstream_get(request->host); + struct upstream *cur_upstream = connptr->upstream_proxy; if(!cur_upstream) { log_message(LOG_WARNING, "No upstream proxy defined for %s.", @@ -1554,7 +1554,8 @@ handle_connection(int fd) goto send_error; } - if (UPSTREAM_CONFIGURED() && (UPSTREAM_HOST(request->host) != NULL)) { + connptr->upstream_proxy = UPSTREAM_HOST(request->host); + if (connptr->upstream_proxy != NULL) { if (connect_to_upstream(connptr, request) < 0) { goto send_error; } @@ -1599,7 +1600,7 @@ handle_connection(int fd) return; } - if (!connptr->connect_method || UPSTREAM_CONFIGURED()) { + if (!connptr->connect_method || (connptr->upstream_proxy != NULL)) { if (process_server_headers(connptr) < 0) { if (connptr->error_variables) send_http_error_message(connptr); diff --git a/src/tinyproxy.h b/src/tinyproxy.h index d014748..c4fb1ef 100644 --- a/src/tinyproxy.h +++ b/src/tinyproxy.h @@ -1,4 +1,4 @@ -/* $Id: tinyproxy.h,v 1.41 2003-06-20 17:02:12 rjkaes Exp $ +/* $Id: tinyproxy.h,v 1.41.2.1 2004-08-06 16:56:55 rjkaes Exp $ * * See 'tinyproxy.c' for a detailed description. * @@ -25,7 +25,10 @@ #define MAXBUFFSIZE ((size_t)(1024 * 96)) /* Max size of buffer */ #define MAX_IDLE_TIME (60 * 10) /* 10 minutes of no activity */ -#ifdef UPSTREAM_SUPPORT +/* + * Even if upstream support is not compiled into tinyproxy, this + * structure still needs to be defined. + */ struct upstream { struct upstream *next; char *domain; /* optional */ @@ -33,7 +36,6 @@ struct upstream { int port; in_addr_t ip, mask; }; -#endif struct config_s { char *logf_name;