* ecore: time to cleanup ecore_con_url time.

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).


SVN revision: 53572
This commit is contained in:
Cedric BAIL 2010-10-18 16:39:12 +00:00
parent 7100d4ac62
commit 515f06978b
3 changed files with 40 additions and 24 deletions

View File

@ -462,14 +462,27 @@ EAPI void ecore_con_client_timeout_set(Ecore_Con_Client *cl, double
/** /**
* @typedef Ecore_Con_Url_Time * @typedef Ecore_Con_Url_Time
* @enum _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 typedef enum _Ecore_Con_Url_Time
{ {
/**
* Do not place time restrictions on the HTTP requests.
*/
ECORE_CON_URL_TIME_NONE = 0, 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_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; } Ecore_Con_Url_Time;
EAPI int ecore_con_url_init(void); 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 void *data, size_t length,
const char *content_type); const char *content_type);
EAPI void ecore_con_url_time(Ecore_Con_Url *url_con, EAPI void ecore_con_url_time(Ecore_Con_Url *url_con,
Ecore_Con_Url_Time condition, Ecore_Con_Url_Time time_condition,
time_t tm); double timestamp);
EAPI Eina_Bool ecore_con_url_ftp_upload(Ecore_Con_Url *url_con, EAPI Eina_Bool ecore_con_url_ftp_upload(Ecore_Con_Url *url_con,
const char *filename, const char *filename,

View File

@ -168,8 +168,8 @@ struct _Ecore_Con_Url
Eina_List *response_headers; Eina_List *response_headers;
char *url; char *url;
Ecore_Con_Url_Time condition; Ecore_Con_Url_Time time_condition;
time_t time; double timestamp;
void *data; void *data;
Ecore_Fd_Handler *fd_handler; Ecore_Fd_Handler *fd_handler;

View File

@ -615,12 +615,18 @@ ecore_con_url_data_get(Ecore_Con_Url *url_con)
} }
/** /**
* FIXME * Sets whether HTTP requests should be conditional, dependent on
* Sets the @ref Ecore_Con_Url object's condition/time members. * 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 EAPI void
ecore_con_url_time(Ecore_Con_Url *url_con, Ecore_Con_Url_Time condition, ecore_con_url_time(Ecore_Con_Url *url_con, Ecore_Con_Url_Time condition,
time_t tm) double timestamp)
{ {
#ifdef HAVE_CURL #ifdef HAVE_CURL
if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 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; return;
} }
url_con->condition = condition; url_con->time_condition = condition;
url_con->time = tm; url_con->timestamp = timestamp;
#else #else
return; return;
url_con = NULL; (void)url_con;
condition = 0; (void)condition;
tm = 0; (void)timestamp;
#endif #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_set()
* @see ecore_con_url_data_get() * @see ecore_con_url_data_get()
* @see ecore_con_url_response_headers_get() * @see ecore_con_url_response_headers_get()
* @see ecore_con_url_time()
*/ */
EAPI Eina_Bool EAPI Eina_Bool
ecore_con_url_send(Ecore_Con_Url *url_con, const void *data, size_t length, 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); 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: case ECORE_CON_URL_TIME_NONE:
curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION, 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: case ECORE_CON_URL_TIME_IFMODSINCE:
curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION, curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION,
CURL_TIMECOND_IFMODSINCE); 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; break;
case ECORE_CON_URL_TIME_IFUNMODSINCE: case ECORE_CON_URL_TIME_IFUNMODSINCE:
curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION, curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION,
CURL_TIMECOND_IFUNMODSINCE); CURL_TIMECOND_IFUNMODSINCE);
curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMEVALUE, url_con->time); curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMEVALUE,
break; (long)url_con->timestamp);
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);
break; break;
} }