]> granicus.if.org Git - curl/commitdiff
time: support > year 2038 time stamps for system with 32bit long
authorDaniel Stenberg <daniel@haxx.se>
Thu, 25 Jan 2018 22:05:24 +0000 (23:05 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 30 Jan 2018 07:29:59 +0000 (08:29 +0100)
... with the introduction of CURLOPT_TIMEVALUE_LARGE and
CURLINFO_FILETIME_T.

Fixes #2238
Closes #2264

14 files changed:
docs/libcurl/curl_easy_getinfo.3
docs/libcurl/curl_easy_setopt.3
docs/libcurl/opts/CURLINFO_FILETIME.3
docs/libcurl/opts/CURLINFO_FILETIME_T.3 [new file with mode: 0644]
docs/libcurl/opts/CURLOPT_TIMEVALUE.3
docs/libcurl/opts/CURLOPT_TIMEVALUE_LARGE.3 [new file with mode: 0644]
docs/libcurl/opts/Makefile.inc
docs/libcurl/symbols-in-versions
include/curl/curl.h
lib/curl_setup.h
lib/getinfo.c
lib/setopt.c
lib/smb.c
lib/urldata.h

index 3edef83e2fb681f64535aa3bd7ceaea0587e8032..c306937ae291e2d82f3a8a302b81da5ea679d48e 100644 (file)
@@ -5,7 +5,7 @@
 .\" *                            | (__| |_| |  _ <| |___
 .\" *                             \___|\___/|_| \_\_____|
 .\" *
-.\" * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+.\" * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
 .\" *
 .\" * This software is licensed as described in the file COPYING, which
 .\" * you should have received as part of this distribution. The terms
@@ -54,8 +54,9 @@ See \fICURLINFO_HTTP_CONNECTCODE(3)\fP
 The http version used in the connection.
 See \fICURLINFO_HTTP_VERSION(3)\fP
 .IP CURLINFO_FILETIME
-Remote time of the retrieved document.
-See \fICURLINFO_FILETIME(3)\fP
+Remote time of the retrieved document. See \fICURLINFO_FILETIME(3)\fP
+.IP CURLINFO_FILETIME_T
+Remote time of the retrieved document. See \fICURLINFO_FILETIME_T(3)\fP
 .IP CURLINFO_TOTAL_TIME
 Total time of previous transfer.
 See \fICURLINFO_TOTAL_TIME(3)\fP
index 2982056f00db0e34116c08d633feaca6775e577f..0249e6bbc6fbd128319c539352630fff59212646 100644 (file)
@@ -5,7 +5,7 @@
 .\" *                            | (__| |_| |  _ <| |___
 .\" *                             \___|\___/|_| \_\_____|
 .\" *
-.\" * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+.\" * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
 .\" *
 .\" * This software is licensed as described in the file COPYING, which
 .\" * you should have received as part of this distribution. The terms
@@ -421,6 +421,8 @@ Maximum file size to get. See \fICURLOPT_MAXFILESIZE_LARGE(3)\fP
 Make a time conditional request. See \fICURLOPT_TIMECONDITION(3)\fP
 .IP CURLOPT_TIMEVALUE
 Time value for the time conditional request. See \fICURLOPT_TIMEVALUE(3)\fP
+.IP CURLOPT_TIMEVALUE_LARGE
+Time value for the time conditional request. See \fICURLOPT_TIMEVALUE_LARGE(3)\fP
 .SH CONNECTION OPTIONS
 .IP CURLOPT_TIMEOUT
 Timeout for the entire request. See \fICURLOPT_TIMEOUT(3)\fP
index 8e1bb981f1d2afe29903696317efd60b548d18aa..3b13bd7e311427c17cbca63a477b3d0852d04a71 100644 (file)
@@ -5,7 +5,7 @@
 .\" *                            | (__| |_| |  _ <| |___
 .\" *                             \___|\___/|_| \_\_____|
 .\" *
-.\" * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+.\" * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
 .\" *
 .\" * This software is licensed as described in the file COPYING, which
 .\" * you should have received as part of this distribution. The terms
@@ -34,9 +34,12 @@ Pass a pointer to a long to receive the remote time of the retrieved document
 hide it or the server doesn't support the command that tells document time
 etc) and the time of the document is unknown.
 
