Commit Graph

122 Commits

Author SHA1 Message Date
Mukund Sivaraman
d5472ec0bd Renamed file to replace underscores in it with dashes 2008-03-13 15:07:37 -07:00
Robert James Kaes
4c58663041 * [Refactor] Moved Reverse Proxy Code
Moved the reverse proxy code from reqs.c into it's own files
(reverse_proxy.c).  The code in reqs.c is way too complicated, so I
want to move unrelated code into their own files to simplify the main
concepts in reqs.c.
2005-08-16 04:03:19 +00:00
Robert James Kaes
c0299e1868 * [Indent] Ran Source Through indent
I re-indented the source code using indent with the following options:

indent -kr -bad -bap -nut -i8 -l80 -psl -sob -ss -ncs

There are now _no_ tabs in the source files, and all indentation is
eight spaces.  Lines are 80 characters long, and the procedure type is
on it's own line.  Read the indent manual for more information about
what each option means.
2005-08-15 03:54:31 +00:00
Robert James Kaes
a59117c7ca * Updated Copyright Email Addresses
Updated the copyright email addresses for Robert James Kaes.  The
users.sourceforge.net address should always exist.
2005-07-12 17:39:44 +00:00
Robert James Kaes
6042483a0e Removed the proxy-* headers from the list of headers to skip. Since
tinyproxy does not prompt for any proxy information from the client, it
should not be eating the proxy headers.  They are most likely needed by
an upstream proxy.
2005-07-06 21:44:08 +00:00
Robert James Kaes
c446e19003 Added code to handle HTTP/0.9 simple GET requests. 2004-08-24 16:35:27 +00:00
Robert James Kaes
b3943c21f2 (check_allowed_connect_ports): By default DENY any CONNECT requests
unless explicitly allowed by a configuration directive.
2004-08-12 20:15:04 +00:00
Robert James Kaes
28dd133623 (add_xtinyproxy_header): Removed the runtime error checking of the
connptr->server_fd variable and moved it into an assert since we
should never be called with invalid data.  Also made the function an
inline function since it's only called in one place.
2004-08-12 19:57:15 +00:00
Robert James Kaes
fd4b67bbb4 (strip_username_password): Removed one of the pointer variables since
it's no longer needed.  Reorganized the function to make it more
obvious what was actually being done.
2004-08-11 02:49:05 +00:00
Robert James Kaes
badc7673d0 Merged in changes from 1.6.3 2004-08-10 21:24:24 +00:00
Robert James Kaes
18df4910a4 Added the "BindSame" configure directive from Oswald Buddenhagen.
This allows tinyproxy to respond to a request bound to the same
interface that the request came in on.  As Oswald explains:

  "attached is a patch that adds the BindSame option. it causes
  binding an outgoing connection to the ip address of the respective
  incoming connection. that way one can simulate an entire proxy farm
  with a single instance of tinyproxy on a multi-homed machine."

Cool.
2004-04-27 18:53:14 +00:00
Robert James Kaes
aee5a63849 Removed unnecessary casts (mostly dealing with memory allocation.) I
should never have added them in the first place.  They don't really
buy anything, and they can hide bugs.
2004-02-13 21:27:42 +00:00
Robert James Kaes
bf22966f55 (strip_return_port): Patch from "alex" to strip the port from the host
string and return the port.  I cleaned up and added error handling to
the code, but it's basically "alex"'s fix.

(extract_http_url): Rewrote this function to remove all the sscanf()
calls.  It's much easier to just split on the path slash (if it's
present) and then strip the user name/password and port from the host
string.  Less code, handles more cases!
2004-02-04 19:57:40 +00:00
Robert James Kaes
0a8e4e4d8d Added reverse proxy support from Kim Holviala. His comments regarding
this addition follow:

  The patch implements a simple reverse proxy (with one funky extra
  feature). It has all the regular features: mapping remote servers to local
  namespace (ReversePath), disabling forward proxying (ReverseOnly) and HTTP
  redirect rewriting (ReverseBaseURL).

  The funky feature is this: You map Google to /google/ and the Google front
  page opens up fine. Type in stuff and click "Google Search" and you'll get
  an error from tinyproxy. Reason for this is that Google's form submits to
  "/search" which unfortunately bypasses our /google/ mapping (if they'd
  submit to "search" without the slash it would have worked ok). Turn on
  ReverseMagic and it starts working....

  ReverseMagic "hijacks" one cookie which it sends to the client browser.
  This cookie contains the current reverse proxy path mapping (in the above
  case /google/) so that even if the site uses absolute links the reverse
  proxy still knows where to map the request.

  And yes, it works. No, I've never seen this done before - I couldn't find
  _any_ working OSS reverse proxies, and the commercial ones I've seen try
  to parse the page and fix all links (in the above case changing "/search"
  to "/google/search"). The problem with modifying the html is that it might
  not be parsable (very common) or it might be encoded so that the proxy
  can't read it (mod_gzip or likes).

  Hope you like that patch. One caveat - I haven't coded with C in like
  three years so my code might be a bit messy.... There shouldn't be any
  security problems thou, but you never know. I did all the stuff out of my
  memory without reading any RFC's, but I tested everything with Moz, Konq,
  IE6, Links and Lynx and they all worked fine.
