mirror of
https://github.com/moparisthebest/curl
synced 2025-01-10 21:48:10 -05:00
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
This commit is contained in:
parent
9caa3e248d
commit
8f69a9f28a
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
71
docs/libcurl/opts/CURLINFO_FILETIME_T.3
Normal file
71
docs/libcurl/opts/CURLINFO_FILETIME_T.3
Normal file
@ -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), "
|
@ -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
|
||||
|
64
docs/libcurl/opts/CURLOPT_TIMEVALUE_LARGE.3
Normal file
64
docs/libcurl/opts/CURLOPT_TIMEVALUE_LARGE.3
Normal file
@ -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), "
|
@ -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 \
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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:
|
||||
/*
|
||||
|
13
lib/smb.c
13
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)
|
||||
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user