Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions src/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,6 @@ ssize_t read_buffer (int fd, struct buffer_s * buffptr)
bytesin = -1;
} else {
switch (errno) {
#ifdef EWOULDBLOCK
case EWOULDBLOCK:
#else
# ifdef EAGAIN
case EAGAIN:
# endif
#endif
case EINTR:
bytesin = 0;
break;
Expand Down Expand Up @@ -295,13 +288,6 @@ ssize_t write_buffer (int fd, struct buffer_s * buffptr)
return bytessent;
} else {
switch (errno) {
#ifdef EWOULDBLOCK
case EWOULDBLOCK:
#else
# ifdef EAGAIN
case EAGAIN:
# endif
#endif
case EINTR:
return 0;
case ENOBUFS:
Expand Down
67 changes: 7 additions & 60 deletions src/reqs.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,10 @@ static struct request_s *process_request (struct conn_s *connptr,
* server headers can be processed.
* - rjkaes
*/
static int pull_client_data (struct conn_s *connptr, long int length, int iehack)
static int pull_client_data (struct conn_s *connptr, long int length)
{
char *buffer;
ssize_t len;
int ret;

buffer =
(char *) safemalloc (min (MAXBUFFSIZE, (unsigned long int) length));
Expand All @@ -549,43 +548,6 @@ static int pull_client_data (struct conn_s *connptr, long int length, int iehack
length -= len;
} while (length > 0);

if (iehack) {
/*
* BUG FIX: Internet Explorer will leave two bytes (carriage
* return and line feed) at the end of a POST message. These
* need to be eaten for tinyproxy to work correctly.
*/
ret = socket_nonblocking (connptr->client_fd);
if (ret != 0) {
log_message(LOG_ERR, "Failed to set the client socket "
"to non-blocking: %s", strerror(errno));
goto ERROR_EXIT;
}

len = recv (connptr->client_fd, buffer, 2, MSG_PEEK);

ret = socket_blocking (connptr->client_fd);
if (ret != 0) {
log_message(LOG_ERR, "Failed to set the client socket "
"to blocking: %s", strerror(errno));
goto ERROR_EXIT;
}

if (len < 0 && errno != EAGAIN)
goto ERROR_EXIT;

if ((len == 2) && CHECK_CRLF (buffer, len)) {
ssize_t bytes_read;

bytes_read = read (connptr->client_fd, buffer, 2);
if (bytes_read == -1) {
log_message
(LOG_WARNING,
"Could not read two bytes from POST message");
}
}
}

safefree (buffer);
return 0;

Expand Down Expand Up @@ -615,7 +577,7 @@ static int pull_client_data_chunked (struct conn_s *connptr) {
chunklen = strtol (buffer, (char**)0, 16);
if (chunklen < 0) goto ERROR_EXIT;

if (pull_client_data (connptr, chunklen+2, 0) < 0)
if (pull_client_data (connptr, chunklen+2) < 0)
goto ERROR_EXIT;

if(!chunklen) break;
Expand Down Expand Up @@ -1008,7 +970,7 @@ process_client_headers (struct conn_s *connptr, pseudomap *hashofheaders)
PULL_CLIENT_DATA:
if (connptr->content_length.client > 0) {
ret = pull_client_data (connptr,
connptr->content_length.client, 1);
connptr->content_length.client);
} else if (connptr->content_length.client == -2)
ret = pull_client_data_chunked (connptr);

Expand Down Expand Up @@ -1195,8 +1157,8 @@ static int process_server_headers (struct conn_s *connptr)
}

/*
* Switch the sockets into nonblocking mode and begin relaying the bytes
* between the two connections. We continue to use the buffering code
* Begin relaying the bytes between the two connections.
* We continue to use the buffering code
* since we want to be able to buffer a certain amount for slower
* connections (as this was the reason why I originally modified
* tinyproxy oh so long ago...)
Expand Down Expand Up @@ -1269,14 +1231,6 @@ static void relay_connection (struct conn_s *connptr)
/*
* Try to send any remaining data to the server if we can.
*/
ret = socket_blocking (connptr->server_fd);
if (ret != 0) {
log_message(LOG_ERR,
"Failed to set server socket to blocking: %s",
strerror(errno));
return;
}

while (buffer_size (connptr->cbuffer) > 0) {
if (write_buffer (connptr->server_fd, connptr->cbuffer) < 0)
break;
Expand Down Expand Up @@ -1573,16 +1527,9 @@ static void auth_error(struct conn_s *connptr, int code) {
}

/*
* This is the main drive for each connection. As you can tell, for the
* first few steps we are using a blocking socket. If you remember the
* older tinyproxy code, this use to be a very confusing state machine.
* Well, no more! :) The sockets are only switched into nonblocking mode
* when we start the relay portion. This makes most of the original
* tinyproxy code, which was confusing, redundant. Hail progress.
* - rjkaes

* This is the main drive for each connection.
* this function is called directly from child_thread() with the newly
* received fd from accept().
* received fd from accept().
*/
void handle_connection (struct conn_s *connptr, union sockaddr_union* addr)
{
Expand Down
27 changes: 0 additions & 27 deletions src/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,33 +212,6 @@ int opensock (const char *host, int port, const char *bind_to)
return sockfd;
}

/*
* Set the socket to non blocking -rjkaes
*/
int socket_nonblocking (int sock)
{
int flags;

assert (sock >= 0);

flags = fcntl (sock, F_GETFL, 0);
return fcntl (sock, F_SETFL, flags | O_NONBLOCK);
}

/*
* Set the socket to blocking -rjkaes
*/
int socket_blocking (int sock)
{
int flags;

assert (sock >= 0);

flags = fcntl (sock, F_GETFL, 0);
return fcntl (sock, F_SETFL, flags & ~O_NONBLOCK);
}


/**
* Try to listen on one socket based on the addrinfo
* as returned from getaddrinfo.
Expand Down
Loading