2004-01-26 19:11:52 +00:00
Robert James Kaes
d2098f638f tinyproxy no longer includes a fall-back regular expression library,
so these files needed to be modified to only use the system's
installed regular expression library.
2003-08-07 16:32:12 +00:00
Robert James Kaes
fd23cd4aed # Fixed a comment to actually reflect what the function does. 2003-08-05 16:11:59 +00:00
Robert James Kaes
6aaa863432 Added appropriate casts from (void*) so that the code will compile
cleanly with a C++ compiler.  (Tested using GCC 3.3)
2003-07-31 23:38:28 +00:00
Robert James Kaes
1cb032a934 (upstream_add): Rewrote the function to actually handle the various
types of upstream configurations correctly.  Hopefully, the code is
also a little clearer in it's implementation.
2003-06-26 18:19:57 +00:00
Robert James Kaes
4c9141aac6 Removed the "ViaHeader" directive and replaced it with the
"ViaProxyName" directive.  The "Via" HTTP header is _required_ by the
HTTP spec, so the code has been changed to always send the header.
However, including the proxy's host name could be considered a
security threat, so the "ViaProxyName" directive is used to set the
token sent in the "Via" header.  If the directive is not enabled the
proxy's host name will be used.
2003-06-20 17:02:13 +00:00
Robert James Kaes
b081019d5a (connect_to_upstream): Fixed an off-by-one error in the snprintf()
call used to build the URL for the upstream proxy. [Patch suggested by
David T. Pierso]
2003-06-06 16:14:50 +00:00
Robert James Kaes
91e082671a (upstream_get):
(upstream_add): Added support to allow ip addresses and networks to be
used when matching an upstream proxy directive.
[Code by Peter da Silva]
2003-06-02 21:55:14 +00:00
Robert James Kaes
77ca1c8ce0 # Changed all the for calls to use the != test rather than < test.
The change was recommended in the C/C++ User Journal magazine.
2003-05-31 23:02:21 +00:00
Robert James Kaes
af5e1e29f6 # Changed the calls to vector_getentry() to use the new calling
convention.
2003-05-30 16:22:30 +00:00
Robert James Kaes
8ab278998f # Renamed the vector_insert() calls to vector_append() 2003-05-29 20:48:25 +00:00
Robert James Kaes
4a377a712d Improved the upstream proxy support by making the upstream proxy
server configurable based on the destination host.  [Code written by
Peter da Silva]
2003-05-29 19:44:00 +00:00
Robert James Kaes
5e1303ecd1 (establish_http_connection): If the port being requested is not a
standard HTTP port (80 or 443) append the port string to the host
header; otherwise, leave the host string with only the host's domain
name.

Replaced all occurrences of constant 80 and 443 with defines HTTP_PORT
and HTTP_PORT_SSL.
2003-05-05 16:46:05 +00:00
Robert James Kaes
c94bfa8223 (build_url): Rebuild the URL from the component pieces. This function
is used by the transparent proxy code.  [Anatole Shaw]
(process_request): Fixed up the transparent proxy code so that
filtering can be done on the whole URL.  [Anatole Shaw]

(pull_client_data): Added a bug fix for Internet Explorer (IE).  IE
will leave an extra CR and LF after the data in an HTTP POST.  The new
code will eat the extra bytes if they're present.  Thanks to Yannick
Koehler for finding the bug and offering an explanation as to why it
was happening.

Changed all calls of connptr->remote_content_length to
connptr->content_length.server
2003-04-16 18:11:58 +00:00
Robert James Kaes
7cd19206cc (establish_http_connection): Always include the port number for the
requested server.  This fixes a problem when the server is not
listening on the default port, 80.
[Fix suggested by duncan@sapio.co.uk]
2003-03-26 16:47:30 +00:00
Robert James Kaes
c76183a3f0 # Updated all the calls to indicate_http_error() to include a
terminating NULL.  The va_arg() function requires it to work
  properly.
2003-03-14 06:13:04 +00:00
Robert James Kaes
cb8aaf521e # Changed calls to indicate_http_error() to use the new HTML variable
substitution mechanism. [Steven Young]
2003-03-13 21:29:45 +00:00
Robert James Kaes
40c4d3c57a # (connect_to_upstream): Improved the preprocessor directives to make
sure the function would compile cleanly regardless of how the
  directive was set.
