X-Git-Url: http://www.privoxy.org/gitweb/?a=blobdiff_plain;f=parsers.c;h=6b922d72c5a8c3ac34220e94dcf127cbfc4b1ece;hb=d9be112e8353413208b1ed009c9541e334ea7fb2;hp=fdd9f4735792d9b78577f09d53dcd63a1bdb47c5;hpb=04104131e7e779b2373db118a09e9343a906ffab;p=privoxy.git diff --git a/parsers.c b/parsers.c index fdd9f473..6b922d72 100644 --- a/parsers.c +++ b/parsers.c @@ -1,4 +1,4 @@ -const char parsers_rcs[] = "$Id: parsers.c,v 1.63 2006/08/14 13:18:08 david__schmidt Exp $"; +const char parsers_rcs[] = "$Id: parsers.c,v 1.70 2006/09/08 12:06:34 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/parsers.c,v $ @@ -40,6 +40,56 @@ const char parsers_rcs[] = "$Id: parsers.c,v 1.63 2006/08/14 13:18:08 david__sch * * Revisions : * $Log: parsers.c,v $ + * Revision 1.70 2006/09/08 12:06:34 fabiankeil + * Have hide-if-modified-since interpret the random + * range value as minutes instead of hours. Allows + * more fine-grained configuration. + * + * Revision 1.69 2006/09/06 16:25:51 fabiankeil + * Always have parse_header_time return a pointer + * that actual makes sense, even though we currently + * only need it to detect problems. + * + * Revision 1.68 2006/09/06 10:43:32 fabiankeil + * Added config option enable-remote-http-toggle + * to specify if Privoxy should recognize special + * headers (currently only X-Filter) to change its + * behaviour. Disabled by default. + * + * Revision 1.67 2006/09/04 11:01:26 fabiankeil + * After filtering de-chunked instances, remove + * "Transfer-Encoding" header entirely instead of changing + * it to "Transfer-Encoding: identity", which is invalid. + * Thanks Michael Shields . Fixes PR 1318658. + * + * Don't use localtime in parse_header_time. An empty time struct + * is good enough, it gets overwritten by strptime anyway. + * + * 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 + * the randomize factor was big enough to lead to a summer/wintertime + * switch. + * + * - Removed now-useless Privoxy 3.0.3 compatibility glue. + * + * - Moved randomization code into pick_from_range(). + * + * - Changed parse_header_time definition. + * time_t isn't guaranteed to be signed and + * if it isn't, -1 isn't available as error code. + * Changed some variable types in client_if_modified_since() + * because of the same reason. + * * Revision 1.63 2006/08/14 13:18:08 david__schmidt * OS/2 compilation compatibility fixups * @@ -1227,8 +1277,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...) @@ -1259,15 +1309,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; } } @@ -1466,6 +1514,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; @@ -1514,7 +1565,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); @@ -1527,7 +1586,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: "); @@ -1659,7 +1726,7 @@ jb_err client_referrer(struct client_state *csp, char **header) const char *newval; const char *host; char *referer; - int hostlenght; + size_t hostlenght; #ifdef FEATURE_FORCE_LOAD /* Since the referrer can include the prefix even @@ -1717,7 +1784,7 @@ jb_err client_referrer(struct client_state *csp, char **header) *if www.example.org/www.example.com-shall-see-the-referer/ *links to www.example.com/ */ - referer[hostlenght+17] = '\n'; + referer[hostlenght+17] = '\0'; } if ( 0 == strstr(referer, host)) /*Host has changed*/ { @@ -2208,6 +2275,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; @@ -2247,16 +2317,16 @@ jb_err client_if_modified_since(struct client_state *csp, char **header) else { rtime = strtol(newval, &endptr, 0); - if(rtime < 0) - { - rtime *= -1; - negative = 1; - } if(rtime) { - log_error(LOG_LEVEL_HEADER, "Randomizing: %s (random range: %d hou%s)", - *header, rtime, (rtime == 1 || rtime == -1) ? "r": "rs"); - rtime *= 3600; + log_error(LOG_LEVEL_HEADER, "Randomizing: %s (random range: %d minut%s)", + *header, rtime, (rtime == 1 || rtime == -1) ? "e": "es"); + if(rtime < 0) + { + rtime *= -1; + negative = 1; + } + rtime *= 60; rtime = pick_from_range(rtime); } else @@ -2264,8 +2334,16 @@ jb_err client_if_modified_since(struct client_state *csp, char **header) log_error(LOG_LEVEL_ERROR, "Random range is 0. Assuming time transformation test.", *header); } - tm += rtime; + tm += rtime * (negative ? -1 : 1); +#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); @@ -2344,17 +2422,24 @@ jb_err client_x_filter(struct client_state *csp, char **header) { if ( 0 == strcmpic(*header, "X-Filter: No")) { - if (csp->action->flags & ACTION_FORCE_TEXT_MODE) + if (!(csp->config->feature_flags & RUNTIME_FEATURE_HTTP_TOGGLE)) { - log_error(LOG_LEVEL_HEADER, "force-text-mode overruled the client's request to disable filtering!"); + log_error(LOG_LEVEL_INFO, "Ignored the client's request to fetch without filtering."); } - else - { - csp->content_type = CT_TABOO; - log_error(LOG_LEVEL_HEADER, "Disabled filter mode on behalf of the client."); + else + { + if (csp->action->flags & ACTION_FORCE_TEXT_MODE) + { + log_error(LOG_LEVEL_HEADER, "force-text-mode overruled the client's request to fetch without filtering!"); + } + else + { + csp->content_type = CT_TABOO; + log_error(LOG_LEVEL_HEADER, "Accepted the client's request to fetch without filtering."); + } + log_error(LOG_LEVEL_HEADER, "Crunching %s", *header); + freez(*header); } - log_error(LOG_LEVEL_HEADER, "Crunching %s", *header); - freez(*header); } return JB_ERR_OK; } @@ -2825,19 +2910,19 @@ 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); + timeptr=&gmt; } return(timeptr); }