On 01/30/2011 12:50 AM, Daniel Stenberg wrote:
FYI,

As this isn't really to me personally...

Hi Daniel,

are you fine with the attached patches?

Kamil
>From 99dcb11ed8bd78d3af47c6ce3cc6b1fa4c51fdf8 Mon Sep 17 00:00:00 2001
From: Dave Reisner <[email protected]>
Date: Sat, 29 Jan 2011 22:12:33 -0500
Subject: [PATCH 1/2] 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 <[email protected]>
Signed-off-by: Kamil Dudka <[email protected]>
---
 lib/transfer.c |   59 ++++++++++++++++++++++++++++++++++---------------------
 lib/transfer.h |    1 +
 2 files changed, 37 insertions(+), 23 deletions(-)

diff --git a/lib/transfer.c b/lib/transfer.c
index e84b8b1..f316000 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 790e1e3..c966caf 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
-- 
1.7.3.5

>From b89122a2bf1663f16d0977977c83320470c6d438 Mon Sep 17 00:00:00 2001
From: Dave Reisner <[email protected]>
Date: Sat, 29 Jan 2011 22:41:07 -0500
Subject: [PATCH 2/2] file: add support for CURLOPT_TIMECONDITION


Signed-off-by: Kamil Dudka <[email protected]>
---
 docs/curl.1                     |    6 +++---
 docs/libcurl/curl_easy_setopt.3 |    4 ++--
 lib/file.c                      |    7 +++++++
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/docs/curl.1 b/docs/curl.1
index ba7f610..093fae5 100644
--- a/docs/curl.1
+++ b/docs/curl.1
@@ -1552,9 +1552,9 @@ not set.
 
 If this option is used several times, the last one will be used.
 .IP "-z/--time-cond <date expression>"
-(HTTP/FTP) Request a file that has been modified later than the given time and
-date, or one that has been modified before that time. The date expression can
-be all sorts of date strings or if it doesn't match any internal ones, it
+(HTTP/FTP/FILE) Request a file that has been modified later than the given time
+and date, or one that has been modified before that time. The date expression
+can be all sorts of date strings or if it doesn't match any internal ones, it
 tries to get the time from a given file name instead! See the
 \fIcurl_getdate(3)\fP man pages for date expression details.
 
diff --git a/docs/libcurl/curl_easy_setopt.3 b/docs/libcurl/curl_easy_setopt.3
index 95772d2..8c772c6 100644
--- a/docs/libcurl/curl_easy_setopt.3
+++ b/docs/libcurl/curl_easy_setopt.3
@@ -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
diff --git a/lib/file.c b/lib/file.c
index 8e4ee07..aaeed70 100644
--- a/lib/file.c
+++ b/lib/file.c
@@ -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)) {
+      *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. */
-- 
1.7.3.5

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Reply via email to