X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=parsers.c;h=15abc4094667aa258071ccad2a3fc0e94560b0a3;hp=11d28c71dc12e2d3c9cbf76b846d9d72a3dbca34;hb=251baeb8f9cfe5521292317bbec20e238aabfd54;hpb=54debef090db214715953499571b8d7ec77980db diff --git a/parsers.c b/parsers.c index 11d28c71..15abc409 100644 --- a/parsers.c +++ b/parsers.c @@ -2748,9 +2748,8 @@ static jb_err server_last_modified(struct client_state *csp, char **header) time_t now; struct tm *timeptr = NULL; long int rtime; -#ifdef HAVE_GMTIME_R struct tm gmt; -#endif + now = time(NULL); rtime = (long int)difftime(now, last_modified); if (rtime) @@ -2769,29 +2768,16 @@ static jb_err server_last_modified(struct client_state *csp, char **header) rtime *= -1; } last_modified += rtime; -#ifdef HAVE_GMTIME_R - timeptr = gmtime_r(&last_modified, &gmt); -#elif defined(MUTEX_LOCKS_AVAILABLE) - privoxy_mutex_lock(&gmtime_mutex); - timeptr = gmtime(&last_modified); -#else - timeptr = gmtime(&last_modified); -#endif + timeptr = privoxy_gmtime_r(&last_modified, &gmt); if ((NULL == timeptr) || !strftime(newheader, sizeof(newheader), "%a, %d %b %Y %H:%M:%S GMT", timeptr)) { -#if !defined(HAVE_GMTIME_R) && defined(MUTEX_LOCKS_AVAILABLE) - privoxy_mutex_unlock(&gmtime_mutex); -#endif log_error(LOG_LEVEL_ERROR, "Randomizing '%s' failed. Crunching the header without replacement.", *header); freez(*header); return JB_ERR_OK; } -#if !defined(HAVE_GMTIME_R) && defined(MUTEX_LOCKS_AVAILABLE) - privoxy_mutex_unlock(&gmtime_mutex); -#endif freez(*header); *header = strdup("Last-Modified: "); string_append(header, newheader); @@ -3417,9 +3403,7 @@ static jb_err client_host(struct client_state *csp, char **header) static 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; @@ -3477,29 +3461,16 @@ static jb_err client_if_modified_since(struct client_state *csp, char **header) *header); } tm += rtime * (negative_range ? -1 : 1); -#ifdef HAVE_GMTIME_R - timeptr = gmtime_r(&tm, &gmt); -#elif defined(MUTEX_LOCKS_AVAILABLE) - privoxy_mutex_lock(&gmtime_mutex); - timeptr = gmtime(&tm); -#else - timeptr = gmtime(&tm); -#endif + timeptr = privoxy_gmtime_r(&tm, &gmt); if ((NULL == timeptr) || !strftime(newheader, sizeof(newheader), "%a, %d %b %Y %H:%M:%S GMT", timeptr)) { -#if !defined(HAVE_GMTIME_R) && defined(MUTEX_LOCKS_AVAILABLE) - privoxy_mutex_unlock(&gmtime_mutex); -#endif log_error(LOG_LEVEL_ERROR, "Randomizing '%s' failed. Crunching the header without replacement.", *header); freez(*header); return JB_ERR_OK; } -#if !defined(HAVE_GMTIME_R) && defined(MUTEX_LOCKS_AVAILABLE) - privoxy_mutex_unlock(&gmtime_mutex); -#endif freez(*header); *header = strdup("If-Modified-Since: "); string_append(header, newheader); @@ -4040,29 +4011,15 @@ static void add_cookie_expiry_date(char **cookie, time_t lifetime) char tmp[50]; struct tm *timeptr = NULL; time_t expiry_date = time(NULL) + lifetime; -#ifdef HAVE_GMTIME_R struct tm gmt; - timeptr = gmtime_r(&expiry_date, &gmt); -#elif defined(MUTEX_LOCKS_AVAILABLE) - privoxy_mutex_lock(&gmtime_mutex); - timeptr = gmtime(&expiry_date); -#else - timeptr = gmtime(&expiry_date); -#endif - + timeptr = privoxy_gmtime_r(&expiry_date, &gmt); if (NULL == timeptr) { -#if !defined(HAVE_GMTIME_R) && defined(MUTEX_LOCKS_AVAILABLE) - privoxy_mutex_unlock(&gmtime_mutex); -#endif log_error(LOG_LEVEL_FATAL, "Failed to get the time in add_cooky_expiry_date()"); } strftime(tmp, sizeof(tmp), "; expires=%a, %d-%b-%Y %H:%M:%S GMT", timeptr); -#if !defined(HAVE_GMTIME_R) && defined(MUTEX_LOCKS_AVAILABLE) - privoxy_mutex_unlock(&gmtime_mutex); -#endif if (JB_ERR_OK != string_append(cookie, tmp)) { log_error(LOG_LEVEL_FATAL, "Out of memory in add_cooky_expiry()"); @@ -4399,9 +4356,10 @@ static jb_err parse_header_time(const char *header_time, time_t *result) { char recreated_date[100]; struct tm *tm; + struct tm storage; time_t result2; - tm = gmtime(result); + tm = privoxy_gmtime_r(result, &storage); if (!strftime(recreated_date, sizeof(recreated_date), time_formats[i], tm)) {