From e7cefd684b2d5e1f3710eb24babc0b9974095c97 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 11 Feb 2005 00:03:49 +0000 Subject: Removed all uses of strftime() since it uses the localised version of the week day names and month names and servers don't like that. --- lib/Makefile.inc | 2 +- lib/file.c | 14 ++++++++++---- lib/ftp.c | 14 ++++++++++---- lib/http.c | 23 ++++++++++++++--------- lib/parsedate.c | 18 +++++++++--------- lib/parsedate.h | 28 ++++++++++++++++++++++++++++ 6 files changed, 72 insertions(+), 27 deletions(-) create mode 100644 lib/parsedate.h (limited to 'lib') diff --git a/lib/Makefile.inc b/lib/Makefile.inc index 4d5778fb1..f008736eb 100644 --- a/lib/Makefile.inc +++ b/lib/Makefile.inc @@ -17,4 +17,4 @@ HHEADERS = arpa_telnet.h netrc.h file.h timeval.h base64.h hostip.h \ http_chunks.h strtok.h connect.h llist.h hash.h content_encoding.h \ share.h md5.h http_digest.h http_negotiate.h http_ntlm.h ca-bundle.h \ inet_pton.h strtoofft.h strerror.h inet_ntop.h curlx.h memory.h \ - setup.h transfer.h select.h easyif.h multiif.h + setup.h transfer.h select.h easyif.h multiif.h parsedate.h diff --git a/lib/file.c b/lib/file.c index 5bebf3287..c325a4673 100644 --- a/lib/file.c +++ b/lib/file.c @@ -87,6 +87,7 @@ #include "transfer.h" #include "url.h" #include "memory.h" +#include "parsedate.h" /* for the week day and month names */ #define _MPRINTF_REPLACE /* use our functions only */ #include @@ -321,7 +322,6 @@ CURLcode Curl_file(struct connectdata *conn, bool *done) if(result) return result; -#ifdef HAVE_STRFTIME if(fstated) { struct tm *tm; time_t clock = (time_t)statbuf.st_mtime; @@ -332,11 +332,17 @@ CURLcode Curl_file(struct connectdata *conn, bool *done) tm = gmtime(&clock); #endif /* format: "Tue, 15 Nov 1994 12:45:26 GMT" */ - strftime(buf, BUFSIZE-1, "Last-Modified: %a, %d %b %Y %H:%M:%S GMT\r\n", - tm); + snprintf(buf, BUFSIZE-1, + "Last-Modified: %s, %02d %s %4d %02d:%02d:%02d GMT\r\n", + Curl_wkday[tm->tm_wday?tm->tm_wday-1:6], + tm->tm_mday, + Curl_month[tm->tm_mon], + tm->tm_year + 1900, + tm->tm_hour, + tm->tm_min, + tm->tm_sec); result = Curl_client_write(data, CLIENTWRITE_BOTH, buf, 0); } -#endif return result; } diff --git a/lib/ftp.c b/lib/ftp.c index 8b628710a..82683aae6 100644 --- a/lib/ftp.c +++ b/lib/ftp.c @@ -94,6 +94,7 @@ #include "memory.h" #include "inet_ntop.h" #include "select.h" +#include "parsedate.h" /* for the week day and month names */ #if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL) #include "inet_ntoa_r.h" @@ -1738,7 +1739,6 @@ static CURLcode ftp_state_mdtm_resp(struct connectdata *conn, /* If we asked for a time of the file and we actually got one as well, we "emulate" a HTTP-style header in our output. */ -#ifdef HAVE_STRFTIME if(data->set.get_filetime && (data->info.filetime>=0) ) { struct tm *tm; time_t clock = (time_t)data->info.filetime; @@ -1749,13 +1749,19 @@ static CURLcode ftp_state_mdtm_resp(struct connectdata *conn, tm = gmtime(&clock); #endif /* format: "Tue, 15 Nov 1994 12:45:26" */ - strftime(buf, BUFSIZE-1, - "Last-Modified: %a, %d %b %Y %H:%M:%S GMT\r\n", tm); + snprintf(buf, BUFSIZE-1, + "Last-Modified: %s, %02d %s %4d %02d:%02d:%02d GMT\r\n", + Curl_wkday[tm->tm_wday?tm->tm_wday-1:6], + tm->tm_mday, + Curl_month[tm->tm_mon], + tm->tm_year + 1900, + tm->tm_hour, + tm->tm_min, + tm->tm_sec); result = Curl_client_write(data, CLIENTWRITE_BOTH, buf, 0); if(result) return result; } -#endif } break; default: diff --git a/lib/http.c b/lib/http.c index 051643126..706cf7e30 100644 --- a/lib/http.c +++ b/lib/http.c @@ -95,6 +95,7 @@ #include "http.h" #include "memory.h" #include "select.h" +#include "parsedate.h" /* for the week day and month names */ #define _MPRINTF_REPLACE /* use our functions only */ #include @@ -1783,7 +1784,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done) #endif if(data->set.timecondition) { - struct tm *thistime; + struct tm *tm; /* Phil Karn (Fri, 13 Apr 2001) pointed out that the If-Modified-Since * header family should have their times set in GMT as RFC2616 defines: @@ -1795,18 +1796,22 @@ CURLcode Curl_http(struct connectdata *conn, bool *done) #ifdef HAVE_GMTIME_R /* thread-safe version */ struct tm keeptime; - thistime = (struct tm *)gmtime_r(&data->set.timevalue, &keeptime); + tm = (struct tm *)gmtime_r(&data->set.timevalue, &keeptime); #else - thistime = gmtime(&data->set.timevalue); + tm = gmtime(&data->set.timevalue); #endif -#ifdef HAVE_STRFTIME /* format: "Tue, 15 Nov 1994 12:45:26 GMT" */ - strftime(buf, BUFSIZE-1, "%a, %d %b %Y %H:%M:%S GMT", thistime); -#else - /* TODO: Right, we *could* write a replacement here */ - strcpy(buf, "no strftime() support"); -#endif + snprintf(buf, BUFSIZE-1, + "%s, %02d %s %4d %02d:%02d:%02d GMT", + Curl_wkday[tm->tm_wday?tm->tm_wday-1:6], + tm->tm_mday, + Curl_month[tm->tm_mon], + tm->tm_year + 1900, + tm->tm_hour, + tm->tm_min, + tm->tm_sec); + switch(data->set.timecondition) { case CURL_TIMECOND_IFMODSINCE: default: diff --git a/lib/parsedate.c b/lib/parsedate.c index 198f70101..063d0c44a 100644 --- a/lib/parsedate.c +++ b/lib/parsedate.c @@ -86,14 +86,14 @@ static time_t Curl_parsedate(const char *date); -static const char * const wkday[] = - {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}; +const char * const Curl_wkday[] = +{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}; static const char * const weekday[] = - { "Monday", "Tuesday", "Wednesday", "Thursday", - "Friday", "Saturday", "Sunday" }; -static const char * const month[]= - { "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; +{ "Monday", "Tuesday", "Wednesday", "Thursday", + "Friday", "Saturday", "Sunday" }; +const char * const Curl_month[]= +{ "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; struct tzinfo { const char *name; @@ -161,7 +161,7 @@ static int checkday(char *check, size_t len) if(len > 3) what = &weekday[0]; else - what = &wkday[0]; + what = &Curl_wkday[0]; for(i=0; i<7; i++) { if(curl_strequal(check, what[0])) { found=TRUE; @@ -178,7 +178,7 @@ static int checkmonth(char *check) const char * const *what; bool found= FALSE; - what = &month[0]; + what = &Curl_month[0]; for(i=0; i<12; i++) { if(curl_strequal(check, what[0])) { found=TRUE; diff --git a/lib/parsedate.h b/lib/parsedate.h new file mode 100644 index 000000000..4738117a2 --- /dev/null +++ b/lib/parsedate.h @@ -0,0 +1,28 @@ +#ifndef __PARSEDATE_H +#define __PARSEDATEL_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + * $Id$ + ***************************************************************************/ +extern const char * const Curl_wkday[7]; +extern const char * const Curl_month[12]; + +#endif -- cgit v1.2.3