-Note that you must tell the server to collect this information before the
-transfer is made, by using the \fICURLOPT_FILETIME(3)\fP option to
-\fIcurl_easy_setopt(3)\fP or you will unconditionally get a -1 back.
+You must tell libcurl to collect this information before the transfer is made,
+by using the \fICURLOPT_FILETIME(3)\fP option to \fIcurl_easy_setopt(3)\fP or
+you will unconditionally get a -1 back.
+
+Consider using \fICURLINFO_FILETIME_T(3)\fP to be able to extract dates beyond
+the year 2038 on systems using 32 bit longs.
 .SH PROTOCOLS
 HTTP(S), FTP(S), SFTP
 .SH EXAMPLE
diff --git a/docs/libcurl/opts/CURLINFO_FILETIME_T.3 b/docs/libcurl/opts/CURLINFO_FILETIME_T.3
new file mode 100644 (file)
index 0000000..d8853cc
--- /dev/null
@@ -0,0 +1,71 @@
+.\" **************************************************************************
+.\" *                                  _   _ ____  _
+.\" *  Project                     ___| | | |  _ \| |
+.\" *                             / __| | | | |_) | |
+.\" *                            | (__| |_| |  _ <| |___
+.\" *                             \___|\___/|_| \_\_____|
+.\" *
+.\" * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, 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 https://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.
+.\" *
+.\" **************************************************************************
+.\"
+.TH CURLINFO_FILETIME 3 "25 Jan 2018" "libcurl 7.59.0" "curl_easy_getinfo options"
+.SH NAME
+CURLINFO_FILETIME_T \- get the remote time of the retrieved document
+.SH SYNOPSIS
+#include <curl/curl.h>
+
+CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_FILETIME_T, curl_off_t *timep);
+.SH DESCRIPTION
+Pass a pointer to a curl_off_t to receive the remote time of the retrieved
+document (in number of seconds since 1 jan 1970 in the GMT/UTC time zone). If
+you get -1, it can be because of many reasons (it might be unknown, the server
+might hide it or the server doesn't support the command that tells document
+time etc) and the time of the document is unknown.
+
+You must ask libcurl to collect this information before the transfer is made,
+by using the \fICURLOPT_FILETIME(3)\fP option to \fIcurl_easy_setopt(3)\fP or
+you will unconditionally get a -1 back.
+
+This option is an alternative to \fICURLINFO_FILETIME(3)\fP to allow systems
+with 32 bit long variables to extract dates outside of the 32bit timestamp
+range.
+.SH PROTOCOLS
+HTTP(S), FTP(S), SFTP
+.SH EXAMPLE
+.nf
+curl = curl_easy_init();
+if(curl) {
+  curl_easy_setopt(curl, CURLOPT_URL, url);
+  /* Ask for filetime */
+  curl_easy_setopt(curl, CURLOPT_FILETIME, 1L);
+  res = curl_easy_perform(curl);
+  if(CURLE_OK == res) {
+    curl_off_t filetime;
+    res = curl_easy_getinfo(curl, CURLINFO_FILETIME_T, &filetime);
+    if((CURLE_OK == res) && (filetime >= 0)) {
+      time_t file_time = (time_t)filetime;
+      printf("filetime %s: %s", filename, ctime(&file_time));
+    }
+  }
+  /* always cleanup */
+  curl_easy_cleanup(curl);
+}
+.fi
+.SH AVAILABILITY
+Added in 7.59.0
+.SH RETURN VALUE
+Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
+.SH "SEE ALSO"
+.BR curl_easy_getinfo "(3), " curl_easy_setopt "(3), "
index cd745ffa7a3a58c3eb8af80ec24e487c8fa7c305..66c582d075a2e712805f556ec86e6c5c98e8b005 100644 (file)
@@ -5,7 +5,7 @@
 .\" *                            | (__| |_| |  _ <| |___
 .\" *                             \___|\___/|_| \_\_____|
 .\" *
