Cleaned up the code which sends the "Via" header. It now uses

write_message().
This commit is contained in:
Robert James Kaes 2001-12-23 21:55:08 +00:00
parent b68354a9da
commit c3124815a1
2 changed files with 27 additions and 27 deletions

View File

@ -1,3 +1,8 @@
2001-12-23 Robert James Kaes <rjkaes@flarenet.com>
* src/reqs.c (process_client_headers): Cleaned up the code to send
the Via header by using the write_message() function.
2001-12-22 Robert James Kaes <rjkaes@flarenet.com> 2001-12-22 Robert James Kaes <rjkaes@flarenet.com>
* src/tinyproxy.h: Add a test for the MSG_NOSIGNAL define, so it's * src/tinyproxy.h: Add a test for the MSG_NOSIGNAL define, so it's

View File

@ -1,4 +1,4 @@
/* $Id: reqs.c,v 1.50 2001-12-20 04:48:32 rjkaes Exp $ /* $Id: reqs.c,v 1.51 2001-12-23 21:55:08 rjkaes Exp $
* *
* This is where all the work in tinyproxy is actually done. Incoming * This is where all the work in tinyproxy is actually done. Incoming
* connections have a new thread created for them. The thread then * connections have a new thread created for them. The thread then
@ -9,7 +9,7 @@
* this feature for a buffering NNTP tunnel.) * this feature for a buffering NNTP tunnel.)
* *
* Copyright (C) 1998 Steven Young * Copyright (C) 1998 Steven Young
* Copyright (C) 1999,2000 Robert James Kaes (rjkaes@flarenet.com) * Copyright (C) 1999-2001 Robert James Kaes (rjkaes@flarenet.com)
* Copyright (C) 2000 Chris Lightfoot (chris@ex-parrot.com) * Copyright (C) 2000 Chris Lightfoot (chris@ex-parrot.com)
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
@ -241,6 +241,8 @@ write_message(int fd, const char *fmt, ...)
} }
if (safe_write(fd, buf, n) < 0) { if (safe_write(fd, buf, n) < 0) {
DEBUG2("Error in write_message(): %d", fd);
safefree(buf); safefree(buf);
return -1; return -1;
} }
@ -594,28 +596,23 @@ process_client_headers(struct conn_s *connptr)
* to the end of it. * to the end of it.
*/ */
if (strncasecmp(header, "via", 3) == 0) { if (strncasecmp(header, "via", 3) == 0) {
if (sent_via_header == 0) {
char hostname[128]; char hostname[128];
char via_header_buffer[256];
char *new_header; chomp(header, len);
gethostname(hostname, sizeof(hostname));
write_message(connptr->server_fd,
"%s, %hu.%hu %s (%s/%s)\r\n",
header,
connptr->protocol.major,
connptr->protocol.minor,
hostname, PACKAGE, VERSION);
sent_via_header = 1; sent_via_header = 1;
}
gethostname(hostname, sizeof(hostname));
snprintf(via_header_buffer, sizeof(via_header_buffer),
", %hu.%hu %s (%s/%s)\r\n",
connptr->protocol.major,
connptr->protocol.minor, hostname, PACKAGE,
VERSION);
chomp(header, strlen(header));
new_header = safemalloc(strlen(header) + strlen(via_header_buffer) + 1);
strcpy(new_header, header);
strcat(new_header, via_header_buffer);
safefree(header); safefree(header);
header = new_header; continue;
} }
/* /*
@ -665,16 +662,14 @@ process_client_headers(struct conn_s *connptr)
/* /*
* We're the first proxy so send the first Via header. * We're the first proxy so send the first Via header.
*/ */
char via_header_buffer[256];
char hostname[128]; char hostname[128];
gethostname(hostname, sizeof(hostname)); gethostname(hostname, sizeof(hostname));
snprintf(via_header_buffer, sizeof(via_header_buffer), write_message(connptr->server_fd,
"Via: %hu.%hu %s (%s/%s)\r\n", connptr->protocol.major, "Via: %hu.%hu %s (%s/%s)\r\n",
connptr->protocol.minor, hostname, PACKAGE, VERSION); connptr->protocol.major,
connptr->protocol.minor,
safe_write(connptr->server_fd, via_header_buffer, hostname, PACKAGE, VERSION);
strlen(via_header_buffer));
} }
if ((connptr->server_fd != -1) if ((connptr->server_fd != -1)