reformat ecore_con so I can read it...

This commit is contained in:
discomfitor 2013-12-20 00:07:50 -05:00
parent 2bcfc800c9
commit 41fe698fc2
11 changed files with 1115 additions and 1049 deletions

View File

@ -209,7 +209,6 @@ ecore_con_init(void)
ECORE_CON_EVENT_SERVER_ERROR = ecore_event_type_new(); ECORE_CON_EVENT_SERVER_ERROR = ecore_event_type_new();
ECORE_CON_EVENT_PROXY_BIND = ecore_event_type_new(); ECORE_CON_EVENT_PROXY_BIND = ecore_event_type_new();
eina_magic_string_set(ECORE_MAGIC_CON_SERVER, "Ecore_Con_Server"); eina_magic_string_set(ECORE_MAGIC_CON_SERVER, "Ecore_Con_Server");
eina_magic_string_set(ECORE_MAGIC_CON_CLIENT, "Ecore_Con_Client"); eina_magic_string_set(ECORE_MAGIC_CON_CLIENT, "Ecore_Con_Client");
eina_magic_string_set(ECORE_MAGIC_CON_URL, "Ecore_Con_Url"); eina_magic_string_set(ECORE_MAGIC_CON_URL, "Ecore_Con_Url");
@ -419,7 +418,6 @@ error:
if (svr->path) if (svr->path)
free(svr->path); free(svr->path);
if (svr->fd_handler) if (svr->fd_handler)
ecore_main_fd_handler_del(svr->fd_handler); ecore_main_fd_handler_del(svr->fd_handler);
@ -1195,7 +1193,6 @@ ecore_con_event_client_data(Ecore_Con_Client *cl, unsigned char *buf, int num, E
_ecore_con_event_count++; _ecore_con_event_count++;
} }
void void
ecore_con_server_infos_del(Ecore_Con_Server *svr, void *info) ecore_con_server_infos_del(Ecore_Con_Server *svr, void *info)
{ {
@ -1889,6 +1886,7 @@ _ecore_con_pretty_ip(struct sockaddr *client_addr)
case AF_INET: case AF_INET:
src = &(((struct sockaddr_in *)client_addr)->sin_addr); src = &(((struct sockaddr_in *)client_addr)->sin_addr);
break; break;
#ifdef HAVE_IPV6 #ifdef HAVE_IPV6
case AF_INET6: case AF_INET6:
src = &(((struct sockaddr_in6 *)client_addr)->sin6_addr); src = &(((struct sockaddr_in6 *)client_addr)->sin6_addr);
@ -1899,6 +1897,7 @@ _ecore_con_pretty_ip(struct sockaddr *client_addr)
src = (char *)src + 12; src = (char *)src + 12;
} }
break; break;
#endif #endif
default: default:
return eina_stringshare_add("0.0.0.0"); return eina_stringshare_add("0.0.0.0");
@ -2190,7 +2189,6 @@ _ecore_con_svr_udp_handler(void *data,
return ECORE_CALLBACK_CANCEL; return ECORE_CALLBACK_CANCEL;
} }
/* Create a new client for use in the client data event */ /* Create a new client for use in the client data event */
cl = calloc(1, sizeof(Ecore_Con_Client)); cl = calloc(1, sizeof(Ecore_Con_Client));
EINA_SAFETY_ON_NULL_RETURN_VAL(cl, ECORE_CALLBACK_RENEW); EINA_SAFETY_ON_NULL_RETURN_VAL(cl, ECORE_CALLBACK_RENEW);
@ -2680,7 +2678,6 @@ _ecore_con_event_server_data_free(void *data EINA_UNUSED,
ecore_con_mempool_shutdown(); ecore_con_mempool_shutdown();
} }
static void static void
_ecore_con_event_server_error_free(void *data EINA_UNUSED, Ecore_Con_Event_Server_Error *e) _ecore_con_event_server_error_free(void *data EINA_UNUSED, Ecore_Con_Event_Server_Error *e)
{ {

View File

@ -44,7 +44,8 @@ struct _Ecore_Con_CAres
struct addrinfo hints; struct addrinfo hints;
Ecore_Con_Info *result; Ecore_Con_Info *result;
union { union
{
struct in_addr v4; struct in_addr v4;
#ifdef HAVE_IPV6 #ifdef HAVE_IPV6
struct in6_addr v6; struct in6_addr v6;
@ -465,6 +466,7 @@ _ecore_con_info_ares_host_cb(Ecore_Con_CAres *arg,
addr = (struct sockaddr *)addri; addr = (struct sockaddr *)addri;
break; break;
} }
#ifdef HAVE_IPV6 #ifdef HAVE_IPV6
case AF_INET6: case AF_INET6:
{ {
@ -487,6 +489,7 @@ _ecore_con_info_ares_host_cb(Ecore_Con_CAres *arg,
addr = (struct sockaddr *)addri6; addr = (struct sockaddr *)addri6;
break; break;
} }
#endif #endif
default: default:
ERR("Unknown addrtype %i", hostent->h_addrtype); ERR("Unknown addrtype %i", hostent->h_addrtype);

View File

@ -78,8 +78,10 @@ _ecore_con_dns_check(Ecore_Con_DNS *dns)
{ {
case 0: case 0:
break; break;
case EAGAIN: case EAGAIN:
return 1; return 1;
default: default:
ERR("resolve failed: %s", dns_strerror(error)); ERR("resolve failed: %s", dns_strerror(error));
goto error; goto error;
@ -298,7 +300,6 @@ ecore_con_info_get(Ecore_Con_Server *svr,
{ {
ERR("res_open: %s", dns_strerror(error)); ERR("res_open: %s", dns_strerror(error));
goto reserr; goto reserr;
} }
error = _dns_addrinfo_get(dns, svr->ecs ? svr->ecs->ip : svr->name, dns->svr->ecs ? dns->svr->ecs->port : dns->svr->port); error = _dns_addrinfo_get(dns, svr->ecs ? svr->ecs->ip : svr->name, dns->svr->ecs ? dns->svr->ecs->port : dns->svr->port);
@ -312,11 +313,13 @@ ecore_con_info_get(Ecore_Con_Server *svr,
{ {
case 0: case 0:
break; break;
case 1: case 1:
dns->fdh = ecore_main_fd_handler_add(dns_ai_pollfd(dns->ai), dns_ai_events(dns->ai), (Ecore_Fd_Cb)_dns_fd_cb, dns, NULL, NULL); dns->fdh = ecore_main_fd_handler_add(dns_ai_pollfd(dns->ai), dns_ai_events(dns->ai), (Ecore_Fd_Cb)_dns_fd_cb, dns, NULL, NULL);
svr->infos = eina_list_append(svr->infos, dns); svr->infos = eina_list_append(svr->infos, dns);
dns->timer = ecore_timer_add(5.0, (Ecore_Task_Cb)_dns_timer_cb, dns); dns->timer = ecore_timer_add(5.0, (Ecore_Task_Cb)_dns_timer_cb, dns);
break; break;
default: default:
return 0; return 0;
} }

View File

@ -76,13 +76,16 @@ struct _Ecore_Con_Eet
Eina_Hash *data_callbacks; Eina_Hash *data_callbacks;
Eina_Hash *raw_data_callbacks; Eina_Hash *raw_data_callbacks;
union { union
struct { {
struct
{
Eina_List *connections; Eina_List *connections;
Eina_List *client_connect_callbacks; Eina_List *client_connect_callbacks;
Eina_List *client_disconnect_callbacks; Eina_List *client_disconnect_callbacks;
} server; } server;
struct { struct
{
Ecore_Con_Reply *r; Ecore_Con_Reply *r;
Eina_List *server_connect_callbacks; Eina_List *server_connect_callbacks;
Eina_List *server_disconnect_callbacks; Eina_List *server_disconnect_callbacks;
@ -111,6 +114,7 @@ _ecore_con_eet_raw_data_free(void *data)
eina_stringshare_del(eced->name); eina_stringshare_del(eced->name);
free(eced); free(eced);
} }
static void static void
_ecore_con_eet_reply_cleanup(Ecore_Con_Reply *n) _ecore_con_eet_reply_cleanup(Ecore_Con_Reply *n)
{ {
@ -122,7 +126,8 @@ _ecore_con_eet_reply_cleanup(Ecore_Con_Reply *n)
} }
typedef struct _Ecore_Con_Eet_Protocol Ecore_Con_Eet_Protocol; typedef struct _Ecore_Con_Eet_Protocol Ecore_Con_Eet_Protocol;
struct _Ecore_Con_Eet_Protocol { struct _Ecore_Con_Eet_Protocol
{
const char *type; const char *type;
void *data; void *data;
}; };

View File

@ -77,7 +77,8 @@ ecore_con_info_shutdown(void)
{ {
info_init--; info_init--;
if (info_init == 0) if (info_init == 0)
while (info_slaves) _ecore_con_info_slave_free(info_slaves); while (info_slaves)
_ecore_con_info_slave_free(info_slaves);
return info_init; return info_init;
} }

View File

@ -12,7 +12,6 @@
#define BUFSIZE 512 #define BUFSIZE 512
static int _ecore_con_local_init_count = 0; static int _ecore_con_local_init_count = 0;
int int
@ -33,7 +32,6 @@ ecore_con_local_shutdown(void)
return _ecore_con_local_init_count; return _ecore_con_local_init_count;
} }
static Eina_Bool static Eina_Bool
_ecore_con_local_win32_server_read_client_handler(void *data, Ecore_Win32_Handler *wh) _ecore_con_local_win32_server_read_client_handler(void *data, Ecore_Win32_Handler *wh)
{ {
@ -752,3 +750,4 @@ ecore_con_local_win32_client_flush(Ecore_Con_Client *cl)
return EINA_TRUE; return EINA_TRUE;
} }

View File

@ -220,7 +220,8 @@ _ecore_con_socks_svr_init_v5(Ecore_Con_Server *svr, Ecore_Con_Socks_v5 *v5)
if (eina_binbuf_length_get(svr->ecs_recvbuf) != EXACT) return; \ if (eina_binbuf_length_get(svr->ecs_recvbuf) != EXACT) return; \
data = eina_binbuf_string_get(svr->ecs_recvbuf); \ data = eina_binbuf_string_get(svr->ecs_recvbuf); \
} \ } \
else if (num > EXACT) goto error; \ else if (num > EXACT) \
goto error; \
else \ else \
data = buf data = buf
@ -238,15 +239,19 @@ _ecore_con_socks_read_v4(Ecore_Con_Server *svr, Ecore_Con_Socks_v4 *v4 EINA_UNUS
case 90: case 90:
/* success! */ /* success! */
break; break;
case 91: case 91:
ecore_con_event_server_error(svr, "proxy request rejected or failed"); ecore_con_event_server_error(svr, "proxy request rejected or failed");
goto error; goto error;
case 92: case 92:
ecore_con_event_server_error(svr, "proxying SOCKS server could not perform authentication"); ecore_con_event_server_error(svr, "proxying SOCKS server could not perform authentication");
goto error; goto error;
case 93: case 93:
ecore_con_event_server_error(svr, "proxy request authentication rejected"); ecore_con_event_server_error(svr, "proxy request authentication rejected");
goto error; goto error;
default: default:
ecore_con_event_server_error(svr, "garbage data from proxy"); ecore_con_event_server_error(svr, "garbage data from proxy");
goto error; goto error;
@ -288,8 +293,10 @@ _ecore_con_socks_auth_v5(Ecore_Con_Server *svr, Ecore_Con_Socks_v5 *v5)
case ECORE_CON_SOCKS_V5_METHOD_NONE: case ECORE_CON_SOCKS_V5_METHOD_NONE:
svr->ecs_state = ECORE_CON_PROXY_STATE_REQUEST; svr->ecs_state = ECORE_CON_PROXY_STATE_REQUEST;
return EINA_TRUE; return EINA_TRUE;
case ECORE_CON_SOCKS_V5_METHOD_GSSAPI: case ECORE_CON_SOCKS_V5_METHOD_GSSAPI:
return EINA_TRUE; return EINA_TRUE;
case ECORE_CON_SOCKS_V5_METHOD_USERPASS: case ECORE_CON_SOCKS_V5_METHOD_USERPASS:
if (!v5->username) return EINA_FALSE; if (!v5->username) return EINA_FALSE;
if (!v5->password) v5->plen = 1; if (!v5->password) v5->plen = 1;
@ -307,6 +314,7 @@ _ecore_con_socks_auth_v5(Ecore_Con_Server *svr, Ecore_Con_Socks_v5 *v5)
data[2 + v5->ulen] = 0; data[2 + v5->ulen] = 0;
svr->ecs_buf = eina_binbuf_manage_new_length(data, size); svr->ecs_buf = eina_binbuf_manage_new_length(data, size);
return EINA_TRUE; return EINA_TRUE;
default: default:
break; break;
} }
@ -321,7 +329,6 @@ _ecore_con_socks_read_v5(Ecore_Con_Server *svr, Ecore_Con_Socks_v5 *v5, const un
DBG("SOCKS: %d bytes", num); DBG("SOCKS: %d bytes", num);
switch (svr->ecs_state) switch (svr->ecs_state)
{ {
case ECORE_CON_PROXY_STATE_READ: case ECORE_CON_PROXY_STATE_READ:
ECORE_CON_SOCKS_READ(2); ECORE_CON_SOCKS_READ(2);
/* http://en.wikipedia.org/wiki/SOCKS */ /* http://en.wikipedia.org/wiki/SOCKS */
@ -342,6 +349,7 @@ _ecore_con_socks_read_v5(Ecore_Con_Server *svr, Ecore_Con_Socks_v5 *v5, const un
ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_WRITE); ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_WRITE);
svr->ecs_state = ECORE_CON_PROXY_STATE_AUTH; svr->ecs_state = ECORE_CON_PROXY_STATE_AUTH;
break; break;
case ECORE_CON_PROXY_STATE_AUTH: case ECORE_CON_PROXY_STATE_AUTH:
ECORE_CON_SOCKS_READ(2); ECORE_CON_SOCKS_READ(2);
switch (v5->method) switch (v5->method)
@ -349,9 +357,11 @@ _ecore_con_socks_read_v5(Ecore_Con_Server *svr, Ecore_Con_Socks_v5 *v5, const un
case ECORE_CON_SOCKS_V5_METHOD_NONE: case ECORE_CON_SOCKS_V5_METHOD_NONE:
CRIT("HOW DID THIS HAPPEN?????????"); CRIT("HOW DID THIS HAPPEN?????????");
goto error; goto error;
case ECORE_CON_SOCKS_V5_METHOD_GSSAPI: case ECORE_CON_SOCKS_V5_METHOD_GSSAPI:
/* TODO: this */ /* TODO: this */
break; break;
case ECORE_CON_SOCKS_V5_METHOD_USERPASS: case ECORE_CON_SOCKS_V5_METHOD_USERPASS:
if (data[0] != 1) if (data[0] != 1)
{ {
@ -363,9 +373,11 @@ _ecore_con_socks_read_v5(Ecore_Con_Server *svr, Ecore_Con_Socks_v5 *v5, const un
ecore_con_event_server_error(svr, "proxy request authentication rejected"); ecore_con_event_server_error(svr, "proxy request authentication rejected");
goto error; goto error;
} }
default: default:
break; break;
} }
case ECORE_CON_PROXY_STATE_REQUEST: case ECORE_CON_PROXY_STATE_REQUEST:
{ {
size_t addrlen, buflen; size_t addrlen, buflen;
@ -399,6 +411,7 @@ _ecore_con_socks_read_v5(Ecore_Con_Server *svr, Ecore_Con_Socks_v5 *v5, const un
ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_WRITE); ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_WRITE);
break; break;
} }
case ECORE_CON_PROXY_STATE_CONFIRM: case ECORE_CON_PROXY_STATE_CONFIRM:
{ {
/* this is ugly because we have to read an exact number of bytes, /* this is ugly because we have to read an exact number of bytes,
@ -424,13 +437,16 @@ _ecore_con_socks_read_v5(Ecore_Con_Server *svr, Ecore_Con_Socks_v5 *v5, const un
case 1: case 1:
to_read = 4; to_read = 4;
break; break;
case 3: case 3:
to_read = data[1] + 1; to_read = data[1] + 1;
break; break;
case 4: case 4:
to_read = 16; to_read = 16;
/* lazy debugging stub comment */ /* lazy debugging stub comment */
break; break;
default: default:
ecore_con_event_server_error(svr, "protocol error"); ecore_con_event_server_error(svr, "protocol error");
goto error; goto error;
@ -447,29 +463,38 @@ _ecore_con_socks_read_v5(Ecore_Con_Server *svr, Ecore_Con_Socks_v5 *v5, const un
{ {
case 0: case 0:
break; break;
case 1: case 1:
ecore_con_event_server_error(svr, "general proxy failure"); ecore_con_event_server_error(svr, "general proxy failure");
goto error; goto error;
case 2: case 2:
ecore_con_event_server_error(svr, "connection not allowed by ruleset"); ecore_con_event_server_error(svr, "connection not allowed by ruleset");
goto error; goto error;
case 3: case 3:
ecore_con_event_server_error(svr, "network unreachable"); ecore_con_event_server_error(svr, "network unreachable");
goto error; goto error;
case 4: case 4:
ecore_con_event_server_error(svr, "host unreachable"); ecore_con_event_server_error(svr, "host unreachable");
goto error; goto error;
case 5: case 5:
ecore_con_event_server_error(svr, "connection refused by destination host"); ecore_con_event_server_error(svr, "connection refused by destination host");
goto error; goto error;
case 6: case 6:
ecore_con_event_server_error(svr, "TTL expired"); ecore_con_event_server_error(svr, "TTL expired");
goto error; goto error;
case 7: case 7:
ecore_con_event_server_error(svr, "command not supported / protocol error"); ecore_con_event_server_error(svr, "command not supported / protocol error");
goto error; goto error;
case 8: case 8:
ecore_con_event_server_error(svr, "address type not supported"); ecore_con_event_server_error(svr, "address type not supported");
default: default:
goto error; goto error;
} }
@ -488,6 +513,7 @@ _ecore_con_socks_read_v5(Ecore_Con_Server *svr, Ecore_Con_Socks_v5 *v5, const un
INF("PROXY CONNECTED"); INF("PROXY CONNECTED");
break; break;
} }
default: default:
break; break;
} }
@ -711,6 +737,7 @@ ecore_con_socks4_remote_del(const char *ip, int port, const char *username)
ecore_con_socks_proxies = eina_list_remove(ecore_con_socks_proxies, v4); ecore_con_socks_proxies = eina_list_remove(ecore_con_socks_proxies, v4);
_ecore_con_socks_free((Ecore_Con_Socks *)v4); _ecore_con_socks_free((Ecore_Con_Socks *)v4);
} }
/** /**
* Add a SOCKS v5 proxy to the proxy list * Add a SOCKS v5 proxy to the proxy list
* *
@ -954,4 +981,5 @@ ecore_con_socks_apply_always(Ecore_Con_Socks *ecs)
{ {
_ecore_con_proxy_global = ecs; _ecore_con_proxy_global = ecs;
} }
/** @} */ /** @} */

View File

@ -97,6 +97,7 @@ _gnutls_log_func(int level,
strncat(buf, str, strlen(str) - 1); strncat(buf, str, strlen(str) - 1);
DBG("|<%d>| %s", level, buf); DBG("|<%d>| %s", level, buf);
} }
#endif #endif
static const char * static const char *
@ -339,7 +340,6 @@ _openssl_print_errors(void *conn, int type)
ecore_con_event_client_error(conn, buf); ecore_con_event_client_error(conn, buf);
else else
ecore_con_event_server_error(conn, buf); ecore_con_event_server_error(conn, buf);
} while (1); } while (1);
} }
@ -954,7 +954,6 @@ error:
return ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED; return ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED;
} }
static Ecore_Con_Ssl_Error static Ecore_Con_Ssl_Error
_ecore_con_ssl_server_init_gnutls(Ecore_Con_Server *svr) _ecore_con_ssl_server_init_gnutls(Ecore_Con_Server *svr)
{ {

View File

@ -33,11 +33,13 @@
// all the types, defines, enums etc. from curl that we actuall USE. // all the types, defines, enums etc. from curl that we actuall USE.
// we have to add to this if we use more things from curl not already // we have to add to this if we use more things from curl not already
// defined here. see culr headers to get them from // defined here. see culr headers to get them from
typedef enum { typedef enum
{
CURLM_CALL_MULTI_PERFORM = -1, CURLM_CALL_MULTI_PERFORM = -1,
CURLM_OK = 0 CURLM_OK = 0
} CURLMcode; } CURLMcode;
typedef enum { typedef enum
{
CURLE_OK = 0, CURLE_OK = 0,
CURLE_OPERATION_TIMEDOUT = 28 CURLE_OPERATION_TIMEDOUT = 28
} CURLcode; } CURLcode;
@ -46,7 +48,8 @@ typedef enum {
#define CURLOPTTYPE_FUNCTIONPOINT 20000 #define CURLOPTTYPE_FUNCTIONPOINT 20000
#define CURLOPTTYPE_OFF_T 30000 #define CURLOPTTYPE_OFF_T 30000
#define CINIT(na, t, nu) CURLOPT_ ## na = CURLOPTTYPE_ ## t + nu #define CINIT(na, t, nu) CURLOPT_ ## na = CURLOPTTYPE_ ## t + nu
typedef enum { typedef enum
{
CINIT(FILE, OBJECTPOINT, 1), CINIT(FILE, OBJECTPOINT, 1),
CINIT(URL, OBJECTPOINT, 2), CINIT(URL, OBJECTPOINT, 2),
CINIT(PROXY, OBJECTPOINT, 4), CINIT(PROXY, OBJECTPOINT, 4),
@ -91,30 +94,37 @@ typedef enum {
#define CURLINFO_SLIST 0x400000 #define CURLINFO_SLIST 0x400000
#define CURLINFO_MASK 0x0fffff #define CURLINFO_MASK 0x0fffff
#define CURLINFO_TYPEMASK 0xf00000 #define CURLINFO_TYPEMASK 0xf00000
typedef enum { typedef enum
{
CURLINFO_RESPONSE_CODE = CURLINFO_LONG + 2, CURLINFO_RESPONSE_CODE = CURLINFO_LONG + 2,
} CURLINFO; } CURLINFO;
typedef enum { typedef enum
{
CURLVERSION_FOURTH = 3 CURLVERSION_FOURTH = 3
} CURLversion; } CURLversion;
typedef enum { typedef enum
{
CURLMSG_DONE = 1 CURLMSG_DONE = 1
} CURLMSG; } CURLMSG;
#undef CINIT #undef CINIT
#define CINIT(name, type, num) CURLMOPT_ ## name = CURLOPTTYPE_ ## type + num #define CINIT(name, type, num) CURLMOPT_ ## name = CURLOPTTYPE_ ## type + num
typedef enum { typedef enum
{
CINIT(PIPELINING, LONG, 3) CINIT(PIPELINING, LONG, 3)
} CURLMoption; } CURLMoption;
typedef enum { typedef enum
{
CURL_TIMECOND_NONE = 0, CURL_TIMECOND_NONE = 0,
CURL_TIMECOND_IFMODSINCE = 1, CURL_TIMECOND_IFMODSINCE = 1,
CURL_TIMECOND_IFUNMODSINCE = 2 CURL_TIMECOND_IFUNMODSINCE = 2
} curl_TimeCond; } curl_TimeCond;
enum { enum
{
CURL_HTTP_VERSION_1_0 = 1, CURL_HTTP_VERSION_1_0 = 1,
CURL_HTTP_VERSION_1_1 = 2, CURL_HTTP_VERSION_1_1 = 2,
}; };
typedef enum { typedef enum
{
CURLPROXY_HTTP = 0, CURLPROXY_HTTP = 0,
CURLPROXY_SOCKS4 = 4, CURLPROXY_SOCKS4 = 4,
CURLPROXY_SOCKS5 = 5, CURLPROXY_SOCKS5 = 5,
@ -138,11 +148,13 @@ typedef enum {
typedef void CURLM; typedef void CURLM;
typedef void CURL; typedef void CURL;
struct curl_slist { struct curl_slist
{
char *data; char *data;
struct curl_slist *next; struct curl_slist *next;
}; };
typedef struct { typedef struct
{
CURLversion age; CURLversion age;
const char *version; const char *version;
unsigned int version_num; unsigned int version_num;
@ -158,16 +170,17 @@ typedef struct {
int iconv_ver_num; int iconv_ver_num;
const char *libssh_version; const char *libssh_version;
} curl_version_info_data; } curl_version_info_data;
typedef struct { typedef struct
{
CURLMSG msg; CURLMSG msg;
CURL *easy_handle; CURL *easy_handle;
union { union
{
void *whatever; void *whatever;
CURLcode result; CURLcode result;
} data; } data;
} CURLMsg; } CURLMsg;
typedef struct _Ecore_Con_Curl Ecore_Con_Curl; typedef struct _Ecore_Con_Curl Ecore_Con_Curl;
struct _Ecore_Con_Curl struct _Ecore_Con_Curl
@ -268,7 +281,8 @@ _c_init(void)
#endif #endif
if (!_c->mod) goto error; if (!_c->mod) goto error;
#define SYM(x) if (!(_c->x = eina_module_symbol_get(_c->mod, #x))) goto error #define SYM(x) if (!(_c->x = eina_module_symbol_get(_c->mod, #x))) \
goto error
SYM(curl_global_init); SYM(curl_global_init);
SYM(curl_global_cleanup); SYM(curl_global_cleanup);
SYM(curl_multi_init); SYM(curl_multi_init);
@ -431,7 +445,8 @@ ecore_con_url_new(const char *url)
if (_ecore_con_proxy_global->lookup) if (_ecore_con_proxy_global->lookup)
snprintf(host, sizeof(host), "socks5h://%s", snprintf(host, sizeof(host), "socks5h://%s",
_ecore_con_proxy_global->ip); _ecore_con_proxy_global->ip);
else snprintf(host, sizeof(host), "socks5://%s", else
snprintf(host, sizeof(host), "socks5://%s",
_ecore_con_proxy_global->ip); _ecore_con_proxy_global->ip);
} }
else if (_ecore_con_proxy_global->version == 4) else if (_ecore_con_proxy_global->version == 4)
@ -439,7 +454,8 @@ ecore_con_url_new(const char *url)
if (_ecore_con_proxy_global->lookup) if (_ecore_con_proxy_global->lookup)
snprintf(host, sizeof(host), "socks4a://%s", snprintf(host, sizeof(host), "socks4a://%s",
_ecore_con_proxy_global->ip); _ecore_con_proxy_global->ip);
else snprintf(host, sizeof(host), "socks4://%s", else
snprintf(host, sizeof(host), "socks4://%s",
_ecore_con_proxy_global->ip); _ecore_con_proxy_global->ip);
} }
@ -549,8 +565,10 @@ ecore_con_url_free(Ecore_Con_Url *url_con)
ECORE_MAGIC_SET(url_con, ECORE_MAGIC_NONE); ECORE_MAGIC_SET(url_con, ECORE_MAGIC_NONE);
_c->curl_slist_free_all(url_con->headers); _c->curl_slist_free_all(url_con->headers);
EINA_LIST_FREE(url_con->additional_headers, s) free(s); EINA_LIST_FREE(url_con->additional_headers, s)
EINA_LIST_FREE(url_con->response_headers, s) free(s); free(s);
EINA_LIST_FREE(url_con->response_headers, s)
free(s);
eina_stringshare_del(url_con->url); eina_stringshare_del(url_con->url);
if (url_con->post_data) free(url_con->post_data); if (url_con->post_data) free(url_con->post_data);
free(url_con); free(url_con);
@ -639,7 +657,8 @@ ecore_con_url_additional_headers_clear(Ecore_Con_Url *url_con)
ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__); ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, __func__);
return; return;
} }
EINA_LIST_FREE(url_con->additional_headers, s) free(s); EINA_LIST_FREE(url_con->additional_headers, s)
free(s);
} }
EAPI void * EAPI void *
@ -770,7 +789,8 @@ _ecore_con_url_send(Ecore_Con_Url *url_con, int mode, const void *data, long len
if (url_con->dead) return EINA_FALSE; if (url_con->dead) return EINA_FALSE;
/* Free response headers from previous send() calls */ /* Free response headers from previous send() calls */
EINA_LIST_FREE(url_con->response_headers, s) free((char *)s); EINA_LIST_FREE(url_con->response_headers, s)
free((char *)s);
url_con->response_headers = NULL; url_con->response_headers = NULL;
url_con->status = 0; url_con->status = 0;
@ -801,7 +821,8 @@ _ecore_con_url_send(Ecore_Con_Url *url_con, int mode, const void *data, long len
else else
return EINA_FALSE; return EINA_FALSE;
} }
else _c->curl_easy_setopt(url_con->curl_easy, else
_c->curl_easy_setopt(url_con->curl_easy,
CURLOPT_POSTFIELDSIZE, 0); CURLOPT_POSTFIELDSIZE, 0);
if (mode == MODE_POST) if (mode == MODE_POST)
_c->curl_easy_setopt(url_con->curl_easy, CURLOPT_POST, 1); _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_POST, 1);
@ -813,12 +834,14 @@ _ecore_con_url_send(Ecore_Con_Url *url_con, int mode, const void *data, long len
_c->curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION, _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION,
CURL_TIMECOND_NONE); CURL_TIMECOND_NONE);
break; break;
case ECORE_CON_URL_TIME_IFMODSINCE: case ECORE_CON_URL_TIME_IFMODSINCE:
_c->curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION, _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION,
CURL_TIMECOND_IFMODSINCE); CURL_TIMECOND_IFMODSINCE);
_c->curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMEVALUE, _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMEVALUE,
(long)url_con->timestamp); (long)url_con->timestamp);
break; break;
case ECORE_CON_URL_TIME_IFUNMODSINCE: case ECORE_CON_URL_TIME_IFUNMODSINCE:
_c->curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION, _c->curl_easy_setopt(url_con->curl_easy, CURLOPT_TIMECONDITION,
CURL_TIMECOND_IFUNMODSINCE); CURL_TIMECOND_IFUNMODSINCE);
@ -1127,11 +1150,13 @@ ecore_con_url_http_version_set(Ecore_Con_Url *url_con, Ecore_Con_Url_Http_Versio
CURLOPT_HTTP_VERSION, CURLOPT_HTTP_VERSION,
CURL_HTTP_VERSION_1_0); CURL_HTTP_VERSION_1_0);
break; break;
case ECORE_CON_URL_HTTP_VERSION_1_1: case ECORE_CON_URL_HTTP_VERSION_1_1:
res = _c->curl_easy_setopt(url_con->curl_easy, res = _c->curl_easy_setopt(url_con->curl_easy,
CURLOPT_HTTP_VERSION, CURLOPT_HTTP_VERSION,
CURL_HTTP_VERSION_1_1); CURL_HTTP_VERSION_1_1);
break; break;
default: default:
break; break;
} }
@ -1157,7 +1182,8 @@ ecore_con_url_proxy_set(Ecore_Con_Url *url_con, const char *proxy)
} }
if (!url_con->url) return EINA_FALSE; if (!url_con->url) return EINA_FALSE;
if (url_con->dead) return EINA_FALSE; if (url_con->dead) return EINA_FALSE;
if (!proxy) res = _c->curl_easy_setopt(url_con->curl_easy, if (!proxy)
res = _c->curl_easy_setopt(url_con->curl_easy,
CURLOPT_PROXY, ""); CURLOPT_PROXY, "");
else else
{ {
@ -1510,8 +1536,10 @@ _ecore_con_url_curl_clear(void)
Ecore_Fd_Handler *fdh; Ecore_Fd_Handler *fdh;
Ecore_Con_Url *url_con; Ecore_Con_Url *url_con;
EINA_LIST_FREE(_fd_hd_list, fdh) ecore_main_fd_handler_del(fdh); EINA_LIST_FREE(_fd_hd_list, fdh)
EINA_LIST_FREE(_url_con_list, url_con) _ecore_con_url_multi_remove(url_con); ecore_main_fd_handler_del(fdh);
EINA_LIST_FREE(_url_con_list, url_con)
_ecore_con_url_multi_remove(url_con);
} }
static Eina_Bool static Eina_Bool
@ -1521,7 +1549,8 @@ _ecore_con_url_fd_handler(void *data EINA_UNUSED, Ecore_Fd_Handler *fd_handler E
long ms; long ms;
if (!_c) return ECORE_CALLBACK_CANCEL; if (!_c) return ECORE_CALLBACK_CANCEL;
EINA_LIST_FREE(_fd_hd_list, fdh) ecore_main_fd_handler_del(fdh); EINA_LIST_FREE(_fd_hd_list, fdh)
ecore_main_fd_handler_del(fdh);
_c->curl_multi_timeout(_c->_curlm, &ms); _c->curl_multi_timeout(_c->_curlm, &ms);
if ((ms >= CURL_MIN_TIMEOUT) || (ms <= 0)) ms = CURL_MIN_TIMEOUT; if ((ms >= CURL_MIN_TIMEOUT) || (ms <= 0)) ms = CURL_MIN_TIMEOUT;
ecore_timer_interval_set(_curl_timer, (double)ms / 1000.0); ecore_timer_interval_set(_curl_timer, (double)ms / 1000.0);
@ -1578,7 +1607,8 @@ _ecore_con_url_timer(void *data EINA_UNUSED)
int still_running; int still_running;
CURLMcode ret; CURLMcode ret;
EINA_LIST_FREE(_fd_hd_list, fdh) ecore_main_fd_handler_del(fdh); EINA_LIST_FREE(_fd_hd_list, fdh)
ecore_main_fd_handler_del(fdh);
_ecore_con_url_info_read(); _ecore_con_url_info_read();
if (!_c) return ECORE_CALLBACK_RENEW; if (!_c) return ECORE_CALLBACK_RENEW;
ret = _c->curl_multi_perform(_c->_curlm, &still_running); ret = _c->curl_multi_perform(_c->_curlm, &still_running);
@ -1650,3 +1680,4 @@ _ecore_con_event_url_free(Ecore_Con_Url *url_con, void *ev)
url_con->event_count--; url_con->event_count--;
if (url_con->dead && (!url_con->event_count)) ecore_con_url_free(url_con); if (url_con->dead && (!url_con->event_count)) ecore_con_url_free(url_con);
} }