X-Git-Url: http://www.privoxy.org/gitweb/?a=blobdiff_plain;f=jcc.c;h=415c2c0542ada02b373f4a02bd6fb32228ba12cd;hb=4dc3b810a5e3aa5cab68cf62708cdabcfe2993cb;hp=2dc0718e9a176c795a1d24f25e77a7cf82fba804;hpb=a978d7d5a4c7bc58d3158910c03af0adab61b429;p=privoxy.git diff --git a/jcc.c b/jcc.c index 2dc0718e..415c2c05 100644 --- a/jcc.c +++ b/jcc.c @@ -1,4 +1,4 @@ -const char jcc_rcs[] = "$Id: jcc.c,v 1.110 2006/12/13 14:52:53 etresoft Exp $"; +const char jcc_rcs[] = "$Id: jcc.c,v 1.115 2006/12/29 17:38:57 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jcc.c,v $ @@ -33,6 +33,26 @@ const char jcc_rcs[] = "$Id: jcc.c,v 1.110 2006/12/13 14:52:53 etresoft Exp $"; * * Revisions : * $Log: jcc.c,v $ + * 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 + * and stop using it on _WIN32 where it could + * cause crashes. + * + * Revision 1.111 2006/12/23 16:15:06 fabiankeil + * Don't prevent core dumps by catching SIGABRT. + * It's rude and makes debugging unreasonable painful. + * * Revision 1.110 2006/12/13 14:52:53 etresoft * Fix build failure on MacOS X. Global symbols can be either static or extern, but not both. * @@ -844,6 +864,11 @@ pthread_mutex_t gethostbyaddr_mutex; #ifndef HAVE_GETHOSTBYNAME_R pthread_mutex_t gethostbyname_mutex; #endif /* ndef HAVE_GETHOSTBYNAME_R */ + +#ifndef HAVE_RANDOM +pthread_mutex_t rand_mutex; +#endif /* ndef HAVE_RANDOM */ + #endif /* FEATURE_PTHREAD */ #if defined(unix) || defined(__EMX__) @@ -899,7 +924,7 @@ const char MISSING_DESTINATION_RESPONSE[] = * Function : sig_handler * * Description : Signal handler for different signals. - * Exit gracefully on ABRT, TERM and INT + * Exit gracefully on TERM and INT * or set a flag that will cause the errlog * to be reopened by the main thread on HUP. * @@ -993,12 +1018,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 */ @@ -1674,7 +1699,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); @@ -1705,7 +1730,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 @@ -1759,7 +1785,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"); @@ -1767,7 +1793,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; @@ -1782,7 +1808,7 @@ static void chat(struct client_state *csp) return; } } - byte_count += len; + byte_count += (size_t)len; continue; } else @@ -1930,7 +1956,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 */ @@ -2069,9 +2095,7 @@ int main(int argc, const char *argv[]) #endif { int argc_pos = 0; -#ifdef HAVE_RANDOM unsigned int random_seed; -#endif /* ifdef HAVE_RANDOM */ #ifdef unix struct passwd *pw = NULL; struct group *grp = NULL; @@ -2238,11 +2262,18 @@ int main(int argc, const char *argv[]) #ifndef HAVE_GETHOSTBYNAME_R pthread_mutex_init(&gethostbyname_mutex,0); #endif /* ndef HAVE_GETHOSTBYNAME_R */ + +#ifndef HAVE_RANDOM + pthread_mutex_init(&rand_mutex,0); +#endif /* ndef HAVE_RANDOM */ + #endif /* FEATURE_PTHREAD */ -#ifdef HAVE_RANDOM random_seed = (unsigned int)time(NULL); +#ifdef HAVE_RANDOM srandom(random_seed); +#else + srand(random_seed); #endif /* ifdef HAVE_RANDOM */ /* @@ -2285,7 +2316,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 */ @@ -2699,7 +2730,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); } @@ -2841,7 +2872,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);