diff options
author | Daniel Stenberg <daniel@haxx.se> | 2018-01-25 23:05:24 +0100 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2018-01-30 08:29:59 +0100 |
commit | 8f69a9f28abf98a10a50b3bae5ba319660de82ee (patch) | |
tree | 2b0eea6d076cd97763f0ce5dde7feed742cfe142 | |
parent | 9caa3e248da91dc8964328b5b50491ba05df7bd4 (diff) | |
download | curl-8f69a9f28abf98a10a50b3bae5ba319660de82ee.tar.gz |
time: support > year 2038 time stamps for system with 32bit long
... with the introduction of CURLOPT_TIMEVALUE_LARGE and
CURLINFO_FILETIME_T.
Fixes #2238
Closes #2264
-rw-r--r-- | docs/libcurl/curl_easy_getinfo.3 | 7 | ||||
-rw-r--r-- | docs/libcurl/curl_easy_setopt.3 | 4 | ||||
-rw-r--r-- | docs/libcurl/opts/CURLINFO_FILETIME.3 | 11 | ||||
-rw-r--r-- | docs/libcurl/opts/CURLINFO_FILETIME_T.3 | 71 | ||||
-rw-r--r-- | docs/libcurl/opts/CURLOPT_TIMEVALUE.3 | 5 | ||||
-rw-r--r-- | docs/libcurl/opts/CURLOPT_TIMEVALUE_LARGE.3 | 64 | ||||
-rw-r--r-- | docs/libcurl/opts/Makefile.inc | 2 | ||||
-rw-r--r-- | docs/libcurl/symbols-in-versions | 2 | ||||
-rw-r--r-- | include/curl/curl.h | 7 | ||||
-rw-r--r-- | lib/curl_setup.h | 2 | ||||
-rw-r--r-- | lib/getinfo.c | 12 | ||||
-rw-r--r-- | lib/setopt.c | 8 | ||||
-rw-r--r-- | lib/smb.c | 13 | ||||
-rw-r--r-- | lib/urldata.h | 6 |
14 files changed, 193 insertions, 21 deletions
diff --git a/docs/libcurl/curl_easy_getinfo.3 b/docs/libcurl/curl_easy_getinfo.3 index 3edef83e2..c306937ae 100644 --- a/docs/libcurl/curl_easy_getinfo.3 +++ b/docs/libcurl/curl_easy_getinfo.3 @@ -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 diff --git a/docs/libcurl/curl_easy_setopt.3 b/docs/libcurl/curl_easy_setopt.3 index 2982056f0..0249e6bbc 100644 --- a/docs/libcurl/curl_easy_setopt.3 +++ b/docs/libcurl/curl_easy_setopt.3 @@ -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 diff --git a/docs/libcurl/opts/CURLINFO_FILETIME.3 b/docs/libcurl/opts/CURLINFO_FILETIME.3 index 8e1bb981f..3b13bd7e3 100644 --- a/docs/libcurl/opts/CURLINFO_FILETIME.3 +++ b/docs/libcurl/opts/CURLINFO_FILETIME.3 @@ -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 index 000000000..d8853ccd2 --- /dev/null +++ b/docs/libcurl/opts/CURLINFO_FILETIME_T.3 @@ -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), " diff --git a/docs/libcurl/opts/CURLOPT_TIMEVALUE.3 b/docs/libcurl/opts/CURLOPT_TIMEVALUE.3 index cd745ffa7..66c582d07 100644 --- a/docs/libcurl/opts/CURLOPT_TIMEVALUE.3 +++ b/docs/libcurl/opts/CURLOPT_TIMEVALUE.3 @@ -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 index 000000000..884b51236 --- /dev/null +++ b/docs/libcurl/opts/CURLOPT_TIMEVALUE_LARGE.3 @@ -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), " diff --git a/docs/libcurl/opts/Makefile.inc b/docs/libcurl/opts/Makefile.inc index f710b5eb3..22a54c399 100644 --- a/docs/libcurl/opts/Makefile.inc +++ b/docs/libcurl/opts/Makefile.inc @@ -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 \ diff --git a/docs/libcurl/symbols-in-versions b/docs/libcurl/symbols-in-versions index ab899b9b0..306b7a845 100644 --- a/docs/libcurl/symbols-in-versions +++ b/docs/libcurl/symbols-in-versions @@ -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 diff --git a/include/curl/curl.h b/include/curl/curl.h index 7680acd18..7e1bc4c94 100644 --- a/include/curl/curl.h +++ b/include/curl/curl.h @@ -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, diff --git a/lib/curl_setup.h b/lib/curl_setup.h index 100b8d40f..ecc0bb3df 100644 --- a/lib/curl_setup.h +++ b/lib/curl_setup.h @@ -438,7 +438,7 @@ # 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 diff --git a/lib/getinfo.c b/lib/getinfo.c index 862ced019..d280eebfa 100644 --- a/lib/getinfo.c +++ b/lib/getinfo.c @@ -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; diff --git a/lib/setopt.c b/lib/setopt.c index a5ef75c72..686e9dbce 100644 --- a/lib/setopt.c +++ b/lib/setopt.c @@ -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: /* @@ -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) diff --git a/lib/urldata.h b/lib/urldata.h index 5c04ad172..6c594fe8d 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -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 */ |