-.\" * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+.\" * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
 .\" *
 .\" * This software is licensed as described in the file COPYING, which
 .\" * you should have received as part of this distribution. The terms
@@ -31,6 +31,9 @@ CURLcode curl_easy_setopt(CURL *handle, CURLOPT_TIMEVALUE, long val);
 Pass a long \fIval\fP as parameter. This should be the time counted as seconds
 since 1 Jan 1970, and the time will be used in a condition as specified with
 \fICURLOPT_TIMECONDITION(3)\fP.
+
+On systems with 32 bit 'long' variables, this option cannot set dates beyond
+the year 2038. Consider \fICURLOPT_TIMEVALUE_LARGE(3)\fP instead.
 .SH DEFAULT
 0
 .SH PROTOCOLS
diff --git a/docs/libcurl/opts/CURLOPT_TIMEVALUE_LARGE.3 b/docs/libcurl/opts/CURLOPT_TIMEVALUE_LARGE.3
new file mode 100644 (file)
index 0000000..884b512
--- /dev/null
@@ -0,0 +1,64 @@
+.\" **************************************************************************
+.\" *                                  _   _ ____  _
+.\" *  Project                     ___| | | |  _ \| |
+.\" *                             / __| | | | |_) | |
+.\" *                            | (__| |_| |  _ <| |___
+.\" *                             \___|\___/|_| \_\_____|
+.\" *
+.\" * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, 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 https://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.
+.\" *
+.\" **************************************************************************
+.\"
+.TH CURLOPT_TIMEVALUE_LARGE 3 "25 Jan 2018" "libcurl 7.59.0" "curl_easy_setopt options"
+.SH NAME
+CURLOPT_TIMEVALUE_LARGE \- set time value for conditional
+.SH SYNOPSIS
+#include <curl/curl.h>
+
+CURLcode curl_easy_setopt(CURL *handle, CURLOPT_TIMEVALUE_LARGE, curl_off_t val);
+.SH DESCRIPTION
+Pass a curl_off_t \fIval\fP as parameter. This should be the time counted as
+seconds since 1 Jan 1970, and the time will be used in a condition as
+specified with \fICURLOPT_TIMECONDITION(3)\fP.
+
+The difference between this option and \fICURLOPT_TIMEVALUE(3)\fP is the type
+of the argument. On systems where 'long' is only 32 bit wide, this option has
+to be used to set dates beyond the year 2038.
+.SH DEFAULT
+0
+.SH PROTOCOLS
+HTTP, FTP, RTSP, and FILE
+.SH EXAMPLE
+.nf
+CURL *curl = curl_easy_init();
+if(curl) {
+  curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
+
+  /* January 1, 2020 is 1577833200 */
+  curl_easy_setopt(curl, CURLOPT_TIMEVALUE_LARGE, (curl_off_t)1577833200);
+
+  /* If-Modified-Since the above time stamp */
+  curl_easy_setopt(curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
+
+  /* Perform the request */
+  curl_easy_perform(curl);
+}
+.fi
+.SH AVAILABILITY
+Added in 7.59.0.
+.SH RETURN VALUE
+Returns CURLE_OK
+.SH "SEE ALSO"
+.BR CURLOPT_TIMECONDITION "(3), "
+.BR CURLOPT_TIMEVALUE_LARGE "(3), "
index f710b5eb398a863311448ddc71455c0c2d22e5ac..22a54c39930758395caf7082a7ad07a5c8fe9121 100644 (file)
@@ -14,6 +14,7 @@ man_MANS =                                      \
   CURLINFO_COOKIELIST.3                         \
   CURLINFO_EFFECTIVE_URL.3                      \
   CURLINFO_FILETIME.3                           \
+  CURLINFO_FILETIME_T.3                         \
   CURLINFO_FTP_ENTRY_PATH.3                     \
   CURLINFO_HEADER_SIZE.3                        \
   CURLINFO_HTTPAUTH_AVAIL.3                     \
@@ -301,6 +302,7 @@ man_MANS =                                      \
   CURLOPT_TIMEOUT.3                             \
   CURLOPT_TIMEOUT_MS.3                          \
   CURLOPT_TIMEVALUE.3                           \
+  CURLOPT_TIMEVALUE_LARGE.3                     \
   CURLOPT_TLSAUTH_PASSWORD.3                    \
   CURLOPT_TLSAUTH_TYPE.3                        \
   CURLOPT_TLSAUTH_USERNAME.3                    \
index ab899b9b0de5fa0405214ada449663141c9c4d02..306b7a845fb37f8864bd954cb43766f37e14fcc9 100644 (file)
@@ -220,6 +220,7 @@ CURLINFO_DOUBLE                 7.4.1
 CURLINFO_EFFECTIVE_URL          7.4
 CURLINFO_END                    7.9.6
 CURLINFO_FILETIME               7.5
+CURLINFO_FILETIME_T             7.59.0
 CURLINFO_FTP_ENTRY_PATH         7.15.4
 CURLINFO_HEADER_IN              7.9.6
 CURLINFO_HEADER_OUT             7.9.6
@@ -587,6 +588,7 @@ CURLOPT_TIMECONDITION           7.1
 CURLOPT_TIMEOUT                 7.1
 CURLOPT_TIMEOUT_MS              7.16.2
 CURLOPT_TIMEVALUE               7.1
+CURLOPT_TIMEVALUE_LARGE         7.59.0
 CURLOPT_TLSAUTH_PASSWORD        7.21.4
 CURLOPT_TLSAUTH_TYPE            7.21.4
 CURLOPT_TLSAUTH_USERNAME        7.21.4
index 7680acd18dba74d8688cdcef0d390d66c015bc61..7e1bc4c94dea5ce1b9306f63bffd21830a46d5d5 100644 (file)
@@ -7,7 +7,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -1819,6 +1819,10 @@ typedef enum {
   /* Post MIME data. */
   CINIT(MIMEPOST, OBJECTPOINT, 269),
 
+  /* Time to use with the CURLOPT_TIMECONDITION. Specified in number of
+     seconds since 1 Jan 1970. */
+  CINIT(TIMEVALUE_LARGE, OFF_T, 270),
+
   CURLOPT_LASTENTRY /* the last unused */
 } CURLoption;
 
@@ -2459,6 +2463,7 @@ typedef enum {
   CURLINFO_REQUEST_SIZE     = CURLINFO_LONG   + 12,
   CURLINFO_SSL_VERIFYRESULT = CURLINFO_LONG   + 13,
   CURLINFO_FILETIME         = CURLINFO_LONG   + 14,
+  CURLINFO_FILETIME_T       = CURLINFO_OFF_T  + 14,
   CURLINFO_CONTENT_LENGTH_DOWNLOAD   = CURLINFO_DOUBLE + 15,
   CURLINFO_CONTENT_LENGTH_DOWNLOAD_T = CURLINFO_OFF_T  + 15,
   CURLINFO_CONTENT_LENGTH_UPLOAD     = CURLINFO_DOUBLE + 16,
index 100b8d40f322201026064e914129858d103f4d19..ecc0bb3dfd18a9ec25ef9b229955606426d34915 100644 (file)
 #  define TIME_T_MIN 0
 #  else
 #  define TIME_T_MAX 0x7FFFFFFFFFFFFFFF
-#  define TIME_T_MIN -0x10000000000000000
+#  define TIME_T_MIN (-TIME_T_MAX - 1)
 #  endif
 #endif
 
index 862ced0194a26b4e64282dfd43e7d5930056a499..d280eebfafaeb16737ef4c64f0bbd6914c201066 100644 (file)
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -156,7 +156,12 @@ static CURLcode getinfo_long(struct Curl_easy *data, CURLINFO info,
     *param_longp = data->info.httpproxycode;
     break;
   case CURLINFO_FILETIME:
-    *param_longp = data->info.filetime;
+    if(data->info.filetime > LONG_MAX)
+      *param_longp = LONG_MAX;
+    else if(data->info.filetime < LONG_MIN)
+      *param_longp = LONG_MIN;
+    else
+      *param_longp = (long)data->info.filetime;
     break;
   case CURLINFO_HEADER_SIZE:
     *param_longp = data->info.header_size;
@@ -253,6 +258,9 @@ static CURLcode getinfo_offt(struct Curl_easy *data, CURLINFO info,
                              curl_off_t *param_offt)
 {
   switch(info) {
+  case CURLINFO_FILETIME_T:
+    *param_offt = (curl_off_t)data->info.filetime;
+    break;
   case CURLINFO_SIZE_UPLOAD_T:
     *param_offt = data->progress.uploaded;
     break;
index a5ef75c722a946a39140bfc882ea0c1584279175..686e9dbcee9c3631f3e12fec3d4ebbeabff6f3aa 100644 (file)
@@ -361,6 +361,14 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option,
     data->set.timevalue = (time_t)va_arg(param, long);
     break;
 
+  case CURLOPT_TIMEVALUE_LARGE:
+    /*
+     * This is the value to compare with the remote document with the
+     * method set with CURLOPT_TIMECONDITION
+     */
+    data->set.timevalue = (time_t)va_arg(param, curl_off_t);
+    break;
+
   case CURLOPT_SSLVERSION:
   case CURLOPT_PROXY_SSLVERSION:
     /*
index 6cb4083bb2d5170e86af9c7635d9da796278a26f..e5ac5d76a876f223e2bd9d130e0a2602567b6117 100644 (file)
--- a/lib/smb.c
+++ b/lib/smb.c
@@ -709,14 +709,19 @@ static CURLcode smb_connection_state(struct connectdata *conn, bool *done)
 }
 
 /*
- * Convert a timestamp from the Windows world (100 nsec units from
- * 1 Jan 1601) to Posix time.
+ * Convert a timestamp from the Windows world (100 nsec units from 1 Jan 1601)
+ * to Posix time. Cap the output to fit within a time_t.
  */
-static void get_posix_time(long *out, curl_off_t timestamp)
+static void get_posix_time(time_t *out, curl_off_t timestamp)
 {
   timestamp -= 116444736000000000;
   timestamp /= 10000000;
-  *out = (long) timestamp;
+  if(timestamp > TIME_T_MAX)
+    *out = TIME_T_MAX;
+  else if(timestamp < TIME_T_MIN)
+    *out = TIME_T_MIN;
+  else
+    *out = (time_t) timestamp;
 }
 
 static CURLcode smb_request_state(struct connectdata *conn, bool *done)
index 5c04ad172064e573284d91e2ce7d544f1896a1ad..6c594fe8d9dcef82915ebb90609814335bd92c49 100644 (file)
@@ -1024,10 +1024,8 @@ struct PureInfo {
   int httpcode;  /* Recent HTTP, FTP, RTSP or SMTP response code */
   int httpproxycode; /* response code from proxy when received separate */
   int httpversion; /* the http version number X.Y = X*10+Y */
-  long filetime; /* If requested, this is might get set. Set to -1 if the time
-                    was unretrievable. We cannot have this of type time_t,
-                    since time_t is unsigned on several platforms such as
-                    OpenVMS. */
+  time_t filetime; /* If requested, this is might get set. Set to -1 if the
+                      time was unretrievable. */
   bool timecond;  /* set to TRUE if the time condition didn't match, which
                      thus made the document NOT get fetched */
   long header_size;  /* size of read header(s) in bytes */