Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/libcurl/curl_easy_setopt.3
Original file line number Diff line number Diff line change
Expand Up @@ -1648,8 +1648,8 @@ given limit. This concerns both FTP and HTTP transfers.
.IP CURLOPT_TIMECONDITION
Pass a long as parameter. This defines how the \fICURLOPT_TIMEVALUE\fP time
value is treated. You can set this parameter to \fICURL_TIMECOND_IFMODSINCE\fP
or \fICURL_TIMECOND_IFUNMODSINCE\fP. This feature applies to HTTP, FTP, and
RTSP.
or \fICURL_TIMECOND_IFUNMODSINCE\fP. This feature applies to HTTP, FTP, RTSP,
and FILE.

The last modification time of a file is not always known and in such instances
this feature will have no effect even if the given time condition would not
Expand Down
7 changes: 7 additions & 0 deletions lib/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,13 @@ static CURLcode file_do(struct connectdata *conn, bool *done)
fstated = TRUE;
}

if(fstated && !data->state.range && data->set.timecondition) {
if(Curl_meets_timecondition(data, data->info.filetime) == 0) {
*done = TRUE;
return CURLE_OK;
}
}

/* If we have selected NOBODY and HEADER, it means that we only want file
information. Which for FILE can't be much more than the file size and
date. */
Expand Down
60 changes: 37 additions & 23 deletions lib/transfer.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,38 @@ static void read_rewind(struct connectdata *conn,
#endif
}

/*
* Check to see if CURLOPT_TIMECONDITION was met by comparing the time of the
* remote document with the time provided by CURLOPT_TIMEVAL
*/
int Curl_meets_timecondition(struct SessionHandle *data, long timeofdoc)
{
if((timeofdoc == 0) || (data->set.timevalue == 0)) {
return -1;
}

switch(data->set.timecondition) {
case CURL_TIMECOND_IFMODSINCE:
default:
if(timeofdoc <= data->set.timevalue) {
infof(data,
"The requested document is not new enough\n");
data->info.timecond = TRUE;
return 0;
}
break;
case CURL_TIMECOND_IFUNMODSINCE:
if(timeofdoc >= data->set.timevalue) {
infof(data,
"The requested document is not old enough\n");
data->info.timecond = TRUE;
return 0;
}
break;
}

return -1;
}

/*
* Go ahead and do a read if we have a readable socket or if
Expand Down Expand Up @@ -518,29 +550,11 @@ static CURLcode readwrite_data(struct SessionHandle *data,
requested. This seems to be what chapter 13.3.4 of
RFC 2616 defines to be the correct action for a
HTTP/1.1 client */
if((k->timeofdoc > 0) && (data->set.timevalue > 0)) {
switch(data->set.timecondition) {
case CURL_TIMECOND_IFMODSINCE:
default:
if(k->timeofdoc < data->set.timevalue) {
infof(data,
"The requested document is not new enough\n");
*done = TRUE;
data->info.timecond = TRUE;
return CURLE_OK;
}
break;
case CURL_TIMECOND_IFUNMODSINCE:
if(k->timeofdoc > data->set.timevalue) {
infof(data,
"The requested document is not old enough\n");
*done = TRUE;
data->info.timecond = TRUE;
return CURLE_OK;
}
break;
} /* switch */
} /* two valid time strings */

if(Curl_meets_timecondition(data, k->timeofdoc) == 0) {
*done = TRUE;
return CURLE_OK;
}
} /* we have a time condition */

} /* this is HTTP */
Expand Down
1 change: 1 addition & 0 deletions lib/transfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ CURLcode Curl_readrewind(struct connectdata *conn);
CURLcode Curl_fillreadbuffer(struct connectdata *conn, int bytes, int *nreadp);
CURLcode Curl_reconnect_request(struct connectdata **connp);
CURLcode Curl_retry_request(struct connectdata *conn, char **url);
int Curl_meets_timecondition(struct SessionHandle *data, long timeofdoc);

/* This sets up a forthcoming transfer */
void
Expand Down