X-Git-Url: http://www.privoxy.org/gitweb/?a=blobdiff_plain;f=jcc.c;h=722d7fd1d53e4371d2a7181797d2817673eaa3a9;hb=b302b2dc2c8fba30ad5389549927bca6c3bdce71;hp=3b0ba8f921be9219cc26d421a7b3a96abb3b25af;hpb=caf0013d7d203d04c49137fd3f502ff73c506b72;p=privoxy.git diff --git a/jcc.c b/jcc.c index 3b0ba8f9..722d7fd1 100644 --- a/jcc.c +++ b/jcc.c @@ -1,4 +1,4 @@ -const char jcc_rcs[] = "$Id: jcc.c,v 1.314 2010/04/03 13:21:53 fabiankeil Exp $"; +const char jcc_rcs[] = "$Id: jcc.c,v 1.319 2010/05/24 11:40:27 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jcc.c,v $ @@ -625,39 +625,39 @@ static const char *crunch_reason(const struct http_response *rsp) return "Internal error while searching for crunch reason"; } - switch (rsp->reason) + switch (rsp->crunch_reason) { - case RSP_REASON_UNSUPPORTED: + case UNSUPPORTED: reason = "Unsupported HTTP feature"; break; - case RSP_REASON_BLOCKED: + case BLOCKED: reason = "Blocked"; break; - case RSP_REASON_UNTRUSTED: + case UNTRUSTED: reason = "Untrusted"; break; - case RSP_REASON_REDIRECTED: + case REDIRECTED: reason = "Redirected"; break; - case RSP_REASON_CGI_CALL: + case CGI_CALL: reason = "CGI Call"; break; - case RSP_REASON_NO_SUCH_DOMAIN: + case NO_SUCH_DOMAIN: reason = "DNS failure"; break; - case RSP_REASON_FORWARDING_FAILED: + case FORWARDING_FAILED: reason = "Forwarding failed"; break; - case RSP_REASON_CONNECT_FAILED: + case CONNECT_FAILED: reason = "Connection failure"; break; - case RSP_REASON_OUT_OF_MEMORY: + case OUT_OF_MEMORY: reason = "Out of memory (may mask other reasons)"; break; - case RSP_REASON_CONNECTION_TIMEOUT: + case CONNECTION_TIMEOUT: reason = "Connection timeout"; break; - case RSP_REASON_NO_SERVER_DATA: + case NO_SERVER_DATA: reason = "No server data received"; break; default: @@ -694,19 +694,7 @@ static void send_crunch_response(const struct client_state *csp, struct http_res if (rsp == NULL) { - /* - * Not supposed to happen. If it does - * anyway, treat it as an unknown error. - */ - cgi_error_unknown(csp, rsp, RSP_REASON_INTERNAL_ERROR); - /* return code doesn't matter */ - } - - if (rsp == NULL) - { - /* If rsp is still NULL, we have serious internal problems. */ - log_error(LOG_LEVEL_FATAL, - "NULL response in send_crunch_response and cgi_error_unknown failed as well."); + log_error(LOG_LEVEL_FATAL, "NULL response in send_crunch_response."); } /* @@ -1724,7 +1712,7 @@ static void chat(struct client_state *csp) #ifdef FEATURE_CONNECTION_KEEP_ALIVE if ((csp->server_connection.sfd != JB_INVALID_SOCKET) - && socket_is_still_usable(csp->server_connection.sfd) + && socket_is_still_alive(csp->server_connection.sfd) && connection_destination_matches(&csp->server_connection, http, fwd)) { log_error(LOG_LEVEL_CONNECT, @@ -2028,7 +2016,7 @@ static void chat(struct client_state *csp) if (FD_ISSET(csp->server_connection.sfd, &rfds)) { #ifdef FEATURE_CONNECTION_KEEP_ALIVE - if (!socket_is_still_usable(csp->cfd)) + if (!socket_is_still_alive(csp->cfd)) { #ifdef _WIN32 log_error(LOG_LEVEL_CONNECT, @@ -2484,6 +2472,46 @@ static void chat(struct client_state *csp) } +#ifdef FEATURE_CONNECTION_KEEP_ALIVE +/********************************************************************* + * + * Function : prepare_csp_for_next_request + * + * Description : Put the csp in a mostly vergin state. + * + * Parameters : + * 1 : csp = Current client state (buffers, headers, etc...) + * + * Returns : N/A + * + *********************************************************************/ +static void prepare_csp_for_next_request(struct client_state *csp) +{ + csp->content_type = 0; + csp->content_length = 0; + csp->expected_content_length = 0; + csp->expected_client_content_length = 0; + list_remove_all(csp->headers); + freez(csp->iob->buf); + memset(csp->iob, 0, sizeof(csp->iob)); + freez(csp->error_message); + free_http_request(csp->http); + destroy_list(csp->headers); + destroy_list(csp->tags); + free_current_action(csp->action); + if (NULL != csp->fwd) + { + unload_forward_spec(csp->fwd); + csp->fwd = NULL; + } + /* XXX: Store per-connection flags someplace else. */ + csp->flags &= CSP_FLAG_TOGGLED_ON; + csp->flags |= CSP_FLAG_ACTIVE; + csp->flags |= CSP_FLAG_REUSED_CLIENT_CONNECTION; +} +#endif /* def FEATURE_CONNECTION_KEEP_ALIVE */ + + /********************************************************************* * * Function : serve @@ -2533,7 +2561,7 @@ static void serve(struct client_state *csp) if (continue_chatting && !(csp->flags & CSP_FLAG_CRUNCHED)) { continue_chatting = (csp->server_connection.sfd != JB_INVALID_SOCKET) - && socket_is_still_usable(csp->server_connection.sfd); + && socket_is_still_alive(csp->server_connection.sfd); if (continue_chatting) { if (!(csp->flags & CSP_FLAG_SERVER_KEEP_ALIVE_TIMEOUT_SET)) @@ -2568,36 +2596,12 @@ static void serve(struct client_state *csp) } if ((csp->flags & CSP_FLAG_CLIENT_CONNECTION_KEEP_ALIVE) && data_is_available(csp->cfd, (int)client_timeout) - && socket_is_still_usable(csp->cfd)) + && socket_is_still_alive(csp->cfd)) { log_error(LOG_LEVEL_CONNECT, "Client request arrived in " "time or the client closed the connection on socket %d.", csp->cfd); - /* - * Get the csp in a mostly vergin state again. - * XXX: Should be done elsewhere. - */ - csp->content_type = 0; - csp->content_length = 0; - csp->expected_content_length = 0; - csp->expected_client_content_length = 0; - list_remove_all(csp->headers); - freez(csp->iob->buf); - memset(csp->iob, 0, sizeof(csp->iob)); - freez(csp->error_message); - free_http_request(csp->http); - destroy_list(csp->headers); - destroy_list(csp->tags); - free_current_action(csp->action); - if (NULL != csp->fwd) - { - unload_forward_spec(csp->fwd); - csp->fwd = NULL; - } - - /* XXX: Store per-connection flags someplace else. */ - csp->flags = CSP_FLAG_ACTIVE | - (csp->flags & CSP_FLAG_TOGGLED_ON) | CSP_FLAG_REUSED_CLIENT_CONNECTION; + prepare_csp_for_next_request(csp); } else { @@ -2606,7 +2610,7 @@ static void serve(struct client_state *csp) csp->cfd); #ifdef FEATURE_CONNECTION_SHARING if ((csp->config->feature_flags & RUNTIME_FEATURE_CONNECTION_SHARING) - && (socket_is_still_usable(csp->server_connection.sfd))) + && (socket_is_still_alive(csp->server_connection.sfd))) { time_t time_open = time(NULL) - csp->server_connection.timestamp; @@ -3141,13 +3145,10 @@ int main(int argc, char **argv) */ #if defined(unix) { - pid_t pid = 0; - if (daemon_mode) { int fd; - - pid = fork(); + pid_t pid = fork(); if ( pid < 0 ) /* error */ {