Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/ftp Parse HTTP 'Date' entries in the `C' locale rath...



details:   https://anonhg.NetBSD.org/src/rev/b6e848974567
branches:  trunk
changeset: 752710:b6e848974567
user:      lukem <lukem%NetBSD.org@localhost>
date:      Thu Mar 04 21:40:53 2010 +0000

description:
Parse HTTP 'Date' entries in the `C' locale rather than the user's.
Fix from [bin/42917] (with minor changes), from KAMADA Ken'ichi.

diffstat:

 usr.bin/ftp/extern.h |   3 ++-
 usr.bin/ftp/fetch.c  |  22 ++++++----------------
 usr.bin/ftp/util.c   |  33 ++++++++++++++++++++++++++++++---
 3 files changed, 38 insertions(+), 20 deletions(-)

diffs (136 lines):

diff -r 1428075c0e9f -r b6e848974567 usr.bin/ftp/extern.h
--- a/usr.bin/ftp/extern.h      Thu Mar 04 20:46:18 2010 +0000
+++ b/usr.bin/ftp/extern.h      Thu Mar 04 21:40:53 2010 +0000
@@ -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 @@
 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);
diff -r 1428075c0e9f -r b6e848974567 usr.bin/ftp/fetch.c
--- a/usr.bin/ftp/fetch.c       Thu Mar 04 20:46:18 2010 +0000
+++ b/usr.bin/ftp/fetch.c       Thu Mar 04 21:40:53 2010 +0000
@@ -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 @@
 
                        } 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
diff -r 1428075c0e9f -r b6e848974567 usr.bin/ftp/util.c
--- a/usr.bin/ftp/util.c        Thu Mar 04 20:46:18 2010 +0000
+++ b/usr.bin/ftp/util.c        Thu Mar 04 21:40:53 2010 +0000
@@ -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 @@
 #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)));
@@ -792,6 +793,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



Home | Main Index | Thread Index | Old Index