Module Name:    src
Committed By:   riz
Date:           Sat Nov 20 01:03:19 UTC 2010

Modified Files:
        src/usr.bin/ftp [netbsd-5]: extern.h fetch.c util.c

Log Message:
Pull up following revision(s) (requested by lukem in ticket #1370):
        usr.bin/ftp/extern.h: revision 1.78
        usr.bin/ftp/fetch.c: revision 1.192
        usr.bin/ftp/util.c: revision 1.153
Parse HTTP 'Date' entries in the `C' locale rather than the user's.
Fix from [bin/42917] (with minor changes), from KAMADA Ken'ichi.


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.75.4.1 src/usr.bin/ftp/extern.h
cvs rdiff -u -r1.185.6.1 -r1.185.6.2 src/usr.bin/ftp/fetch.c
cvs rdiff -u -r1.148 -r1.148.4.1 src/usr.bin/ftp/util.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/extern.h
diff -u src/usr.bin/ftp/extern.h:1.75 src/usr.bin/ftp/extern.h:1.75.4.1
--- src/usr.bin/ftp/extern.h:1.75	Sat May 10 00:05:31 2008
+++ src/usr.bin/ftp/extern.h	Sat Nov 20 01:03:18 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: extern.h,v 1.75 2008/05/10 00:05:31 skd Exp $	*/
+/*	$NetBSD: extern.h,v 1.75.4.1 2010/11/20 01:03:18 riz Exp $	*/
 
 /*-
  * Copyright (c) 1996-2008 The NetBSD Foundation, Inc.
@@ -166,6 +166,7 @@
 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);

Index: src/usr.bin/ftp/fetch.c
diff -u src/usr.bin/ftp/fetch.c:1.185.6.1 src/usr.bin/ftp/fetch.c:1.185.6.2
--- src/usr.bin/ftp/fetch.c:1.185.6.1	Sat Nov 20 00:54:10 2010
+++ src/usr.bin/ftp/fetch.c	Sat Nov 20 01:03:18 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.185.6.1 2010/11/20 00:54:10 riz Exp $	*/
+/*	$NetBSD: fetch.c,v 1.185.6.2 2010/11/20 01:03:18 riz Exp $	*/
 
 /*-
  * Copyright (c) 1997-2008 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.185.6.1 2010/11/20 00:54:10 riz Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.185.6.2 2010/11/20 01:03:18 riz Exp $");
 #endif /* not lint */
 
 /*
@@ -931,28 +931,18 @@
 
 			} 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

Index: src/usr.bin/ftp/util.c
diff -u src/usr.bin/ftp/util.c:1.148 src/usr.bin/ftp/util.c:1.148.4.1
--- src/usr.bin/ftp/util.c:1.148	Wed Aug 13 04:59:13 2008
+++ src/usr.bin/ftp/util.c	Sat Nov 20 01:03:19 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: util.c,v 1.148 2008/08/13 04:59:13 lukem Exp $	*/
+/*	$NetBSD: util.c,v 1.148.4.1 2010/11/20 01:03:19 riz Exp $	*/
 
 /*-
  * Copyright (c) 1997-2008 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: util.c,v 1.148 2008/08/13 04:59:13 lukem Exp $");
+__RCSID("$NetBSD: util.c,v 1.148.4.1 2010/11/20 01:03:19 riz Exp $");
 #endif /* not lint */
 
 /*
@@ -85,6 +85,7 @@
 #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 @@
 			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 @@
 }
 
 /*
+ * 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
  */
 void

Reply via email to