2003-01-28 21:21:55 +00:00
Robert James Kaes
2fc9c76969 (connect_to_upstream): Reorganized the preprocessor directives to make
sure the function's symbol name is stored, even if upstream was not
compiled it.  This should keep some compilers from reporting errors.
2003-01-27 18:42:18 +00:00
Robert James Kaes
212abd64d7 (process_client_headers): Fixed inverted anonymous header logic. Fix
comes from the FreeBSD port through James E. Flemer.
2003-01-27 17:39:02 +00:00
Robert James Kaes
59ec5dc69f (strip_username_password): New function to remove any
username/password part from the host URI.

(extract_http_url), (extract_ssl_url): Use the new
strip_username_password function to remove any non-host information
from the URI.
2002-12-04 17:36:48 +00:00
Robert James Kaes
0a20bdd5b4 Removed the "bool_t" type since it conflicts with the newer C standards.
The type was just replaced by "unsigned int" types.
2002-12-04 17:06:14 +00:00
Robert James Kaes
d069b4fce9 (extract_http_url): Removed the leading "http://" from all the tests,
since it's skipped by the caller before the URL is passed to this
function.

(process_request): Include code to handle proxy FTP requests as
well.  This also lead to a bit of a cleanup in the calling conventions
of extract_http_url function.  tinyproxy can handle both types of
resources by skipping the leading :// part.
2002-11-29 19:25:59 +00:00
Robert James Kaes
e58343012f Included code to disable the sending of the Via header. This is now
controlled by the ViaHeader configure directive.
2002-11-26 21:44:43 +00:00
Robert James Kaes
d40a4e8af7 (relay_connection): Shutdown the client socket for writing once all
the data has been sent.
2002-11-13 17:48:48 +00:00
Robert James Kaes
3b2be8ae88 Removed all the code supporting the TCP tunnelling feature of
tinyproxy.  There is really no need for this code, since there are
perfectly good programs out there (like rinetd) which are designed for
TCP tunnelling.  tinyproxy should be a good HTTP proxy, nothing more,
and nothing less; therefore, the tunnelling code is gone.
2002-11-03 17:10:33 +00:00
Robert James Kaes
69be2b84d7 (relay_connection): Ivan pointed out a bug with the code to send any
remaining data to the server when the connections are being closed.
It was a one line fix.
2002-10-17 19:27:08 +00:00
Robert James Kaes
f47685c861 A bunch of changes from Petr Lampa that add transparent proxy support to tinyproxy. The additional code is in process_request(), but Petr also had to change around some of the other functions (like process_client_headers and handle_connection.) Note: Right now this code has not been tested, but it is believed to work. To enable run ./configure --enable-transparent-proxy 2002-06-06 20:32:30 +00:00
Robert James Kaes
26a983b467 (process_server_headers): Since we're stripping off the carriage return and newline, we need to add them back on when sending the response header to the client. 2002-05-31 18:09:09 +00:00
Robert James Kaes
9b13e9bda8 (add_header_to_connection): Removed the "double_cgi" boolean, since tinyproxy now ignores all the headers after a "double CGI" situation has occurred.
(get_all_headers): Instead of dropping duplicate headers when the "double CGI" situation occurs, tinyproxy will now drop _all_ the headers from the "inner" HTTP response.
2002-05-29 18:11:57 +00:00
Robert James Kaes
e7fcb5fc7d (add_header_to_connection): Added a boolean to indicate that a "Double CGI" situation is in affect. This is needed to solve a problem with some sites (like cgi.ebay.com) where they are sending two HTTP response lines (and associated headers) with a response.
(get_all_headers): Detect if a "Double CGI" situation has occured.
2002-05-28 20:40:01 +00:00
Robert James Kaes
cf2bd809fb (get_all_headers): Added code to ignore a "response" line in a header. This was pointed out as being a problem with eBay (cgi.ebay.com)
(process_server_headers): Added code to make skip blank lines before a response line.
2002-05-28 04:53:33 +00:00
Robert James Kaes
4ce9674365 (process_request): Changed the filtering code around to handle both domains and URLs. 2002-05-27 02:00:22 +00:00
Robert James Kaes
63f481c61a Spelling changes (from thread to child.) 2002-05-26 18:55:19 +00:00
Robert James Kaes
391a408eee Fixed a tonne of spelling mistakes. 2002-05-24 04:45:32 +00:00
Robert James Kaes
47ab97a347 Fixed up a spelling mistake and changed various bits of code to take
advantage of the fact that the peer's socket information is now stored
inside the connection structure.
2002-05-23 18:24:46 +00:00
Robert James Kaes
e4e78e0f1b request->host might have been freed by the time we get to
free_request_struct(), so make sure it's pointing to memory.
2002-05-17 16:34:42 +00:00