From pasi.eronen@hut.fi Sun Aug 3 14:32:59 1997 Date: Fri, 1 Aug 1997 21:15:48 +0300 (EEST) From: Pasi Eronen To: htdig@sdsu.edu Subject: htdig: Bug in Document::getdate() Hello! There's a bug in HTDig 3.0.8b1's date parsing routine, Document::getdate() in htdig/Document.cc, at least on some platforms. As a result of this, the If-Modified-Since header in the HTTP request is incorrect, and everything is always read again. I'm running IRIX 5.3 with configuration HAVE_MKTIME=1, HAVE_TIMEGM=0, HAVE_LOCALTIME=1 and HAVE_TIMELOCAL=0. The date itself is parsed correctly (when debug>2, the original and translated dates printed are the same), but the conversion to Unix timestamp doesn't correctly handle the timezone. I wonder why this hasn't been noticed before...? As far as I can tell, it should affect everyone who's not running a BSD-variant of Unix (one with tm_gmtoff field). If you test these patches, please tell me did they work or not! The patches (three of them): [removed, since they are in the .tar.gz file anyway] You need to run autoconf after patching configure.in, of course. And I don't think it's necessary to check for mktime() and localtime(), or are there really systems that don't have these? Again, comments are welcome. Best regards, Pasi --- Pasi Eronen , 050-5123499 *** ../htdig-3.0.8b1.orig/configure.in Mon Mar 24 00:44:03 1997 --- configure.in Fri Aug 1 20:17:05 1997 *************** *** 53,58 **** AC_STRUCT_TM dnl Checks for library functions. ! AC_CHECK_FUNCS(mktime timelocal localtime gmtime) HTDIG_TOP=`pwd` --- 53,71 ---- AC_STRUCT_TM + dnl Check for timegm + AC_CHECK_FUNCS(timegm) + + AC_MSG_CHECKING(for timezone) + AC_TRY_COMPILE([#include ], [return timezone;], + [AC_MSG_RESULT(yes);AC_DEFINE(HAVE_TIMEZONE)], + [AC_MSG_RESULT(no)]) + + AC_MSG_CHECKING(for altzone) + AC_TRY_COMPILE([#include ], [return altzone;], + [AC_MSG_RESULT(yes);AC_DEFINE(HAVE_ALTZONE)], + [AC_MSG_RESULT(no)]) + dnl Checks for library functions. ! dnl AC_CHECK_FUNCS(mktime timelocal localtime gmtime) HTDIG_TOP=`pwd` *** ../htdig-3.0.8b1.orig/htdig/Document.cc Sun Apr 20 18:25:28 1997 --- htdig/Document.cc Fri Aug 1 20:49:46 1997 *************** *** 188,196 **** time_t now = time(0); - #if HAVE_LOCALTIME struct tm *tm = localtime(&now); - #else - struct tm *tm = gmtime(&now); - #endif #if HAVE_TM_GMTOFF tm->tm_zone = "GMT"; --- 188,192 ---- *************** *** 198,202 **** #endif mystrptime(d.get(), "%a, %d %b %Y %T", tm); - if (tm->tm_year < 0) tm->tm_year += 1900; --- 194,197 ---- *************** *** 209,217 **** cout << buffer << " (" << tm->tm_year << ")" << endl; } ! #if HAVE_MKTIME ! return mktime(tm); #else ! return timelocal(tm); #endif } --- 204,228 ---- cout << buffer << " (" << tm->tm_year << ")" << endl; } ! time_t ret; ! #if HAVE_TM_GMTOFF ! ret = mktime(tm); ! #elif HAVE_TIMEGM ! ret = timegm(tm); ! #elif HAVE_TIMEZONE && HAVE_ALTZONE ! ret = mktime(tm) - (daylight ? altzone : timezone); ! #elif HAVE_TIMEZONE ! ret = mktime(tm) - (tm->tm_isdst ? (timezone-3600) : timezone); #else ! #error Must have either timezone, tm.tm_gmtoff or timegm()! #endif + if (debug > 2) + { + cout << "And converted to "; + tm = gmtime(&ret); + char buffer[100]; + strftime(buffer, sizeof(buffer), "%a, %d %b %Y %T", tm); + cout << buffer << endl; + } + return ret; } *** ../htdig-3.0.8b1.orig/include/htconfig.h.in Fri Feb 7 11:26:51 1997 --- include/htconfig.h.in Fri Aug 1 20:21:36 1997 *************** *** 11,26 **** #define TM_IN_SYS_TIME 0 - /* Define if you have the mktime function. */ - #define HAVE_MKTIME 0 - /* Define if you have the timegm function. */ #define HAVE_TIMEGM 0 - /* Define if you have the localtime function. */ - #define HAVE_LOCALTIME 0 - - /* Define if you have the timelocal function. */ - #define HAVE_TIMELOCAL 0 - /* Define if you have the header file. */ #define HAVE_FCNTL_H 0 --- 11,17 ---- *************** *** 46,49 **** --- 37,46 ---- /* Define if you have the tm.tm_gmtoff member of struct tm. */ #define HAVE_TM_GMTOFF 0 + + /* Define if you have timezone variable in time.h. */ + #define HAVE_TIMEZONE 0 + + /* Define if you have altzone variable in time.h. */ + #define HAVE_ALTZONE 0 /* Define if you need a prototype for gethostname() */