X-Git-Url: http://www.privoxy.org/gitweb/?a=blobdiff_plain;f=jcc.c;h=4cbf24baefd1e6ff75f71310f706c18f62486656;hb=44bebd0cda396f58388fa5929c7cf93905f2bfad;hp=967a984de0bdc50ccc56d3f8d79a3ff37890c831;hpb=56a86b80f13c8f4247505b99482f71e6290a4afa;p=privoxy.git diff --git a/jcc.c b/jcc.c index 967a984d..4cbf24ba 100644 --- a/jcc.c +++ b/jcc.c @@ -1,4 +1,4 @@ -const char jcc_rcs[] = "$Id: jcc.c,v 1.112 2006/12/26 17:31:41 fabiankeil Exp $"; +const char jcc_rcs[] = "$Id: jcc.c,v 1.117 2006/12/31 17:56:37 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jcc.c,v $ @@ -33,6 +33,24 @@ const char jcc_rcs[] = "$Id: jcc.c,v 1.112 2006/12/26 17:31:41 fabiankeil Exp $" * * Revisions : * $Log: jcc.c,v $ + * Revision 1.117 2006/12/31 17:56:37 fabiankeil + * Added config option accept-intercepted-requests + * and disabled it by default. + * + * Revision 1.116 2006/12/29 19:08:22 fabiankeil + * Reverted parts of my last commit + * to keep error handling working. + * + * Revision 1.115 2006/12/29 17:38:57 fabiankeil + * Fixed gcc43 conversion warnings. + * + * Revision 1.114 2006/12/27 18:52:02 fabiankeil + * Fix -pedantic ISO C warning about converting + * from function pointer to object pointer. + * + * Revision 1.113 2006/12/26 17:38:50 fabiankeil + * Silence compiler warning I introduced with my last commit. + * * Revision 1.112 2006/12/26 17:31:41 fabiankeil * Mutex protect rand() if POSIX threading * is used, warn the user if that's not possible @@ -1008,12 +1026,12 @@ static void chat(struct client_state *csp) jb_socket maxfd; int server_body; int ms_iis5_hack = 0; - int byte_count = 0; - unsigned int forwarded_connect_retries = 0; - unsigned int max_forwarded_connect_retries = csp->config->forwarded_connect_retries; + size_t byte_count = 0; + int forwarded_connect_retries = 0; + int max_forwarded_connect_retries = csp->config->forwarded_connect_retries; const struct forward_spec * fwd; struct http_request *http; - int len; /* for buffer sizes */ + int len; /* for buffer sizes (and negative error codes) */ #ifdef FEATURE_KILL_POPUPS int block_popups; /* bool, 1==will block popups */ int block_popups_now = 0; /* bool, 1==currently blocking popups */ @@ -1173,9 +1191,23 @@ static void chat(struct client_state *csp) { /* * Intercepted or invalid request without domain - * inside the request line. Try to get it another way. + * inside the request line. Try to get it another way, + * unless accept-intercepted-requests is disabled. */ - if (JB_ERR_OK == get_destination_from_headers(headers, http)) + if (!(csp->config->feature_flags & RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS)) + { + log_error(LOG_LEVEL_ERROR, "%s's request: \'%s\' is invalid." + " Privoxy isn't configured to accept intercepted requests.", + csp->ip_addr_str, http->cmd); + log_error(LOG_LEVEL_CLF, "%s - - [%T] \"%s\" 400 0", csp->ip_addr_str, http->cmd); + + strcpy(buf, CHEADER); + write_socket(csp->cfd, buf, strlen(buf)); + free_http_request(http); + destroy_list(headers); + return; + } + else if (JB_ERR_OK == get_destination_from_headers(headers, http)) { /* Split the domain we just got for pattern matching */ init_domain_components(http); @@ -1689,7 +1721,7 @@ static void chat(struct client_state *csp) */ if (NULL == (p = (*content_filter)(csp))) { - csp->content_length = csp->iob->eod - csp->iob->cur; + csp->content_length = (size_t)(csp->iob->eod - csp->iob->cur); } hdr = sed(server_patterns_light, NULL, csp); @@ -1720,7 +1752,8 @@ static void chat(struct client_state *csp) * This is NOT the body, so * Let's pretend the server just sent us a blank line. */ - len = sprintf(buf, "\r\n"); + snprintf(buf, sizeof(buf), "\r\n"); + len = (int)strlen(buf); /* * Now, let the normal header parsing algorithm below do its @@ -1774,7 +1807,7 @@ static void chat(struct client_state *csp) if (write_socket(csp->cfd, hdr, hdrlen) || ((flushed = flush_socket(csp->cfd, csp)) < 0) - || (write_socket(csp->cfd, buf, (size_t) len))) + || (write_socket(csp->cfd, buf, (size_t)len))) { log_error(LOG_LEVEL_CONNECT, "Flush header and buffers to client failed: %E"); @@ -1782,7 +1815,7 @@ static void chat(struct client_state *csp) return; } - byte_count += hdrlen + flushed + len; + byte_count += hdrlen + (size_t)(flushed + len); freez(hdr); content_filter = NULL; server_body = 1; @@ -1797,7 +1830,7 @@ static void chat(struct client_state *csp) return; } } - byte_count += len; + byte_count += (size_t)len; continue; } else @@ -1945,7 +1978,7 @@ static void chat(struct client_state *csp) return; } - byte_count += len; + byte_count += (size_t)len; } /* we're finished with the server's header */ @@ -2258,7 +2291,7 @@ int main(int argc, const char *argv[]) #endif /* FEATURE_PTHREAD */ - random_seed = (int)time(NULL); + random_seed = (unsigned int)time(NULL); #ifdef HAVE_RANDOM srandom(random_seed); #else @@ -2305,7 +2338,7 @@ int main(int argc, const char *argv[]) * We *are* in a windows console app. * Print a verbose messages about FAQ's and such */ - printf(win32_blurb); + printf("%s", win32_blurb); # endif /* def _WIN_CONSOLE */ #endif /* def _WIN32 */ @@ -2719,7 +2752,7 @@ static void listen_loop(void) pthread_attr_init(&attrs); pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED); errno = pthread_create(&the_thread, &attrs, - (void*)serve, csp); + (void * (*)(void *))serve, csp); child_id = errno ? -1 : 0; pthread_attr_destroy(&attrs); } @@ -2763,13 +2796,22 @@ static void listen_loop(void) #define SELECTED_ONE_OPTION csp->cfd = ReleaseSocket(csp->cfd, -1); - if((child_id = (int)CreateNewProcTags( - NP_Entry, (ULONG)server_thread, - NP_Output, Output(), - NP_CloseOutput, FALSE, - NP_Name, (ULONG)"privoxy child", - NP_StackSize, 200*1024, - TAG_DONE))) +#ifdef __amigaos4__ + child_id = (int)CreateNewProcTags(NP_Entry, (ULONG)server_thread, + NP_Output, Output(), + NP_CloseOutput, FALSE, + NP_Name, (ULONG)"privoxy child", + NP_Child, TRUE, + TAG_DONE); +#else + child_id = (int)CreateNewProcTags(NP_Entry, (ULONG)server_thread, + NP_Output, Output(), + NP_CloseOutput, FALSE, + NP_Name, (ULONG)"privoxy child", + NP_StackSize, 200*1024, + TAG_DONE); +#endif + if(0 != child_id) { childs++; ((struct Task *)child_id)->tc_UserData = csp; @@ -2861,7 +2903,7 @@ static void listen_loop(void) log_error(LOG_LEVEL_ERROR, "can't fork: %E"); - sprintf(buf , "Privoxy: can't fork: errno = %d", errno); + snprintf(buf , sizeof(buf), "Privoxy: can't fork: errno = %d", errno); write_socket(csp->cfd, buf, strlen(buf)); close_socket(csp->cfd);