summaryrefslogtreecommitdiff
path: root/src/lib/ecore_con/ecore_con_url.c
diff options
context:
space:
mode:
authordiscomfitor <michael.blumenkrantz@gmail.com>2013-12-20 00:07:50 -0500
committerdiscomfitor <michael.blumenkrantz@gmail.com>2013-12-20 00:08:43 -0500
commit41fe698fc2ac2b02b5fefcd5e638a5486f36c353 (patch)
tree4c08633f376d57037c41f25687fc9f5925cb767a /src/lib/ecore_con/ecore_con_url.c
parent2bcfc800c991b33aea116d16ad962a6eae6ac697 (diff)
reformat ecore_con so I can read it...
Diffstat (limited to '')
-rw-r--r--src/lib/ecore_con/ecore_con_url.c311
1 files changed, 171 insertions, 140 deletions
diff --git a/src/lib/ecore_con/ecore_con_url.c b/src/lib/ecore_con/ecore_con_url.c
index 4e4c19dd00..0a796d3d17 100644
--- a/src/lib/ecore_con/ecore_con_url.c
+++ b/src/lib/ecore_con/ecore_con_url.c
@@ -33,11 +33,13 @@
33// all the types, defines, enums etc. from curl that we actuall USE. 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 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 35// defined here. see culr headers to get them from
36typedef enum { 36typedef enum
37{
37 CURLM_CALL_MULTI_PERFORM = -1, 38 CURLM_CALL_MULTI_PERFORM = -1,
38 CURLM_OK = 0 39 CURLM_OK = 0
39} CURLMcode; 40} CURLMcode;
40typedef enum { 41typedef enum
42{
41 CURLE_OK = 0, 43 CURLE_OK = 0,
42 CURLE_OPERATION_TIMEDOUT = 28 44 CURLE_OPERATION_TIMEDOUT = 28
43} CURLcode; 45} CURLcode;
@@ -45,10 +47,11 @@ typedef enum {
45#define CURLOPTTYPE_OBJECTPOINT 10000 47#define CURLOPTTYPE_OBJECTPOINT 10000
46#define CURLOPTTYPE_FUNCTIONPOINT 20000 48#define CURLOPTTYPE_FUNCTIONPOINT 20000
47#define CURLOPTTYPE_OFF_T 30000 49#define CURLOPTTYPE_OFF_T 30000
48#define CINIT(na,t,nu) CURLOPT_ ## na = CURLOPTTYPE_ ## t + nu 50#define CINIT(na, t, nu) CURLOPT_ ## na = CURLOPTTYPE_ ## t + nu
49typedef enum { 51typedef enum
52{
50 CINIT(FILE, OBJECTPOINT, 1), 53 CINIT(FILE, OBJECTPOINT, 1),
51 CINIT(URL, OBJECTPOINT, 2), 54 CINIT(URL, OBJECTPOINT, 2),
52 CINIT(PROXY, OBJECTPOINT, 4), 55 CINIT(PROXY, OBJECTPOINT, 4),
53 CINIT(USERPWD, OBJECTPOINT, 5), 56 CINIT(USERPWD, OBJECTPOINT, 5),
54 CINIT(INFILE, OBJECTPOINT, 9), 57 CINIT(INFILE, OBJECTPOINT, 9),
@@ -91,30 +94,37 @@ typedef enum {
91#define CURLINFO_SLIST 0x400000 94#define CURLINFO_SLIST 0x400000
92#define CURLINFO_MASK 0x0fffff 95#define CURLINFO_MASK 0x0fffff
93#define CURLINFO_TYPEMASK 0xf00000 96#define CURLINFO_TYPEMASK 0xf00000
94typedef enum { 97typedef enum
95 CURLINFO_RESPONSE_CODE = CURLINFO_LONG + 2, 98{
99 CURLINFO_RESPONSE_CODE = CURLINFO_LONG + 2,
96} CURLINFO; 100} CURLINFO;
97typedef enum { 101typedef enum
102{
98 CURLVERSION_FOURTH = 3 103 CURLVERSION_FOURTH = 3
99} CURLversion; 104} CURLversion;
100typedef enum { 105typedef enum
106{
101 CURLMSG_DONE = 1 107 CURLMSG_DONE = 1
102} CURLMSG; 108} CURLMSG;
103#undef CINIT 109#undef CINIT
104#define CINIT(name,type,num) CURLMOPT_ ## name = CURLOPTTYPE_ ## type + num 110#define CINIT(name, type, num) CURLMOPT_ ## name = CURLOPTTYPE_ ## type + num
105typedef enum { 111typedef enum
112{
106 CINIT(PIPELINING, LONG, 3) 113 CINIT(PIPELINING, LONG, 3)
107} CURLMoption; 114} CURLMoption;
108typedef enum { 115typedef enum
116{
109 CURL_TIMECOND_NONE = 0, 117 CURL_TIMECOND_NONE = 0,
110 CURL_TIMECOND_IFMODSINCE = 1, 118 CURL_TIMECOND_IFMODSINCE = 1,
111 CURL_TIMECOND_IFUNMODSINCE = 2 119 CURL_TIMECOND_IFUNMODSINCE = 2
112} curl_TimeCond; 120} curl_TimeCond;
113enum { 121enum
122{
114 CURL_HTTP_VERSION_1_0 = 1, 123 CURL_HTTP_VERSION_1_0 = 1,
115 CURL_HTTP_VERSION_1_1 = 2, 124 CURL_HTTP_VERSION_1_1 = 2,
116}; 125};
117typedef enum { 126typedef enum
127{
118 CURLPROXY_HTTP = 0, 128 CURLPROXY_HTTP = 0,
119 CURLPROXY_SOCKS4 = 4, 129 CURLPROXY_SOCKS4 = 4,
120 CURLPROXY_SOCKS5 = 5, 130 CURLPROXY_SOCKS5 = 5,
@@ -122,90 +132,93 @@ typedef enum {
122 CURLPROXY_SOCKS5_HOSTNAME = 7 132 CURLPROXY_SOCKS5_HOSTNAME = 7
123} curl_proxytype; 133} curl_proxytype;
124 134
125#define CURL_GLOBAL_SSL (1<<0) 135#define CURL_GLOBAL_SSL (1 << 0)
126#define CURL_GLOBAL_WIN32 (1<<1) 136#define CURL_GLOBAL_WIN32 (1 << 1)
127#define CURL_GLOBAL_ALL (CURL_GLOBAL_SSL|CURL_GLOBAL_WIN32) 137#define CURL_GLOBAL_ALL (CURL_GLOBAL_SSL | CURL_GLOBAL_WIN32)
128#define CURLOPT_ENCODING CURLOPT_ACCEPT_ENCODING 138#define CURLOPT_ENCODING CURLOPT_ACCEPT_ENCODING
129#define CURLOPT_WRITEDATA CURLOPT_FILE 139#define CURLOPT_WRITEDATA CURLOPT_FILE
130#define CURLOPT_READDATA CURLOPT_INFILE 140#define CURLOPT_READDATA CURLOPT_INFILE
131#define CURLOPT_HEADERDATA CURLOPT_WRITEHEADER 141#define CURLOPT_HEADERDATA CURLOPT_WRITEHEADER
132#define CURLVERSION_NOW CURLVERSION_FOURTH 142#define CURLVERSION_NOW CURLVERSION_FOURTH
133#define CURLAUTH_BASIC (((unsigned long)1)<<0) 143#define CURLAUTH_BASIC (((unsigned long)1) << 0)
134#define CURLAUTH_DIGEST_IE (((unsigned long)1)<<4) 144#define CURLAUTH_DIGEST_IE (((unsigned long)1) << 4)
135#define CURLAUTH_ANY (~CURLAUTH_DIGEST_IE) 145#define CURLAUTH_ANY (~CURLAUTH_DIGEST_IE)
136#define CURLAUTH_ANYSAFE (~(CURLAUTH_BASIC|CURLAUTH_DIGEST_IE)) 146#define CURLAUTH_ANYSAFE (~(CURLAUTH_BASIC | CURLAUTH_DIGEST_IE))
137#define CURL_READFUNC_ABORT 0x10000000 147#define CURL_READFUNC_ABORT 0x10000000
138 148
139typedef void CURLM; 149typedef void CURLM;
140typedef void CURL; 150typedef void CURL;
141struct curl_slist { 151struct curl_slist
142 char *data; 152{
153 char *data;
143 struct curl_slist *next; 154 struct curl_slist *next;
144}; 155};
145typedef struct { 156typedef struct
146 CURLversion age; 157{
147 const char *version; 158 CURLversion age;
148 unsigned int version_num; 159 const char *version;
149 const char *host; 160 unsigned int version_num;
150 int features; 161 const char *host;
151 const char *ssl_version; 162 int features;
152 long ssl_version_num; 163 const char *ssl_version;
153 const char *libz_version; 164 long ssl_version_num;
154 const char * const *protocols; 165 const char *libz_version;
155 const char *ares; 166 const char *const *protocols;
156 int ares_num; 167 const char *ares;
157 const char *libidn; 168 int ares_num;
158 int iconv_ver_num; 169 const char *libidn;
159 const char *libssh_version; 170 int iconv_ver_num;
171 const char *libssh_version;
160} curl_version_info_data; 172} curl_version_info_data;
161typedef struct { 173typedef struct
174{
162 CURLMSG msg; 175 CURLMSG msg;
163 CURL *easy_handle; 176 CURL *easy_handle;
164 union { 177 union
165 void *whatever; 178 {
179 void *whatever;
166 CURLcode result; 180 CURLcode result;
167 } data; 181 } data;
168} CURLMsg; 182} CURLMsg;
169 183
170
171typedef struct _Ecore_Con_Curl Ecore_Con_Curl; 184typedef struct _Ecore_Con_Curl Ecore_Con_Curl;
172 185
173struct _Ecore_Con_Curl 186struct _Ecore_Con_Curl
174{ 187{
175 Eina_Module *mod; 188 Eina_Module *mod;
176 189
177 CURLM *_curlm; 190 CURLM *_curlm;
178 191
179 CURLcode (*curl_global_init) (long flags); 192 CURLcode (*curl_global_init)(long flags);
180 void (*curl_global_cleanup)(void); 193 void (*curl_global_cleanup)(void);
181 CURLM *(*curl_multi_init)(void); 194 CURLM *(*curl_multi_init)(void);
182 CURLMcode (*curl_multi_timeout)(CURLM *multi_handle, 195 CURLMcode (*curl_multi_timeout)(CURLM *multi_handle,
183 long *milliseconds); 196 long *milliseconds);
184 CURLMcode (*curl_multi_cleanup)(CURLM *multi_handle); 197 CURLMcode (*curl_multi_cleanup)(CURLM *multi_handle);
185 CURLMcode (*curl_multi_remove_handle)(CURLM *multi_handle, 198 CURLMcode (*curl_multi_remove_handle)(CURLM *multi_handle,
186 CURL *curl_handle); 199 CURL *curl_handle);
187 const char *(*curl_multi_strerror)(CURLMcode); 200 const char *(*curl_multi_strerror)(CURLMcode);
188 CURLMsg *(*curl_multi_info_read)(CURLM *multi_handle, 201 CURLMsg *(*curl_multi_info_read)(CURLM * multi_handle,
189 int *msgs_in_queue); 202 int *msgs_in_queue);
190 CURLMcode (*curl_multi_fdset)(CURLM *multi_handle, 203 CURLMcode (*curl_multi_fdset)(CURLM *multi_handle,
191 fd_set *read_fd_set, 204 fd_set *read_fd_set,
192 fd_set *write_fd_set, 205 fd_set *write_fd_set,
193 fd_set *exc_fd_set, 206 fd_set *exc_fd_set,
194 int *max_fd); 207 int *max_fd);
195 CURLMcode (*curl_multi_perform)(CURLM *multi_handle, 208 CURLMcode (*curl_multi_perform)(CURLM *multi_handle,
196 int *running_handles); 209 int *running_handles);
197 CURLMcode (*curl_multi_add_handle)(CURLM *multi_handle, 210 CURLMcode (*curl_multi_add_handle)(CURLM *multi_handle,
198 CURL *curl_handle); 211 CURL *curl_handle);
199 CURLMcode (*curl_multi_setopt)(CURLM *multi_handle, 212 CURLMcode (*curl_multi_setopt)(CURLM *multi_handle,
200 CURLMoption option, ...); 213 CURLMoption option, ...);
201 CURL *(*curl_easy_init)(void); 214 CURL *(*curl_easy_init)(void);
202 CURLcode (*curl_easy_setopt)(CURL *curl, CURLoption option, ...); 215 CURLcode (*curl_easy_setopt)(CURL *curl, CURLoption option, ...);
203 const char *(*curl_easy_strerror)(CURLcode); 216 const char *(*curl_easy_strerror)(CURLcode);
204 void (*curl_easy_cleanup)(CURL *curl); 217 void (*curl_easy_cleanup)(CURL *curl);
205 CURLcode (*curl_easy_getinfo)(CURL *curl, CURLINFO info, ...); 218 CURLcode (*curl_easy_getinfo)(CURL *curl, CURLINFO info, ...);
206 void (*curl_slist_free_all)(struct curl_slist *); 219 void (*curl_slist_free_all)(struct curl_slist *);
207 struct curl_slist *(*curl_slist_append)(struct curl_slist *list, 220 struct curl_slist *(*curl_slist_append)(struct curl_slist *list,
208 const char *string); 221 const char *string);
209 curl_version_info_data *(*curl_version_info)(CURLversion); 222 curl_version_info_data *(*curl_version_info)(CURLversion);
210}; 223};
211 224
@@ -242,33 +255,34 @@ static Eina_Bool
242_c_init(void) 255_c_init(void)
243{ 256{
244 long ms = 0; 257 long ms = 0;
245 258
246 if (_c) return EINA_TRUE; 259 if (_c) return EINA_TRUE;
247 if (_c_fail) return EINA_FALSE; 260 if (_c_fail) return EINA_FALSE;
248 _c = calloc(1, sizeof(Ecore_Con_Curl)); 261 _c = calloc(1, sizeof(Ecore_Con_Curl));
249 if (!_c) goto error; 262 if (!_c) goto error;
250 263
251#define LOAD(x) \ 264#define LOAD(x) \
252 if (!_c->mod) { \ 265 if (!_c->mod) { \
253 if ((_c->mod = eina_module_new(x))) { \ 266 if ((_c->mod = eina_module_new(x))) { \
254 if (!eina_module_load(_c->mod)) { \ 267 if (!eina_module_load(_c->mod)) { \
255 eina_module_free(_c->mod); \ 268 eina_module_free(_c->mod); \
256 _c->mod = NULL; \ 269 _c->mod = NULL; \
257 } \ 270 } \
258 } \ 271 } \
259 } 272 }
260#if defined(_WIN32) || defined(__CYGWIN__) 273#if defined(_WIN32) || defined(__CYGWIN__)
261 LOAD("libcurl.dll"); // try 1 274 LOAD("libcurl.dll"); // try 1
262 LOAD("curllib.dll"); // if fail try 2 275 LOAD("curllib.dll"); // if fail try 2
263#elif defined(__APPLE__) && defined(__MACH__) 276#elif defined(__APPLE__) && defined(__MACH__)
264 LOAD("libcurl.4.dylib"); // try 1 277 LOAD("libcurl.4.dylib"); // try 1
265 LOAD("libcurl.so.4"); // if fail try 2 278 LOAD("libcurl.so.4"); // if fail try 2
266#else 279#else
267 LOAD("libcurl.so.4"); // try only 280 LOAD("libcurl.so.4"); // try only
268#endif 281#endif
269 if (!_c->mod) goto error; 282 if (!_c->mod) goto error;
270 283
271#define SYM(x) if (!(_c->x = eina_module_symbol_get(_c->mod, #x))) goto error 284#define SYM(x) if (!(_c->x = eina_module_symbol_get(_c->mod, #x))) \
285 goto error
272 SYM(curl_global_init); 286 SYM(curl_global_init);
273 SYM(curl_global_cleanup); 287 SYM(curl_global_cleanup);
274 SYM(curl_multi_init); 288 SYM(curl_multi_init);
@@ -289,7 +303,7 @@ _c_init(void)
289 SYM(curl_slist_free_all); 303 SYM(curl_slist_free_all);
290 SYM(curl_slist_append); 304 SYM(curl_slist_append);
291 SYM(curl_version_info); 305 SYM(curl_version_info);
292 306
293 // curl_global_init() is not thread safe! 307 // curl_global_init() is not thread safe!
294 if (_c->curl_global_init(CURL_GLOBAL_ALL)) goto error; 308 if (_c->curl_global_init(CURL_GLOBAL_ALL)) goto error;
295 _c->_curlm = _c->curl_multi_init(); 309 _c->_curlm = _c->curl_multi_init();
@@ -396,7 +410,7 @@ ecore_con_url_new(const char *url)
396 410
397 if (!_init_count) return NULL; 411 if (!_init_count) return NULL;
398 if (!_c_init()) return NULL; 412 if (!_c_init()) return NULL;
399 413
400 url_con = calloc(1, sizeof(Ecore_Con_Url)); 414 url_con = calloc(1, sizeof(Ecore_Con_Url));
401 if (!url_con) return NULL; 415 if (!url_con) return NULL;
402 416
@@ -429,24 +443,26 @@ ecore_con_url_new(const char *url)
429 if (_ecore_con_proxy_global->version == 5) 443 if (_ecore_con_proxy_global->version == 5)
430 { 444 {
431 if (_ecore_con_proxy_global->lookup) 445 if (_ecore_con_proxy_global->lookup)
432 snprintf(host, sizeof(host), "socks5h://%s", 446 snprintf(host, sizeof(host), "socks5h://%s",
433 _ecore_con_proxy_global->ip); 447 _ecore_con_proxy_global->ip);
434 else snprintf(host, sizeof(host), "socks5://%s", 448 else
435 _ecore_con_proxy_global->ip); 449 snprintf(host, sizeof(host), "socks5://%s",
450 _ecore_con_proxy_global->ip);
436 } 451 }
437 else if (_ecore_con_proxy_global->version == 4) 452 else if (_ecore_con_proxy_global->version == 4)
438 { 453 {
439 if (_ecore_con_proxy_global->lookup) 454 if (_ecore_con_proxy_global->lookup)
440 snprintf(host, sizeof(host), "socks4a://%s", 455 snprintf(host, sizeof(host), "socks4a://%s",
441 _ecore_con_proxy_global->ip); 456 _ecore_con_proxy_global->ip);
442 else snprintf(host, sizeof(host), "socks4://%s", 457 else
443 _ecore_con_proxy_global->ip); 458 snprintf(host, sizeof(host), "socks4://%s",
459 _ecore_con_proxy_global->ip);
444 } 460 }
445 461
446 if (_ecore_con_proxy_global->port > 0 && 462 if (_ecore_con_proxy_global->port > 0 &&
447 _ecore_con_proxy_global->port <= 65535) 463 _ecore_con_proxy_global->port <= 65535)
448 snprintf(proxy, sizeof(proxy), "%s:%d", host, 464 snprintf(proxy, sizeof(proxy), "%s:%d", host,
449 _ecore_con_proxy_global->port); 465 _ecore_con_proxy_global->port);
450 else snprintf(proxy, sizeof(proxy), "%s", host); 466 else snprintf(proxy, sizeof(proxy), "%s", host);
451 467
452 ecore_con_url_proxy_set(url_con, proxy); 468 ecore_con_url_proxy_set(url_con, proxy);
@@ -467,12 +483,12 @@ ecore_con_url_new(const char *url)
467 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_WRITEFUNCTION, 483 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_WRITEFUNCTION,
468 _ecore_con_url_data_cb); 484 _ecore_con_url_data_cb);
469 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_WRITEDATA, url_con); 485 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_WRITEDATA, url_con);
470 486
471 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_PROGRESSFUNCTION, 487 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_PROGRESSFUNCTION,
472 _ecore_con_url_progress_cb); 488 _ecore_con_url_progress_cb);
473 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_PROGRESSDATA, url_con); 489 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_PROGRESSDATA, url_con);
474 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_NOPROGRESS, EINA_FALSE); 490 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_NOPROGRESS, EINA_FALSE);
475 491
476 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_HEADERFUNCTION, 492 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_HEADERFUNCTION,
477 _ecore_con_url_header_cb); 493 _ecore_con_url_header_cb);
478 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_HEADERDATA, url_con); 494 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_HEADERDATA, url_con);
@@ -549,8 +565,10 @@ ecore_con_url_free(Ecore_Con_Url *url_con)
549 ECORE_MAGIC_SET(url_con, ECORE_MAGIC_NONE); 565 ECORE_MAGIC_SET(url_con, ECORE_MAGIC_NONE);
550 566
551 _c->curl_slist_free_all(url_con->headers); 567 _c->curl_slist_free_all(url_con->headers);
552 EINA_LIST_FREE(url_con->additional_headers, s) free(s); 568 EINA_LIST_FREE(url_con->additional_headers, s)
553 EINA_LIST_FREE(url_con->response_headers, s) free(s); 569 free(s);
570 EINA_LIST_FREE(url_con->response_headers, s)
571 free(s);
554 eina_stringshare_del(url_con->url); 572 eina_stringshare_del(url_con->url);
555 if (url_con->post_data) free(url_con->post_data); 573 if (url_con->post_data) free(url_con->post_data);
556 free(url_con); 574 free(url_con);
@@ -639,7 +657,8 @@ ecore_con_url_additional_headers_clear(Ecore_Con_Url *url_con)
639 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__); 657 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
640 return; 658 return;
641 } 659 }
642 EINA_LIST_FREE(url_con->additional_headers, s) free(s); 660 EINA_LIST_FREE(url_con->additional_headers, s)
661 free(s);
643} 662}
644 663
645EAPI void * 664EAPI void *
@@ -720,11 +739,11 @@ ecore_con_url_httpauth_set(Ecore_Con_Url *url_con, const char *username, const c
720 { 739 {
721 if (safe) 740 if (safe)
722 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_HTTPAUTH, 741 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_HTTPAUTH,
723 CURLAUTH_ANYSAFE); 742 CURLAUTH_ANYSAFE);
724 else 743 else
725 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_HTTPAUTH, 744 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_HTTPAUTH,
726 CURLAUTH_ANY); 745 CURLAUTH_ANY);
727 746
728 ret = _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_USERNAME, 747 ret = _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_USERNAME,
729 username); 748 username);
730 if (ret != CURLE_OK) 749 if (ret != CURLE_OK)
@@ -733,7 +752,7 @@ ecore_con_url_httpauth_set(Ecore_Con_Url *url_con, const char *username, const c
733 _c->curl_easy_strerror(ret)); 752 _c->curl_easy_strerror(ret));
734 return EINA_FALSE; 753 return EINA_FALSE;
735 } 754 }
736 755
737 ret = _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_PASSWORD, 756 ret = _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_PASSWORD,
738 password); 757 password);
739 if (ret != CURLE_OK) 758 if (ret != CURLE_OK)
@@ -770,7 +789,8 @@ _ecore_con_url_send(Ecore_Con_Url *url_con, int mode, const void *data, long len
770 if (url_con->dead) return EINA_FALSE; 789 if (url_con->dead) return EINA_FALSE;
771 790
772 /* Free response headers from previous send() calls */ 791 /* Free response headers from previous send() calls */
773 EINA_LIST_FREE(url_con->response_headers, s) free((char *)s); 792 EINA_LIST_FREE(url_con->response_headers, s)
793 free((char *)s);
774 url_con->response_headers = NULL; 794 url_con->response_headers = NULL;
775 url_con->status = 0; 795 url_con->status = 0;
776 796
@@ -801,8 +821,9 @@ _ecore_con_url_send(Ecore_Con_Url *url_con, int mode, const void *data, long len
801 else 821 else
802 return EINA_FALSE; 822 return EINA_FALSE;
803 } 823 }
804 else _c->curl_easy_setopt(url_con->curl_easy, 824 else
805 CURLOPT_POSTFIELDSIZE, 0); 825 _c->curl_easy_setopt(url_con->curl_easy,
826 CURLOPT_POSTFIELDSIZE, 0);
806 if (mode == MODE_POST) 827 if (mode == MODE_POST)
807 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_POST, 1); 828 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_POST, 1);
808 } 829 }
@@ -811,19 +832,21 @@ _ecore_con_url_send(Ecore_Con_Url *url_con, int mode, const void *data, long len
811 { 832 {
812 case ECORE_CON_URL_TIME_NONE: 833 case ECORE_CON_URL_TIME_NONE:
813 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION, 834 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION,
814 CURL_TIMECOND_NONE); 835 CURL_TIMECOND_NONE);
815 break; 836 break;
837
816 case ECORE_CON_URL_TIME_IFMODSINCE: 838 case ECORE_CON_URL_TIME_IFMODSINCE:
817 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION, 839 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION,
818 CURL_TIMECOND_IFMODSINCE); 840 CURL_TIMECOND_IFMODSINCE);
819 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMEVALUE, 841 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMEVALUE,
820 (long)url_con->timestamp); 842 (long)url_con->timestamp);
821 break; 843 break;
844
822 case ECORE_CON_URL_TIME_IFUNMODSINCE: 845 case ECORE_CON_URL_TIME_IFUNMODSINCE:
823 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION, 846 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION,
824 CURL_TIMECOND_IFUNMODSINCE); 847 CURL_TIMECOND_IFUNMODSINCE);
825 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMEVALUE, 848 _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMEVALUE,
826 (long)url_con->timestamp); 849 (long)url_con->timestamp);
827 break; 850 break;
828 } 851 }
829 /* Additional headers */ 852 /* Additional headers */
@@ -1112,7 +1135,7 @@ EAPI Eina_Bool
1112ecore_con_url_http_version_set(Ecore_Con_Url *url_con, Ecore_Con_Url_Http_Version version) 1135ecore_con_url_http_version_set(Ecore_Con_Url *url_con, Ecore_Con_Url_Http_Version version)
1113{ 1136{
1114 int res = -1; 1137 int res = -1;
1115 1138
1116 if (!_c) return EINA_FALSE; 1139 if (!_c) return EINA_FALSE;
1117 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 1140 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
1118 { 1141 {
@@ -1127,11 +1150,13 @@ ecore_con_url_http_version_set(Ecore_Con_Url *url_con, Ecore_Con_Url_Http_Versio
1127 CURLOPT_HTTP_VERSION, 1150 CURLOPT_HTTP_VERSION,
1128 CURL_HTTP_VERSION_1_0); 1151 CURL_HTTP_VERSION_1_0);
1129 break; 1152 break;
1153
1130 case ECORE_CON_URL_HTTP_VERSION_1_1: 1154 case ECORE_CON_URL_HTTP_VERSION_1_1:
1131 res = _c->curl_easy_setopt(url_con->curl_easy, 1155 res = _c->curl_easy_setopt(url_con->curl_easy,
1132 CURLOPT_HTTP_VERSION, 1156 CURLOPT_HTTP_VERSION,
1133 CURL_HTTP_VERSION_1_1); 1157 CURL_HTTP_VERSION_1_1);
1134 break; 1158 break;
1159
1135 default: 1160 default:
1136 break; 1161 break;
1137 } 1162 }
@@ -1157,8 +1182,9 @@ ecore_con_url_proxy_set(Ecore_Con_Url *url_con, const char *proxy)
1157 } 1182 }
1158 if (!url_con->url) return EINA_FALSE; 1183 if (!url_con->url) return EINA_FALSE;
1159 if (url_con->dead) return EINA_FALSE; 1184 if (url_con->dead) return EINA_FALSE;
1160 if (!proxy) res = _c->curl_easy_setopt(url_con->curl_easy, 1185 if (!proxy)
1161 CURLOPT_PROXY, ""); 1186 res = _c->curl_easy_setopt(url_con->curl_easy,
1187 CURLOPT_PROXY, "");
1162 else 1188 else
1163 { 1189 {
1164 // before curl version 7.21.7, socks protocol:// prefix is not supported 1190 // before curl version 7.21.7, socks protocol:// prefix is not supported
@@ -1215,7 +1241,7 @@ EAPI Eina_Bool
1215ecore_con_url_proxy_username_set(Ecore_Con_Url *url_con, const char *username) 1241ecore_con_url_proxy_username_set(Ecore_Con_Url *url_con, const char *username)
1216{ 1242{
1217 int res = -1; 1243 int res = -1;
1218 1244
1219 if (!_c) return EINA_FALSE; 1245 if (!_c) return EINA_FALSE;
1220 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 1246 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
1221 { 1247 {
@@ -1245,7 +1271,7 @@ EAPI Eina_Bool
1245ecore_con_url_proxy_password_set(Ecore_Con_Url *url_con, const char *password) 1271ecore_con_url_proxy_password_set(Ecore_Con_Url *url_con, const char *password)
1246{ 1272{
1247 int res = -1; 1273 int res = -1;
1248 1274
1249 if (!_c) return EINA_FALSE; 1275 if (!_c) return EINA_FALSE;
1250 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) 1276 if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
1251 { 1277 {
@@ -1277,7 +1303,7 @@ static void
1277_ecore_con_url_status_get(Ecore_Con_Url *url_con) 1303_ecore_con_url_status_get(Ecore_Con_Url *url_con)
1278{ 1304{
1279 long status = 0; 1305 long status = 0;
1280 1306
1281 if (!_c) return; 1307 if (!_c) return;
1282 if (!url_con->curl_easy) return; 1308 if (!url_con->curl_easy) return;
1283 if (!_c->curl_easy_getinfo(url_con->curl_easy, CURLINFO_RESPONSE_CODE, 1309 if (!_c->curl_easy_getinfo(url_con->curl_easy, CURLINFO_RESPONSE_CODE,
@@ -1317,7 +1343,7 @@ _ecore_con_url_event_url_complete(Ecore_Con_Url *url_con, CURLMsg *curlmsg)
1317 else 1343 else
1318 { 1344 {
1319 ERR("Curl message have errors: %d (%s)", 1345 ERR("Curl message have errors: %d (%s)",
1320 curlmsg->data.result, _c->curl_easy_strerror(curlmsg->data.result)); 1346 curlmsg->data.result, _c->curl_easy_strerror(curlmsg->data.result));
1321 } 1347 }
1322 e->status = status; 1348 e->status = status;
1323 e->url_con = url_con; 1349 e->url_con = url_con;
@@ -1451,7 +1477,7 @@ _ecore_con_url_progress_cb(void *clientp, double dltotal, double dlnow, double u
1451 e->up.total = ultotal; 1477 e->up.total = ultotal;
1452 e->up.now = ulnow; 1478 e->up.now = ulnow;
1453 url_con->event_count++; 1479 url_con->event_count++;
1454 ecore_event_add(ECORE_CON_EVENT_URL_PROGRESS, e, 1480 ecore_event_add(ECORE_CON_EVENT_URL_PROGRESS, e,
1455 (Ecore_End_Cb)_ecore_con_event_url_free, url_con); 1481 (Ecore_End_Cb)_ecore_con_event_url_free, url_con);
1456 } 1482 }
1457 return 0; 1483 return 0;
@@ -1491,7 +1517,7 @@ _ecore_con_url_info_read(void)
1491 { 1517 {
1492 Eina_List *l, *ll; 1518 Eina_List *l, *ll;
1493 Ecore_Con_Url *url_con = NULL; 1519 Ecore_Con_Url *url_con = NULL;
1494 1520
1495 DBG("Curl message: %d", curlmsg->msg); 1521 DBG("Curl message: %d", curlmsg->msg);
1496 if (curlmsg->msg == CURLMSG_DONE) 1522 if (curlmsg->msg == CURLMSG_DONE)
1497 { 1523 {
@@ -1500,7 +1526,7 @@ _ecore_con_url_info_read(void)
1500 if (curlmsg->easy_handle == url_con->curl_easy) 1526 if (curlmsg->easy_handle == url_con->curl_easy)
1501 _ecore_con_url_event_url_complete(url_con, curlmsg); 1527 _ecore_con_url_event_url_complete(url_con, curlmsg);
1502 } 1528 }
1503 } 1529 }
1504 } 1530 }
1505} 1531}
1506 1532
@@ -1510,8 +1536,10 @@ _ecore_con_url_curl_clear(void)
1510 Ecore_Fd_Handler *fdh; 1536 Ecore_Fd_Handler *fdh;
1511 Ecore_Con_Url *url_con; 1537 Ecore_Con_Url *url_con;
1512 1538
1513 EINA_LIST_FREE(_fd_hd_list, fdh) ecore_main_fd_handler_del(fdh); 1539 EINA_LIST_FREE(_fd_hd_list, fdh)
1514 EINA_LIST_FREE(_url_con_list, url_con) _ecore_con_url_multi_remove(url_con); 1540 ecore_main_fd_handler_del(fdh);
1541 EINA_LIST_FREE(_url_con_list, url_con)
1542 _ecore_con_url_multi_remove(url_con);
1515} 1543}
1516 1544
1517static Eina_Bool 1545static Eina_Bool
@@ -1521,7 +1549,8 @@ _ecore_con_url_fd_handler(void *data EINA_UNUSED, Ecore_Fd_Handler *fd_handler E
1521 long ms; 1549 long ms;
1522 1550
1523 if (!_c) return ECORE_CALLBACK_CANCEL; 1551 if (!_c) return ECORE_CALLBACK_CANCEL;
1524 EINA_LIST_FREE(_fd_hd_list, fdh) ecore_main_fd_handler_del(fdh); 1552 EINA_LIST_FREE(_fd_hd_list, fdh)
1553 ecore_main_fd_handler_del(fdh);
1525 _c->curl_multi_timeout(_c->_curlm, &ms); 1554 _c->curl_multi_timeout(_c->_curlm, &ms);
1526 if ((ms >= CURL_MIN_TIMEOUT) || (ms <= 0)) ms = CURL_MIN_TIMEOUT; 1555 if ((ms >= CURL_MIN_TIMEOUT) || (ms <= 0)) ms = CURL_MIN_TIMEOUT;
1527 ecore_timer_interval_set(_curl_timer, (double)ms / 1000.0); 1556 ecore_timer_interval_set(_curl_timer, (double)ms / 1000.0);
@@ -1537,7 +1566,7 @@ _ecore_con_url_fdset(void)
1537 int fd, fd_max; 1566 int fd, fd_max;
1538 1567
1539 if (!_c) return; 1568 if (!_c) return;
1540 1569
1541 FD_ZERO(&read_set); 1570 FD_ZERO(&read_set);
1542 FD_ZERO(&write_set); 1571 FD_ZERO(&write_set);
1543 FD_ZERO(&exc_set); 1572 FD_ZERO(&exc_set);
@@ -1566,7 +1595,7 @@ _ecore_con_url_fdset(void)
1566 _ecore_con_url_fd_handler, 1595 _ecore_con_url_fd_handler,
1567 NULL, NULL, NULL); 1596 NULL, NULL, NULL);
1568 if (fd_handler) 1597 if (fd_handler)
1569 _fd_hd_list = eina_list_append(_fd_hd_list, fd_handler); 1598 _fd_hd_list = eina_list_append(_fd_hd_list, fd_handler);
1570 } 1599 }
1571 } 1600 }
1572} 1601}
@@ -1578,7 +1607,8 @@ _ecore_con_url_timer(void *data EINA_UNUSED)
1578 int still_running; 1607 int still_running;
1579 CURLMcode ret; 1608 CURLMcode ret;
1580 1609
1581 EINA_LIST_FREE(_fd_hd_list, fdh) ecore_main_fd_handler_del(fdh); 1610 EINA_LIST_FREE(_fd_hd_list, fdh)
1611 ecore_main_fd_handler_del(fdh);
1582 _ecore_con_url_info_read(); 1612 _ecore_con_url_info_read();
1583 if (!_c) return ECORE_CALLBACK_RENEW; 1613 if (!_c) return ECORE_CALLBACK_RENEW;
1584 ret = _c->curl_multi_perform(_c->_curlm, &still_running); 1614 ret = _c->curl_multi_perform(_c->_curlm, &still_running);
@@ -1601,7 +1631,7 @@ _ecore_con_url_timer(void *data EINA_UNUSED)
1601 if (still_running) 1631 if (still_running)
1602 { 1632 {
1603 long ms; 1633 long ms;
1604 1634
1605 _ecore_con_url_fdset(); 1635 _ecore_con_url_fdset();
1606 _c->curl_multi_timeout(_c->_curlm, &ms); 1636 _c->curl_multi_timeout(_c->_curlm, &ms);
1607 DBG("multiperform is still running: %d, timeout: %ld", 1637 DBG("multiperform is still running: %d, timeout: %ld",
@@ -1650,3 +1680,4 @@ _ecore_con_event_url_free(Ecore_Con_Url *url_con, void *ev)
1650 url_con->event_count--; 1680 url_con->event_count--;
1651 if (url_con->dead && (!url_con->event_count)) ecore_con_url_free(url_con); 1681 if (url_con->dead && (!url_con->event_count)) ecore_con_url_free(url_con);
1652} 1682}
1683