From f9d0fcd1a2bfd55fa092080cb920be6e12601bb1 Mon Sep 17 00:00:00 2001 From: Robert James Kaes Date: Tue, 28 Aug 2001 04:32:14 +0000 Subject: Moved the strip new line/carriage return from the end of a line into a separate function. --- src/reqs.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/reqs.c b/src/reqs.c index 97224d8..c54da28 100644 --- a/src/reqs.c +++ b/src/reqs.c @@ -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.) * @@ -81,6 +81,29 @@ static ssize_t safe_read(int fd, void *buffer, size_t count) 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. */ @@ -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); -- cgit v1.2.3