aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Reisner <d@falconindy.com>2011-01-29 22:12:33 -0500
committerKamil Dudka <kdudka@redhat.com>2011-01-31 14:29:48 +0100
commit99dcb11ed8bd78d3af47c6ce3cc6b1fa4c51fdf8 (patch)
treeec75b822599f59963eda4c01c47a3564dade4ac3
parent819dfddc58e22ea2248851bcd1b4605a0de2a9e4 (diff)
transfer: add Curl_meets_timecondition()
This will be used by file_do() and Curl_readwrite() as a unified method of checking to see if a remote document meets the supplied CURLOPT_TIMEVAL and CURLOPT_TIMECONDITION. Signed-off-by: Dave Reisner <d@falconindy.com>
-rw-r--r--lib/transfer.c59
-rw-r--r--lib/transfer.h1
2 files changed, 37 insertions, 23 deletions
diff --git a/lib/transfer.c b/lib/transfer.c
index e84b8b14c..f316000a1 100644
--- a/lib/transfer.c
+++ b/lib/transfer.c
@@ -355,6 +355,37 @@ 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
+ */
+bool Curl_meets_timecondition(struct SessionHandle *data, long timeofdoc)
+{
+ if((timeofdoc == 0) || (data->set.timevalue == 0))
+ return TRUE;
+
+ 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 FALSE;
+ }
+ 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 FALSE;
+ }
+ break;
+ }
+
+ return TRUE;
+}
/*
* Go ahead and do a read if we have a readable socket or if
@@ -518,29 +549,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)) {
+ *done = TRUE;
+ return CURLE_OK;
+ }
} /* we have a time condition */
} /* this is HTTP */
diff --git a/lib/transfer.h b/lib/transfer.h
index 790e1e3ef..c966cafb0 100644
--- a/lib/transfer.h
+++ b/lib/transfer.h
@@ -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);
+bool Curl_meets_timecondition(struct SessionHandle *data, long timeofdoc);
/* This sets up a forthcoming transfer */
void