X-Git-Url: http://www.privoxy.org/gitweb/?a=blobdiff_plain;f=parsers.c;h=c6f9c66fd8d15c5733fd8d7a1d1de14e6a099ccb;hb=19b68ba6ac1d627dc975dbc70897a9600efdc80f;hp=d6a770157fb7c76a2f902a8b9b9976c7cf9e14a9;hpb=2a5ed65ce70e5c208a13e02fec17ef9c362d56e1;p=privoxy.git diff --git a/parsers.c b/parsers.c index d6a77015..c6f9c66f 100644 --- a/parsers.c +++ b/parsers.c @@ -1,4 +1,4 @@ -const char parsers_rcs[] = "$Id: parsers.c,v 1.64 2006/08/17 17:15:10 fabiankeil Exp $"; +const char parsers_rcs[] = "$Id: parsers.c,v 1.66 2006/09/03 19:38:28 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/parsers.c,v $ @@ -40,6 +40,15 @@ const char parsers_rcs[] = "$Id: parsers.c,v 1.64 2006/08/17 17:15:10 fabiankeil * * Revisions : * $Log: parsers.c,v $ + * Revision 1.66 2006/09/03 19:38:28 fabiankeil + * Use gmtime_r if available, fallback to gmtime with mutex + * protection for MacOSX and use vanilla gmtime for the rest. + * + * Revision 1.65 2006/08/22 10:55:56 fabiankeil + * Changed client_referrer to use the right type (size_t) for + * hostlenght and to shorten the temporary referrer string with + * '\0' instead of adding a useless line break. + * * Revision 1.64 2006/08/17 17:15:10 fabiankeil * - Back to timegm() using GnuPG's replacement if necessary. * Using mktime() and localtime() could add a on hour offset if @@ -1243,8 +1252,8 @@ jb_err server_content_type(struct client_state *csp, char **header) * * Description : - Prohibit filtering (CT_TABOO) if transfer coding compresses * - Raise the CSP_FLAG_CHUNKED flag if coding is "chunked" - * - Change from "chunked" to "identity" if body was chunked - * but has been de-chunked for filtering. + * - Remove header if body was chunked but has been + * de-chunked for filtering. * * Parameters : * 1 : csp = Current client state (buffers, headers, etc...) @@ -1275,15 +1284,13 @@ jb_err server_transfer_coding(struct client_state *csp, char **header) csp->flags |= CSP_FLAG_CHUNKED; /* - * If the body was modified, it has been - * de-chunked first, so adjust the header: + * If the body was modified, it has been de-chunked first + * and the header must be removed. */ if (csp->flags & CSP_FLAG_MODIFIED) { + log_error(LOG_LEVEL_HEADER, "Removing: %s", *header); freez(*header); - *header = strdup("Transfer-Encoding: identity"); - log_error(LOG_LEVEL_HEADER, "Set: %s", *header); - return (header == NULL) ? JB_ERR_MEMORY : JB_ERR_OK; } } @@ -1482,6 +1489,9 @@ jb_err server_last_modified(struct client_state *csp, char **header) char buf[BUFFER_SIZE]; char newheader[50]; +#ifdef HAVE_GMTIME_R + struct tm gmt; +#endif struct tm *timeptr = NULL; time_t now, last_modified; long int rtime; @@ -1530,7 +1540,15 @@ jb_err server_last_modified(struct client_state *csp, char **header) { log_error(LOG_LEVEL_HEADER, "Randomizing: %s", *header); now = time(NULL); +#ifdef HAVE_GMTIME_R + timeptr = gmtime_r(&now, &gmt); +#elif OSX_DARWIN + pthread_mutex_lock(&gmtime_mutex); timeptr = gmtime(&now); + pthread_mutex_unlock(&gmtime_mutex); +#else + timeptr = gmtime(&now); +#endif if ((timeptr = parse_header_time(*header, &last_modified)) == NULL) { log_error(LOG_LEVEL_HEADER, "Couldn't parse: %s (crunching!)", *header); @@ -1543,7 +1561,15 @@ jb_err server_last_modified(struct client_state *csp, char **header) { rtime = pick_from_range(rtime); last_modified += rtime; +#ifdef HAVE_GMTIME_R + timeptr = gmtime_r(&last_modified, &gmt); +#elif OSX_DARWIN + pthread_mutex_lock(&gmtime_mutex); + timeptr = gmtime(&last_modified); + pthread_mutex_unlock(&gmtime_mutex); +#else timeptr = gmtime(&last_modified); +#endif strftime(newheader, sizeof(newheader), "%a, %d %b %Y %H:%M:%S GMT", timeptr); freez(*header); *header = strdup("Last-Modified: "); @@ -2224,6 +2250,9 @@ jb_err client_host(struct client_state *csp, char **header) jb_err client_if_modified_since(struct client_state *csp, char **header) { char newheader[50]; +#ifdef HAVE_GMTIME_R + struct tm gmt; +#endif struct tm *timeptr = NULL; time_t tm = 0; const char *newval; @@ -2281,7 +2310,15 @@ jb_err client_if_modified_since(struct client_state *csp, char **header) *header); } tm += rtime; +#ifdef HAVE_GMTIME_R + timeptr = gmtime_r(&tm, &gmt); +#elif OSX_DARWIN + pthread_mutex_lock(&gmtime_mutex); timeptr = gmtime(&tm); + pthread_mutex_unlock(&gmtime_mutex); +#else + timeptr = gmtime(&tm); +#endif strftime(newheader, sizeof(newheader), "%a, %d %b %Y %H:%M:%S GMT", timeptr); freez(*header); @@ -2841,19 +2878,18 @@ int strclean(const char *string, const char *substring) struct tm *parse_header_time(char *header, time_t *tm) { char * timestring; + struct tm gmt; struct tm * timeptr; - - *tm = 0; - timeptr = localtime(tm); + /* Skipping header name */ timestring = strstr(header, ": "); - if (strptime(timestring, ": %a, %d %b %Y %H:%M:%S", timeptr) == NULL) + if (strptime(timestring, ": %a, %d %b %Y %H:%M:%S", &gmt) == NULL) { timeptr = NULL; } else { - *tm = timegm(timeptr); + *tm = timegm(&gmt); } return(timeptr); }