A bunch of malloc() return code checks for the HAVE_RFC2553 code.
[privoxy.git] / jcc.c
diff --git a/jcc.c b/jcc.c
index c5a8a4a..03b2431 100644 (file)
--- a/jcc.c
+++ b/jcc.c
@@ -1,4 +1,4 @@
-const char jcc_rcs[] = "$Id: jcc.c,v 1.250 2009/05/16 13:27:20 fabiankeil Exp $";
+const char jcc_rcs[] = "$Id: jcc.c,v 1.256 2009/06/11 11:49:11 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/jcc.c,v $
@@ -236,15 +236,6 @@ static const char MISSING_DESTINATION_RESPONSE[] =
    "Connection: close\r\n\r\n"
    "Bad request. Privoxy was unable to extract the destination.\r\n";
 
-/* XXX: should be a template */
-static const char NO_SERVER_DATA_RESPONSE[] =
-   "HTTP/1.0 502 Server or forwarder response empty\r\n"
-   "Proxy-Agent: Privoxy " VERSION "\r\n"
-   "Content-Type: text/plain\r\n"
-   "Connection: close\r\n\r\n"
-   "Empty server or forwarder response.\r\n"
-   "The connection has been closed but Privoxy didn't receive any data.\r\n";
-
 /* XXX: should be a template */
 static const char INVALID_SERVER_HEADERS_RESPONSE[] =
    "HTTP/1.0 502 Server or forwarder response invalid\r\n"
@@ -278,13 +269,12 @@ static const char TOO_MANY_CONNECTIONS_RESPONSE[] =
    "Connection: close\r\n\r\n"
    "Maximum number of open connections reached.\r\n";
 
-/* XXX: should be a template */
-static const char CONNECTION_TIMEOUT_RESPONSE[] =
+static const char CLIENT_CONNECTION_TIMEOUT_RESPONSE[] =
    "HTTP/1.0 504 Connection timeout\r\n"
    "Proxy-Agent: Privoxy " VERSION "\r\n"
    "Content-Type: text/plain\r\n"
    "Connection: close\r\n\r\n"
-   "The connection timed out.\r\n";
+   "The connection timed out because the client request didn't arrive in time.\r\n";
 
 /* A function to crunch a response */
 typedef struct http_response *(*crunch_func_ptr)(struct client_state *);
@@ -664,6 +654,12 @@ static const char *crunch_reason(const struct http_response *rsp)
       case RSP_REASON_OUT_OF_MEMORY:
          reason = "Out of memory (may mask other reasons)";
          break;
+      case RSP_REASON_CONNECTION_TIMEOUT:
+         reason = "Connection timeout";
+         break;
+      case RSP_REASON_NO_SERVER_DATA:
+         reason = "No server data received";
+         break;
       default:
          reason = "No reason recorded";
          break;
@@ -1176,8 +1172,8 @@ static char *get_request_line(struct client_state *csp)
       {
          log_error(LOG_LEVEL_ERROR,
             "Stopped waiting for the request line.");
-         write_socket(csp->cfd, CONNECTION_TIMEOUT_RESPONSE,
-            strlen(CONNECTION_TIMEOUT_RESPONSE));
+         write_socket(csp->cfd, CLIENT_CONNECTION_TIMEOUT_RESPONSE,
+            strlen(CLIENT_CONNECTION_TIMEOUT_RESPONSE));
          return NULL;
       }
 
@@ -1307,6 +1303,7 @@ static jb_err receive_client_request(struct client_state *csp)
          {
             log_error(LOG_LEVEL_ERROR,
                "Stopped grabbing the client headers.");
+            destroy_list(headers);
             return JB_ERR_PARSE;
          }
 
@@ -1634,15 +1631,15 @@ static void chat(struct client_state *csp)
          if (fwd->type != SOCKS_NONE)
          {
             /* Socks error. */
-            rsp = error_response(csp, "forwarding-failed", errno);
+            rsp = error_response(csp, "forwarding-failed");
          }
          else if (errno == EINVAL)
          {
-            rsp = error_response(csp, "no-such-domain", errno);
+            rsp = error_response(csp, "no-such-domain");
          }
          else
          {
-            rsp = error_response(csp, "connect-failed", errno);
+            rsp = error_response(csp, "connect-failed");
             log_error(LOG_LEVEL_CONNECT, "connect to: %s failed: %E",
                http->hostport);
          }
@@ -1681,7 +1678,7 @@ static void chat(struct client_state *csp)
          log_error(LOG_LEVEL_CONNECT,
             "write header to: %s failed: %E", http->hostport);
 
-         rsp = error_response(csp, "connect-failed", errno);
+         rsp = error_response(csp, "connect-failed");
          if (rsp)
          {
             send_crunch_response(csp, rsp);
@@ -1771,8 +1768,7 @@ static void chat(struct client_state *csp)
             "Didn't receive data in time: %s", http->url);
          if ((byte_count == 0) && (http->ssl == 0))
          {
-            write_socket(csp->cfd, CONNECTION_TIMEOUT_RESPONSE,
-               strlen(CONNECTION_TIMEOUT_RESPONSE));
+            send_crunch_response(csp, error_response(csp, "connection-timeout"));
          }
          mark_server_socket_tainted(csp);
          return;
@@ -1818,7 +1814,7 @@ static void chat(struct client_state *csp)
        */
       if (FD_ISSET(csp->sfd, &rfds))
       {
-         fflush(0);
+         fflush(NULL);
          len = read_socket(csp->sfd, buf, sizeof(buf) - 1);
 
          if (len < 0)
@@ -2097,7 +2093,7 @@ static void chat(struct client_state *csp)
             {
                log_error(LOG_LEVEL_ERROR, "Empty server or forwarder response.");
                log_error(LOG_LEVEL_CLF, "%s - - [%T] \"%s\" 502 0", csp->ip_addr_str, http->cmd);
-               write_socket(csp->cfd, NO_SERVER_DATA_RESPONSE, strlen(NO_SERVER_DATA_RESPONSE));
+               send_crunch_response(csp, error_response(csp, "no-server-data"));
                free_http_request(http);
                mark_server_socket_tainted(csp);
                return;