summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2013-10-10 22:31:18 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2013-10-10 22:31:18 +0900
commit2c1c6b9335e38c6e52b06829a95d9b58d780c99e (patch)
tree8ff42a2d2e2c3be345953558fd94aa463b670fb7 /src
parent4ce3e1e72f600be69702ac918f4ff8a099d49c6d (diff)
ecore-con: make curl support entirely runtime loaded via eina_module
this makes curl support a pure runtime-only thing. libcurl is loaded by eina_module (dlopen/dlsym) when curl is actually first needed (when a url connection/object is created). this means that ecore-con has no link or compile dependencies on curl, only runtime, AND this saves memory (due to curl inits using apparently a chunk of private pages). so this saves memory and moves the dependency to runtime (though still consider libcurl a dependency of efl - but like a binary executed, it's at runtime).
Diffstat (limited to 'src')
-rw-r--r--src/lib/ecore_con/ecore_con_private.h7
-rw-r--r--src/lib/ecore_con/ecore_con_url.c1074
2 files changed, 514 insertions, 567 deletions
diff --git a/src/lib/ecore_con/ecore_con_private.h b/src/lib/ecore_con/ecore_con_private.h
index bdd7d961d6..ea9fada698 100644
--- a/src/lib/ecore_con/ecore_con_private.h
+++ b/src/lib/ecore_con/ecore_con_private.h
@@ -17,9 +17,6 @@
17#elif HAVE_OPENSSL 17#elif HAVE_OPENSSL
18# include <openssl/ssl.h> 18# include <openssl/ssl.h>
19#endif 19#endif
20#ifdef HAVE_CURL
21#include <curl/curl.h>
22#endif
23 20
24#define READBUFSIZ 65536 21#define READBUFSIZ 65536
25 22
@@ -199,11 +196,10 @@ struct _Ecore_Con_Server
199#endif 196#endif
200}; 197};
201 198
202#ifdef HAVE_CURL
203struct _Ecore_Con_Url 199struct _Ecore_Con_Url
204{ 200{
205 ECORE_MAGIC; 201 ECORE_MAGIC;
206 CURL *curl_easy; 202 void *curl_easy;
207 struct curl_slist *headers; 203 struct curl_slist *headers;
208 Eina_List *additional_headers; 204 Eina_List *additional_headers;
209 Eina_List *response_headers; 205 Eina_List *response_headers;
@@ -226,7 +222,6 @@ struct _Ecore_Con_Url
226 Eina_Bool dead : 1; 222 Eina_Bool dead : 1;
227 Eina_Bool multi : 1; 223 Eina_Bool multi : 1;
228}; 224};
229#endif
230 225
231struct _Ecore_Con_Info 226struct _Ecore_Con_Info
232{ 227{
diff --git a/src/lib/ecore_con/ecore_con_url.c b/src/lib/ecore_con/ecore_con_url.c
index f427138571..959ca94af3 100644
--- a/src/lib/ecore_con/ecore_con_url.c
+++ b/src/lib/ecore_con/ecore_con_url.c
@@ -30,13 +30,191 @@
30#include "Ecore_Con.h" 30#include "Ecore_Con.h"
31#include "ecore_con_private.h" 31#include "ecore_con_private.h"
32 32
33// all the types, defines, enums etc. from curl that we actuall USE.
34// we have to add to this if we use more things from curl not already
35// defined here. see culr headers to get them from
36typedef enum {
37 CURLM_CALL_MULTI_PERFORM = -1,
38 CURLM_OK = 0
39} CURLMcode;
40typedef enum {
41 CURLE_OK = 0,
42 CURLE_OPERATION_TIMEDOUT = 28
43} CURLcode;
44#define CURLOPTTYPE_LONG 0
45#define CURLOPTTYPE_OBJECTPOINT 10000
46#define CURLOPTTYPE_FUNCTIONPOINT 20000
47#define CURLOPTTYPE_OFF_T 30000
48#define CINIT(na,t,nu) CURLOPT_ ## na = CURLOPTTYPE_ ## t + nu
49typedef enum {
50 CINIT(FILE, OBJECTPOINT, 1),
51 CINIT(URL, OBJECTPOINT, 2),
52 CINIT(PROXY, OBJECTPOINT, 4),
53 CINIT(USERPWD, OBJECTPOINT, 5),
54 CINIT(INFILE, OBJECTPOINT, 9),
55 CINIT(WRITEFUNCTION, FUNCTIONPOINT, 11),
56 CINIT(READFUNCTION, FUNCTIONPOINT, 12),
57 CINIT(POSTFIELDS, OBJECTPOINT, 15),
58 CINIT(HTTPHEADER, OBJECTPOINT, 23),
59 CINIT(WRITEHEADER, OBJECTPOINT, 29),
60 CINIT(COOKIEFILE, OBJECTPOINT, 31),
61 CINIT(TIMECONDITION, LONG, 33),
62 CINIT(TIMEVALUE, LONG, 34),
63 CINIT(CUSTOMREQUEST, OBJECTPOINT, 36),
64 CINIT(VERBOSE, LONG, 41),
65 CINIT(NOPROGRESS, LONG, 43),
66 CINIT(UPLOAD, LONG, 46),
67 CINIT(POST, LONG, 47),
68 CINIT(FOLLOWLOCATION, LONG, 52),
69 CINIT(PROGRESSFUNCTION, FUNCTIONPOINT, 56),
70 CINIT(PROGRESSDATA, OBJECTPOINT, 57),
71 CINIT(POSTFIELDSIZE, LONG, 60),
72 CINIT(SSL_VERIFYPEER, LONG, 64),
73 CINIT(CAINFO, OBJECTPOINT, 65),
74 CINIT(CONNECTTIMEOUT, LONG, 78),
75 CINIT(HEADERFUNCTION, FUNCTIONPOINT, 79),
76 CINIT(COOKIEJAR, OBJECTPOINT, 82),
77 CINIT(HTTP_VERSION, LONG, 84),
78 CINIT(FTP_USE_EPSV, LONG, 85),
79 CINIT(COOKIESESSION, LONG, 96),
80 CINIT(PROXYTYPE, LONG, 101),
81 CINIT(ACCEPT_ENCODING, OBJECTPOINT, 102),
82 CINIT(HTTPAUTH, LONG, 107),
83 CINIT(INFILESIZE_LARGE, OFF_T, 115),
84 CINIT(COOKIELIST, OBJECTPOINT, 135),
85 CINIT(USERNAME, OBJECTPOINT, 173),
86 CINIT(PASSWORD, OBJECTPOINT, 174)
87} CURLoption;
88#define CURLINFO_STRING 0x100000
89#define CURLINFO_LONG 0x200000
90#define CURLINFO_DOUBLE 0x300000
91#define CURLINFO_SLIST 0x400000
92#define CURLINFO_MASK 0x0fffff
93#define CURLINFO_TYPEMASK 0xf00000
94typedef enum {
95 CURLINFO_RESPONSE_CODE = CURLINFO_LONG + 2,
96} CURLINFO;
97typedef enum {
98 CURLVERSION_FOURTH = 3
99} CURLversion;
100typedef enum {
101 CURLMSG_DONE = 1
102} CURLMSG;
103#undef CINIT
104#define CINIT(name,type,num) CURLMOPT_ ## name = CURLOPTTYPE_ ## type + num
105typedef enum {
106 CINIT(PIPELINING, LONG, 3)
107} CURLMoption;
108typedef enum {
109 CURL_TIMECOND_NONE = 0,
110 CURL_TIMECOND_IFMODSINCE = 1,
111 CURL_TIMECOND_IFUNMODSINCE = 2
112} curl_TimeCond;
113enum {
114 CURL_HTTP_VERSION_1_0 = 1,
115 CURL_HTTP_VERSION_1_1 = 2,
116};
117typedef enum {
118 CURLPROXY_HTTP = 0,
119 CURLPROXY_SOCKS4 = 4,
120 CURLPROXY_SOCKS5 = 5,
121 CURLPROXY_SOCKS4A = 6,
122 CURLPROXY_SOCKS5_HOSTNAME = 7
123} curl_proxytype;
124
125#define CURL_GLOBAL_SSL (1<<0)
126#define CURL_GLOBAL_WIN32 (1<<1)
127#define CURL_GLOBAL_ALL (CURL_GLOBAL_SSL|CURL_GLOBAL_WIN32)
128#define CURLOPT_ENCODING CURLOPT_ACCEPT_ENCODING
129#define CURLOPT_WRITEDATA CURLOPT_FILE
130#define CURLOPT_READDATA CURLOPT_INFILE
131#define CURLOPT_HEADERDATA CURLOPT_WRITEHEADER
132#define CURLVERSION_NOW CURLVERSION_FOURTH
133#define CURLAUTH_BASIC (((unsigned long)1)<<0)
134#define CURLAUTH_DIGEST_IE (((unsigned long)1)<<4)
135#define CURLAUTH_ANY (~CURLAUTH_DIGEST_IE)
136#define CURLAUTH_ANYSAFE (~(CURLAUTH_BASIC|CURLAUTH_DIGEST_IE))
137#define CURL_READFUNC_ABORT 0x10000000
138
139typedef void CURLM;
140typedef void CURL;
141struct curl_slist {
142 char *data;
143 struct curl_slist *next;
144};
145typedef struct {
146 CURLversion age;
147 const char *version;
148 unsigned int version_num;
149 const char *host;
150 int features;
151 const char *ssl_version;
152 long ssl_version_num;
153 const char *libz_version;
154 const char * const *protocols;
155 const char *ares;
156 int ares_num;
157 const char *libidn;
158 int iconv_ver_num;
159 const char *libssh_version;
160} curl_version_info_data;
161typedef struct {
162 CURLMSG msg;
163 CURL *easy_handle;
164 union {
165 void *whatever;
166 CURLcode result;
167 } data;
168} CURLMsg;
169
170
171typedef struct _Ecore_Con_Curl Ecore_Con_Curl;
172
173struct _Ecore_Con_Curl
174{
175 Eina_Module *mod;
176
177 CURLM *_curlm;
178
179 CURLcode (*curl_global_init) (long flags);
180 void (*curl_global_cleanup)(void);
181 CURLM *(*curl_multi_init)(void);
182 CURLMcode (*curl_multi_timeout)(CURLM *multi_handle,
183 long *milliseconds);
184 CURLMcode (*curl_multi_cleanup)(CURLM *multi_handle);
185 CURLMcode (*curl_multi_remove_handle)(CURLM *multi_handle,
186 CURL *curl_handle);
187 const char *(*curl_multi_strerror)(CURLMcode);
188 CURLMsg *(*curl_multi_info_read)(CURLM *multi_handle,
189 int *msgs_in_queue);
190 CURLMcode (*curl_multi_fdset)(CURLM *multi_handle,
191 fd_set *read_fd_set,
192 fd_set *write_fd_set,
193 fd_set *exc_fd_set,
194 int *max_fd);
195 CURLMcode (*curl_multi_perform)(CURLM *multi_handle,
196 int *running_handles);
197 CURLMcode (*curl_multi_add_handle)(CURLM *multi_handle,
198 CURL *curl_handle);
199 CURLMcode (*curl_multi_setopt)(CURLM *multi_handle,
200 CURLMoption option, ...);
201 CURL *(*curl_easy_init)(void);
202 CURLcode (*curl_easy_setopt)(CURL *curl, CURLoption option, ...);
203 const char *(*curl_easy_strerror)(CURLcode);
204 void (*curl_easy_cleanup)(CURL *curl);
205 CURLcode (*curl_easy_getinfo)(CURL *curl, CURLINFO info, ...);
206 void (*curl_slist_free_all)(struct curl_slist *);
207 struct curl_slist *(*curl_slist_append)(struct curl_slist *list,
208 const char *string);
209 curl_version_info_data *(*curl_version_info)(CURLversion);
210};
211
33#define CURL_MIN_TIMEOUT 100 212#define CURL_MIN_TIMEOUT 100
34 213
35int ECORE_CON_EVENT_URL_DATA = 0; 214int ECORE_CON_EVENT_URL_DATA = 0;
36int ECORE_CON_EVENT_URL_COMPLETE = 0; 215int ECORE_CON_EVENT_URL_COMPLETE = 0;
37int ECORE_CON_EVENT_URL_PROGRESS = 0; 216int ECORE_CON_EVENT_URL_PROGRESS = 0;
38 217
39#ifdef HAVE_CURL
40static void _ecore_con_url_event_url_complete(Ecore_Con_Url *url_con, CURLMsg *curlmsg); 218static void _ecore_con_url_event_url_complete(Ecore_Con_Url *url_con, CURLMsg *curlmsg);
41static void _ecore_con_url_multi_remove(Ecore_Con_Url *url_con); 219static void _ecore_con_url_multi_remove(Ecore_Con_Url *url_con);
42static Eina_Bool _ecore_con_url_perform(Ecore_Con_Url *url_con); 220static Eina_Bool _ecore_con_url_perform(Ecore_Con_Url *url_con);
@@ -52,12 +230,87 @@ static void _ecore_con_url_status_get(Ecore_Con_Url *url_con);
52 230
53static Eina_List *_url_con_list = NULL; 231static Eina_List *_url_con_list = NULL;
54static Eina_List *_fd_hd_list = NULL; 232static Eina_List *_fd_hd_list = NULL;
55static CURLM *_curlm = NULL;
56static int _init_count = 0; 233static int _init_count = 0;
57static Ecore_Timer *_curl_timer = NULL; 234static Ecore_Timer *_curl_timer = NULL;
58static Eina_Bool pipelining = EINA_FALSE; 235static Eina_Bool pipelining = EINA_FALSE;
59static Ecore_Idler *_curl_idler = NULL; 236static Ecore_Idler *_curl_idler = NULL;
60#endif 237
238static Ecore_Con_Curl *_c = NULL;
239static Eina_Bool _c_fail = EINA_FALSE;
240
241static Eina_Bool
242_c_init(void)
243{
244 long ms = 0;
245
246 if (_c) return EINA_TRUE;
247 if (_c_fail) return EINA_FALSE;
248 _c = calloc(1, sizeof(Ecore_Con_Curl));
249 if (!_c) goto error;
250 _c->mod = eina_module_new("libcurl.so.4");
251 if (!_c->mod) goto error;
252 if (!eina_module_load(_c->mod)) goto error;
253
254#define SYM(x) if (!(_c->x = eina_module_symbol_get(_c->mod, #x))) goto error
255 SYM(curl_global_init);
256 SYM(curl_global_cleanup);
257 SYM(curl_multi_init);
258 SYM(curl_multi_timeout);
259 SYM(curl_multi_cleanup);
260 SYM(curl_multi_remove_handle);
261 SYM(curl_multi_strerror);
262 SYM(curl_multi_info_read);
263 SYM(curl_multi_fdset);
264 SYM(curl_multi_perform);
265 SYM(curl_multi_add_handle);
266 SYM(curl_multi_setopt);
267 SYM(curl_easy_init);
268 SYM(curl_easy_setopt);
269 SYM(curl_easy_strerror);
270 SYM(curl_easy_cleanup);
271 SYM(curl_easy_getinfo);
272 SYM(curl_slist_free_all);
273 SYM(curl_slist_append);
274 SYM(curl_version_info);
275
276 // curl_global_init() is not thread safe!
277 if (_c->curl_global_init(CURL_GLOBAL_ALL)) goto error;
278 _c->_curlm = _c->curl_multi_init();
279 if (!_c->_curlm)
280 {
281 _c->curl_global_cleanup();
282 goto error;
283 }
284 _c->curl_multi_timeout(_c->_curlm, &ms);
285 if ((ms >= CURL_MIN_TIMEOUT) || (ms <= 0)) ms = CURL_MIN_TIMEOUT;
286 _curl_timer = ecore_timer_add((double)ms / 1000.0,
287 _ecore_con_url_timer, NULL);
288 ecore_timer_freeze(_curl_timer);
289 return EINA_TRUE;
290error:
291 if (_c)
292 {
293 if (_c->mod) eina_module_free(_c->mod);
294 free(_c);
295 _c = NULL;
296 }
297 _c_fail = EINA_TRUE;
298 return EINA_FALSE;
299}
300
301static void
302_c_shutdown(void)
303{
304 if (!_c) return;
305 if (_c->_curlm)
306 {
307 _c->curl_multi_cleanup(_c->_curlm);
308 }
309 _c->curl_global_cleanup();
310 if (_c->mod) eina_module_free(_c->mod);
311 free(_c);
312 _c = NULL;
313}
61 314
62/** 315/**
63 * @addtogroup Ecore_Con_Url_Group Ecore URL Connection Functions 316 * @addtogroup Ecore_Con_Url_Group Ecore URL Connection Functions
@@ -68,95 +321,52 @@ static Ecore_Idler *_curl_idler = NULL;
68EAPI int 321EAPI int
69ecore_con_url_init(void) 322ecore_con_url_init(void)
70{ 323{
71#ifdef HAVE_CURL
72 long ms;
73 if (++_init_count > 1) return _init_count; 324 if (++_init_count > 1) return _init_count;
74
75 ECORE_CON_EVENT_URL_DATA = ecore_event_type_new(); 325 ECORE_CON_EVENT_URL_DATA = ecore_event_type_new();
76 ECORE_CON_EVENT_URL_COMPLETE = ecore_event_type_new(); 326 ECORE_CON_EVENT_URL_COMPLETE = ecore_event_type_new();
77 ECORE_CON_EVENT_URL_PROGRESS = ecore_event_type_new(); 327 ECORE_CON_EVENT_URL_PROGRESS = ecore_event_type_new();
78
79 // curl_global_init() is not thread safe!
80 if (curl_global_init(CURL_GLOBAL_ALL)) return --_init_count;
81
82 _curlm = curl_multi_init();
83 if (!_curlm)
84 {
85 curl_global_cleanup();
86 return --_init_count;
87 }
88
89 curl_multi_timeout(_curlm, &ms);
90 if ((ms >= CURL_MIN_TIMEOUT) || (ms <= 0)) ms = CURL_MIN_TIMEOUT;
91
92 _curl_timer = ecore_timer_add((double)ms / 1000.0,
93 _ecore_con_url_timer, NULL);
94 ecore_timer_freeze(_curl_timer);
95
96 return _init_count; 328 return _init_count;
97#else
98 return 0;
99#endif
100} 329}
101 330
102EAPI int 331EAPI int
103ecore_con_url_shutdown(void) 332ecore_con_url_shutdown(void)
104{ 333{
105#ifdef HAVE_CURL
106 Ecore_Con_Url *url_con; 334 Ecore_Con_Url *url_con;
107 Ecore_Fd_Handler *fd_handler; 335 Ecore_Fd_Handler *fd_handler;
108 if (_init_count == 0) return 0; 336 if (_init_count == 0) return 0;
109 --_init_count; 337 --_init_count;
110 if (_init_count) return _init_count; 338 if (_init_count) return _init_count;
111
112 if (_curl_timer) 339 if (_curl_timer)
113 { 340 {
114 ecore_timer_del(_curl_timer); 341 ecore_timer_del(_curl_timer);
115 _curl_timer = NULL; 342 _curl_timer = NULL;
116 } 343 }
117
118 if (_curl_idler) 344 if (_curl_idler)
119 { 345 {
120 ecore_idler_del(_curl_idler); 346 ecore_idler_del(_curl_idler);
121 _curl_idler = NULL; 347 _curl_idler = NULL;
122 } 348 }
123
124 EINA_LIST_FREE(_url_con_list, url_con) 349 EINA_LIST_FREE(_url_con_list, url_con)
125 ecore_con_url_free(url_con); 350 ecore_con_url_free(url_con);
126 EINA_LIST_FREE(_fd_hd_list, fd_handler) 351 EINA_LIST_FREE(_fd_hd_list, fd_handler)
127 ecore_main_fd_handler_del(fd_handler); 352 ecore_main_fd_handler_del(fd_handler);
128 353 _c_shutdown();
129 if (_curlm)
130 {
131 curl_multi_cleanup(_curlm);
132 _curlm = NULL;
133 }
134 curl_global_cleanup();
135 return 0; 354 return 0;
136#endif
137 return 1;
138} 355}
139 356
140EAPI void 357EAPI void
141ecore_con_url_pipeline_set(Eina_Bool enable) 358ecore_con_url_pipeline_set(Eina_Bool enable)
142{ 359{
143#ifdef HAVE_CURL 360 if (!_c_init()) return;
144 if (enable == pipelining) return; 361 if (enable == pipelining) return;
145 curl_multi_setopt(_curlm, CURLMOPT_PIPELINING, !!enable); 362 _c->curl_multi_setopt(_c->_curlm, CURLMOPT_PIPELINING, !!enable);
146 pipelining = enable; 363 pipelining = enable;
147#else
148 return;
149 (void)enable;
150#endif
151} 364}
152 365
153EAPI Eina_Bool 366EAPI Eina_Bool
154ecore_con_url_pipeline_get(void) 367ecore_con_url_pipeline_get(void)
155{ 368{
156#ifdef HAVE_CURL
157 return pipelining; 369 return pipelining;
158#endif
159 return EINA_FALSE;
160} 370}
161 371
162extern Ecore_Con_Socks *_ecore_con_proxy_global; 372extern Ecore_Con_Socks *_ecore_con_proxy_global;
@@ -164,20 +374,18 @@ extern Ecore_Con_Socks *_ecore_con_proxy_global;
164EAPI Ecore_Con_Url * 374EAPI Ecore_Con_Url *
165ecore_con_url_new(const char *url) 375ecore_con_url_new(const char *url)
166{ 376{
167#ifdef HAVE_CURL
168 Ecore_Con_Url *url_con; 377 Ecore_Con_Url *url_con;
169 CURLcode ret; 378 CURLcode ret;
170 379
171 if (!_init_count) 380 if (!_init_count) return NULL;
172 return NULL; 381 if (!_c_init()) return NULL;
173 382
174 url_con = calloc(1, sizeof(Ecore_Con_Url)); 383 url_con = calloc(1, sizeof(Ecore_Con_Url));
175 if (!url_con) 384 if (!url_con) return NULL;
176 return NULL;
177 385
178 url_con->write_fd = -1; 386 url_con->write_fd = -1;
179 387
180 url_con->curl_easy = curl_easy_init(); 388 url_con->curl_easy = _c->curl_easy_init();
181 if (!url_con->curl_easy) 389 if (!url_con->curl_easy)
182 { 390 {
183 free(url_con); 391 free(url_con);
@@ -195,8 +403,8 @@ ecore_con_url_new(const char *url)
195 // Read socks proxy 403 // Read socks proxy
196 url_con->proxy_type = -1; 404 url_con->proxy_type = -1;
197 if (_ecore_con_proxy_global && _ecore_con_proxy_global->ip && 405 if (_ecore_con_proxy_global && _ecore_con_proxy_global->ip &&
198 (_ecore_con_proxy_global->version == 4 || 406 ((_ecore_con_proxy_global->version == 4) ||
199 _ecore_con_proxy_global->version == 5)) 407 (_ecore_con_proxy_global->version == 5)))
200 { 408 {
201 char proxy[256]; 409 char proxy[256];
202 char host[256]; 410 char host[256];
@@ -229,98 +437,83 @@ ecore_con_url_new(const char *url)
229 _ecore_con_proxy_global->username); 437 _ecore_con_proxy_global->username);
230 } 438 }
231 439
232 ret = curl_easy_setopt(url_con->curl_easy, CURLOPT_ENCODING, "gzip,deflate"); 440 ret = _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_ENCODING,
441 "gzip,deflate");
233 if (ret != CURLE_OK) 442 if (ret != CURLE_OK)
234 { 443 {
235 ERR("Could not set CURLOPT_ENCODING to \"gzip,deflate\": %s", 444 ERR("Could not set CURLOPT_ENCODING to \"gzip,deflate\": %s",
236 curl_easy_strerror(ret)); 445 _c->curl_easy_strerror(ret));
237 ecore_con_url_free(url_con); 446 ecore_con_url_free(url_con);
238 return NULL; 447 return NULL;
239 } 448 }
240 449
241 curl_easy_setopt(url_con->curl_easy, CURLOPT_WRITEFUNCTION, 450 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_WRITEFUNCTION,
242 _ecore_con_url_data_cb); 451 _ecore_con_url_data_cb);
243 curl_easy_setopt(url_con->curl_easy, CURLOPT_WRITEDATA, url_con); 452 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_WRITEDATA, url_con);
244 453
245 curl_easy_setopt(url_con->curl_easy, CURLOPT_PROGRESSFUNCTION, 454 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_PROGRESSFUNCTION,
246 _ecore_con_url_progress_cb); 455 _ecore_con_url_progress_cb);
247 curl_easy_setopt(url_con->curl_easy, CURLOPT_PROGRESSDATA, url_con); 456 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_PROGRESSDATA, url_con);
248 curl_easy_setopt(url_con->curl_easy, CURLOPT_NOPROGRESS, EINA_FALSE); 457 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_NOPROGRESS, EINA_FALSE);
249 458
250 curl_easy_setopt(url_con->curl_easy, CURLOPT_HEADERFUNCTION, 459 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_HEADERFUNCTION,
251 _ecore_con_url_header_cb); 460 _ecore_con_url_header_cb);
252 curl_easy_setopt(url_con->curl_easy, CURLOPT_HEADERDATA, url_con); 461 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_HEADERDATA, url_con);
253
254 /* 462 /*
255 * FIXME: Check that these timeouts are sensible defaults 463 * FIXME: Check that these timeouts are sensible defaults
256 * FIXME: Provide a means to change these timeouts 464 * FIXME: Provide a means to change these timeouts
257 */ 465 */
258 curl_easy_setopt(url_con->curl_easy, CURLOPT_CONNECTTIMEOUT, 30); 466 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_CONNECTTIMEOUT, 30);
259 curl_easy_setopt(url_con->curl_easy, CURLOPT_FOLLOWLOCATION, 1); 467 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_FOLLOWLOCATION, 1);
260
261 return url_con; 468 return url_con;
262#else
263 return NULL;
264 (void)url;
265#endif
266} 469}
267 470
268EAPI Ecore_Con_Url * 471EAPI Ecore_Con_Url *
269ecore_con_url_custom_new(const char *url, 472ecore_con_url_custom_new(const char *url,
270 const char *custom_request) 473 const char *custom_request)
271{ 474{
272#ifdef HAVE_CURL
273 Ecore_Con_Url *url_con; 475 Ecore_Con_Url *url_con;
274 CURLcode ret; 476 CURLcode ret;
275 477
276 if (!url) 478 if (!_init_count) return NULL;
277 return NULL; 479 if (!_c_init()) return NULL;
278 480 if (!url) return NULL;
279 if (!custom_request) 481 if (!custom_request) return NULL;
280 return NULL;
281
282 url_con = ecore_con_url_new(url); 482 url_con = ecore_con_url_new(url);
483 if (!url_con) return NULL;
283 484
284 if (!url_con) 485 ret = _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_CUSTOMREQUEST,
285 return NULL; 486 custom_request);
286
287 ret = curl_easy_setopt(url_con->curl_easy, CURLOPT_CUSTOMREQUEST, custom_request);
288 if (ret != CURLE_OK) 487 if (ret != CURLE_OK)
289 { 488 {
290 ERR("Could not set a custom request string: %s", 489 ERR("Could not set a custom request string: %s",
291 curl_easy_strerror(ret)); 490 _c->curl_easy_strerror(ret));
292 ecore_con_url_free(url_con); 491 ecore_con_url_free(url_con);
293 return NULL; 492 return NULL;
294 } 493 }
295
296 return url_con; 494 return url_con;
297#else
298 return NULL;
299 (void)url;
300 (void)custom_request;
301#endif
302} 495}
303 496
304EAPI void 497EAPI void
305ecore_con_url_free(Ecore_Con_Url *url_con) 498ecore_con_url_free(Ecore_Con_Url *url_con)
306{ 499{
307#ifdef HAVE_CURL
308 char *s; 500 char *s;
309 501
310 if (!url_con) return; 502 if (!_c) return;
311
312 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 503 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
313 { 504 {
314 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_free"); 505 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
315 return; 506 return;
316 } 507 }
317
318 if (url_con->curl_easy) 508 if (url_con->curl_easy)
319 { 509 {
320 // FIXME : How can we delete curl_easy's fds ?? (Curl do not give this info.) 510 // FIXME : How can we delete curl_easy's fds ??
511 // (Curl do not give this info.)
321 // This cause "Failed to delete epoll fd xx!" error messages 512 // This cause "Failed to delete epoll fd xx!" error messages
322 curl_easy_setopt(url_con->curl_easy, CURLOPT_PROGRESSFUNCTION, NULL); 513 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_PROGRESSFUNCTION,
323 curl_easy_setopt(url_con->curl_easy, CURLOPT_NOPROGRESS, EINA_TRUE); 514 NULL);
515 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_NOPROGRESS,
516 EINA_TRUE);
324 517
325 if (url_con->multi) 518 if (url_con->multi)
326 { 519 {
@@ -328,7 +521,7 @@ ecore_con_url_free(Ecore_Con_Url *url_con)
328 _url_con_list = eina_list_remove(_url_con_list, url_con); 521 _url_con_list = eina_list_remove(_url_con_list, url_con);
329 } 522 }
330 523
331 curl_easy_cleanup(url_con->curl_easy); 524 _c->curl_easy_cleanup(url_con->curl_easy);
332 } 525 }
333 if (url_con->timer) ecore_timer_del(url_con->timer); 526 if (url_con->timer) ecore_timer_del(url_con->timer);
334 527
@@ -338,287 +531,203 @@ ecore_con_url_free(Ecore_Con_Url *url_con)
338 if (url_con->event_count) return; 531 if (url_con->event_count) return;
339 ECORE_MAGIC_SET(url_con, ECORE_MAGIC_NONE); 532 ECORE_MAGIC_SET(url_con, ECORE_MAGIC_NONE);
340 533
341 curl_slist_free_all(url_con->headers); 534 _c->curl_slist_free_all(url_con->headers);
342 EINA_LIST_FREE(url_con->additional_headers, s) 535 EINA_LIST_FREE(url_con->additional_headers, s) free(s);
343 free(s); 536 EINA_LIST_FREE(url_con->response_headers, s) free(s);
344 EINA_LIST_FREE(url_con->response_headers, s)
345 free(s);
346 eina_stringshare_del(url_con->url); 537 eina_stringshare_del(url_con->url);
347 if (url_con->post_data) free(url_con->post_data); 538 if (url_con->post_data) free(url_con->post_data);
348 free(url_con); 539 free(url_con);
349#else
350 return;
351 (void)url_con;
352#endif
353} 540}
354 541
355EAPI const char * 542EAPI const char *
356ecore_con_url_url_get(Ecore_Con_Url *url_con) 543ecore_con_url_url_get(Ecore_Con_Url *url_con)
357{ 544{
358#ifdef HAVE_CURL
359 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 545 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
360 { 546 {
361 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__); 547 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
362 return NULL; 548 return NULL;
363 } 549 }
364 return url_con->url; 550 return url_con->url;
365#else
366 return NULL;
367 (void)url_con;
368#endif
369} 551}
370 552
371EAPI int 553EAPI int
372ecore_con_url_status_code_get(Ecore_Con_Url *url_con) 554ecore_con_url_status_code_get(Ecore_Con_Url *url_con)
373{ 555{
374#ifdef HAVE_CURL
375 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 556 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
376 { 557 {
377 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__); 558 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
378 return 0; 559 return 0;
379 } 560 }
380
381 if (url_con->status) return url_con->status; 561 if (url_con->status) return url_con->status;
382 _ecore_con_url_status_get(url_con); 562 _ecore_con_url_status_get(url_con);
383 return url_con->status; 563 return url_con->status;
384#else
385 return -1;
386 (void)url_con;
387#endif
388} 564}
389 565
390EAPI Eina_Bool 566EAPI Eina_Bool
391ecore_con_url_url_set(Ecore_Con_Url *url_con, const char *url) 567ecore_con_url_url_set(Ecore_Con_Url *url_con, const char *url)
392{ 568{
393#ifdef HAVE_CURL 569 if (!_c) return EINA_FALSE;
394 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 570 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
395 { 571 {
396 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_url_set"); 572 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
397 return EINA_FALSE; 573 return EINA_FALSE;
398 } 574 }
399
400 if (url_con->dead) return EINA_FALSE; 575 if (url_con->dead) return EINA_FALSE;
401 eina_stringshare_replace(&url_con->url, url); 576 eina_stringshare_replace(&url_con->url, url);
402
403 if (url_con->url) 577 if (url_con->url)
404 curl_easy_setopt(url_con->curl_easy, CURLOPT_URL, 578 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_URL,
405 url_con->url); 579 url_con->url);
406 else 580 else
407 curl_easy_setopt(url_con->curl_easy, CURLOPT_URL, ""); 581 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_URL, "");
408
409 return EINA_TRUE; 582 return EINA_TRUE;
410#else
411 return EINA_FALSE;
412 (void)url;
413 (void)url_con;
414#endif
415} 583}
416 584
417EAPI void 585EAPI void
418ecore_con_url_data_set(Ecore_Con_Url *url_con, void *data) 586ecore_con_url_data_set(Ecore_Con_Url *url_con, void *data)
419{ 587{
420#ifdef HAVE_CURL
421 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 588 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
422 { 589 {
423 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_data_set"); 590 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
424 return; 591 return;
425 } 592 }
426
427 url_con->data = data; 593 url_con->data = data;
428#else
429 return;
430 (void)url_con;
431 (void)data;
432#endif
433} 594}
434 595
435EAPI void 596EAPI void
436ecore_con_url_additional_header_add(Ecore_Con_Url *url_con, const char *key, const char *value) 597ecore_con_url_additional_header_add(Ecore_Con_Url *url_con, const char *key, const char *value)
437{ 598{
438#ifdef HAVE_CURL
439 char *tmp; 599 char *tmp;
440 600
441 if (url_con->dead) return;
442 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 601 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
443 { 602 {
444 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, 603 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
445 "ecore_con_url_additional_header_add");
446 return; 604 return;
447 } 605 }
448 606
449 if (url_con->dead) return; 607 if (url_con->dead) return;
450 tmp = malloc(strlen(key) + strlen(value) + 3); 608 tmp = malloc(strlen(key) + strlen(value) + 3);
451 if (!tmp) 609 if (!tmp) return;
452 return;
453
454 sprintf(tmp, "%s: %s", key, value); 610 sprintf(tmp, "%s: %s", key, value);
455 url_con->additional_headers = eina_list_append(url_con->additional_headers, 611 url_con->additional_headers = eina_list_append(url_con->additional_headers,
456 tmp); 612 tmp);
457#else
458 return;
459 (void)url_con;
460 (void)key;
461 (void)value;
462#endif
463} 613}
464 614
465EAPI void 615EAPI void
466ecore_con_url_additional_headers_clear(Ecore_Con_Url *url_con) 616ecore_con_url_additional_headers_clear(Ecore_Con_Url *url_con)
467{ 617{
468#ifdef HAVE_CURL
469 char *s; 618 char *s;
470 619
471 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 620 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
472 { 621 {
473 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, 622 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
474 "ecore_con_url_additional_headers_clear");
475 return; 623 return;
476 } 624 }
477 625 EINA_LIST_FREE(url_con->additional_headers, s) free(s);
478 EINA_LIST_FREE(url_con->additional_headers, s)
479 free(s);
480#else
481 return;
482 (void)url_con;
483#endif
484} 626}
485 627
486EAPI void * 628EAPI void *
487ecore_con_url_data_get(Ecore_Con_Url *url_con) 629ecore_con_url_data_get(Ecore_Con_Url *url_con)
488{ 630{
489#ifdef HAVE_CURL
490 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 631 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
491 { 632 {
492 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_data_get"); 633 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
493 return NULL; 634 return NULL;
494 } 635 }
495
496 return url_con->data; 636 return url_con->data;
497#else
498 return NULL;
499 (void)url_con;
500#endif
501} 637}
502 638
503EAPI void 639EAPI void
504ecore_con_url_time(Ecore_Con_Url *url_con, Ecore_Con_Url_Time condition, double timestamp) 640ecore_con_url_time(Ecore_Con_Url *url_con, Ecore_Con_Url_Time condition, double timestamp)
505{ 641{
506#ifdef HAVE_CURL
507 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 642 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
508 { 643 {
509 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_time"); 644 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
510 return; 645 return;
511 } 646 }
512
513 if (url_con->dead) return; 647 if (url_con->dead) return;
514 url_con->time_condition = condition; 648 url_con->time_condition = condition;
515 url_con->timestamp = timestamp; 649 url_con->timestamp = timestamp;
516#else
517 return;
518 (void)url_con;
519 (void)condition;
520 (void)timestamp;
521#endif
522} 650}
523 651
524EAPI void 652EAPI void
525ecore_con_url_fd_set(Ecore_Con_Url *url_con, int fd) 653ecore_con_url_fd_set(Ecore_Con_Url *url_con, int fd)
526{ 654{
527#ifdef HAVE_CURL
528 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 655 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
529 { 656 {
530 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_set"); 657 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
531 return; 658 return;
532 } 659 }
533
534 if (url_con->dead) return; 660 if (url_con->dead) return;
535 url_con->write_fd = fd; 661 url_con->write_fd = fd;
536#else
537 return;
538 (void)url_con;
539 (void)fd;
540#endif
541} 662}
542 663
543EAPI int 664EAPI int
544ecore_con_url_received_bytes_get(Ecore_Con_Url *url_con) 665ecore_con_url_received_bytes_get(Ecore_Con_Url *url_con)
545{ 666{
546#ifdef HAVE_CURL
547 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 667 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
548 { 668 {
549 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, 669 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
550 "ecore_con_url_received_bytes_get");
551 return -1; 670 return -1;
552 } 671 }
553
554 return url_con->received; 672 return url_con->received;
555#else
556 return 0;
557 (void)url_con;
558#endif
559} 673}
560 674
561EAPI const Eina_List * 675EAPI const Eina_List *
562ecore_con_url_response_headers_get(Ecore_Con_Url *url_con) 676ecore_con_url_response_headers_get(Ecore_Con_Url *url_con)
563{ 677{
564#ifdef HAVE_CURL 678 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
679 {
680 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
681 return NULL;
682 }
565 return url_con->response_headers; 683 return url_con->response_headers;
566#else
567 return NULL;
568 (void)url_con;
569#endif
570} 684}
571 685
572EAPI Eina_Bool 686EAPI Eina_Bool
573ecore_con_url_httpauth_set(Ecore_Con_Url *url_con, const char *username, const char *password, Eina_Bool safe) 687ecore_con_url_httpauth_set(Ecore_Con_Url *url_con, const char *username, const char *password, Eina_Bool safe)
574{ 688{
575#ifdef HAVE_CURL
576 CURLcode ret; 689 CURLcode ret;
690 curl_version_info_data *vers = NULL;
577 691
692 if (!_c) return EINA_FALSE;
578 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 693 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
579 { 694 {
580 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, 695 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
581 "ecore_con_url_httpauth_set");
582 return EINA_FALSE; 696 return EINA_FALSE;
583 } 697 }
584
585 if (url_con->dead) return EINA_FALSE; 698 if (url_con->dead) return EINA_FALSE;
586# if LIBCURL_VERSION_NUM >= 0x071301 699 vers = _c->curl_version_info(CURLVERSION_NOW);
587 if ((username) && (password)) 700 if (vers->version_num >= 0x071301)
588 { 701 {
589 if (safe) 702 if ((username) && (password))
590 curl_easy_setopt(url_con->curl_easy, CURLOPT_HTTPAUTH,
591 CURLAUTH_ANYSAFE);
592 else
593 curl_easy_setopt(url_con->curl_easy, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
594
595 ret = curl_easy_setopt(url_con->curl_easy, CURLOPT_USERNAME, username);
596 if (ret != CURLE_OK)
597 { 703 {
598 ERR("Could not set username for HTTP authentication: %s", 704 if (safe)
599 curl_easy_strerror(ret)); 705 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_HTTPAUTH,
600 return EINA_FALSE; 706 CURLAUTH_ANYSAFE);
601 } 707 else
602 708 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_HTTPAUTH,
603 ret = curl_easy_setopt(url_con->curl_easy, CURLOPT_PASSWORD, password); 709 CURLAUTH_ANY);
604 if (ret != CURLE_OK) 710
605 { 711 ret = _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_USERNAME,
606 ERR("Could not set password for HTTP authentication: %s", 712 username);
607 curl_easy_strerror(ret)); 713 if (ret != CURLE_OK)
608 return EINA_FALSE; 714 {
715 ERR("Could not set username for HTTP authentication: %s",
716 _c->curl_easy_strerror(ret));
717 return EINA_FALSE;
718 }
719
720 ret = _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_PASSWORD,
721 password);
722 if (ret != CURLE_OK)
723 {
724 ERR("Could not set password for HTTP authentication: %s",
725 _c->curl_easy_strerror(ret));
726 return EINA_FALSE;
727 }
728 return EINA_TRUE;
609 } 729 }
610
611 return EINA_TRUE;
612 } 730 }
613# endif
614#else
615 return EINA_FALSE;
616 (void)url_con;
617 (void)username;
618 (void)password;
619 (void)safe;
620#endif
621
622 return EINA_FALSE; 731 return EINA_FALSE;
623} 732}
624 733
@@ -629,14 +738,14 @@ ecore_con_url_httpauth_set(Ecore_Con_Url *url_con, const char *username, const c
629static Eina_Bool 738static Eina_Bool
630_ecore_con_url_send(Ecore_Con_Url *url_con, int mode, const void *data, long length, const char *content_type) 739_ecore_con_url_send(Ecore_Con_Url *url_con, int mode, const void *data, long length, const char *content_type)
631{ 740{
632#ifdef HAVE_CURL
633 Eina_List *l; 741 Eina_List *l;
634 const char *s; 742 const char *s;
635 char tmp[512]; 743 char tmp[512];
636 744
745 if (!_c) return EINA_FALSE;
637 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 746 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
638 { 747 {
639 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_send"); 748 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
640 return EINA_FALSE; 749 return EINA_FALSE;
641 } 750 }
642 751
@@ -644,14 +753,12 @@ _ecore_con_url_send(Ecore_Con_Url *url_con, int mode, const void *data, long len
644 if (url_con->dead) return EINA_FALSE; 753 if (url_con->dead) return EINA_FALSE;
645 754
646 /* Free response headers from previous send() calls */ 755 /* Free response headers from previous send() calls */
647 EINA_LIST_FREE(url_con->response_headers, s) 756 EINA_LIST_FREE(url_con->response_headers, s) free((char *)s);
648 free((char *)s);
649 url_con->response_headers = NULL; 757 url_con->response_headers = NULL;
650 url_con->status = 0; 758 url_con->status = 0;
651 759
652 curl_slist_free_all(url_con->headers); 760 _c->curl_slist_free_all(url_con->headers);
653 url_con->headers = NULL; 761 url_con->headers = NULL;
654
655 if ((mode == MODE_POST) || (mode == MODE_AUTO)) 762 if ((mode == MODE_POST) || (mode == MODE_AUTO))
656 { 763 {
657 if (url_con->post_data) free(url_con->post_data); 764 if (url_con->post_data) free(url_con->post_data);
@@ -664,59 +771,52 @@ _ecore_con_url_send(Ecore_Con_Url *url_con, int mode, const void *data, long len
664 memcpy(url_con->post_data, data, length); 771 memcpy(url_con->post_data, data, length);
665 if ((content_type) && (strlen(content_type) < 450)) 772 if ((content_type) && (strlen(content_type) < 450))
666 { 773 {
667 snprintf(tmp, sizeof(tmp), "Content-Type: %s", content_type); 774 snprintf(tmp, sizeof(tmp), "Content-Type: %s",
668 url_con->headers = curl_slist_append(url_con->headers, tmp); 775 content_type);
776 url_con->headers =
777 _c->curl_slist_append(url_con->headers, tmp);
669 } 778 }
670 curl_easy_setopt(url_con->curl_easy, CURLOPT_POSTFIELDS, url_con->post_data); 779 _c->curl_easy_setopt(url_con->curl_easy,
671 curl_easy_setopt(url_con->curl_easy, CURLOPT_POSTFIELDSIZE, length); 780 CURLOPT_POSTFIELDS, url_con->post_data);
781 _c->curl_easy_setopt(url_con->curl_easy,
782 CURLOPT_POSTFIELDSIZE, length);
672 } 783 }
673 else 784 else
674 return EINA_FALSE; 785 return EINA_FALSE;
675 } 786 }
676 else curl_easy_setopt(url_con->curl_easy, CURLOPT_POSTFIELDSIZE, 0); 787 else _c->curl_easy_setopt(url_con->curl_easy,
788 CURLOPT_POSTFIELDSIZE, 0);
677 if (mode == MODE_POST) 789 if (mode == MODE_POST)
678 curl_easy_setopt(url_con->curl_easy, CURLOPT_POST, 1); 790 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_POST, 1);
679 } 791 }
680 792
681 switch (url_con->time_condition) 793 switch (url_con->time_condition)
682 { 794 {
683 case ECORE_CON_URL_TIME_NONE: 795 case ECORE_CON_URL_TIME_NONE:
684 curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION, 796 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION,
685 CURL_TIMECOND_NONE); 797 CURL_TIMECOND_NONE);
686 break; 798 break;
687
688 case ECORE_CON_URL_TIME_IFMODSINCE: 799 case ECORE_CON_URL_TIME_IFMODSINCE:
689 curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION, 800 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION,
690 CURL_TIMECOND_IFMODSINCE); 801 CURL_TIMECOND_IFMODSINCE);
691 curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMEVALUE, 802 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMEVALUE,
692 (long)url_con->timestamp); 803 (long)url_con->timestamp);
693 break; 804 break;
694
695 case ECORE_CON_URL_TIME_IFUNMODSINCE: 805 case ECORE_CON_URL_TIME_IFUNMODSINCE:
696 curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION, 806 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION,
697 CURL_TIMECOND_IFUNMODSINCE); 807 CURL_TIMECOND_IFUNMODSINCE);
698 curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMEVALUE, 808 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMEVALUE,
699 (long)url_con->timestamp); 809 (long)url_con->timestamp);
700 break; 810 break;
701 } 811 }
702
703 /* Additional headers */ 812 /* Additional headers */
704 EINA_LIST_FOREACH(url_con->additional_headers, l, s) 813 EINA_LIST_FOREACH(url_con->additional_headers, l, s)
705 url_con->headers = curl_slist_append(url_con->headers, s); 814 url_con->headers = _c->curl_slist_append(url_con->headers, s);
706
707 curl_easy_setopt(url_con->curl_easy, CURLOPT_HTTPHEADER, url_con->headers);
708 815
816 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_HTTPHEADER,
817 url_con->headers);
709 url_con->received = 0; 818 url_con->received = 0;
710
711 return _ecore_con_url_perform(url_con); 819 return _ecore_con_url_perform(url_con);
712#else
713 return EINA_FALSE;
714 (void)url_con;
715 (void)mode;
716 (void)data;
717 (void)length;
718 (void)content_type;
719#endif
720} 820}
721 821
722EAPI Eina_Bool 822EAPI Eina_Bool
@@ -734,18 +834,16 @@ ecore_con_url_post(Ecore_Con_Url *url_con, const void *data, long length, const
734EAPI Eina_Bool 834EAPI Eina_Bool
735ecore_con_url_ftp_upload(Ecore_Con_Url *url_con, const char *filename, const char *user, const char *pass, const char *upload_dir) 835ecore_con_url_ftp_upload(Ecore_Con_Url *url_con, const char *filename, const char *user, const char *pass, const char *upload_dir)
736{ 836{
737#ifdef HAVE_CURL
738 char url[4096]; 837 char url[4096];
739 char userpwd[4096]; 838 char userpwd[4096];
740 FILE *fd; 839 FILE *fd;
741 struct stat file_info; 840 struct stat file_info;
742 CURLcode ret; 841 CURLcode ret;
743 842
843 if (!_c) return EINA_FALSE;
744 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 844 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
745 { 845 {
746 ECORE_MAGIC_FAIL(url_con, 846 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
747 ECORE_MAGIC_CON_URL,
748 "ecore_con_url_ftp_upload");
749 return EINA_FALSE; 847 return EINA_FALSE;
750 } 848 }
751 849
@@ -753,15 +851,14 @@ ecore_con_url_ftp_upload(Ecore_Con_Url *url_con, const char *filename, const cha
753 if (!url_con->url) return EINA_FALSE; 851 if (!url_con->url) return EINA_FALSE;
754 if ((!filename) || (!filename[0])) return EINA_FALSE; 852 if ((!filename) || (!filename[0])) return EINA_FALSE;
755 853
756 if (stat(filename, &file_info)) 854 if (stat(filename, &file_info)) return EINA_FALSE;
757 return EINA_FALSE;
758 855
759 snprintf(userpwd, sizeof(userpwd), "%s:%s", user, pass); 856 snprintf(userpwd, sizeof(userpwd), "%s:%s", user, pass);
760 ret = curl_easy_setopt(url_con->curl_easy, CURLOPT_USERPWD, userpwd); 857 ret = _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_USERPWD, userpwd);
761 if (ret != CURLE_OK) 858 if (ret != CURLE_OK)
762 { 859 {
763 ERR("Could not set username and password for FTP upload: %s", 860 ERR("Could not set username and password for FTP upload: %s",
764 curl_easy_strerror(ret)); 861 _c->curl_easy_strerror(ret));
765 return EINA_FALSE; 862 return EINA_FALSE;
766 } 863 }
767 864
@@ -777,244 +874,150 @@ ecore_con_url_ftp_upload(Ecore_Con_Url *url_con, const char *filename, const cha
777 874
778 if (!ecore_con_url_url_set(url_con, url)) 875 if (!ecore_con_url_url_set(url_con, url))
779 return EINA_FALSE; 876 return EINA_FALSE;
780 877 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_INFILESIZE_LARGE,
781 curl_easy_setopt(url_con->curl_easy, CURLOPT_INFILESIZE_LARGE, 878 (off_t)file_info.st_size);
782 (curl_off_t)file_info.st_size); 879 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_UPLOAD, 1);
783 curl_easy_setopt(url_con->curl_easy, CURLOPT_UPLOAD, 1); 880 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_READFUNCTION,
784 curl_easy_setopt(url_con->curl_easy, CURLOPT_READFUNCTION, 881 _ecore_con_url_read_cb);
785 _ecore_con_url_read_cb);
786
787 fd = fopen(filename, "rb"); 882 fd = fopen(filename, "rb");
788 if (!fd) 883 if (!fd)
789 { 884 {
790 ERR("Could not open \"%s\" for FTP upload", filename); 885 ERR("Could not open \"%s\" for FTP upload", filename);
791 return EINA_FALSE; 886 return EINA_FALSE;
792 } 887 }
793 curl_easy_setopt(url_con->curl_easy, CURLOPT_READDATA, fd); 888 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_READDATA, fd);
794
795 return _ecore_con_url_perform(url_con); 889 return _ecore_con_url_perform(url_con);
796#else
797 return EINA_FALSE;
798 (void)url_con;
799 (void)filename;
800 (void)user;
801 (void)pass;
802 (void)upload_dir;
803#endif
804} 890}
805 891
806EAPI void 892EAPI void
807ecore_con_url_cookies_init(Ecore_Con_Url *url_con) 893ecore_con_url_cookies_init(Ecore_Con_Url *url_con)
808{ 894{
809#ifdef HAVE_CURL 895 if (!_c) return;
810 if (!url_con)
811 return;
812
813 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 896 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
814 { 897 {
815 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, 898 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
816 "ecore_con_url_cookies_init");
817 return; 899 return;
818 } 900 }
819
820 if (url_con->dead) return; 901 if (url_con->dead) return;
821 curl_easy_setopt(url_con->curl_easy, CURLOPT_COOKIEFILE, ""); 902 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_COOKIEFILE, "");
822#else
823 return;
824 (void)url_con;
825#endif
826} 903}
827 904
828EAPI void 905EAPI void
829ecore_con_url_cookies_ignore_old_session_set(Ecore_Con_Url *url_con, Eina_Bool ignore) 906ecore_con_url_cookies_ignore_old_session_set(Ecore_Con_Url *url_con, Eina_Bool ignore)
830{ 907{
831#ifdef HAVE_CURL 908 if (!_c) return;
832 if (!url_con)
833 return;
834
835 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 909 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
836 { 910 {
837 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, 911 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
838 "ecore_con_url_cookies_ignore_old_session_set");
839 return; 912 return;
840 } 913 }
841
842 if (url_con->dead) return; 914 if (url_con->dead) return;
843 curl_easy_setopt(url_con->curl_easy, CURLOPT_COOKIESESSION, ignore); 915 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_COOKIESESSION, ignore);
844#else
845 return;
846 (void)url_con;
847 (void)ignore;
848#endif
849} 916}
850 917
851EAPI void 918EAPI void
852ecore_con_url_cookies_clear(Ecore_Con_Url *url_con) 919ecore_con_url_cookies_clear(Ecore_Con_Url *url_con)
853{ 920{
854#ifdef HAVE_CURL 921 if (!_c) return;
855 if (!url_con)
856 return;
857
858 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 922 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
859 { 923 {
860 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, 924 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
861 "ecore_con_url_cookies_clear");
862 return; 925 return;
863 } 926 }
864
865 if (url_con->dead) return; 927 if (url_con->dead) return;
866 curl_easy_setopt(url_con->curl_easy, CURLOPT_COOKIELIST, "ALL"); 928 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_COOKIELIST, "ALL");
867#else
868 return;
869 (void)url_con;
870#endif
871} 929}
872 930
873EAPI void 931EAPI void
874ecore_con_url_cookies_session_clear(Ecore_Con_Url *url_con) 932ecore_con_url_cookies_session_clear(Ecore_Con_Url *url_con)
875{ 933{
876#ifdef HAVE_CURL 934 if (!_c) return;
877 if (!url_con)
878 return;
879
880 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 935 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
881 { 936 {
882 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, 937 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
883 "ecore_con_url_cookies_session_clear");
884 return; 938 return;
885 } 939 }
886
887 if (url_con->dead) return; 940 if (url_con->dead) return;
888 curl_easy_setopt(url_con->curl_easy, CURLOPT_COOKIELIST, "SESS"); 941 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_COOKIELIST, "SESS");
889#else
890 return;
891 (void)url_con;
892#endif
893} 942}
894 943
895EAPI void 944EAPI void
896ecore_con_url_cookies_file_add(Ecore_Con_Url *url_con, const char *const file_name) 945ecore_con_url_cookies_file_add(Ecore_Con_Url *url_con, const char *const file_name)
897{ 946{
898#ifdef HAVE_CURL 947 if (!_c) return;
899 if (!url_con)
900 return;
901
902 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 948 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
903 { 949 {
904 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, 950 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
905 "ecore_con_url_cookies_file_add");
906 return; 951 return;
907 } 952 }
908
909 if (url_con->dead) return; 953 if (url_con->dead) return;
910 curl_easy_setopt(url_con->curl_easy, CURLOPT_COOKIEFILE, file_name); 954 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_COOKIEFILE, file_name);
911#else
912 return;
913 (void)url_con;
914 (void)file_name;
915#endif
916} 955}
917 956
918EAPI Eina_Bool 957EAPI Eina_Bool
919ecore_con_url_cookies_jar_file_set(Ecore_Con_Url *url_con, const char *const cookiejar_file) 958ecore_con_url_cookies_jar_file_set(Ecore_Con_Url *url_con, const char *const cookiejar_file)
920{ 959{
921#ifdef HAVE_CURL
922 CURLcode ret; 960 CURLcode ret;
923 961
924 if (!url_con) 962 if (!_c) return EINA_FALSE;
925 return EINA_FALSE;
926
927 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 963 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
928 { 964 {
929 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, 965 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
930 "ecore_con_url_cookies_jar_file_set");
931 return EINA_FALSE; 966 return EINA_FALSE;
932 } 967 }
933
934 if (url_con->dead) return EINA_FALSE; 968 if (url_con->dead) return EINA_FALSE;
935 ret = curl_easy_setopt(url_con->curl_easy, CURLOPT_COOKIEJAR, 969 ret = _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_COOKIEJAR,
936 cookiejar_file); 970 cookiejar_file);
937 if (ret != CURLE_OK) 971 if (ret != CURLE_OK)
938 { 972 {
939 ERR("Setting the cookie-jar name failed: %s", 973 ERR("Setting the cookie-jar name failed: %s",
940 curl_easy_strerror(ret)); 974 _c->curl_easy_strerror(ret));
941 return EINA_FALSE; 975 return EINA_FALSE;
942 } 976 }
943
944 return EINA_TRUE; 977 return EINA_TRUE;
945#else
946 return EINA_FALSE;
947 (void)url_con;
948 (void)cookiejar_file;
949#endif
950} 978}
951 979
952EAPI void 980EAPI void
953ecore_con_url_cookies_jar_write(Ecore_Con_Url *url_con) 981ecore_con_url_cookies_jar_write(Ecore_Con_Url *url_con)
954{ 982{
955#ifdef HAVE_CURL 983 if (!_c) return;
956 if (!url_con)
957 return;
958
959 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 984 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
960 { 985 {
961 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, 986 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
962 "ecore_con_url_cookies_jar_write");
963 return; 987 return;
964 } 988 }
965 989
966 if (url_con->dead) return; 990 if (url_con->dead) return;
967 curl_easy_setopt(url_con->curl_easy, CURLOPT_COOKIELIST, "FLUSH"); 991 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_COOKIELIST, "FLUSH");
968#else
969 return;
970 (void)url_con;
971#endif
972} 992}
973 993
974EAPI void 994EAPI void
975ecore_con_url_verbose_set(Ecore_Con_Url *url_con, Eina_Bool verbose) 995ecore_con_url_verbose_set(Ecore_Con_Url *url_con, Eina_Bool verbose)
976{ 996{
977#ifdef HAVE_CURL 997 if (!_c) return;
978 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 998 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
979 { 999 {
980 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, 1000 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
981 "ecore_con_url_verbose_set");
982 return; 1001 return;
983 } 1002 }
984 1003 if (!url_con->url) return;
985 if (!url_con->url)
986 return;
987
988 if (url_con->dead) return; 1004 if (url_con->dead) return;
989 curl_easy_setopt(url_con->curl_easy, CURLOPT_VERBOSE, (int)verbose); 1005 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_VERBOSE, (int)verbose);
990#else
991 return;
992 (void)url_con;
993 (void)verbose;
994#endif
995} 1006}
996 1007
997EAPI void 1008EAPI void
998ecore_con_url_ftp_use_epsv_set(Ecore_Con_Url *url_con, Eina_Bool use_epsv) 1009ecore_con_url_ftp_use_epsv_set(Ecore_Con_Url *url_con, Eina_Bool use_epsv)
999{ 1010{
1000#ifdef HAVE_CURL 1011 if (!_c) return;
1001 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 1012 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
1002 { 1013 {
1003 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, 1014 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
1004 "ecore_con_url_ftp_use_epsv_set");
1005 return; 1015 return;
1006 } 1016 }
1007 1017 if (!url_con->url) return;
1008 if (!url_con->url)
1009 return;
1010
1011 if (url_con->dead) return; 1018 if (url_con->dead) return;
1012 curl_easy_setopt(url_con->curl_easy, CURLOPT_FTP_USE_EPSV, (int)use_epsv); 1019 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_FTP_USE_EPSV,
1013#else 1020 (int)use_epsv);
1014 return;
1015 (void)url_con;
1016 (void)use_epsv;
1017#endif
1018} 1021}
1019 1022
1020/** 1023/**
@@ -1032,24 +1035,16 @@ ecore_con_url_ftp_use_epsv_set(Ecore_Con_Url *url_con, Eina_Bool use_epsv)
1032EAPI void 1035EAPI void
1033ecore_con_url_ssl_verify_peer_set(Ecore_Con_Url *url_con, Eina_Bool verify) 1036ecore_con_url_ssl_verify_peer_set(Ecore_Con_Url *url_con, Eina_Bool verify)
1034{ 1037{
1035#ifdef HAVE_CURL 1038 if (!_c) return;
1036 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 1039 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
1037 { 1040 {
1038 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, 1041 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
1039 "ecore_con_url_ssl_verify_peer_set");
1040 return; 1042 return;
1041 } 1043 }
1042 1044 if (!url_con->url) return;
1043 if (!url_con->url)
1044 return;
1045
1046 if (url_con->dead) return; 1045 if (url_con->dead) return;
1047 curl_easy_setopt(url_con->curl_easy, CURLOPT_SSL_VERIFYPEER, (int)verify); 1046 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_SSL_VERIFYPEER,
1048#else 1047 (int)verify);
1049 return;
1050 (void)url_con;
1051 (void)verify;
1052#endif
1053} 1048}
1054 1049
1055/** 1050/**
@@ -1075,95 +1070,83 @@ ecore_con_url_ssl_ca_set(Ecore_Con_Url *url_con, const char *ca_path)
1075{ 1070{
1076 int res = -1; 1071 int res = -1;
1077 1072
1078#ifdef HAVE_CURL 1073 if (!_c) return -1;
1079 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 1074 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
1080 { 1075 {
1081 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_ssl_ca_set"); 1076 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
1082 return -1; 1077 return -1;
1083 } 1078 }
1084
1085 if (!url_con->url) return -1; 1079 if (!url_con->url) return -1;
1086 if (url_con->dead) return -1; 1080 if (url_con->dead) return -1;
1087 if (ca_path == NULL) 1081 if (ca_path == NULL)
1088 res = curl_easy_setopt(url_con->curl_easy, CURLOPT_SSL_VERIFYPEER, 0); 1082 res = _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_SSL_VERIFYPEER, 0);
1089 else 1083 else
1090 { 1084 {
1091 res = curl_easy_setopt(url_con->curl_easy, CURLOPT_SSL_VERIFYPEER, 1); 1085 res = _c->curl_easy_setopt(url_con->curl_easy,
1086 CURLOPT_SSL_VERIFYPEER, 1);
1092 if (!res) 1087 if (!res)
1093 res = curl_easy_setopt(url_con->curl_easy, CURLOPT_CAINFO, ca_path); 1088 res = _c->curl_easy_setopt(url_con->curl_easy,
1089 CURLOPT_CAINFO, ca_path);
1094 } 1090 }
1095#else
1096 return -1;
1097 (void)url_con;
1098 (void)ca_path;
1099#endif
1100
1101 return res; 1091 return res;
1102} 1092}
1103 1093
1104EAPI Eina_Bool 1094EAPI Eina_Bool
1105ecore_con_url_http_version_set(Ecore_Con_Url *url_con, Ecore_Con_Url_Http_Version version) 1095ecore_con_url_http_version_set(Ecore_Con_Url *url_con, Ecore_Con_Url_Http_Version version)
1106{ 1096{
1107#ifdef HAVE_CURL
1108 int res = -1; 1097 int res = -1;
1098
1099 if (!_c) return EINA_FALSE;
1109 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 1100 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
1110 { 1101 {
1111 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_http_version_set"); 1102 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
1112 return EINA_FALSE; 1103 return EINA_FALSE;
1113 } 1104 }
1114 if (url_con->dead) return EINA_FALSE; 1105 if (url_con->dead) return EINA_FALSE;
1115 switch (version) 1106 switch (version)
1116 { 1107 {
1117 case ECORE_CON_URL_HTTP_VERSION_1_0: 1108 case ECORE_CON_URL_HTTP_VERSION_1_0:
1118 res = curl_easy_setopt(url_con->curl_easy, 1109 res = _c->curl_easy_setopt(url_con->curl_easy,
1119 CURLOPT_HTTP_VERSION, 1110 CURLOPT_HTTP_VERSION,
1120 CURL_HTTP_VERSION_1_0); 1111 CURL_HTTP_VERSION_1_0);
1121 break; 1112 break;
1122
1123 case ECORE_CON_URL_HTTP_VERSION_1_1: 1113 case ECORE_CON_URL_HTTP_VERSION_1_1:
1124 res = curl_easy_setopt(url_con->curl_easy, 1114 res = _c->curl_easy_setopt(url_con->curl_easy,
1125 CURLOPT_HTTP_VERSION, 1115 CURLOPT_HTTP_VERSION,
1126 CURL_HTTP_VERSION_1_1); 1116 CURL_HTTP_VERSION_1_1);
1127 break; 1117 break;
1128
1129 default: 1118 default:
1130 break; 1119 break;
1131 } 1120 }
1132 if (res != CURLE_OK) 1121 if (res != CURLE_OK)
1133 { 1122 {
1134 ERR("curl http version setting failed: %s", curl_easy_strerror(res)); 1123 ERR("curl http version setting failed: %s", _c->curl_easy_strerror(res));
1135 return EINA_FALSE; 1124 return EINA_FALSE;
1136 } 1125 }
1137 return EINA_TRUE; 1126 return EINA_TRUE;
1138#else
1139 (void)url_con;
1140 (void)version;
1141 return EINA_FALSE;
1142#endif
1143} 1127}
1144 1128
1145EAPI Eina_Bool 1129EAPI Eina_Bool
1146ecore_con_url_proxy_set(Ecore_Con_Url *url_con, const char *proxy) 1130ecore_con_url_proxy_set(Ecore_Con_Url *url_con, const char *proxy)
1147{ 1131{
1148#ifdef HAVE_CURL
1149 int res = -1; 1132 int res = -1;
1150 curl_version_info_data *vers = NULL; 1133 curl_version_info_data *vers = NULL;
1151 1134
1135 if (!_c) return EINA_FALSE;
1152 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 1136 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
1153 { 1137 {
1154 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_proxy_set"); 1138 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
1155 return EINA_FALSE; 1139 return EINA_FALSE;
1156 } 1140 }
1157
1158 if (!url_con->url) return EINA_FALSE; 1141 if (!url_con->url) return EINA_FALSE;
1159 if (url_con->dead) return EINA_FALSE; 1142 if (url_con->dead) return EINA_FALSE;
1160 1143 if (!proxy) res = _c->curl_easy_setopt(url_con->curl_easy,
1161 if (!proxy) res = curl_easy_setopt(url_con->curl_easy, CURLOPT_PROXY, ""); 1144 CURLOPT_PROXY, "");
1162 else 1145 else
1163 { 1146 {
1164 // before curl version 7.21.7, socks protocol:// prefix is not supported 1147 // before curl version 7.21.7, socks protocol:// prefix is not supported
1165 // (e.g. socks4://, socks4a://, socks5:// or socks5h://, etc.) 1148 // (e.g. socks4://, socks4a://, socks5:// or socks5h://, etc.)
1166 vers = curl_version_info(CURLVERSION_NOW); 1149 vers = _c->curl_version_info(CURLVERSION_NOW);
1167 if (vers->version_num < 0x71507) 1150 if (vers->version_num < 0x71507)
1168 { 1151 {
1169 url_con->proxy_type = CURLPROXY_HTTP; 1152 url_con->proxy_type = CURLPROXY_HTTP;
@@ -1175,95 +1158,81 @@ ecore_con_url_proxy_set(Ecore_Con_Url *url_con, const char *proxy)
1175 url_con->proxy_type = CURLPROXY_SOCKS5_HOSTNAME; 1158 url_con->proxy_type = CURLPROXY_SOCKS5_HOSTNAME;
1176 else if (strstr(proxy, "socks5")) 1159 else if (strstr(proxy, "socks5"))
1177 url_con->proxy_type = CURLPROXY_SOCKS5; 1160 url_con->proxy_type = CURLPROXY_SOCKS5;
1178 res = curl_easy_setopt(url_con->curl_easy, CURLOPT_PROXYTYPE, 1161 res = _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_PROXYTYPE,
1179 url_con->proxy_type); 1162 url_con->proxy_type);
1180 if (res != CURLE_OK) 1163 if (res != CURLE_OK)
1181 { 1164 {
1182 ERR("curl proxy type setting failed: %s", 1165 ERR("curl proxy type setting failed: %s",
1183 curl_easy_strerror(res)); 1166 _c->curl_easy_strerror(res));
1184 url_con->proxy_type = -1; 1167 url_con->proxy_type = -1;
1185 return EINA_FALSE; 1168 return EINA_FALSE;
1186 } 1169 }
1187 } 1170 }
1188 res = curl_easy_setopt(url_con->curl_easy, CURLOPT_PROXY, proxy); 1171 res = _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_PROXY, proxy);
1189 } 1172 }
1190 if (res != CURLE_OK) 1173 if (res != CURLE_OK)
1191 { 1174 {
1192 ERR("curl proxy setting failed: %s", curl_easy_strerror(res)); 1175 ERR("curl proxy setting failed: %s", _c->curl_easy_strerror(res));
1193 url_con->proxy_type = -1; 1176 url_con->proxy_type = -1;
1194 return EINA_FALSE; 1177 return EINA_FALSE;
1195 } 1178 }
1196 return EINA_TRUE; 1179 return EINA_TRUE;
1197#else
1198 return EINA_FALSE;
1199 (void)url_con;
1200 (void)proxy;
1201#endif
1202} 1180}
1203 1181
1204EAPI void 1182EAPI void
1205ecore_con_url_timeout_set(Ecore_Con_Url *url_con, double timeout) 1183ecore_con_url_timeout_set(Ecore_Con_Url *url_con, double timeout)
1206{ 1184{
1207#ifdef HAVE_CURL
1208 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 1185 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
1209 { 1186 {
1210 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_timeout_set"); 1187 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
1211 return; 1188 return;
1212 } 1189 }
1213
1214 if (url_con->dead) return; 1190 if (url_con->dead) return;
1215 if (!url_con->url || timeout < 0) return; 1191 if (!url_con->url || timeout < 0) return;
1216 if (url_con->timer) ecore_timer_del(url_con->timer); 1192 if (url_con->timer) ecore_timer_del(url_con->timer);
1217 url_con->timer = ecore_timer_add(timeout, _ecore_con_url_timeout_cb, url_con); 1193 url_con->timer = ecore_timer_add(timeout, _ecore_con_url_timeout_cb,
1218#else 1194 url_con);
1219 return;
1220 (void)url_con;
1221 (void)timeout;
1222#endif
1223} 1195}
1224 1196
1225EAPI Eina_Bool 1197EAPI Eina_Bool
1226ecore_con_url_proxy_username_set(Ecore_Con_Url *url_con, const char *username) 1198ecore_con_url_proxy_username_set(Ecore_Con_Url *url_con, const char *username)
1227{ 1199{
1228#ifdef HAVE_CURL
1229 int res = -1; 1200 int res = -1;
1201
1202 if (!_c) return EINA_FALSE;
1230 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 1203 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
1231 { 1204 {
1232 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_proxy_username_set"); 1205 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
1233 return EINA_FALSE; 1206 return EINA_FALSE;
1234 } 1207 }
1235
1236 if (url_con->dead) return EINA_FALSE; 1208 if (url_con->dead) return EINA_FALSE;
1237 if (!url_con->url) return EINA_FALSE; 1209 if (!url_con->url) return EINA_FALSE;
1238 if ((!username) || (!username[0])) return EINA_FALSE; 1210 if ((!username) || (!username[0])) return EINA_FALSE;
1239 if (url_con->proxy_type == CURLPROXY_SOCKS4 || url_con->proxy_type == CURLPROXY_SOCKS4A) 1211 if ((url_con->proxy_type == CURLPROXY_SOCKS4) ||
1212 (url_con->proxy_type == CURLPROXY_SOCKS4A))
1240 { 1213 {
1241 ERR("Proxy type should be socks5 and above"); 1214 ERR("Proxy type should be socks5 and above");
1242 return EINA_FALSE; 1215 return EINA_FALSE;
1243 } 1216 }
1244 1217
1245 res = curl_easy_setopt(url_con->curl_easy, CURLOPT_USERNAME, username); 1218 res = _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_USERNAME, username);
1246 if (res != CURLE_OK) 1219 if (res != CURLE_OK)
1247 { 1220 {
1248 ERR("curl_easy_setopt() failed: %s", curl_easy_strerror(res)); 1221 ERR("curl_easy_setopt() failed: %s", _c->curl_easy_strerror(res));
1249 return EINA_FALSE; 1222 return EINA_FALSE;
1250 } 1223 }
1251 return EINA_TRUE; 1224 return EINA_TRUE;
1252#else
1253 return EINA_FALSE;
1254 (void)url_con;
1255 (void)username;
1256#endif
1257} 1225}
1258 1226
1259EAPI Eina_Bool 1227EAPI Eina_Bool
1260ecore_con_url_proxy_password_set(Ecore_Con_Url *url_con, const char *password) 1228ecore_con_url_proxy_password_set(Ecore_Con_Url *url_con, const char *password)
1261{ 1229{
1262#ifdef HAVE_CURL
1263 int res = -1; 1230 int res = -1;
1231
1232 if (!_c) return EINA_FALSE;
1264 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 1233 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
1265 { 1234 {
1266 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_proxy_password_set"); 1235 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
1267 return EINA_FALSE; 1236 return EINA_FALSE;
1268 } 1237 }
1269 if (!url_con->url) return EINA_FALSE; 1238 if (!url_con->url) return EINA_FALSE;
@@ -1274,33 +1243,28 @@ ecore_con_url_proxy_password_set(Ecore_Con_Url *url_con, const char *password)
1274 ERR("Proxy type should be socks5 and above"); 1243 ERR("Proxy type should be socks5 and above");
1275 return EINA_FALSE; 1244 return EINA_FALSE;
1276 } 1245 }
1277 1246 res = _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_PASSWORD, password);
1278 res = curl_easy_setopt(url_con->curl_easy, CURLOPT_PASSWORD, password);
1279 if (res != CURLE_OK) 1247 if (res != CURLE_OK)
1280 { 1248 {
1281 ERR("curl_easy_setopt() failed: %s", curl_easy_strerror(res)); 1249 ERR("curl_easy_setopt() failed: %s", _c->curl_easy_strerror(res));
1282 return EINA_FALSE; 1250 return EINA_FALSE;
1283 } 1251 }
1284 return EINA_TRUE; 1252 return EINA_TRUE;
1285#else
1286 return EINA_FALSE;
1287 (void)url_con;
1288 (void)password;
1289#endif
1290} 1253}
1291 1254
1292/** 1255/**
1293 * @} 1256 * @}
1294 */ 1257 */
1295 1258
1296#ifdef HAVE_CURL
1297static void 1259static void
1298_ecore_con_url_status_get(Ecore_Con_Url *url_con) 1260_ecore_con_url_status_get(Ecore_Con_Url *url_con)
1299{ 1261{
1300 long status = 0; 1262 long status = 0;
1301 1263
1264 if (!_c) return;
1302 if (!url_con->curl_easy) return; 1265 if (!url_con->curl_easy) return;
1303 if (!curl_easy_getinfo(url_con->curl_easy, CURLINFO_RESPONSE_CODE, &status)) 1266 if (!_c->curl_easy_getinfo(url_con->curl_easy, CURLINFO_RESPONSE_CODE,
1267 &status))
1304 url_con->status = status; 1268 url_con->status = status;
1305 else 1269 else
1306 url_con->status = 0; 1270 url_con->status = 0;
@@ -1312,13 +1276,12 @@ _ecore_con_url_event_url_complete(Ecore_Con_Url *url_con, CURLMsg *curlmsg)
1312 Ecore_Con_Event_Url_Complete *e; 1276 Ecore_Con_Event_Url_Complete *e;
1313 int status = url_con->status; 1277 int status = url_con->status;
1314 1278
1279 if (!_c) return;
1315 e = calloc(1, sizeof(Ecore_Con_Event_Url_Complete)); 1280 e = calloc(1, sizeof(Ecore_Con_Event_Url_Complete));
1316 if (!e) return; 1281 if (!e) return;
1317 1282
1318 if (!curlmsg) 1283 if (!curlmsg)
1319 { 1284 ERR("Event completed without CURL message handle. Shouldn't happen");
1320 ERR("Event completed without CURL message handle. Shouldn't happen");
1321 }
1322 else if ((curlmsg->msg == CURLMSG_DONE) && 1285 else if ((curlmsg->msg == CURLMSG_DONE) &&
1323 (curlmsg->data.result == CURLE_OPERATION_TIMEDOUT) && 1286 (curlmsg->data.result == CURLE_OPERATION_TIMEDOUT) &&
1324 (!curlmsg->easy_handle)) 1287 (!curlmsg->easy_handle))
@@ -1337,14 +1300,13 @@ _ecore_con_url_event_url_complete(Ecore_Con_Url *url_con, CURLMsg *curlmsg)
1337 else 1300 else
1338 { 1301 {
1339 ERR("Curl message have errors: %d (%s)", 1302 ERR("Curl message have errors: %d (%s)",
1340 curlmsg->data.result, curl_easy_strerror(curlmsg->data.result)); 1303 curlmsg->data.result, _c->curl_easy_strerror(curlmsg->data.result));
1341 } 1304 }
1342
1343 e->status = status; 1305 e->status = status;
1344 e->url_con = url_con; 1306 e->url_con = url_con;
1345
1346 url_con->event_count++; 1307 url_con->event_count++;
1347 ecore_event_add(ECORE_CON_EVENT_URL_COMPLETE, e, (Ecore_End_Cb)_ecore_con_event_url_free, url_con); 1308 ecore_event_add(ECORE_CON_EVENT_URL_COMPLETE, e,
1309 (Ecore_End_Cb)_ecore_con_event_url_free, url_con);
1348} 1310}
1349 1311
1350static void 1312static void
@@ -1352,9 +1314,10 @@ _ecore_con_url_multi_remove(Ecore_Con_Url *url_con)
1352{ 1314{
1353 CURLMcode ret; 1315 CURLMcode ret;
1354 1316
1355 ret = curl_multi_remove_handle(_curlm, url_con->curl_easy); 1317 if (!_c) return;
1318 ret = _c->curl_multi_remove_handle(_c->_curlm, url_con->curl_easy);
1356 url_con->multi = EINA_FALSE; 1319 url_con->multi = EINA_FALSE;
1357 if (ret != CURLM_OK) ERR("curl_multi_remove_handle failed: %s", curl_multi_strerror(ret)); 1320 if (ret != CURLM_OK) ERR("curl_multi_remove_handle failed: %s", _c->curl_multi_strerror(ret));
1358} 1321}
1359 1322
1360static Eina_Bool 1323static Eina_Bool
@@ -1363,13 +1326,14 @@ _ecore_con_url_timeout_cb(void *data)
1363 Ecore_Con_Url *url_con = data; 1326 Ecore_Con_Url *url_con = data;
1364 CURLMsg timeout_msg; 1327 CURLMsg timeout_msg;
1365 1328
1329 if (!_c) return ECORE_CALLBACK_CANCEL;
1366 if (!url_con) return ECORE_CALLBACK_CANCEL; 1330 if (!url_con) return ECORE_CALLBACK_CANCEL;
1367 if (!url_con->curl_easy) return ECORE_CALLBACK_CANCEL; 1331 if (!url_con->curl_easy) return ECORE_CALLBACK_CANCEL;
1368 1332
1369 _ecore_con_url_multi_remove(url_con); 1333 _ecore_con_url_multi_remove(url_con);
1370 _url_con_list = eina_list_remove(_url_con_list, url_con); 1334 _url_con_list = eina_list_remove(_url_con_list, url_con);
1371 1335
1372 curl_slist_free_all(url_con->headers); 1336 _c->curl_slist_free_all(url_con->headers);
1373 url_con->headers = NULL; 1337 url_con->headers = NULL;
1374 1338
1375 url_con->timer = NULL; 1339 url_con->timer = NULL;
@@ -1390,18 +1354,14 @@ _ecore_con_url_data_cb(void *buffer, size_t size, size_t nitems, void *userp)
1390 size_t real_size = size * nitems; 1354 size_t real_size = size * nitems;
1391 1355
1392 url_con = (Ecore_Con_Url *)userp; 1356 url_con = (Ecore_Con_Url *)userp;
1393 1357 if (!url_con) return -1;
1394 if (!url_con)
1395 return -1;
1396
1397 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 1358 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
1398 { 1359 {
1399 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_data_cb"); 1360 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
1400 return -1; 1361 return -1;
1401 } 1362 }
1402 1363
1403 url_con->received += real_size; 1364 url_con->received += real_size;
1404
1405 INF("reading from %s", url_con->url); 1365 INF("reading from %s", url_con->url);
1406 if (url_con->write_fd < 0) 1366 if (url_con->write_fd < 0)
1407 { 1367 {
@@ -1414,7 +1374,8 @@ _ecore_con_url_data_cb(void *buffer, size_t size, size_t nitems, void *userp)
1414 e->size = real_size; 1374 e->size = real_size;
1415 memcpy(e->data, buffer, real_size); 1375 memcpy(e->data, buffer, real_size);
1416 url_con->event_count++; 1376 url_con->event_count++;
1417 ecore_event_add(ECORE_CON_EVENT_URL_DATA, e, (Ecore_End_Cb)_ecore_con_event_url_free, url_con); 1377 ecore_event_add(ECORE_CON_EVENT_URL_DATA, e,
1378 (Ecore_End_Cb)_ecore_con_event_url_free, url_con);
1418 } 1379 }
1419 } 1380 }
1420 else 1381 else
@@ -1430,8 +1391,7 @@ _ecore_con_url_data_cb(void *buffer, size_t size, size_t nitems, void *userp)
1430 total_size); 1391 total_size);
1431 if (count < 0) 1392 if (count < 0)
1432 { 1393 {
1433 if (errno != EAGAIN && errno != EINTR) 1394 if ((errno != EAGAIN) && (errno != EINTR)) return -1;
1434 return -1;
1435 } 1395 }
1436 else 1396 else
1437 { 1397 {
@@ -1440,7 +1400,6 @@ _ecore_con_url_data_cb(void *buffer, size_t size, size_t nitems, void *userp)
1440 } 1400 }
1441 } 1401 }
1442 } 1402 }
1443
1444 return real_size; 1403 return real_size;
1445} 1404}
1446 1405
@@ -1451,15 +1410,11 @@ _ecore_con_url_header_cb(void *ptr, size_t size, size_t nitems, void *stream)
1451 Ecore_Con_Url *url_con = stream; 1410 Ecore_Con_Url *url_con = stream;
1452 1411
1453 char *header = malloc(sizeof(char) * (real_size + 1)); 1412 char *header = malloc(sizeof(char) * (real_size + 1));
1454 if (!header) 1413 if (!header) return real_size;
1455 return real_size;
1456
1457 memcpy(header, ptr, real_size); 1414 memcpy(header, ptr, real_size);
1458 header[real_size] = '\0'; 1415 header[real_size] = '\0';
1459
1460 url_con->response_headers = eina_list_append(url_con->response_headers, 1416 url_con->response_headers = eina_list_append(url_con->response_headers,
1461 header); 1417 header);
1462
1463 return real_size; 1418 return real_size;
1464} 1419}
1465 1420
@@ -1470,7 +1425,6 @@ _ecore_con_url_progress_cb(void *clientp, double dltotal, double dlnow, double u
1470 Ecore_Con_Url *url_con; 1425 Ecore_Con_Url *url_con;
1471 1426
1472 url_con = clientp; 1427 url_con = clientp;
1473
1474 e = malloc(sizeof(Ecore_Con_Event_Url_Progress)); 1428 e = malloc(sizeof(Ecore_Con_Event_Url_Progress));
1475 if (e) 1429 if (e)
1476 { 1430 {
@@ -1480,9 +1434,9 @@ _ecore_con_url_progress_cb(void *clientp, double dltotal, double dlnow, double u
1480 e->up.total = ultotal; 1434 e->up.total = ultotal;
1481 e->up.now = ulnow; 1435 e->up.now = ulnow;
1482 url_con->event_count++; 1436 url_con->event_count++;
1483 ecore_event_add(ECORE_CON_EVENT_URL_PROGRESS, e, (Ecore_End_Cb)_ecore_con_event_url_free, url_con); 1437 ecore_event_add(ECORE_CON_EVENT_URL_PROGRESS, e,
1438 (Ecore_End_Cb)_ecore_con_event_url_free, url_con);
1484 } 1439 }
1485
1486 return 0; 1440 return 0;
1487} 1441}
1488 1442
@@ -1501,7 +1455,6 @@ _ecore_con_url_read_cb(void *ptr, size_t size, size_t nitems, void *stream)
1501 fclose((FILE *)stream); 1455 fclose((FILE *)stream);
1502 return 0; 1456 return 0;
1503 } 1457 }
1504
1505#ifdef _WIN32 1458#ifdef _WIN32
1506 INF("*** We read %Iu bytes from file", retcode); 1459 INF("*** We read %Iu bytes from file", retcode);
1507#else 1460#else
@@ -1516,12 +1469,13 @@ _ecore_con_url_info_read(void)
1516 CURLMsg *curlmsg; 1469 CURLMsg *curlmsg;
1517 int n_remaining; 1470 int n_remaining;
1518 1471
1519 while ((curlmsg = curl_multi_info_read(_curlm, &n_remaining))) 1472 if (!_c) return;
1473 while ((curlmsg = _c->curl_multi_info_read(_c->_curlm, &n_remaining)))
1520 { 1474 {
1521 Eina_List *l, *ll; 1475 Eina_List *l, *ll;
1522 Ecore_Con_Url *url_con = NULL; 1476 Ecore_Con_Url *url_con = NULL;
1477
1523 DBG("Curl message: %d", curlmsg->msg); 1478 DBG("Curl message: %d", curlmsg->msg);
1524
1525 if (curlmsg->msg == CURLMSG_DONE) 1479 if (curlmsg->msg == CURLMSG_DONE)
1526 { 1480 {
1527 EINA_LIST_FOREACH_SAFE(_url_con_list, l, ll, url_con) 1481 EINA_LIST_FOREACH_SAFE(_url_con_list, l, ll, url_con)
@@ -1549,15 +1503,12 @@ _ecore_con_url_fd_handler(void *data EINA_UNUSED, Ecore_Fd_Handler *fd_handler E
1549 Ecore_Fd_Handler *fdh; 1503 Ecore_Fd_Handler *fdh;
1550 long ms; 1504 long ms;
1551 1505
1506 if (!_c) return ECORE_CALLBACK_CANCEL;
1552 EINA_LIST_FREE(_fd_hd_list, fdh) ecore_main_fd_handler_del(fdh); 1507 EINA_LIST_FREE(_fd_hd_list, fdh) ecore_main_fd_handler_del(fdh);
1553 1508 _c->curl_multi_timeout(_c->_curlm, &ms);
1554 curl_multi_timeout(_curlm, &ms);
1555 if ((ms >= CURL_MIN_TIMEOUT) || (ms <= 0)) ms = CURL_MIN_TIMEOUT; 1509 if ((ms >= CURL_MIN_TIMEOUT) || (ms <= 0)) ms = CURL_MIN_TIMEOUT;
1556 ecore_timer_interval_set(_curl_timer, (double)ms / 1000.0); 1510 ecore_timer_interval_set(_curl_timer, (double)ms / 1000.0);
1557 1511 if (!_curl_idler) _curl_idler = ecore_idler_add(_ecore_con_url_timer, NULL);
1558 if (!_curl_idler)
1559 _curl_idler = ecore_idler_add(_ecore_con_url_timer, NULL);
1560
1561 return ECORE_CALLBACK_CANCEL; 1512 return ECORE_CALLBACK_CANCEL;
1562} 1513}
1563 1514
@@ -1568,14 +1519,17 @@ _ecore_con_url_fdset(void)
1568 fd_set read_set, write_set, exc_set; 1519 fd_set read_set, write_set, exc_set;
1569 int fd, fd_max; 1520 int fd, fd_max;
1570 1521
1522 if (!_c) return;
1523
1571 FD_ZERO(&read_set); 1524 FD_ZERO(&read_set);
1572 FD_ZERO(&write_set); 1525 FD_ZERO(&write_set);
1573 FD_ZERO(&exc_set); 1526 FD_ZERO(&exc_set);
1574 1527
1575 ret = curl_multi_fdset(_curlm, &read_set, &write_set, &exc_set, &fd_max); 1528 ret = _c->curl_multi_fdset(_c->_curlm, &read_set,
1529 &write_set, &exc_set, &fd_max);
1576 if (ret != CURLM_OK) 1530 if (ret != CURLM_OK)
1577 { 1531 {
1578 ERR("curl_multi_fdset failed: %s", curl_multi_strerror(ret)); 1532 ERR("curl_multi_fdset failed: %s", _c->curl_multi_strerror(ret));
1579 return; 1533 return;
1580 } 1534 }
1581 1535
@@ -1587,7 +1541,8 @@ _ecore_con_url_fdset(void)
1587 if (FD_ISSET(fd, &exc_set)) flags |= ECORE_FD_ERROR; 1541 if (FD_ISSET(fd, &exc_set)) flags |= ECORE_FD_ERROR;
1588 if (flags) 1542 if (flags)
1589 { 1543 {
1590 // FIXME: Who is owner (easy_handle) of this fd?? (Curl do not give this info.) 1544 // FIXME: Who is owner (easy_handle) of this fd??
1545 // (Curl do not give this info.)
1591 // This cause "Failed to delete epoll fd xx!" error messages 1546 // This cause "Failed to delete epoll fd xx!" error messages
1592 Ecore_Fd_Handler *fd_handler; 1547 Ecore_Fd_Handler *fd_handler;
1593 fd_handler = ecore_main_fd_handler_add(fd, flags, 1548 fd_handler = ecore_main_fd_handler_add(fd, flags,
@@ -1608,8 +1563,8 @@ _ecore_con_url_timer(void *data EINA_UNUSED)
1608 1563
1609 EINA_LIST_FREE(_fd_hd_list, fdh) ecore_main_fd_handler_del(fdh); 1564 EINA_LIST_FREE(_fd_hd_list, fdh) ecore_main_fd_handler_del(fdh);
1610 _ecore_con_url_info_read(); 1565 _ecore_con_url_info_read();
1611 1566 if (!_c) return ECORE_CALLBACK_RENEW;
1612 ret = curl_multi_perform(_curlm, &still_running); 1567 ret = _c->curl_multi_perform(_c->_curlm, &still_running);
1613 if (ret == CURLM_CALL_MULTI_PERFORM) 1568 if (ret == CURLM_CALL_MULTI_PERFORM)
1614 { 1569 {
1615 DBG("curl_multi_perform() again immediately"); 1570 DBG("curl_multi_perform() again immediately");
@@ -1617,7 +1572,7 @@ _ecore_con_url_timer(void *data EINA_UNUSED)
1617 } 1572 }
1618 else if (ret != CURLM_OK) 1573 else if (ret != CURLM_OK)
1619 { 1574 {
1620 ERR("curl_multi_perform() failed: %s", curl_multi_strerror(ret)); 1575 ERR("curl_multi_perform() failed: %s", _c->curl_multi_strerror(ret));
1621 _ecore_con_url_curl_clear(); 1576 _ecore_con_url_curl_clear();
1622 ecore_timer_freeze(_curl_timer); 1577 ecore_timer_freeze(_curl_timer);
1623 if (_curl_idler) 1578 if (_curl_idler)
@@ -1626,13 +1581,14 @@ _ecore_con_url_timer(void *data EINA_UNUSED)
1626 _curl_idler = NULL; 1581 _curl_idler = NULL;
1627 } 1582 }
1628 } 1583 }
1629
1630 if (still_running) 1584 if (still_running)
1631 { 1585 {
1632 long ms; 1586 long ms;
1587
1633 _ecore_con_url_fdset(); 1588 _ecore_con_url_fdset();
1634 curl_multi_timeout(_curlm, &ms); 1589 _c->curl_multi_timeout(_c->_curlm, &ms);
1635 DBG("multiperform is still running: %d, timeout: %ld", still_running, ms); 1590 DBG("multiperform is still running: %d, timeout: %ld",
1591 still_running, ms);
1636 if ((ms >= CURL_MIN_TIMEOUT) || (ms <= 0)) ms = CURL_MIN_TIMEOUT; 1592 if ((ms >= CURL_MIN_TIMEOUT) || (ms <= 0)) ms = CURL_MIN_TIMEOUT;
1637 ecore_timer_interval_set(_curl_timer, (double)ms / 1000.0); 1593 ecore_timer_interval_set(_curl_timer, (double)ms / 1000.0);
1638 } 1594 }
@@ -1648,7 +1604,6 @@ _ecore_con_url_timer(void *data EINA_UNUSED)
1648 _curl_idler = NULL; 1604 _curl_idler = NULL;
1649 } 1605 }
1650 } 1606 }
1651
1652 return ECORE_CALLBACK_RENEW; 1607 return ECORE_CALLBACK_RENEW;
1653} 1608}
1654 1609
@@ -1657,17 +1612,17 @@ _ecore_con_url_perform(Ecore_Con_Url *url_con)
1657{ 1612{
1658 CURLMcode ret; 1613 CURLMcode ret;
1659 1614
1660 ret = curl_multi_add_handle(_curlm, url_con->curl_easy); 1615 if (!_c) return EINA_FALSE;
1616 ret = _c->curl_multi_add_handle(_c->_curlm, url_con->curl_easy);
1661 if (ret != CURLM_OK) 1617 if (ret != CURLM_OK)
1662 { 1618 {
1663 ERR("curl_multi_add_handle() failed: %s", curl_multi_strerror(ret)); 1619 ERR("curl_multi_add_handle() failed: %s",
1620 _c->curl_multi_strerror(ret));
1664 return EINA_FALSE; 1621 return EINA_FALSE;
1665 } 1622 }
1666
1667 url_con->multi = EINA_TRUE; 1623 url_con->multi = EINA_TRUE;
1668 _url_con_list = eina_list_append(_url_con_list, url_con); 1624 _url_con_list = eina_list_append(_url_con_list, url_con);
1669 ecore_timer_thaw(_curl_timer); 1625 ecore_timer_thaw(_curl_timer);
1670
1671 return EINA_TRUE; 1626 return EINA_TRUE;
1672} 1627}
1673 1628
@@ -1676,8 +1631,5 @@ _ecore_con_event_url_free(Ecore_Con_Url *url_con, void *ev)
1676{ 1631{
1677 free(ev); 1632 free(ev);
1678 url_con->event_count--; 1633 url_con->event_count--;
1679 if (url_con->dead && (!url_con->event_count)) 1634 if (url_con->dead && (!url_con->event_count)) ecore_con_url_free(url_con);
1680 ecore_con_url_free(url_con);
1681} 1635}
1682
1683#endif