2008-05-25 22:16:34 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2011-12-06 08:09:05 -08:00
|
|
|
#include <stdlib.h>
|
2009-01-31 10:33:39 -08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2010-04-05 01:26:48 -07:00
|
|
|
#ifdef BUILD_ECORE_CON
|
|
|
|
# include "Ecore_Con.h"
|
|
|
|
#endif
|
|
|
|
|
2005-06-15 18:54:12 -07:00
|
|
|
#include "ecore_file_private.h"
|
|
|
|
|
2009-10-14 10:29:13 -07:00
|
|
|
#ifdef BUILD_ECORE_CON
|
|
|
|
|
2010-09-30 00:25:06 -07:00
|
|
|
#define ECORE_MAGIC_FILE_DOWNLOAD_JOB 0xf7427cb8
|
2011-12-20 22:18:25 -08:00
|
|
|
#define ECORE_FILE_DOWNLOAD_TIMEOUT 30
|
2005-06-17 16:52:32 -07:00
|
|
|
|
|
|
|
struct _Ecore_File_Download_Job
|
|
|
|
{
|
2008-03-09 09:43:32 -07:00
|
|
|
ECORE_MAGIC;
|
|
|
|
|
2010-09-30 00:25:06 -07:00
|
|
|
Ecore_Con_Url *url_con;
|
|
|
|
FILE *file;
|
2008-03-09 09:43:32 -07:00
|
|
|
|
2010-09-30 00:25:06 -07:00
|
|
|
char *dst;
|
2008-03-09 09:43:32 -07:00
|
|
|
|
2010-10-23 04:33:56 -07:00
|
|
|
Ecore_File_Download_Completion_Cb completion_cb;
|
|
|
|
Ecore_File_Download_Progress_Cb progress_cb;
|
2005-06-17 16:52:32 -07:00
|
|
|
};
|
|
|
|
|
2008-03-09 09:43:32 -07:00
|
|
|
#ifdef HAVE_CURL
|
2005-06-17 16:52:32 -07:00
|
|
|
Ecore_File_Download_Job *_ecore_file_download_curl(const char *url, const char *dst,
|
2010-10-23 04:33:56 -07:00
|
|
|
Ecore_File_Download_Completion_Cb completion_cb,
|
|
|
|
Ecore_File_Download_Progress_Cb progress_cb,
|
2011-02-16 04:44:34 -08:00
|
|
|
void *data,
|
|
|
|
Eina_Hash *headers);
|
2005-06-17 16:52:32 -07:00
|
|
|
|
2010-06-24 09:15:56 -07:00
|
|
|
static Eina_Bool _ecore_file_download_url_complete_cb(void *data, int type, void *event);
|
|
|
|
static Eina_Bool _ecore_file_download_url_progress_cb(void *data, int type, void *event);
|
2005-06-17 16:52:32 -07:00
|
|
|
#endif
|
|
|
|
|
2010-09-30 00:25:06 -07:00
|
|
|
static Ecore_Event_Handler *_url_complete_handler = NULL;
|
|
|
|
static Ecore_Event_Handler *_url_progress_download = NULL;
|
|
|
|
static Eina_List *_job_list;
|
2008-03-09 09:43:32 -07:00
|
|
|
|
2009-10-14 10:29:13 -07:00
|
|
|
#endif /* BUILD_ECORE_CON */
|
|
|
|
|
2009-10-09 22:28:43 -07:00
|
|
|
int
|
2005-06-17 16:52:32 -07:00
|
|
|
ecore_file_download_init(void)
|
|
|
|
{
|
2009-10-14 10:29:13 -07:00
|
|
|
#ifdef BUILD_ECORE_CON
|
2009-10-09 22:28:43 -07:00
|
|
|
if (!ecore_con_url_init())
|
|
|
|
return 0;
|
2005-09-07 01:50:25 -07:00
|
|
|
|
2009-10-14 10:29:13 -07:00
|
|
|
# ifdef HAVE_CURL
|
2009-10-09 22:28:43 -07:00
|
|
|
_url_complete_handler = ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE, _ecore_file_download_url_complete_cb, NULL);
|
|
|
|
_url_progress_download = ecore_event_handler_add(ECORE_CON_EVENT_URL_PROGRESS, _ecore_file_download_url_progress_cb, NULL);
|
2009-10-14 10:29:13 -07:00
|
|
|
# endif
|
|
|
|
|
|
|
|
#endif /* BUILD_ECORE_CON */
|
2008-03-09 09:43:32 -07:00
|
|
|
|
|
|
|
return 1;
|
2005-06-17 16:52:32 -07:00
|
|
|
}
|
|
|
|
|
2009-10-09 22:28:43 -07:00
|
|
|
void
|
2005-06-17 16:52:32 -07:00
|
|
|
ecore_file_download_shutdown(void)
|
|
|
|
{
|
2009-10-14 10:29:13 -07:00
|
|
|
#ifdef BUILD_ECORE_CON
|
2009-10-09 22:28:43 -07:00
|
|
|
if (_url_complete_handler)
|
|
|
|
ecore_event_handler_del(_url_complete_handler);
|
|
|
|
if (_url_progress_download)
|
|
|
|
ecore_event_handler_del(_url_progress_download);
|
|
|
|
_url_complete_handler = NULL;
|
|
|
|
_url_progress_download = NULL;
|
|
|
|
ecore_file_download_abort_all();
|
|
|
|
|
|
|
|
ecore_con_url_shutdown();
|
2009-10-14 10:29:13 -07:00
|
|
|
#endif /* BUILD_ECORE_CON */
|
2005-06-17 16:52:32 -07:00
|
|
|
}
|
|
|
|
|
2011-02-23 23:52:25 -08:00
|
|
|
#ifdef BUILD_ECORE_CON
|
|
|
|
# ifdef HAVE_CURL
|
2011-02-16 04:44:34 -08:00
|
|
|
static Eina_Bool
|
|
|
|
_ecore_file_download_headers_foreach_cb(const Eina_Hash *hash __UNUSED__, const void *key, void *data, void *fdata)
|
|
|
|
{
|
|
|
|
Ecore_File_Download_Job *job = fdata;
|
|
|
|
ecore_con_url_additional_header_add(job->url_con, key, data);
|
2006-09-08 09:52:29 -07:00
|
|
|
|
2011-02-16 04:44:34 -08:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
2011-02-23 23:52:25 -08:00
|
|
|
# endif
|
|
|
|
#endif
|
2011-02-16 04:44:34 -08:00
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_ecore_file_download(const char *url,
|
|
|
|
const char *dst,
|
|
|
|
Ecore_File_Download_Completion_Cb completion_cb,
|
|
|
|
Ecore_File_Download_Progress_Cb progress_cb,
|
|
|
|
void *data,
|
|
|
|
Ecore_File_Download_Job **job_ret,
|
|
|
|
Eina_Hash *headers)
|
2005-06-15 18:54:12 -07:00
|
|
|
{
|
2009-10-14 10:29:13 -07:00
|
|
|
#ifdef BUILD_ECORE_CON
|
2007-11-07 13:15:11 -08:00
|
|
|
char *dir = ecore_file_dir_get(dst);
|
|
|
|
|
|
|
|
if (!ecore_file_is_dir(dir))
|
|
|
|
{
|
2011-11-08 17:03:09 -08:00
|
|
|
ERR("%s is not a directory", dir);
|
2010-09-30 00:25:06 -07:00
|
|
|
free(dir);
|
|
|
|
return EINA_FALSE;
|
2007-11-07 13:15:11 -08:00
|
|
|
}
|
|
|
|
free(dir);
|
2011-01-29 14:46:23 -08:00
|
|
|
if (ecore_file_exists(dst))
|
|
|
|
{
|
2011-11-08 17:03:09 -08:00
|
|
|
WRN("%s already exists", dst);
|
2011-01-31 09:29:24 -08:00
|
|
|
return EINA_FALSE;
|
2011-01-29 14:46:23 -08:00
|
|
|
}
|
2005-06-15 18:54:12 -07:00
|
|
|
|
|
|
|
if (!strncmp(url, "file://", 7))
|
|
|
|
{
|
2010-09-30 00:25:06 -07:00
|
|
|
/* FIXME: Maybe fork? Might take a while to copy.
|
|
|
|
* Check filesize? */
|
|
|
|
/* Just copy it */
|
|
|
|
|
|
|
|
url += 7;
|
|
|
|
/* skip hostname */
|
|
|
|
url = strchr(url, '/');
|
|
|
|
return ecore_file_cp(url, dst);
|
2005-06-17 16:52:32 -07:00
|
|
|
}
|
2009-10-14 10:29:13 -07:00
|
|
|
# ifdef HAVE_CURL
|
2011-01-29 14:46:23 -08:00
|
|
|
else if ((!strncmp(url, "http://", 7)) || (!strncmp(url, "https://", 8)) ||
|
2010-09-30 00:25:06 -07:00
|
|
|
(!strncmp(url, "ftp://", 6)))
|
2005-06-17 16:52:32 -07:00
|
|
|
{
|
2010-09-30 00:25:06 -07:00
|
|
|
/* download */
|
|
|
|
Ecore_File_Download_Job *job;
|
2007-11-07 13:15:11 -08:00
|
|
|
|
2011-02-16 04:44:34 -08:00
|
|
|
job = _ecore_file_download_curl(url, dst, completion_cb, progress_cb, data, headers);
|
2010-09-30 00:25:06 -07:00
|
|
|
if(job_ret) *job_ret = job;
|
2011-01-29 14:46:23 -08:00
|
|
|
if(job)
|
|
|
|
return EINA_TRUE;
|
|
|
|
else
|
|
|
|
{
|
2011-11-08 17:03:09 -08:00
|
|
|
ERR("no job returned\n");
|
2011-01-29 14:46:23 -08:00
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
2010-09-30 00:25:06 -07:00
|
|
|
return job ? EINA_TRUE : EINA_FALSE;
|
2005-06-15 18:54:12 -07:00
|
|
|
}
|
2010-10-27 13:34:36 -07:00
|
|
|
# else
|
2011-01-29 14:46:23 -08:00
|
|
|
else if ((!strncmp(url, "http://", 7)) || (!strncmp(url, "https://", 8)) ||
|
2010-10-27 13:34:36 -07:00
|
|
|
(!strncmp(url, "ftp://", 6)))
|
|
|
|
{
|
|
|
|
(void)completion_cb;
|
|
|
|
(void)progress_cb;
|
|
|
|
(void)data;
|
|
|
|
(void)job_ret;
|
2011-08-18 03:59:12 -07:00
|
|
|
(void)headers;
|
2010-10-27 13:56:00 -07:00
|
|
|
return EINA_FALSE;
|
2010-10-27 13:34:36 -07:00
|
|
|
}
|
2009-10-14 10:29:13 -07:00
|
|
|
# endif
|
2005-06-15 18:54:12 -07:00
|
|
|
else
|
|
|
|
{
|
2010-09-30 00:25:06 -07:00
|
|
|
return EINA_FALSE;
|
2005-06-15 18:54:12 -07:00
|
|
|
}
|
2009-10-14 10:29:13 -07:00
|
|
|
#else
|
2011-08-18 03:59:12 -07:00
|
|
|
(void)url;
|
|
|
|
(void)dst;
|
|
|
|
(void)completion_cb;
|
|
|
|
(void)progress_cb;
|
|
|
|
(void)data;
|
|
|
|
(void)job_ret;
|
|
|
|
(void)headers;
|
2010-09-24 22:34:26 -07:00
|
|
|
return EINA_FALSE;
|
2009-10-14 10:29:13 -07:00
|
|
|
#endif /* BUILD_ECORE_CON */
|
2005-06-15 18:54:12 -07:00
|
|
|
}
|
2005-06-17 16:52:32 -07:00
|
|
|
|
2011-02-16 04:44:34 -08:00
|
|
|
/**
|
|
|
|
* @addtogroup Ecore_File_Group Ecore_File - Files and directories convenience functions
|
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Download the given url to the given destination.
|
|
|
|
*
|
|
|
|
* @param url The complete url to download.
|
|
|
|
* @param dst The local file to save the downloaded to.
|
|
|
|
* @param completion_cb A callback called on download complete.
|
|
|
|
* @param progress_cb A callback called during the download operation.
|
|
|
|
* @param data User data passed to both callbacks.
|
|
|
|
* @param job_ret Job used to abort the download.
|
|
|
|
* @return EINA_TRUE if the download start or EINA_FALSE on failure
|
|
|
|
*
|
|
|
|
* This function starts the download of the URL @p url and saves it to
|
|
|
|
* @p dst. @p url must provide the protocol, including 'http://',
|
|
|
|
* 'ftp://' or 'file://'. Ecore_File must be compiled with CURL to
|
|
|
|
* download using http and ftp protocols. If @p dst is ill-formed, or
|
|
|
|
* if it already exists, the function returns EINA_FALSE. When the
|
|
|
|
* download is complete, the callback @p completion_cb is called and
|
2011-04-20 07:15:33 -07:00
|
|
|
* @p data is passed to it. The @p status parameter of @p completion_cb
|
2011-02-16 04:44:34 -08:00
|
|
|
* will be filled with the status of the download (200, 404,...). The
|
|
|
|
* @p progress_cb is called during the download operation, each time a
|
|
|
|
* packet is received or when CURL wants. It can be used to display the
|
|
|
|
* percentage of the downloaded file. Return 0 from this callback, if provided,
|
|
|
|
* to continue the operation or anything else to abort the download. The only
|
2011-04-20 07:15:33 -07:00
|
|
|
* operations that can be aborted are those with protocol 'http' or 'ftp'. In
|
2011-02-16 04:44:34 -08:00
|
|
|
* that case @p job_ret can be filled. It can be used with
|
|
|
|
* ecore_file_download_abort() or ecore_file_download_abort_all() to
|
|
|
|
* respectively abort one or all download operations. This function returns
|
|
|
|
* EINA_TRUE if the download starts, EINA_FALSE otherwise.
|
|
|
|
*/
|
|
|
|
EAPI Eina_Bool
|
|
|
|
ecore_file_download(const char *url,
|
|
|
|
const char *dst,
|
|
|
|
Ecore_File_Download_Completion_Cb completion_cb,
|
|
|
|
Ecore_File_Download_Progress_Cb progress_cb,
|
|
|
|
void *data,
|
|
|
|
Ecore_File_Download_Job **job_ret)
|
|
|
|
{
|
2011-02-16 04:46:24 -08:00
|
|
|
return _ecore_file_download(url, dst, completion_cb, progress_cb, data, job_ret, NULL);
|
2011-02-16 04:44:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Download the given url to the given destination with additional headers.
|
|
|
|
*
|
|
|
|
* @param url The complete url to download.
|
|
|
|
* @param dst The local file to save the downloaded to.
|
|
|
|
* @param completion_cb A callback called on download complete.
|
|
|
|
* @param progress_cb A callback called during the download operation.
|
|
|
|
* @param data User data passed to both callbacks.
|
|
|
|
* @param job_ret Job used to abort the download.
|
|
|
|
* @param headers pointer of header lists.
|
|
|
|
* @return EINA_TRUE if the download start or EINA_FALSE on failure
|
|
|
|
*/
|
|
|
|
EAPI Eina_Bool
|
|
|
|
ecore_file_download_full(const char *url,
|
|
|
|
const char *dst,
|
|
|
|
Ecore_File_Download_Completion_Cb completion_cb,
|
|
|
|
Ecore_File_Download_Progress_Cb progress_cb,
|
|
|
|
void *data,
|
|
|
|
Ecore_File_Download_Job **job_ret,
|
|
|
|
Eina_Hash *headers)
|
|
|
|
{
|
2011-02-16 04:46:24 -08:00
|
|
|
return _ecore_file_download(url, dst, completion_cb, progress_cb, data, job_ret, headers);
|
2011-02-16 04:44:34 -08:00
|
|
|
}
|
|
|
|
|
2007-08-06 13:00:28 -07:00
|
|
|
/**
|
2010-10-23 04:05:36 -07:00
|
|
|
* @brief Check if the given protocol is available.
|
2007-08-06 13:00:28 -07:00
|
|
|
*
|
2010-10-23 04:05:36 -07:00
|
|
|
* @param protocol The protocol to check.
|
|
|
|
* @return EINA_TRUE if protocol is handled, EINA_FALSE otherwise.
|
|
|
|
*
|
|
|
|
* This function returns EINA_TRUE if @p protocol is supported,
|
|
|
|
* EINA_FALSE otherwise. @p protocol can be 'http://', 'ftp://' or
|
|
|
|
* 'file://'. Ecore_FILE must be compiled with CURL to handle http and
|
|
|
|
* ftp protocols.
|
2007-08-06 13:00:28 -07:00
|
|
|
*/
|
2010-09-24 22:34:26 -07:00
|
|
|
EAPI Eina_Bool
|
2005-06-22 07:51:37 -07:00
|
|
|
ecore_file_download_protocol_available(const char *protocol)
|
|
|
|
{
|
2009-10-14 10:29:13 -07:00
|
|
|
#ifdef BUILD_ECORE_CON
|
2010-09-24 22:34:26 -07:00
|
|
|
if (!strncmp(protocol, "file://", 7)) return EINA_TRUE;
|
2009-10-14 10:29:13 -07:00
|
|
|
# ifdef HAVE_CURL
|
2010-09-24 22:34:26 -07:00
|
|
|
else if (!strncmp(protocol, "http://", 7)) return EINA_TRUE;
|
|
|
|
else if (!strncmp(protocol, "ftp://", 6)) return EINA_TRUE;
|
2009-10-14 10:29:13 -07:00
|
|
|
# endif
|
2011-08-18 03:59:12 -07:00
|
|
|
#else
|
|
|
|
(void)protocol;
|
2009-10-14 10:29:13 -07:00
|
|
|
#endif /* BUILD_ECORE_CON */
|
2005-06-22 07:51:37 -07:00
|
|
|
|
2010-09-24 22:34:26 -07:00
|
|
|
return EINA_FALSE;
|
2005-06-22 07:51:37 -07:00
|
|
|
}
|
|
|
|
|
2009-10-14 10:29:13 -07:00
|
|
|
#ifdef BUILD_ECORE_CON
|
|
|
|
|
|
|
|
# ifdef HAVE_CURL
|
2006-11-10 11:11:12 -08:00
|
|
|
static int
|
2008-03-09 09:43:32 -07:00
|
|
|
_ecore_file_download_url_compare_job(const void *data1, const void *data2)
|
2007-11-07 13:15:11 -08:00
|
|
|
{
|
2010-09-30 00:25:06 -07:00
|
|
|
const Ecore_File_Download_Job *job = data1;
|
|
|
|
const Ecore_Con_Url *url = data2;
|
2008-03-09 09:43:32 -07:00
|
|
|
|
|
|
|
if (job->url_con == url) return 0;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-06-24 09:15:56 -07:00
|
|
|
static Eina_Bool
|
2010-02-28 15:27:47 -08:00
|
|
|
_ecore_file_download_url_complete_cb(void *data __UNUSED__, int type __UNUSED__, void *event)
|
2008-03-09 09:43:32 -07:00
|
|
|
{
|
2010-09-30 00:25:06 -07:00
|
|
|
Ecore_Con_Event_Url_Complete *ev = event;
|
|
|
|
Ecore_File_Download_Job *job;
|
2008-03-09 09:43:32 -07:00
|
|
|
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
job = eina_list_search_unsorted(_job_list, _ecore_file_download_url_compare_job, ev->url_con);
|
2010-06-24 09:15:56 -07:00
|
|
|
if (!ECORE_MAGIC_CHECK(job, ECORE_MAGIC_FILE_DOWNLOAD_JOB)) return ECORE_CALLBACK_PASS_ON;
|
2008-03-09 09:43:32 -07:00
|
|
|
|
2011-11-24 03:55:50 -08:00
|
|
|
fclose(job->file);
|
2008-03-09 09:43:32 -07:00
|
|
|
if (job->completion_cb)
|
2011-07-06 13:56:55 -07:00
|
|
|
job->completion_cb(ecore_con_url_data_get(job->url_con), job->dst, ev->status);
|
2008-03-09 09:43:32 -07:00
|
|
|
|
2009-11-14 05:43:38 -08:00
|
|
|
_job_list = eina_list_remove(_job_list, job);
|
|
|
|
free(job->dst);
|
2010-10-01 00:38:36 -07:00
|
|
|
ecore_con_url_free(job->url_con);
|
2009-11-14 05:43:38 -08:00
|
|
|
free(job);
|
2008-03-09 09:43:32 -07:00
|
|
|
|
2010-06-24 09:15:56 -07:00
|
|
|
return ECORE_CALLBACK_DONE;
|
2008-03-09 09:43:32 -07:00
|
|
|
}
|
|
|
|
|
2010-06-24 09:15:56 -07:00
|
|
|
static Eina_Bool
|
2010-02-28 15:27:47 -08:00
|
|
|
_ecore_file_download_url_progress_cb(void *data __UNUSED__, int type __UNUSED__, void *event)
|
2008-03-09 09:43:32 -07:00
|
|
|
{
|
|
|
|
/* this reports the downloads progress. if we return 0, then download
|
|
|
|
* continues, if we return anything else, then the download stops */
|
2010-09-30 00:25:06 -07:00
|
|
|
Ecore_Con_Event_Url_Progress *ev = event;
|
|
|
|
Ecore_File_Download_Job *job;
|
2008-03-09 09:43:32 -07:00
|
|
|
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
job = eina_list_search_unsorted(_job_list, _ecore_file_download_url_compare_job, ev->url_con);
|
2010-06-24 09:15:56 -07:00
|
|
|
if (!ECORE_MAGIC_CHECK(job, ECORE_MAGIC_FILE_DOWNLOAD_JOB)) return ECORE_CALLBACK_PASS_ON;
|
2008-03-09 09:43:32 -07:00
|
|
|
|
|
|
|
if (job->progress_cb)
|
|
|
|
if (job->progress_cb(ecore_con_url_data_get(job->url_con), job->dst,
|
2010-09-30 00:25:06 -07:00
|
|
|
(long int) ev->down.total, (long int) ev->down.now,
|
|
|
|
(long int) ev->up.total, (long int) ev->up.now) != 0)
|
2008-03-09 09:43:32 -07:00
|
|
|
{
|
2010-09-30 00:25:06 -07:00
|
|
|
_job_list = eina_list_remove(_job_list, job);
|
|
|
|
fclose(job->file);
|
|
|
|
free(job->dst);
|
|
|
|
free(job);
|
2009-11-14 05:43:38 -08:00
|
|
|
|
2010-09-30 00:25:06 -07:00
|
|
|
return ECORE_CALLBACK_PASS_ON;
|
2008-03-09 09:43:32 -07:00
|
|
|
}
|
2007-11-07 13:15:11 -08:00
|
|
|
|
2010-06-24 09:15:56 -07:00
|
|
|
return ECORE_CALLBACK_DONE;
|
2006-04-07 05:27:39 -07:00
|
|
|
}
|
|
|
|
|
2005-06-17 16:52:32 -07:00
|
|
|
Ecore_File_Download_Job *
|
|
|
|
_ecore_file_download_curl(const char *url, const char *dst,
|
2010-10-23 04:33:56 -07:00
|
|
|
Ecore_File_Download_Completion_Cb completion_cb,
|
|
|
|
Ecore_File_Download_Progress_Cb progress_cb,
|
2011-02-16 04:44:34 -08:00
|
|
|
void *data,
|
|
|
|
Eina_Hash *headers)
|
2005-06-17 16:52:32 -07:00
|
|
|
{
|
|
|
|
Ecore_File_Download_Job *job;
|
|
|
|
|
|
|
|
job = calloc(1, sizeof(Ecore_File_Download_Job));
|
|
|
|
if (!job) return NULL;
|
|
|
|
|
2008-03-09 09:43:32 -07:00
|
|
|
ECORE_MAGIC_SET(job, ECORE_MAGIC_FILE_DOWNLOAD_JOB);
|
|
|
|
|
2005-06-17 16:52:32 -07:00
|
|
|
job->file = fopen(dst, "wb");
|
|
|
|
if (!job->file)
|
|
|
|
{
|
2010-09-30 00:25:06 -07:00
|
|
|
free(job);
|
|
|
|
return NULL;
|
2005-06-17 16:52:32 -07:00
|
|
|
}
|
2008-03-09 09:43:32 -07:00
|
|
|
job->url_con = ecore_con_url_new(url);
|
|
|
|
if (!job->url_con)
|
2005-06-17 16:52:32 -07:00
|
|
|
{
|
2010-09-30 00:25:06 -07:00
|
|
|
fclose(job->file);
|
|
|
|
free(job);
|
|
|
|
return NULL;
|
2005-06-17 16:52:32 -07:00
|
|
|
}
|
2007-11-07 13:15:11 -08:00
|
|
|
|
2011-02-16 04:44:34 -08:00
|
|
|
if (headers) eina_hash_foreach(headers, _ecore_file_download_headers_foreach_cb, job);
|
2011-12-20 22:18:25 -08:00
|
|
|
ecore_con_url_timeout_set(job->url_con, ECORE_FILE_DOWNLOAD_TIMEOUT);
|
2008-03-09 09:43:32 -07:00
|
|
|
ecore_con_url_fd_set(job->url_con, fileno(job->file));
|
|
|
|
ecore_con_url_data_set(job->url_con, data);
|
|
|
|
|
|
|
|
job->dst = strdup(dst);
|
2007-11-07 13:15:11 -08:00
|
|
|
|
2005-06-17 16:52:32 -07:00
|
|
|
job->completion_cb = completion_cb;
|
2006-04-07 05:27:39 -07:00
|
|
|
job->progress_cb = progress_cb;
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
_job_list = eina_list_append(_job_list, job);
|
2005-06-17 16:52:32 -07:00
|
|
|
|
2011-11-05 23:14:31 -07:00
|
|
|
if (!ecore_con_url_get(job->url_con))
|
|
|
|
{
|
|
|
|
ecore_con_url_free(job->url_con);
|
|
|
|
_job_list = eina_list_remove(_job_list, job);
|
|
|
|
fclose(job->file);
|
2011-11-08 17:03:09 -08:00
|
|
|
ecore_file_remove(job->dst);
|
2011-11-05 23:14:31 -07:00
|
|
|
free(job->dst);
|
|
|
|
free(job);
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-06-17 16:52:32 -07:00
|
|
|
|
|
|
|
return job;
|
|
|
|
}
|
2009-10-14 10:29:13 -07:00
|
|
|
# endif
|
2009-11-23 01:05:02 -08:00
|
|
|
#endif
|
2008-03-11 03:24:10 -07:00
|
|
|
|
2010-03-14 03:53:14 -07:00
|
|
|
/**
|
2010-10-23 04:05:36 -07:00
|
|
|
* @brief Abort the given download job and call the completion_cb
|
|
|
|
* callbck with a status of 1 (error).
|
|
|
|
*
|
|
|
|
* @param job The download job to abort.
|
|
|
|
*
|
|
|
|
* This function aborts a download operation started by
|
|
|
|
* ecore_file_download(). @p job is the #Ecore_File_Download_Job
|
|
|
|
* structure filled by ecore_file_download(). If it is @c NULL, this
|
|
|
|
* function does nothing. To abort all the currently downloading
|
|
|
|
* operations, call ecore_file_download_abort_all().
|
2010-03-14 03:53:14 -07:00
|
|
|
*/
|
2009-11-13 09:51:52 -08:00
|
|
|
EAPI void
|
|
|
|
ecore_file_download_abort(Ecore_File_Download_Job *job)
|
2008-03-11 03:24:10 -07:00
|
|
|
{
|
2010-10-23 04:05:36 -07:00
|
|
|
if (!job)
|
|
|
|
return;
|
|
|
|
|
2009-11-23 01:05:02 -08:00
|
|
|
#ifdef BUILD_ECORE_CON
|
2010-05-18 16:06:07 -07:00
|
|
|
if (job->completion_cb)
|
|
|
|
job->completion_cb(ecore_con_url_data_get(job->url_con), job->dst, 1);
|
2009-10-14 10:29:13 -07:00
|
|
|
# ifdef HAVE_CURL
|
2010-09-20 23:49:07 -07:00
|
|
|
ecore_con_url_free(job->url_con);
|
2009-11-14 05:43:38 -08:00
|
|
|
# endif
|
2009-11-13 09:51:52 -08:00
|
|
|
_job_list = eina_list_remove(_job_list, job);
|
2008-03-11 03:24:10 -07:00
|
|
|
fclose(job->file);
|
|
|
|
free(job->dst);
|
|
|
|
free(job);
|
2009-10-14 10:29:13 -07:00
|
|
|
#endif /* BUILD_ECORE_CON */
|
2009-11-23 01:05:02 -08:00
|
|
|
}
|
2010-10-23 04:05:36 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Abort all downloads.
|
|
|
|
*
|
|
|
|
* This function aborts all the downloads that have been started by
|
|
|
|
* ecore_file_download(). It loops over the started downloads and call
|
|
|
|
* ecore_file_download_abort() for each of them. To abort only one
|
|
|
|
* specific download operation, call ecore_file_download_abort().
|
|
|
|
*/
|
|
|
|
EAPI void
|
|
|
|
ecore_file_download_abort_all(void)
|
|
|
|
{
|
|
|
|
#ifdef BUILD_ECORE_CON
|
|
|
|
Ecore_File_Download_Job *job;
|
|
|
|
|
|
|
|
EINA_LIST_FREE(_job_list, job)
|
|
|
|
ecore_file_download_abort(job);
|
|
|
|
#endif /* BUILD_ECORE_CON */
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|