Parse HTTP 'Date' entries in the `C' locale rather than the user's.
Fix from [bin/42917] (with minor changes), from KAMADA Ken'ichi.
This commit is contained in:
parent
029e3bd476
commit
cbd600cfd6
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: extern.h,v 1.77 2009/07/13 19:05:41 roy Exp $ */
|
||||
/* $NetBSD: extern.h,v 1.78 2010/03/04 21:40:53 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
|
||||
@ -166,6 +166,7 @@ const char *onoff(int);
|
||||
void opts(int, char **);
|
||||
void newer(int, char **);
|
||||
void page(int, char **);
|
||||
const char *parse_rfc2616time(struct tm *, const char *);
|
||||
int parserate(int, char **, int);
|
||||
char *prompt(void);
|
||||
void proxabort(int);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: fetch.c,v 1.191 2009/08/17 09:08:16 christos Exp $ */
|
||||
/* $NetBSD: fetch.c,v 1.192 2010/03/04 21:40:53 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
|
||||
@ -34,7 +34,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: fetch.c,v 1.191 2009/08/17 09:08:16 christos Exp $");
|
||||
__RCSID("$NetBSD: fetch.c,v 1.192 2010/03/04 21:40:53 lukem Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
@ -934,28 +934,18 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
|
||||
|
||||
} else if (match_token(&cp, "Last-Modified:")) {
|
||||
struct tm parsed;
|
||||
char *t;
|
||||
const char *t;
|
||||
|
||||
memset(&parsed, 0, sizeof(parsed));
|
||||
/* RFC1123 */
|
||||
if ((t = strptime(cp,
|
||||
"%a, %d %b %Y %H:%M:%S GMT",
|
||||
&parsed))
|
||||
/* RFC0850 */
|
||||
|| (t = strptime(cp,
|
||||
"%a, %d-%b-%y %H:%M:%S GMT",
|
||||
&parsed))
|
||||
/* asctime */
|
||||
|| (t = strptime(cp,
|
||||
"%a, %b %d %H:%M:%S %Y",
|
||||
&parsed))) {
|
||||
t = parse_rfc2616time(&parsed, cp);
|
||||
if (t != NULL) {
|
||||
parsed.tm_isdst = -1;
|
||||
if (*t == '\0')
|
||||
mtime = timegm(&parsed);
|
||||
#ifndef NO_DEBUG
|
||||
if (ftp_debug && mtime != -1) {
|
||||
fprintf(ttyout,
|
||||
"parsed date as: %s",
|
||||
"parsed time as: %s",
|
||||
rfc2822time(localtime(&mtime)));
|
||||
}
|
||||
#endif
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: util.c,v 1.152 2009/07/13 19:05:41 roy Exp $ */
|
||||
/* $NetBSD: util.c,v 1.153 2010/03/04 21:40:53 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
|
||||
@ -64,7 +64,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: util.c,v 1.152 2009/07/13 19:05:41 roy Exp $");
|
||||
__RCSID("$NetBSD: util.c,v 1.153 2010/03/04 21:40:53 lukem Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
@ -85,6 +85,7 @@ __RCSID("$NetBSD: util.c,v 1.152 2009/07/13 19:05:41 roy Exp $");
|
||||
#include <signal.h>
|
||||
#include <libgen.h>
|
||||
#include <limits.h>
|
||||
#include <locale.h>
|
||||
#include <netdb.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -756,7 +757,7 @@ remotemodtime(const char *file, int noisy)
|
||||
else
|
||||
goto cleanup_parse_time;
|
||||
} else {
|
||||
DPRINTF("remotemodtime: parsed date `%s' as " LLF
|
||||
DPRINTF("remotemodtime: parsed time `%s' as " LLF
|
||||
", %s",
|
||||
timestr, (LLT)rtime,
|
||||
rfc2822time(localtime(&rtime)));
|
||||
@ -791,6 +792,32 @@ rfc2822time(const struct tm *tm)
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse HTTP-date as per RFC 2616.
|
||||
* Return a pointer to the next character of the consumed date string,
|
||||
* or NULL if failed.
|
||||
*/
|
||||
const char *
|
||||
parse_rfc2616time(struct tm *parsed, const char *httpdate)
|
||||
{
|
||||
const char *t;
|
||||
const char *curlocale;
|
||||
|
||||
/* The representation of %a depends on the current locale. */
|
||||
curlocale = setlocale(LC_TIME, NULL);
|
||||
(void)setlocale(LC_TIME, "C");
|
||||
/* RFC1123 */
|
||||
if ((t = strptime(httpdate, "%a, %d %b %Y %H:%M:%S GMT", parsed)) ||
|
||||
/* RFC0850 */
|
||||
(t = strptime(httpdate, "%a, %d-%b-%y %H:%M:%S GMT", parsed)) ||
|
||||
/* asctime */
|
||||
(t = strptime(httpdate, "%a, %b %d %H:%M:%S %Y", parsed))) {
|
||||
; /* do nothing */
|
||||
}
|
||||
(void)setlocale(LC_TIME, curlocale);
|
||||
return t;
|
||||
}
|
||||
|
||||
/*
|
||||
* Update global `localcwd', which contains the state of the local cwd
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user