X-Git-Url: http://www.privoxy.org/gitweb/?a=blobdiff_plain;f=jcc.c;h=32e6f0d8449dd7d01c16978871668cc611c6292c;hb=0c556e7b91320783f6ff77d63053bc95bd1d116a;hp=5d8bff17c7ba37022767a05c2b208569b7478d86;hpb=8c144430bd5b07ee088dcc01f3799b488219954a;p=privoxy.git diff --git a/jcc.c b/jcc.c index 5d8bff17..32e6f0d8 100644 --- a/jcc.c +++ b/jcc.c @@ -1,4 +1,4 @@ -const char jcc_rcs[] = "$Id: jcc.c,v 1.378 2012/03/10 11:08:10 fabiankeil Exp $"; +const char jcc_rcs[] = "$Id: jcc.c,v 1.387 2012/09/04 08:37:51 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jcc.c,v $ @@ -6,7 +6,7 @@ const char jcc_rcs[] = "$Id: jcc.c,v 1.378 2012/03/10 11:08:10 fabiankeil Exp $" * Purpose : Main file. Contains main() method, main loop, and * the main connection-handling function. * - * Copyright : Written by and Copyright (C) 2001-2010 the + * Copyright : Written by and Copyright (C) 2001-2012 the * Privoxy team. http://www.privoxy.org/ * * Based on the Internet Junkbuster originally written @@ -661,6 +661,34 @@ static const char *crunch_reason(const struct http_response *rsp) } +/********************************************************************* + * + * Function : log_applied_actions + * + * Description : Logs the applied actions if LOG_LEVEL_ACTIONS is + * enabled. + * + * Parameters : + * 1 : actions = Current action spec to log + * + * Returns : Nothing. + * + *********************************************************************/ +static void log_applied_actions(const struct current_action_spec *actions) +{ + /* + * The conversion to text requires lots of memory allocations so + * we only do the conversion if the user is actually interested. + */ + if (debug_level_is_enabled(LOG_LEVEL_ACTIONS)) + { + char *actions_as_text = actions_to_line_of_text(actions); + log_error(LOG_LEVEL_ACTIONS, "%s", actions_as_text); + freez(actions_as_text); + } +} + + /********************************************************************* * * Function : send_crunch_response @@ -705,6 +733,7 @@ static void send_crunch_response(const struct client_state *csp, struct http_res status_code[3] = '\0'; /* Log that the request was crunched and why. */ + log_applied_actions(csp->action); log_error(LOG_LEVEL_CRUNCH, "%s: %s", crunch_reason(rsp), http->url); log_error(LOG_LEVEL_CLF, "%s - - [%T] \"%s\" %s %u", csp->ip_addr_str, http->ocmd, status_code, rsp->content_length); @@ -827,12 +856,7 @@ static void build_request_line(struct client_state *csp, const struct forward_sp && (!strcmpic(http->ver, "HTTP/1.1"))) { freez(http->ver); - http->ver = strdup("HTTP/1.0"); - - if (http->ver == NULL) - { - log_error(LOG_LEVEL_FATAL, "Out of memory downgrading HTTP version"); - } + http->ver = strdup_or_die("HTTP/1.0"); } /* @@ -891,12 +915,7 @@ static jb_err change_request_destination(struct client_state *csp) else { /* XXX: ocmd is a misleading name */ - http->ocmd = strdup(http->cmd); - if (http->ocmd == NULL) - { - log_error(LOG_LEVEL_FATAL, - "Out of memory copying rewritten HTTP request line"); - } + http->ocmd = strdup_or_die(http->cmd); } return err; @@ -1003,11 +1022,7 @@ void save_connection_destination(jb_socket sfd, assert(NULL != http->host); server_connection->sfd = sfd; - server_connection->host = strdup(http->host); - if (NULL == server_connection->host) - { - log_error(LOG_LEVEL_FATAL, "Out of memory saving socket."); - } + server_connection->host = strdup_or_die(http->host); server_connection->port = http->port; assert(NULL != fwd); @@ -1020,11 +1035,7 @@ void save_connection_destination(jb_socket sfd, server_connection->forwarder_type = fwd->type; if (NULL != fwd->gateway_host) { - server_connection->gateway_host = strdup(fwd->gateway_host); - if (NULL == server_connection->gateway_host) - { - log_error(LOG_LEVEL_FATAL, "Out of memory saving gateway_host."); - } + server_connection->gateway_host = strdup_or_die(fwd->gateway_host); } else { @@ -1034,11 +1045,7 @@ void save_connection_destination(jb_socket sfd, if (NULL != fwd->forward_host) { - server_connection->forward_host = strdup(fwd->forward_host); - if (NULL == server_connection->forward_host) - { - log_error(LOG_LEVEL_FATAL, "Out of memory saving forward_host."); - } + server_connection->forward_host = strdup_or_die(fwd->forward_host); } else { @@ -1405,12 +1412,7 @@ static jb_err receive_client_request(struct client_state *csp) /* * Save a copy of the original request for logging */ - http->ocmd = strdup(http->cmd); - if (http->ocmd == NULL) - { - log_error(LOG_LEVEL_FATAL, - "Out of memory copying HTTP request line"); - } + http->ocmd = strdup_or_die(http->cmd); enlist(csp->headers, http->cmd); /* Append the previously read headers */ @@ -1452,6 +1454,12 @@ static jb_err parse_client_request(struct client_state *csp) /* Assume persistence until further notice */ csp->flags |= CSP_FLAG_CLIENT_CONNECTION_KEEP_ALIVE; } + + if (csp->http->ssl == 0) + { + csp->expected_client_content_length = get_expected_content_length(csp->headers); + verify_request_length(csp); + } #endif /* def FEATURE_CONNECTION_KEEP_ALIVE */ err = sed(csp, FILTER_CLIENT_HEADERS); @@ -1482,13 +1490,6 @@ static jb_err parse_client_request(struct client_state *csp) return JB_ERR_PARSE; } -#ifdef FEATURE_CONNECTION_KEEP_ALIVE - if (csp->http->ssl == 0) - { - verify_request_length(csp); - } -#endif /* def FEATURE_CONNECTION_KEEP_ALIVE */ - return JB_ERR_OK; } @@ -1629,6 +1630,7 @@ static void chat(struct client_state *csp) return; } + log_applied_actions(csp->action); log_error(LOG_LEVEL_GPC, "%s%s", http->hostport, http->path); if (fwd->forward_host) @@ -2505,6 +2507,9 @@ static void serve(struct client_state *csp) #endif /* def FEATURE_CONNECTION_SHARING */ int continue_chatting = 0; + log_error(LOG_LEVEL_CONNECT, "Accepted connection from %s on socket %d", + csp->ip_addr_str, csp->cfd); + do { unsigned int latency; @@ -2657,6 +2662,10 @@ static void serve(struct client_state *csp) if (csp->cfd != JB_INVALID_SOCKET) { + log_error(LOG_LEVEL_CONNECT, "Closing client socket %d. " + "Keep-alive: %u, Socket alive: %u. Data available: %u.", + csp->cfd, 0 != (csp->flags & CSP_FLAG_CLIENT_CONNECTION_KEEP_ALIVE), + socket_is_still_alive(csp->cfd), data_is_available(csp->cfd, 0)); close_socket(csp->cfd); } @@ -2975,7 +2984,7 @@ int main(int argc, char **argv) else if (strcmp(argv[argc_pos], "--pidfile") == 0) { if (++argc_pos == argc) usage(argv[0]); - pidfile = strdup(argv[argc_pos]); + pidfile = strdup_or_die(argv[argc_pos]); } else if (strcmp(argv[argc_pos], "--user") == 0) @@ -2985,12 +2994,7 @@ int main(int argc, char **argv) if (++argc_pos == argc) usage(argv[argc_pos]); - user_arg = strdup(argv[argc_pos]); - if (NULL == user_arg) - { - log_error(LOG_LEVEL_FATAL, - "Out of memory splitting --user argument '%s'.", argv[argc_pos]); - } + user_arg = strdup_or_die(argv[argc_pos]); group_name = strchr(user_arg, '.'); if (NULL != group_name) { @@ -3018,7 +3022,7 @@ int main(int argc, char **argv) else if (strcmp(argv[argc_pos], "--pre-chroot-nslookup") == 0) { if (++argc_pos == argc) usage(argv[0]); - pre_chroot_nslookup_to_load_resolver = strdup(argv[argc_pos]); + pre_chroot_nslookup_to_load_resolver = strdup_or_die(argv[argc_pos]); } else if (strcmp(argv[argc_pos], "--chroot") == 0) @@ -3061,16 +3065,10 @@ int main(int argc, char **argv) exit(1); } + basedir = strdup_or_die(cwd); /* XXX: why + 5? */ abs_file_size = strlen(cwd) + strlen(configfile) + 5; - basedir = strdup(cwd); - - if (NULL == basedir || - NULL == (abs_file = malloc(abs_file_size))) - { - perror("malloc failed"); - exit(1); - } + abs_file = malloc_or_die(abs_file_size); strlcpy(abs_file, basedir, abs_file_size); strlcat(abs_file, "/", abs_file_size); strlcat(abs_file, configfile, abs_file_size); @@ -3559,12 +3557,6 @@ static void listen_loop(void) freez(csp_list); continue; } - else - { - log_error(LOG_LEVEL_CONNECT, - "accepted connection from %s on socket %d", - csp->ip_addr_str, csp->cfd); - } csp->flags |= CSP_FLAG_ACTIVE; csp->server_connection.sfd = JB_INVALID_SOCKET;