* ecore: time to cleanup ecore_con_url time.
authorcedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Mon, 18 Oct 2010 16:39:12 +0000 (16:39 +0000)
committercedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Mon, 18 Oct 2010 16:39:12 +0000 (16:39 +0000)
Patch by Patch by Raphael Kubo da Costa <kubo@profusion.mobi>

As discussed on the development mailing list, we should accept a
double instead of a time_t for consistency with the rest of the API.
Some apidox has been added too, and as a result
ECORE_CON_URL_TIME_LASTMOD has been removed, since it does not make
much sense (it is an HTTP response header).

git-svn-id: http://svn.enlightenment.org/svn/e/trunk/ecore@53572 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/lib/ecore_con/Ecore_Con.h
src/lib/ecore_con/ecore_con_private.h
src/lib/ecore_con/ecore_con_url.c

index 2f6b0d1..11515de 100644 (file)
@@ -462,14 +462,27 @@ EAPI void              ecore_con_client_timeout_set(Ecore_Con_Client *cl, double
 /**
  * @typedef Ecore_Con_Url_Time
  * @enum _Ecore_Con_Url_Time
- * The type of time in the object
+ * The type of condition to use when making an HTTP request dependent on time,
+ * so that headers such as "If-Modified-Since" are used.
  */
 typedef enum _Ecore_Con_Url_Time
 {
+   /**
+    * Do not place time restrictions on the HTTP requests.
+    */
    ECORE_CON_URL_TIME_NONE = 0,
+   /**
+    * Add the "If-Modified-Since" HTTP header, so that the request is performed
+    * by the server only if the target has been modified since the time value
+    * passed to it in the request.
+    */
    ECORE_CON_URL_TIME_IFMODSINCE,
-   ECORE_CON_URL_TIME_IFUNMODSINCE,
-   ECORE_CON_URL_TIME_LASTMOD
+   /**
+    * Add the "If-Unmodified-Since" HTTP header, so that the request is
+    * performed by the server only if the target has NOT been modified since
+    * the time value passed to it in the request.
+    */
+   ECORE_CON_URL_TIME_IFUNMODSINCE
 } Ecore_Con_Url_Time;
 
 EAPI int               ecore_con_url_init(void);
@@ -498,8 +511,8 @@ EAPI Eina_Bool         ecore_con_url_send(Ecore_Con_Url *url_con,
                                           const void *data, size_t length,
                                           const char *content_type);
 EAPI void              ecore_con_url_time(Ecore_Con_Url *url_con,
-                                          Ecore_Con_Url_Time condition,
-                                          time_t tm);
+                                          Ecore_Con_Url_Time time_condition,
+                                          double timestamp);
 
 EAPI Eina_Bool         ecore_con_url_ftp_upload(Ecore_Con_Url *url_con,
                                                 const char *filename,
index 58d5da1..5eaaf47 100644 (file)
@@ -168,8 +168,8 @@ struct _Ecore_Con_Url
    Eina_List *response_headers;
    char *url;
 
-   Ecore_Con_Url_Time condition;
-   time_t time;
+   Ecore_Con_Url_Time time_condition;
+   double timestamp;
    void *data;
 
    Ecore_Fd_Handler *fd_handler;
index f97ff08..2ddbfad 100644 (file)
@@ -615,12 +615,18 @@ ecore_con_url_data_get(Ecore_Con_Url *url_con)
 }
 
 /**
- * FIXME
- * Sets the @ref Ecore_Con_Url object's condition/time members.
+ * Sets whether HTTP requests should be conditional, dependent on
+ * modification time.
+ *
+ * @param url_con   Ecore_Con_Url to act upon.
+ * @param condition Condition to use for HTTP requests.
+ * @param timestamp Time since 1 Jan 1970 to use in the condition.
+ *
+ * @sa ecore_con_url_send()
  */
 EAPI void
 ecore_con_url_time(Ecore_Con_Url *url_con, Ecore_Con_Url_Time condition,
-                   time_t tm)
+                   double timestamp)
 {
 #ifdef HAVE_CURL
    if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
@@ -629,13 +635,13 @@ ecore_con_url_time(Ecore_Con_Url *url_con, Ecore_Con_Url_Time condition,
         return;
      }
 
-   url_con->condition = condition;
-   url_con->time = tm;
+   url_con->time_condition = condition;
+   url_con->timestamp = timestamp;
 #else
    return;
-   url_con = NULL;
-   condition = 0;
-   tm = 0;
+   (void)url_con;
+   (void)condition;
+   (void)timestamp;
 #endif
 }
 
@@ -793,6 +799,7 @@ ecore_con_url_httpauth_set(Ecore_Con_Url *url_con, const char *username,
  * @see ecore_con_url_data_set()
  * @see ecore_con_url_data_get()
  * @see ecore_con_url_response_headers_get()
+ * @see ecore_con_url_time()
  */
 EAPI Eina_Bool
 ecore_con_url_send(Ecore_Con_Url *url_con, const void *data, size_t length,
@@ -838,7 +845,7 @@ ecore_con_url_send(Ecore_Con_Url *url_con, const void *data, size_t length,
         url_con->headers = curl_slist_append(url_con->headers, tmp);
      }
 
-   switch (url_con->condition)
+   switch (url_con->time_condition)
      {
       case ECORE_CON_URL_TIME_NONE:
          curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION,
@@ -848,19 +855,15 @@ ecore_con_url_send(Ecore_Con_Url *url_con, const void *data, size_t length,
       case ECORE_CON_URL_TIME_IFMODSINCE:
          curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION,
                           CURL_TIMECOND_IFMODSINCE);
-         curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMEVALUE, url_con->time);
+         curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMEVALUE,
+                          (long)url_con->timestamp);
          break;
 
       case ECORE_CON_URL_TIME_IFUNMODSINCE:
          curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION,
                           CURL_TIMECOND_IFUNMODSINCE);
-         curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMEVALUE, url_con->time);
-         break;
-
-      case ECORE_CON_URL_TIME_LASTMOD:
-         curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION,
-                          CURL_TIMECOND_LASTMOD);
-         curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMEVALUE, url_con->time);
+         curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMEVALUE,
+                          (long)url_con->timestamp);
          break;
      }