diff options
author | Robert James Kaes <rjkaes@users.sourceforge.net> | 2001-08-28 04:32:14 +0000 |
---|---|---|
committer | Robert James Kaes <rjkaes@users.sourceforge.net> | 2001-08-28 04:32:14 +0000 |
commit | f9d0fcd1a2bfd55fa092080cb920be6e12601bb1 (patch) | |
tree | c230c11c19594c127b6804a619be9003fc40608f /src | |
parent | 298784d80ef5b748dd38e9b22c8cbeb390497d96 (diff) | |
download | tinyproxy-f9d0fcd1a2bfd55fa092080cb920be6e12601bb1.tar.gz tinyproxy-f9d0fcd1a2bfd55fa092080cb920be6e12601bb1.zip |
Moved the strip new line/carriage return from the end of a line into a
separate function.
Diffstat (limited to '')
-rw-r--r-- | src/reqs.c | 32 |
1 files changed, 26 insertions, 6 deletions
@@ -1,10 +1,10 @@ -/* $Id: reqs.c,v 1.16 2001-08-27 03:44:22 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 * connections have a new thread created for them. The thread then * processes the headers from the client, the response from the server, * and then relays the bytes between the two. - * If the UPSTEAM_PROXY is enabled, then tinyproxy will actually work + * If TUNNEL_SUPPORT is enabled, then tinyproxy will actually work * as a simple buffering TCP tunnel. Very cool! (Robert actually uses * this feature for a buffering NNTP tunnel.) * @@ -82,6 +82,29 @@ static ssize_t safe_read(int fd, void *buffer, size_t count) } /* + * 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. */ static int process_method(struct conn_s *connptr) @@ -89,7 +112,6 @@ static int process_method(struct conn_s *connptr) URI *uri = NULL; char inbuf[LINE_LENGTH]; char *buffer = NULL, *request = NULL, *port = NULL; - char *inbuf_ptr = NULL; regex_t preg; regmatch_t pmatch[NMATCH]; @@ -112,9 +134,7 @@ static int process_method(struct conn_s *connptr) /* * Strip the newline and character return from the string. */ - inbuf_ptr = inbuf + len - 1; - while (*inbuf_ptr == '\r' || *inbuf_ptr == '\n') - *inbuf_ptr-- = '\0'; + trim(inbuf, len); log_message(LOG_CONN, "Request: %s", inbuf); |